summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-10-09 02:15:20 +1100
committerGitHub <noreply@github.com>2021-10-08 16:15:20 +0100
commitdb41a3426c594fccac149b99b810e207cd069d65 (patch)
tree56237380cb3b3b83a4f9802d975a570843984f79
parent00fd4044334022b5bbace987f8ab94b72e9f49bc (diff)
Improve Adafruit BLE configuration defines (#14749)
* Improve Adafruit BLE configuration defines * Formatting
-rw-r--r--docs/feature_bluetooth.md6
-rw-r--r--drivers/bluetooth/adafruit_ble.cpp44
-rw-r--r--keyboards/dtisaac/dosa40rgb/config.h5
-rw-r--r--keyboards/dtisaac/dosa40rgb/keymaps/default/keymap.c4
-rw-r--r--keyboards/handwired/dactyl_manuform/5x6_2_5/config.h3
-rw-r--r--keyboards/handwired/prkl30/feather/config.h3
-rw-r--r--keyboards/handwired/pterodactyl/config.h4
-rw-r--r--keyboards/spaceman/pancake/rev1/feather/config.h4
-rw-r--r--keyboards/tokyokeyboard/alix40/config.h3
9 files changed, 26 insertions, 50 deletions
diff --git a/docs/feature_bluetooth.md b/docs/feature_bluetooth.md
index 1b6a825e7a..fdf19c1077 100644
--- a/docs/feature_bluetooth.md
+++ b/docs/feature_bluetooth.md
@@ -17,9 +17,9 @@ Not Supported Yet but possible:
### Adafruit BLE SPI Friend
Currently The only bluetooth chipset supported by QMK is the Adafruit Bluefruit SPI Friend. It's a Nordic nRF5182 based chip running Adafruit's custom firmware. Data is transmitted via Adafruit's SDEP over Hardware SPI. The [Feather 32u4 Bluefruit LE](https://www.adafruit.com/product/2829) is supported as it's an AVR mcu connected via SPI to the Nordic BLE chip with Adafruit firmware. If Building a custom board with the SPI friend it would be easiest to just use the pin selection that the 32u4 feather uses but you can change the pins in the config.h options with the following defines:
-* #define AdafruitBleResetPin D4
-* #define AdafruitBleCSPin B4
-* #define AdafruitBleIRQPin E6
+* `#define ADAFRUIT_BLE_RST_PIN D4`
+* `#define ADAFRUIT_BLE_CS_PIN B4`
+* `#define ADAFRUIT_BLE_IRQ_PIN E6`
A Bluefruit UART friend can be converted to an SPI friend, however this [requires](https://github.com/qmk/qmk_firmware/issues/2274) some reflashing and soldering directly to the MDBT40 chip.
diff --git a/drivers/bluetooth/adafruit_ble.cpp b/drivers/bluetooth/adafruit_ble.cpp
index 3f2cc35734..34a780e9a5 100644
--- a/drivers/bluetooth/adafruit_ble.cpp
+++ b/drivers/bluetooth/adafruit_ble.cpp
@@ -16,24 +16,22 @@
// These are the pin assignments for the 32u4 boards.
// You may define them to something else in your config.h
// if yours is wired up differently.
-#ifndef AdafruitBleResetPin
-# define AdafruitBleResetPin D4
+#ifndef ADAFRUIT_BLE_RST_PIN
+# define ADAFRUIT_BLE_RST_PIN D4
#endif
-#ifndef AdafruitBleCSPin
-# define AdafruitBleCSPin B4
+#ifndef ADAFRUIT_BLE_CS_PIN
+# define ADAFRUIT_BLE_CS_PIN B4
#endif
-#ifndef AdafruitBleIRQPin
-# define AdafruitBleIRQPin E6
+#ifndef ADAFRUIT_BLE_IRQ_PIN
+# define ADAFRUIT_BLE_IRQ_PIN E6
#endif
-#ifndef AdafruitBleSpiClockSpeed
-# define AdafruitBleSpiClockSpeed 4000000UL // SCK frequency
+#ifndef ADAFRUIT_BLE_SCK_DIVISOR
+# define ADAFRUIT_BLE_SCK_DIVISOR 2 // 4MHz SCK/8MHz CPU, calculated for Feather 32U4 BLE
#endif
-#define SCK_DIVISOR (F_CPU / AdafruitBleSpiClockSpeed)
-
#define SAMPLE_BATTERY
#define ConnectionUpdateInterval 1000 /* milliseconds */
@@ -145,7 +143,7 @@ static bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool ver
// Send a single SDEP packet
static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
- spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR);
+ spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR);
uint16_t timerStart = timer_read();
bool success = false;
bool ready = false;
@@ -159,7 +157,7 @@ static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
// Release it and let it initialize
spi_stop();
wait_us(SdepBackOff);
- spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR);
+ spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR);
} while (timer_elapsed(timerStart) < timeout);
if (ready) {
@@ -192,7 +190,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) {
bool ready = false;
do {
- ready = readPin(AdafruitBleIRQPin);
+ ready = readPin(ADAFRUIT_BLE_IRQ_PIN);
if (ready) {
break;
}
@@ -200,7 +198,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) {
} while (timer_elapsed(timerStart) < timeout);
if (ready) {
- spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR);
+ spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR);
do {
// 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) {
// Release it and let it initialize
spi_stop();
wait_us(SdepBackOff);
- spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR);
+ spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR);
continue;
}
@@ -235,7 +233,7 @@ static void resp_buf_read_one(bool greedy) {
return;
}
- if (readPin(AdafruitBleIRQPin)) {
+ if (readPin(ADAFRUIT_BLE_IRQ_PIN)) {
struct sdep_msg msg;
again:
@@ -246,7 +244,7 @@ static void resp_buf_read_one(bool greedy) {
dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send));
}
- if (greedy && resp_buf.peek(last_send) && readPin(AdafruitBleIRQPin)) {
+ if (greedy && resp_buf.peek(last_send) && readPin(ADAFRUIT_BLE_IRQ_PIN)) {
goto again;
}
}
@@ -297,16 +295,16 @@ static bool ble_init(void) {
state.configured = false;
state.is_connected = false;
- setPinInput(AdafruitBleIRQPin);
+ setPinInput(ADAFRUIT_BLE_IRQ_PIN);
spi_init();
// Perform a hardware reset
- setPinOutput(AdafruitBleResetPin);
- writePinHigh(AdafruitBleResetPin);
- writePinLow(AdafruitBleResetPin);
+ setPinOutput(ADAFRUIT_BLE_RST_PIN);
+ writePinHigh(ADAFRUIT_BLE_RST_PIN);
+ writePinLow(ADAFRUIT_BLE_RST_PIN);
wait_ms(10);
- writePinHigh(AdafruitBleResetPin);
+ writePinHigh(ADAFRUIT_BLE_RST_PIN);
wait_ms(1000); // Give it a second to initialize
@@ -509,7 +507,7 @@ void adafruit_ble_task(void) {
resp_buf_read_one(true);
send_buf_send_one(SdepShortTimeout);
- if (resp_buf.empty() && (state.event_flags & UsingEvents) && readPin(AdafruitBleIRQPin)) {
+ if (resp_buf.empty() && (state.event_flags & UsingEvents) && readPin(ADAFRUIT_BLE_IRQ_PIN)) {
// Must be an event update
if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) {
uint32_t mask = strtoul(resbuf, NULL, 16);
diff --git a/keyboards/dtisaac/dosa40rgb/config.h b/keyboards/dtisaac/dosa40rgb/config.h
index 52891c4aa5..0ed29bf941 100644
--- a/keyboards/dtisaac/dosa40rgb/config.h
+++ b/keyboards/dtisaac/dosa40rgb/config.h
@@ -30,11 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROWS 4
#define MATRIX_COLS 11
-/* AdafruitBle Pin */
-#define AdafruitBleResetPin D4
-#define AdafruitBleCSPin B4
-#define AdafruitBleIRQPin E6
-
/*
* Keyboard Matrix Assignments
*
diff --git a/keyboards/dtisaac/dosa40rgb/keymaps/default/keymap.c b/keyboards/dtisaac/dosa40rgb/keymaps/default/keymap.c
index c9bde4bb8d..e25bd59708 100644
--- a/keyboards/dtisaac/dosa40rgb/keymaps/default/keymap.c
+++ b/keyboards/dtisaac/dosa40rgb/keymaps/default/keymap.c
@@ -77,7 +77,7 @@ void rgb_matrix_indicators_user(void)
void sdep_send(const uint8_t *cmd, uint8_t len) {
- spi_start(AdafruitBleCSPin, false, 0, 2);
+ spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, 2);
uint8_t cnt = 200;
bool ready = false;
@@ -88,7 +88,7 @@ void sdep_send(const uint8_t *cmd, uint8_t len) {
}
spi_stop();
wait_us(25);
- spi_start(AdafruitBleCSPin, false, 0, 2);
+ spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, 2);
} while (cnt--);
if (ready) {
diff --git a/keyboards/handwired/dactyl_manuform/5x6_2_5/config.h b/keyboards/handwired/dactyl_manuform/5x6_2_5/config.h
index 79ea625d9e..cb147654ba 100644
--- a/keyboards/handwired/dactyl_manuform/5x6_2_5/config.h
+++ b/keyboards/handwired/dactyl_manuform/5x6_2_5/config.h
@@ -34,9 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// // right half adafruit feather
// #define MATRIX_COL_PINS { F1, F0, B1, B2, B3, D2 }
// #define MATRIX_ROW_PINS { D6, B7, B6, B5, D7, C6 }
-// #define AdafruitBleResetPin D4
-// #define AdafruitBleCSPin B4
-// #define AdafruitBleIRQPin E6
#define DIODE_DIRECTION COL2ROW
diff --git a/keyboards/handwired/prkl30/feather/config.h b/keyboards/handwired/prkl30/feather/config.h
index 6a9bce38cd..875b3d7401 100644
--- a/keyboards/handwired/prkl30/feather/config.h
+++ b/keyboards/handwired/prkl30/feather/config.h
@@ -35,9 +35,6 @@
#define ENCODERS_PAD_A { F7 }
#define ENCODERS_PAD_B { F6 }
#define ENCODER_RESOLUTION 4
-#define AdafruitBleResetPin D4
-#define AdafruitBleCSPin B4
-#define AdafruitBleIRQPin E6
#define UNUSED_PINS
/* RGB Light Configuration */
diff --git a/keyboards/handwired/pterodactyl/config.h b/keyboards/handwired/pterodactyl/config.h
index 9f5f1412b8..044fa12f78 100644
--- a/keyboards/handwired/pterodactyl/config.h
+++ b/keyboards/handwired/pterodactyl/config.h
@@ -60,7 +60,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 0
-
-#define AdafruitBleResetPin D4
-#define AdafruitBleCSPin B4
-#define AdafruitBleIRQPin E6
diff --git a/keyboards/spaceman/pancake/rev1/feather/config.h b/keyboards/spaceman/pancake/rev1/feather/config.h
index e72b25f3db..cb80721e46 100644
--- a/keyboards/spaceman/pancake/rev1/feather/config.h
+++ b/keyboards/spaceman/pancake/rev1/feather/config.h
@@ -21,8 +21,4 @@
#define MATRIX_COL_PINS { C7, D6, B7, B6, F0, D2, D3, F1, F4, F5, F6, F7 }
#define UNUSED_PINS
-#define AdafruitBleResetPin D4
-#define AdafruitBleCSPin B4
-#define AdafruitBleIRQPin E6
-
#define VIA_HAS_BROKEN_KEYCODES
diff --git a/keyboards/tokyokeyboard/alix40/config.h b/keyboards/tokyokeyboard/alix40/config.h
index 113412e95a..f4b4e6e5ab 100644
--- a/keyboards/tokyokeyboard/alix40/config.h
+++ b/keyboards/tokyokeyboard/alix40/config.h
@@ -65,9 +65,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define QMK_ESC_INPUT D7 // usually ROW
/* Bluetooth */
-#define AdafruitBleResetPin D4
-#define AdafruitBleCSPin B4
-#define AdafruitBleIRQPin E6
#define BATTERY_LEVEL_PIN B6
#define VIA_HAS_BROKEN_KEYCODES