Hiroh Satoh / keyboard Featured

Dependencies:   BLE_API mbed-dev nRF51822

Committer:
cho45
Date:
Mon Aug 29 14:09:09 2016 +0000
Revision:
48:d6938de02f62
Parent:
47:5bf2ae8cc710
Child:
49:09ae6fb04a32
const

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cho45 42:2c3be8694896 1 /* BLE Keyboard Implementation for mbed
cho45 42:2c3be8694896 2 * Copyright (c) 2016 cho45 <cho45@lowreal.net>
cho45 0:be89b5fdea09 3 *
cho45 0:be89b5fdea09 4 * Licensed under the Apache License, Version 2.0 (the "License");
cho45 0:be89b5fdea09 5 * you may not use this file except in compliance with the License.
cho45 0:be89b5fdea09 6 * You may obtain a copy of the License at
cho45 0:be89b5fdea09 7 *
cho45 0:be89b5fdea09 8 * http://www.apache.org/licenses/LICENSE-2.0
cho45 0:be89b5fdea09 9 *
cho45 0:be89b5fdea09 10 * Unless required by applicable law or agreed to in writing, software
cho45 0:be89b5fdea09 11 * distributed under the License is distributed on an "AS IS" BASIS,
cho45 0:be89b5fdea09 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cho45 0:be89b5fdea09 13 * See the License for the specific language governing permissions and
cho45 0:be89b5fdea09 14 * limitations under the License.
cho45 0:be89b5fdea09 15 */
cho45 0:be89b5fdea09 16
cho45 30:f9ebc769118d 17 #include <cmath>
cho45 0:be89b5fdea09 18 #include "mbed.h"
cho45 6:f1c3ea8bc850 19
cho45 6:f1c3ea8bc850 20 #include "HIDController_BLE.h"
cho45 42:2c3be8694896 21 #include "KeyboardMatrixController.h"
cho45 42:2c3be8694896 22 #include "BatteryLevel.h"
cho45 42:2c3be8694896 23 #include "WatchDog.h"
cho45 4:54cb552e50c4 24
cho45 42:2c3be8694896 25 #include "keymap.h"
cho45 42:2c3be8694896 26 #include "config.h"
cho45 5:65d4e94735b6 27
cho45 42:2c3be8694896 28 RawSerial serial(USBTX, USBRX);
cho45 48:d6938de02f62 29
cho45 48:d6938de02f62 30 static I2C i2c(I2C_SDA0, I2C_SCL0);
cho45 48:d6938de02f62 31 static KeyboardMatrixController keyboardMatrixController(i2c);
cho45 48:d6938de02f62 32 static Keymap keymap;
cho45 15:70bf079d3ee1 33
cho45 15:70bf079d3ee1 34 // Interrupt from MCP23017
cho45 15:70bf079d3ee1 35 // (pulled-up and two MCP23017 is configured with open drain INT)
cho45 48:d6938de02f62 36 static InterruptIn keyboardInterruptIn(P0_5);
cho45 5:65d4e94735b6 37
cho45 37:4ce71fa47fc3 38 #define PIN_STATUS_LED P0_4
cho45 48:d6938de02f62 39 static DigitalOut statusLed(PIN_STATUS_LED, 0);
cho45 25:094df0d9e95b 40
cho45 43:4de3870b39cb 41 // timeout for status led and wakeup from sleep
cho45 48:d6938de02f62 42 static Timeout timeout;
cho45 35:6a7fddfa14cf 43
cho45 5:65d4e94735b6 44 // ROWS=8
cho45 5:65d4e94735b6 45 // COLS=16
cho45 5:65d4e94735b6 46 // 列ごとに1バイトにパックしてキーの状態を保持する
cho45 5:65d4e94735b6 47 static uint8_t keysA[COLS];
cho45 5:65d4e94735b6 48 static uint8_t keysB[COLS];
cho45 5:65d4e94735b6 49 static bool state = 0;
cho45 28:1f843a3daab0 50 #define is_pressed(keys, row, col) (!!(keys[col] & (1<<row)))
cho45 28:1f843a3daab0 51
cho45 9:d1daefbf1fbd 52 // delay for interrupt
cho45 23:b31957ce64e9 53 static volatile int8_t pollCount = 50;
cho45 5:65d4e94735b6 54
cho45 48:d6938de02f62 55 static void keyboardInterrupt() {
cho45 8:d684faf04c9a 56 // just for wakeup
cho45 33:6a2301a89e92 57 pollCount = 25;
cho45 2:c2e3f240640c 58 }
cho45 2:c2e3f240640c 59
cho45 48:d6938de02f62 60 static void powerOff() {
cho45 42:2c3be8694896 61 DEBUG_PRINTF("power off\r\n");
cho45 23:b31957ce64e9 62 NRF_POWER->SYSTEMOFF = 1;
cho45 23:b31957ce64e9 63 }
cho45 23:b31957ce64e9 64
cho45 48:d6938de02f62 65 static void tickerStatus() {
cho45 43:4de3870b39cb 66 statusLed = !statusLed;
cho45 26:78ee13f69ec3 67 }
cho45 26:78ee13f69ec3 68
cho45 35:6a7fddfa14cf 69 static bool updateStatudLedEnabled = false;
cho45 48:d6938de02f62 70 static void updateStatusLed() {
cho45 35:6a7fddfa14cf 71 switch (HIDController::status()) {
cho45 35:6a7fddfa14cf 72 case TIMEOUT:
cho45 38:115875b8cb6c 73 case DISCONNECTED:
cho45 38:115875b8cb6c 74 case CONNECTED:
cho45 38:115875b8cb6c 75 statusLed = 0;
cho45 38:115875b8cb6c 76 updateStatudLedEnabled = false;
cho45 38:115875b8cb6c 77 return;
cho45 35:6a7fddfa14cf 78 case ADVERTISING:
cho45 38:115875b8cb6c 79 case CONNECTING:
cho45 38:115875b8cb6c 80 statusLed = !statusLed;
cho45 38:115875b8cb6c 81 updateStatudLedEnabled = true;
cho45 38:115875b8cb6c 82 timeout.attach(updateStatusLed, statusLed ? 0.5 : 0.1);
cho45 38:115875b8cb6c 83 break;
cho45 35:6a7fddfa14cf 84 }
cho45 35:6a7fddfa14cf 85 }
cho45 35:6a7fddfa14cf 86
cho45 36:78c211da4eb0 87 static volatile bool keyIntervalInterrupt = false;
cho45 48:d6938de02f62 88 static void wakeupKeyIntervalSleep() {
cho45 36:78c211da4eb0 89 keyIntervalInterrupt = true;
cho45 30:f9ebc769118d 90 }
cho45 30:f9ebc769118d 91
cho45 38:115875b8cb6c 92 #define is_pressed(keys, row, col) (!!(keys[col] & (1<<row)))
cho45 35:6a7fddfa14cf 93
cho45 0:be89b5fdea09 94 int main(void) {
cho45 33:6a2301a89e92 95 {
cho45 48:d6938de02f62 96 const uint32_t reason = NRF_POWER->RESETREAS;
cho45 33:6a2301a89e92 97 NRF_POWER->RESETREAS = 0xffffffff; // clear reason
cho45 43:4de3870b39cb 98 // reset cause should be shown everytime
cho45 42:2c3be8694896 99 serial.printf("init [%x]\r\n", reason);
cho45 33:6a2301a89e92 100 }
cho45 43:4de3870b39cb 101
cho45 48:d6938de02f62 102 const float battery = BatteryLevel::readBatteryVoltage();
cho45 42:2c3be8694896 103 if (battery < BatteryLevel::BATTERY_LOW) {
cho45 37:4ce71fa47fc3 104 powerOff();
cho45 37:4ce71fa47fc3 105 }
cho45 43:4de3870b39cb 106
cho45 30:f9ebc769118d 107 // Enable Pin-reset on DEBUG mode
cho45 30:f9ebc769118d 108 // This makes possiable booting without normal mode easily.
cho45 30:f9ebc769118d 109 NRF_POWER->RESET = 1;
cho45 30:f9ebc769118d 110 // Disable Internal DC/DC step down converter surely
cho45 29:ec548c473d50 111 NRF_POWER->DCDCEN = 0;
cho45 30:f9ebc769118d 112 // Enable 2.1V brown out detection for avoiding over discharge of NiMH
cho45 29:ec548c473d50 113 NRF_POWER->POFCON =
cho45 29:ec548c473d50 114 POWER_POFCON_POF_Enabled << POWER_POFCON_POF_Pos |
cho45 29:ec548c473d50 115 POWER_POFCON_THRESHOLD_V21 << POWER_POFCON_THRESHOLD_Pos;
cho45 43:4de3870b39cb 116
cho45 4:54cb552e50c4 117 // mbed's Serial of TARGET_RBLAB_BLENANO sucks
cho45 30:f9ebc769118d 118 // DO NOT CONNECT RTS/CTS WITHOUT PRIOR CONSENT!
cho45 4:54cb552e50c4 119 NRF_UART0->PSELRTS = 0xFFFFFFFFUL;
cho45 4:54cb552e50c4 120 NRF_UART0->PSELCTS = 0xFFFFFFFFUL;
cho45 43:4de3870b39cb 121
cho45 37:4ce71fa47fc3 122 // Set LED Pin as HIGH Current mode
cho45 37:4ce71fa47fc3 123 NRF_GPIO->PIN_CNF[PIN_STATUS_LED] =
cho45 41:2b034f22b98f 124 (NRF_GPIO->PIN_CNF[PIN_STATUS_LED] & ~GPIO_PIN_CNF_DRIVE_Msk) |
cho45 41:2b034f22b98f 125 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos);
cho45 16:345eebc4f259 126
cho45 42:2c3be8694896 127 // Unsed pins.
cho45 42:2c3be8694896 128 // Set as PullUp for power consumption
cho45 42:2c3be8694896 129 // Use GPIO registers directly for saving ram
cho45 42:2c3be8694896 130 // Pad pinouts
cho45 42:2c3be8694896 131 /*
cho45 42:2c3be8694896 132 DigitalIn unused_p0_7(P0_7, PullUp);
cho45 42:2c3be8694896 133 DigitalIn unused_p0_6(P0_6, PullUp);
cho45 42:2c3be8694896 134 DigitalIn unused_p0_15(P0_15, PullUp);
cho45 42:2c3be8694896 135 DigitalIn unused_p0_29(P0_29, PullUp);
cho45 42:2c3be8694896 136 DigitalIn unused_p0_28(P0_28, PullUp);
cho45 42:2c3be8694896 137 */
cho45 42:2c3be8694896 138 NRF_GPIO->PIN_CNF[P0_7] =
cho45 42:2c3be8694896 139 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 140 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 141 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 142 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 143 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 144 NRF_GPIO->PIN_CNF[P0_6] =
cho45 42:2c3be8694896 145 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 146 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 147 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 148 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 149 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 150 NRF_GPIO->PIN_CNF[P0_15] =
cho45 42:2c3be8694896 151 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 152 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 153 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 154 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 155 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 156 NRF_GPIO->PIN_CNF[P0_29] =
cho45 42:2c3be8694896 157 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 158 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 159 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 160 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 161 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 162 NRF_GPIO->PIN_CNF[P0_28] =
cho45 42:2c3be8694896 163 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 164 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 165 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 166 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 167 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 168 /*
cho45 42:2c3be8694896 169 DigitalIn unused_p0_19(P0_19, PullUp); // This is on board LED which connected to VDD
cho45 42:2c3be8694896 170 DigitalIn unused_p0_11(P0_11, PullUp); // RXD
cho45 42:2c3be8694896 171 */
cho45 42:2c3be8694896 172 NRF_GPIO->PIN_CNF[P0_19] = // This is on board LED which connected to VDD
cho45 42:2c3be8694896 173 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 174 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 175 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 176 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 177 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 178 NRF_GPIO->PIN_CNF[P0_11] = // RXD
cho45 42:2c3be8694896 179 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
cho45 42:2c3be8694896 180 (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
cho45 42:2c3be8694896 181 (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
cho45 42:2c3be8694896 182 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
cho45 42:2c3be8694896 183 (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
cho45 42:2c3be8694896 184
cho45 32:6c0f43fda460 185 WatchDog::init();
cho45 42:2c3be8694896 186
cho45 42:2c3be8694896 187 // only 100kHz/250khz/400khz
cho45 36:78c211da4eb0 188 i2c.frequency(250000);
cho45 4:54cb552e50c4 189
cho45 43:4de3870b39cb 190 keyboardInterruptIn.mode(PullUp);
cho45 43:4de3870b39cb 191 keyboardInterruptIn.fall(keyboardInterrupt);
cho45 4:54cb552e50c4 192
cho45 5:65d4e94735b6 193 keyboardMatrixController.init();
cho45 33:6a2301a89e92 194 pollCount = 10;
cho45 4:54cb552e50c4 195
cho45 6:f1c3ea8bc850 196 HIDController::init();
cho45 43:4de3870b39cb 197
cho45 16:345eebc4f259 198 // STOP UART RX for power consumption
cho45 21:d801c32231b0 199 NRF_UART0->TASKS_STOPRX = 1;
cho45 43:4de3870b39cb 200
cho45 30:f9ebc769118d 201 // Disable TWI by default.
cho45 16:345eebc4f259 202 NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
cho45 43:4de3870b39cb 203
cho45 32:6c0f43fda460 204 while (1) {
cho45 32:6c0f43fda460 205 WatchDog::reload();
cho45 43:4de3870b39cb 206
cho45 23:b31957ce64e9 207 if (pollCount > 0) {
cho45 42:2c3be8694896 208 DEBUG_PRINTF("scan keys\r\n");
cho45 43:4de3870b39cb 209
cho45 33:6a2301a89e92 210 while (pollCount-- > 0) {
cho45 33:6a2301a89e92 211 WatchDog::reload();
cho45 43:4de3870b39cb 212
cho45 23:b31957ce64e9 213 uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
cho45 23:b31957ce64e9 214 uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
cho45 43:4de3870b39cb 215
cho45 23:b31957ce64e9 216 NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
cho45 23:b31957ce64e9 217 keyboardMatrixController.scanKeyboard(keysCurr);
cho45 23:b31957ce64e9 218 NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
cho45 43:4de3870b39cb 219
cho45 23:b31957ce64e9 220 bool queue = false;
cho45 43:4de3870b39cb 221
cho45 23:b31957ce64e9 222 for (int col = 0; col < COLS; col++) {
cho45 48:d6938de02f62 223 const uint8_t changed = keysPrev[col] ^ keysCurr[col];
cho45 23:b31957ce64e9 224 if (changed) queue = true;
cho45 23:b31957ce64e9 225 for (int row = 0; row < ROWS; row++) {
cho45 23:b31957ce64e9 226 if (changed & (1<<row)) {
cho45 23:b31957ce64e9 227 bool pressed = keysCurr[col] & (1<<row);
cho45 42:2c3be8694896 228 // DEBUG_KEYEVENT("changed: col=%d, row=%d / pressed=%d\r\n", col, row, pressed);
cho45 47:5bf2ae8cc710 229 keymap.execute(row, col, pressed);
cho45 23:b31957ce64e9 230 }
cho45 7:b9270a37345b 231 }
cho45 7:b9270a37345b 232 }
cho45 23:b31957ce64e9 233 state = !state;
cho45 43:4de3870b39cb 234
cho45 38:115875b8cb6c 235 if (HIDController::status() == DISCONNECTED ||
cho45 38:115875b8cb6c 236 HIDController::status() == TIMEOUT) {
cho45 43:4de3870b39cb 237
cho45 43:4de3870b39cb 238 if (
cho45 43:4de3870b39cb 239 is_pressed(keysCurr, 0, 0) && // left top 1
cho45 43:4de3870b39cb 240 is_pressed(keysCurr, 1, 0) && // left top 2
cho45 43:4de3870b39cb 241 is_pressed(keysCurr, 0, 15) // right top
cho45 43:4de3870b39cb 242 ) {
cho45 43:4de3870b39cb 243 DEBUG_PRINTF("re-init connection\r\n");
cho45 43:4de3870b39cb 244 HIDController::initializeConnection(true);
cho45 43:4de3870b39cb 245 } else {
cho45 43:4de3870b39cb 246 if (HIDController::status() == TIMEOUT) {
cho45 43:4de3870b39cb 247 DEBUG_PRINTF("wakeup\r\n");
cho45 43:4de3870b39cb 248 HIDController::initializeConnection(false);
cho45 43:4de3870b39cb 249 }
cho45 43:4de3870b39cb 250 }
cho45 38:115875b8cb6c 251 }
cho45 43:4de3870b39cb 252
cho45 23:b31957ce64e9 253 if (queue) HIDController::queueCurrentReportData();
cho45 43:4de3870b39cb 254
cho45 47:5bf2ae8cc710 255 // use timer to use wait 5ms
cho45 47:5bf2ae8cc710 256 keyIntervalInterrupt = false;
cho45 36:78c211da4eb0 257 timeout.attach_us(wakeupKeyIntervalSleep, 5000);
cho45 45:f4be69c936f6 258 while (!keyIntervalInterrupt) HIDController::waitForEvent();
cho45 7:b9270a37345b 259 }
cho45 8:d684faf04c9a 260 } else {
cho45 35:6a7fddfa14cf 261 if (!updateStatudLedEnabled) updateStatusLed();
cho45 43:4de3870b39cb 262
cho45 48:d6938de02f62 263 const float batteryVoltage = BatteryLevel::readBatteryVoltage();
cho45 48:d6938de02f62 264 const uint8_t batteryPercentage = BatteryLevel::readBatteryPercentage(batteryVoltage);
cho45 48:d6938de02f62 265 const bool isLowBattery = batteryVoltage < BatteryLevel::BATTERY_LOW;
cho45 37:4ce71fa47fc3 266
cho45 42:2c3be8694896 267 DEBUG_PRINTF("%d%% [%d:%s] %s\r\n",
cho45 37:4ce71fa47fc3 268 batteryPercentage,
cho45 37:4ce71fa47fc3 269 HIDController::status(),
cho45 37:4ce71fa47fc3 270 HIDController::statusString(),
cho45 39:b7889285c9ef 271 isLowBattery ? "LOWBAT" : "WFE"
cho45 37:4ce71fa47fc3 272 );
cho45 43:4de3870b39cb 273
cho45 37:4ce71fa47fc3 274 HIDController::updateBatteryLevel(batteryPercentage);
cho45 43:4de3870b39cb 275
cho45 37:4ce71fa47fc3 276 if (isLowBattery) {
cho45 37:4ce71fa47fc3 277 powerOff();
cho45 37:4ce71fa47fc3 278 }
cho45 45:f4be69c936f6 279
cho45 45:f4be69c936f6 280 if (HIDController::status() == DISCONNECTED) {
cho45 45:f4be69c936f6 281 HIDController::initializeConnection(false);
cho45 45:f4be69c936f6 282 }
cho45 43:4de3870b39cb 283
cho45 42:2c3be8694896 284 if (DEBUG_BLE_INTERRUPT) {
cho45 42:2c3be8694896 285 HIDController::waitForEvent();
cho45 42:2c3be8694896 286 } else {
cho45 42:2c3be8694896 287 // disable internal HFCLK RC Clock surely. It consume 1mA constantly
cho45 42:2c3be8694896 288 // TWI / SPI / UART must be disabled and boot without debug mode
cho45 42:2c3be8694896 289 while (NRF_UART0->EVENTS_TXDRDY != 1);
cho45 43:4de3870b39cb 290
cho45 48:d6938de02f62 291 const uint32_t tx = NRF_UART0->PSELTXD;
cho45 43:4de3870b39cb 292
cho45 42:2c3be8694896 293 NRF_UART0->TASKS_STOPTX = 1;
cho45 42:2c3be8694896 294 NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
cho45 43:4de3870b39cb 295
cho45 42:2c3be8694896 296 HIDController::waitForEvent();
cho45 43:4de3870b39cb 297
cho45 42:2c3be8694896 298 NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
cho45 42:2c3be8694896 299 NRF_UART0->TASKS_STARTTX = 1;
cho45 42:2c3be8694896 300 // dummy send to wakeup...
cho45 42:2c3be8694896 301 NRF_UART0->PSELTXD = 0xFFFFFFFF;
cho45 43:4de3870b39cb 302 NRF_UART0->EVENTS_TXDRDY = 0;
cho45 43:4de3870b39cb 303 NRF_UART0->TXD = 0;
cho45 43:4de3870b39cb 304 while (NRF_UART0->EVENTS_TXDRDY != 1);
cho45 42:2c3be8694896 305 NRF_UART0->PSELTXD = tx;
cho45 42:2c3be8694896 306 }
cho45 7:b9270a37345b 307 }
cho45 2:c2e3f240640c 308 }
cho45 43:4de3870b39cb 309 }