summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/lufa/lufa.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
-rw-r--r--tmk_core/protocol/lufa/lufa.c156
1 files changed, 56 insertions, 100 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index e3be96d93d..b4b03357a3 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -67,10 +67,10 @@ extern keymap_config_t keymap_config;
#ifdef BLUETOOTH_ENABLE
# include "outputselect.h"
-# ifdef MODULE_ADAFRUIT_BLE
-# include "adafruit_ble.h"
-# else
-# include "../serial.h"
+# ifdef BLUETOOTH_BLUEFRUIT_LE
+# include "bluefruit_le.h"
+# elif BLUETOOTH_RN42
+# include "rn42.h"
# endif
#endif
@@ -90,46 +90,6 @@ extern keymap_config_t keymap_config;
# include "joystick.h"
#endif
-// https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
-static inline uint16_t CONSUMER2RN42(uint16_t usage) {
- switch (usage) {
- case AC_HOME:
- return 0x0001;
- case AL_EMAIL:
- return 0x0002;
- case AC_SEARCH:
- return 0x0004;
- case AL_KEYBOARD_LAYOUT:
- return 0x0008;
- case AUDIO_VOL_UP:
- return 0x0010;
- case AUDIO_VOL_DOWN:
- return 0x0020;
- case AUDIO_MUTE:
- return 0x0040;
- case TRANSPORT_PLAY_PAUSE:
- return 0x0080;
- case TRANSPORT_NEXT_TRACK:
- return 0x0100;
- case TRANSPORT_PREV_TRACK:
- return 0x0200;
- case TRANSPORT_STOP:
- return 0x0400;
- case TRANSPORT_EJECT:
- return 0x0800;
- case TRANSPORT_FAST_FORWARD:
- return 0x1000;
- case TRANSPORT_REWIND:
- return 0x2000;
- case TRANSPORT_STOP_EJECT:
- return 0x4000;
- case AL_LOCAL_BROWSER:
- return 0x8000;
- default:
- return 0;
- }
-}
-
uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1;
@@ -296,7 +256,8 @@ static void Console_Task(void) {
}
// fill empty bank
- while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0);
+ while (Endpoint_IsReadWriteAllowed())
+ Endpoint_Write_8(0);
// flush sendchar packet
if (Endpoint_IsINReady()) {
@@ -336,7 +297,7 @@ void send_joystick_packet(joystick_t *joystick) {
joystick->axes[5],
# endif
},
-# endif // JOYSTICK_AXES_COUNT>0
+# endif // JOYSTICK_AXES_COUNT>0
# if JOYSTICK_BUTTON_COUNT > 0
.buttons = {
@@ -352,14 +313,15 @@ void send_joystick_packet(joystick_t *joystick) {
joystick->buttons[3],
# endif
}
-# endif // JOYSTICK_BUTTON_COUNT>0
+# endif // JOYSTICK_BUTTON_COUNT>0
};
/* Select the Joystick Report Endpoint */
Endpoint_SelectEndpoint(JOYSTICK_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */
- while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ while (timeout-- && !Endpoint_IsReadWriteAllowed())
+ _delay_us(40);
if (!Endpoint_IsReadWriteAllowed()) return;
/* Write Joystick Report Data */
@@ -454,9 +416,11 @@ void EVENT_USB_Device_WakeUp() {
#ifdef CONSOLE_ENABLE
static bool console_flush = false;
-# define CONSOLE_FLUSH_SET(b) \
- do { \
- ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { console_flush = b; } \
+# define CONSOLE_FLUSH_SET(b) \
+ do { \
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { \
+ console_flush = b; \
+ } \
} while (0)
/** \brief Event USB Device Start Of Frame
@@ -674,7 +638,9 @@ void EVENT_USB_Device_ControlRequest(void) {
*
* FIXME: Needs doc
*/
-static uint8_t keyboard_leds(void) { return keyboard_led_state; }
+static uint8_t keyboard_leds(void) {
+ return keyboard_led_state;
+}
/** \brief Send Keyboard
*
@@ -685,17 +651,10 @@ static void send_keyboard(report_keyboard_t *report) {
#ifdef BLUETOOTH_ENABLE
if (where_to_send() == OUTPUT_BLUETOOTH) {
-# ifdef MODULE_ADAFRUIT_BLE
- adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
-# elif MODULE_RN42
- serial_send(0xFD);
- serial_send(0x09);
- serial_send(0x01);
- serial_send(report->mods);
- serial_send(report->reserved);
- for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
- serial_send(report->keys[i]);
- }
+# ifdef BLUETOOTH_BLUEFRUIT_LE
+ bluefruit_le_send_keys(report->mods, report->keys, sizeof(report->keys));
+# elif BLUETOOTH_RN42
+ rn42_send_keyboard(report);
# endif
return;
}
@@ -712,7 +671,8 @@ static void send_keyboard(report_keyboard_t *report) {
#endif
Endpoint_SelectEndpoint(ep);
/* Check if write ready for a polling interval around 10ms */
- while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ while (timeout-- && !Endpoint_IsReadWriteAllowed())
+ _delay_us(40);
if (!Endpoint_IsReadWriteAllowed()) return;
/* If we're in Boot Protocol, don't send any report ID or other funky fields */
@@ -738,19 +698,11 @@ static void send_mouse(report_mouse_t *report) {
# ifdef BLUETOOTH_ENABLE
if (where_to_send() == OUTPUT_BLUETOOTH) {
-# ifdef MODULE_ADAFRUIT_BLE
+# ifdef BLUETOOTH_BLUEFRUIT_LE
// FIXME: mouse buttons
- adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
-# else
- serial_send(0xFD);
- serial_send(0x00);
- serial_send(0x03);
- serial_send(report->buttons);
- serial_send(report->x);
- serial_send(report->y);
- serial_send(report->v); // should try sending the wheel v here
- serial_send(report->h); // should try sending the wheel h here
- serial_send(0x00);
+ bluefruit_le_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
+# elif BLUETOOTH_RN42
+ rn42_send_mouse(report);
# endif
return;
}
@@ -760,7 +712,8 @@ static void send_mouse(report_mouse_t *report) {
Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */
- while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ while (timeout-- && !Endpoint_IsReadWriteAllowed())
+ _delay_us(40);
if (!Endpoint_IsReadWriteAllowed()) return;
/* Write Mouse Report Data */
@@ -780,7 +733,8 @@ static void send_report(void *report, size_t size) {
Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */
- while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ while (timeout-- && !Endpoint_IsReadWriteAllowed())
+ _delay_us(40);
if (!Endpoint_IsReadWriteAllowed()) return;
Endpoint_Write_Stream_LE(report, size, NULL);
@@ -818,18 +772,10 @@ static void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
# ifdef BLUETOOTH_ENABLE
if (where_to_send() == OUTPUT_BLUETOOTH) {
-# ifdef MODULE_ADAFRUIT_BLE
- adafruit_ble_send_consumer_key(data);
-# elif MODULE_RN42
- static uint16_t last_data = 0;
- if (data == last_data) return;
- last_data = data;
- uint16_t bitmap = CONSUMER2RN42(data);
- serial_send(0xFD);
- serial_send(0x03);
- serial_send(0x03);
- serial_send(bitmap & 0xFF);
- serial_send((bitmap >> 8) & 0xFF);
+# ifdef BLUETOOTH_BLUEFRUIT_LE
+ bluefruit_le_send_consumer_key(data);
+# elif BLUETOOTH_RN42
+ rn42_send_consumer(data);
# endif
return;
}
@@ -939,9 +885,13 @@ USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = {
// clang-format on
-void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); }
+void send_midi_packet(MIDI_EventPacket_t *event) {
+ MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event);
+}
-bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); }
+bool recv_midi_packet(MIDI_EventPacket_t *const event) {
+ return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event);
+}
#endif
@@ -997,7 +947,8 @@ void virtser_send(const uint8_t byte) {
return;
}
- while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ while (timeout-- && !Endpoint_IsReadWriteAllowed())
+ _delay_us(40);
Endpoint_Write_8(byte);
CDC_Device_Flush(&cdc_device);
@@ -1020,7 +971,8 @@ void send_digitizer(report_digitizer_t *report) {
Endpoint_SelectEndpoint(DIGITIZER_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */
- while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ while (timeout-- && !Endpoint_IsReadWriteAllowed())
+ _delay_us(40);
if (!Endpoint_IsReadWriteAllowed()) return;
Endpoint_Write_Stream_LE(report, sizeof(report_digitizer_t), NULL);
@@ -1076,8 +1028,8 @@ void protocol_pre_init(void) {
setup_usb();
sei();
-#if defined(MODULE_RN42)
- serial_init();
+#if defined(BLUETOOTH_RN42)
+ rn42_init();
#endif
/* wait for USB startup & debug output */
@@ -1096,7 +1048,9 @@ void protocol_pre_init(void) {
#endif
}
-void protocol_post_init(void) { host_set_driver(&lufa_driver); }
+void protocol_post_init(void) {
+ host_set_driver(&lufa_driver);
+}
void protocol_pre_task(void) {
#if !defined(NO_USB_STARTUP_CHECK)
@@ -1129,8 +1083,8 @@ void protocol_post_task(void) {
MIDI_Device_USBTask(&USB_MIDI_Interface);
#endif
-#ifdef MODULE_ADAFRUIT_BLE
- adafruit_ble_task();
+#ifdef BLUETOOTH_BLUEFRUIT_LE
+ bluefruit_le_task();
#endif
#ifdef VIRTSER_ENABLE
@@ -1147,4 +1101,6 @@ void protocol_post_task(void) {
#endif
}
-uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) { return get_usb_descriptor(wValue, wIndex, DescriptorAddress); }
+uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) {
+ return get_usb_descriptor(wValue, wIndex, DescriptorAddress);
+}