From 30680c6eb396a2bb06928afd69edae9908ac84fb Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Wed, 29 Aug 2018 15:07:52 -0400 Subject: Massdrop keyboard support (#3780) * Massdrop SAMD51 Massdrop SAMD51 keyboards initial project upload * Removing relocated files Removing files that were relocated and not deleted from previous location * LED queue fix and cleaning Cleaned some white space or comments. Fix for LED I2C command queue. Cleaned up interrupts. Added debug function for printing numbers to scope through m15 line. * Factory programmed serial usage Ability to use factory programmed serial in hub and keyboard usb descriptors * USB serial number and bugfix Added support for factory programmed serial and usage. Incorporated bootloader's conditional compiling to align project closer. Fixed issue when USB device attempted to send before enabled. General white space and comment cleanup. * Project cleanup Cleaned up project in terms of white space, commented code, and unecessary files. NKRO keyboard is now using correct setreport although KBD was fine to use. Fixed broken linkage to __xprintf for serial debug statements. * Fix for extra keys Fixed possible USB hang on extra keys report set missing * I2C cleanup I2C cleanup and file renames necessary for master branch merge * Boot tracing and clocks cleanup Added optional boot debug trace mode through debug LED codes. General clock code cleanup. * Relocate ARM/Atmel headers Moved ARM/Atmel header folder from drivers to lib and made necessary makefile changes. * Pull request changes Pull request changes * Keymap and compile flag fix Keymap fix for momentary layer. Potential compile flag fix for Travis CI failure. * va_list include fix Fix for va_list compile failure * Include file case fixes Fixes for include files with incorrect case * ctrl and alt67 keyboard readme Added ctrl and alt67 keyboard readme files --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 279 +++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 tmk_core/protocol/arm_atsam/main_arm_atsam.c (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c new file mode 100644 index 000000000..e9514730e --- /dev/null +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -0,0 +1,279 @@ +/* +Copyright 2018 Massdrop Inc. + +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 . +*/ + +#include "samd51j18a.h" +#include "tmk_core/common/keyboard.h" + +#include "report.h" +#include "host.h" +#include "host_driver.h" +#include "keycode_config.h" +#include +#include "quantum.h" + +//From protocol directory +#include "arm_atsam_protocol.h" + +//From keyboard's directory +#include "config_led.h" + +uint8_t keyboard_leds(void); +void send_keyboard(report_keyboard_t *report); +void send_mouse(report_mouse_t *report); +void send_system(uint16_t data); +void send_consumer(uint16_t data); + +host_driver_t arm_atsam_driver = { + keyboard_leds, + send_keyboard, + send_mouse, + send_system, + send_consumer +}; + +uint8_t led_states; + +uint8_t keyboard_leds(void) +{ +#ifdef NKRO_ENABLE + if (keymap_config.nkro) + return udi_hid_nkro_report_set; + else +#endif //NKRO_ENABLE + return udi_hid_kbd_report_set; +} + +void send_keyboard(report_keyboard_t *report) +{ + uint32_t irqflags; + +#ifdef NKRO_ENABLE + if (!keymap_config.nkro) + { +#endif //NKRO_ENABLE + dprint("s-kbd\r\n"); + + irqflags = __get_PRIMASK(); + __disable_irq(); + __DMB(); + + memcpy(udi_hid_kbd_report, report->raw, UDI_HID_KBD_REPORT_SIZE); + udi_hid_kbd_b_report_valid = 1; + udi_hid_kbd_send_report(); + + __DMB(); + __set_PRIMASK(irqflags); +#ifdef NKRO_ENABLE + } + else + { + dprint("s-nkro\r\n"); + + irqflags = __get_PRIMASK(); + __disable_irq(); + __DMB(); + + memcpy(udi_hid_nkro_report, report->raw, UDI_HID_NKRO_REPORT_SIZE); + udi_hid_nkro_b_report_valid = 1; + udi_hid_nkro_send_report(); + + __DMB(); + __set_PRIMASK(irqflags); + } +#endif //NKRO_ENABLE +} + +void send_mouse(report_mouse_t *report) +{ +#ifdef MOUSEKEY_ENABLE + uint32_t irqflags; + + dprint("s-mou\r\n"); + + irqflags = __get_PRIMASK(); + __disable_irq(); + __DMB(); + + memcpy(udi_hid_mou_report, report, UDI_HID_MOU_REPORT_SIZE); + udi_hid_mou_b_report_valid = 1; + udi_hid_mou_send_report(); + + __DMB(); + __set_PRIMASK(irqflags); +#endif //MOUSEKEY_ENABLE +} + +void send_system(uint16_t data) +{ +#ifdef EXTRAKEY_ENABLE + dprintf("s-exks %i\r\n", data); + + uint32_t irqflags; + + irqflags = __get_PRIMASK(); + __disable_irq(); + __DMB(); + + udi_hid_exk_report.desc.report_id = REPORT_ID_SYSTEM; + if (data != 0) data = data - SYSTEM_POWER_DOWN + 1; + udi_hid_exk_report.desc.report_data = data; + udi_hid_exk_b_report_valid = 1; + udi_hid_exk_send_report(); + + __DMB(); + __set_PRIMASK(irqflags); +#endif //EXTRAKEY_ENABLE +} + +void send_consumer(uint16_t data) +{ +#ifdef EXTRAKEY_ENABLE + dprintf("s-exkc %i\r\n",data); + + uint32_t irqflags; + + irqflags = __get_PRIMASK(); + __disable_irq(); + __DMB(); + + udi_hid_exk_report.desc.report_id = REPORT_ID_CONSUMER; + udi_hid_exk_report.desc.report_data = data; + udi_hid_exk_b_report_valid = 1; + udi_hid_exk_send_report(); + + __DMB(); + __set_PRIMASK(irqflags); +#endif //EXTRAKEY_ENABLE +} + +int main(void) +{ + led_ena; + m15_ena; + + debug_code_init(); + + CLK_init(); + + ADC0_init(); + + SPI_Init(); + + i2c1_init(); + + matrix_init(); + + USB2422_init(); + + DBGC(DC_MAIN_UDC_START_BEGIN); + udc_start(); + DBGC(DC_MAIN_UDC_START_COMPLETE); + + DBGC(DC_MAIN_CDC_INIT_BEGIN); + CDC_init(); + DBGC(DC_MAIN_CDC_INIT_COMPLETE); + + while (USB2422_Port_Detect_Init() == 0) {} + + led_off; + m15_off; + + led_matrix_init(); + + while (I2C3733_Init_Control() != 1) {} + while (I2C3733_Init_Drivers() != 1) {} + + I2C_DMAC_LED_Init(); + + i2c_led_q_init(); + + uint8_t drvid; + for (drvid=0;drvid next_5v_checkup) + { + next_5v_checkup = CLK_get_ms() + 5; + + v_5v = adc_get(ADC_5V); + v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v; + + gcr_compute(); + } + + if (CLK_get_ms() > next_usb_checkup) + { + next_usb_checkup = CLK_get_ms() + 10; + + USB_HandleExtraDevice(); + } + +#ifdef VIRTSER_ENABLE + if (CLK_get_ms() > next_print) + { + next_print = CLK_get_ms() + 250; + //dpf("5v=%i 5vu=%i dlow=%i dhi=%i gca=%i gcd=%i\r\n",v_5v,v_5v_avg,v_5v_avg-V5_LOW,v_5v_avg-V5_HIGH,gcr_actual,gcr_desired); + } +#endif //VIRTSER_ENABLE + } + + return 1; +} + -- cgit v1.2.3-24-g4f1b From e5465e1c57f1ae6b71e1e665e4afd5f5e3909a89 Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Wed, 5 Sep 2018 12:25:47 -0400 Subject: CTRL and ALT updates Added support to enter bootloader from software (bootloader version must be newer than "v2.18Jun 22 2018 17:28:08" until workaround for older is created). Updated CTRL and ALT keymaps for entering bootloader with Fn+b held for >500ms. Added basic MacOS keymap for ALT. USB sleep LED indicator now turns off after 1 second. Slowed down debug LED code printing. --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index e9514730e..8cc776703 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -225,6 +225,8 @@ int main(void) { if (usb_state == USB_STATE_POWERDOWN) { + uint32_t timer_led = timer_read32(); + led_on; if (led_enabled) { @@ -233,7 +235,10 @@ int main(void) I2C3733_Control_Set(0); } } - while (usb_state == USB_STATE_POWERDOWN) {} + while (usb_state == USB_STATE_POWERDOWN) + { + if (timer_read32() - timer_led > 1000) led_off; //Good to indicate went to sleep, but only for a second + } if (led_enabled) { for (drvid=0;drvid Date: Fri, 28 Sep 2018 21:32:15 -0400 Subject: Massdrop keyboard updates for SEND_STRING, syscalls, stdio, debug prints, Auto Shift (#3973) * Update for SEND_STRING usage Update for SEND_STRING usage. Sending keyboard reports (kbd, nkro) now obey the minimum polling time. While attempting to send a keyboard report and waiting for a USB poll, other functions of the keyboard, including LED effects and power management, will continue to operate at their intended intervals. * Updates for send string, syscalls, stdio, debug prints, auto shift Now properly waiting for previous keys sent over USB to complete before sending new. Added heap to linker and now compiling with syscalls support. Removed custom string functions and now using stdio. dprintf now works as intended through virtser device. * CTRL and ALT keymap updates CTRL mac keymap updated ALT default and mac keymap updated ALT rules.mk added Auto Shift with default no * Code cleanup as per discussion with vomindoraan Code cleanup as per discussion with vomindoraan --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 136 +++++++++++++++------------ 1 file changed, 78 insertions(+), 58 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 8cc776703..676dac4ea 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -31,6 +31,7 @@ along with this program. If not, see . //From keyboard's directory #include "config_led.h" +void main_subtasks(void); uint8_t keyboard_leds(void); void send_keyboard(report_keyboard_t *report); void send_mouse(report_mouse_t *report); @@ -65,7 +66,7 @@ void send_keyboard(report_keyboard_t *report) if (!keymap_config.nkro) { #endif //NKRO_ENABLE - dprint("s-kbd\r\n"); + while (udi_hid_kbd_b_report_trans_ongoing) { main_subtasks(); } //Run other tasks while waiting for USB to be free irqflags = __get_PRIMASK(); __disable_irq(); @@ -81,7 +82,7 @@ void send_keyboard(report_keyboard_t *report) } else { - dprint("s-nkro\r\n"); + while (udi_hid_nkro_b_report_trans_ongoing) { main_subtasks(); } //Run other tasks while waiting for USB to be free irqflags = __get_PRIMASK(); __disable_irq(); @@ -102,8 +103,6 @@ void send_mouse(report_mouse_t *report) #ifdef MOUSEKEY_ENABLE uint32_t irqflags; - dprint("s-mou\r\n"); - irqflags = __get_PRIMASK(); __disable_irq(); __DMB(); @@ -120,8 +119,6 @@ void send_mouse(report_mouse_t *report) void send_system(uint16_t data) { #ifdef EXTRAKEY_ENABLE - dprintf("s-exks %i\r\n", data); - uint32_t irqflags; irqflags = __get_PRIMASK(); @@ -142,8 +139,6 @@ void send_system(uint16_t data) void send_consumer(uint16_t data) { #ifdef EXTRAKEY_ENABLE - dprintf("s-exkc %i\r\n",data); - uint32_t irqflags; irqflags = __get_PRIMASK(); @@ -160,6 +155,77 @@ void send_consumer(uint16_t data) #endif //EXTRAKEY_ENABLE } +uint8_t g_drvid; + +void main_subtask_usb_state(void) +{ + if (usb_state == USB_STATE_POWERDOWN) + { + uint32_t timer_led = timer_read32(); + + led_on; + if (led_enabled) + { + for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) + { + I2C3733_Control_Set(0); + } + } + while (usb_state == USB_STATE_POWERDOWN) + { + if (timer_read32() - timer_led > 1000) led_off; //Good to indicate went to sleep, but only for a second + } + if (led_enabled) + { + for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) + { + I2C3733_Control_Set(1); + } + } + led_off; + } +} + +void main_subtask_led(void) +{ + led_matrix_task(); +} + +void main_subtask_power_check(void) +{ + static uint64_t next_5v_checkup = 0; + + if (CLK_get_ms() > next_5v_checkup) + { + next_5v_checkup = CLK_get_ms() + 5; + + v_5v = adc_get(ADC_5V); + v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v; + + gcr_compute(); + } +} + +void main_subtask_usb_extra_device(void) +{ + static uint64_t next_usb_checkup = 0; + + if (CLK_get_ms() > next_usb_checkup) + { + next_usb_checkup = CLK_get_ms() + 10; + + USB_HandleExtraDevice(); + } +} + +void main_subtasks(void) +{ + main_subtask_usb_state(); + main_subtask_led(); + main_subtask_power_check(); + main_subtask_usb_extra_device(); +} + int main(void) { led_ena; @@ -201,9 +267,8 @@ int main(void) i2c_led_q_init(); - uint8_t drvid; - for (drvid=0;drvid 1000) led_off; //Good to indicate went to sleep, but only for a second - } - if (led_enabled) - { - for (drvid=0;drvid next_5v_checkup) - { - next_5v_checkup = CLK_get_ms() + 5; - - v_5v = adc_get(ADC_5V); - v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v; - - gcr_compute(); - } - - if (CLK_get_ms() > next_usb_checkup) - { - next_usb_checkup = CLK_get_ms() + 10; - - USB_HandleExtraDevice(); - } + main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals #ifdef VIRTSER_ENABLE if (CLK_get_ms() > next_print) { next_print = CLK_get_ms() + 250; - //dpf("5v=%i 5vu=%i dlow=%i dhi=%i gca=%i gcd=%i\r\n",v_5v,v_5v_avg,v_5v_avg-V5_LOW,v_5v_avg-V5_HIGH,gcr_actual,gcr_desired); + dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n",v_5v,v_5v_avg,v_5v_avg-V5_LOW,v_5v_avg-V5_HIGH,gcr_actual,gcr_desired); } #endif //VIRTSER_ENABLE } -- cgit v1.2.3-24-g4f1b From ab91e07753720f8114d6c427139a1436e6efa3ce Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Tue, 9 Oct 2018 15:14:13 -0400 Subject: Massdrop keyboards console device support for hid_listen Added hid_listen USB device for arm_atsam USB protocol. Debug printing is now done through the console device (CONSOLE_ENABLE = yes) rather than the virtser device, for viewing in hid_listen. Function dpf(...) renamed to CDC_printf(...) and should now be called directly if intending to print to the virtual serial device. --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 676dac4ea..54d056a14 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -276,9 +276,9 @@ int main(void) host_set_driver(&arm_atsam_driver); -#ifdef VIRTSER_ENABLE +#ifdef CONSOLE_ENABLE uint64_t next_print = 0; -#endif //VIRTSER_ENABLE +#endif //CONSOLE_ENABLE v_5v_avg = adc_get(ADC_5V); @@ -290,15 +290,17 @@ int main(void) main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals -#ifdef VIRTSER_ENABLE +#ifdef CONSOLE_ENABLE if (CLK_get_ms() > next_print) { next_print = CLK_get_ms() + 250; - dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n",v_5v,v_5v_avg,v_5v_avg-V5_LOW,v_5v_avg-V5_HIGH,gcr_actual,gcr_desired); + //Add any debug information here that you want to see very often + //dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired); } -#endif //VIRTSER_ENABLE +#endif //CONSOLE_ENABLE } + return 1; } -- cgit v1.2.3-24-g4f1b From 563fe23e53fb747f509b8558bb29bde0baf2d6a8 Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Tue, 30 Oct 2018 12:23:57 -0400 Subject: Fix CTRL/ALT keyboard does not wake computer from sleep Fix for Massdrop CTRL and ALT keyboards not waking computer from sleep --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 30 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 54d056a14..d3dc272ee 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -62,6 +62,12 @@ void send_keyboard(report_keyboard_t *report) { uint32_t irqflags; + if (usb_state == USB_STATE_POWERDOWN) + { + udc_remotewakeup(); + return; + } + #ifdef NKRO_ENABLE if (!keymap_config.nkro) { @@ -156,25 +162,27 @@ void send_consumer(uint16_t data) } uint8_t g_drvid; +uint8_t g_usb_sleeping = 0; void main_subtask_usb_state(void) { if (usb_state == USB_STATE_POWERDOWN) { - uint32_t timer_led = timer_read32(); - - led_on; - if (led_enabled) + if (!g_usb_sleeping) { - for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) + g_usb_sleeping = 1; + if (led_enabled) { - I2C3733_Control_Set(0); + for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) + { + I2C3733_Control_Set(0); + } } } - while (usb_state == USB_STATE_POWERDOWN) - { - if (timer_read32() - timer_led > 1000) led_off; //Good to indicate went to sleep, but only for a second - } + } + else if (g_usb_sleeping) + { + g_usb_sleeping = 0; if (led_enabled) { for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) @@ -182,12 +190,12 @@ void main_subtask_usb_state(void) I2C3733_Control_Set(1); } } - led_off; } } void main_subtask_led(void) { + if (g_usb_sleeping) return; led_matrix_task(); } -- cgit v1.2.3-24-g4f1b From cec203ea80c8e9365bb5f43418fba5971dd4091f Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Fri, 2 Nov 2018 15:30:51 -0400 Subject: USB Suspend for arm_atsam protocol Rewrote USB state tracking for implementation of suspend state. Updated suspend.c in entirety. Main subtasks (generally hardware related) are now run prior to keyboard task. --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 80 ++++++++++++++++++---------- 1 file changed, 51 insertions(+), 29 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index d3dc272ee..13034a05d 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -31,6 +31,8 @@ along with this program. If not, see . //From keyboard's directory #include "config_led.h" +uint8_t g_usb_state = USB_FSMSTATUS_FSMSTATE_OFF_Val; //Saved USB state from hardware value to detect changes + void main_subtasks(void); uint8_t keyboard_leds(void); void send_keyboard(report_keyboard_t *report); @@ -62,12 +64,6 @@ void send_keyboard(report_keyboard_t *report) { uint32_t irqflags; - if (usb_state == USB_STATE_POWERDOWN) - { - udc_remotewakeup(); - return; - } - #ifdef NKRO_ENABLE if (!keymap_config.nkro) { @@ -161,41 +157,56 @@ void send_consumer(uint16_t data) #endif //EXTRAKEY_ENABLE } -uint8_t g_drvid; -uint8_t g_usb_sleeping = 0; - void main_subtask_usb_state(void) { - if (usb_state == USB_STATE_POWERDOWN) + static uint32_t fsmstate_on_delay = 0; //Delay timer to be sure USB is actually operating before bringing up hardware + uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; //Current state from hardware register + + if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) //If USB SUSPENDED { - if (!g_usb_sleeping) + fsmstate_on_delay = 0; //Clear ON delay timer + + if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) //If previously not SUSPENDED { - g_usb_sleeping = 1; - if (led_enabled) - { - for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) - { - I2C3733_Control_Set(0); - } - } + suspend_power_down(); //Run suspend routine + g_usb_state = fsmstate_now; //Save current USB state } } - else if (g_usb_sleeping) + else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) //Else if USB SLEEPING { - g_usb_sleeping = 0; - if (led_enabled) + fsmstate_on_delay = 0; //Clear ON delay timer + + if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SLEEP_Val) //If previously not SLEEPING { - for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) + suspend_power_down(); //Run suspend routine + g_usb_state = fsmstate_now; //Save current USB state + } + } + else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_ON_Val) //Else if USB ON + { + if (g_usb_state != USB_FSMSTATUS_FSMSTATE_ON_Val) //If previously not ON + { + if (fsmstate_on_delay == 0) //If ON delay timer is cleared { - I2C3733_Control_Set(1); + fsmstate_on_delay = CLK_get_ms() + 250; //Set ON delay timer + } + else if (CLK_get_ms() > fsmstate_on_delay) //Else if ON delay timer is active and timed out + { + suspend_wakeup_init(); //Run wakeup routine + g_usb_state = fsmstate_now; //Save current USB state } } } + else //Else if USB is in a state not being tracked + { + fsmstate_on_delay = 0; //Clear ON delay timer + } } void main_subtask_led(void) { - if (g_usb_sleeping) return; + if (g_usb_state != USB_FSMSTATUS_FSMSTATE_ON_Val) return; //Only run LED tasks if USB is operating + led_matrix_task(); } @@ -275,8 +286,8 @@ int main(void) i2c_led_q_init(); - for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++) - I2C_LED_Q_ONOFF(g_drvid); //Queue data + for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) + I2C_LED_Q_ONOFF(drvid); //Queue data keyboard_setup(); @@ -294,10 +305,21 @@ int main(void) while (1) { - keyboard_task(); - main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals + if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) + { + if (suspend_wakeup_condition()) + { + udc_remotewakeup(); //Send remote wakeup signal + wait_ms(50); + } + + continue; + } + + keyboard_task(); + #ifdef CONSOLE_ENABLE if (CLK_get_ms() > next_print) { -- cgit v1.2.3-24-g4f1b From 4a5e68f4f29b0c4c75a68b5958dff197f4ac0f53 Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Mon, 10 Dec 2018 14:28:06 -0500 Subject: Bringing Massdrop keyboard hardware configuration to keyboard level (#4593) MCU Pins for debugging, LED, boot tracing, and shift registers are now configurable at keyboard level. Macros led_* replaced by DBG_LED_* Macros m15_* replaced by DBG_1_* Macros m27_* replaced by DBG_2_* Macros m28_* replaced by DBG_3_* For CTRL and ALT keyboards, debug boot tracing pin default now set to pad M27 instead of M28 since although M28 is not being used, it is technically a signal for USB port detection. m15_print(...) renamed to dbg_print(...) to get away from hard coded port names. dbg_print function now follows similar pattern to debug led output. --- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c') diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 13034a05d..2bda7d7c7 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -247,8 +247,13 @@ void main_subtasks(void) int main(void) { - led_ena; - m15_ena; + DBG_LED_ENA; + DBG_1_ENA; + DBG_1_OFF; + DBG_2_ENA; + DBG_2_OFF; + DBG_3_ENA; + DBG_3_OFF; debug_code_init(); @@ -256,7 +261,7 @@ int main(void) ADC0_init(); - SPI_Init(); + SR_EXP_Init(); i2c1_init(); @@ -274,8 +279,7 @@ int main(void) while (USB2422_Port_Detect_Init() == 0) {} - led_off; - m15_off; + DBG_LED_OFF; led_matrix_init(); -- cgit v1.2.3-24-g4f1b