Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIOI G60/Morgan65: use custom Bluetooth driver #20897

Merged
merged 1 commit into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -906,17 +906,19 @@ ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
OPT_DEFS += -DBLUETOOTH_ENABLE
NO_USB_STARTUP_CHECK := yes
COMMON_VPATH += $(DRIVER_PATH)/bluetooth
SRC += outputselect.c bluetooth.c
SRC += outputselect.c

ifeq ($(strip $(BLUETOOTH_DRIVER)), BluefruitLE)
OPT_DEFS += -DBLUETOOTH_BLUEFRUIT_LE -DHAL_USE_SPI=TRUE
SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c
SRC += $(DRIVER_PATH)/bluetooth/bluefruit_le.cpp
QUANTUM_LIB_SRC += analog.c
QUANTUM_LIB_SRC += spi_master.c
endif

ifeq ($(strip $(BLUETOOTH_DRIVER)), RN42)
OPT_DEFS += -DBLUETOOTH_RN42 -DHAL_USE_SERIAL=TRUE
SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c
SRC += $(DRIVER_PATH)/bluetooth/rn42.c
QUANTUM_LIB_SRC += uart.c
endif
Expand Down
2 changes: 1 addition & 1 deletion data/schemas/keyboard.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"properties": {
"driver": {
"type": "string",
"enum": ["BluefruitLE", "RN42"]
"enum": ["BluefruitLE", "RN42", "custom"]
}
}
},
Expand Down
87 changes: 25 additions & 62 deletions keyboards/bioi/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,17 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/pgmspace.h>
#include "report.h"
#include "host.h"
#include "host_driver.h"
#include "keyboard.h"
#include "action.h"
#include "led.h"

#include "sendchar.h"
#include "debug.h"
#ifdef SLEEP_LED_ENABLE
#include "sleep_led.h"
#endif
#include "suspend.h"

#include "usb_descriptor.h"
#include "lufa.h"
#include "quantum.h"
#include <util/atomic.h>

#include "print.h"

#include "bluetooth.h"
#include "ble.h"
#include "usart.h"
#include "progmem.h"
#include "wait.h"
#include "debug.h"
#include "usb_descriptor.h"
#include "report.h"

keyboard_config_t ble_config;

static uint8_t bluefruit_keyboard_leds = 0;

static void bluefruit_serial_send(uint8_t);

void send_str(const char *str)
Expand Down Expand Up @@ -89,30 +71,13 @@ static void bluefruit_serial_send(uint8_t data)
serial_send(data);
}

/*------------------------------------------------------------------*
* Host driver
*------------------------------------------------------------------*/

static uint8_t keyboard_leds(void);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_extra(report_extra_t *report);

host_driver_t bluefruit_driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_extra
};

host_driver_t null_driver = {};

static uint8_t keyboard_leds(void)
{
return bluefruit_keyboard_leds;
void bluetooth_init(void) {
usart_init();
}

static void send_keyboard(report_keyboard_t *report)
void bluetooth_task(void) {}

void bluetooth_send_keyboard(report_keyboard_t *report)
{
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_header();
Expand All @@ -136,7 +101,7 @@ static void send_keyboard(report_keyboard_t *report)
#endif
}

static void send_mouse(report_mouse_t *report)
void bluetooth_send_mouse(report_mouse_t *report)
{
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_header();
Expand Down Expand Up @@ -177,27 +142,25 @@ static void send_mouse(report_mouse_t *report)
#define CONSUMER2BLUEFRUIT(usage) \
(usage == AUDIO_MUTE ? 0x00e2 : (usage == AUDIO_VOL_UP ? 0x00e9 : (usage == AUDIO_VOL_DOWN ? 0x00ea : (usage == TRANSPORT_NEXT_TRACK ? 0x00b5 : (usage == TRANSPORT_PREV_TRACK ? 0x00b6 : (usage == TRANSPORT_STOP ? 0x00b7 : (usage == TRANSPORT_STOP_EJECT ? 0x00b8 : (usage == TRANSPORT_PLAY_PAUSE ? 0x00b1 : (usage == AL_CC_CONFIG ? 0x0183 : (usage == AL_EMAIL ? 0x018c : (usage == AL_CALCULATOR ? 0x0192 : (usage == AL_LOCAL_BROWSER ? 0x0196 : (usage == AC_SEARCH ? 0x021f : (usage == AC_HOME ? 0x0223 : (usage == AC_BACK ? 0x0224 : (usage == AC_FORWARD ? 0x0225 : (usage == AC_STOP ? 0x0226 : (usage == AC_REFRESH ? 0x0227 : (usage == AC_BOOKMARKS ? 0x022a : 0)))))))))))))))))))

static void send_extra(report_extra_t *report)
void bluetooth_send_consumer(uint16_t usage)
{
if (report->report_id == REPORT_ID_CONSUMER) {
uint16_t bitmap = CONSUMER2BLUEFRUIT(report->usage);
uint16_t bitmap = CONSUMER2BLUEFRUIT(usage);

#ifdef BLUEFRUIT_TRACE_SERIAL
dprintf("\nData: ");
debug_hex16(data);
dprintf("; bitmap: ");
debug_hex16(bitmap);
dprintf("\n");
bluefruit_trace_header();
dprintf("\nData: ");
debug_hex16(data);
dprintf("; bitmap: ");
debug_hex16(bitmap);
dprintf("\n");
bluefruit_trace_header();
#endif
send_str(PSTR("AT+BLEHIDCONTROLKEY=0x"));
send_bytes((bitmap >> 8) & 0xFF);
send_bytes(bitmap & 0xFF);
send_str(PSTR("\r\n"));
send_str(PSTR("AT+BLEHIDCONTROLKEY=0x"));
send_bytes((bitmap >> 8) & 0xFF);
send_bytes(bitmap & 0xFF);
send_str(PSTR("\r\n"));
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_footer();
bluefruit_trace_footer();
#endif
}
}

void usart_init(void)
Expand Down
6 changes: 0 additions & 6 deletions keyboards/bioi/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once

#include <stdbool.h>
#include "host_driver.h"
#include "host.h"


typedef union {
uint32_t raw;
Expand All @@ -28,9 +25,6 @@ typedef union {

extern keyboard_config_t ble_config;

extern host_driver_t bluefruit_driver;
extern host_driver_t null_driver;

void send_str(const char *str);
void usart_init(void);
void module_reset(void);
15 changes: 7 additions & 8 deletions keyboards/bioi/g60/rules.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# Processor frequency
F_CPU = 8000000

SRC += usart.c \
ble.c \
main.c

OPT_DEFS += -DPROTOCOL_BLE
OPT_DEFS += -DUART_RX1_BUFFER_SIZE=16 -DUART_TX1_BUFFER_SIZE=16
OPT_DEFS += -DUSART1_ENABLED

# Build Options
# change yes to no to disable
#
Expand All @@ -22,5 +14,12 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
AUDIO_ENABLE = no # Audio output
LTO_ENABLE = yes # Reduce firmware size
BLUETOOTH_ENABLE = yes
BLUETOOTH_DRIVER = custom

VIA_ENABLE = yes # VIA support should be enabled here due to the main() loop will be compiled first.

SRC += usart.c ble.c

OPT_DEFS += -DUART_RX1_BUFFER_SIZE=16 -DUART_TX1_BUFFER_SIZE=16
OPT_DEFS += -DUSART1_ENABLED
Loading