summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/arm_atsam/main_arm_atsam.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/arm_atsam/main_arm_atsam.c')
-rw-r--r--tmk_core/protocol/arm_atsam/main_arm_atsam.c136
1 files changed, 78 insertions, 58 deletions
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 <http://www.gnu.org/licenses/>.
//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<ISSI3733_DRIVER_COUNT;drvid++)
- I2C_LED_Q_ONOFF(drvid); //Queue data
+ for (g_drvid = 0; g_drvid < ISSI3733_DRIVER_COUNT; g_drvid++)
+ I2C_LED_Q_ONOFF(g_drvid); //Queue data
keyboard_setup();
@@ -214,8 +279,6 @@ int main(void)
#ifdef VIRTSER_ENABLE
uint64_t next_print = 0;
#endif //VIRTSER_ENABLE
- uint64_t next_usb_checkup = 0;
- uint64_t next_5v_checkup = 0;
v_5v_avg = adc_get(ADC_5V);
@@ -223,58 +286,15 @@ int main(void)
while (1)
{
- if (usb_state == USB_STATE_POWERDOWN)
- {
- uint32_t timer_led = timer_read32();
-
- led_on;
- if (led_enabled)
- {
- for (drvid=0;drvid<ISSI3733_DRIVER_COUNT;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 (drvid=0;drvid<ISSI3733_DRIVER_COUNT;drvid++)
- {
- I2C3733_Control_Set(1);
- }
- }
- led_off;
- }
-
keyboard_task();
- led_matrix_task();
-
- 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();
- }
-
- 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
}