Refactor more host code (programmable button & digitizer) (#18565)
This commit is contained in:
parent
3168a3c883
commit
09d3e27710
|
@ -59,11 +59,9 @@ uint8_t keyboard_leds(void);
|
||||||
void send_keyboard(report_keyboard_t *report);
|
void send_keyboard(report_keyboard_t *report);
|
||||||
void send_mouse(report_mouse_t *report);
|
void send_mouse(report_mouse_t *report);
|
||||||
void send_extra(uint8_t report_id, uint16_t data);
|
void send_extra(uint8_t report_id, uint16_t data);
|
||||||
void send_programmable_button(uint32_t data);
|
|
||||||
void send_digitizer(report_digitizer_t *report);
|
|
||||||
|
|
||||||
/* host struct */
|
/* host struct */
|
||||||
host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra, send_programmable_button};
|
host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
|
||||||
|
|
||||||
#ifdef VIRTSER_ENABLE
|
#ifdef VIRTSER_ENABLE
|
||||||
void virtser_task(void);
|
void virtser_task(void);
|
||||||
|
|
|
@ -970,7 +970,7 @@ void send_extra(uint8_t report_id, uint16_t data) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_programmable_button(uint32_t data) {
|
void send_programmable_button(report_programmable_button_t *report) {
|
||||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||||
osalSysLock();
|
osalSysLock();
|
||||||
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
|
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
|
||||||
|
@ -988,13 +988,8 @@ void send_programmable_button(uint32_t data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static report_programmable_button_t report = {
|
|
||||||
.report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
|
|
||||||
};
|
|
||||||
|
|
||||||
report.usage = data;
|
usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(report_programmable_button_t));
|
||||||
|
|
||||||
usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report));
|
|
||||||
osalSysUnlock();
|
osalSysUnlock();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
//#include <avr/interrupt.h>
|
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "digitizer.h"
|
|
||||||
|
#ifdef DIGITIZER_ENABLE
|
||||||
|
# include "digitizer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef JOYSTICK_ENABLE
|
#ifdef JOYSTICK_ENABLE
|
||||||
# include "joystick.h"
|
# include "joystick.h"
|
||||||
|
@ -39,9 +41,8 @@ extern keymap_config_t keymap_config;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static host_driver_t *driver;
|
static host_driver_t *driver;
|
||||||
static uint16_t last_system_report = 0;
|
static uint16_t last_system_report = 0;
|
||||||
static uint16_t last_consumer_report = 0;
|
static uint16_t last_consumer_report = 0;
|
||||||
static uint32_t last_programmable_button_report = 0;
|
|
||||||
|
|
||||||
void host_set_driver(host_driver_t *d) {
|
void host_set_driver(host_driver_t *d) {
|
||||||
driver = d;
|
driver = d;
|
||||||
|
@ -200,13 +201,12 @@ void host_joystick_send(joystick_t *joystick) {
|
||||||
|
|
||||||
__attribute__((weak)) void send_joystick(report_joystick_t *report) {}
|
__attribute__((weak)) void send_joystick(report_joystick_t *report) {}
|
||||||
|
|
||||||
|
#ifdef DIGITIZER_ENABLE
|
||||||
void host_digitizer_send(digitizer_t *digitizer) {
|
void host_digitizer_send(digitizer_t *digitizer) {
|
||||||
if (!driver) return;
|
|
||||||
|
|
||||||
report_digitizer_t report = {
|
report_digitizer_t report = {
|
||||||
#ifdef DIGITIZER_SHARED_EP
|
# ifdef DIGITIZER_SHARED_EP
|
||||||
.report_id = REPORT_ID_DIGITIZER,
|
.report_id = REPORT_ID_DIGITIZER,
|
||||||
#endif
|
# endif
|
||||||
.tip = digitizer->tipswitch & 0x1,
|
.tip = digitizer->tipswitch & 0x1,
|
||||||
.inrange = digitizer->inrange & 0x1,
|
.inrange = digitizer->inrange & 0x1,
|
||||||
.x = (uint16_t)(digitizer->x * 0x7FFF),
|
.x = (uint16_t)(digitizer->x * 0x7FFF),
|
||||||
|
@ -215,16 +215,22 @@ void host_digitizer_send(digitizer_t *digitizer) {
|
||||||
|
|
||||||
send_digitizer(&report);
|
send_digitizer(&report);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
__attribute__((weak)) void send_digitizer(report_digitizer_t *report) {}
|
__attribute__((weak)) void send_digitizer(report_digitizer_t *report) {}
|
||||||
|
|
||||||
void host_programmable_button_send(uint32_t report) {
|
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||||
if (report == last_programmable_button_report) return;
|
void host_programmable_button_send(uint32_t data) {
|
||||||
last_programmable_button_report = report;
|
report_programmable_button_t report = {
|
||||||
|
.report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
|
||||||
|
.usage = data,
|
||||||
|
};
|
||||||
|
|
||||||
if (!driver) return;
|
send_programmable_button(&report);
|
||||||
(*driver->send_programmable_button)(report);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__attribute__((weak)) void send_programmable_button(report_programmable_button_t *report) {}
|
||||||
|
|
||||||
uint16_t host_last_system_report(void) {
|
uint16_t host_last_system_report(void) {
|
||||||
return last_system_report;
|
return last_system_report;
|
||||||
|
@ -233,7 +239,3 @@ uint16_t host_last_system_report(void) {
|
||||||
uint16_t host_last_consumer_report(void) {
|
uint16_t host_last_consumer_report(void) {
|
||||||
return last_consumer_report;
|
return last_consumer_report;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t host_last_programmable_button_report(void) {
|
|
||||||
return last_programmable_button_report;
|
|
||||||
}
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ void host_programmable_button_send(uint32_t data);
|
||||||
|
|
||||||
uint16_t host_last_system_report(void);
|
uint16_t host_last_system_report(void);
|
||||||
uint16_t host_last_consumer_report(void);
|
uint16_t host_last_consumer_report(void);
|
||||||
uint32_t host_last_programmable_button_report(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ typedef struct {
|
||||||
void (*send_keyboard)(report_keyboard_t *);
|
void (*send_keyboard)(report_keyboard_t *);
|
||||||
void (*send_mouse)(report_mouse_t *);
|
void (*send_mouse)(report_mouse_t *);
|
||||||
void (*send_extra)(uint8_t, uint16_t);
|
void (*send_extra)(uint8_t, uint16_t);
|
||||||
void (*send_programmable_button)(uint32_t);
|
|
||||||
} host_driver_t;
|
} host_driver_t;
|
||||||
|
|
||||||
void send_joystick(report_joystick_t *report);
|
void send_joystick(report_joystick_t *report);
|
||||||
void send_digitizer(report_digitizer_t *report);
|
void send_digitizer(report_digitizer_t *report);
|
||||||
|
void send_programmable_button(report_programmable_button_t *report);
|
||||||
|
|
|
@ -61,10 +61,6 @@
|
||||||
extern keymap_config_t keymap_config;
|
extern keymap_config_t keymap_config;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AUDIO_ENABLE
|
|
||||||
# include "audio.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VIRTSER_ENABLE
|
#ifdef VIRTSER_ENABLE
|
||||||
# include "virtser.h"
|
# include "virtser.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,8 +85,7 @@ static uint8_t keyboard_leds(void);
|
||||||
static void send_keyboard(report_keyboard_t *report);
|
static void send_keyboard(report_keyboard_t *report);
|
||||||
static void send_mouse(report_mouse_t *report);
|
static void send_mouse(report_mouse_t *report);
|
||||||
static void send_extra(uint8_t report_id, uint16_t data);
|
static void send_extra(uint8_t report_id, uint16_t data);
|
||||||
static void send_programmable_button(uint32_t data);
|
host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
|
||||||
host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra, send_programmable_button};
|
|
||||||
|
|
||||||
#ifdef VIRTSER_ENABLE
|
#ifdef VIRTSER_ENABLE
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -676,11 +671,9 @@ static void send_extra(uint8_t report_id, uint16_t data) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_programmable_button(uint32_t data) {
|
void send_programmable_button(report_programmable_button_t *report) {
|
||||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||||
static report_programmable_button_t r;
|
send_report(report, sizeof(report_programmable_button_t));
|
||||||
r = (report_programmable_button_t){.report_id = REPORT_ID_PROGRAMMABLE_BUTTON, .usage = data};
|
|
||||||
send_report(&r, sizeof(r));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,9 +225,8 @@ static uint8_t keyboard_leds(void);
|
||||||
static void send_keyboard(report_keyboard_t *report);
|
static void send_keyboard(report_keyboard_t *report);
|
||||||
static void send_mouse(report_mouse_t *report);
|
static void send_mouse(report_mouse_t *report);
|
||||||
static void send_extra(uint8_t report_id, uint16_t data);
|
static void send_extra(uint8_t report_id, uint16_t data);
|
||||||
static void send_programmable_button(uint32_t data);
|
|
||||||
|
|
||||||
static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_extra, send_programmable_button};
|
static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
|
||||||
|
|
||||||
host_driver_t *vusb_driver(void) {
|
host_driver_t *vusb_driver(void) {
|
||||||
return &driver;
|
return &driver;
|
||||||
|
@ -292,16 +291,10 @@ void send_digitizer(report_digitizer_t *report) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_programmable_button(uint32_t data) {
|
void send_programmable_button(report_programmable_button_t *report) {
|
||||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||||
static report_programmable_button_t report = {
|
|
||||||
.report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
|
|
||||||
};
|
|
||||||
|
|
||||||
report.usage = data;
|
|
||||||
|
|
||||||
if (usbInterruptIsReadyShared()) {
|
if (usbInterruptIsReadyShared()) {
|
||||||
usbSetInterruptShared((void *)&report, sizeof(report));
|
usbSetInterruptShared((void *)report, sizeof(report_programmable_button_t));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue