The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
Diff: drivers/PortInOut.h
- Revision:
- 170:e95d10626187
- Parent:
- 156:ff21514d8981
- Child:
- 172:65be27845400
--- a/drivers/PortInOut.h Fri Jun 22 15:38:59 2018 +0100 +++ b/drivers/PortInOut.h Thu Sep 06 13:39:34 2018 +0100 @@ -39,7 +39,8 @@ * @param port Port to connect to (Port0-Port5) * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) */ - PortInOut(PortName port, int mask = 0xFFFFFFFF) { + PortInOut(PortName port, int mask = 0xFFFFFFFF) + { core_util_critical_section_enter(); port_init(&_port, port, mask, PIN_INPUT); core_util_critical_section_exit(); @@ -49,7 +50,8 @@ * * @param value An integer specifying a bit to write for every corresponding port pin */ - void write(int value) { + void write(int value) + { port_write(&_port, value); } @@ -58,13 +60,15 @@ * @returns * An integer with each bit corresponding to associated port pin setting */ - int read() { + int read() + { return port_read(&_port); } /** Set as an output */ - void output() { + void output() + { core_util_critical_section_enter(); port_dir(&_port, PIN_OUTPUT); core_util_critical_section_exit(); @@ -72,7 +76,8 @@ /** Set as an input */ - void input() { + void input() + { core_util_critical_section_enter(); port_dir(&_port, PIN_INPUT); core_util_critical_section_exit(); @@ -82,7 +87,8 @@ * * @param mode PullUp, PullDown, PullNone, OpenDrain */ - void mode(PinMode mode) { + void mode(PinMode mode) + { core_util_critical_section_enter(); port_mode(&_port, mode); core_util_critical_section_exit(); @@ -91,7 +97,8 @@ /** A shorthand for write() * \sa PortInOut::write() */ - PortInOut& operator= (int value) { + PortInOut &operator= (int value) + { write(value); return *this; } @@ -99,7 +106,8 @@ /** A shorthand for write() * \sa PortInOut::write() */ - PortInOut& operator= (PortInOut& rhs) { + PortInOut &operator= (PortInOut &rhs) + { write(rhs.read()); return *this; } @@ -107,7 +115,8 @@ /** A shorthand for read() * \sa PortInOut::read() */ - operator int() { + operator int() + { return read(); }