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/common/arm_atsam/bootloader.c | 19 +++++++
tmk_core/common/arm_atsam/eeprom.c | 98 ++++++++++++++++++++++++++++++++++
tmk_core/common/arm_atsam/printf.h | 8 +++
tmk_core/common/arm_atsam/suspend.c | 17 ++++++
tmk_core/common/arm_atsam/timer.c | 59 ++++++++++++++++++++
5 files changed, 201 insertions(+)
create mode 100644 tmk_core/common/arm_atsam/bootloader.c
create mode 100644 tmk_core/common/arm_atsam/eeprom.c
create mode 100644 tmk_core/common/arm_atsam/printf.h
create mode 100644 tmk_core/common/arm_atsam/suspend.c
create mode 100644 tmk_core/common/arm_atsam/timer.c
(limited to 'tmk_core/common/arm_atsam')
diff --git a/tmk_core/common/arm_atsam/bootloader.c b/tmk_core/common/arm_atsam/bootloader.c
new file mode 100644
index 000000000..5155d9ff0
--- /dev/null
+++ b/tmk_core/common/arm_atsam/bootloader.c
@@ -0,0 +1,19 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * 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 "bootloader.h"
+
+void bootloader_jump(void) {}
diff --git a/tmk_core/common/arm_atsam/eeprom.c b/tmk_core/common/arm_atsam/eeprom.c
new file mode 100644
index 000000000..61cc039ef
--- /dev/null
+++ b/tmk_core/common/arm_atsam/eeprom.c
@@ -0,0 +1,98 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * 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 "eeprom.h"
+
+#define EEPROM_SIZE 32
+
+static uint8_t buffer[EEPROM_SIZE];
+
+uint8_t eeprom_read_byte(const uint8_t *addr) {
+ uintptr_t offset = (uintptr_t)addr;
+ return buffer[offset];
+}
+
+void eeprom_write_byte(uint8_t *addr, uint8_t value) {
+ uintptr_t offset = (uintptr_t)addr;
+ buffer[offset] = value;
+}
+
+uint16_t eeprom_read_word(const uint16_t *addr) {
+ const uint8_t *p = (const uint8_t *)addr;
+ return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
+}
+
+uint32_t eeprom_read_dword(const uint32_t *addr) {
+ const uint8_t *p = (const uint8_t *)addr;
+ return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
+ | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
+}
+
+void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+ const uint8_t *p = (const uint8_t *)addr;
+ uint8_t *dest = (uint8_t *)buf;
+ while (len--) {
+ *dest++ = eeprom_read_byte(p++);
+ }
+}
+
+void eeprom_write_word(uint16_t *addr, uint16_t value) {
+ uint8_t *p = (uint8_t *)addr;
+ eeprom_write_byte(p++, value);
+ eeprom_write_byte(p, value >> 8);
+}
+
+void eeprom_write_dword(uint32_t *addr, uint32_t value) {
+ uint8_t *p = (uint8_t *)addr;
+ eeprom_write_byte(p++, value);
+ eeprom_write_byte(p++, value >> 8);
+ eeprom_write_byte(p++, value >> 16);
+ eeprom_write_byte(p, value >> 24);
+}
+
+void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+ uint8_t *p = (uint8_t *)addr;
+ const uint8_t *src = (const uint8_t *)buf;
+ while (len--) {
+ eeprom_write_byte(p++, *src++);
+ }
+}
+
+void eeprom_update_byte(uint8_t *addr, uint8_t value) {
+ eeprom_write_byte(addr, value);
+}
+
+void eeprom_update_word(uint16_t *addr, uint16_t value) {
+ uint8_t *p = (uint8_t *)addr;
+ eeprom_write_byte(p++, value);
+ eeprom_write_byte(p, value >> 8);
+}
+
+void eeprom_update_dword(uint32_t *addr, uint32_t value) {
+ uint8_t *p = (uint8_t *)addr;
+ eeprom_write_byte(p++, value);
+ eeprom_write_byte(p++, value >> 8);
+ eeprom_write_byte(p++, value >> 16);
+ eeprom_write_byte(p, value >> 24);
+}
+
+void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
+ uint8_t *p = (uint8_t *)addr;
+ const uint8_t *src = (const uint8_t *)buf;
+ while (len--) {
+ eeprom_write_byte(p++, *src++);
+ }
+}
diff --git a/tmk_core/common/arm_atsam/printf.h b/tmk_core/common/arm_atsam/printf.h
new file mode 100644
index 000000000..582c83bf5
--- /dev/null
+++ b/tmk_core/common/arm_atsam/printf.h
@@ -0,0 +1,8 @@
+#ifndef _PRINTF_H_
+#define _PRINTF_H_
+
+#define __xprintf dpf
+int dpf(const char *_Format, ...);
+
+#endif //_PRINTF_H_
+
diff --git a/tmk_core/common/arm_atsam/suspend.c b/tmk_core/common/arm_atsam/suspend.c
new file mode 100644
index 000000000..01d1930ea
--- /dev/null
+++ b/tmk_core/common/arm_atsam/suspend.c
@@ -0,0 +1,17 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * 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 .
+ */
+
+
diff --git a/tmk_core/common/arm_atsam/timer.c b/tmk_core/common/arm_atsam/timer.c
new file mode 100644
index 000000000..bcfe5002c
--- /dev/null
+++ b/tmk_core/common/arm_atsam/timer.c
@@ -0,0 +1,59 @@
+#include "samd51j18a.h"
+#include "timer.h"
+#include "tmk_core/protocol/arm_atsam/clks.h"
+
+void set_time(uint64_t tset)
+{
+ ms_clk = tset;
+}
+
+void timer_init(void)
+{
+ ms_clk = 0;
+}
+
+uint16_t timer_read(void)
+{
+ return (uint16_t)ms_clk;
+}
+
+uint32_t timer_read32(void)
+{
+ return (uint32_t)ms_clk;
+}
+
+uint64_t timer_read64(void)
+{
+ return ms_clk;
+}
+
+uint16_t timer_elapsed(uint16_t tlast)
+{
+ return TIMER_DIFF_16(timer_read(), tlast);
+}
+
+uint32_t timer_elapsed32(uint32_t tlast)
+{
+ return TIMER_DIFF_32(timer_read32(), tlast);
+}
+
+uint32_t timer_elapsed64(uint32_t tlast)
+{
+ uint64_t tnow = timer_read64();
+ return (tnow >= tlast ? tnow - tlast : UINT64_MAX - tlast + tnow);
+}
+
+void timer_clear(void)
+{
+ ms_clk = 0;
+}
+
+void wait_ms(uint64_t msec)
+{
+ CLK_delay_ms(msec);
+}
+
+void wait_us(uint16_t usec)
+{
+ CLK_delay_us(usec);
+}
--
cgit v1.2.3-70-g09d2
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.
---
keyboards/massdrop/alt/keymaps/default/keymap.c | 14 +-
keyboards/massdrop/alt/keymaps/mac/keymap.c | 212 +++++++++++++++++++++++
keyboards/massdrop/ctrl/keymaps/default/keymap.c | 16 +-
keyboards/massdrop/ctrl/keymaps/mac/keymap.c | 12 ++
tmk_core/common/arm_atsam/bootloader.c | 32 +++-
tmk_core/protocol/arm_atsam/d51_util.c | 4 +-
tmk_core/protocol/arm_atsam/main_arm_atsam.c | 7 +-
7 files changed, 290 insertions(+), 7 deletions(-)
create mode 100644 keyboards/massdrop/alt/keymaps/mac/keymap.c
(limited to 'tmk_core/common/arm_atsam')
diff --git a/keyboards/massdrop/alt/keymaps/default/keymap.c b/keyboards/massdrop/alt/keymaps/default/keymap.c
index 3f0b84e38..9d8387bb7 100644
--- a/keyboards/massdrop/alt/keymaps/default/keymap.c
+++ b/keyboards/massdrop/alt/keymaps/default/keymap.c
@@ -19,6 +19,7 @@ enum alt_keycodes {
DBG_MTRX, //DEBUG Toggle Matrix Prints
DBG_KBD, //DEBUG Toggle Keyboard Prints
DBG_MOU, //DEBUG Toggle Mouse Prints
+ MD_BOOT, //Restart into bootloader after hold timeout
};
#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode
@@ -37,7 +38,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_MUTE, \
L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_TRNS, KC_TRNS, \
L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU, \
- KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_VOLD, \
+ KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_VOLD, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END \
),
/*
@@ -68,6 +69,8 @@ void matrix_scan_user(void) {
#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ static uint32_t key_timer;
+
switch (keycode) {
case L_BRI:
if (record->event.pressed) {
@@ -194,6 +197,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
CDC_print("\r\n");
}
return false;
+ case MD_BOOT:
+ if (record->event.pressed) {
+ key_timer = timer_read32();
+ } else {
+ if (timer_elapsed32(key_timer) >= 500) {
+ reset_keyboard();
+ }
+ }
+ return false;
default:
return true; //Process all other keycodes normally
}
diff --git a/keyboards/massdrop/alt/keymaps/mac/keymap.c b/keyboards/massdrop/alt/keymaps/mac/keymap.c
new file mode 100644
index 000000000..a8adbd3c8
--- /dev/null
+++ b/keyboards/massdrop/alt/keymaps/mac/keymap.c
@@ -0,0 +1,212 @@
+#include QMK_KEYBOARD_H
+
+enum alt_keycodes {
+ L_BRI = SAFE_RANGE, //LED Brightness Increase
+ L_BRD, //LED Brightness Decrease
+ L_PTN, //LED Pattern Select Next
+ L_PTP, //LED Pattern Select Previous
+ L_PSI, //LED Pattern Speed Increase
+ L_PSD, //LED Pattern Speed Decrease
+ L_T_MD, //LED Toggle Mode
+ L_T_ONF, //LED Toggle On / Off
+ L_ON, //LED On
+ L_OFF, //LED Off
+ L_T_BR, //LED Toggle Breath Effect
+ L_T_PTD, //LED Toggle Scrolling Pattern Direction
+ U_T_AUTO, //USB Extra Port Toggle Auto Detect / Always Active
+ U_T_AGCR, //USB Toggle Automatic GCR control
+ DBG_TOG, //DEBUG Toggle On / Off
+ DBG_MTRX, //DEBUG Toggle Matrix Prints
+ DBG_KBD, //DEBUG Toggle Keyboard Prints
+ DBG_MOU, //DEBUG Toggle Mouse Prints
+ MD_BOOT, //Restart into bootloader after hold timeout
+};
+
+#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode
+
+keymap_config_t keymap_config;
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [0] = LAYOUT(
+ KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, \
+ KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_HOME, \
+ KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, \
+ KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, \
+ KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_RGUI, MO(1), KC_LEFT, KC_DOWN, KC_RGHT \
+ ),
+ [1] = LAYOUT(
+ KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_MUTE, \
+ L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_TRNS, KC_TRNS, \
+ L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU, \
+ KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_VOLD, \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END \
+ ),
+ /*
+ [X] = LAYOUT(
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
+ ),
+ */
+};
+
+const uint16_t PROGMEM fn_actions[] = {
+
+};
+
+// Runs just one time when the keyboard initializes.
+void matrix_init_user(void) {
+};
+
+// Runs constantly in the background, in a loop.
+void matrix_scan_user(void) {
+};
+
+#define MODS_SHIFT (keyboard_report->mods & MOD_BIT(KC_LSHIFT) || keyboard_report->mods & MOD_BIT(KC_RSHIFT))
+#define MODS_CTRL (keyboard_report->mods & MOD_BIT(KC_LCTL) || keyboard_report->mods & MOD_BIT(KC_RCTRL))
+#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT))
+
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ static uint32_t key_timer;
+
+ switch (keycode) {
+ case L_BRI:
+ if (record->event.pressed) {
+ if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX;
+ else gcr_desired += LED_GCR_STEP;
+ if (led_animation_breathing) gcr_breathe = gcr_desired;
+ }
+ return false;
+ case L_BRD:
+ if (record->event.pressed) {
+ if (LED_GCR_STEP > gcr_desired) gcr_desired = 0;
+ else gcr_desired -= LED_GCR_STEP;
+ if (led_animation_breathing) gcr_breathe = gcr_desired;
+ }
+ return false;
+ case L_PTN:
+ if (record->event.pressed) {
+ if (led_animation_id == led_setups_count - 1) led_animation_id = 0;
+ else led_animation_id++;
+ }
+ return false;
+ case L_PTP:
+ if (record->event.pressed) {
+ if (led_animation_id == 0) led_animation_id = led_setups_count - 1;
+ else led_animation_id--;
+ }
+ return false;
+ case L_PSI:
+ if (record->event.pressed) {
+ led_animation_speed += ANIMATION_SPEED_STEP;
+ }
+ return false;
+ case L_PSD:
+ if (record->event.pressed) {
+ led_animation_speed -= ANIMATION_SPEED_STEP;
+ if (led_animation_speed < 0) led_animation_speed = 0;
+ }
+ return false;
+ case L_T_MD:
+ if (record->event.pressed) {
+ led_lighting_mode++;
+ if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL;
+ }
+ return false;
+ case L_T_ONF:
+ if (record->event.pressed) {
+ led_enabled = !led_enabled;
+ I2C3733_Control_Set(led_enabled);
+ }
+ return false;
+ case L_ON:
+ if (record->event.pressed) {
+ led_enabled = 1;
+ I2C3733_Control_Set(led_enabled);
+ }
+ return false;
+ case L_OFF:
+ if (record->event.pressed) {
+ led_enabled = 0;
+ I2C3733_Control_Set(led_enabled);
+ }
+ return false;
+ case L_T_BR:
+ if (record->event.pressed) {
+ led_animation_breathing = !led_animation_breathing;
+ if (led_animation_breathing)
+ {
+ gcr_breathe = gcr_desired;
+ led_animation_breathe_cur = BREATHE_MIN_STEP;
+ breathe_dir = 1;
+ }
+ }
+ return false;
+ case L_T_PTD:
+ if (record->event.pressed) {
+ led_animation_direction = !led_animation_direction;
+ }
+ return false;
+ case U_T_AUTO:
+ if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
+ usb_extra_manual = !usb_extra_manual;
+ CDC_print("USB extra port manual mode ");
+ CDC_print(usb_extra_manual ? "enabled" : "disabled");
+ CDC_print("\r\n");
+ }
+ return false;
+ case U_T_AGCR:
+ if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
+ usb_gcr_auto = !usb_gcr_auto;
+ CDC_print("USB GCR auto mode ");
+ CDC_print(usb_gcr_auto ? "enabled" : "disabled");
+ CDC_print("\r\n");
+ }
+ return false;
+ case DBG_TOG:
+ if (record->event.pressed) {
+ debug_enable = !debug_enable;
+ CDC_print("Debug mode ");
+ CDC_print(debug_enable ? "enabled" : "disabled");
+ CDC_print("\r\n");
+ }
+ return false;
+ case DBG_MTRX:
+ if (record->event.pressed) {
+ debug_matrix = !debug_matrix;
+ CDC_print("Debug matrix ");
+ CDC_print(debug_matrix ? "enabled" : "disabled");
+ CDC_print("\r\n");
+ }
+ return false;
+ case DBG_KBD:
+ if (record->event.pressed) {
+ debug_keyboard = !debug_keyboard;
+ CDC_print("Debug keyboard ");
+ CDC_print(debug_keyboard ? "enabled" : "disabled");
+ CDC_print("\r\n");
+ }
+ return false;
+ case DBG_MOU:
+ if (record->event.pressed) {
+ debug_mouse = !debug_mouse;
+ CDC_print("Debug mouse ");
+ CDC_print(debug_mouse ? "enabled" : "disabled");
+ CDC_print("\r\n");
+ }
+ return false;
+ case MD_BOOT:
+ if (record->event.pressed) {
+ key_timer = timer_read32();
+ } else {
+ if (timer_elapsed32(key_timer) >= 500) {
+ reset_keyboard();
+ }
+ }
+ return false;
+ default:
+ return true; //Process all other keycodes normally
+ }
+}
diff --git a/keyboards/massdrop/ctrl/keymaps/default/keymap.c b/keyboards/massdrop/ctrl/keymaps/default/keymap.c
index ac58f336e..9bfb7fec5 100644
--- a/keyboards/massdrop/ctrl/keymaps/default/keymap.c
+++ b/keyboards/massdrop/ctrl/keymaps/default/keymap.c
@@ -19,6 +19,7 @@ enum ctrl_keycodes {
DBG_MTRX, //DEBUG Toggle Matrix Prints
DBG_KBD, //DEBUG Toggle Keyboard Prints
DBG_MOU, //DEBUG Toggle Mouse Prints
+ MD_BOOT, //Restart into bootloader after hold timeout
};
#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode
@@ -39,7 +40,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_MSTP, KC_VOLU, \
L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_VOLD, \
L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
- KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
+ KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
),
/*
@@ -71,6 +72,8 @@ void matrix_scan_user(void) {
#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ static uint32_t key_timer;
+
switch (keycode) {
case L_BRI:
if (record->event.pressed) {
@@ -197,7 +200,16 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
CDC_print("\r\n");
}
return false;
+ case MD_BOOT:
+ if (record->event.pressed) {
+ key_timer = timer_read32();
+ } else {
+ if (timer_elapsed32(key_timer) >= 500) {
+ reset_keyboard();
+ }
+ }
+ return false;
default:
return true; //Process all other keycodes normally
}
-}
\ No newline at end of file
+}
diff --git a/keyboards/massdrop/ctrl/keymaps/mac/keymap.c b/keyboards/massdrop/ctrl/keymaps/mac/keymap.c
index 116aaa9a1..a03f891e8 100644
--- a/keyboards/massdrop/ctrl/keymaps/mac/keymap.c
+++ b/keyboards/massdrop/ctrl/keymaps/mac/keymap.c
@@ -19,6 +19,7 @@ enum ctrl_keycodes {
DBG_MTRX, //DEBUG Toggle Matrix Prints
DBG_KBD, //DEBUG Toggle Keyboard Prints
DBG_MOU, //DEBUG Toggle Mouse Prints
+ MD_BOOT, //Restart into bootloader after hold timeout
};
#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode
@@ -71,6 +72,8 @@ void matrix_scan_user(void) {
#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ static uint32_t key_timer;
+
switch (keycode) {
case L_BRI:
if (record->event.pressed) {
@@ -197,6 +200,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
CDC_print("\r\n");
}
return false;
+ case MD_BOOT:
+ if (record->event.pressed) {
+ key_timer = timer_read32();
+ } else {
+ if (timer_elapsed32(key_timer) >= 500) {
+ reset_keyboard();
+ }
+ }
+ return false;
default:
return true; //Process all other keycodes normally
}
diff --git a/tmk_core/common/arm_atsam/bootloader.c b/tmk_core/common/arm_atsam/bootloader.c
index 5155d9ff0..9701a6219 100644
--- a/tmk_core/common/arm_atsam/bootloader.c
+++ b/tmk_core/common/arm_atsam/bootloader.c
@@ -15,5 +15,35 @@
*/
#include "bootloader.h"
+#include "samd51j18a.h"
-void bootloader_jump(void) {}
+//Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
+void bootloader_jump(void)
+{
+ //Keyboards released with certain bootloader can not enter bootloader from app until workaround is created
+ uint8_t ver_no_jump[] = "v2.18Jun 22 2018 17:28:08";
+ uint8_t *ver_check = ver_no_jump;
+ uint8_t *boot_check = (uint8_t *)0x21A0;
+ while (*ver_check && *boot_check == *ver_check)
+ {
+ ver_check++;
+ boot_check++;
+ }
+ if (!*ver_check)
+ {
+ //Version match
+ //Software workaround would go here
+ return; //No software restart method implemented... must use hardware reset button
+ }
+
+ WDT->CTRLA.bit.ENABLE = 0;
+ while (WDT->SYNCBUSY.bit.ENABLE) {}
+ while (WDT->CTRLA.bit.ENABLE) {}
+ WDT->CONFIG.bit.WINDOW = 0;
+ WDT->CONFIG.bit.PER = 0;
+ WDT->EWCTRL.bit.EWOFFSET = 0;
+ WDT->CTRLA.bit.ENABLE = 1;
+ while (WDT->SYNCBUSY.bit.ENABLE) {}
+ while (!WDT->CTRLA.bit.ENABLE) {}
+ while (1) {} //Wait on timeout
+}
diff --git a/tmk_core/protocol/arm_atsam/d51_util.c b/tmk_core/protocol/arm_atsam/d51_util.c
index 91b58757c..bb63a9481 100644
--- a/tmk_core/protocol/arm_atsam/d51_util.c
+++ b/tmk_core/protocol/arm_atsam/d51_util.c
@@ -41,8 +41,8 @@ void m15_print(uint32_t x)
//Display unsigned 32-bit number through debug led
//Read as follows: 1230 = [*] [* *] [* * *] [**] (note zero is fast double flash)
-#define DLED_ONTIME 600000
-#define DLED_PAUSE 1000000
+#define DLED_ONTIME 1000000
+#define DLED_PAUSE 1500000
volatile uint32_t w;
void dled_print(uint32_t x, uint8_t long_pause)
{
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
---
keyboards/massdrop/alt/alt.h | 10 +
keyboards/massdrop/alt/keymaps/default/keymap.c | 35 +--
keyboards/massdrop/alt/keymaps/mac/keymap.c | 33 +--
keyboards/massdrop/alt/rules.mk | 1 +
keyboards/massdrop/ctrl/ctrl.h | 10 +
keyboards/massdrop/ctrl/keymaps/default/keymap.c | 39 +--
keyboards/massdrop/ctrl/keymaps/mac/keymap.c | 41 +---
keyboards/massdrop/ctrl/rules.mk | 1 +
.../SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld | 16 +-
tmk_core/arm_atsam.mk | 2 +-
tmk_core/common/arm_atsam/printf.h | 2 +-
tmk_core/common/print.h | 2 +-
tmk_core/protocol/arm_atsam.mk | 1 -
tmk_core/protocol/arm_atsam/arm_atsam_protocol.h | 1 -
tmk_core/protocol/arm_atsam/d51_util.h | 10 +
tmk_core/protocol/arm_atsam/main_arm_atsam.c | 136 ++++++-----
tmk_core/protocol/arm_atsam/usb/spfssf.c | 268 ---------------------
tmk_core/protocol/arm_atsam/usb/spfssf.h | 57 -----
tmk_core/protocol/arm_atsam/usb/udi_cdc.c | 8 +-
tmk_core/protocol/arm_atsam/usb/udi_cdc.h | 10 +-
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | 10 +-
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h | 2 +
22 files changed, 175 insertions(+), 520 deletions(-)
delete mode 100644 tmk_core/protocol/arm_atsam/usb/spfssf.c
delete mode 100644 tmk_core/protocol/arm_atsam/usb/spfssf.h
(limited to 'tmk_core/common/arm_atsam')
diff --git a/keyboards/massdrop/alt/alt.h b/keyboards/massdrop/alt/alt.h
index 387985512..8dfed8d2d 100644
--- a/keyboards/massdrop/alt/alt.h
+++ b/keyboards/massdrop/alt/alt.h
@@ -22,3 +22,13 @@
{ K45, KC_NO, K46, K47, K48, K49, K50, K51, K52, K53, K54, K55, K56, K57, K58, }, \
{ K59, K60, K61, KC_NO, KC_NO, KC_NO, K62, KC_NO, KC_NO, KC_NO, K63, K64, K65, K66, K67, }, \
}
+
+#define TOGGLE_FLAG_AND_PRINT(var, name) { \
+ if (var) { \
+ dprintf(name " disabled\r\n"); \
+ var = !var; \
+ } else { \
+ var = !var; \
+ dprintf(name " enabled\r\n"); \
+ } \
+ }
diff --git a/keyboards/massdrop/alt/keymaps/default/keymap.c b/keyboards/massdrop/alt/keymaps/default/keymap.c
index 0cbce8629..a5c443ffc 100644
--- a/keyboards/massdrop/alt/keymaps/default/keymap.c
+++ b/keyboards/massdrop/alt/keymaps/default/keymap.c
@@ -136,8 +136,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case L_T_BR:
if (record->event.pressed) {
led_animation_breathing = !led_animation_breathing;
- if (led_animation_breathing)
- {
+ if (led_animation_breathing) {
gcr_breathe = gcr_desired;
led_animation_breathe_cur = BREATHE_MIN_STEP;
breathe_dir = 1;
@@ -151,50 +150,32 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
case U_T_AUTO:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_extra_manual = !usb_extra_manual;
- CDC_print("USB extra port manual mode ");
- CDC_print(usb_extra_manual ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode");
}
return false;
case U_T_AGCR:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_gcr_auto = !usb_gcr_auto;
- CDC_print("USB GCR auto mode ");
- CDC_print(usb_gcr_auto ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
}
return false;
case DBG_TOG:
if (record->event.pressed) {
- debug_enable = !debug_enable;
- CDC_print("Debug mode ");
- CDC_print(debug_enable ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
}
return false;
case DBG_MTRX:
if (record->event.pressed) {
- debug_matrix = !debug_matrix;
- CDC_print("Debug matrix ");
- CDC_print(debug_matrix ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
}
return false;
case DBG_KBD:
if (record->event.pressed) {
- debug_keyboard = !debug_keyboard;
- CDC_print("Debug keyboard ");
- CDC_print(debug_keyboard ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
}
return false;
case DBG_MOU:
if (record->event.pressed) {
- debug_mouse = !debug_mouse;
- CDC_print("Debug mouse ");
- CDC_print(debug_mouse ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
}
return false;
case MD_BOOT:
@@ -209,4 +190,4 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
default:
return true; //Process all other keycodes normally
}
-}
\ No newline at end of file
+}
diff --git a/keyboards/massdrop/alt/keymaps/mac/keymap.c b/keyboards/massdrop/alt/keymaps/mac/keymap.c
index e886290e7..d6978fd80 100644
--- a/keyboards/massdrop/alt/keymaps/mac/keymap.c
+++ b/keyboards/massdrop/alt/keymaps/mac/keymap.c
@@ -136,8 +136,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case L_T_BR:
if (record->event.pressed) {
led_animation_breathing = !led_animation_breathing;
- if (led_animation_breathing)
- {
+ if (led_animation_breathing) {
gcr_breathe = gcr_desired;
led_animation_breathe_cur = BREATHE_MIN_STEP;
breathe_dir = 1;
@@ -151,50 +150,32 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
case U_T_AUTO:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_extra_manual = !usb_extra_manual;
- CDC_print("USB extra port manual mode ");
- CDC_print(usb_extra_manual ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode");
}
return false;
case U_T_AGCR:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_gcr_auto = !usb_gcr_auto;
- CDC_print("USB GCR auto mode ");
- CDC_print(usb_gcr_auto ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
}
return false;
case DBG_TOG:
if (record->event.pressed) {
- debug_enable = !debug_enable;
- CDC_print("Debug mode ");
- CDC_print(debug_enable ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
}
return false;
case DBG_MTRX:
if (record->event.pressed) {
- debug_matrix = !debug_matrix;
- CDC_print("Debug matrix ");
- CDC_print(debug_matrix ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
}
return false;
case DBG_KBD:
if (record->event.pressed) {
- debug_keyboard = !debug_keyboard;
- CDC_print("Debug keyboard ");
- CDC_print(debug_keyboard ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
}
return false;
case DBG_MOU:
if (record->event.pressed) {
- debug_mouse = !debug_mouse;
- CDC_print("Debug mouse ");
- CDC_print(debug_mouse ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
}
return false;
case MD_BOOT:
diff --git a/keyboards/massdrop/alt/rules.mk b/keyboards/massdrop/alt/rules.mk
index daf679585..c5539158f 100644
--- a/keyboards/massdrop/alt/rules.mk
+++ b/keyboards/massdrop/alt/rules.mk
@@ -30,3 +30,4 @@ FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
VIRTSER_ENABLE = no # USB Serial Driver
RAW_ENABLE = no # Raw device
+AUTO_SHIFT_ENABLE = no # Auto Shift
diff --git a/keyboards/massdrop/ctrl/ctrl.h b/keyboards/massdrop/ctrl/ctrl.h
index dc7c7eabe..c83efca16 100644
--- a/keyboards/massdrop/ctrl/ctrl.h
+++ b/keyboards/massdrop/ctrl/ctrl.h
@@ -30,3 +30,13 @@
{ K59, K60, K61, K62, K63, K76, K50, K33 }, \
{ K72, K73, K74, K75, K85, K86, K87, }, \
}
+
+#define TOGGLE_FLAG_AND_PRINT(var, name) { \
+ if (var) { \
+ dprintf(name " disabled\r\n"); \
+ var = !var; \
+ } else { \
+ var = !var; \
+ dprintf(name " enabled\r\n"); \
+ } \
+ }
diff --git a/keyboards/massdrop/ctrl/keymaps/default/keymap.c b/keyboards/massdrop/ctrl/keymaps/default/keymap.c
index 9bfb7fec5..88c1ac312 100644
--- a/keyboards/massdrop/ctrl/keymaps/default/keymap.c
+++ b/keyboards/massdrop/ctrl/keymaps/default/keymap.c
@@ -33,7 +33,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, \
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \
- KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \
+ KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \
),
[1] = LAYOUT(
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, KC_TRNS, KC_TRNS, \
@@ -41,7 +41,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_VOLD, \
L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
- KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
),
/*
[X] = LAYOUT(
@@ -50,7 +50,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
- KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
),
*/
};
@@ -139,8 +139,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case L_T_BR:
if (record->event.pressed) {
led_animation_breathing = !led_animation_breathing;
- if (led_animation_breathing)
- {
+ if (led_animation_breathing) {
gcr_breathe = gcr_desired;
led_animation_breathe_cur = BREATHE_MIN_STEP;
breathe_dir = 1;
@@ -154,50 +153,32 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
case U_T_AUTO:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_extra_manual = !usb_extra_manual;
- CDC_print("USB extra port manual mode ");
- CDC_print(usb_extra_manual ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode");
}
return false;
case U_T_AGCR:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_gcr_auto = !usb_gcr_auto;
- CDC_print("USB GCR auto mode ");
- CDC_print(usb_gcr_auto ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
}
return false;
case DBG_TOG:
if (record->event.pressed) {
- debug_enable = !debug_enable;
- CDC_print("Debug mode ");
- CDC_print(debug_enable ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
}
return false;
case DBG_MTRX:
if (record->event.pressed) {
- debug_matrix = !debug_matrix;
- CDC_print("Debug matrix ");
- CDC_print(debug_matrix ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
}
return false;
case DBG_KBD:
if (record->event.pressed) {
- debug_keyboard = !debug_keyboard;
- CDC_print("Debug keyboard ");
- CDC_print(debug_keyboard ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
}
return false;
case DBG_MOU:
if (record->event.pressed) {
- debug_mouse = !debug_mouse;
- CDC_print("Debug mouse ");
- CDC_print(debug_mouse ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
}
return false;
case MD_BOOT:
diff --git a/keyboards/massdrop/ctrl/keymaps/mac/keymap.c b/keyboards/massdrop/ctrl/keymaps/mac/keymap.c
index a03f891e8..6c5dfe19c 100644
--- a/keyboards/massdrop/ctrl/keymaps/mac/keymap.c
+++ b/keyboards/massdrop/ctrl/keymaps/mac/keymap.c
@@ -33,15 +33,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, \
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \
- KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_RGUI, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \
+ KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_RGUI, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \
),
[1] = LAYOUT(
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, KC_TRNS, KC_TRNS, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_MSTP, KC_VOLU, \
L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_VOLD, \
L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
- KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
- KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
+ KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
),
/*
[X] = LAYOUT(
@@ -50,7 +50,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
- KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \
),
*/
};
@@ -139,8 +139,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case L_T_BR:
if (record->event.pressed) {
led_animation_breathing = !led_animation_breathing;
- if (led_animation_breathing)
- {
+ if (led_animation_breathing) {
gcr_breathe = gcr_desired;
led_animation_breathe_cur = BREATHE_MIN_STEP;
breathe_dir = 1;
@@ -154,50 +153,32 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
case U_T_AUTO:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_extra_manual = !usb_extra_manual;
- CDC_print("USB extra port manual mode ");
- CDC_print(usb_extra_manual ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode");
}
return false;
case U_T_AGCR:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
- usb_gcr_auto = !usb_gcr_auto;
- CDC_print("USB GCR auto mode ");
- CDC_print(usb_gcr_auto ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
}
return false;
case DBG_TOG:
if (record->event.pressed) {
- debug_enable = !debug_enable;
- CDC_print("Debug mode ");
- CDC_print(debug_enable ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
}
return false;
case DBG_MTRX:
if (record->event.pressed) {
- debug_matrix = !debug_matrix;
- CDC_print("Debug matrix ");
- CDC_print(debug_matrix ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
}
return false;
case DBG_KBD:
if (record->event.pressed) {
- debug_keyboard = !debug_keyboard;
- CDC_print("Debug keyboard ");
- CDC_print(debug_keyboard ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
}
return false;
case DBG_MOU:
if (record->event.pressed) {
- debug_mouse = !debug_mouse;
- CDC_print("Debug mouse ");
- CDC_print(debug_mouse ? "enabled" : "disabled");
- CDC_print("\r\n");
+ TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
}
return false;
case MD_BOOT:
diff --git a/keyboards/massdrop/ctrl/rules.mk b/keyboards/massdrop/ctrl/rules.mk
index daf679585..c5539158f 100644
--- a/keyboards/massdrop/ctrl/rules.mk
+++ b/keyboards/massdrop/ctrl/rules.mk
@@ -30,3 +30,4 @@ FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
VIRTSER_ENABLE = no # USB Serial Driver
RAW_ENABLE = no # Raw device
+AUTO_SHIFT_ENABLE = no # Auto Shift
diff --git a/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld b/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
index 3d114f5b7..35db61971 100644
--- a/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
+++ b/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
@@ -35,7 +35,7 @@ SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
- //rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
+/*rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000*/
rom (rx) : ORIGIN = 0x00004000, LENGTH = 0x0003C000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
bkupram (rwx) : ORIGIN = 0x47000000, LENGTH = 0x00002000
@@ -45,6 +45,9 @@ MEMORY
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x8000;
+/* The heap size used by the application. */
+HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : DEFINED(__heap_size__) ? __heap_size__ : 0x800;
+
_srom = ORIGIN(rom);
_lrom = LENGTH(rom);
_erom = ORIGIN(rom) + LENGTH(rom);
@@ -153,6 +156,17 @@ SECTIONS
_ezero = .;
} > ram
+ /* .heap section for syscalls */
+ .heap (NOLOAD) :
+ {
+ . = ALIGN(4);
+ _end = .;
+ end = .;
+ _heap_start = .;
+ . = . + HEAP_SIZE;
+ _heap_end = .;
+ } > ram
+
/* stack section */
.stack (NOLOAD):
{
diff --git a/tmk_core/arm_atsam.mk b/tmk_core/arm_atsam.mk
index ef412d59d..06823fb62 100644
--- a/tmk_core/arm_atsam.mk
+++ b/tmk_core/arm_atsam.mk
@@ -36,7 +36,7 @@ LDFLAGS +=-Wl,--gc-sections
LDFLAGS += -Wl,-Map="%OUT%%PROJ_NAME%.map"
LDFLAGS += -Wl,--start-group
LDFLAGS += -Wl,--end-group
-LDFLAGS += -Wl,--gc-sections
+LDFLAGS += --specs=rdimon.specs
LDFLAGS += -T$(LIB_PATH)/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
OPT_DEFS += -DPROTOCOL_ARM_ATSAM
diff --git a/tmk_core/common/arm_atsam/printf.h b/tmk_core/common/arm_atsam/printf.h
index 582c83bf5..3206b40bd 100644
--- a/tmk_core/common/arm_atsam/printf.h
+++ b/tmk_core/common/arm_atsam/printf.h
@@ -1,8 +1,8 @@
#ifndef _PRINTF_H_
#define _PRINTF_H_
-#define __xprintf dpf
int dpf(const char *_Format, ...);
+#define __xprintf dpf
#endif //_PRINTF_H_
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index 9cbe67bad..d94527657 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -29,7 +29,7 @@
#include
#include "util.h"
-#if defined(PROTOCOL_CHIBIOS)
+#if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM)
#define PSTR(x) x
#endif
diff --git a/tmk_core/protocol/arm_atsam.mk b/tmk_core/protocol/arm_atsam.mk
index d535b64cd..04e02790a 100644
--- a/tmk_core/protocol/arm_atsam.mk
+++ b/tmk_core/protocol/arm_atsam.mk
@@ -10,7 +10,6 @@ SRC += $(ARM_ATSAM_DIR)/spi.c
SRC += $(ARM_ATSAM_DIR)/startup.c
SRC += $(ARM_ATSAM_DIR)/usb/main_usb.c
-SRC += $(ARM_ATSAM_DIR)/usb/spfssf.c
SRC += $(ARM_ATSAM_DIR)/usb/udc.c
SRC += $(ARM_ATSAM_DIR)/usb/udi_cdc.c
SRC += $(ARM_ATSAM_DIR)/usb/udi_hid.c
diff --git a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h
index be73beccd..2ba099174 100644
--- a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h
+++ b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h
@@ -36,7 +36,6 @@ along with this program. If not, see .
#include "issi3733_driver.h"
#include "./usb/compiler.h"
#include "./usb/udc.h"
-#include "./usb/spfssf.h"
#include "./usb/udi_cdc.h"
#endif //MD_BOOTLOADER
diff --git a/tmk_core/protocol/arm_atsam/d51_util.h b/tmk_core/protocol/arm_atsam/d51_util.h
index 465889c7c..7a35f7989 100644
--- a/tmk_core/protocol/arm_atsam/d51_util.h
+++ b/tmk_core/protocol/arm_atsam/d51_util.h
@@ -32,6 +32,16 @@ along with this program. If not, see .
#define m15_on REG_PORT_OUTSET1 = 0x40000000 //PB30 High
#define m15_off REG_PORT_OUTCLR1 = 0x40000000 //PB30 Low
+//Debug Port PB23
+#define m27_ena REG_PORT_DIRSET1 = 0x800000 //PB23 Output
+#define m27_on REG_PORT_OUTSET1 = 0x800000 //PB23 High
+#define m27_off REG_PORT_OUTCLR1 = 0x800000 //PB23 Low
+
+//Debug Port PB31
+#define m28_ena REG_PORT_DIRSET1 = 0x80000000 //PB31 Output
+#define m28_on REG_PORT_OUTSET1 = 0x80000000 //PB31 High
+#define m28_off REG_PORT_OUTCLR1 = 0x80000000 //PB31 Low
+
#define m15_loop(M15X) {uint8_t M15L=M15X; while(M15L--){m15_on;CLK_delay_us(1);m15_off;}}
void m15_print(uint32_t x);
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
}
diff --git a/tmk_core/protocol/arm_atsam/usb/spfssf.c b/tmk_core/protocol/arm_atsam/usb/spfssf.c
deleted file mode 100644
index 449a8bb7d..000000000
--- a/tmk_core/protocol/arm_atsam/usb/spfssf.c
+++ /dev/null
@@ -1,268 +0,0 @@
-#include "samd51j18a.h"
-#include "stdarg.h"
-#include "spfssf.h"
-#include "usb_util.h"
-
-int vspf(char *_Dest, const char *_Format, va_list va)
-{
- //va_list va; //Variable argument list variable
- char *d = _Dest; //Pointer to dest
-
- //va_start(va,_Format); //Initialize the variable argument list
- while (*_Format) //While not end of format string
- {
- if (*_Format == SPF_SPEC_START) //If current format string character is the specifier start character
- {
- _Format++; //Skip over the character
- while (*_Format && *_Format <= 64) _Format++; //Forward past any options
- if (*_Format == SPF_SPEC_START) *d++ = *_Format; //If the character is the specifier start character, output the character and advance dest
- else if (*_Format == SPF_SPEC_LONG) //If the character is the long type
- {
- _Format++; //Skip over the character
- if (*_Format == SPF_SPEC_DECIMAL) //If the character is the decimal type
- {
- int64_t buf = va_arg(va,int64_t); //Get the next value from the va list
- //if (buf < 0) { *d++ = '-'; buf = -buf; } //If the given number is negative, add a negative sign to the dest and invert number
- //spf_uint2str_32_3t(&d,buf,32); //Perform the conversion
- d += UTIL_ltoa_radix(buf, d, 10);
- }
- else if (*_Format == SPF_SPEC_UNSIGNED) //If the character is the unsigned type
- {
- uint64_t num = va_arg(va,uint64_t); //Get the next value from the va list
- //spf_uint2str_32_3t(&d,num,32); //Perform the conversion
- d += UTIL_ltoa_radix(num, d, 10);
- }
- else if (*_Format == SPF_SPEC_UHINT || *_Format == SPF_SPEC_UHINT_UP) //If the character is the unsigned type
- {
- uint64_t buf = va_arg(va,uint64_t); //Get the next value from the va list
- //spf_uint2hex_32(&d,(unsigned long) buf);
- d += UTIL_ltoa_radix(buf, d, 16);
- }
- else //If the character was not a known type
- {
- *d++ = SPF_SPEC_START; //Output the start specifier
- *d++ = SPF_SPEC_LONG; //Output the long type
- *d++ = *_Format; //Output the unknown type
- }
- }
- else if (*_Format == SPF_SPEC_DECIMAL) //If the character is the decimal type
- {
- int buf = va_arg(va,int); //Get the next value from the va list
- //if (buf < 0) { *d++ = '-'; buf = -buf; } //If the given number is negative, add a negative sign to the dest and invert number
- //spf_uint2str_32_3t(&d,buf,16); //Perform the conversion
- d += UTIL_itoa(buf, d);
- }
- else if (*_Format == SPF_SPEC_INT) //If the character is the integer type
- {
- int buf = va_arg(va,int); //Get the next value from the va list
- //if (buf < 0) { *d++ = '-'; buf = -buf; } //If the given number is negative, add a negative sign to the dest and inverted number
- //spf_uint2str_32_3t(&d,buf,16); //Perform the conversion
- d += UTIL_itoa(buf, d);
- }
- else if (*_Format == SPF_SPEC_UINT) //If the character is the unsigned integer type
- {
- int buf = va_arg(va,int); //Get the next value from the va list
- //spf_uint2str_32_3t(&d,buf,16); //Perform the conversion
- d += UTIL_utoa(buf, d);
- }
- else if (*_Format == SPF_SPEC_STRING) //If the character is the string type
- {
- char *buf = va_arg(va,char*); //Get the next value from the va list
- while (*buf) *d++ = *buf++; //Perform the conversion (simply output characters and adcance pointers)
- }
- else if (*_Format == SPF_SPEC_UHINT || *_Format == SPF_SPEC_UHINT_UP) //If the character is the short type
- {
- int buf = va_arg(va,unsigned int); //Get the next value from the va list
- //spf_uint2hex_32(&d,(unsigned long) buf); //Perform the conversion
- d += UTIL_utoa(buf, d);
- }
- else //If the character type is unknown
- {
- *d++ = SPF_SPEC_START; //Output the start specifier
- *d++ = *_Format; //Output the unknown type
- }
- }
- else *d++ = *_Format; //If the character is unknown, output it to dest and advance dest
- _Format++; //Advance the format buffer pointer to next character
- }
- //va_end(va); //End the variable argument list
-
- *d = '\0'; //Cap off the destination string with a zero
-
- return d - _Dest; //Return the length of the destintion buffer
-}
-
-int spf(char *_Dest, const char *_Format, ...)
-{
- va_list va; //Variable argument list variable
- int result;
-
- va_start(va,_Format); //Initialize the variable argument list
- result = vspf(_Dest, _Format, va);
- va_end(va);
- return result;
-}
-
-//sscanf string to number (integer types)
-int64_t ssf_ston(const char **_Src, uint32_t count, uint32_t *conv_count)
-{
- int64_t value = 0; //Return value accumulator
- uint32_t counter=count; //Counter to keep track of numbers converted
- const char* p; //Pointer to first non space character
-
- while (*(*_Src) == SSF_SKIP_SPACE) (*_Src)++; //Forward through the whitespace to next non whitespace
-
- p = (*_Src); //Set pointer to first non space character
- if (*p == '+' || *p == '-') (*_Src)++; //Skip over sign if any
- while (*(*_Src) >= ASCII_NUM_START &&
- *(*_Src) <= ASCII_NUM_END &&
- counter) //While the source character is a digit and counter is not zero
- {
- value *= 10; //Multiply result by 10 to make room for next 1's place number
- value += *(*_Src)++ - ASCII_NUM_START; //Add source number to value
- counter--; //Decrement counter
- }
- if (counter - count == 0) return 0; //If no number conversion were performed, return 0
- if (*p == '-') value = -value; //If the number given was negative, make the result negative
-
- if (conv_count) (*conv_count)++; //Increment the converted count
- return value; //Return the value
-}
-
-uint64_t ssf_hton(const char **_Src, uint32_t count,uint32_t *conv_count)
-{
- int64_t value=0; //Return value accumulator
- uint32_t counter=count; //Counter to keep track of numbers converted
- //const char* p; //Pointer to first non space character
- char c;
-
- while (*(*_Src) == SSF_SKIP_SPACE) (*_Src)++; //Forward through the whitespace to next non whitespace
-
- //p = (*_Src); //Set pointer to first non space character
-
- while (counter)
- {
- c = *(*_Src)++;
- if (c >= 'a' && c <= 'f') c -= ('a'-'A'); //toupper
- if (c < '0' || (c > '9' && c < 'A') || c > 'F') break;
- value *= 16; //Multiply result by 10 to make room for next 1's place number
- c = c - '0';
- if (c > 9) c -= 7;
- value += c; //Add source number to value
- counter--; //Decrement counter
- }
-
- if (counter - count == 0) return 0; //If no number conversion were performed, return 0
- //if (*p == '-') value = -value; //If the number given was negative, make the result negative
-
- if (conv_count) (*conv_count)++; //Increment the converted count
- return value;
-}
-
-//sscanf
-int ssf(const char *_Src, const char *_Format, ...)
-{
- va_list va; //Variable argument list variable
- unsigned char looking_for=0; //Static char specified in format to be found in source
- uint32_t conv_count=0; //Count of conversions made
-
- va_start(va,_Format); //Initialize the variable argument list
- while (*_Format) //While the format string has not been fully read
- {
- if (looking_for != 0) //If we are looking for a matching character in the source string
- {
- while (*_Src != looking_for && *_Src) _Src++; //While the character is not found in the source string and not the end of the source
- // string, increment the pointer position
- if (*_Src == looking_for) _Src++; //If the character was found, step over it
- else break; //Else the end was reached and the scan is now invalid (Could not find static character)
- looking_for = 0; //Clear the looking for character
- }
- if (*_Format == SSF_SPEC_START) //If the current format character is the specifier start character
- {
- _Format++; //Step over the specifier start character
- if (*_Format == SSF_SPEC_DECIMAL) //If the decimal specifier type is found
- {
- int *value=va_arg(va,int*); //User given destination address
- //*value = (int)ssf_ston(&_Src,5,&conv_count); //Run conversion
- *value = (int)ssf_ston(&_Src,10,&conv_count); //Run conversion
- }
- else if (*_Format == SSF_SPEC_LONG) //If the long specifier type is found
- {
- _Format++; //Skip over the specifier type
- if (*_Format == SSF_SPEC_DECIMAL) //If the decimal specifier type is found
- {
- int64_t *value=va_arg(va,int64_t*); //User given destination address
- //*value = (int64_t)ssf_ston(&_Src,10,&conv_count); //Run conversion
- *value = (int64_t)ssf_ston(&_Src,19,&conv_count); //Run conversion
- }
- else if (*_Format == SSF_SPEC_UHINT) //If the decimal specifier type is found
- {
- uint64_t *value=va_arg(va,uint64_t *); //User given destination address
- //*value = (uint64_t int)ssf_hton(&_Src,12,&conv_count); //Run conversion
- *value = (uint64_t)ssf_hton(&_Src,16,&conv_count); //Run conversion
- }
- }
- else if (*_Format == SSF_SPEC_SHORTINT) //If the short int specifier type is found
- {
- _Format++; //Skip over the specifier type
- if (*_Format == SSF_SPEC_SHORTINT) //If the short int specifier type is found
- {
- _Format++; //Skip over the specifier type
- if (*_Format == SSF_SPEC_DECIMAL) //If the decimal specifier type is found
- {
- unsigned char *value=va_arg(va,unsigned char*); //User given destination address
- //*value = (unsigned char)ssf_ston(&_Src,3,&conv_count); //Run conversion
- *value = (unsigned char)ssf_ston(&_Src,5,&conv_count); //Run conversion
- }
- }
- }
- else if (*_Format == SSF_SPEC_STRING) //If the specifier type is string
- {
- char *value=va_arg(va,char*); //User given destination address, max chars read pointer
- while (*_Src == SSF_SKIP_SPACE) _Src++; //Forward through the whitespace to next non whitespace
- while (*_Src != SSF_SKIP_SPACE && *_Src) *value++ = *_Src++; //While any character but space and not end of string and not end location, copy char to dest
- *value = 0; //Cap off the string pointer with zero
- conv_count++; //Increment the converted count
- }
- else if (*_Format == SSF_SPEC_VERSION) //If the specifier type is string
- {
- char *value=va_arg(va,char*); //User given destination address, max chars read pointer
- while (*_Src == SSF_SKIP_SPACE) _Src++; //Forward through the whitespace to next non whitespace
- while (*_Src != SSF_DELIM_COMMA && *_Src) *value++ = *_Src++; //While any character but space and not end of string and not end location, copy char to dest
- *value = 0; //Cap off the string pointer with zero
- conv_count++; //Increment the converted count
- }
- else if (*_Format >= ASCII_NUM_START && *_Format <= ASCII_NUM_END)
- {
- uint32_t len = (uint32_t)ssf_ston(&_Format,3,NULL); //Convert the given length
- if (*_Format == SSF_SPEC_STRING) //If the specifier type is string
- {
- char *value=va_arg(va,char*),*e; //User given destination address, max chars read pointer
- while (*_Src == SSF_SKIP_SPACE) _Src++; //Forward through the whitespace to next non whitespace
- e = (char*)_Src+len; //Set a maximum length pointer location
- while (*_Src != SSF_SKIP_SPACE && *_Src && _Src != e) *value++ = *_Src++; //While any character but space and not end of string and not end location, copy char to dest
- *value = 0; //Cap off the string pointer with zero
- conv_count++; //Increment the converted count
- }
- else if (*_Format == SSF_SPEC_VERSION) //If the specifier type is string
- {
- char *value=va_arg(va,char*),*e; //User given destination address, max chars read pointer
- while (*_Src == SSF_SKIP_SPACE) _Src++; //Forward through the whitespace to next non whitespace
- e = (char*)_Src+len; //Set a maximum length pointer location
- while (*_Src != SSF_DELIM_COMMA && *_Src && _Src != e) *value++ = *_Src++; //While any character but space and not end of string and not end location, copy char to dest
- *value = 0; //Cap off the string pointer with zero
- conv_count++; //Increment the converted count
- }
- }
- else if (*_Format == SSF_SPEC_START) looking_for = *_Format; //If another start specifier character is found, output a specifier character
- else break; //Scan is now invalid (Uknown type specified)
- }
- else if (*_Format == SSF_SKIP_SPACE) { } //If a space is found, ignore it
- else looking_for = *_Format; //If any other character is found, it is static and should be found in src as well
- _Format++; //Skip over current format character
- }
-
- va_end(va); //End the variable argument list
- return conv_count; //Return the number of conversions made
-}
-
diff --git a/tmk_core/protocol/arm_atsam/usb/spfssf.h b/tmk_core/protocol/arm_atsam/usb/spfssf.h
deleted file mode 100644
index 337a904df..000000000
--- a/tmk_core/protocol/arm_atsam/usb/spfssf.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef ____spfssf_h
-#define ____spfssf_h
-
-#include
-
-#define sprintf spf
-#define sscanf ssf
-
-#define SIZEOF_OFFSET 1
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#define SPF_NONE 0
-
-#define SPF_SPEC_START 37 //%
-#define SPF_SPEC_DECIMAL 100 //d 16bit dec signed (-32767 to 32767) DONE same as i
-#define SPF_SPEC_INT 105 //i 16bit dec signed (-32767 to 32767) DONE same as d
-#define SPF_SPEC_UINT 117 //u 16bit dec unsigned (0 to 65535) DONE
-#define SPF_SPEC_STRING 115 //s variable length (abcd...) DONE
-#define SPF_SPEC_UHINT 120 //x 16bit hex lwrc (7fa) DONE
-#define SPF_SPEC_UHINT_UP 88 //x 16bit hex lwrc (7fa) DONE
-#define SPF_SPEC_LONG 108 //l start of either ld or lu DONE
-#define SPF_SPEC_DECIMAL 100 //ld 32bit dec signed (-2147483647 to 2147483647) DONE
-#define SPF_SPEC_UNSIGNED 117 //lu 32bit dec unsigned (0 to 4294967295) DONE
-#define SPF_SPEC_UHINT 120 //lx 32bit hex unsigned (0 to ffffffff) DONE
-
-#define SSF_SPEC_START 37 //%
-#define SSF_SPEC_SHORTINT 104 //h 8bit dec signed (-127 to 127) DONE
-#define SSF_LEN_SHORTINT 3 //hhd
-#define SSF_SPEC_DECIMAL 100 //d 16bit dec signed (-32767 to 32767) DONE
-#define SSF_LEN_DECIMAL 5 //32767
-#define SSF_SPEC_INT 105 //i 16bit dec signed (-32767 to 32767) DONE
-#define SSF_LEN_INT 5 //32767
-#define SSF_SPEC_LONG 108 //l start of either ld or lu DONE
-#define SSF_SPEC_DECIMAL 100 //ld 32bit dec signed (-2147483647 to 2147483647) DONE
-#define SSF_SPEC_UHINT 120 //lx 32bit hex unsigned DONE
-#define SSF_LEN_LDECIMAL 10 //2147483647
-#define SSF_SPEC_STRING 115 //s variable length (abcd...) DONE
-#define SSF_SKIP_SPACE 32 //space
-
-#define SSF_SPEC_VERSION 118 //v collect to comma delimiter - special
-#define SSF_DELIM_COMMA 44 //,
-
-#define ASCII_NUM_START 48 //0
-#define ASCII_NUM_END 58 //9
-
-#define T_UINT32_0_LIMIT 14
-#define T_UINT32_1_LIMIT 27
-
-int vspf(char *_Dest, const char *_Format, va_list va);
-int spf(char *_Dest, const char *_Format, ...);
-int ssf(const char *_Src, const char *_Format, ...);
-
-#endif //____spfssf_h
-
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_cdc.c b/tmk_core/protocol/arm_atsam/usb/udi_cdc.c
index b4159d325..15f0f760c 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_cdc.c
+++ b/tmk_core/protocol/arm_atsam/usb/udi_cdc.c
@@ -54,7 +54,6 @@
#include
#include "udi_cdc_conf.h"
#include "udi_device_conf.h"
-#include "spfssf.h"
#include "stdarg.h"
#include "tmk_core/protocol/arm_atsam/clks.h"
@@ -1259,7 +1258,6 @@ uint32_t CDC_print(char *printbuf)
return 1;
}
-
char printbuf[CDC_PRINTBUF_SIZE];
int dpf(const char *_Format, ...)
@@ -1267,8 +1265,8 @@ int dpf(const char *_Format, ...)
va_list va; //Variable argument list variable
int result;
- va_start(va,_Format); //Initialize the variable argument list
- result = vspf(printbuf, _Format, va);
+ va_start(va, _Format); //Initialize the variable argument list
+ result = vsnprintf(printbuf, CDC_PRINTBUF_SIZE, _Format, va);
va_end(va);
CDC_print(printbuf);
@@ -1377,8 +1375,6 @@ void CDC_init(void)
printbuf[0]=0;
}
-char printbuf[CDC_PRINTBUF_SIZE];
-
#endif //CDC line 62
//@}
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_cdc.h b/tmk_core/protocol/arm_atsam/usb/udi_cdc.h
index 6b70e96d0..e134cf236 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_cdc.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_cdc.h
@@ -57,8 +57,8 @@
#include "udi.h"
// Check the number of port
-#ifndef UDI_CDC_PORT_NB
-# define UDI_CDC_PORT_NB 1
+#ifndef UDI_CDC_PORT_NB
+# define UDI_CDC_PORT_NB 1
#endif
#if (UDI_CDC_PORT_NB > 1)
# error UDI_CDC_PORT_NB must be at most 1
@@ -86,9 +86,6 @@ extern UDC_DESC_STORAGE udi_api_t udi_api_cdc_data;
//! CDC data endpoints size for FS speed (8B, 16B, 32B, 64B)
#define UDI_CDC_DATA_EPS_FS_SIZE CDC_RX_SIZE
-#define CDC_PRINT_BUF_SIZE 256
-extern char printbuf[CDC_PRINT_BUF_SIZE];
-
//@}
/**
@@ -371,9 +368,6 @@ uint32_t CDC_print(char *printbuf);
uint32_t CDC_input(void);
void CDC_init(void);
-#define __xprintf dpf
-int dpf(const char *_Format, ...);
-
#ifdef __cplusplus
}
#endif
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
index 18f69350c..1a6f7905e 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
@@ -45,6 +45,7 @@
*/
#include "samd51j18a.h"
+#include "d51_util.h"
#include "conf_usb.h"
#include "usb_protocol.h"
#include "udd.h"
@@ -86,7 +87,7 @@ bool udi_hid_kbd_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_kbd_report[UDI_HID_KBD_REPORT_SIZE];
-static bool udi_hid_kbd_b_report_trans_ongoing;
+volatile bool udi_hid_kbd_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_kbd_report_trans[UDI_HID_KBD_REPORT_SIZE];
@@ -186,8 +187,7 @@ bool udi_hid_kbd_send_report(void)
return false;
}
- memcpy(udi_hid_kbd_report_trans, udi_hid_kbd_report,
- UDI_HID_KBD_REPORT_SIZE);
+ memcpy(udi_hid_kbd_report_trans, udi_hid_kbd_report, UDI_HID_KBD_REPORT_SIZE);
udi_hid_kbd_b_report_valid = false;
udi_hid_kbd_b_report_trans_ongoing =
udd_ep_run(UDI_HID_KBD_EP_IN | USB_EP_DIR_IN,
@@ -249,7 +249,7 @@ bool udi_hid_nkro_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_nkro_report[UDI_HID_NKRO_REPORT_SIZE];
-static bool udi_hid_nkro_b_report_trans_ongoing;
+volatile bool udi_hid_nkro_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_nkro_report_trans[UDI_HID_NKRO_REPORT_SIZE];
@@ -355,7 +355,7 @@ bool udi_hid_nkro_send_report(void)
return false;
}
- memcpy(udi_hid_nkro_report_trans, udi_hid_nkro_report,UDI_HID_NKRO_REPORT_SIZE);
+ memcpy(udi_hid_nkro_report_trans, udi_hid_nkro_report, UDI_HID_NKRO_REPORT_SIZE);
udi_hid_nkro_b_report_valid = false;
udi_hid_nkro_b_report_trans_ongoing =
udd_ep_run(UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN,
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
index 9a2741534..babfdb7a7 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
@@ -60,6 +60,7 @@ extern "C" {
#ifdef KBD
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd;
extern bool udi_hid_kbd_b_report_valid;
+extern volatile bool udi_hid_kbd_b_report_trans_ongoing;
extern uint8_t udi_hid_kbd_report_set;
bool udi_hid_kbd_send_report(void);
#endif //KBD
@@ -70,6 +71,7 @@ bool udi_hid_kbd_send_report(void);
#ifdef NKRO
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_nkro;
extern bool udi_hid_nkro_b_report_valid;
+extern volatile bool udi_hid_nkro_b_report_trans_ongoing;
bool udi_hid_nkro_send_report(void);
#endif //NKRO
--
cgit v1.2.3-70-g09d2
From daf0cc60bff54be948c923cdc40aa80b82a27f6d Mon Sep 17 00:00:00 2001
From: patrickmt <40182064+patrickmt@users.noreply.github.com>
Date: Fri, 28 Sep 2018 22:34:56 -0400
Subject: CTRL keyboard bootloader_jump support
Adds support for CTRL keyboards to enter bootloader via bootloader_jump()
---
.../SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld | 3 ++
tmk_core/common/arm_atsam/bootloader.c | 32 ++++++++++++----------
tmk_core/protocol/arm_atsam/md_bootloader.h | 7 +++++
tmk_core/protocol/arm_atsam/startup.c | 11 ++++++++
4 files changed, 38 insertions(+), 15 deletions(-)
(limited to 'tmk_core/common/arm_atsam')
diff --git a/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld b/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
index 35db61971..1c6354786 100644
--- a/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
+++ b/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld
@@ -51,6 +51,9 @@ HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : DEFINED(__heap_size__) ? __heap_siz
_srom = ORIGIN(rom);
_lrom = LENGTH(rom);
_erom = ORIGIN(rom) + LENGTH(rom);
+_sram = ORIGIN(ram);
+_lram = LENGTH(ram);
+_eram = ORIGIN(ram) + LENGTH(ram);
/* Section Definitions */
SECTIONS
diff --git a/tmk_core/common/arm_atsam/bootloader.c b/tmk_core/common/arm_atsam/bootloader.c
index 9701a6219..ba71bfeb0 100644
--- a/tmk_core/common/arm_atsam/bootloader.c
+++ b/tmk_core/common/arm_atsam/bootloader.c
@@ -16,25 +16,27 @@
#include "bootloader.h"
#include "samd51j18a.h"
+#include "md_bootloader.h"
//Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
-void bootloader_jump(void)
-{
- //Keyboards released with certain bootloader can not enter bootloader from app until workaround is created
- uint8_t ver_no_jump[] = "v2.18Jun 22 2018 17:28:08";
- uint8_t *ver_check = ver_no_jump;
- uint8_t *boot_check = (uint8_t *)0x21A0;
- while (*ver_check && *boot_check == *ver_check)
- {
- ver_check++;
- boot_check++;
+void bootloader_jump(void) {
+#ifdef KEYBOARD_massdrop_ctrl
+ //CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
+ uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; //The version to match (NULL terminated by compiler)
+ uint8_t *ver_check = ver_ram_method; //Pointer to version match string for traversal
+ uint8_t *ver_rom = (uint8_t *)0x21A0; //Pointer to address in ROM where this specific bootloader version would exist
+
+ while (*ver_check && *ver_rom == *ver_check) { //While there are check version characters to match and bootloader's version matches check's version
+ ver_check++; //Move check version pointer to next character
+ ver_rom++; //Move ROM version pointer to next character
}
- if (!*ver_check)
- {
- //Version match
- //Software workaround would go here
- return; //No software restart method implemented... must use hardware reset button
+
+ if (!*ver_check) { //If check version pointer is NULL, all characters have matched
+ *MAGIC_ADDR = BOOTLOADER_MAGIC; //Set magic number into RAM
+ NVIC_SystemReset(); //Perform system reset
+ while (1) {} //Won't get here
}
+#endif
WDT->CTRLA.bit.ENABLE = 0;
while (WDT->SYNCBUSY.bit.ENABLE) {}
diff --git a/tmk_core/protocol/arm_atsam/md_bootloader.h b/tmk_core/protocol/arm_atsam/md_bootloader.h
index 1316876c8..956145c31 100644
--- a/tmk_core/protocol/arm_atsam/md_bootloader.h
+++ b/tmk_core/protocol/arm_atsam/md_bootloader.h
@@ -7,6 +7,13 @@ extern uint32_t _erom;
#define BOOTLOADER_SERIAL_MAX_SIZE 20 //DO NOT MODIFY!
+#ifdef KEYBOARD_massdrop_ctrl
+//WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
+extern uint32_t _eram;
+#define BOOTLOADER_MAGIC 0x3B9ACA00
+#define MAGIC_ADDR (uint32_t *)(&_eram - 4)
+#endif
+
#ifdef MD_BOOTLOADER
#define MCU_HZ 48000000
diff --git a/tmk_core/protocol/arm_atsam/startup.c b/tmk_core/protocol/arm_atsam/startup.c
index a62d02f1c..f29fac179 100644
--- a/tmk_core/protocol/arm_atsam/startup.c
+++ b/tmk_core/protocol/arm_atsam/startup.c
@@ -28,6 +28,7 @@
*/
#include "samd51.h"
+#include "md_bootloader.h"
/* Initialize segments */
extern uint32_t _sfixed;
@@ -500,6 +501,16 @@ const DeviceVectors exception_table = {
*/
void Reset_Handler(void)
{
+#ifdef KEYBOARD_massdrop_ctrl
+ /* WARNING: This is only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support */
+ if (*MAGIC_ADDR == BOOTLOADER_MAGIC) {
+ /* At this point, the bootloader's memory is initialized properly, so undo the jump to here, then jump back */
+ *MAGIC_ADDR = 0x00000000; /* Change value to prevent potential bootloader entrance loop */
+ __set_MSP(0x20008818); /* MSP according to bootloader */
+ SCB->VTOR = 0x00000000; /* Vector table back to bootloader's */
+ asm("bx %0"::"r"(0x00001267)); /* Jump past bootloader RCAUSE check using THUMB */
+ }
+#endif
uint32_t *pSrc, *pDest;
/* Initialize the relocate segment */
--
cgit v1.2.3-70-g09d2
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/common.mk | 1 +
tmk_core/common/arm_atsam/printf.c | 66 ++++++++++
tmk_core/common/arm_atsam/printf.h | 7 +-
tmk_core/protocol/arm_atsam/main_arm_atsam.c | 12 +-
tmk_core/protocol/arm_atsam/usb/conf_usb.h | 5 +
tmk_core/protocol/arm_atsam/usb/main_usb.c | 14 ++
tmk_core/protocol/arm_atsam/usb/udi_cdc.c | 4 +-
tmk_core/protocol/arm_atsam/usb/udi_cdc.h | 1 +
tmk_core/protocol/arm_atsam/usb/udi_device_conf.h | 88 +++++++++++--
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | 146 +++++++++++++++++++++
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h | 11 ++
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c | 6 +
tmk_core/protocol/arm_atsam/usb/usb_main.h | 6 +
13 files changed, 347 insertions(+), 20 deletions(-)
create mode 100644 tmk_core/common/arm_atsam/printf.c
(limited to 'tmk_core/common/arm_atsam')
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 319d196ae..4a0f7dcf9 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -43,6 +43,7 @@ endif
endif
ifeq ($(PLATFORM),ARM_ATSAM)
+ TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
endif
diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c
new file mode 100644
index 000000000..d49d234de
--- /dev/null
+++ b/tmk_core/common/arm_atsam/printf.c
@@ -0,0 +1,66 @@
+/*
+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 .
+*/
+
+#ifdef CONSOLE_PRINT
+
+#include "samd51j18a.h"
+#include "arm_atsam_protocol.h"
+#include "printf.h"
+#include
+#include
+
+void console_printf(char *fmt, ...) {
+ while (udi_hid_con_b_report_trans_ongoing) {} //Wait for any previous transfers to complete
+
+ static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; //Print and send buffer
+ va_list va;
+ int result;
+
+ va_start(va, fmt);
+ result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va);
+ va_end(va);
+
+ uint32_t irqflags;
+ char *pconbuf = console_printbuf; //Pointer to start send from
+ int send_out = CONSOLE_EPSIZE; //Bytes to send per transfer
+
+ while (result > 0) { //While not error and bytes remain
+ while (udi_hid_con_b_report_trans_ongoing) {} //Wait for any previous transfers to complete
+
+ irqflags = __get_PRIMASK();
+ __disable_irq();
+ __DMB();
+
+ if (result < CONSOLE_EPSIZE) { //If remaining bytes are less than console epsize
+ memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); //Clear the buffer
+ send_out = result; //Send remaining size
+ }
+
+ memcpy(udi_hid_con_report, pconbuf, send_out); //Copy data into the send buffer
+
+ udi_hid_con_b_report_valid = 1; //Set report valid
+ udi_hid_con_send_report(); //Send report
+
+ __DMB();
+ __set_PRIMASK(irqflags);
+
+ result -= send_out; //Decrement result by bytes sent
+ pconbuf += send_out; //Increment buffer point by bytes sent
+ }
+}
+
+#endif //CONSOLE_PRINT
diff --git a/tmk_core/common/arm_atsam/printf.h b/tmk_core/common/arm_atsam/printf.h
index 3206b40bd..1f1c2280b 100644
--- a/tmk_core/common/arm_atsam/printf.h
+++ b/tmk_core/common/arm_atsam/printf.h
@@ -1,8 +1,11 @@
#ifndef _PRINTF_H_
#define _PRINTF_H_
-int dpf(const char *_Format, ...);
-#define __xprintf dpf
+#define CONSOLE_PRINTBUF_SIZE 512
+
+void console_printf(char *fmt, ...);
+
+#define __xprintf console_printf
#endif //_PRINTF_H_
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;
}
diff --git a/tmk_core/protocol/arm_atsam/usb/conf_usb.h b/tmk_core/protocol/arm_atsam/usb/conf_usb.h
index 8f0f47268..c91caffe0 100644
--- a/tmk_core/protocol/arm_atsam/usb/conf_usb.h
+++ b/tmk_core/protocol/arm_atsam/usb/conf_usb.h
@@ -134,6 +134,11 @@
#define UDI_HID_EXK_DISABLE_EXT() main_exk_disable()
#endif
+#ifdef CON
+#define UDI_HID_CON_ENABLE_EXT() main_con_enable()
+#define UDI_HID_CON_DISABLE_EXT() main_con_disable()
+#endif
+
#ifdef MOU
#define UDI_HID_MOU_ENABLE_EXT() main_mou_enable()
#define UDI_HID_MOU_DISABLE_EXT() main_mou_disable()
diff --git a/tmk_core/protocol/arm_atsam/usb/main_usb.c b/tmk_core/protocol/arm_atsam/usb/main_usb.c
index e943cbcdc..0f676ab63 100644
--- a/tmk_core/protocol/arm_atsam/usb/main_usb.c
+++ b/tmk_core/protocol/arm_atsam/usb/main_usb.c
@@ -88,6 +88,20 @@ void main_exk_disable(void)
}
#endif
+#ifdef CON
+volatile bool main_b_con_enable = false;
+bool main_con_enable(void)
+{
+ main_b_con_enable = true;
+ return true;
+}
+
+void main_con_disable(void)
+{
+ main_b_con_enable = false;
+}
+#endif
+
#ifdef MOU
volatile bool main_b_mou_enable = false;
bool main_mou_enable(void)
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_cdc.c b/tmk_core/protocol/arm_atsam/usb/udi_cdc.c
index 15f0f760c..5f3c289e8 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_cdc.c
+++ b/tmk_core/protocol/arm_atsam/usb/udi_cdc.c
@@ -1260,7 +1260,7 @@ uint32_t CDC_print(char *printbuf)
char printbuf[CDC_PRINTBUF_SIZE];
-int dpf(const char *_Format, ...)
+int CDC_printf(const char *_Format, ...)
{
va_list va; //Variable argument list variable
int result;
@@ -1356,7 +1356,7 @@ uint32_t CDC_print(char *printbuf)
return 0;
}
-int dpf(const char *_Format, ...)
+int CDC_printf(const char *_Format, ...)
{
return 0;
}
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_cdc.h b/tmk_core/protocol/arm_atsam/usb/udi_cdc.h
index e134cf236..86077ce53 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_cdc.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_cdc.h
@@ -365,6 +365,7 @@ extern inbuf_t inbuf;
#endif //CDC
uint32_t CDC_print(char *printbuf);
+int CDC_printf(const char *_Format, ...);
uint32_t CDC_input(void);
void CDC_init(void);
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
index c78726234..1e82b9ecc 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
@@ -44,10 +44,10 @@ along with this program. If not, see .
#define RAW
#endif
-//#define CONSOLE_ENABLE //deferred implementation
-//#ifdef CONSOLE_ENABLE
-//#define CON
-//#endif
+//#define CONSOLE_ENABLE //rules.mk
+#ifdef CONSOLE_ENABLE
+#define CON
+#endif
//#define NKRO_ENABLE //rules.mk
#ifdef NKRO_ENABLE
@@ -110,8 +110,9 @@ along with this program. If not, see .
#endif
#ifdef CON
-#define CONSOLE_INTERFACE NEXT_INTERFACE_4
-#define NEXT_INTERFACE_5 (CONSOLE_INTERFACE + 1)
+#define CON_INTERFACE NEXT_INTERFACE_4
+#define NEXT_INTERFACE_5 (CON_INTERFACE + 1)
+#define UDI_HID_CON_IFACE_NUMBER CON_INTERFACE
#else
#define NEXT_INTERFACE_5 NEXT_INTERFACE_4
#endif
@@ -211,11 +212,16 @@ along with this program. If not, see .
#endif
#ifdef CON
-#define CONSOLE_IN_EPNUM NEXT_IN_EPNUM_4
-#define NEXT_IN_EPNUM_5 (CONSOLE_IN_EPNUM + 1)
-#define CONSOLE_OUT_EPNUM NEXT_OUT_EPNUM_1
-#define NEXT_OUT_EPNUM_2 (CONSOLE_OUT_EPNUM + 1)
-#define CONSOLE_POLLING_INTERVAL 1
+#define CON_IN_EPNUM NEXT_IN_EPNUM_4
+#define UDI_HID_CON_EP_IN CON_IN_EPNUM
+#define NEXT_IN_EPNUM_5 (CON_IN_EPNUM + 1)
+#define CON_OUT_EPNUM NEXT_OUT_EPNUM_1
+#define UDI_HID_CON_EP_OUT CON_OUT_EPNUM
+#define NEXT_OUT_EPNUM_2 (CON_OUT_EPNUM + 1)
+#define CON_POLLING_INTERVAL 1
+#ifndef UDI_HID_CON_STRING_ID
+#define UDI_HID_CON_STRING_ID 0
+#endif
#else
#define NEXT_IN_EPNUM_5 NEXT_IN_EPNUM_4
#define NEXT_OUT_EPNUM_2 NEXT_OUT_EPNUM_1
@@ -558,6 +564,66 @@ COMPILER_PACK_RESET()
#endif //RAW
+// **********************************************************************
+// CON Descriptor structure and content
+// **********************************************************************
+#ifdef CON
+
+COMPILER_PACK_SET(1)
+
+typedef struct {
+ usb_iface_desc_t iface;
+ usb_hid_descriptor_t hid;
+ usb_ep_desc_t ep_out;
+ usb_ep_desc_t ep_in;
+} udi_hid_con_desc_t;
+
+typedef struct {
+ uint8_t array[34];
+} udi_hid_con_report_desc_t;
+
+#define UDI_HID_CON_DESC {\
+ .iface.bLength = sizeof(usb_iface_desc_t),\
+ .iface.bDescriptorType = USB_DT_INTERFACE,\
+ .iface.bInterfaceNumber = UDI_HID_CON_IFACE_NUMBER,\
+ .iface.bAlternateSetting = 0,\
+ .iface.bNumEndpoints = 2,\
+ .iface.bInterfaceClass = HID_CLASS,\
+ .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT,\
+ .iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT,\
+ .iface.iInterface = UDI_HID_CON_STRING_ID,\
+ .hid.bLength = sizeof(usb_hid_descriptor_t),\
+ .hid.bDescriptorType = USB_DT_HID,\
+ .hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
+ .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
+ .hid.bNumDescriptors = USB_HID_NUM_DESC,\
+ .hid.bRDescriptorType = USB_DT_HID_REPORT,\
+ .hid.wDescriptorLength = LE16(sizeof(udi_hid_con_report_desc_t)),\
+ .ep_out.bLength = sizeof(usb_ep_desc_t),\
+ .ep_out.bDescriptorType = USB_DT_ENDPOINT,\
+ .ep_out.bEndpointAddress = UDI_HID_CON_EP_OUT | USB_EP_DIR_OUT,\
+ .ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT,\
+ .ep_out.wMaxPacketSize = LE16(CONSOLE_EPSIZE),\
+ .ep_out.bInterval = CON_POLLING_INTERVAL,\
+ .ep_in.bLength = sizeof(usb_ep_desc_t),\
+ .ep_in.bDescriptorType = USB_DT_ENDPOINT,\
+ .ep_in.bEndpointAddress = UDI_HID_CON_EP_IN | USB_EP_DIR_IN,\
+ .ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT,\
+ .ep_in.wMaxPacketSize = LE16(CONSOLE_EPSIZE),\
+ .ep_in.bInterval = CON_POLLING_INTERVAL,\
+}
+
+#define UDI_HID_CON_REPORT_SIZE CONSOLE_EPSIZE
+
+extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
+
+//report buffer
+extern uint8_t udi_hid_con_report[UDI_HID_CON_REPORT_SIZE];
+
+COMPILER_PACK_RESET()
+
+#endif //CON
+
// **********************************************************************
// CDC Descriptor structure and content
// **********************************************************************
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
index 1a6f7905e..18f9784ae 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
@@ -843,3 +843,149 @@ static void udi_hid_raw_setreport_valid(void)
}
#endif //RAW
+
+//********************************************************************************************
+// CON
+//********************************************************************************************
+#ifdef CON
+
+bool udi_hid_con_enable(void);
+void udi_hid_con_disable(void);
+bool udi_hid_con_setup(void);
+uint8_t udi_hid_con_getsetting(void);
+
+UDC_DESC_STORAGE udi_api_t udi_api_hid_con = {
+ .enable = (bool(*)(void))udi_hid_con_enable,
+ .disable = (void (*)(void))udi_hid_con_disable,
+ .setup = (bool(*)(void))udi_hid_con_setup,
+ .getsetting = (uint8_t(*)(void))udi_hid_con_getsetting,
+ .sof_notify = NULL,
+};
+
+COMPILER_WORD_ALIGNED
+static uint8_t udi_hid_con_rate;
+
+COMPILER_WORD_ALIGNED
+static uint8_t udi_hid_con_protocol;
+
+COMPILER_WORD_ALIGNED
+uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
+
+bool udi_hid_con_b_report_valid;
+
+COMPILER_WORD_ALIGNED
+uint8_t udi_hid_con_report[UDI_HID_CON_REPORT_SIZE];
+
+volatile bool udi_hid_con_b_report_trans_ongoing;
+
+COMPILER_WORD_ALIGNED
+static uint8_t udi_hid_con_report_trans[UDI_HID_CON_REPORT_SIZE];
+
+COMPILER_WORD_ALIGNED
+UDC_DESC_STORAGE udi_hid_con_report_desc_t udi_hid_con_report_desc = {
+ {
+ 0x06, 0x31, 0xFF, // Vendor Page (PJRC Teensy compatible)
+ 0x09, 0x74, // Vendor Usage (PJRC Teensy compatible)
+ 0xA1, 0x01, // Collection (Application)
+ 0x09, 0x75, // Usage (Vendor)
+ 0x15, 0x00, // Logical Minimum (0x00)
+ 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
+ 0x95, CONSOLE_EPSIZE, // Report Count
+ 0x75, 0x08, // Report Size (8)
+ 0x81, 0x02, // Input (Data)
+ 0x09, 0x76, // Usage (Vendor)
+ 0x15, 0x00, // Logical Minimum (0x00)
+ 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
+ 0x95, CONSOLE_EPSIZE, // Report Count
+ 0x75, 0x08, // Report Size (8)
+ 0x91, 0x02, // Output (Data)
+ 0xC0, // End Collection
+ }
+};
+
+static bool udi_hid_con_setreport(void);
+static void udi_hid_con_setreport_valid(void);
+
+static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
+
+bool udi_hid_con_enable(void)
+{
+ // Initialize internal values
+ udi_hid_con_rate = 0;
+ udi_hid_con_protocol = 0;
+ udi_hid_con_b_report_trans_ongoing = false;
+ memset(udi_hid_con_report, 0, UDI_HID_CON_REPORT_SIZE);
+ udi_hid_con_b_report_valid = false;
+ return UDI_HID_CON_ENABLE_EXT();
+}
+
+void udi_hid_con_disable(void)
+{
+ UDI_HID_CON_DISABLE_EXT();
+}
+
+bool udi_hid_con_setup(void)
+{
+ return udi_hid_setup(&udi_hid_con_rate,
+ &udi_hid_con_protocol,
+ (uint8_t *) &udi_hid_con_report_desc,
+ udi_hid_con_setreport);
+}
+
+uint8_t udi_hid_con_getsetting(void)
+{
+ return 0;
+}
+
+static bool udi_hid_con_setreport(void)
+{
+ if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8))
+ && (0 == (0xFF & udd_g_ctrlreq.req.wValue))
+ && (UDI_HID_CON_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
+ udd_g_ctrlreq.payload = udi_hid_con_report_set;
+ udd_g_ctrlreq.callback = udi_hid_con_setreport_valid;
+ udd_g_ctrlreq.payload_size = UDI_HID_CON_REPORT_SIZE;
+ return true;
+ }
+ return false;
+}
+
+bool udi_hid_con_send_report(void)
+{
+ if (!main_b_con_enable) {
+ return false;
+ }
+
+ if (udi_hid_con_b_report_trans_ongoing) {
+ return false;
+ }
+
+ memcpy(udi_hid_con_report_trans, udi_hid_con_report,UDI_HID_CON_REPORT_SIZE);
+ udi_hid_con_b_report_valid = false;
+ udi_hid_con_b_report_trans_ongoing =
+ udd_ep_run(UDI_HID_CON_EP_IN | USB_EP_DIR_IN,
+ false,
+ udi_hid_con_report_trans,
+ UDI_HID_CON_REPORT_SIZE,
+ udi_hid_con_report_sent);
+
+ return udi_hid_con_b_report_trans_ongoing;
+}
+
+static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
+{
+ UNUSED(status);
+ UNUSED(nb_sent);
+ UNUSED(ep);
+ udi_hid_con_b_report_trans_ongoing = false;
+ if (udi_hid_con_b_report_valid) {
+ udi_hid_con_send_report();
+ }
+}
+
+static void udi_hid_con_setreport_valid(void)
+{
+
+}
+
+#endif //CON
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
index babfdb7a7..e442919a9 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
@@ -85,6 +85,17 @@ extern uint8_t udi_hid_exk_report_set;
bool udi_hid_exk_send_report(void);
#endif //EXK
+//********************************************************************************************
+// CON Console
+//********************************************************************************************
+#ifdef CON
+extern UDC_DESC_STORAGE udi_api_t udi_api_hid_con;
+extern bool udi_hid_con_b_report_valid;
+extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
+extern volatile bool udi_hid_con_b_report_trans_ongoing;
+bool udi_hid_con_send_report(void);
+#endif //CON
+
//********************************************************************************************
// MOU Mouse
//********************************************************************************************
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c
index 16bd4e514..2d6e35e25 100644
--- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c
+++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c
@@ -134,6 +134,9 @@ UDC_DESC_STORAGE udc_desc_t udc_desc = {
#ifdef EXK
.hid_exk = UDI_HID_EXK_DESC,
#endif
+#ifdef CON
+ .hid_con = UDI_HID_CON_DESC,
+#endif
#ifdef NKRO
.hid_nkro = UDI_HID_NKRO_DESC,
#endif
@@ -155,6 +158,9 @@ UDC_DESC_STORAGE udi_api_t *udi_apis[USB_DEVICE_NB_INTERFACE] = {
#ifdef EXK
&udi_api_hid_exk,
#endif
+ #ifdef CON
+ &udi_api_hid_con,
+ #endif
#ifdef NKRO
&udi_api_hid_nkro,
#endif
diff --git a/tmk_core/protocol/arm_atsam/usb/usb_main.h b/tmk_core/protocol/arm_atsam/usb/usb_main.h
index b7adaa1a7..76ced474d 100644
--- a/tmk_core/protocol/arm_atsam/usb/usb_main.h
+++ b/tmk_core/protocol/arm_atsam/usb/usb_main.h
@@ -82,6 +82,12 @@ bool main_exk_enable(void);
void main_exk_disable(void);
#endif //EXK
+#ifdef CON
+extern volatile bool main_b_con_enable;
+bool main_con_enable(void);
+void main_con_disable(void);
+#endif //CON
+
#ifdef MOU
extern volatile bool main_b_mou_enable;
bool main_mou_enable(void);
--
cgit v1.2.3-70-g09d2
From cd23984afcee9a8dd2b1b44876b77141d692de45 Mon Sep 17 00:00:00 2001
From: patrickmt <40182064+patrickmt@users.noreply.github.com>
Date: Mon, 29 Oct 2018 10:04:52 -0400
Subject: Fix undefined reference to `console_printf` for CTRL and ALT
keyboards
Fix undefined reference to `console_printf` for CTRL and ALT keyboards when enabling CONSOLE_ENABLE
---
tmk_core/common/arm_atsam/printf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'tmk_core/common/arm_atsam')
diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c
index d49d234de..7f298d1fd 100644
--- a/tmk_core/common/arm_atsam/printf.c
+++ b/tmk_core/common/arm_atsam/printf.c
@@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-#ifdef CONSOLE_PRINT
+#ifdef CONSOLE_ENABLE
#include "samd51j18a.h"
#include "arm_atsam_protocol.h"
@@ -63,4 +63,4 @@ void console_printf(char *fmt, ...) {
}
}
-#endif //CONSOLE_PRINT
+#endif //CONSOLE_ENABLE
--
cgit v1.2.3-70-g09d2
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/common/arm_atsam/suspend.c | 90 ++++++++++++++++++++++++----
tmk_core/protocol/arm_atsam/i2c_master.c | 5 +-
tmk_core/protocol/arm_atsam/main_arm_atsam.c | 80 ++++++++++++++++---------
tmk_core/protocol/arm_atsam/usb/ui.c | 8 +--
tmk_core/protocol/arm_atsam/usb/ui.h | 6 --
5 files changed, 136 insertions(+), 53 deletions(-)
(limited to 'tmk_core/common/arm_atsam')
diff --git a/tmk_core/common/arm_atsam/suspend.c b/tmk_core/common/arm_atsam/suspend.c
index 01d1930ea..e34965df6 100644
--- a/tmk_core/common/arm_atsam/suspend.c
+++ b/tmk_core/common/arm_atsam/suspend.c
@@ -1,17 +1,85 @@
-/* Copyright 2017 Fred Sundvik
+#include "matrix.h"
+#include "i2c_master.h"
+#include "led_matrix.h"
+#include "suspend.h"
+
+/** \brief Suspend idle
*
- * 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.
+ * FIXME: needs doc
+ */
+void suspend_idle(uint8_t time) {
+ /* Note: Not used anywhere currently */
+}
+
+/** \brief Run user level Power down
*
- * 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.
+ * FIXME: needs doc
+ */
+__attribute__ ((weak))
+void suspend_power_down_user (void) {
+
+}
+
+/** \brief Run keyboard level Power down
+ *
+ * FIXME: needs doc
+ */
+__attribute__ ((weak))
+void suspend_power_down_kb(void) {
+ suspend_power_down_user();
+}
+
+/** \brief Suspend power down
+ *
+ * FIXME: needs doc
+ */
+void suspend_power_down(void)
+{
+ I2C3733_Control_Set(0); //Disable LED driver
+
+ suspend_power_down_kb();
+}
+
+__attribute__ ((weak)) void matrix_power_up(void) {}
+__attribute__ ((weak)) void matrix_power_down(void) {}
+bool suspend_wakeup_condition(void) {
+ matrix_power_up();
+ matrix_scan();
+ matrix_power_down();
+ for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
+ if (matrix_get_row(r)) return true;
+ }
+ return false;
+}
+
+/** \brief run user level code immediately after wakeup
+ *
+ * FIXME: needs doc
+ */
+__attribute__ ((weak))
+void suspend_wakeup_init_user(void) {
+
+}
+
+/** \brief run keyboard level code immediately after wakeup
+ *
+ * FIXME: needs doc
+ */
+__attribute__ ((weak))
+void suspend_wakeup_init_kb(void) {
+ suspend_wakeup_init_user();
+}
+
+/** \brief run immediately after wakeup
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
+ * FIXME: needs doc
*/
+void suspend_wakeup_init(void) {
+ /* If LEDs are set to enabled, enable the hardware */
+ if (led_enabled) {
+ I2C3733_Control_Set(1);
+ }
+ suspend_wakeup_init_kb();
+}
diff --git a/tmk_core/protocol/arm_atsam/i2c_master.c b/tmk_core/protocol/arm_atsam/i2c_master.c
index 4f5a79e89..ece9ee5db 100644
--- a/tmk_core/protocol/arm_atsam/i2c_master.c
+++ b/tmk_core/protocol/arm_atsam/i2c_master.c
@@ -261,8 +261,9 @@ uint8_t I2C3733_Init_Control(void)
{
DBGC(DC_I2C3733_INIT_CONTROL_BEGIN);
- srdata.bit.SDB_N = 1;
- SPI_WriteSRData();
+ //Hardware state shutdown on boot
+ //USB state machine will enable driver when communication is ready
+ I2C3733_Control_Set(0);
CLK_delay_ms(1);
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)
{
diff --git a/tmk_core/protocol/arm_atsam/usb/ui.c b/tmk_core/protocol/arm_atsam/usb/ui.c
index 031678b64..70a619109 100644
--- a/tmk_core/protocol/arm_atsam/usb/ui.c
+++ b/tmk_core/protocol/arm_atsam/usb/ui.c
@@ -52,8 +52,6 @@
#include "samd51j18a.h"
#include "ui.h"
-volatile uint8_t usb_state;
-
//! Sequence process running each \c SEQUENCE_PERIOD ms
#define SEQUENCE_PERIOD 150
@@ -72,12 +70,12 @@ static void ui_wakeup_handler(void)
void ui_init(void)
{
- usb_state = USB_STATE_POWERUP;
+
}
void ui_powerdown(void)
{
- usb_state = USB_STATE_POWERDOWN;
+
}
void ui_wakeup_enable(void)
@@ -92,7 +90,7 @@ void ui_wakeup_disable(void)
void ui_wakeup(void)
{
- usb_state = USB_STATE_POWERUP;
+
}
void ui_process(uint16_t framenumber)
diff --git a/tmk_core/protocol/arm_atsam/usb/ui.h b/tmk_core/protocol/arm_atsam/usb/ui.h
index 3d899e669..d1c767d45 100644
--- a/tmk_core/protocol/arm_atsam/usb/ui.h
+++ b/tmk_core/protocol/arm_atsam/usb/ui.h
@@ -47,12 +47,6 @@
#ifndef _UI_H_
#define _UI_H_
-extern volatile uint8_t usb_state;
-
-#define USB_STATE_UNKNOWN 0
-#define USB_STATE_POWERDOWN 1
-#define USB_STATE_POWERUP 2
-
//! \brief Initializes the user interface
void ui_init(void);
--
cgit v1.2.3-70-g09d2