Skip to content

Commit

Permalink
update support for adafruit bluefruit spi friend
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Rubin <[email protected]>
  • Loading branch information
joshuarubin committed May 12, 2020
1 parent 9616aa9 commit 3768aa6
Show file tree
Hide file tree
Showing 15 changed files with 1,333 additions and 26 deletions.
2 changes: 1 addition & 1 deletion quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ extern layer_state_t layer_state;
# include "wpm.h"
#endif

#ifdef BLUETOOTH_BATTERY_ENABLE
#ifdef BLUETOOTH_ENABLE
# include "bluetooth.h"
#endif

Expand Down
5 changes: 3 additions & 2 deletions tmk_core/protocol/lufa.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ ifeq ($(strip $(BLUETOOTH)), RN42)
endif

ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
LUFA_SRC += spi_master.c
LUFA_SRC += analog.c
LUFA_SRC += $(LUFA_DIR)/bluetooth.c
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/new.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/FIFO.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/Print.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/Stream.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/SPI.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/ATParser.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/BLE.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/BluefruitLE_SPI.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/BLEBattery.cpp
LUFA_SRC += $(LUFA_DIR)/adafruit_ble/qmk.cpp
endif
Expand Down
10 changes: 5 additions & 5 deletions tmk_core/protocol/lufa/adafruit_ble/ATParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <stdlib.h>
#include "ATParser.h"
#include "wait.h"
#include "print.h"
#include "debug.h"

#define lowByte(w) ((uint8_t)((w)&0xff))

Expand All @@ -59,7 +59,7 @@ ATParser::ATParser(void) {
*/
/******************************************************************************/
bool ATParser::waitForOK(void) {
if (_verbose) print("\n<- ");
if (_verbose) dprint("\n<- ");

// Use temp buffer to avoid overwrite returned result if any
char tempbuf[BLE_BUFSIZE + 1];
Expand Down Expand Up @@ -130,7 +130,7 @@ bool ATParser::send_arg_get_resp(int32_t* reply, uint8_t argcount, uint16_t argt

// parse integer response if required
if (reply) {
if (_verbose) print("\n<- ");
if (_verbose) dprint("\n<- ");
(*reply) = readline_parseInt();
}

Expand Down Expand Up @@ -251,8 +251,8 @@ uint16_t ATParser::readline(char* buf, uint16_t bufsize, uint16_t timeout, bool

// Print out if is verbose
if (_verbose && replyidx > 0) {
xprintf("%s", buf);
if (replyidx < bufsize) println();
dprintf("%s", buf);
if (replyidx < bufsize) dprintln();
}

return replyidx;
Expand Down
9 changes: 8 additions & 1 deletion tmk_core/protocol/lufa/adafruit_ble/BLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ BLE::BLE(void) {
_timeout = BLE_DEFAULT_TIMEOUT;

_reset_started_timestamp = 0;
_using_events = false;

_disconnect_callback = NULL;
_connect_callback = NULL;
Expand All @@ -90,7 +91,9 @@ void BLE::install_callback(bool enable, int8_t system_id) {

this->pprintln();

waitForOK();
if (waitForOK()) {
_using_events = true;
}

// switch back if necessary
if (current_mode == BLUEFRUIT_MODE_DATA) setMode(BLUEFRUIT_MODE_DATA);
Expand Down Expand Up @@ -261,6 +264,8 @@ bool BLE::isVersionAtLeast(const char* versionString) {
*/
/******************************************************************************/
void BLE::update(uint32_t period_ms) {
if (!_using_events) return;

static uint32_t tt = 0;

if (timer_elapsed32(tt) > period_ms) {
Expand Down Expand Up @@ -502,3 +507,5 @@ void BLE::setBleUartRxCallback(void (*fp)(char data[], uint16_t len)) {
this->_ble_uart_rx_callback = fp;
install_callback(fp != NULL, EVENT_SYSTEM_BLE_UART_RX);
}

bool BLE::usingEvents() { return _using_events; }
2 changes: 2 additions & 0 deletions tmk_core/protocol/lufa/adafruit_ble/BLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BLE : public ATParser {

uint8_t _physical_transport;
uint32_t _reset_started_timestamp;
bool _using_events;

public:
// Constructor
Expand All @@ -77,6 +78,7 @@ class BLE : public ATParser {

void info(void);
bool echo(bool enable);
bool usingEvents();

bool isConnected(void);
bool isVersionAtLeast(const char *versionString);
Expand Down
Loading

0 comments on commit 3768aa6

Please sign in to comment.