Improve Adafruit BLE configuration defines (#14749)
* Improve Adafruit BLE configuration defines * Formatting
This commit is contained in:
parent
00fd404433
commit
db41a3426c
@ -17,9 +17,9 @@ Not Supported Yet but possible:
|
|||||||
|
|
||||||
### Adafruit BLE SPI Friend
|
### 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:
|
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 ADAFRUIT_BLE_RST_PIN D4`
|
||||||
* #define AdafruitBleCSPin B4
|
* `#define ADAFRUIT_BLE_CS_PIN B4`
|
||||||
* #define AdafruitBleIRQPin E6
|
* `#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.
|
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.
|
||||||
|
|
||||||
|
@ -16,24 +16,22 @@
|
|||||||
// These are the pin assignments for the 32u4 boards.
|
// These are the pin assignments for the 32u4 boards.
|
||||||
// You may define them to something else in your config.h
|
// You may define them to something else in your config.h
|
||||||
// if yours is wired up differently.
|
// if yours is wired up differently.
|
||||||
#ifndef AdafruitBleResetPin
|
#ifndef ADAFRUIT_BLE_RST_PIN
|
||||||
# define AdafruitBleResetPin D4
|
# define ADAFRUIT_BLE_RST_PIN D4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef AdafruitBleCSPin
|
#ifndef ADAFRUIT_BLE_CS_PIN
|
||||||
# define AdafruitBleCSPin B4
|
# define ADAFRUIT_BLE_CS_PIN B4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef AdafruitBleIRQPin
|
#ifndef ADAFRUIT_BLE_IRQ_PIN
|
||||||
# define AdafruitBleIRQPin E6
|
# define ADAFRUIT_BLE_IRQ_PIN E6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef AdafruitBleSpiClockSpeed
|
#ifndef ADAFRUIT_BLE_SCK_DIVISOR
|
||||||
# define AdafruitBleSpiClockSpeed 4000000UL // SCK frequency
|
# define ADAFRUIT_BLE_SCK_DIVISOR 2 // 4MHz SCK/8MHz CPU, calculated for Feather 32U4 BLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SCK_DIVISOR (F_CPU / AdafruitBleSpiClockSpeed)
|
|
||||||
|
|
||||||
#define SAMPLE_BATTERY
|
#define SAMPLE_BATTERY
|
||||||
#define ConnectionUpdateInterval 1000 /* milliseconds */
|
#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
|
// Send a single SDEP packet
|
||||||
static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
|
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();
|
uint16_t timerStart = timer_read();
|
||||||
bool success = false;
|
bool success = false;
|
||||||
bool ready = 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
|
// Release it and let it initialize
|
||||||
spi_stop();
|
spi_stop();
|
||||||
wait_us(SdepBackOff);
|
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);
|
} while (timer_elapsed(timerStart) < timeout);
|
||||||
|
|
||||||
if (ready) {
|
if (ready) {
|
||||||
@ -192,7 +190,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) {
|
|||||||
bool ready = false;
|
bool ready = false;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ready = readPin(AdafruitBleIRQPin);
|
ready = readPin(ADAFRUIT_BLE_IRQ_PIN);
|
||||||
if (ready) {
|
if (ready) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -200,7 +198,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) {
|
|||||||
} while (timer_elapsed(timerStart) < timeout);
|
} while (timer_elapsed(timerStart) < timeout);
|
||||||
|
|
||||||
if (ready) {
|
if (ready) {
|
||||||
spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR);
|
spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Read the command type, waiting for the data to be ready
|
// 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
|
// Release it and let it initialize
|
||||||
spi_stop();
|
spi_stop();
|
||||||
wait_us(SdepBackOff);
|
wait_us(SdepBackOff);
|
||||||
spi_start(AdafruitBleCSPin, false, 0, SCK_DIVISOR);
|
spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, ADAFRUIT_BLE_SCK_DIVISOR);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +233,7 @@ static void resp_buf_read_one(bool greedy) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readPin(AdafruitBleIRQPin)) {
|
if (readPin(ADAFRUIT_BLE_IRQ_PIN)) {
|
||||||
struct sdep_msg msg;
|
struct sdep_msg msg;
|
||||||
|
|
||||||
again:
|
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));
|
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;
|
goto again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,16 +295,16 @@ static bool ble_init(void) {
|
|||||||
state.configured = false;
|
state.configured = false;
|
||||||
state.is_connected = false;
|
state.is_connected = false;
|
||||||
|
|
||||||
setPinInput(AdafruitBleIRQPin);
|
setPinInput(ADAFRUIT_BLE_IRQ_PIN);
|
||||||
|
|
||||||
spi_init();
|
spi_init();
|
||||||
|
|
||||||
// Perform a hardware reset
|
// Perform a hardware reset
|
||||||
setPinOutput(AdafruitBleResetPin);
|
setPinOutput(ADAFRUIT_BLE_RST_PIN);
|
||||||
writePinHigh(AdafruitBleResetPin);
|
writePinHigh(ADAFRUIT_BLE_RST_PIN);
|
||||||
writePinLow(AdafruitBleResetPin);
|
writePinLow(ADAFRUIT_BLE_RST_PIN);
|
||||||
wait_ms(10);
|
wait_ms(10);
|
||||||
writePinHigh(AdafruitBleResetPin);
|
writePinHigh(ADAFRUIT_BLE_RST_PIN);
|
||||||
|
|
||||||
wait_ms(1000); // Give it a second to initialize
|
wait_ms(1000); // Give it a second to initialize
|
||||||
|
|
||||||
@ -509,7 +507,7 @@ void adafruit_ble_task(void) {
|
|||||||
resp_buf_read_one(true);
|
resp_buf_read_one(true);
|
||||||
send_buf_send_one(SdepShortTimeout);
|
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
|
// Must be an event update
|
||||||
if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) {
|
if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) {
|
||||||
uint32_t mask = strtoul(resbuf, NULL, 16);
|
uint32_t mask = strtoul(resbuf, NULL, 16);
|
||||||
|
@ -30,11 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define MATRIX_ROWS 4
|
#define MATRIX_ROWS 4
|
||||||
#define MATRIX_COLS 11
|
#define MATRIX_COLS 11
|
||||||
|
|
||||||
/* AdafruitBle Pin */
|
|
||||||
#define AdafruitBleResetPin D4
|
|
||||||
#define AdafruitBleCSPin B4
|
|
||||||
#define AdafruitBleIRQPin E6
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keyboard Matrix Assignments
|
* Keyboard Matrix Assignments
|
||||||
*
|
*
|
||||||
|
@ -77,7 +77,7 @@ void rgb_matrix_indicators_user(void)
|
|||||||
|
|
||||||
void sdep_send(const uint8_t *cmd, uint8_t len) {
|
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;
|
uint8_t cnt = 200;
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ void sdep_send(const uint8_t *cmd, uint8_t len) {
|
|||||||
}
|
}
|
||||||
spi_stop();
|
spi_stop();
|
||||||
wait_us(25);
|
wait_us(25);
|
||||||
spi_start(AdafruitBleCSPin, false, 0, 2);
|
spi_start(ADAFRUIT_BLE_CS_PIN, false, 0, 2);
|
||||||
} while (cnt--);
|
} while (cnt--);
|
||||||
|
|
||||||
if (ready) {
|
if (ready) {
|
||||||
|
@ -34,9 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
// // right half adafruit feather
|
// // right half adafruit feather
|
||||||
// #define MATRIX_COL_PINS { F1, F0, B1, B2, B3, D2 }
|
// #define MATRIX_COL_PINS { F1, F0, B1, B2, B3, D2 }
|
||||||
// #define MATRIX_ROW_PINS { D6, B7, B6, B5, D7, C6 }
|
// #define MATRIX_ROW_PINS { D6, B7, B6, B5, D7, C6 }
|
||||||
// #define AdafruitBleResetPin D4
|
|
||||||
// #define AdafruitBleCSPin B4
|
|
||||||
// #define AdafruitBleIRQPin E6
|
|
||||||
|
|
||||||
#define DIODE_DIRECTION COL2ROW
|
#define DIODE_DIRECTION COL2ROW
|
||||||
|
|
||||||
|
@ -35,9 +35,6 @@
|
|||||||
#define ENCODERS_PAD_A { F7 }
|
#define ENCODERS_PAD_A { F7 }
|
||||||
#define ENCODERS_PAD_B { F6 }
|
#define ENCODERS_PAD_B { F6 }
|
||||||
#define ENCODER_RESOLUTION 4
|
#define ENCODER_RESOLUTION 4
|
||||||
#define AdafruitBleResetPin D4
|
|
||||||
#define AdafruitBleCSPin B4
|
|
||||||
#define AdafruitBleIRQPin E6
|
|
||||||
#define UNUSED_PINS
|
#define UNUSED_PINS
|
||||||
|
|
||||||
/* RGB Light Configuration */
|
/* RGB Light Configuration */
|
||||||
|
@ -60,7 +60,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
/* Set 0 if debouncing isn't needed */
|
/* Set 0 if debouncing isn't needed */
|
||||||
#define DEBOUNCE 0
|
#define DEBOUNCE 0
|
||||||
|
|
||||||
#define AdafruitBleResetPin D4
|
|
||||||
#define AdafruitBleCSPin B4
|
|
||||||
#define AdafruitBleIRQPin E6
|
|
||||||
|
@ -21,8 +21,4 @@
|
|||||||
#define MATRIX_COL_PINS { C7, D6, B7, B6, F0, D2, D3, F1, F4, F5, F6, F7 }
|
#define MATRIX_COL_PINS { C7, D6, B7, B6, F0, D2, D3, F1, F4, F5, F6, F7 }
|
||||||
#define UNUSED_PINS
|
#define UNUSED_PINS
|
||||||
|
|
||||||
#define AdafruitBleResetPin D4
|
|
||||||
#define AdafruitBleCSPin B4
|
|
||||||
#define AdafruitBleIRQPin E6
|
|
||||||
|
|
||||||
#define VIA_HAS_BROKEN_KEYCODES
|
#define VIA_HAS_BROKEN_KEYCODES
|
||||||
|
@ -65,9 +65,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define QMK_ESC_INPUT D7 // usually ROW
|
#define QMK_ESC_INPUT D7 // usually ROW
|
||||||
|
|
||||||
/* Bluetooth */
|
/* Bluetooth */
|
||||||
#define AdafruitBleResetPin D4
|
|
||||||
#define AdafruitBleCSPin B4
|
|
||||||
#define AdafruitBleIRQPin E6
|
|
||||||
#define BATTERY_LEVEL_PIN B6
|
#define BATTERY_LEVEL_PIN B6
|
||||||
|
|
||||||
#define VIA_HAS_BROKEN_KEYCODES
|
#define VIA_HAS_BROKEN_KEYCODES
|
||||||
|
Loading…
Reference in New Issue
Block a user