From 5ba4391cf29ce624f17593417212b3dbca1609ad Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Sun, 28 Feb 2021 15:52:58 +0000
Subject: Refactor of USB code within split_common (#11890)
* Initial refactor of usb code within split_common
* Add headers
* Correct disable condition
* Format
* Align func name---
tmk_core/protocol/vusb/usb_util.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 tmk_core/protocol/vusb/usb_util.c
(limited to 'tmk_core/protocol/vusb')
diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c
new file mode 100644
index 0000000000..602854dbe6
--- /dev/null
+++ b/tmk_core/protocol/vusb/usb_util.c
@@ -0,0 +1,24 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include
+#include "usb_util.h"
+
+void usb_disable(void) { usbDeviceDisconnect(); }
+
+bool usb_connected_state(void) {
+ usbPoll();
+ return usbConfiguration;
+}
--
cgit v1.2.3
From 58142f0726147d538167ff3ab793743348f40dcd Mon Sep 17 00:00:00 2001
From: Nick Brassel
Date: Tue, 18 May 2021 17:02:28 +1000
Subject: Fixup housekeeping from being invoked twice per loop. (#12933)
---
tmk_core/common/keyboard.c | 12 +++++++++---
tmk_core/common/keyboard.h | 5 +++--
tmk_core/protocol/arm_atsam/main_arm_atsam.c | 3 +++
tmk_core/protocol/chibios/main.c | 3 +--
tmk_core/protocol/lufa/lufa.c | 3 +--
tmk_core/protocol/vusb/main.c | 3 +--
6 files changed, 18 insertions(+), 11 deletions(-)
(limited to 'tmk_core/protocol/vusb')
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 24baf41c00..3d6092e71c 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -280,6 +280,15 @@ __attribute__((weak)) void housekeeping_task_kb(void) {}
*/
__attribute__((weak)) void housekeeping_task_user(void) {}
+/** \brief housekeeping_task
+ *
+ * Invokes hooks for executing code after QMK is done after each loop iteration.
+ */
+void housekeeping_task(void) {
+ housekeeping_task_kb();
+ housekeeping_task_user();
+}
+
/** \brief keyboard_init
*
* FIXME: needs doc
@@ -374,9 +383,6 @@ void keyboard_task(void) {
bool encoders_changed = false;
#endif
- housekeeping_task_kb();
- housekeeping_task_user();
-
uint8_t matrix_changed = matrix_scan();
if (matrix_changed) last_matrix_activity_trigger();
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h
index eaf74bac58..779973f1d6 100644
--- a/tmk_core/common/keyboard.h
+++ b/tmk_core/common/keyboard.h
@@ -70,8 +70,9 @@ void keyboard_pre_init_user(void);
void keyboard_post_init_kb(void);
void keyboard_post_init_user(void);
-void housekeeping_task_kb(void);
-void housekeeping_task_user(void);
+void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol
+void housekeeping_task_kb(void); // To be overridden by keyboard-level code
+void housekeeping_task_user(void); // To be overridden by user/keymap-level code
uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity
uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
index e4e79d3510..ce0f54593c 100644
--- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c
+++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
@@ -305,6 +305,9 @@ int main(void) {
// 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 // CONSOLE_ENABLE
+
+ // Run housekeeping
+ housekeeping_task();
}
return 1;
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index e2ec011186..199741594a 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -257,7 +257,6 @@ int main(void) {
#endif
// Run housekeeping
- housekeeping_task_kb();
- housekeeping_task_user();
+ housekeeping_task();
}
}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 85d71d0835..63619fdb3b 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1107,8 +1107,7 @@ int main(void) {
#endif
// Run housekeeping
- housekeeping_task_kb();
- housekeeping_task_user();
+ housekeeping_task();
}
}
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index 2de4f6a80a..53926a7493 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -173,8 +173,7 @@ int main(void) {
#endif
// Run housekeeping
- housekeeping_task_kb();
- housekeeping_task_user();
+ housekeeping_task();
}
}
}
--
cgit v1.2.3
From 49fd3c0760e06b7eab3647098530f1a9bdfc5054 Mon Sep 17 00:00:00 2001
From: Stefan Kerkmann
Date: Mon, 7 Jun 2021 07:16:55 +0200
Subject: [Core] ChibiOS fix O3 and LTO breakage of extra keys and joystick
(#12819)
---
tmk_core/protocol/chibios/usb_main.c | 34 +++++++++++++++++-----------------
tmk_core/protocol/lufa/lufa.c | 34 +++++++++++++++++-----------------
tmk_core/protocol/vusb/vusb.c | 3 ++-
3 files changed, 36 insertions(+), 35 deletions(-)
(limited to 'tmk_core/protocol/vusb')
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index d04302acae..407b8ea75d 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -903,7 +903,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {
return;
}
- report_extra_t report = {.report_id = report_id, .usage = data};
+ static report_extra_t report;
+ report = (report_extra_t){.report_id = report_id, .usage = data};
usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));
osalSysUnlock();
@@ -1051,45 +1052,44 @@ void virtser_task(void) {
#ifdef JOYSTICK_ENABLE
void send_joystick_packet(joystick_t *joystick) {
- joystick_report_t rep = {
+ static joystick_report_t rep;
+ rep = (joystick_report_t) {
# if JOYSTICK_AXES_COUNT > 0
.axes =
- {
- joystick->axes[0],
+ { joystick->axes[0],
# if JOYSTICK_AXES_COUNT >= 2
- joystick->axes[1],
+ joystick->axes[1],
# endif
# if JOYSTICK_AXES_COUNT >= 3
- joystick->axes[2],
+ joystick->axes[2],
# endif
# if JOYSTICK_AXES_COUNT >= 4
- joystick->axes[3],
+ joystick->axes[3],
# endif
# if JOYSTICK_AXES_COUNT >= 5
- joystick->axes[4],
+ joystick->axes[4],
# endif
# if JOYSTICK_AXES_COUNT >= 6
- joystick->axes[5],
+ joystick->axes[5],
# endif
- },
+ },
# endif // JOYSTICK_AXES_COUNT>0
# if JOYSTICK_BUTTON_COUNT > 0
- .buttons =
- {
- joystick->buttons[0],
+ .buttons = {
+ joystick->buttons[0],
# if JOYSTICK_BUTTON_COUNT > 8
- joystick->buttons[1],
+ joystick->buttons[1],
# endif
# if JOYSTICK_BUTTON_COUNT > 16
- joystick->buttons[2],
+ joystick->buttons[2],
# endif
# if JOYSTICK_BUTTON_COUNT > 24
- joystick->buttons[3],
+ joystick->buttons[3],
# endif
- }
+ }
# endif // JOYSTICK_BUTTON_COUNT>0
};
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 63619fdb3b..4ac079e168 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -314,45 +314,44 @@ static void Console_Task(void) {
void send_joystick_packet(joystick_t *joystick) {
uint8_t timeout = 255;
- joystick_report_t r = {
+ static joystick_report_t;
+ r = (joystick_report_t) {
# if JOYSTICK_AXES_COUNT > 0
.axes =
- {
- joystick->axes[0],
+ { joystick->axes[0],
# if JOYSTICK_AXES_COUNT >= 2
- joystick->axes[1],
+ joystick->axes[1],
# endif
# if JOYSTICK_AXES_COUNT >= 3
- joystick->axes[2],
+ joystick->axes[2],
# endif
# if JOYSTICK_AXES_COUNT >= 4
- joystick->axes[3],
+ joystick->axes[3],
# endif
# if JOYSTICK_AXES_COUNT >= 5
- joystick->axes[4],
+ joystick->axes[4],
# endif
# if JOYSTICK_AXES_COUNT >= 6
- joystick->axes[5],
+ joystick->axes[5],
# endif
- },
+ },
# endif // JOYSTICK_AXES_COUNT>0
# if JOYSTICK_BUTTON_COUNT > 0
- .buttons =
- {
- joystick->buttons[0],
+ .buttons = {
+ joystick->buttons[0],
# if JOYSTICK_BUTTON_COUNT > 8
- joystick->buttons[1],
+ joystick->buttons[1],
# endif
# if JOYSTICK_BUTTON_COUNT > 16
- joystick->buttons[2],
+ joystick->buttons[2],
# endif
# if JOYSTICK_BUTTON_COUNT > 24
- joystick->buttons[3],
+ joystick->buttons[3],
# endif
- }
+ }
# endif // JOYSTICK_BUTTON_COUNT>0
};
@@ -768,7 +767,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {
if (USB_DeviceState != DEVICE_STATE_Configured) return;
- report_extra_t r = {.report_id = report_id, .usage = data};
+ static report_extra_t r;
+ r = (report_extra_t){.report_id = report_id, .usage = data};
Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 9362fbde78..876a313786 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -272,7 +272,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {
last_id = report_id;
last_data = data;
- report_extra_t report = {.report_id = report_id, .usage = data};
+ static report_extra_t report;
+ report = (report_extra_t){.report_id = report_id, .usage = data};
if (usbInterruptIsReadyShared()) {
usbSetInterruptShared((void *)&report, sizeof(report_extra_t));
}
--
cgit v1.2.3
From 7ed5ac4a6026939898810f9a9c706fb7a09db171 Mon Sep 17 00:00:00 2001
From: Ryan
Date: Fri, 16 Jul 2021 19:43:18 +1000
Subject: Use string literals for `SERIAL_NUMBER` (#13403)
---
tmk_core/protocol/usb_descriptor.c | 4 ++--
tmk_core/protocol/usb_descriptor_common.h | 4 ++++
tmk_core/protocol/vusb/vusb.c | 4 ++--
3 files changed, 8 insertions(+), 4 deletions(-)
(limited to 'tmk_core/protocol/vusb')
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index c88aceb6ed..7a4a790315 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -953,10 +953,10 @@ const USB_Descriptor_String_t PROGMEM ProductString = {
#if defined(SERIAL_NUMBER)
const USB_Descriptor_String_t PROGMEM SerialNumberString = {
.Header = {
- .Size = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator
+ .Size = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1), // Subtract 1 for null terminator
.Type = DTYPE_String
},
- .UnicodeString = LSTR(SERIAL_NUMBER)
+ .UnicodeString = USBSTR(SERIAL_NUMBER)
};
#endif
diff --git a/tmk_core/protocol/usb_descriptor_common.h b/tmk_core/protocol/usb_descriptor_common.h
index b1f602c82e..ce0cf09763 100644
--- a/tmk_core/protocol/usb_descriptor_common.h
+++ b/tmk_core/protocol/usb_descriptor_common.h
@@ -16,6 +16,10 @@
#pragma once
+// Prefix string literal with L for descriptors
+#define USBCONCAT(a, b) a##b
+#define USBSTR(s) USBCONCAT(L, s)
+
/////////////////////
// RAW Usage page and ID configuration
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 876a313786..98cebf6012 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -599,10 +599,10 @@ const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {
#if defined(SERIAL_NUMBER)
const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
.header = {
- .bLength = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1),
+ .bLength = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1),
.bDescriptorType = USBDESCR_STRING
},
- .bString = LSTR(SERIAL_NUMBER)
+ .bString = USBSTR(SERIAL_NUMBER)
};
#endif
--
cgit v1.2.3
From 567da49ed027a936a6f56aa069aad0db4605a198 Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Sat, 24 Jul 2021 12:13:06 +0100
Subject: Avoid LTO conficts on arm_atsam (#13676)
---
quantum/split_common/split_util.c | 2 +-
tmk_core/common/usb_util.c | 2 +-
tmk_core/common/usb_util.h | 2 +-
tmk_core/protocol/chibios/usb_util.c | 2 +-
tmk_core/protocol/lufa/usb_util.c | 2 +-
tmk_core/protocol/vusb/usb_util.c | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
(limited to 'tmk_core/protocol/vusb')
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 989829d2dc..8d414f6fe6 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -106,7 +106,7 @@ __attribute__((weak)) bool is_keyboard_master(void) {
// Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
if (usbstate == SLAVE) {
- usb_disable();
+ usb_disconnect();
}
}
diff --git a/tmk_core/common/usb_util.c b/tmk_core/common/usb_util.c
index d4134a0446..dd1deeaa11 100644
--- a/tmk_core/common/usb_util.c
+++ b/tmk_core/common/usb_util.c
@@ -16,7 +16,7 @@
#include "quantum.h"
#include "usb_util.h"
-__attribute__((weak)) void usb_disable(void) {}
+__attribute__((weak)) void usb_disconnect(void) {}
__attribute__((weak)) bool usb_connected_state(void) { return true; }
__attribute__((weak)) bool usb_vbus_state(void) {
#ifdef USB_VBUS_PIN
diff --git a/tmk_core/common/usb_util.h b/tmk_core/common/usb_util.h
index 4ebedb1e71..13db9fbfbd 100644
--- a/tmk_core/common/usb_util.h
+++ b/tmk_core/common/usb_util.h
@@ -17,6 +17,6 @@
#include
-void usb_disable(void);
+void usb_disconnect(void);
bool usb_connected_state(void);
bool usb_vbus_state(void);
diff --git a/tmk_core/protocol/chibios/usb_util.c b/tmk_core/protocol/chibios/usb_util.c
index 5945e8a8de..e32d6ebfa4 100644
--- a/tmk_core/protocol/chibios/usb_util.c
+++ b/tmk_core/protocol/chibios/usb_util.c
@@ -16,6 +16,6 @@
#include
#include "usb_util.h"
-void usb_disable(void) { usbStop(&USBD1); }
+void usb_disconnect(void) { usbStop(&USBD1); }
bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; }
diff --git a/tmk_core/protocol/lufa/usb_util.c b/tmk_core/protocol/lufa/usb_util.c
index 9e943a21b9..9691eff1e4 100644
--- a/tmk_core/protocol/lufa/usb_util.c
+++ b/tmk_core/protocol/lufa/usb_util.c
@@ -17,7 +17,7 @@
#include "usb_util.h"
#include "wait.h"
-void usb_disable(void) {
+void usb_disconnect(void) {
USB_Disable();
USB_DeviceState = DEVICE_STATE_Unattached;
}
diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c
index 602854dbe6..4ee2d3188b 100644
--- a/tmk_core/protocol/vusb/usb_util.c
+++ b/tmk_core/protocol/vusb/usb_util.c
@@ -16,7 +16,7 @@
#include
#include "usb_util.h"
-void usb_disable(void) { usbDeviceDisconnect(); }
+void usb_disconnect(void) { usbDeviceDisconnect(); }
bool usb_connected_state(void) {
usbPoll();
--
cgit v1.2.3
From 75b49aff56436c57a424e622c91f6d80e1d0ecc2 Mon Sep 17 00:00:00 2001
From: a-chol
Date: Tue, 17 Aug 2021 20:52:44 +0200
Subject: Digitizer HID interface : absolute coordinates for mouse cursor
(#12851)
* Add digitizer HID interface for setting the mouse cursor position at
absolute screen coordinates. Tested on Pro Micro, Proton C and
Blackpill.
* Update docs/feature_digitizer.md
Co-authored-by: Ryan
* Update tmk_core/protocol/usb_descriptor.c
Co-authored-by: Ryan
* Add missing copyrights
Add V-USB support
* Add support for digitizer dedicated endpoint for lufa and chibios.
Fix formatting issues
Move digitizer_task definition to the feature's base implementation file
* Run cformat on modified files
* Change digitizer report usage to Digitizer instead of Pen to avoid
pointer disappearing on Windows.
* Update tmk_core/protocol/vusb/vusb.c
Co-authored-by: Ryan
* Run cformat from docker image
* Remove send_digitizer from host_driver_t and instead rely on the
declaration being the interface to the implementation in each
HW-specific usb implementation.
* Fix build : send_digitizer shouldn't be static in vusb and add
weak-linkage implementation for tests without usb implementation
* Change digitizer user interface to match pointing device's
* Update documentation with new API
Co-authored-by: a-chol
Co-authored-by: Ryan ---
common_features.mk | 5 +
docs/_summary.md | 1 +
docs/feature_digitizer.md | 35 +++++++
.../handwired/onekey/keymaps/digitizer/keymap.c | 38 ++++++++
.../handwired/onekey/keymaps/digitizer/rules.mk | 1 +
quantum/digitizer.c | 34 +++++++
quantum/digitizer.h | 41 +++++++++
tmk_core/common.mk | 13 +++
tmk_core/common/host.c | 19 ++++
tmk_core/common/host_driver.h | 2 +
tmk_core/common/keyboard.c | 7 ++
tmk_core/common/report.h | 14 ++-
tmk_core/protocol/chibios/main.c | 1 +
tmk_core/protocol/chibios/usb_main.c | 28 ++++++
tmk_core/protocol/lufa/lufa.c | 26 +++++-
tmk_core/protocol/usb_descriptor.c | 101 +++++++++++++++++++++
tmk_core/protocol/usb_descriptor.h | 27 +++++-
tmk_core/protocol/vusb/vusb.c | 48 +++++++++-
18 files changed, 435 insertions(+), 6 deletions(-)
create mode 100644 docs/feature_digitizer.md
create mode 100644 keyboards/handwired/onekey/keymaps/digitizer/keymap.c
create mode 100644 keyboards/handwired/onekey/keymaps/digitizer/rules.mk
create mode 100644 quantum/digitizer.c
create mode 100644 quantum/digitizer.h
(limited to 'tmk_core/protocol/vusb')
diff --git a/common_features.mk b/common_features.mk
index e442222eae..493aab6353 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -695,6 +695,11 @@ ifeq ($(strip $(JOYSTICK_ENABLE)), digital)
OPT_DEFS += -DDIGITAL_JOYSTICK_ENABLE
endif
+DIGITIZER_ENABLE ?= no
+ifneq ($(strip $(DIGITIZER_ENABLE)), no)
+ SRC += $(QUANTUM_DIR)/digitizer.c
+endif
+
USBPD_ENABLE ?= no
VALID_USBPD_DRIVER_TYPES = custom vendor
USBPD_DRIVER ?= vendor
diff --git a/docs/_summary.md b/docs/_summary.md
index 48115cef46..2f6309e41d 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -108,6 +108,7 @@
* [Bluetooth](feature_bluetooth.md)
* [Bootmagic Lite](feature_bootmagic.md)
* [Custom Matrix](custom_matrix.md)
+ * [Digitizer](feature_digitizer.md)
* [DIP Switch](feature_dip_switch.md)
* [Encoders](feature_encoders.md)
* [Haptic Feedback](feature_haptic_feedback.md)
diff --git a/docs/feature_digitizer.md b/docs/feature_digitizer.md
new file mode 100644
index 0000000000..9b6aeddbaa
--- /dev/null
+++ b/docs/feature_digitizer.md
@@ -0,0 +1,35 @@
+## Digitizer
+
+The digitizer HID interface allows setting the mouse cursor position at absolute coordinates, unlike the Pointing Device feature that applies relative displacements.
+
+To enable the digitizer interface, add the following line to your rules.mk:
+
+```makefile
+DIGITIZER_ENABLE = yes
+```
+
+In order to change the mouse cursor position from your keymap.c file, include the digitizer header :
+
+```c
+#include "digitizer.h"
+```
+
+This gives you access to the `digitizer` structure which members allow you to change the cursor position.
+
+The coordinates are normalized, meaning there value must be set between 0 and 1. For the `x` coordinate, the value `0` is the leftmost position, whereas the value `1` is the rightmost position.
+For the `y` coordinate, `0` is at the top and `1` at the bottom.
+
+Here is an example setting the cursor in the middle of the screen:
+
+```c
+digitizer_t digitizer;
+digitizer.x = 0.5;
+digitizer.y = 0.5;
+digitizer.tipswitch = 0;
+digitizer.inrange = 1;
+digitizer_set_report(digitizer);
+```
+
+The `tipswitch` member triggers what equates to a click when set to `1`. The `inrange` member is required for the change in coordinates to be taken. It can then be set to `0` in a new report to signal the end of the digitizer interaction, but it is not strictly required.
+
+Once all members are set to the desired value, the `status` member needs its bitmask `DZ_UPDATED` to be set so the report is sent during the next main loop iteration.
diff --git a/keyboards/handwired/onekey/keymaps/digitizer/keymap.c b/keyboards/handwired/onekey/keymaps/digitizer/keymap.c
new file mode 100644
index 0000000000..6b304e86fe
--- /dev/null
+++ b/keyboards/handwired/onekey/keymaps/digitizer/keymap.c
@@ -0,0 +1,38 @@
+ /* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 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 QMK_KEYBOARD_H
+
+#include "digitizer.h"
+
+#include "math.h"
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {LAYOUT_ortho_1x1(KC_A)};
+
+uint32_t timer = 0;
+
+void matrix_scan_user() {
+ if (timer_elapsed32(timer) < 200) {
+ return;
+ }
+
+ timer = timer_read32();
+ digitizer_t digitizer;
+ digitizer.x = 0.5 - 0.2 * cos(timer_read() / 250. / 6.28);
+ digitizer.y = 0.5 - 0.2 * sin(timer_read() / 250. / 6.28);
+ digitizer.tipswitch = 0;
+ digitizer.inrange = 1;
+ digitizer_set_report(digitizer);
+}
diff --git a/keyboards/handwired/onekey/keymaps/digitizer/rules.mk b/keyboards/handwired/onekey/keymaps/digitizer/rules.mk
new file mode 100644
index 0000000000..ea9f9bd9ac
--- /dev/null
+++ b/keyboards/handwired/onekey/keymaps/digitizer/rules.mk
@@ -0,0 +1 @@
+DIGITIZER_ENABLE = yes
\ No newline at end of file
diff --git a/quantum/digitizer.c b/quantum/digitizer.c
new file mode 100644
index 0000000000..e299867429
--- /dev/null
+++ b/quantum/digitizer.c
@@ -0,0 +1,34 @@
+/* Copyright 2021
+ *
+ * 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 "digitizer.h"
+
+digitizer_t digitizerReport = {.tipswitch = 0, .inrange = 0, .id = 0, .x = 0, .y = 0, .status = DZ_INITIALIZED};
+
+__attribute__((weak)) void digitizer_send(void) {
+ if (digitizerReport.status & DZ_UPDATED) {
+ host_digitizer_send(&digitizerReport);
+ digitizerReport.status &= ~DZ_UPDATED;
+ }
+}
+
+__attribute__((weak)) void digitizer_task(void) { digitizer_send(); }
+
+digitizer_t digitizer_get_report(void) { return digitizerReport; }
+
+void digitizer_set_report(digitizer_t newDigitizerReport) {
+ digitizerReport = newDigitizerReport;
+ digitizerReport.status |= DZ_UPDATED;
+}
\ No newline at end of file
diff --git a/quantum/digitizer.h b/quantum/digitizer.h
new file mode 100644
index 0000000000..cef551567e
--- /dev/null
+++ b/quantum/digitizer.h
@@ -0,0 +1,41 @@
+/* Copyright 2021
+ *
+ * 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 .
+ */
+#pragma once
+
+#include "quantum.h"
+
+#include
+
+enum digitizer_status { DZ_INITIALIZED = 1, DZ_UPDATED = 2 };
+
+typedef struct {
+ int8_t tipswitch;
+ int8_t inrange;
+ uint8_t id;
+ float x;
+ float y;
+ uint8_t status : 2;
+} digitizer_t;
+
+extern digitizer_t digitizer;
+
+digitizer_t digitizer_get_report(void);
+
+void digitizer_set_report(digitizer_t newDigitizerReport);
+
+void digitizer_task(void);
+
+void host_digitizer_send(digitizer_t *digitizer);
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 6c8cf69356..fa907b47b8 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -106,6 +106,19 @@ ifeq ($(strip $(NO_USB_STARTUP_CHECK)), yes)
TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK
endif
+ifeq ($(strip $(DIGITIZER_SHARED_EP)), yes)
+ TMK_COMMON_DEFS += -DDIGITIZER_SHARED_EP
+ SHARED_EP_ENABLE = yes
+endif
+
+ifeq ($(strip $(DIGITIZER_ENABLE)), yes)
+ TMK_COMMON_DEFS += -DDIGITIZER_ENABLE
+ ifeq ($(strip $(SHARED_EP_ENABLE)), yes)
+ TMK_COMMON_DEFS += -DDIGITIZER_SHARED_EP
+ SHARED_EP_ENABLE = yes
+ endif
+endif
+
ifeq ($(strip $(SHARED_EP_ENABLE)), yes)
TMK_COMMON_DEFS += -DSHARED_EP_ENABLE
endif
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index a8b391e893..f0c396b189 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -22,6 +22,7 @@ along with this program. If not, see .
#include "host.h"
#include "util.h"
#include "debug.h"
+#include "digitizer.h"
#ifdef NKRO_ENABLE
# include "keycode_config.h"
@@ -103,6 +104,24 @@ void host_consumer_send(uint16_t report) {
(*driver->send_consumer)(report);
}
+void host_digitizer_send(digitizer_t *digitizer) {
+ if (!driver) return;
+
+ report_digitizer_t report = {
+#ifdef DIGITIZER_SHARED_EP
+ .report_id = REPORT_ID_DIGITIZER,
+#endif
+ .tip = digitizer->tipswitch & 0x1,
+ .inrange = digitizer->inrange & 0x1,
+ .x = (uint16_t)(digitizer->x * 0x7FFF),
+ .y = (uint16_t)(digitizer->y * 0x7FFF),
+ };
+
+ send_digitizer(&report);
+}
+
+__attribute__((weak)) void send_digitizer(report_digitizer_t *report) {}
+
uint16_t host_last_system_report(void) { return last_system_report; }
uint16_t host_last_consumer_report(void) { return last_consumer_report; }
diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h
index f34a220530..2aebca043d 100644
--- a/tmk_core/common/host_driver.h
+++ b/tmk_core/common/host_driver.h
@@ -30,3 +30,5 @@ typedef struct {
void (*send_system)(uint16_t);
void (*send_consumer)(uint16_t);
} host_driver_t;
+
+void send_digitizer(report_digitizer_t *report);
\ No newline at end of file
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 28fa97bc8f..fcc51973fd 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -106,6 +106,9 @@ along with this program. If not, see .
#if defined(CRC_ENABLE)
# include "crc.h"
#endif
+#ifdef DIGITIZER_ENABLE
+# include "digitizer.h"
+#endif
static uint32_t last_input_modification_time = 0;
uint32_t last_input_activity_time(void) { return last_input_modification_time; }
@@ -537,6 +540,10 @@ MATRIX_LOOP_END:
joystick_task();
#endif
+#ifdef DIGITIZER_ENABLE
+ digitizer_task();
+#endif
+
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index db6370657d..f2223e8063 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -30,7 +30,8 @@ enum hid_report_ids {
REPORT_ID_SYSTEM,
REPORT_ID_CONSUMER,
REPORT_ID_NKRO,
- REPORT_ID_JOYSTICK
+ REPORT_ID_JOYSTICK,
+ REPORT_ID_DIGITIZER
};
/* Mouse buttons */
@@ -205,6 +206,17 @@ typedef struct {
int8_t h;
} __attribute__((packed)) report_mouse_t;
+typedef struct {
+#ifdef DIGITIZER_SHARED_EP
+ uint8_t report_id;
+#endif
+ uint8_t tip : 1;
+ uint8_t inrange : 1;
+ uint8_t pad2 : 6;
+ uint16_t x;
+ uint16_t y;
+} __attribute__((packed)) report_digitizer_t;
+
typedef struct {
#if JOYSTICK_AXES_COUNT > 0
# if JOYSTICK_AXES_RESOLUTION > 8
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 199741594a..e41d6ff195 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -65,6 +65,7 @@ void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
+void send_digitizer(report_digitizer_t *report);
/* host struct */
host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index e5edd74dcb..cc282e6a9b 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -315,6 +315,9 @@ typedef struct {
#endif
#ifdef JOYSTICK_ENABLE
usb_driver_config_t joystick_driver;
+#endif
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ usb_driver_config_t digitizer_driver;
#endif
};
usb_driver_config_t array[0];
@@ -360,6 +363,14 @@ static usb_driver_configs_t drivers = {
# define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK
.joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false),
#endif
+
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+# define DIGITIZER_IN_CAPACITY 4
+# define DIGITIZER_OUT_CAPACITY 4
+# define DIGITIZER_IN_MODE USB_EP_MODE_TYPE_BULK
+# define DIGITIZER_OUT_MODE USB_EP_MODE_TYPE_BULK
+ .digitizer_driver = QMK_USB_DRIVER_CONFIG(DIGITIZER, 0, false),
+#endif
};
#define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t))
@@ -930,6 +941,23 @@ void send_consumer(uint16_t data) {
#endif
}
+void send_digitizer(report_digitizer_t *report) {
+#ifdef DIGITIZER_ENABLE
+# ifdef DIGITIZER_SHARED_EP
+ osalSysLock();
+ if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+ osalSysUnlock();
+ return;
+ }
+
+ usbStartTransmitI(&USB_DRIVER, DIGITIZER_IN_EPNUM, (uint8_t *)report, sizeof(report_digitizer_t));
+ osalSysUnlock();
+# else
+ chnWrite(&drivers.digitizer_driver.driver, (uint8_t *)report, sizeof(report_digitizer_t));
+# endif
+#endif
+}
+
/* ---------------------------------------------------------
* Console functions
* ---------------------------------------------------------
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 4ac079e168..8ddb8b1c4b 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -142,9 +142,7 @@ static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
-host_driver_t lufa_driver = {
- keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer,
-};
+host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
#ifdef VIRTSER_ENABLE
// clang-format off
@@ -525,6 +523,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
/* Setup joystick endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((JOYSTICK_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);
#endif
+
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ /* Setup digitizer endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((DIGITIZER_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, DIGITIZER_EPSIZE, 1);
+#endif
}
/* FIXME: Expose this table in the docs somehow
@@ -983,6 +986,23 @@ void virtser_send(const uint8_t byte) {
}
#endif
+void send_digitizer(report_digitizer_t *report) {
+#ifdef DIGITIZER_ENABLE
+ uint8_t timeout = 255;
+
+ if (USB_DeviceState != DEVICE_STATE_Configured) return;
+
+ Endpoint_SelectEndpoint(DIGITIZER_IN_EPNUM);
+
+ /* Check if write ready for a polling interval around 10ms */
+ while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ if (!Endpoint_IsReadWriteAllowed()) return;
+
+ Endpoint_Write_Stream_LE(report, sizeof(report_digitizer_t), NULL);
+ Endpoint_ClearIN();
+#endif
+}
+
/*******************************************************************************
* main
******************************************************************************/
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 7a4a790315..099964ae56 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -158,6 +158,53 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
# endif
#endif
+#ifdef DIGITIZER_ENABLE
+# ifndef DIGITIZER_SHARED_EP
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM DigitizerReport[] = {
+# elif !defined(SHARED_REPORT_STARTED)
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
+# define SHARED_REPORT_STARTED
+# endif
+ HID_RI_USAGE_PAGE(8, 0x0D), // Digitizers
+ HID_RI_USAGE(8, 0x01), // Digitizer
+ HID_RI_COLLECTION(8, 0x01), // Application
+# ifdef DIGITIZER_SHARED_EP
+ HID_RI_REPORT_ID(8, REPORT_ID_DIGITIZER),
+# endif
+ HID_RI_USAGE(8, 0x20), // Stylus
+ HID_RI_COLLECTION(8, 0x00), // Physical
+ // Tip Switch (1 bit)
+ HID_RI_USAGE(8, 0x42), // Tip Switch
+ HID_RI_LOGICAL_MINIMUM(8, 0x00),
+ HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+ HID_RI_REPORT_SIZE(8, 0x01),
+ HID_RI_REPORT_COUNT(8, 0x01),
+ HID_RI_INPUT(8, HID_IOF_VARIABLE),
+ // In Range (1 bit)
+ HID_RI_USAGE(8, 0x32), // In Range
+ HID_RI_INPUT(8, HID_IOF_VARIABLE),
+ // Padding (6 bits)
+ HID_RI_REPORT_COUNT(8, 0x06),
+ HID_RI_INPUT(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE),
+
+ // X/Y Position (4 bytes)
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+ HID_RI_LOGICAL_MAXIMUM(16, 0x7FFF),
+ HID_RI_REPORT_SIZE(8, 0x10),
+ HID_RI_REPORT_COUNT(8, 0x01),
+ HID_RI_UNIT(8, 0x33), // Inch, English Linear
+ HID_RI_UNIT_EXPONENT(8, 0x0E), // -2
+ HID_RI_USAGE(8, 0x30), // X
+ HID_RI_INPUT(8, HID_IOF_VARIABLE),
+ HID_RI_USAGE(8, 0x31), // Y
+ HID_RI_INPUT(8, HID_IOF_VARIABLE),
+ HID_RI_END_COLLECTION(0),
+ HID_RI_END_COLLECTION(0),
+# ifndef DIGITIZER_SHARED_EP
+};
+# endif
+#endif
+
#if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED)
const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
#endif
@@ -227,6 +274,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
HID_RI_END_COLLECTION(0),
#endif
+
#ifdef SHARED_EP_ENABLE
};
#endif
@@ -921,6 +969,46 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.PollingIntervalMS = USB_POLLING_INTERVAL_MS
}
#endif
+
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ /*
+ * Digitizer
+ */
+ .Digitizer_Interface = {
+ .Header = {
+ .Size = sizeof(USB_Descriptor_Interface_t),
+ .Type = DTYPE_Interface
+ },
+ .InterfaceNumber = DIGITIZER_INTERFACE,
+ .AlternateSetting = 0x00,
+ .TotalEndpoints = 1,
+ .Class = HID_CSCP_HIDClass,
+ .SubClass = HID_CSCP_NonBootSubclass,
+ .Protocol = HID_CSCP_NonBootProtocol,
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+ .Digitizer_HID = {
+ .Header = {
+ .Size = sizeof(USB_HID_Descriptor_HID_t),
+ .Type = HID_DTYPE_HID
+ },
+ .HIDSpec = VERSION_BCD(1, 1, 1),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = HID_DTYPE_Report,
+ .HIDReportLength = sizeof(DigitizerReport)
+ },
+ .Digitizer_INEndpoint = {
+ .Header = {
+ .Size = sizeof(USB_Descriptor_Endpoint_t),
+ .Type = DTYPE_Endpoint
+ },
+ .EndpointAddress = (ENDPOINT_DIR_IN | DIGITIZER_IN_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = DIGITIZER_EPSIZE,
+ .PollingIntervalMS = USB_POLLING_INTERVAL_MS
+ },
+#endif
};
/*
@@ -1059,6 +1147,13 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
#endif
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ case DIGITIZER_INTERFACE:
+ Address = &ConfigurationDescriptor.Digitizer_HID;
+ Size = sizeof(USB_HID_Descriptor_HID_t);
+
+ break;
+#endif
}
break;
@@ -1108,6 +1203,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
Address = &JoystickReport;
Size = sizeof(JoystickReport);
break;
+#endif
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ case DIGITIZER_INTERFACE:
+ Address = &DigitizerReport;
+ Size = sizeof(DigitizerReport);
+ break;
#endif
}
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index 867e549b4f..0f0c78f66c 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -135,6 +135,13 @@ typedef struct {
USB_HID_Descriptor_HID_t Joystick_HID;
USB_Descriptor_Endpoint_t Joystick_INEndpoint;
#endif
+
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ // Digitizer HID Interface
+ USB_Descriptor_Interface_t Digitizer_Interface;
+ USB_HID_Descriptor_HID_t Digitizer_HID;
+ USB_Descriptor_Endpoint_t Digitizer_INEndpoint;
+#endif
} USB_Descriptor_Configuration_t;
/*
@@ -180,6 +187,10 @@ enum usb_interfaces {
#if defined(JOYSTICK_ENABLE)
JOYSTICK_INTERFACE,
#endif
+
+#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
+ DIGITIZER_INTERFACE,
+#endif
TOTAL_INTERFACES
};
@@ -226,7 +237,7 @@ enum usb_endpoints {
# if STM32_USB_USE_OTG1
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
# else
- CONSOLE_OUT_EPNUM = NEXT_EPNUM,
+ CONSOLE_OUT_EPNUM = NEXT_EPNUM,
# endif
# else
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
@@ -259,6 +270,19 @@ enum usb_endpoints {
JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
# endif
#endif
+
+#ifdef DIGITIZER_ENABLE
+# if !defined(DIGITIZER_SHARED_EP)
+ DIGITIZER_IN_EPNUM = NEXT_EPNUM,
+# if STM32_USB_USE_OTG1
+ DIGITIZER_OUT_EPNUM = DIGITIZER_IN_EPNUM,
+# else
+ DIGITIZER_OUT_EPNUM = NEXT_EPNUM,
+# endif
+# else
+# define DIGITIZER_IN_EPNUM SHARED_IN_EPNUM
+# endif
+#endif
};
#ifdef PROTOCOL_LUFA
@@ -284,5 +308,6 @@ enum usb_endpoints {
#define CDC_NOTIFICATION_EPSIZE 8
#define CDC_EPSIZE 16
#define JOYSTICK_EPSIZE 8
+#define DIGITIZER_EPSIZE 8
uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 98cebf6012..485b20c900 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -292,6 +292,14 @@ static void send_consumer(uint16_t data) {
#endif
}
+void send_digitizer(report_digitizer_t *report) {
+#ifdef DIGITIZER_ENABLE
+ if (usbInterruptIsReadyShared()) {
+ usbSetInterruptShared((void *)report, sizeof(report_digitizer_t));
+ }
+#endif
+}
+
/*------------------------------------------------------------------*
* Request from host *
*------------------------------------------------------------------*/
@@ -510,8 +518,46 @@ const PROGMEM uchar shared_hid_report[] = {
0x95, 0x01, // Report Count (1)
0x75, 0x10, // Report Size (16)
0x81, 0x00, // Input (Data, Array, Absolute)
- 0xC0 // End Collection
+ 0xC0, // End Collection
+#endif
+
+#ifdef DIGITIZER_ENABLE
+ // Digitizer report descriptor
+ 0x05, 0x0D, // Usage Page (Digitizers)
+ 0x09, 0x01, // Usage (Digitizer)
+ 0xA1, 0x01, // Collection (Application)
+ 0x85, REPORT_ID_DIGITIZER, // Report ID
+ 0x09, 0x22, // Usage (Finger)
+ 0xA1, 0x00, // Collection (Physical)
+ // Tip Switch (1 bit)
+ 0x09, 0x42, // Usage (Tip Switch)
+ 0x15, 0x00, // Logical Minimum
+ 0x25, 0x01, // Logical Maximum
+ 0x95, 0x01, // Report Count (1)
+ 0x75, 0x01, // Report Size (16)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ // In Range (1 bit)
+ 0x09, 0x32, // Usage (In Range)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ // Padding (6 bits)
+ 0x95, 0x06, // Report Count (6)
+ 0x81, 0x03, // Input (Constant)
+
+ // X/Y Position (4 bytes)
+ 0x05, 0x01, // Usage Page (Generic Desktop)
+ 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
+ 0x95, 0x01, // Report Count (1)
+ 0x75, 0x10, // Report Size (16)
+ 0x65, 0x33, // Unit (Inch, English Linear)
+ 0x55, 0x0E, // Unit Exponent (-2)
+ 0x09, 0x30, // Usage (X)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ 0x09, 0x31, // Usage (Y)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ 0xC0, // End Collection
+ 0xC0 // End Collection
#endif
+
#ifdef SHARED_EP_ENABLE
};
#endif
--
cgit v1.2.3
From 96e2b13d1de227cdc2b918fb0292bd832d346a25 Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Wed, 18 Aug 2021 00:11:07 +0100
Subject: Begin to carve out platform/protocol API - Single main loop (#13843)
* Begin to carve out platform/protocol API
* Fix up after rebase---
build_keyboard.mk | 6 +-
quantum/main.c | 41 ++++++
tmk_core/common.mk | 1 +
tmk_core/common/arm_atsam/platform.c | 21 +++
tmk_core/common/avr/platform.c | 21 +++
tmk_core/common/chibios/platform.c | 22 +++
tmk_core/common/test/platform.c | 21 +++
tmk_core/protocol/chibios.mk | 2 +-
tmk_core/protocol/chibios/chibios.c | 255 +++++++++++++++++++++++++++++++++
tmk_core/protocol/chibios/main.c | 263 -----------------------------------
tmk_core/protocol/lufa/lufa.c | 64 ++++-----
tmk_core/protocol/vusb.mk | 2 +-
tmk_core/protocol/vusb/main.c | 179 ------------------------
tmk_core/protocol/vusb/protocol.c | 178 ++++++++++++++++++++++++
14 files changed, 596 insertions(+), 480 deletions(-)
create mode 100644 quantum/main.c
create mode 100644 tmk_core/common/arm_atsam/platform.c
create mode 100644 tmk_core/common/avr/platform.c
create mode 100644 tmk_core/common/chibios/platform.c
create mode 100644 tmk_core/common/test/platform.c
create mode 100644 tmk_core/protocol/chibios/chibios.c
delete mode 100644 tmk_core/protocol/chibios/main.c
delete mode 100644 tmk_core/protocol/vusb/main.c
create mode 100644 tmk_core/protocol/vusb/protocol.c
(limited to 'tmk_core/protocol/vusb')
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 62a7ba6a0d..46d1e45667 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -338,9 +338,11 @@ ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
endif
# project specific files
-SRC += $(KEYBOARD_SRC) \
+SRC += \
+ $(KEYBOARD_SRC) \
$(KEYMAP_C) \
- $(QUANTUM_SRC)
+ $(QUANTUM_SRC) \
+ $(QUANTUM_DIR)/main.c \
# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax
diff --git a/quantum/main.c b/quantum/main.c
new file mode 100644
index 0000000000..2cbcd73d8f
--- /dev/null
+++ b/quantum/main.c
@@ -0,0 +1,41 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "keyboard.h"
+
+void platform_setup(void);
+
+void protocol_setup(void);
+void protocol_init(void);
+void protocol_task(void);
+
+/** \brief Main
+ *
+ * FIXME: Needs doc
+ */
+int main(void) __attribute__((weak));
+int main(void) {
+ platform_setup();
+ protocol_setup();
+
+ protocol_init();
+
+ /* Main loop */
+ while (true) {
+ protocol_task();
+ housekeeping_task();
+ }
+}
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 923a736d35..57de8d95e8 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -12,6 +12,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/report.c \
$(COMMON_DIR)/sync_timer.c \
$(COMMON_DIR)/usb_util.c \
+ $(PLATFORM_COMMON_DIR)/platform.c \
$(PLATFORM_COMMON_DIR)/suspend.c \
$(PLATFORM_COMMON_DIR)/timer.c \
$(PLATFORM_COMMON_DIR)/bootloader.c \
diff --git a/tmk_core/common/arm_atsam/platform.c b/tmk_core/common/arm_atsam/platform.c
new file mode 100644
index 0000000000..3e35b4fe4c
--- /dev/null
+++ b/tmk_core/common/arm_atsam/platform.c
@@ -0,0 +1,21 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "platform_deps.h"
+
+void platform_setup(void) {
+ // do nothing
+}
diff --git a/tmk_core/common/avr/platform.c b/tmk_core/common/avr/platform.c
new file mode 100644
index 0000000000..3e35b4fe4c
--- /dev/null
+++ b/tmk_core/common/avr/platform.c
@@ -0,0 +1,21 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "platform_deps.h"
+
+void platform_setup(void) {
+ // do nothing
+}
diff --git a/tmk_core/common/chibios/platform.c b/tmk_core/common/chibios/platform.c
new file mode 100644
index 0000000000..d4a229f278
--- /dev/null
+++ b/tmk_core/common/chibios/platform.c
@@ -0,0 +1,22 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "platform_deps.h"
+
+void platform_setup(void) {
+ halInit();
+ chSysInit();
+}
\ No newline at end of file
diff --git a/tmk_core/common/test/platform.c b/tmk_core/common/test/platform.c
new file mode 100644
index 0000000000..8ddceeda8f
--- /dev/null
+++ b/tmk_core/common/test/platform.c
@@ -0,0 +1,21 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "platform_deps.h"
+
+void platform_setup(void) {
+ // do nothing
+}
\ No newline at end of file
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk
index d01697835b..a7f2d8e93d 100644
--- a/tmk_core/protocol/chibios.mk
+++ b/tmk_core/protocol/chibios.mk
@@ -3,7 +3,7 @@ CHIBIOS_DIR = $(PROTOCOL_DIR)/chibios
SRC += $(CHIBIOS_DIR)/usb_main.c
-SRC += $(CHIBIOS_DIR)/main.c
+SRC += $(CHIBIOS_DIR)/chibios.c
SRC += usb_descriptor.c
SRC += $(CHIBIOS_DIR)/usb_driver.c
SRC += $(CHIBIOS_DIR)/usb_util.c
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
new file mode 100644
index 0000000000..78a2e3fcbb
--- /dev/null
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -0,0 +1,255 @@
+/*
+ * (c) 2015 flabberast
+ *
+ * Based on the following work:
+ * - Guillaume Duc's raw hid example (MIT License)
+ * https://github.com/guiduc/usb-hid-chibios-example
+ * - PJRC Teensy examples (MIT License)
+ * https://www.pjrc.com/teensy/usb_keyboard.html
+ * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
+ * https://github.com/tmk/tmk_keyboard/
+ * - ChibiOS demo code (Apache 2.0 License)
+ * http://www.chibios.org
+ *
+ * Since some GPL'd code is used, this work is licensed under
+ * GPL v2 or later.
+ */
+
+#include
+#include
+
+#include "usb_main.h"
+
+/* TMK includes */
+#include "report.h"
+#include "host.h"
+#include "host_driver.h"
+#include "keyboard.h"
+#include "action.h"
+#include "action_util.h"
+#include "mousekey.h"
+#include "led.h"
+#include "sendchar.h"
+#include "debug.h"
+#include "print.h"
+
+#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
+// Change this to be TRUE once we've migrated keyboards to the new init system
+// Remember to change docs/platformdev_chibios_earlyinit.md as well.
+# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE
+#endif
+
+#ifdef SLEEP_LED_ENABLE
+# include "sleep_led.h"
+#endif
+#ifdef SERIAL_LINK_ENABLE
+# include "serial_link/system/serial_link.h"
+#endif
+#ifdef VISUALIZER_ENABLE
+# include "visualizer/visualizer.h"
+#endif
+#ifdef MIDI_ENABLE
+# include "qmk_midi.h"
+#endif
+#include "suspend.h"
+#include "wait.h"
+
+/* -------------------------
+ * TMK host driver defs
+ * -------------------------
+ */
+
+/* declarations */
+uint8_t keyboard_leds(void);
+void send_keyboard(report_keyboard_t *report);
+void send_mouse(report_mouse_t *report);
+void send_system(uint16_t data);
+void send_consumer(uint16_t data);
+void send_digitizer(report_digitizer_t *report);
+
+/* host struct */
+host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
+
+#ifdef VIRTSER_ENABLE
+void virtser_task(void);
+#endif
+
+#ifdef RAW_ENABLE
+void raw_hid_task(void);
+#endif
+
+#ifdef CONSOLE_ENABLE
+void console_task(void);
+#endif
+#ifdef MIDI_ENABLE
+void midi_ep_task(void);
+#endif
+
+/* TESTING
+ * Amber LED blinker thread, times are in milliseconds.
+ */
+/* set this variable to non-zero anywhere to blink once */
+// static THD_WORKING_AREA(waThread1, 128);
+// static THD_FUNCTION(Thread1, arg) {
+
+// (void)arg;
+// chRegSetThreadName("blinker");
+// while (true) {
+// systime_t time;
+
+// time = USB_DRIVER.state == USB_ACTIVE ? 250 : 500;
+// palClearLine(LINE_CAPS_LOCK);
+// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
+// palSetLine(LINE_CAPS_LOCK);
+// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
+// }
+// }
+
+/* Early initialisation
+ */
+__attribute__((weak)) void early_hardware_init_pre(void) {
+#if EARLY_INIT_PERFORM_BOOTLOADER_JUMP
+ void enter_bootloader_mode_if_requested(void);
+ enter_bootloader_mode_if_requested();
+#endif // EARLY_INIT_PERFORM_BOOTLOADER_JUMP
+}
+
+__attribute__((weak)) void early_hardware_init_post(void) {}
+
+__attribute__((weak)) void board_init(void) {}
+
+// This overrides what's normally in ChibiOS board definitions
+void __early_init(void) {
+ early_hardware_init_pre();
+
+ // This is the renamed equivalent of __early_init in the board.c file
+ void __chibios_override___early_init(void);
+ __chibios_override___early_init();
+
+ early_hardware_init_post();
+}
+
+// This overrides what's normally in ChibiOS board definitions
+void boardInit(void) {
+ // This is the renamed equivalent of boardInit in the board.c file
+ void __chibios_override_boardInit(void);
+ __chibios_override_boardInit();
+
+ board_init();
+}
+
+void protocol_setup(void) {
+ // TESTING
+ // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+
+ keyboard_setup();
+}
+
+void protocol_init(void) {
+ /* Init USB */
+ usb_event_queue_init();
+ init_usb_driver(&USB_DRIVER);
+
+#ifdef MIDI_ENABLE
+ setup_midi();
+#endif
+
+#ifdef SERIAL_LINK_ENABLE
+ init_serial_link();
+#endif
+
+#ifdef VISUALIZER_ENABLE
+ visualizer_init();
+#endif
+
+ host_driver_t *driver = NULL;
+
+ /* Wait until the USB or serial link is active */
+ while (true) {
+#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
+ if (USB_DRIVER.state == USB_ACTIVE) {
+ driver = &chibios_driver;
+ break;
+ }
+#else
+ driver = &chibios_driver;
+ break;
+#endif
+#ifdef SERIAL_LINK_ENABLE
+ if (is_serial_link_connected()) {
+ driver = get_serial_link_driver();
+ break;
+ }
+ serial_link_update();
+#endif
+ wait_ms(50);
+ }
+
+ /* Do need to wait here!
+ * Otherwise the next print might start a transfer on console EP
+ * before the USB is completely ready, which sometimes causes
+ * HardFaults.
+ */
+ wait_ms(50);
+
+ print("USB configured.\n");
+
+ /* init TMK modules */
+ keyboard_init();
+ host_set_driver(driver);
+
+#ifdef SLEEP_LED_ENABLE
+ sleep_led_init();
+#endif
+
+ print("Keyboard start.\n");
+}
+
+void protocol_task(void) {
+ usb_event_queue_task();
+
+#if !defined(NO_USB_STARTUP_CHECK)
+ if (USB_DRIVER.state == USB_SUSPENDED) {
+ print("[s]");
+# ifdef VISUALIZER_ENABLE
+ visualizer_suspend();
+# endif
+ while (USB_DRIVER.state == USB_SUSPENDED) {
+ /* Do this in the suspended state */
+# ifdef SERIAL_LINK_ENABLE
+ serial_link_update();
+# endif
+ suspend_power_down(); // on AVR this deep sleeps for 15ms
+ /* Remote wakeup */
+ if (suspend_wakeup_condition()) {
+ usbWakeupHost(&USB_DRIVER);
+ restart_usb_driver(&USB_DRIVER);
+ }
+ }
+ /* Woken up */
+ // variables has been already cleared by the wakeup hook
+ send_keyboard_report();
+# ifdef MOUSEKEY_ENABLE
+ mousekey_send();
+# endif /* MOUSEKEY_ENABLE */
+
+# ifdef VISUALIZER_ENABLE
+ visualizer_resume();
+# endif
+ }
+#endif
+
+ keyboard_task();
+#ifdef CONSOLE_ENABLE
+ console_task();
+#endif
+#ifdef MIDI_ENABLE
+ midi_ep_task();
+#endif
+#ifdef VIRTSER_ENABLE
+ virtser_task();
+#endif
+#ifdef RAW_ENABLE
+ raw_hid_task();
+#endif
+}
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
deleted file mode 100644
index e41d6ff195..0000000000
--- a/tmk_core/protocol/chibios/main.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * (c) 2015 flabberast
- *
- * Based on the following work:
- * - Guillaume Duc's raw hid example (MIT License)
- * https://github.com/guiduc/usb-hid-chibios-example
- * - PJRC Teensy examples (MIT License)
- * https://www.pjrc.com/teensy/usb_keyboard.html
- * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
- * https://github.com/tmk/tmk_keyboard/
- * - ChibiOS demo code (Apache 2.0 License)
- * http://www.chibios.org
- *
- * Since some GPL'd code is used, this work is licensed under
- * GPL v2 or later.
- */
-
-#include
-#include
-
-#include "usb_main.h"
-
-/* TMK includes */
-#include "report.h"
-#include "host.h"
-#include "host_driver.h"
-#include "keyboard.h"
-#include "action.h"
-#include "action_util.h"
-#include "mousekey.h"
-#include "led.h"
-#include "sendchar.h"
-#include "debug.h"
-#include "print.h"
-
-#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
-// Change this to be TRUE once we've migrated keyboards to the new init system
-// Remember to change docs/platformdev_chibios_earlyinit.md as well.
-# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE
-#endif
-
-#ifdef SLEEP_LED_ENABLE
-# include "sleep_led.h"
-#endif
-#ifdef SERIAL_LINK_ENABLE
-# include "serial_link/system/serial_link.h"
-#endif
-#ifdef VISUALIZER_ENABLE
-# include "visualizer/visualizer.h"
-#endif
-#ifdef MIDI_ENABLE
-# include "qmk_midi.h"
-#endif
-#include "suspend.h"
-#include "wait.h"
-
-/* -------------------------
- * TMK host driver defs
- * -------------------------
- */
-
-/* declarations */
-uint8_t keyboard_leds(void);
-void send_keyboard(report_keyboard_t *report);
-void send_mouse(report_mouse_t *report);
-void send_system(uint16_t data);
-void send_consumer(uint16_t data);
-void send_digitizer(report_digitizer_t *report);
-
-/* host struct */
-host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
-
-#ifdef VIRTSER_ENABLE
-void virtser_task(void);
-#endif
-
-#ifdef RAW_ENABLE
-void raw_hid_task(void);
-#endif
-
-#ifdef CONSOLE_ENABLE
-void console_task(void);
-#endif
-#ifdef MIDI_ENABLE
-void midi_ep_task(void);
-#endif
-
-/* TESTING
- * Amber LED blinker thread, times are in milliseconds.
- */
-/* set this variable to non-zero anywhere to blink once */
-// static THD_WORKING_AREA(waThread1, 128);
-// static THD_FUNCTION(Thread1, arg) {
-
-// (void)arg;
-// chRegSetThreadName("blinker");
-// while (true) {
-// systime_t time;
-
-// time = USB_DRIVER.state == USB_ACTIVE ? 250 : 500;
-// palClearLine(LINE_CAPS_LOCK);
-// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
-// palSetLine(LINE_CAPS_LOCK);
-// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
-// }
-// }
-
-/* Early initialisation
- */
-__attribute__((weak)) void early_hardware_init_pre(void) {
-#if EARLY_INIT_PERFORM_BOOTLOADER_JUMP
- void enter_bootloader_mode_if_requested(void);
- enter_bootloader_mode_if_requested();
-#endif // EARLY_INIT_PERFORM_BOOTLOADER_JUMP
-}
-
-__attribute__((weak)) void early_hardware_init_post(void) {}
-
-__attribute__((weak)) void board_init(void) {}
-
-// This overrides what's normally in ChibiOS board definitions
-void __early_init(void) {
- early_hardware_init_pre();
-
- // This is the renamed equivalent of __early_init in the board.c file
- void __chibios_override___early_init(void);
- __chibios_override___early_init();
-
- early_hardware_init_post();
-}
-
-// This overrides what's normally in ChibiOS board definitions
-void boardInit(void) {
- // This is the renamed equivalent of boardInit in the board.c file
- void __chibios_override_boardInit(void);
- __chibios_override_boardInit();
-
- board_init();
-}
-
-/* Main thread
- */
-int main(void) {
- /* ChibiOS/RT init */
- halInit();
- chSysInit();
-
- // TESTING
- // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
-
- keyboard_setup();
-
- /* Init USB */
- usb_event_queue_init();
- init_usb_driver(&USB_DRIVER);
-
-#ifdef MIDI_ENABLE
- setup_midi();
-#endif
-
-#ifdef SERIAL_LINK_ENABLE
- init_serial_link();
-#endif
-
-#ifdef VISUALIZER_ENABLE
- visualizer_init();
-#endif
-
- host_driver_t *driver = NULL;
-
- /* Wait until the USB or serial link is active */
- while (true) {
-#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
- if (USB_DRIVER.state == USB_ACTIVE) {
- driver = &chibios_driver;
- break;
- }
-#else
- driver = &chibios_driver;
- break;
-#endif
-#ifdef SERIAL_LINK_ENABLE
- if (is_serial_link_connected()) {
- driver = get_serial_link_driver();
- break;
- }
- serial_link_update();
-#endif
- wait_ms(50);
- }
-
- /* Do need to wait here!
- * Otherwise the next print might start a transfer on console EP
- * before the USB is completely ready, which sometimes causes
- * HardFaults.
- */
- wait_ms(50);
-
- print("USB configured.\n");
-
- /* init TMK modules */
- keyboard_init();
- host_set_driver(driver);
-
-#ifdef SLEEP_LED_ENABLE
- sleep_led_init();
-#endif
-
- print("Keyboard start.\n");
-
- /* Main loop */
- while (true) {
- usb_event_queue_task();
-
-#if !defined(NO_USB_STARTUP_CHECK)
- if (USB_DRIVER.state == USB_SUSPENDED) {
- print("[s]");
-# ifdef VISUALIZER_ENABLE
- visualizer_suspend();
-# endif
- while (USB_DRIVER.state == USB_SUSPENDED) {
- /* Do this in the suspended state */
-# ifdef SERIAL_LINK_ENABLE
- serial_link_update();
-# endif
- suspend_power_down(); // on AVR this deep sleeps for 15ms
- /* Remote wakeup */
- if (suspend_wakeup_condition()) {
- usbWakeupHost(&USB_DRIVER);
- restart_usb_driver(&USB_DRIVER);
- }
- }
- /* Woken up */
- // variables has been already cleared by the wakeup hook
- send_keyboard_report();
-# ifdef MOUSEKEY_ENABLE
- mousekey_send();
-# endif /* MOUSEKEY_ENABLE */
-
-# ifdef VISUALIZER_ENABLE
- visualizer_resume();
-# endif
- }
-#endif
-
- keyboard_task();
-#ifdef CONSOLE_ENABLE
- console_task();
-#endif
-#ifdef MIDI_ENABLE
- midi_ep_task();
-#endif
-#ifdef VIRTSER_ENABLE
- virtser_task();
-#endif
-#ifdef RAW_ENABLE
- raw_hid_task();
-#endif
-
- // Run housekeeping
- housekeeping_task();
- }
-}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 8ddb8b1c4b..e638dbc0fb 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1033,18 +1033,16 @@ static void setup_usb(void) {
USB_Device_EnableSOFEvents();
}
-/** \brief Main
- *
- * FIXME: Needs doc
- */
-int main(void) __attribute__((weak));
-int main(void) {
+void protocol_setup(void) {
#ifdef MIDI_ENABLE
setup_midi();
#endif
setup_mcu();
keyboard_setup();
+}
+
+void protocol_init(void) {
setup_usb();
sei();
@@ -1078,57 +1076,55 @@ int main(void) {
#endif
print("Keyboard start.\n");
- while (1) {
+}
+
+void protocol_task(void) {
#if !defined(NO_USB_STARTUP_CHECK)
- if (USB_DeviceState == DEVICE_STATE_Suspended) {
- print("[s]");
- while (USB_DeviceState == DEVICE_STATE_Suspended) {
- suspend_power_down();
- if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
- USB_Device_SendRemoteWakeup();
- clear_keyboard();
+ if (USB_DeviceState == DEVICE_STATE_Suspended) {
+ print("[s]");
+ while (USB_DeviceState == DEVICE_STATE_Suspended) {
+ suspend_power_down();
+ if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
+ USB_Device_SendRemoteWakeup();
+ clear_keyboard();
# if USB_SUSPEND_WAKEUP_DELAY > 0
- // Some hubs, kvm switches, and monitors do
- // weird things, with USB device state bouncing
- // around wildly on wakeup, yielding race
- // conditions that can corrupt the keyboard state.
- //
- // Pause for a while to let things settle...
- wait_ms(USB_SUSPEND_WAKEUP_DELAY);
+ // Some hubs, kvm switches, and monitors do
+ // weird things, with USB device state bouncing
+ // around wildly on wakeup, yielding race
+ // conditions that can corrupt the keyboard state.
+ //
+ // Pause for a while to let things settle...
+ wait_ms(USB_SUSPEND_WAKEUP_DELAY);
# endif
- }
}
- suspend_wakeup_init();
}
+ suspend_wakeup_init();
+ }
#endif
- keyboard_task();
+ keyboard_task();
#ifdef MIDI_ENABLE
- MIDI_Device_USBTask(&USB_MIDI_Interface);
+ MIDI_Device_USBTask(&USB_MIDI_Interface);
#endif
#ifdef MODULE_ADAFRUIT_BLE
- adafruit_ble_task();
+ adafruit_ble_task();
#endif
#ifdef VIRTSER_ENABLE
- virtser_task();
- CDC_Device_USBTask(&cdc_device);
+ virtser_task();
+ CDC_Device_USBTask(&cdc_device);
#endif
#ifdef RAW_ENABLE
- raw_hid_task();
+ raw_hid_task();
#endif
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
- USB_USBTask();
+ USB_USBTask();
#endif
-
- // Run housekeeping
- housekeeping_task();
- }
}
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) { return get_usb_descriptor(wValue, wIndex, DescriptorAddress); }
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index e4d013b38d..5572597e21 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -3,7 +3,7 @@ VUSB_DIR = protocol/vusb
# Path to the V-USB library
VUSB_PATH = $(LIB_PATH)/vusb
-SRC += $(VUSB_DIR)/main.c \
+SRC += $(VUSB_DIR)/protocol.c \
$(VUSB_DIR)/vusb.c \
$(VUSB_DIR)/usb_util.c \
$(VUSB_PATH)/usbdrv/usbdrv.c \
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
deleted file mode 100644
index 53926a7493..0000000000
--- a/tmk_core/protocol/vusb/main.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/* Name: main.c
- * Project: hid-mouse, a very simple HID example
- * Author: Christian Starkjohann
- * Creation Date: 2008-04-07
- * Tabsize: 4
- * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
- * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
- */
-
-#include
-
-#include
-#include
-#include
-#include
-
-#include
-
-#include "vusb.h"
-
-#include "keyboard.h"
-#include "host.h"
-#include "timer.h"
-#include "print.h"
-#include "suspend.h"
-#include "wait.h"
-#include "sendchar.h"
-
-#ifdef SLEEP_LED_ENABLE
-# include "sleep_led.h"
-#endif
-
-#ifdef CONSOLE_ENABLE
-void console_task(void);
-#endif
-
-#ifdef RAW_ENABLE
-void raw_hid_task(void);
-#endif
-
-/* This is from main.c of USBaspLoader */
-static void initForUsbConnectivity(void) {
- uint8_t i = 0;
-
- usbInit();
- /* enforce USB re-enumerate: */
- usbDeviceDisconnect(); /* do this while interrupts are disabled */
- while (--i) { /* fake USB disconnect for > 250 ms */
- wdt_reset();
- wait_ms(1);
- }
- usbDeviceConnect();
-}
-
-static void vusb_send_remote_wakeup(void) {
- cli();
-
- uint8_t ddr_orig = USBDDR;
- USBOUT |= (1 << USBMINUS);
- USBDDR = ddr_orig | USBMASK;
- USBOUT ^= USBMASK;
-
- wait_ms(25);
-
- USBOUT ^= USBMASK;
- USBDDR = ddr_orig;
- USBOUT &= ~(1 << USBMINUS);
-
- sei();
-}
-
-bool vusb_suspended = false;
-
-static void vusb_suspend(void) {
- vusb_suspended = true;
-
-#ifdef SLEEP_LED_ENABLE
- sleep_led_enable();
-#endif
-
- suspend_power_down();
-}
-
-#if USB_COUNT_SOF
-static void vusb_wakeup(void) {
- vusb_suspended = false;
- suspend_wakeup_init();
-
-# ifdef SLEEP_LED_ENABLE
- sleep_led_disable();
-# endif
-}
-#endif
-
-/** \brief Setup USB
- *
- * FIXME: Needs doc
- */
-static void setup_usb(void) { initForUsbConnectivity(); }
-
-/** \brief Main
- *
- * FIXME: Needs doc
- */
-int main(void) __attribute__((weak));
-int main(void) {
-#if USB_COUNT_SOF
- uint16_t sof_timer = timer_read();
-#endif
-
-#ifdef CLKPR
- // avoid unintentional changes of clock frequency in devices that have a
- // clock prescaler
- clock_prescale_set(clock_div_1);
-#endif
- keyboard_setup();
- setup_usb();
- sei();
- keyboard_init();
- host_set_driver(vusb_driver());
-
- wait_ms(50);
-
-#ifdef SLEEP_LED_ENABLE
- sleep_led_init();
-#endif
-
- while (1) {
-#if USB_COUNT_SOF
- if (usbSofCount != 0) {
- usbSofCount = 0;
- sof_timer = timer_read();
- if (vusb_suspended) {
- vusb_wakeup();
- }
- } else {
- // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
- if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
- vusb_suspend();
- }
- }
-#endif
- if (vusb_suspended) {
- vusb_suspend();
- if (suspend_wakeup_condition()) {
- vusb_send_remote_wakeup();
- }
- } else {
- usbPoll();
-
- // TODO: configuration process is inconsistent. it sometime fails.
- // To prevent failing to configure NOT scan keyboard during configuration
- if (usbConfiguration && usbInterruptIsReady()) {
- keyboard_task();
- }
- vusb_transfer_keyboard();
-
-#ifdef RAW_ENABLE
- usbPoll();
-
- if (usbConfiguration && usbInterruptIsReady3()) {
- raw_hid_task();
- }
-#endif
-
-#ifdef CONSOLE_ENABLE
- usbPoll();
-
- if (usbConfiguration && usbInterruptIsReady3()) {
- console_task();
- }
-#endif
-
- // Run housekeeping
- housekeeping_task();
- }
- }
-}
diff --git a/tmk_core/protocol/vusb/protocol.c b/tmk_core/protocol/vusb/protocol.c
new file mode 100644
index 0000000000..89dc795b21
--- /dev/null
+++ b/tmk_core/protocol/vusb/protocol.c
@@ -0,0 +1,178 @@
+/* Name: main.c
+ * Project: hid-mouse, a very simple HID example
+ * Author: Christian Starkjohann
+ * Creation Date: 2008-04-07
+ * Tabsize: 4
+ * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
+ */
+
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "vusb.h"
+
+#include "keyboard.h"
+#include "host.h"
+#include "timer.h"
+#include "print.h"
+#include "suspend.h"
+#include "wait.h"
+#include "sendchar.h"
+
+#ifdef SLEEP_LED_ENABLE
+# include "sleep_led.h"
+#endif
+
+#ifdef CONSOLE_ENABLE
+void console_task(void);
+#endif
+
+#ifdef RAW_ENABLE
+void raw_hid_task(void);
+#endif
+
+/* This is from main.c of USBaspLoader */
+static void initForUsbConnectivity(void) {
+ uint8_t i = 0;
+
+ usbInit();
+ /* enforce USB re-enumerate: */
+ usbDeviceDisconnect(); /* do this while interrupts are disabled */
+ while (--i) { /* fake USB disconnect for > 250 ms */
+ wdt_reset();
+ wait_ms(1);
+ }
+ usbDeviceConnect();
+}
+
+static void vusb_send_remote_wakeup(void) {
+ cli();
+
+ uint8_t ddr_orig = USBDDR;
+ USBOUT |= (1 << USBMINUS);
+ USBDDR = ddr_orig | USBMASK;
+ USBOUT ^= USBMASK;
+
+ wait_ms(25);
+
+ USBOUT ^= USBMASK;
+ USBDDR = ddr_orig;
+ USBOUT &= ~(1 << USBMINUS);
+
+ sei();
+}
+
+bool vusb_suspended = false;
+
+static void vusb_suspend(void) {
+ vusb_suspended = true;
+
+#ifdef SLEEP_LED_ENABLE
+ sleep_led_enable();
+#endif
+
+ suspend_power_down();
+}
+
+#if USB_COUNT_SOF
+static void vusb_wakeup(void) {
+ vusb_suspended = false;
+ suspend_wakeup_init();
+
+# ifdef SLEEP_LED_ENABLE
+ sleep_led_disable();
+# endif
+}
+#endif
+
+/** \brief Setup USB
+ *
+ * FIXME: Needs doc
+ */
+static void setup_usb(void) { initForUsbConnectivity(); }
+
+uint16_t sof_timer = 0;
+
+void protocol_setup(void) {
+#if USB_COUNT_SOF
+ sof_timer = timer_read();
+#endif
+
+#ifdef CLKPR
+ // avoid unintentional changes of clock frequency in devices that have a
+ // clock prescaler
+ clock_prescale_set(clock_div_1);
+#endif
+ keyboard_setup();
+}
+
+void protocol_init(void) {
+ setup_usb();
+ sei();
+
+ keyboard_init();
+
+ host_set_driver(vusb_driver());
+
+ wait_ms(50);
+
+#ifdef SLEEP_LED_ENABLE
+ sleep_led_init();
+#endif
+}
+
+void protocol_task(void) {
+#if USB_COUNT_SOF
+ if (usbSofCount != 0) {
+ usbSofCount = 0;
+ sof_timer = timer_read();
+ if (vusb_suspended) {
+ vusb_wakeup();
+ }
+ } else {
+ // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
+ if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
+ vusb_suspend();
+ }
+ }
+#endif
+ if (vusb_suspended) {
+ vusb_suspend();
+ if (suspend_wakeup_condition()) {
+ vusb_send_remote_wakeup();
+ }
+ } else {
+ usbPoll();
+
+ // TODO: configuration process is inconsistent. it sometime fails.
+ // To prevent failing to configure NOT scan keyboard during configuration
+ if (usbConfiguration && usbInterruptIsReady()) {
+ keyboard_task();
+ }
+ vusb_transfer_keyboard();
+
+#ifdef RAW_ENABLE
+ usbPoll();
+
+ if (usbConfiguration && usbInterruptIsReady3()) {
+ raw_hid_task();
+ }
+#endif
+
+#ifdef CONSOLE_ENABLE
+ usbPoll();
+
+ if (usbConfiguration && usbInterruptIsReady3()) {
+ console_task();
+ }
+#endif
+ }
+}
--
cgit v1.2.3