From 5ba4391cf29ce624f17593417212b3dbca1609ad Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 28 Feb 2021 15:52:58 +0000 Subject: Refactor of USB code within split_common (#11890) * Initial refactor of usb code within split_common * Add headers * Correct disable condition * Format * Align func name --- tmk_core/protocol/vusb/usb_util.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tmk_core/protocol/vusb/usb_util.c (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c new file mode 100644 index 0000000000..602854dbe6 --- /dev/null +++ b/tmk_core/protocol/vusb/usb_util.c @@ -0,0 +1,24 @@ +/* Copyright 2021 QMK + * + * 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 3 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 . + */ +#include +#include "usb_util.h" + +void usb_disable(void) { usbDeviceDisconnect(); } + +bool usb_connected_state(void) { + usbPoll(); + return usbConfiguration; +} -- cgit v1.2.3 From 58142f0726147d538167ff3ab793743348f40dcd Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Tue, 18 May 2021 17:02:28 +1000 Subject: Fixup housekeeping from being invoked twice per loop. (#12933) --- tmk_core/protocol/vusb/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 2de4f6a80a..53926a7493 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c @@ -173,8 +173,7 @@ int main(void) { #endif // Run housekeeping - housekeeping_task_kb(); - housekeeping_task_user(); + housekeeping_task(); } } } -- cgit v1.2.3 From 49fd3c0760e06b7eab3647098530f1a9bdfc5054 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 7 Jun 2021 07:16:55 +0200 Subject: [Core] ChibiOS fix O3 and LTO breakage of extra keys and joystick (#12819) --- tmk_core/protocol/vusb/vusb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 9362fbde78..876a313786 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -272,7 +272,8 @@ static void send_extra(uint8_t report_id, uint16_t data) { last_id = report_id; last_data = data; - report_extra_t report = {.report_id = report_id, .usage = data}; + static report_extra_t report; + report = (report_extra_t){.report_id = report_id, .usage = data}; if (usbInterruptIsReadyShared()) { usbSetInterruptShared((void *)&report, sizeof(report_extra_t)); } -- cgit v1.2.3 From 7ed5ac4a6026939898810f9a9c706fb7a09db171 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 16 Jul 2021 19:43:18 +1000 Subject: Use string literals for `SERIAL_NUMBER` (#13403) --- tmk_core/protocol/vusb/vusb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 876a313786..98cebf6012 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -599,10 +599,10 @@ const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = { #if defined(SERIAL_NUMBER) const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = { .header = { - .bLength = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), + .bLength = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1), .bDescriptorType = USBDESCR_STRING }, - .bString = LSTR(SERIAL_NUMBER) + .bString = USBSTR(SERIAL_NUMBER) }; #endif -- cgit v1.2.3 From 567da49ed027a936a6f56aa069aad0db4605a198 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sat, 24 Jul 2021 12:13:06 +0100 Subject: Avoid LTO conficts on arm_atsam (#13676) --- tmk_core/protocol/vusb/usb_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c index 602854dbe6..4ee2d3188b 100644 --- a/tmk_core/protocol/vusb/usb_util.c +++ b/tmk_core/protocol/vusb/usb_util.c @@ -16,7 +16,7 @@ #include #include "usb_util.h" -void usb_disable(void) { usbDeviceDisconnect(); } +void usb_disconnect(void) { usbDeviceDisconnect(); } bool usb_connected_state(void) { usbPoll(); -- cgit v1.2.3 From 75b49aff56436c57a424e622c91f6d80e1d0ecc2 Mon Sep 17 00:00:00 2001 From: a-chol Date: Tue, 17 Aug 2021 20:52:44 +0200 Subject: Digitizer HID interface : absolute coordinates for mouse cursor (#12851) * Add digitizer HID interface for setting the mouse cursor position at absolute screen coordinates. Tested on Pro Micro, Proton C and Blackpill. * Update docs/feature_digitizer.md Co-authored-by: Ryan * Update tmk_core/protocol/usb_descriptor.c Co-authored-by: Ryan * Add missing copyrights Add V-USB support * Add support for digitizer dedicated endpoint for lufa and chibios. Fix formatting issues Move digitizer_task definition to the feature's base implementation file * Run cformat on modified files * Change digitizer report usage to Digitizer instead of Pen to avoid pointer disappearing on Windows. * Update tmk_core/protocol/vusb/vusb.c Co-authored-by: Ryan * Run cformat from docker image * Remove send_digitizer from host_driver_t and instead rely on the declaration being the interface to the implementation in each HW-specific usb implementation. * Fix build : send_digitizer shouldn't be static in vusb and add weak-linkage implementation for tests without usb implementation * Change digitizer user interface to match pointing device's * Update documentation with new API Co-authored-by: a-chol Co-authored-by: Ryan --- tmk_core/protocol/vusb/vusb.c | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 98cebf6012..485b20c900 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -292,6 +292,14 @@ static void send_consumer(uint16_t data) { #endif } +void send_digitizer(report_digitizer_t *report) { +#ifdef DIGITIZER_ENABLE + if (usbInterruptIsReadyShared()) { + usbSetInterruptShared((void *)report, sizeof(report_digitizer_t)); + } +#endif +} + /*------------------------------------------------------------------* * Request from host * *------------------------------------------------------------------*/ @@ -510,8 +518,46 @@ const PROGMEM uchar shared_hid_report[] = { 0x95, 0x01, // Report Count (1) 0x75, 0x10, // Report Size (16) 0x81, 0x00, // Input (Data, Array, Absolute) - 0xC0 // End Collection + 0xC0, // End Collection +#endif + +#ifdef DIGITIZER_ENABLE + // Digitizer report descriptor + 0x05, 0x0D, // Usage Page (Digitizers) + 0x09, 0x01, // Usage (Digitizer) + 0xA1, 0x01, // Collection (Application) + 0x85, REPORT_ID_DIGITIZER, // Report ID + 0x09, 0x22, // Usage (Finger) + 0xA1, 0x00, // Collection (Physical) + // Tip Switch (1 bit) + 0x09, 0x42, // Usage (Tip Switch) + 0x15, 0x00, // Logical Minimum + 0x25, 0x01, // Logical Maximum + 0x95, 0x01, // Report Count (1) + 0x75, 0x01, // Report Size (16) + 0x81, 0x02, // Input (Data, Variable, Absolute) + // In Range (1 bit) + 0x09, 0x32, // Usage (In Range) + 0x81, 0x02, // Input (Data, Variable, Absolute) + // Padding (6 bits) + 0x95, 0x06, // Report Count (6) + 0x81, 0x03, // Input (Constant) + + // X/Y Position (4 bytes) + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x26, 0xFF, 0x7F, // Logical Maximum (32767) + 0x95, 0x01, // Report Count (1) + 0x75, 0x10, // Report Size (16) + 0x65, 0x33, // Unit (Inch, English Linear) + 0x55, 0x0E, // Unit Exponent (-2) + 0x09, 0x30, // Usage (X) + 0x81, 0x02, // Input (Data, Variable, Absolute) + 0x09, 0x31, // Usage (Y) + 0x81, 0x02, // Input (Data, Variable, Absolute) + 0xC0, // End Collection + 0xC0 // End Collection #endif + #ifdef SHARED_EP_ENABLE }; #endif -- cgit v1.2.3 From 96e2b13d1de227cdc2b918fb0292bd832d346a25 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 18 Aug 2021 00:11:07 +0100 Subject: Begin to carve out platform/protocol API - Single main loop (#13843) * Begin to carve out platform/protocol API * Fix up after rebase --- tmk_core/protocol/vusb/main.c | 179 -------------------------------------- tmk_core/protocol/vusb/protocol.c | 178 +++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 179 deletions(-) delete mode 100644 tmk_core/protocol/vusb/main.c create mode 100644 tmk_core/protocol/vusb/protocol.c (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c deleted file mode 100644 index 53926a7493..0000000000 --- a/tmk_core/protocol/vusb/main.c +++ /dev/null @@ -1,179 +0,0 @@ -/* Name: main.c - * Project: hid-mouse, a very simple HID example - * Author: Christian Starkjohann - * Creation Date: 2008-04-07 - * Tabsize: 4 - * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH - * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) - * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ - */ - -#include - -#include -#include -#include -#include - -#include - -#include "vusb.h" - -#include "keyboard.h" -#include "host.h" -#include "timer.h" -#include "print.h" -#include "suspend.h" -#include "wait.h" -#include "sendchar.h" - -#ifdef SLEEP_LED_ENABLE -# include "sleep_led.h" -#endif - -#ifdef CONSOLE_ENABLE -void console_task(void); -#endif - -#ifdef RAW_ENABLE -void raw_hid_task(void); -#endif - -/* This is from main.c of USBaspLoader */ -static void initForUsbConnectivity(void) { - uint8_t i = 0; - - usbInit(); - /* enforce USB re-enumerate: */ - usbDeviceDisconnect(); /* do this while interrupts are disabled */ - while (--i) { /* fake USB disconnect for > 250 ms */ - wdt_reset(); - wait_ms(1); - } - usbDeviceConnect(); -} - -static void vusb_send_remote_wakeup(void) { - cli(); - - uint8_t ddr_orig = USBDDR; - USBOUT |= (1 << USBMINUS); - USBDDR = ddr_orig | USBMASK; - USBOUT ^= USBMASK; - - wait_ms(25); - - USBOUT ^= USBMASK; - USBDDR = ddr_orig; - USBOUT &= ~(1 << USBMINUS); - - sei(); -} - -bool vusb_suspended = false; - -static void vusb_suspend(void) { - vusb_suspended = true; - -#ifdef SLEEP_LED_ENABLE - sleep_led_enable(); -#endif - - suspend_power_down(); -} - -#if USB_COUNT_SOF -static void vusb_wakeup(void) { - vusb_suspended = false; - suspend_wakeup_init(); - -# ifdef SLEEP_LED_ENABLE - sleep_led_disable(); -# endif -} -#endif - -/** \brief Setup USB - * - * FIXME: Needs doc - */ -static void setup_usb(void) { initForUsbConnectivity(); } - -/** \brief Main - * - * FIXME: Needs doc - */ -int main(void) __attribute__((weak)); -int main(void) { -#if USB_COUNT_SOF - uint16_t sof_timer = timer_read(); -#endif - -#ifdef CLKPR - // avoid unintentional changes of clock frequency in devices that have a - // clock prescaler - clock_prescale_set(clock_div_1); -#endif - keyboard_setup(); - setup_usb(); - sei(); - keyboard_init(); - host_set_driver(vusb_driver()); - - wait_ms(50); - -#ifdef SLEEP_LED_ENABLE - sleep_led_init(); -#endif - - while (1) { -#if USB_COUNT_SOF - if (usbSofCount != 0) { - usbSofCount = 0; - sof_timer = timer_read(); - if (vusb_suspended) { - vusb_wakeup(); - } - } else { - // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) - if (!vusb_suspended && timer_elapsed(sof_timer) > 5) { - vusb_suspend(); - } - } -#endif - if (vusb_suspended) { - vusb_suspend(); - if (suspend_wakeup_condition()) { - vusb_send_remote_wakeup(); - } - } else { - usbPoll(); - - // TODO: configuration process is inconsistent. it sometime fails. - // To prevent failing to configure NOT scan keyboard during configuration - if (usbConfiguration && usbInterruptIsReady()) { - keyboard_task(); - } - vusb_transfer_keyboard(); - -#ifdef RAW_ENABLE - usbPoll(); - - if (usbConfiguration && usbInterruptIsReady3()) { - raw_hid_task(); - } -#endif - -#ifdef CONSOLE_ENABLE - usbPoll(); - - if (usbConfiguration && usbInterruptIsReady3()) { - console_task(); - } -#endif - - // Run housekeeping - housekeeping_task(); - } - } -} diff --git a/tmk_core/protocol/vusb/protocol.c b/tmk_core/protocol/vusb/protocol.c new file mode 100644 index 0000000000..89dc795b21 --- /dev/null +++ b/tmk_core/protocol/vusb/protocol.c @@ -0,0 +1,178 @@ +/* Name: main.c + * Project: hid-mouse, a very simple HID example + * Author: Christian Starkjohann + * Creation Date: 2008-04-07 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ + */ + +#include + +#include +#include +#include +#include + +#include + +#include "vusb.h" + +#include "keyboard.h" +#include "host.h" +#include "timer.h" +#include "print.h" +#include "suspend.h" +#include "wait.h" +#include "sendchar.h" + +#ifdef SLEEP_LED_ENABLE +# include "sleep_led.h" +#endif + +#ifdef CONSOLE_ENABLE +void console_task(void); +#endif + +#ifdef RAW_ENABLE +void raw_hid_task(void); +#endif + +/* This is from main.c of USBaspLoader */ +static void initForUsbConnectivity(void) { + uint8_t i = 0; + + usbInit(); + /* enforce USB re-enumerate: */ + usbDeviceDisconnect(); /* do this while interrupts are disabled */ + while (--i) { /* fake USB disconnect for > 250 ms */ + wdt_reset(); + wait_ms(1); + } + usbDeviceConnect(); +} + +static void vusb_send_remote_wakeup(void) { + cli(); + + uint8_t ddr_orig = USBDDR; + USBOUT |= (1 << USBMINUS); + USBDDR = ddr_orig | USBMASK; + USBOUT ^= USBMASK; + + wait_ms(25); + + USBOUT ^= USBMASK; + USBDDR = ddr_orig; + USBOUT &= ~(1 << USBMINUS); + + sei(); +} + +bool vusb_suspended = false; + +static void vusb_suspend(void) { + vusb_suspended = true; + +#ifdef SLEEP_LED_ENABLE + sleep_led_enable(); +#endif + + suspend_power_down(); +} + +#if USB_COUNT_SOF +static void vusb_wakeup(void) { + vusb_suspended = false; + suspend_wakeup_init(); + +# ifdef SLEEP_LED_ENABLE + sleep_led_disable(); +# endif +} +#endif + +/** \brief Setup USB + * + * FIXME: Needs doc + */ +static void setup_usb(void) { initForUsbConnectivity(); } + +uint16_t sof_timer = 0; + +void protocol_setup(void) { +#if USB_COUNT_SOF + sof_timer = timer_read(); +#endif + +#ifdef CLKPR + // avoid unintentional changes of clock frequency in devices that have a + // clock prescaler + clock_prescale_set(clock_div_1); +#endif + keyboard_setup(); +} + +void protocol_init(void) { + setup_usb(); + sei(); + + keyboard_init(); + + host_set_driver(vusb_driver()); + + wait_ms(50); + +#ifdef SLEEP_LED_ENABLE + sleep_led_init(); +#endif +} + +void protocol_task(void) { +#if USB_COUNT_SOF + if (usbSofCount != 0) { + usbSofCount = 0; + sof_timer = timer_read(); + if (vusb_suspended) { + vusb_wakeup(); + } + } else { + // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) + if (!vusb_suspended && timer_elapsed(sof_timer) > 5) { + vusb_suspend(); + } + } +#endif + if (vusb_suspended) { + vusb_suspend(); + if (suspend_wakeup_condition()) { + vusb_send_remote_wakeup(); + } + } else { + usbPoll(); + + // TODO: configuration process is inconsistent. it sometime fails. + // To prevent failing to configure NOT scan keyboard during configuration + if (usbConfiguration && usbInterruptIsReady()) { + keyboard_task(); + } + vusb_transfer_keyboard(); + +#ifdef RAW_ENABLE + usbPoll(); + + if (usbConfiguration && usbInterruptIsReady3()) { + raw_hid_task(); + } +#endif + +#ifdef CONSOLE_ENABLE + usbPoll(); + + if (usbConfiguration && usbInterruptIsReady3()) { + console_task(); + } +#endif + } +} -- cgit v1.2.3 [cgit] Unable to lock slot /tmp/cgit/99100000.lock: Permission denied (13)