updates
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal-eddystone by
Revision 65:f7ebabf23e15, committed 2016-07-13
- Comitter:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:45 2016 +0100
- Parent:
- 64:98cb56bf7711
- Child:
- 66:2fc7d7c2fffc
- Commit message:
- Synchronized with git rev 00674e34
Author: Joe Finney
microbit: Tuning and furhter debounce of SHAKE gesture
- Added timeout code to prevent over-generation of SHAKE events.
- Tuning of SHAKE detection parameters to align sensitivity with existing
microbit.co.uk algorithm
Changed in this revision
--- a/inc/bluetooth/MicroBitUARTService.h Wed Jul 13 12:18:43 2016 +0100 +++ b/inc/bluetooth/MicroBitUARTService.h Wed Jul 13 12:18:45 2016 +0100 @@ -55,7 +55,7 @@ uint8_t txBufferSize; - uint32_t rxCharacteristicHandle; + uint32_t txCharacteristicHandle; // Bluetooth stack we're running on. BLEDevice &ble; @@ -115,69 +115,36 @@ int getc(MicroBitSerialMode mode = SYNC_SLEEP); /** - * Places a single character into our transmission buffer, + * places a single character into our transmission buffer, * * @param c the character to transmit * - * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode - * gives a different behaviour: - * - * ASYNC - Will copy as many characters as it can into the buffer for transmission, - * and return control to the user. - * - * SYNC_SPINWAIT - will return MICROBIT_INVALID_PARAMETER - * - * SYNC_SLEEP - Will perform a cooperative blocking wait until all - * given characters have been received by the connected - * device. - * - * @return the number of characters written, or MICROBIT_NOT_SUPPORTED if there is - * no connected device, or the connected device has not enabled indications. + * @return the number of characters written (0, or 1). */ - int putc(char c, MicroBitSerialMode mode = SYNC_SLEEP); + int putc(char c); /** * Copies characters into the buffer used for Transmitting to the central device. * * @param buf a buffer containing length number of bytes. * @param length the size of the buffer. - * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode - * gives a different behaviour: * - * ASYNC - Will copy as many characters as it can into the buffer for transmission, - * and return control to the user. - * - * SYNC_SPINWAIT - will return MICROBIT_INVALID_PARAMETER + * @return the number of characters copied into the buffer * - * SYNC_SLEEP - Will perform a cooperative blocking wait until all - * given characters have been received by the connected - * device. - * - * @return the number of characters written, or MICROBIT_NOT_SUPPORTED if there is - * no connected device, or the connected device has not enabled indications. + * @note no modes for sending are available at the moment, due to interrupt overhead. */ - int send(const uint8_t *buf, int length, MicroBitSerialMode mode = SYNC_SLEEP); + int send(const uint8_t *buf, int length); /** * Copies characters into the buffer used for Transmitting to the central device. * * @param s the string to transmit - * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode - * gives a different behaviour: * - * ASYNC - Will copy as many characters as it can into the buffer for transmission, - * and return control to the user. - * - * SYNC_SPINWAIT - will return MICROBIT_INVALID_PARAMETER + * @return the number of characters copied into the buffer * - * SYNC_SLEEP - Will perform a cooperative blocking wait until all - * given characters have been received by the connected - * device. - * - * @return the number of characters written, or MICROBIT_NOT_SUPPORTED if there is - * no connected device, or the connected device has not enabled indications. + * @note no modes for sending are available at the moment, due to interrupt overhead. */ - int send(ManagedString s, MicroBitSerialMode mode = SYNC_SLEEP); + int send(ManagedString s); /** * Reads a number of characters from the rxBuffer and fills user given buffer.
--- a/inc/core/MicroBitConfig.h Wed Jul 13 12:18:43 2016 +0100 +++ b/inc/core/MicroBitConfig.h Wed Jul 13 12:18:45 2016 +0100 @@ -320,19 +320,6 @@ // -// 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/MicroBitAccelerometer.h Wed Jul 13 12:18:43 2016 +0100 +++ b/inc/drivers/MicroBitAccelerometer.h Wed Jul 13 12:18:45 2016 +0100 @@ -97,12 +97,13 @@ #define MICROBIT_ACCELEROMETER_REST_TOLERANCE 200 #define MICROBIT_ACCELEROMETER_TILT_TOLERANCE 200 #define MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE 400 -#define MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE 1000 +#define MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE 400 #define MICROBIT_ACCELEROMETER_3G_TOLERANCE 3072 #define MICROBIT_ACCELEROMETER_6G_TOLERANCE 6144 #define MICROBIT_ACCELEROMETER_8G_TOLERANCE 8192 -#define MICROBIT_ACCELEROMETER_GESTURE_DAMPING 10 -#define MICROBIT_ACCELEROMETER_SHAKE_DAMPING 10 +#define MICROBIT_ACCELEROMETER_GESTURE_DAMPING 5 +#define MICROBIT_ACCELEROMETER_SHAKE_DAMPING 10 +#define MICROBIT_ACCELEROMETER_SHAKE_RTX 30 #define MICROBIT_ACCELEROMETER_REST_THRESHOLD (MICROBIT_ACCELEROMETER_REST_TOLERANCE * MICROBIT_ACCELEROMETER_REST_TOLERANCE) #define MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD (MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE * MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE) @@ -144,8 +145,9 @@ impulse_3, impulse_6, impulse_8, - count:4, - timer:4; + count:8; + + uint16_t timer; }; /**
--- a/inc/drivers/MicroBitPin.h Wed Jul 13 12:18:43 2016 +0100 +++ b/inc/drivers/MicroBitPin.h Wed Jul 13 12:18:45 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,21 +200,6 @@ 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/drivers/MicroBitSerial.h Wed Jul 13 12:18:43 2016 +0100 +++ b/inc/drivers/MicroBitSerial.h Wed Jul 13 12:18:45 2016 +0100 @@ -436,8 +436,6 @@ /** * Configures an event to be fired after "len" characters. * - * Will generate an event with the ID: MICROBIT_ID_SERIAL and the value MICROBIT_SERIAL_EVT_HEAD_MATCH. - * * @param len the number of characters to wait before triggering the event. * * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode @@ -457,9 +455,7 @@ /** * Configures an event to be fired on a match with one of the delimeters. * - * Will generate an event with the ID: MICROBIT_ID_SERIAL and the value MICROBIT_SERIAL_EVT_DELIM_MATCH. - * - * @param delimeters the characters to match received characters against e.g. ManagedString("\n") + * @param delimeters the characters to match received characters against e.g. ManagedString("\r\n") * * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode * gives a different behaviour:
--- a/inc/platform/yotta_cfg_mappings.h Wed Jul 13 12:18:43 2016 +0100 +++ b/inc/platform/yotta_cfg_mappings.h Wed Jul 13 12:18:45 2016 +0100 @@ -63,10 +63,6 @@ #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/module.json Wed Jul 13 12:18:43 2016 +0100 +++ b/module.json Wed Jul 13 12:18:45 2016 +0100 @@ -14,7 +14,7 @@ "author": "Joe Finney <j.finney@lancaster.ac.uk (mailto:j.finney@lancaster.ac.uk) >", "homepage": "https://github.com/lancaster-university/microbit-dal/", "dependencies": { - "mbed-classic": "lancaster-university/mbed-classic#microbit_hfclk+mb5", + "mbed-classic": "lancaster-university/mbed-classic#microbit_hfclk+mb4", "ble": "lancaster-university/BLE_API#v2.5.0+mb3", "ble-nrf51822": "lancaster-university/nrf51822#v2.5.0+mb6", "nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb4"
--- a/source/bluetooth/MicroBitBLEManager.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/bluetooth/MicroBitBLEManager.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -336,8 +336,6 @@ #if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE) DeviceInformationService ble_device_information_service (*ble, MICROBIT_BLE_MANUFACTURER, MICROBIT_BLE_MODEL, serialNumber.toCharArray(), MICROBIT_BLE_HARDWARE_VERSION, MICROBIT_BLE_FIRMWARE_VERSION, MICROBIT_BLE_SOFTWARE_VERSION); -#else - (void)serialNumber; #endif #if CONFIG_ENABLED(MICROBIT_BLE_EVENT_SERVICE)
--- a/source/bluetooth/MicroBitUARTService.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/bluetooth/MicroBitUARTService.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -40,14 +40,17 @@ static uint8_t txBufferHead = 0; static uint8_t txBufferTail = 0; -static GattCharacteristic* txCharacteristic = NULL; +static GattCharacteristic* rxCharacteristic = NULL; /** - * A callback function for whenever a Bluetooth device consumes our TX Buffer + * A callback function for whenever a Bluetooth device consumes our RX Buffer */ -void on_confirmation(uint16_t handle) +void on_confirmation_received_callback(uint16_t handle) { - if(handle == txCharacteristic->getValueAttribute().getHandle()) +#if CONFIG_ENABLED(MICROBIT_DBG) + SERIAL_DEBUG->printf("RECEIVED!! %d \r\n",handle); +#endif + if(handle == rxCharacteristic->getValueAttribute().getHandle()) { txBufferTail = txBufferHead; MicroBitEvent(MICROBIT_ID_NOTIFY, MICROBIT_UART_S_EVT_TX_EMPTY); @@ -78,27 +81,27 @@ txBufferTail = 0; this->txBufferSize = txBufferSize; - GattCharacteristic rxCharacteristic(UARTServiceRXCharacteristicUUID, rxBuffer, 1, rxBufferSize, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); + GattCharacteristic txCharacteristic(UARTServiceTXCharacteristicUUID, rxBuffer, 1, rxBufferSize, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); - txCharacteristic = new GattCharacteristic(UARTServiceTXCharacteristicUUID, txBuffer, 1, txBufferSize, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE); + rxCharacteristic = new GattCharacteristic(UARTServiceRXCharacteristicUUID, txBuffer, 1, txBufferSize, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE); - GattCharacteristic *charTable[] = {txCharacteristic, &rxCharacteristic}; + GattCharacteristic *charTable[] = {&txCharacteristic, rxCharacteristic}; GattService uartService(UARTServiceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); _ble.addService(uartService); - this->rxCharacteristicHandle = rxCharacteristic.getValueAttribute().getHandle(); + this->txCharacteristicHandle = txCharacteristic.getValueAttribute().getHandle(); _ble.gattServer().onDataWritten(this, &MicroBitUARTService::onDataWritten); - _ble.gattServer().onConfirmationReceived(on_confirmation); + _ble.gattServer().onConfirmationReceived(on_confirmation_received_callback); } /** - * A callback function for whenever a Bluetooth device writes to our RX characteristic. + * A callback function for whenever a Bluetooth device writes to our TX characteristic. */ void MicroBitUARTService::onDataWritten(const GattWriteCallbackParams *params) { - if (params->handle == this->rxCharacteristicHandle) + if (params->handle == this->txCharacteristicHandle) { uint16_t bytesWritten = params->len; @@ -207,24 +210,11 @@ * * @param c the character to transmit * - * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode - * gives a different behaviour: - * - * ASYNC - Will copy as many characters as it can into the buffer for transmission, - * and return control to the user. - * - * SYNC_SPINWAIT - will return MICROBIT_INVALID_PARAMETER - * - * SYNC_SLEEP - Will perform a cooperative blocking wait until all - * given characters have been received by the connected - * device. - * - * @return the number of characters written, or MICROBIT_NOT_SUPPORTED if there is - * no connected device, or the connected device has not enabled indications. + * @return the number of characters written (0, or 1). */ -int MicroBitUARTService::putc(char c, MicroBitSerialMode mode) +int MicroBitUARTService::putc(char c) { - return (send((uint8_t *)&c, 1, mode) == 1) ? 1 : EOF; + return (send((uint8_t *)&c, 1) == 1) ? 1 : EOF; } /** @@ -232,38 +222,21 @@ * * @param buf a buffer containing length number of bytes. * @param length the size of the buffer. - * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode - * gives a different behaviour: * - * ASYNC - Will copy as many characters as it can into the buffer for transmission, - * and return control to the user. - * - * SYNC_SPINWAIT - will return MICROBIT_INVALID_PARAMETER - * - * SYNC_SLEEP - Will perform a cooperative blocking wait until all - * given characters have been received by the connected - * device. + * @return the number of characters copied into the buffer * - * @return the number of characters written, or MICROBIT_NOT_SUPPORTED if there is - * no connected device, or the connected device has not enabled indications. + * @note no modes for sending are available at the moment, due to interrupt overhead. */ -int MicroBitUARTService::send(const uint8_t *buf, int length, MicroBitSerialMode mode) +int MicroBitUARTService::send(const uint8_t *buf, int length) { - if(length < 1 || mode == SYNC_SPINWAIT) + if(length < 1) return MICROBIT_INVALID_PARAMETER; - bool updatesEnabled = false; - - ble.gattServer().areUpdatesEnabled(*txCharacteristic, &updatesEnabled); - - if(!ble.getGapState().connected && !updatesEnabled) - return MICROBIT_NOT_SUPPORTED; - int bytesWritten = 0; - while(bytesWritten < length && ble.getGapState().connected && updatesEnabled) - { - for(int bufferIterator = bytesWritten; bufferIterator < length; bufferIterator++) + if (ble.getGapState().connected) { + + for(int bufferIterator = 0; bufferIterator < length; bufferIterator++) { int nextHead = (txBufferHead + 1) % txBufferSize; @@ -279,25 +252,27 @@ int size = txBufferedSize(); +#if CONFIG_ENABLED(MICROBIT_DBG) + SERIAL_DEBUG->printf("tx size: %d", size); +#endif + uint8_t temp[size]; memclr(&temp, size); circularCopy(txBuffer, txBufferSize, temp, txBufferTail, txBufferHead); - - if(mode == SYNC_SLEEP) - fiber_wake_on_event(MICROBIT_ID_NOTIFY, MICROBIT_UART_S_EVT_TX_EMPTY); - - ble.gattServer().write(txCharacteristic->getValueAttribute().getHandle(), temp, size); +#if CONFIG_ENABLED(MICROBIT_DBG) + for(int i = 0; i < size; i++) + SERIAL_DEBUG->printf("%c",temp[i]); +#endif - if(mode == SYNC_SLEEP) - schedule(); - else - break; + ble.gattServer().write(rxCharacteristic->getValueAttribute().getHandle(), temp, size); + } - ble.gattServer().areUpdatesEnabled(*txCharacteristic, &updatesEnabled); - } +#if CONFIG_ENABLED(MICROBIT_DBG) + SERIAL_DEBUG->printf("written: %d \r\n",bytesWritten); +#endif return bytesWritten; } @@ -306,24 +281,14 @@ * Copies characters into the buffer used for Transmitting to the central device. * * @param s the string to transmit - * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode - * gives a different behaviour: * - * ASYNC - Will copy as many characters as it can into the buffer for transmission, - * and return control to the user. - * - * SYNC_SPINWAIT - will return MICROBIT_INVALID_PARAMETER + * @return the number of characters copied into the buffer * - * SYNC_SLEEP - Will perform a cooperative blocking wait until all - * given characters have been received by the connected - * device. - * - * @return the number of characters written, or MICROBIT_NOT_SUPPORTED if there is - * no connected device, or the connected device has not enabled indications. + * @note no modes for sending are available at the moment, due to interrupt overhead. */ -int MicroBitUARTService::send(ManagedString s, MicroBitSerialMode mode) +int MicroBitUARTService::send(ManagedString s) { - return send((uint8_t *)s.toCharArray(), s.length(), mode); + return send((uint8_t *)s.toCharArray(), s.length()); } /**
--- a/source/core/MicroBitDevice.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/core/MicroBitDevice.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -67,12 +67,8 @@ */ bool ble_running() { - uint8_t t = 0; - -#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED) || CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) + uint8_t t; sd_softdevice_is_enabled(&t); -#endif - return t==1; }
--- a/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -348,23 +348,43 @@ shake.z = !shake.z; } - if (shakeDetected && shake.count < MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD && ++shake.count == MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD) - shake.shaken = 1; - - if (++shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_DAMPING) + // If we detected a zero crossing in this sample period, count this. + if (shakeDetected && shake.count < MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD) { - shake.timer = 0; - if (shake.count > 0) + shake.count++; + + if (shake.count == 1) + shake.timer = 0; + + if (shake.count == MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD) { - if(--shake.count == 0) - shake.shaken = 0; + shake.shaken = 1; + shake.timer = 0; + return MICROBIT_ACCELEROMETER_EVT_SHAKE; } } - // Shake events take the highest priority, as under high levels of change, other events - // are likely to be transient. - if (shake.shaken) - return MICROBIT_ACCELEROMETER_EVT_SHAKE; + // measure how long we have been detecting a SHAKE event. + if (shake.count > 0) + { + shake.timer++; + + // If we've issued a SHAKE event already, and sufficient time has assed, allow another SHAKE event to be issued. + if (shake.shaken && shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_RTX) + { + shake.shaken = 0; + shake.timer = 0; + shake.count = 0; + } + + // Decay our count of zero crossings over time. We don't want them to accumulate if the user performs slow moving motions. + else if (!shake.shaken && shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_DAMPING) + { + shake.timer = 0; + if (shake.count > 0) + shake.count--; + } + } if (instantaneousAccelerationSquared() < MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD) return MICROBIT_ACCELEROMETER_EVT_FREEFALL; @@ -433,6 +453,12 @@ // Determine what it looks like we're doing based on the latest sample... uint16_t g = instantaneousPosture(); + if (g == MICROBIT_ACCELEROMETER_EVT_SHAKE) + { + MicroBitEvent e(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_SHAKE); + return; + } + // Perform some low pass filtering to reduce jitter from any detected effects if (g == currentGesture) {
--- a/source/drivers/MicroBitPin.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/drivers/MicroBitPin.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -57,7 +57,6 @@ 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... @@ -160,7 +159,7 @@ if (!(status & (IO_STATUS_DIGITAL_IN | IO_STATUS_EVENT_ON_EDGE | IO_STATUS_EVENT_PULSE_ON_EDGE))) { disconnect(); - pin = new DigitalIn(name, (PinMode)pullMode); + pin = new DigitalIn(name,PullDown); status |= IO_STATUS_DIGITAL_IN; } @@ -170,25 +169,6 @@ 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! @@ -471,8 +451,6 @@ */ int MicroBitPin::setPull(PinMode pull) { - pullMode = pull; - if ((status & IO_STATUS_DIGITAL_IN)) { ((DigitalIn *)pin)->mode(pull); @@ -550,7 +528,7 @@ disconnect(); pin = new TimedInterruptIn(name); - ((TimedInterruptIn *)pin)->mode((PinMode)pullMode); + ((TimedInterruptIn *)pin)->mode(PullDown); ((TimedInterruptIn *)pin)->rise(this, &MicroBitPin::onRise); ((TimedInterruptIn *)pin)->fall(this, &MicroBitPin::onFall); }
--- a/source/drivers/MicroBitRadio.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/drivers/MicroBitRadio.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -59,6 +59,10 @@ extern "C" void RADIO_IRQHandler(void) { + // Move on to the next buffer, if possible. + MicroBitRadio::instance->queueRxBuf(); + NRF_RADIO->PACKETPTR = (uint32_t) MicroBitRadio::instance->getRxBuf(); + if(NRF_RADIO->EVENTS_READY) { NRF_RADIO->EVENTS_READY = 0; @@ -70,24 +74,12 @@ if(NRF_RADIO->EVENTS_END) { NRF_RADIO->EVENTS_END = 0; + if(NRF_RADIO->CRCSTATUS == 1) { uint8_t sample = NRF_RADIO->RSSISAMPLE; - // Associate this packet's rssi value with the data just - // transferred by DMA receive MicroBitRadio::instance->setRSSI(sample); - - // Now move on to the next buffer, if possible. - // The queued packet will get the rssi value set above. - MicroBitRadio::instance->queueRxBuf(); - - // Set the new buffer for DMA - NRF_RADIO->PACKETPTR = (uint32_t) MicroBitRadio::instance->getRxBuf(); - } - else - { - MicroBitRadio::instance->setRSSI(0); } // Start listening and wait for the END event
--- a/source/drivers/MicroBitSerial.cpp Wed Jul 13 12:18:43 2016 +0100 +++ b/source/drivers/MicroBitSerial.cpp Wed Jul 13 12:18:45 2016 +0100 @@ -57,9 +57,8 @@ */ MicroBitSerial::MicroBitSerial(PinName tx, PinName rx, uint8_t rxBufferSize, uint8_t txBufferSize) : RawSerial(tx,rx), delimeters() { - // + 1 so there is a usable buffer size, of the size the user requested. - this->rxBuffSize = rxBufferSize + 1; - this->txBuffSize = txBufferSize + 1; + this->rxBuffSize = rxBufferSize; + this->txBuffSize = txBufferSize; this->rxBuff = NULL; this->txBuff = NULL; @@ -546,7 +545,7 @@ return result; } - int c = getChar(mode); + char c = (char)getChar(mode); unlockRx(); @@ -835,6 +834,7 @@ detach(Serial::RxIrq); + serial_free(&_serial); serial_init(&_serial, tx, rx); attach(this, &MicroBitSerial::dataReceived, Serial::RxIrq); @@ -853,8 +853,6 @@ /** * Configures an event to be fired after "len" characters. * - * Will generate an event with the ID: MICROBIT_ID_SERIAL and the value MICROBIT_SERIAL_EVT_HEAD_MATCH. - * * @param len the number of characters to wait before triggering the event. * * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode @@ -887,9 +885,7 @@ /** * Configures an event to be fired on a match with one of the delimeters. * - * Will generate an event with the ID: MICROBIT_ID_SERIAL and the value MICROBIT_SERIAL_EVT_DELIM_MATCH. - * - * @param delimeters the characters to match received characters against e.g. ManagedString("\n") + * @param delimeters the characters to match received characters against e.g. ManagedString("\r\n") * * @param mode the selected mode, one of: ASYNC, SYNC_SPINWAIT, SYNC_SLEEP. Each mode * gives a different behaviour: @@ -961,8 +957,7 @@ lockRx(); - // + 1 so there is a usable buffer size, of the size the user requested. - this->rxBuffSize = size + 1; + this->rxBuffSize = size; int result = initialiseRx(); @@ -986,8 +981,7 @@ lockTx(); - // + 1 so there is a usable buffer size, of the size the user requested. - this->txBuffSize = size + 1; + this->txBuffSize = size; int result = initialiseTx();