Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed by
Diff: DigitalIn.h
- Revision:
- 122:f9eeca106725
- Parent:
- 93:e188a91d3eaa
- Child:
- 123:b0220dba8be7
diff -r 6c34061e7c34 -r f9eeca106725 DigitalIn.h
--- a/DigitalIn.h Wed May 25 16:44:06 2016 +0100
+++ b/DigitalIn.h Thu Jul 07 14:34:11 2016 +0100
@@ -19,11 +19,14 @@
#include "platform.h"
#include "gpio_api.h"
+#include "critical.h"
namespace mbed {
/** A digital input, used for reading the state of a pin
*
+ * @Note Synchronization level: Interrupt safe
+ *
* Example:
* @code
* // Flash an LED while a DigitalIn is true
@@ -51,6 +54,7 @@
* @param pin DigitalIn pin to connect to
*/
DigitalIn(PinName pin) : gpio() {
+ // No lock needed in the constructor
gpio_init_in(&gpio, pin);
}
@@ -60,6 +64,7 @@
* @param mode the initial mode of the pin
*/
DigitalIn(PinName pin, PinMode mode) : gpio() {
+ // No lock needed in the constructor
gpio_init_in_ex(&gpio, pin, mode);
}
/** Read the input, represented as 0 or 1 (int)
@@ -69,6 +74,7 @@
* 0 for logical 0, 1 for logical 1
*/
int read() {
+ // Thread safe / atomic HAL call
return gpio_read(&gpio);
}
@@ -77,7 +83,9 @@
* @param mode PullUp, PullDown, PullNone, OpenDrain
*/
void mode(PinMode pull) {
+ core_util_critical_section_enter();
gpio_mode(&gpio, pull);
+ core_util_critical_section_exit();
}
/** Return the output setting, represented as 0 or 1 (int)
@@ -87,6 +95,7 @@
* 0 if gpio object was initialized with NC
*/
int is_connected() {
+ // Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
}
@@ -94,6 +103,7 @@
/** An operator shorthand for read()
*/
operator int() {
+ // Underlying read is thread safe
return read();
}
#endif
