updates
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal-eddystone by
Revision 63:b4372a29994f, committed 2016-07-13
- Comitter:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:42 2016 +0100
- Parent:
- 62:e633e0eeaf19
- Child:
- 64:98cb56bf7711
- Commit message:
- Synchronized with git rev 4cf48035
Author: Joe Finney
microbit: Added getDigitalValue overload for PullMode #156
- Introduced an overload to MicroBitIOPin::getDigitalValue() to permit the
setting of a specific pull mode at the time of reading.
- Bugfix of MicroBitIOPin::setPull() to persist preferred pull settings
- Added configuration options to allow the default PullMode to be set via
compile time option through MicroBitConfig.h or YOTTA_CONFIG
Changed in this revision
--- a/inc/core/MicroBitConfig.h Wed Jul 13 12:18:41 2016 +0100 +++ b/inc/core/MicroBitConfig.h Wed Jul 13 12:18:42 2016 +0100 @@ -320,6 +320,19 @@ // +// I/O Options +// + + +// +// Define the default mode in which the digital input pins are configured. +// valid options are PullDown, PullUp and PullNone. +// +#ifndef MICROBIT_DEFAULT_PULLMODE +#define MICROBIT_DEFAULT_PULLMODE PullDown +#endif + +// // Panic options //
--- a/inc/drivers/MicroBitPin.h Wed Jul 13 12:18:41 2016 +0100 +++ b/inc/drivers/MicroBitPin.h Wed Jul 13 12:18:42 2016 +0100 @@ -95,8 +95,8 @@ { // The mbed object looking after this pin at any point in time (untyped due to dynamic behaviour). void *pin; - PinCapability capability; + uint8_t pullMode; /** * Disconnect any attached mBed IO from this pin. @@ -200,6 +200,21 @@ int getDigitalValue(); /** + * Configures this IO pin as a digital input with the specified internal pull-up/pull-down configuraiton (if necessary) and tests its current value. + * + * @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone + * + * @return 1 if this input is high, 0 if input is LO, or MICROBIT_NOT_SUPPORTED + * if the given pin does not have digital capability. + * + * @code + * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH); + * P0.getDigitalValue(PullUp); // P0 is either 0 or 1; + * @endcode + */ + int getDigitalValue(PinMode pull); + + /** * Configures this IO pin as an analog/pwm output, and change the output value to the given level. * * @param value the level to set on the output pin, in the range 0 - 1024
--- a/inc/platform/yotta_cfg_mappings.h Wed Jul 13 12:18:41 2016 +0100 +++ b/inc/platform/yotta_cfg_mappings.h Wed Jul 13 12:18:42 2016 +0100 @@ -63,6 +63,10 @@ #define MICROBIT_DEFAULT_PRINT_SPEED YOTTA_CFG_MICROBIT_DAL_DISPLAY_PRINT_SPEED #endif +#ifdef YOTTA_CFG_MICROBIT_DAL_DEFAULT_PULLMODE + #define MICROBIT_DEFAULT_PULLMODE YOTTA_CFG_MICROBIT_DAL_DEFAULT_PULLMODE +#endif + #ifdef YOTTA_CFG_MICROBIT_DAL_PANIC_ON_HEAP_FULL #define MICROBIT_PANIC_HEAP_FULL YOTTA_CFG_MICROBIT_DAL_PANIC_ON_HEAP_FULL #endif
--- a/source/drivers/MicroBitPin.cpp Wed Jul 13 12:18:41 2016 +0100 +++ b/source/drivers/MicroBitPin.cpp Wed Jul 13 12:18:42 2016 +0100 @@ -57,6 +57,7 @@ this->id = id; this->name = name; this->capability = capability; + this->pullMode = MICROBIT_DEFAULT_PULLMODE; // Power up in a disconnected, low power state. // If we're unused, this is how it will stay... @@ -159,7 +160,7 @@ if (!(status & (IO_STATUS_DIGITAL_IN | IO_STATUS_EVENT_ON_EDGE | IO_STATUS_EVENT_PULSE_ON_EDGE))) { disconnect(); - pin = new DigitalIn(name,PullDown); + pin = new DigitalIn(name, (PinMode)pullMode); status |= IO_STATUS_DIGITAL_IN; } @@ -169,6 +170,25 @@ return ((DigitalIn *)pin)->read(); } +/** + * Configures this IO pin as a digital input with the specified internal pull-up/pull-down configuraiton (if necessary) and tests its current value. + * + * @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone + * + * @return 1 if this input is high, 0 if input is LO, or MICROBIT_NOT_SUPPORTED + * if the given pin does not have digital capability. + * + * @code + * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH); + * P0.getDigitalValue(PullUp); // P0 is either 0 or 1; + * @endcode + */ +int MicroBitPin::getDigitalValue(PinMode pull) +{ + setPull(pull); + return getDigitalValue(); +} + int MicroBitPin::obtainAnalogChannel() { // Move into an analogue input state if necessary, if we are no longer the focus of a DynamicPWM instance, allocate ourselves again! @@ -451,6 +471,8 @@ */ int MicroBitPin::setPull(PinMode pull) { + pullMode = pull; + if ((status & IO_STATUS_DIGITAL_IN)) { ((DigitalIn *)pin)->mode(pull); @@ -528,7 +550,7 @@ disconnect(); pin = new TimedInterruptIn(name); - ((TimedInterruptIn *)pin)->mode(PullDown); + ((TimedInterruptIn *)pin)->mode((PinMode)pullMode); ((TimedInterruptIn *)pin)->rise(this, &MicroBitPin::onRise); ((TimedInterruptIn *)pin)->fall(this, &MicroBitPin::onFall); }