mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: drivers/DigitalInOut.h
- Revision:
- 187:0387e8f68319
- Parent:
- 167:e84263d55307
- Child:
- 188:bcfe06ba3d64
--- a/drivers/DigitalInOut.h Fri Jun 22 16:45:37 2018 +0100 +++ b/drivers/DigitalInOut.h Thu Sep 06 13:40:20 2018 +0100 @@ -36,7 +36,8 @@ * * @param pin DigitalInOut pin to connect to */ - DigitalInOut(PinName pin) : gpio() { + DigitalInOut(PinName pin) : gpio() + { // No lock needed in the constructor gpio_init_in(&gpio, pin); } @@ -48,7 +49,8 @@ * @param mode the initial mode of the pin * @param value the initial value of the pin if is an output */ - DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() { + DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() + { // No lock needed in the constructor gpio_init_inout(&gpio, pin, direction, mode, value); } @@ -58,7 +60,8 @@ * @param value An integer specifying the pin output value, * 0 for logical 0, 1 (or any other non-zero value) for logical 1 */ - void write(int value) { + void write(int value) + { // Thread safe / atomic HAL call gpio_write(&gpio, value); } @@ -69,14 +72,16 @@ * an integer representing the output setting of the pin if it is an output, * or read the input if set as an input */ - int read() { + int read() + { // Thread safe / atomic HAL call return gpio_read(&gpio); } /** Set as an output */ - void output() { + void output() + { core_util_critical_section_enter(); gpio_dir(&gpio, PIN_OUTPUT); core_util_critical_section_exit(); @@ -84,7 +89,8 @@ /** Set as an input */ - void input() { + void input() + { core_util_critical_section_enter(); gpio_dir(&gpio, PIN_INPUT); core_util_critical_section_exit(); @@ -94,7 +100,8 @@ * * @param pull PullUp, PullDown, PullNone, OpenDrain */ - void mode(PinMode pull) { + void mode(PinMode pull) + { core_util_critical_section_enter(); gpio_mode(&gpio, pull); core_util_critical_section_exit(); @@ -106,7 +113,8 @@ * Non zero value if pin is connected to uc GPIO * 0 if gpio object was initialized with NC */ - int is_connected() { + int is_connected() + { // Thread safe / atomic HAL call return gpio_is_connected(&gpio); } @@ -114,7 +122,8 @@ /** A shorthand for write() * \sa DigitalInOut::write() */ - DigitalInOut& operator= (int value) { + DigitalInOut &operator= (int value) + { // Underlying write is thread safe write(value); return *this; @@ -123,7 +132,8 @@ /** A shorthand for write() * \sa DigitalInOut::write() */ - DigitalInOut& operator= (DigitalInOut& rhs) { + DigitalInOut &operator= (DigitalInOut &rhs) + { core_util_critical_section_enter(); write(rhs.read()); core_util_critical_section_exit(); @@ -133,7 +143,8 @@ /** A shorthand for read() * \sa DigitalInOut::read() */ - operator int() { + operator int() + { // Underlying call is thread safe return read(); }