diff options
| author | Ryan <fauxpark@gmail.com> | 2021-10-09 02:15:20 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-08 16:15:20 +0100 |
| commit | db41a3426c594fccac149b99b810e207cd069d65 (patch) | |
| tree | 56237380cb3b3b83a4f9802d975a570843984f79 /drivers | |
| parent | 00fd4044334022b5bbace987f8ab94b72e9f49bc (diff) | |
| download | qmk_firmware-db41a3426c594fccac149b99b810e207cd069d65.tar.gz qmk_firmware-db41a3426c594fccac149b99b810e207cd069d65.zip | |
Improve Adafruit BLE configuration defines (#14749)
* Improve Adafruit BLE configuration defines
* Formatting
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/bluetooth/adafruit_ble.cpp | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/drivers/bluetooth/adafruit_ble.cpp b/drivers/bluetooth/adafruit_ble.cpp index 3f2cc3573..34a780e9a 100644 --- a/drivers/bluetooth/adafruit_ble.cpp +++ b/drivers/bluetooth/adafruit_ble.cpp | |||
| @@ -16,24 +16,22 @@ | |||
| 16 | // These are the pin assignments for the 32u4 boards. | 16 | // These are the pin assignments for the 32u4 boards. |
| 17 | // You may define them to something else in your config.h | 17 | // You may define them to something else in your config.h |
| 18 | // if yours is wired up differently. | 18 | // if yours is wired up differently. |
| 19 | #ifndef AdafruitBleResetPin | 19 | #ifndef ADAFRUIT_BLE_RST_PIN |
| 20 | # define AdafruitBleResetPin D4 | 20 | # define ADAFRUIT_BLE_RST_PIN D4 |
| 21 | #endif | 21 | #endif |
| 22 | 22 | ||
| 23 | #ifndef AdafruitBleCSPin | 23 | #ifndef ADAFRUIT_BLE_CS_PIN |
| 24 | # define AdafruitBleCSPin B4 | 24 | # define ADAFRUIT_BLE_CS_PIN B4 |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | #ifndef AdafruitBleIRQPin | 27 | #ifndef ADAFRUIT_BLE_IRQ_PIN |
| 28 | # define AdafruitBleIRQPin E6 | 28 | # define ADAFRUIT_BLE_IRQ_PIN E6 |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | #ifndef AdafruitBleSpiClockSpeed | 31 | #ifndef ADAFRUIT_BLE_SCK_DIVISOR |
| 32 | # define AdafruitBleSpiClockSpeed 4000000UL // SCK frequency | 32 | # define ADAFRUIT_BLE_SCK_DIVISOR 2 // 4MHz SCK/8MHz CPU, calculated for Feather 32U4 BLE |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | #define SCK_DIVISOR (F_CPU / AdafruitBleSpiClockSpeed) | ||
| 36 | |||
| 37 | #define SAMPLE_BATTERY | 35 | #define SAMPLE_BATTERY |
| 38 | #define ConnectionUpdateInterval 1000 /* milliseconds */ | 36 | #define ConnectionUpdateInterval 1000 /* milliseconds */ |
| 39 | 37 | ||
| @@ -145,7 +143,7 @@ static bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool ver | |||
| 145 | 143 | ||
| 146 | // Send a single SDEP packet | 144 | // Send a single SDEP packet |
| 147 | static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) { | 145 | static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) { |
| 148 | spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR); | 146 | spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR); |
| 149 | uint16_t timerStart = timer_read(); | 147 | uint16_t timerStart = timer_read(); |
| 150 | bool success = false; | 148 | bool success = false; |
| 151 | bool ready = false; | 149 | bool ready = false; |
| @@ -159,7 +157,7 @@ static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) { | |||
| 159 | // Release it and let it initialize | 157 | // Release it and let it initialize |
| 160 | spi_stop(); | 158 | spi_stop(); |
| 161 | wait_us(SdepBackOff); | 159 | wait_us(SdepBackOff); |
| 162 | spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR); | 160 | spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR); |
| 163 | } while (timer_elapsed(timerStart) < timeout); | 161 | } while (timer_elapsed(timerStart) < timeout); |
| 164 | 162 | ||
| 165 | if (ready) { | 163 | if (ready) { |
| @@ -192,7 +190,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) { | |||
| 192 | bool ready = false; | 190 | bool ready = false; |
| 193 | 191 | ||
| 194 | do { | 192 | do { |
| 195 | ready = readPin(AdafruitBleIRQPin); | 193 | ready = readPin(ADAFRUIT_BLE_IRQ_PIN); |
| 196 | if (ready) { | 194 | if (ready) { |
| 197 | break; | 195 | break; |
| 198 | } | 196 | } |
| @@ -200,7 +198,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) { | |||
| 200 | } while (timer_elapsed(timerStart) < timeout); | 198 | } while (timer_elapsed(timerStart) < timeout); |
| 201 | 199 | ||
| 202 | if (ready) { | 200 | if (ready) { |
| 203 | spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR); | 201 | spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR); |
| 204 | 202 | ||
| 205 | do { | 203 | do { |
| 206 | // Read the command type, waiting for the data to be ready | 204 | // Read the command type, waiting for the data to be ready |
| @@ -209,7 +207,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) { | |||
| 209 | // Release it and let it initialize | 207 | // Release it and let it initialize |
| 210 | spi_stop(); | 208 | spi_stop(); |
| 211 | wait_us(SdepBackOff); | 209 | wait_us(SdepBackOff); |
| 212 | spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR); | 210 | spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR); |
| 213 | continue; | 211 | continue; |
| 214 | } | 212 | } |
| 215 | 213 | ||
| @@ -235,7 +233,7 @@ static void resp_buf_read_one(bool greedy) { | |||
| 235 | return; | 233 | return; |
| 236 | } | 234 | } |
| 237 | 235 | ||
| 238 | if (readPin(AdafruitBleIRQPin)) { | 236 | if (readPin(ADAFRUIT_BLE_IRQ_PIN)) { |
| 239 | struct sdep_msg msg; | 237 | struct sdep_msg msg; |
| 240 | 238 | ||
| 241 | again: | 239 | again: |
| @@ -246,7 +244,7 @@ static void resp_buf_read_one(bool greedy) { | |||
| 246 | dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send)); | 244 | dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send)); |
| 247 | } | 245 | } |
| 248 | 246 | ||
| 249 | if (greedy && resp_buf.peek(last_send) && readPin(AdafruitBleIRQPin)) { | 247 | if (greedy && resp_buf.peek(last_send) && readPin(ADAFRUIT_BLE_IRQ_PIN)) { |
| 250 | goto again; | 248 | goto again; |
| 251 | } | 249 | } |
| 252 | } | 250 | } |
| @@ -297,16 +295,16 @@ static bool ble_init(void) { | |||
| 297 | state.configured = false; | 295 | state.configured = false; |
| 298 | state.is_connected = false; | 296 | state.is_connected = false; |
| 299 | 297 | ||
| 300 | setPinInput(AdafruitBleIRQPin); | 298 | setPinInput(ADAFRUIT_BLE_IRQ_PIN); |
| 301 | 299 | ||
| 302 | spi_init(); | 300 | spi_init(); |
| 303 | 301 | ||
| 304 | // Perform a hardware reset | 302 | // Perform a hardware reset |
| 305 | setPinOutput(AdafruitBleResetPin); | 303 | setPinOutput(ADAFRUIT_BLE_RST_PIN); |
| 306 | writePinHigh(AdafruitBleResetPin); | 304 | writePinHigh(ADAFRUIT_BLE_RST_PIN); |
| 307 | writePinLow(AdafruitBleResetPin); | 305 | writePinLow(ADAFRUIT_BLE_RST_PIN); |
| 308 | wait_ms(10); | 306 | wait_ms(10); |
| 309 | writePinHigh(AdafruitBleResetPin); | 307 | writePinHigh(ADAFRUIT_BLE_RST_PIN); |
| 310 | 308 | ||
| 311 | wait_ms(1000); // Give it a second to initialize | 309 | wait_ms(1000); // Give it a second to initialize |
| 312 | 310 | ||
| @@ -509,7 +507,7 @@ void adafruit_ble_task(void) { | |||
| 509 | resp_buf_read_one(true); | 507 | resp_buf_read_one(true); |
| 510 | send_buf_send_one(SdepShortTimeout); | 508 | send_buf_send_one(SdepShortTimeout); |
| 511 | 509 | ||
| 512 | if (resp_buf.empty() && (state.event_flags & UsingEvents) && readPin(AdafruitBleIRQPin)) { | 510 | if (resp_buf.empty() && (state.event_flags & UsingEvents) && readPin(ADAFRUIT_BLE_IRQ_PIN)) { |
| 513 | // Must be an event update | 511 | // Must be an event update |
| 514 | if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) { | 512 | if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) { |
| 515 | uint32_t mask = strtoul(resbuf, NULL, 16); | 513 | uint32_t mask = strtoul(resbuf, NULL, 16); |
