merge from master

This commit is contained in:
Jack Humbert 2021-02-07 21:01:30 -05:00
commit 3996250d81
11279 changed files with 499671 additions and 99678 deletions

View file

@ -11,6 +11,7 @@
#include "spi_master.h"
#include "wait.h"
#include "analog.h"
#include "progmem.h"
// These are the pin assignments for the 32u4 boards.
// You may define them to something else in your config.h
@ -36,10 +37,8 @@
#define SAMPLE_BATTERY
#define ConnectionUpdateInterval 1000 /* milliseconds */
#ifdef SAMPLE_BATTERY
# ifndef BATTERY_LEVEL_PIN
# define BATTERY_LEVEL_PIN 7
# endif
#ifndef BATTERY_LEVEL_PIN
# define BATTERY_LEVEL_PIN B5
#endif
static struct {
@ -118,15 +117,15 @@ enum sdep_type {
SdepResponse = 0x20,
SdepAlert = 0x40,
SdepError = 0x80,
SdepSlaveNotReady = 0xfe, // Try again later
SdepSlaveOverflow = 0xff, // You read more data than is available
SdepSlaveNotReady = 0xFE, // Try again later
SdepSlaveOverflow = 0xFF, // You read more data than is available
};
enum ble_cmd {
BleInitialize = 0xbeef,
BleAtWrapper = 0x0a00,
BleUartTx = 0x0a01,
BleUartRx = 0x0a02,
BleInitialize = 0xBEEF,
BleAtWrapper = 0x0A00,
BleUartTx = 0x0A01,
BleUartRx = 0x0A02,
};
enum ble_system_event_bits {
@ -176,7 +175,7 @@ static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
static inline void sdep_build_pkt(struct sdep_msg *msg, uint16_t command, const uint8_t *payload, uint8_t len, bool moredata) {
msg->type = SdepCommand;
msg->cmd_low = command & 0xff;
msg->cmd_low = command & 0xFF;
msg->cmd_high = command >> 8;
msg->len = len;
msg->more = (moredata && len == SdepMaxPayload) ? 1 : 0;
@ -407,11 +406,11 @@ static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbo
}
if (resp == NULL) {
auto now = timer_read();
uint16_t now = timer_read();
while (!resp_buf.enqueue(now)) {
resp_buf_read_one(false);
}
auto later = timer_read();
uint16_t later = timer_read();
if (TIMER_DIFF_16(later, now) > 0) {
dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now));
}
@ -422,7 +421,7 @@ static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbo
}
bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose) {
auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
char *cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
strcpy_P(cmdbuf, cmd);
return at_command(cmdbuf, resp, resplen, verbose);
}
@ -484,9 +483,9 @@ fail:
static void set_connected(bool connected) {
if (connected != state.is_connected) {
if (connected) {
print("****** BLE CONNECT!!!!\n");
dprint("BLE connected\n");
} else {
print("****** BLE DISCONNECT!!!!\n");
dprint("BLE disconnected\n");
}
state.is_connected = connected;
@ -556,7 +555,7 @@ void adafruit_ble_task(void) {
if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
state.last_battery_update = timer_read();
state.vbat = analogRead(BATTERY_LEVEL_PIN);
state.vbat = analogReadPin(BATTERY_LEVEL_PIN);
}
#endif
}
@ -612,7 +611,7 @@ static bool process_queue_item(struct queue_item *item, uint16_t timeout) {
}
}
bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) {
void adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) {
struct queue_item item;
bool didWait = false;
@ -638,30 +637,27 @@ bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nk
}
if (nkeys <= 6) {
return true;
return;
}
nkeys -= 6;
keys += 6;
}
return true;
}
bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration) {
void adafruit_ble_send_consumer_key(uint16_t usage) {
struct queue_item item;
item.queue_type = QTConsumer;
item.consumer = keycode;
item.consumer = usage;
while (!send_buf.enqueue(item)) {
send_buf_send_one();
}
return true;
}
#ifdef MOUSE_ENABLE
bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) {
void adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) {
struct queue_item item;
item.queue_type = QTMouseMove;
@ -674,7 +670,6 @@ bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan,
while (!send_buf.enqueue(item)) {
send_buf_send_one();
}
return true;
}
#endif

View file

@ -2,18 +2,18 @@
* Author: Wez Furlong, 2016
* Supports the Adafruit BLE board built around the nRF51822 chip.
*/
#pragma once
#ifdef MODULE_ADAFRUIT_BLE
# include <stdbool.h>
# include <stdint.h>
# include <string.h>
# include "config_common.h"
# include "progmem.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
# ifdef __cplusplus
#include "config_common.h"
#ifdef __cplusplus
extern "C" {
# endif
#endif
/* Instruct the module to enable HID keyboard support and reset */
extern bool adafruit_ble_enable_keyboard(void);
@ -34,18 +34,18 @@ extern void adafruit_ble_task(void);
* this set of keys.
* Also sends a key release indicator, so that the keys do not remain
* held down. */
extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
extern void adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
/* Send a consumer keycode, holding it down for the specified duration
/* Send a consumer usage.
* (milliseconds) */
extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration);
extern void adafruit_ble_send_consumer_key(uint16_t usage);
# ifdef MOUSE_ENABLE
#ifdef MOUSE_ENABLE
/* Send a mouse/wheel movement report.
* The parameters are signed and indicate positive of negative direction
* The parameters are signed and indicate positive or negative direction
* change. */
extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
# endif
extern void adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
#endif
/* Compute battery voltage by reading an analog pin.
* Returns the integer number of millivolts */
@ -54,8 +54,6 @@ extern uint32_t adafruit_ble_read_battery_voltage(void);
extern bool adafruit_ble_set_mode_leds(bool on);
extern bool adafruit_ble_set_power_level(int8_t level);
# ifdef __cplusplus
#ifdef __cplusplus
}
# endif
#endif // MODULE_ADAFRUIT_BLE
#endif

View file

@ -1,38 +0,0 @@
/*
Bluefruit Protocol for TMK firmware
Author: Benjamin Gould, 2013
Jack Humbert, 2015
Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 <stdint.h>
#include "report.h"
#include "print.h"
#include "debug.h"
#include "bluetooth.h"
void bluefruit_keyboard_print_report(report_keyboard_t *report) {
if (!debug_keyboard) return;
dprintf("keys: ");
for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
debug_hex8(report->keys[i]);
dprintf(" ");
}
dprintf(" mods: ");
debug_hex8(report->mods);
dprintf(" reserved: ");
debug_hex8(report->reserved);
dprintf("\n");
}
void bluefruit_serial_send(uint8_t data) { serial_send(data); }

View file

@ -1,48 +0,0 @@
/*
Bluefruit Protocol for TMK firmware
Author: Benjamin Gould, 2013
Jack Humbert, 2015
Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
#include "../serial.h"
void bluefruit_serial_send(uint8_t data);
/*
+-----------------+-------------------+-------+
| Consumer Key | Bit Map | Hex |
+-----------------+-------------------+-------+
| Home | 00000001 00000000 | 01 00 |
| KeyboardLayout | 00000010 00000000 | 02 00 |
| Search | 00000100 00000000 | 04 00 |
| Snapshot | 00001000 00000000 | 08 00 |
| VolumeUp | 00010000 00000000 | 10 00 |
| VolumeDown | 00100000 00000000 | 20 00 |
| Play/Pause | 01000000 00000000 | 40 00 |
| Fast Forward | 10000000 00000000 | 80 00 |
| Rewind | 00000000 00000001 | 00 01 |
| Scan Next Track | 00000000 00000010 | 00 02 |
| Scan Prev Track | 00000000 00000100 | 00 04 |
| Random Play | 00000000 00001000 | 00 08 |
| Stop | 00000000 00010000 | 00 10 |
+-------------------------------------+-------+
*/
#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
#define CONSUMER2RN42(usage) (usage == AUDIO_MUTE ? 0x0040 : (usage == AUDIO_VOL_UP ? 0x0010 : (usage == AUDIO_VOL_DOWN ? 0x0020 : (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : (usage == TRANSPORT_PREV_TRACK ? 0x0200 : (usage == TRANSPORT_STOP ? 0x0400 : (usage == TRANSPORT_STOP_EJECT ? 0x0800 : (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : (usage == AL_EMAIL ? 0x0200 : (usage == AL_LOCAL_BROWSER ? 0x8000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : 0))))))))))))
#endif

View file

@ -53,7 +53,6 @@
#include "lufa.h"
#include "quantum.h"
#include <util/atomic.h>
#include "outputselect.h"
#ifdef NKRO_ENABLE
# include "keycode_config.h"
@ -62,14 +61,15 @@ extern keymap_config_t keymap_config;
#endif
#ifdef AUDIO_ENABLE
# include <audio.h>
# include "audio.h"
#endif
#ifdef BLUETOOTH_ENABLE
# include "outputselect.h"
# ifdef MODULE_ADAFRUIT_BLE
# include "adafruit_ble.h"
# else
# include "bluetooth.h"
# include "../serial.h"
# endif
#endif
@ -89,10 +89,50 @@ 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;
static uint8_t keyboard_led_stats = 0;
static uint8_t keyboard_led_state = 0;
static report_keyboard_t keyboard_report_sent;
@ -107,30 +147,30 @@ host_driver_t lufa_driver = {
};
#ifdef VIRTSER_ENABLE
// clang-format off
USB_ClassInfo_CDC_Device_t cdc_device = {
.Config =
{
.ControlInterfaceNumber = CCI_INTERFACE,
.DataINEndpoint =
{
.Address = CDC_IN_EPADDR,
.Size = CDC_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint =
{
.Address = CDC_OUT_EPADDR,
.Size = CDC_EPSIZE,
.Banks = 1,
},
.NotificationEndpoint =
{
.Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1,
},
.Config = {
.ControlInterfaceNumber = CCI_INTERFACE,
.DataINEndpoint = {
.Address = (CDC_IN_EPNUM | ENDPOINT_DIR_IN),
.Size = CDC_EPSIZE,
.Banks = 1
},
.DataOUTEndpoint = {
.Address = (CDC_OUT_EPNUM | ENDPOINT_DIR_OUT),
.Size = CDC_EPSIZE,
.Banks = 1
},
.NotificationEndpoint = {
.Address = (CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN),
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1
}
}
};
// clang-format on
#endif
#ifdef RAW_ENABLE
@ -258,7 +298,7 @@ static void Console_Task(void) {
// fill empty bank
while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0);
// flash senchar packet
// flush sendchar packet
if (Endpoint_IsINReady()) {
Endpoint_ClearIN();
}
@ -276,39 +316,43 @@ void send_joystick_packet(joystick_t *joystick) {
joystick_report_t r = {
# if JOYSTICK_AXES_COUNT > 0
.axes = {joystick->axes[0],
.axes =
{
joystick->axes[0],
# if JOYSTICK_AXES_COUNT >= 2
joystick->axes[1],
joystick->axes[1],
# endif
# if JOYSTICK_AXES_COUNT >= 3
joystick->axes[2],
joystick->axes[2],
# endif
# if JOYSTICK_AXES_COUNT >= 4
joystick->axes[3],
joystick->axes[3],
# endif
# if JOYSTICK_AXES_COUNT >= 5
joystick->axes[4],
joystick->axes[4],
# endif
# if JOYSTICK_AXES_COUNT >= 6
joystick->axes[5],
joystick->axes[5],
# endif
},
},
# endif // JOYSTICK_AXES_COUNT>0
# if JOYSTICK_BUTTON_COUNT > 0
.buttons = {joystick->buttons[0],
.buttons =
{
joystick->buttons[0],
# if JOYSTICK_BUTTON_COUNT > 8
joystick->buttons[1],
joystick->buttons[1],
# endif
# if JOYSTICK_BUTTON_COUNT > 16
joystick->buttons[2],
joystick->buttons[2],
# endif
# if JOYSTICK_BUTTON_COUNT > 24
joystick->buttons[3],
joystick->buttons[3],
# endif
}
}
# endif // JOYSTICK_BUTTON_COUNT>0
};
@ -434,45 +478,51 @@ void EVENT_USB_Device_StartOfFrame(void) {
void EVENT_USB_Device_ConfigurationChanged(void) {
bool ConfigSuccess = true;
/* Setup Keyboard HID Report Endpoints */
#ifndef KEYBOARD_SHARED_EP
ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup keyboard report endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((KEYBOARD_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1);
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
/* Setup Mouse HID Report Endpoint */
ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup mouse report endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((MOUSE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1);
#endif
#ifdef SHARED_EP_ENABLE
/* Setup Shared HID Report Endpoint */
ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup shared report endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((SHARED_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, SHARED_EPSIZE, 1);
#endif
#ifdef RAW_ENABLE
/* Setup Raw HID Report Endpoints */
ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup raw HID endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
#endif
#ifdef CONSOLE_ENABLE
/* Setup Console HID Report Endpoints */
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup console endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
# if 0
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
# endif
#endif
#ifdef MIDI_ENABLE
ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup MIDI stream endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
#endif
#ifdef VIRTSER_ENABLE
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup virtual serial endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_BULK, CDC_EPSIZE, 1);
ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1);
#endif
#ifdef JOYSTICK_ENABLE
/* Setup joystick endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((JOYSTICK_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);
#endif
#ifdef JOYSTICK_ENABLE
ConfigSuccess &= ENDPOINT_CONFIG(JOYSTICK_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, JOYSTICK_EPSIZE, ENDPOINT_BANK_SINGLE);
@ -539,10 +589,10 @@ void EVENT_USB_Device_ControlRequest(void) {
uint8_t report_id = Endpoint_Read_8();
if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) {
keyboard_led_stats = Endpoint_Read_8();
keyboard_led_state = Endpoint_Read_8();
}
} else {
keyboard_led_stats = Endpoint_Read_8();
keyboard_led_state = Endpoint_Read_8();
}
Endpoint_ClearOUT();
@ -612,7 +662,7 @@ void EVENT_USB_Device_ControlRequest(void) {
*
* FIXME: Needs doc
*/
static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
static uint8_t keyboard_leds(void) { return keyboard_led_state; }
/** \brief Send Keyboard
*
@ -620,35 +670,29 @@ static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
*/
static void send_keyboard(report_keyboard_t *report) {
uint8_t timeout = 255;
uint8_t where = where_to_send();
#ifdef BLUETOOTH_ENABLE
uint8_t where = where_to_send();
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
# elif MODULE_RN42
bluefruit_serial_send(0xFD);
bluefruit_serial_send(0x09);
bluefruit_serial_send(0x01);
bluefruit_serial_send(report->mods);
bluefruit_serial_send(report->reserved);
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++) {
bluefruit_serial_send(report->keys[i]);
}
# else
bluefruit_serial_send(0xFD);
bluefruit_serial_send(report->mods);
bluefruit_serial_send(report->reserved);
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
bluefruit_serial_send(report->keys[i]);
serial_send(report->keys[i]);
}
# endif
}
#endif
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
return;
}
#endif
/* Select the Keyboard Report Endpoint */
uint8_t ep = KEYBOARD_IN_EPNUM;
@ -684,30 +728,31 @@ static void send_keyboard(report_keyboard_t *report) {
static void send_mouse(report_mouse_t *report) {
#ifdef MOUSE_ENABLE
uint8_t timeout = 255;
uint8_t where = where_to_send();
# ifdef BLUETOOTH_ENABLE
uint8_t where = where_to_send();
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
// FIXME: mouse buttons
adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
# else
bluefruit_serial_send(0xFD);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x03);
bluefruit_serial_send(report->buttons);
bluefruit_serial_send(report->x);
bluefruit_serial_send(report->y);
bluefruit_serial_send(report->v); // should try sending the wheel v here
bluefruit_serial_send(report->h); // should try sending the wheel h here
bluefruit_serial_send(0x00);
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);
# endif
}
# endif
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
return;
}
# endif
/* Select the Mouse Report Endpoint */
Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
@ -762,43 +807,29 @@ static void send_system(uint16_t data) {
*/
static void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
# ifdef BLUETOOTH_ENABLE
uint8_t where = where_to_send();
# ifdef BLUETOOTH_ENABLE
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
adafruit_ble_send_consumer_key(data, 0);
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);
bluefruit_serial_send(0xFD);
bluefruit_serial_send(0x03);
bluefruit_serial_send(0x03);
bluefruit_serial_send(bitmap & 0xFF);
bluefruit_serial_send((bitmap >> 8) & 0xFF);
# else
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;
uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
bluefruit_serial_send(0xFD);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x02);
bluefruit_serial_send((bitmap >> 8) & 0xFF);
bluefruit_serial_send(bitmap & 0xFF);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);
serial_send(0xFD);
serial_send(0x03);
serial_send(0x03);
serial_send(bitmap & 0xFF);
serial_send((bitmap >> 8) & 0xFF);
# endif
}
# endif
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
return;
}
# endif
send_extra(REPORT_ID_CONSUMER, data);
#endif
@ -875,25 +906,26 @@ ERROR_EXIT:
******************************************************************************/
#ifdef MIDI_ENABLE
// clang-format off
USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = {
.Config =
{
.StreamingInterfaceNumber = AS_INTERFACE,
.DataINEndpoint =
{
.Address = MIDI_STREAM_IN_EPADDR,
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint =
{
.Address = MIDI_STREAM_OUT_EPADDR,
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1,
},
.Config = {
.StreamingInterfaceNumber = AS_INTERFACE,
.DataINEndpoint = {
.Address = (MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN),
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1
},
.DataOUTEndpoint = {
.Address = (MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_OUT),
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1
}
}
};
// clang-format on
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); }
@ -1012,7 +1044,7 @@ int main(void) {
setup_usb();
sei();
#if defined(MODULE_ADAFRUIT_EZKEY) || defined(MODULE_RN42)
#if defined(MODULE_RN42)
serial_init();
#endif
@ -1075,6 +1107,10 @@ int main(void) {
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
// Run housekeeping
housekeeping_task_kb();
housekeeping_task_user();
}
}

View file

@ -36,8 +36,7 @@
this software.
*/
#ifndef _LUFA_H_
#define _LUFA_H_
#pragma once
#include <avr/io.h>
#include <avr/wdt.h>
@ -68,9 +67,3 @@ extern host_driver_t lufa_driver;
// The header and terminator are not stored to save a few bytes of precious ram
# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
#endif
#define ENDPOINT_BANK_SINGLE 1
#define ENDPOINT_BANK_DOUBLE 2
#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum), eptype, epsize, epbank)
#endif

View file

@ -12,8 +12,12 @@ 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 "lufa.h"
#include "outputselect.h"
#if defined(PROTOCOL_LUFA)
# include "lufa.h"
#endif
#ifdef MODULE_ADAFRUIT_BLE
# include "adafruit_ble.h"
#endif
@ -35,12 +39,18 @@ void set_output(uint8_t output) {
*/
__attribute__((weak)) void set_output_user(uint8_t output) {}
static bool is_usb_configured(void) {
#if defined(PROTOCOL_LUFA)
return USB_DeviceState == DEVICE_STATE_Configured;
#endif
}
/** \brief Auto Detect Output
*
* FIXME: Needs doc
*/
uint8_t auto_detect_output(void) {
if (USB_DeviceState == DEVICE_STATE_Configured) {
if (is_usb_configured()) {
return OUTPUT_USB;
}

View file

@ -12,6 +12,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
enum outputs {
OUTPUT_AUTO,
@ -37,4 +41,4 @@ enum outputs {
void set_output(uint8_t output);
void set_output_user(uint8_t output);
uint8_t auto_detect_output(void);
uint8_t where_to_send(void);
uint8_t where_to_send(void);