ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
Diff: HIDController_BLE.cpp
- Revision:
- 58:64df960619ce
- Parent:
- 57:ae521136842c
- Child:
- 59:2d6c0bff2151
--- a/HIDController_BLE.cpp Tue Aug 30 14:17:14 2016 +0000 +++ b/HIDController_BLE.cpp Tue Aug 30 14:44:24 2016 +0000 @@ -253,7 +253,29 @@ void HIDController::waitForEvent() { BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); keyboardService->processSend(); - ble.waitForEvent(); + if (DEBUG_BLE_INTERRUPT) { + ble.waitForEvent(); + } else { + // disable internal HFCLK RC Clock surely. It consume 1mA constantly + // TWI / SPI / UART must be disabled and boot without debug mode + while (NRF_UART0->EVENTS_TXDRDY != 1); + + const uint32_t tx = NRF_UART0->PSELTXD; + + NRF_UART0->TASKS_STOPTX = 1; + NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos); + + ble.waitForEvent(); + + NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos); + NRF_UART0->TASKS_STARTTX = 1; + // dummy send to wakeup... + NRF_UART0->PSELTXD = 0xFFFFFFFF; + NRF_UART0->EVENTS_TXDRDY = 0; + NRF_UART0->TXD = 0; + while (NRF_UART0->EVENTS_TXDRDY != 1); + NRF_UART0->PSELTXD = tx; + } } void HIDController::appendReportData(const uint8_t key) { @@ -276,9 +298,9 @@ } } -void HIDController::updateBatteryLevel(const uint8_t percentage) { +void HIDController::updateBatteryLevel(const uint8_t percentage, const uint16_t voltage) { if (!batteryService) return; - batteryService->updateBatteryLevel(percentage); + batteryService->updateBatteryLevel(percentage, voltage); } void HIDController::initializeConnection(const bool ignoreWhiteList = false) {