diff options
Diffstat (limited to 'tmk_core/protocol/chibios')
| -rw-r--r-- | tmk_core/protocol/chibios/main.c | 1 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 85 |
2 files changed, 79 insertions, 7 deletions
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index 7d32c16ed..a0d28f9af 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | 35 | ||
| 36 | #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP | 36 | #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP |
| 37 | // Change this to be TRUE once we've migrated keyboards to the new init system | 37 | // Change this to be TRUE once we've migrated keyboards to the new init system |
| 38 | // Remember to change docs/platformdev_chibios_earlyinit.md as well. | ||
| 38 | # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE | 39 | # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE |
| 39 | #endif | 40 | #endif |
| 40 | 41 | ||
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 65bd291be..ae33e86a7 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c | |||
| @@ -47,6 +47,10 @@ | |||
| 47 | extern keymap_config_t keymap_config; | 47 | extern keymap_config_t keymap_config; |
| 48 | #endif | 48 | #endif |
| 49 | 49 | ||
| 50 | #ifdef JOYSTICK_ENABLE | ||
| 51 | # include "joystick.h" | ||
| 52 | #endif | ||
| 53 | |||
| 50 | /* --------------------------------------------------------- | 54 | /* --------------------------------------------------------- |
| 51 | * Global interface variables and declarations | 55 | * Global interface variables and declarations |
| 52 | * --------------------------------------------------------- | 56 | * --------------------------------------------------------- |
| @@ -62,7 +66,7 @@ extern keymap_config_t keymap_config; | |||
| 62 | 66 | ||
| 63 | uint8_t keyboard_idle __attribute__((aligned(2))) = 0; | 67 | uint8_t keyboard_idle __attribute__((aligned(2))) = 0; |
| 64 | uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; | 68 | uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; |
| 65 | uint8_t keyboard_led_stats = 0; | 69 | uint8_t keyboard_led_state = 0; |
| 66 | volatile uint16_t keyboard_idle_count = 0; | 70 | volatile uint16_t keyboard_idle_count = 0; |
| 67 | static virtual_timer_t keyboard_idle_timer; | 71 | static virtual_timer_t keyboard_idle_timer; |
| 68 | static void keyboard_idle_timer_cb(void *arg); | 72 | static void keyboard_idle_timer_cb(void *arg); |
| @@ -247,6 +251,9 @@ typedef struct { | |||
| 247 | #ifdef VIRTSER_ENABLE | 251 | #ifdef VIRTSER_ENABLE |
| 248 | usb_driver_config_t serial_driver; | 252 | usb_driver_config_t serial_driver; |
| 249 | #endif | 253 | #endif |
| 254 | #ifdef JOYSTICK_ENABLE | ||
| 255 | usb_driver_config_t joystick_driver; | ||
| 256 | #endif | ||
| 250 | }; | 257 | }; |
| 251 | usb_driver_config_t array[0]; | 258 | usb_driver_config_t array[0]; |
| 252 | }; | 259 | }; |
| @@ -283,6 +290,14 @@ static usb_driver_configs_t drivers = { | |||
| 283 | # define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK | 290 | # define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK |
| 284 | .serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false), | 291 | .serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false), |
| 285 | #endif | 292 | #endif |
| 293 | |||
| 294 | #ifdef JOYSTICK_ENABLE | ||
| 295 | # define JOYSTICK_IN_CAPACITY 4 | ||
| 296 | # define JOYSTICK_OUT_CAPACITY 4 | ||
| 297 | # define JOYSTICK_IN_MODE USB_EP_MODE_TYPE_BULK | ||
| 298 | # define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK | ||
| 299 | .joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false), | ||
| 300 | #endif | ||
| 286 | }; | 301 | }; |
| 287 | 302 | ||
| 288 | #define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t)) | 303 | #define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t)) |
| @@ -386,10 +401,10 @@ static void set_led_transfer_cb(USBDriver *usbp) { | |||
| 386 | if (usbp->setup[6] == 2) { /* LSB(wLength) */ | 401 | if (usbp->setup[6] == 2) { /* LSB(wLength) */ |
| 387 | uint8_t report_id = set_report_buf[0]; | 402 | uint8_t report_id = set_report_buf[0]; |
| 388 | if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) { | 403 | if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) { |
| 389 | keyboard_led_stats = set_report_buf[1]; | 404 | keyboard_led_state = set_report_buf[1]; |
| 390 | } | 405 | } |
| 391 | } else { | 406 | } else { |
| 392 | keyboard_led_stats = set_report_buf[0]; | 407 | keyboard_led_state = set_report_buf[0]; |
| 393 | } | 408 | } |
| 394 | } | 409 | } |
| 395 | 410 | ||
| @@ -610,7 +625,7 @@ static void keyboard_idle_timer_cb(void *arg) { | |||
| 610 | } | 625 | } |
| 611 | 626 | ||
| 612 | /* LED status */ | 627 | /* LED status */ |
| 613 | uint8_t keyboard_leds(void) { return keyboard_led_stats; } | 628 | uint8_t keyboard_leds(void) { return keyboard_led_state; } |
| 614 | 629 | ||
| 615 | /* prepare and start sending a report IN | 630 | /* prepare and start sending a report IN |
| 616 | * not callable from ISR or locked state */ | 631 | * not callable from ISR or locked state */ |
| @@ -796,9 +811,7 @@ int8_t sendchar(uint8_t c) { | |||
| 796 | } | 811 | } |
| 797 | #endif /* CONSOLE_ENABLE */ | 812 | #endif /* CONSOLE_ENABLE */ |
| 798 | 813 | ||
| 799 | void _putchar(char character) { | 814 | void _putchar(char character) { sendchar(character); } |
| 800 | sendchar(character); | ||
| 801 | } | ||
| 802 | 815 | ||
| 803 | #ifdef RAW_ENABLE | 816 | #ifdef RAW_ENABLE |
| 804 | void raw_hid_send(uint8_t *data, uint8_t length) { | 817 | void raw_hid_send(uint8_t *data, uint8_t length) { |
| @@ -869,3 +882,61 @@ void virtser_task(void) { | |||
| 869 | } | 882 | } |
| 870 | 883 | ||
| 871 | #endif | 884 | #endif |
| 885 | |||
| 886 | #ifdef JOYSTICK_ENABLE | ||
| 887 | |||
| 888 | void send_joystick_packet(joystick_t *joystick) { | ||
| 889 | joystick_report_t rep = { | ||
| 890 | # if JOYSTICK_AXES_COUNT > 0 | ||
| 891 | .axes = | ||
| 892 | { | ||
| 893 | joystick->axes[0], | ||
| 894 | |||
| 895 | # if JOYSTICK_AXES_COUNT >= 2 | ||
| 896 | joystick->axes[1], | ||
| 897 | # endif | ||
| 898 | # if JOYSTICK_AXES_COUNT >= 3 | ||
| 899 | joystick->axes[2], | ||
| 900 | # endif | ||
| 901 | # if JOYSTICK_AXES_COUNT >= 4 | ||
| 902 | joystick->axes[3], | ||
| 903 | # endif | ||
| 904 | # if JOYSTICK_AXES_COUNT >= 5 | ||
| 905 | joystick->axes[4], | ||
| 906 | # endif | ||
| 907 | # if JOYSTICK_AXES_COUNT >= 6 | ||
| 908 | joystick->axes[5], | ||
| 909 | # endif | ||
| 910 | }, | ||
| 911 | # endif // JOYSTICK_AXES_COUNT>0 | ||
| 912 | |||
| 913 | # if JOYSTICK_BUTTON_COUNT > 0 | ||
| 914 | .buttons = | ||
| 915 | { | ||
| 916 | joystick->buttons[0], | ||
| 917 | |||
| 918 | # if JOYSTICK_BUTTON_COUNT > 8 | ||
| 919 | joystick->buttons[1], | ||
| 920 | # endif | ||
| 921 | # if JOYSTICK_BUTTON_COUNT > 16 | ||
| 922 | joystick->buttons[2], | ||
| 923 | # endif | ||
| 924 | # if JOYSTICK_BUTTON_COUNT > 24 | ||
| 925 | joystick->buttons[3], | ||
| 926 | # endif | ||
| 927 | } | ||
| 928 | # endif // JOYSTICK_BUTTON_COUNT>0 | ||
| 929 | }; | ||
| 930 | |||
| 931 | // chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep)); | ||
| 932 | osalSysLock(); | ||
| 933 | if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) { | ||
| 934 | osalSysUnlock(); | ||
| 935 | return; | ||
| 936 | } | ||
| 937 | |||
| 938 | usbStartTransmitI(&USB_DRIVER, JOYSTICK_IN_EPNUM, (uint8_t *)&rep, sizeof(joystick_report_t)); | ||
| 939 | osalSysUnlock(); | ||
| 940 | } | ||
| 941 | |||
| 942 | #endif | ||
