![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
temp
Dependencies: mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem
mbed/drivers/PortOut.h@0:c88c3b616c00, 2020-03-16 (annotated)
- Committer:
- IKobayashi
- Date:
- Mon Mar 16 23:37:42 2020 +0900
- Revision:
- 0:c88c3b616c00
copy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IKobayashi | 0:c88c3b616c00 | 1 | /* mbed Microcontroller Library |
IKobayashi | 0:c88c3b616c00 | 2 | * Copyright (c) 2006-2013 ARM Limited |
IKobayashi | 0:c88c3b616c00 | 3 | * |
IKobayashi | 0:c88c3b616c00 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
IKobayashi | 0:c88c3b616c00 | 5 | * you may not use this file except in compliance with the License. |
IKobayashi | 0:c88c3b616c00 | 6 | * You may obtain a copy of the License at |
IKobayashi | 0:c88c3b616c00 | 7 | * |
IKobayashi | 0:c88c3b616c00 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
IKobayashi | 0:c88c3b616c00 | 9 | * |
IKobayashi | 0:c88c3b616c00 | 10 | * Unless required by applicable law or agreed to in writing, software |
IKobayashi | 0:c88c3b616c00 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
IKobayashi | 0:c88c3b616c00 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
IKobayashi | 0:c88c3b616c00 | 13 | * See the License for the specific language governing permissions and |
IKobayashi | 0:c88c3b616c00 | 14 | * limitations under the License. |
IKobayashi | 0:c88c3b616c00 | 15 | */ |
IKobayashi | 0:c88c3b616c00 | 16 | #ifndef MBED_PORTOUT_H |
IKobayashi | 0:c88c3b616c00 | 17 | #define MBED_PORTOUT_H |
IKobayashi | 0:c88c3b616c00 | 18 | |
IKobayashi | 0:c88c3b616c00 | 19 | #include "platform/platform.h" |
IKobayashi | 0:c88c3b616c00 | 20 | |
IKobayashi | 0:c88c3b616c00 | 21 | #if DEVICE_PORTOUT |
IKobayashi | 0:c88c3b616c00 | 22 | |
IKobayashi | 0:c88c3b616c00 | 23 | #include "hal/port_api.h" |
IKobayashi | 0:c88c3b616c00 | 24 | #include "platform/critical.h" |
IKobayashi | 0:c88c3b616c00 | 25 | |
IKobayashi | 0:c88c3b616c00 | 26 | namespace mbed { |
IKobayashi | 0:c88c3b616c00 | 27 | /** \addtogroup drivers */ |
IKobayashi | 0:c88c3b616c00 | 28 | /** @{*/ |
IKobayashi | 0:c88c3b616c00 | 29 | /** A multiple pin digital out |
IKobayashi | 0:c88c3b616c00 | 30 | * |
IKobayashi | 0:c88c3b616c00 | 31 | * @Note Synchronization level: Interrupt safe |
IKobayashi | 0:c88c3b616c00 | 32 | * |
IKobayashi | 0:c88c3b616c00 | 33 | * Example: |
IKobayashi | 0:c88c3b616c00 | 34 | * @code |
IKobayashi | 0:c88c3b616c00 | 35 | * // Toggle all four LEDs |
IKobayashi | 0:c88c3b616c00 | 36 | * |
IKobayashi | 0:c88c3b616c00 | 37 | * #include "mbed.h" |
IKobayashi | 0:c88c3b616c00 | 38 | * |
IKobayashi | 0:c88c3b616c00 | 39 | * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
IKobayashi | 0:c88c3b616c00 | 40 | * #define LED_MASK 0x00B40000 |
IKobayashi | 0:c88c3b616c00 | 41 | * |
IKobayashi | 0:c88c3b616c00 | 42 | * PortOut ledport(Port1, LED_MASK); |
IKobayashi | 0:c88c3b616c00 | 43 | * |
IKobayashi | 0:c88c3b616c00 | 44 | * int main() { |
IKobayashi | 0:c88c3b616c00 | 45 | * while(1) { |
IKobayashi | 0:c88c3b616c00 | 46 | * ledport = LED_MASK; |
IKobayashi | 0:c88c3b616c00 | 47 | * wait(1); |
IKobayashi | 0:c88c3b616c00 | 48 | * ledport = 0; |
IKobayashi | 0:c88c3b616c00 | 49 | * wait(1); |
IKobayashi | 0:c88c3b616c00 | 50 | * } |
IKobayashi | 0:c88c3b616c00 | 51 | * } |
IKobayashi | 0:c88c3b616c00 | 52 | * @endcode |
IKobayashi | 0:c88c3b616c00 | 53 | */ |
IKobayashi | 0:c88c3b616c00 | 54 | class PortOut { |
IKobayashi | 0:c88c3b616c00 | 55 | public: |
IKobayashi | 0:c88c3b616c00 | 56 | |
IKobayashi | 0:c88c3b616c00 | 57 | /** Create an PortOut, connected to the specified port |
IKobayashi | 0:c88c3b616c00 | 58 | * |
IKobayashi | 0:c88c3b616c00 | 59 | * @param port Port to connect to (Port0-Port5) |
IKobayashi | 0:c88c3b616c00 | 60 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
IKobayashi | 0:c88c3b616c00 | 61 | */ |
IKobayashi | 0:c88c3b616c00 | 62 | PortOut(PortName port, int mask = 0xFFFFFFFF) { |
IKobayashi | 0:c88c3b616c00 | 63 | core_util_critical_section_enter(); |
IKobayashi | 0:c88c3b616c00 | 64 | port_init(&_port, port, mask, PIN_OUTPUT); |
IKobayashi | 0:c88c3b616c00 | 65 | core_util_critical_section_exit(); |
IKobayashi | 0:c88c3b616c00 | 66 | } |
IKobayashi | 0:c88c3b616c00 | 67 | |
IKobayashi | 0:c88c3b616c00 | 68 | /** Write the value to the output port |
IKobayashi | 0:c88c3b616c00 | 69 | * |
IKobayashi | 0:c88c3b616c00 | 70 | * @param value An integer specifying a bit to write for every corresponding PortOut pin |
IKobayashi | 0:c88c3b616c00 | 71 | */ |
IKobayashi | 0:c88c3b616c00 | 72 | void write(int value) { |
IKobayashi | 0:c88c3b616c00 | 73 | port_write(&_port, value); |
IKobayashi | 0:c88c3b616c00 | 74 | } |
IKobayashi | 0:c88c3b616c00 | 75 | |
IKobayashi | 0:c88c3b616c00 | 76 | /** Read the value currently output on the port |
IKobayashi | 0:c88c3b616c00 | 77 | * |
IKobayashi | 0:c88c3b616c00 | 78 | * @returns |
IKobayashi | 0:c88c3b616c00 | 79 | * An integer with each bit corresponding to associated PortOut pin setting |
IKobayashi | 0:c88c3b616c00 | 80 | */ |
IKobayashi | 0:c88c3b616c00 | 81 | int read() { |
IKobayashi | 0:c88c3b616c00 | 82 | return port_read(&_port); |
IKobayashi | 0:c88c3b616c00 | 83 | } |
IKobayashi | 0:c88c3b616c00 | 84 | |
IKobayashi | 0:c88c3b616c00 | 85 | /** A shorthand for write() |
IKobayashi | 0:c88c3b616c00 | 86 | */ |
IKobayashi | 0:c88c3b616c00 | 87 | PortOut& operator= (int value) { |
IKobayashi | 0:c88c3b616c00 | 88 | write(value); |
IKobayashi | 0:c88c3b616c00 | 89 | return *this; |
IKobayashi | 0:c88c3b616c00 | 90 | } |
IKobayashi | 0:c88c3b616c00 | 91 | |
IKobayashi | 0:c88c3b616c00 | 92 | PortOut& operator= (PortOut& rhs) { |
IKobayashi | 0:c88c3b616c00 | 93 | write(rhs.read()); |
IKobayashi | 0:c88c3b616c00 | 94 | return *this; |
IKobayashi | 0:c88c3b616c00 | 95 | } |
IKobayashi | 0:c88c3b616c00 | 96 | |
IKobayashi | 0:c88c3b616c00 | 97 | /** A shorthand for read() |
IKobayashi | 0:c88c3b616c00 | 98 | */ |
IKobayashi | 0:c88c3b616c00 | 99 | operator int() { |
IKobayashi | 0:c88c3b616c00 | 100 | return read(); |
IKobayashi | 0:c88c3b616c00 | 101 | } |
IKobayashi | 0:c88c3b616c00 | 102 | |
IKobayashi | 0:c88c3b616c00 | 103 | private: |
IKobayashi | 0:c88c3b616c00 | 104 | port_t _port; |
IKobayashi | 0:c88c3b616c00 | 105 | }; |
IKobayashi | 0:c88c3b616c00 | 106 | |
IKobayashi | 0:c88c3b616c00 | 107 | } // namespace mbed |
IKobayashi | 0:c88c3b616c00 | 108 | |
IKobayashi | 0:c88c3b616c00 | 109 | #endif |
IKobayashi | 0:c88c3b616c00 | 110 | |
IKobayashi | 0:c88c3b616c00 | 111 | #endif |
IKobayashi | 0:c88c3b616c00 | 112 | |
IKobayashi | 0:c88c3b616c00 | 113 | /** @}*/ |