From 239f02408e219567be060be7e65e92e888304ed0 Mon Sep 17 00:00:00 2001
From: patrickmt <40182064+patrickmt@users.noreply.github.com>
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