Skip to content

Commit

Permalink
console, virtser, raw_hid.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc committed Nov 30, 2024
1 parent 597d876 commit c89576e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 24 deletions.
2 changes: 1 addition & 1 deletion keyboards/annepro2/annepro2_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static host_driver_t ap2_ble_driver = {
.send_nkro = NULL,
.send_mouse = ap2_ble_mouse,
.send_extra = ap2_ble_extra,
#ifdef JOYSTICK_ENABLE
#ifdef JOYSTICK_ENABLE
.send_joystick = NULL,
#endif // JOYSTICK_ENABLE
#ifdef DIGITIZER_ENABLE
Expand Down
26 changes: 22 additions & 4 deletions tmk_core/protocol/chibios/chibios.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
*/

/* declarations */
extern void send_keyboard(report_keyboard_t *report);
extern void send_nkro(report_nkro_t *report);
extern void send_mouse(report_mouse_t *report);
extern void send_extra(report_extra_t *report);
extern void send_keyboard(report_keyboard_t *report);
extern void send_nkro(report_nkro_t *report);
extern void send_mouse(report_mouse_t *report);
extern void send_extra(report_extra_t *report);
#ifdef JOYSTICK_ENABLE
extern void send_joystick(report_joystick_t *report);
#endif // JOYSTICK_ENABLE
Expand All @@ -75,6 +75,15 @@ extern void send_digitizer(report_digitizer_t *report);
#ifdef PROGRAMMABLE_BUTTON_ENABLE
extern void send_programmable_button(report_programmable_button_t *report);
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
extern int8_t send_console(uint8_t c);
#endif // CONSOLE_ENABLE
#ifdef VIRTSER_ENABLE
extern void send_virtser(uint8_t c);
#endif // VIRTSER_ENABLE
#ifdef RAW_ENABLE
extern void send_raw_hid(uint8_t *data, uint8_t length);
#endif // RAW_ENABLE

/* host struct */
host_driver_t chibios_driver = {
Expand All @@ -97,6 +106,15 @@ host_driver_t chibios_driver = {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
.send_programmable_button = send_programmable_button,
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
.send_console = send_console,
#endif // CONSOLE_ENABLE
#ifdef VIRTSER_ENABLE
.send_virtser = send_virtser,
#endif // VIRTSER_ENABLE
#ifdef RAW_ENABLE
.send_raw_hid = send_raw_hid,
#endif // RAW_ENABLE
};

host_driver_t *host_usb_driver(void) {
Expand Down
6 changes: 3 additions & 3 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void send_digitizer(report_digitizer_t *report) {

#ifdef CONSOLE_ENABLE

int8_t sendchar(uint8_t c) {
int8_t send_console(uint8_t c) {
return (int8_t)send_report_buffered(USB_ENDPOINT_IN_CONSOLE, &c, sizeof(uint8_t));
}

Expand All @@ -523,7 +523,7 @@ void console_task(void) {
#endif /* CONSOLE_ENABLE */

#ifdef RAW_ENABLE
void raw_hid_send(uint8_t *data, uint8_t length) {
void send_raw_hid(uint8_t *data, uint8_t length) {
if (length != RAW_EPSIZE) {
return;
}
Expand Down Expand Up @@ -590,7 +590,7 @@ bool virtser_usb_request_cb(USBDriver *usbp) {

void virtser_init(void) {}

void virtser_send(const uint8_t byte) {
void send_virtser(const uint8_t byte) {
send_report_buffered(USB_ENDPOINT_IN_CDC_DATA, (void *)&byte, sizeof(byte));
}

Expand Down
36 changes: 36 additions & 0 deletions tmk_core/protocol/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,42 @@ void host_programmable_button_send(uint32_t data) {
}
#endif

#ifdef CONSOLE_ENABLE
int8_t host_console_send(uint8_t c) {
if (!driver || !driver->send_console) return -1;
return (*driver->send_console)(c);
}

// Original API
int8_t sendchar(uint8_t c) {
return host_console_send(c);
}
#endif // CONSOLE_ENABLE

#ifdef VIRTSER_ENABLE
void host_virtser_send(const uint8_t c) {
if (!driver || !driver->send_virtser) return;
(*driver->send_virtser)(c);
}

// Original API
void virtser_send(const uint8_t c) {
host_virtser_send(c);
}
#endif // VIRTSER_ENABLE

#ifdef RAW_ENABLE
void host_raw_hid_send(uint8_t *data, uint8_t length) {
if (!driver || !driver->send_raw_hid) return;
(*driver->send_raw_hid)(data, length);
}

// Original API
void raw_hid_send(uint8_t *data, uint8_t length) {
host_raw_hid_send(data, length);
}
#endif // RAW_ENABLE

uint16_t host_last_system_usage(void) {
return last_system_usage;
}
Expand Down
18 changes: 15 additions & 3 deletions tmk_core/protocol/host_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <stdint.h>
#include "report.h"
#ifdef MIDI_ENABLE
# include "midi.h"
#endif

typedef struct host_driver_t {
bool has_init_executed;
Expand All @@ -34,7 +31,22 @@ typedef struct host_driver_t {
void (*send_nkro)(report_nkro_t *);
void (*send_mouse)(report_mouse_t *);
void (*send_extra)(report_extra_t *);
#ifdef JOYSTICK_ENABLE
void (*send_joystick)(report_joystick_t *);
#endif // JOYSTICK_ENABLE
#ifdef DIGITIZER_ENABLE
void (*send_digitizer)(report_digitizer_t *);
#endif // DIGITIZER_ENABLE
#ifdef PROGRAMMABLE_BUTTON_ENABLE
void (*send_programmable_button)(report_programmable_button_t *);
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
int8_t (*send_console)(uint8_t);
#endif // CONSOLE_ENABLE
#ifdef VIRTSER_ENABLE
void (*send_virtser)(uint8_t);
#endif // VIRTSER_ENABLE
#ifdef RAW_ENABLE
void (*send_raw_hid)(uint8_t *, uint8_t);
#endif // RAW_ENABLE
} host_driver_t;
33 changes: 26 additions & 7 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
static report_keyboard_t keyboard_report_sent;

/* Host driver */
static void send_keyboard(report_keyboard_t *report);
static void send_nkro(report_nkro_t *report);
static void send_mouse(report_mouse_t *report);
static void send_extra(report_extra_t *report);
static void send_keyboard(report_keyboard_t *report);
static void send_nkro(report_nkro_t *report);
static void send_mouse(report_mouse_t *report);
static void send_extra(report_extra_t *report);
#ifdef JOYSTICK_ENABLE
static void send_joystick(report_joystick_t *report);
#endif // JOYSTICK_ENABLE
Expand All @@ -88,6 +88,15 @@ static void send_digitizer(report_digitizer_t *report);
#ifdef PROGRAMMABLE_BUTTON_ENABLE
static void send_programmable_button(report_programmable_button_t *report);
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
static int8_t send_console(uint8_t c);
#endif // CONSOLE_ENABLE
#ifdef VIRTSER_ENABLE
static void send_virtser(uint8_t c);
#endif // VIRTSER_ENABLE
#ifdef RAW_ENABLE
static void send_raw_hid(uint8_t *data, uint8_t length);
#endif // RAW_ENABLE

static host_driver_t lufa_driver = {
.has_init_executed = false,
Expand All @@ -109,6 +118,16 @@ static host_driver_t lufa_driver = {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
.send_programmable_button = send_programmable_button,
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
.send_console = send_console,
#endif // CONSOLE_ENABLE
#ifdef VIRTSER_ENABLE
.send_virtser = send_virtser,
#endif // VIRTSER_ENABLE
#ifdef RAW_ENABLE
.send_raw_hid = send_raw_hid,
#endif // RAW_ENABLE

};

host_driver_t *host_usb_driver(void) {
Expand Down Expand Up @@ -165,7 +184,7 @@ USB_ClassInfo_CDC_Device_t cdc_device = {
*
* FIXME: Needs doc
*/
void raw_hid_send(uint8_t *data, uint8_t length) {
void send_raw_hid(uint8_t *data, uint8_t length) {
if (length != RAW_EPSIZE) return;
send_report(RAW_IN_EPNUM, data, RAW_EPSIZE);
}
Expand Down Expand Up @@ -624,7 +643,7 @@ void send_digitizer(report_digitizer_t *report) {
*
* FIXME: Needs doc
*/
int8_t sendchar(uint8_t c) {
int8_t send_console(uint8_t c) {
// Do not wait if the previous write has timed_out.
// Because sendchar() is called so many times, waiting each call causes big lag.
// The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state.
Expand Down Expand Up @@ -756,7 +775,7 @@ void virtser_task(void) {
*
* FIXME: Needs doc
*/
void virtser_send(const uint8_t byte) {
void send_virtser(const uint8_t byte) {
uint8_t timeout = 255;
uint8_t ep = Endpoint_GetCurrentEndpoint();

Expand Down
27 changes: 21 additions & 6 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void send_report(uint8_t endpoint, void *report, size_t size) {
static uint8_t raw_output_buffer[RAW_BUFFER_SIZE];
static uint8_t raw_output_received_bytes = 0;

void raw_hid_send(uint8_t *data, uint8_t length) {
void send_raw_hid(uint8_t *data, uint8_t length) {
if (length != RAW_BUFFER_SIZE) {
return;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ void raw_hid_task(void) {
# define CONSOLE_BUFFER_SIZE 32
# define CONSOLE_EPSIZE 8

int8_t sendchar(uint8_t c) {
int8_t send_console(uint8_t c) {
rbuf_enqueue(c);
return 0;
}
Expand Down Expand Up @@ -213,10 +213,10 @@ void console_task(void) {
/*------------------------------------------------------------------*
* Host driver
*------------------------------------------------------------------*/
static void send_keyboard(report_keyboard_t *report);
static void send_nkro(report_nkro_t *report);
static void send_mouse(report_mouse_t *report);
static void send_extra(report_extra_t *report);
static void send_keyboard(report_keyboard_t *report);
static void send_nkro(report_nkro_t *report);
static void send_mouse(report_mouse_t *report);
static void send_extra(report_extra_t *report);
#ifdef JOYSTICK_ENABLE
static void send_joystick(report_joystick_t *report);
#endif // JOYSTICK_ENABLE
Expand All @@ -226,6 +226,12 @@ static void send_digitizer(report_digitizer_t *report);
#ifdef PROGRAMMABLE_BUTTON_ENABLE
static void send_programmable_button(report_programmable_button_t *report);
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
static int8_t send_console(uint8_t c);
#endif // CONSOLE_ENABLE
#ifdef RAW_ENABLE
static void send_raw_hid(uint8_t *data, uint8_t length);
#endif // RAW_ENABLE

static host_driver_t vusb_driver = {
.has_init_executed = false,
Expand All @@ -247,6 +253,15 @@ static host_driver_t vusb_driver = {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
.send_programmable_button = send_programmable_button,
#endif // PROGRAMMABLE_BUTTON_ENABLE
#ifdef CONSOLE_ENABLE
.send_console = send_console,
#endif // CONSOLE_ENABLE
#ifdef VIRTSER_ENABLE
.send_virtser = NULL, // unsupported
#endif // VIRTSER_ENABLE
#ifdef RAW_ENABLE
.send_raw_hid = send_raw_hid,
#endif // RAW_ENABLE
};

host_driver_t *host_usb_driver(void) {
Expand Down

0 comments on commit c89576e

Please sign in to comment.