diff options
author | foxx1337 <foxx1337@yahoo.com> | 2020-03-26 03:34:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-26 02:34:57 +0000 |
commit | 96bfce70009ac15f21e440fd3894e6c11e1b7615 (patch) | |
tree | c9450b02e7b3fa8971d93007290b90d394663718 /tmk_core | |
parent | d68c4d810634f5ffcb29c38d57b16bc72faf45dc (diff) | |
download | qmk_firmware-96bfce70009ac15f21e440fd3894e6c11e1b7615.tar.gz qmk_firmware-96bfce70009ac15f21e440fd3894e6c11e1b7615.zip |
Add RawHID support to ATSAM (Massdrop boards) (#8530)
* Add support for RAW endpoint for arm_atsam
This the excellent work from helluvamatt/qmk_firmware in bb6eeb93b.
* Reformat arm_atsam RAW endpoint code
Co-authored-by: Matt Schneeberger <helluvamatt@gmail.com>
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/protocol/arm_atsam/main_arm_atsam.c | 9 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/conf_usb.h | 1 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/main_usb.c | 7 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | 29 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h | 1 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/usb_main.h | 1 |
6 files changed, 47 insertions, 1 deletions
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index e952a427e..93f34d9c3 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c | |||
@@ -206,10 +206,19 @@ void main_subtask_usb_extra_device(void) { | |||
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | #ifdef RAW_ENABLE | ||
210 | void main_subtask_raw(void) { | ||
211 | udi_hid_raw_receive_report(); | ||
212 | } | ||
213 | #endif | ||
214 | |||
209 | void main_subtasks(void) { | 215 | void main_subtasks(void) { |
210 | main_subtask_usb_state(); | 216 | main_subtask_usb_state(); |
211 | main_subtask_power_check(); | 217 | main_subtask_power_check(); |
212 | main_subtask_usb_extra_device(); | 218 | main_subtask_usb_extra_device(); |
219 | #ifdef RAW_ENABLE | ||
220 | main_subtask_raw(); | ||
221 | #endif | ||
213 | } | 222 | } |
214 | 223 | ||
215 | int main(void) { | 224 | int main(void) { |
diff --git a/tmk_core/protocol/arm_atsam/usb/conf_usb.h b/tmk_core/protocol/arm_atsam/usb/conf_usb.h index f23c2a80d..f236427ca 100644 --- a/tmk_core/protocol/arm_atsam/usb/conf_usb.h +++ b/tmk_core/protocol/arm_atsam/usb/conf_usb.h | |||
@@ -146,6 +146,7 @@ | |||
146 | #ifdef RAW | 146 | #ifdef RAW |
147 | # define UDI_HID_RAW_ENABLE_EXT() main_raw_enable() | 147 | # define UDI_HID_RAW_ENABLE_EXT() main_raw_enable() |
148 | # define UDI_HID_RAW_DISABLE_EXT() main_raw_disable() | 148 | # define UDI_HID_RAW_DISABLE_EXT() main_raw_disable() |
149 | # define UDI_HID_RAW_RECEIVE(buffer, len) main_raw_receive(buffer, len) | ||
149 | #endif | 150 | #endif |
150 | 151 | ||
151 | //@} | 152 | //@} |
diff --git a/tmk_core/protocol/arm_atsam/usb/main_usb.c b/tmk_core/protocol/arm_atsam/usb/main_usb.c index 82ab123fd..24630d949 100644 --- a/tmk_core/protocol/arm_atsam/usb/main_usb.c +++ b/tmk_core/protocol/arm_atsam/usb/main_usb.c | |||
@@ -18,6 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | #include "samd51j18a.h" | 18 | #include "samd51j18a.h" |
19 | #include "conf_usb.h" | 19 | #include "conf_usb.h" |
20 | #include "udd.h" | 20 | #include "udd.h" |
21 | #ifdef RAW | ||
22 | #include "raw_hid.h" | ||
23 | #endif | ||
21 | 24 | ||
22 | uint8_t keyboard_protocol = 1; | 25 | uint8_t keyboard_protocol = 1; |
23 | 26 | ||
@@ -89,4 +92,8 @@ bool main_raw_enable(void) { | |||
89 | } | 92 | } |
90 | 93 | ||
91 | void main_raw_disable(void) { main_b_raw_enable = false; } | 94 | void main_raw_disable(void) { main_b_raw_enable = false; } |
95 | |||
96 | void main_raw_receive(uint8_t *buffer, uint8_t len) { | ||
97 | raw_hid_receive(buffer, len); | ||
98 | } | ||
92 | #endif | 99 | #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 cf9297dc7..8142f297d 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c +++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | |||
@@ -641,6 +641,9 @@ COMPILER_WORD_ALIGNED | |||
641 | static uint8_t udi_hid_raw_report_trans[UDI_HID_RAW_REPORT_SIZE]; | 641 | static uint8_t udi_hid_raw_report_trans[UDI_HID_RAW_REPORT_SIZE]; |
642 | 642 | ||
643 | COMPILER_WORD_ALIGNED | 643 | COMPILER_WORD_ALIGNED |
644 | static uint8_t udi_hid_raw_report_recv[UDI_HID_RAW_REPORT_SIZE]; | ||
645 | |||
646 | COMPILER_WORD_ALIGNED | ||
644 | UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{ | 647 | UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{ |
645 | 0x06, 0x60, 0xFF, // Usage Page (Vendor Defined) | 648 | 0x06, 0x60, 0xFF, // Usage Page (Vendor Defined) |
646 | 0x09, 0x61, // Usage (Vendor Defined) | 649 | 0x09, 0x61, // Usage (Vendor Defined) |
@@ -663,6 +666,7 @@ static bool udi_hid_raw_setreport(void); | |||
663 | static void udi_hid_raw_setreport_valid(void); | 666 | static void udi_hid_raw_setreport_valid(void); |
664 | 667 | ||
665 | static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep); | 668 | static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep); |
669 | static void udi_hid_raw_report_rcvd(udd_ep_status_t status, iram_size_t nb_rcvd, udd_ep_id_t ep); | ||
666 | 670 | ||
667 | bool udi_hid_raw_enable(void) { | 671 | bool udi_hid_raw_enable(void) { |
668 | // Initialize internal values | 672 | // Initialize internal values |
@@ -719,7 +723,30 @@ static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, | |||
719 | 723 | ||
720 | static void udi_hid_raw_setreport_valid(void) {} | 724 | static void udi_hid_raw_setreport_valid(void) {} |
721 | 725 | ||
722 | #endif // RAW | 726 | void raw_hid_send(uint8_t *data, uint8_t length) { |
727 | if (main_b_raw_enable && !udi_hid_raw_b_report_trans_ongoing && length == UDI_HID_RAW_REPORT_SIZE) { | ||
728 | memcpy(udi_hid_raw_report, data, UDI_HID_RAW_REPORT_SIZE); | ||
729 | udi_hid_raw_send_report(); | ||
730 | } | ||
731 | } | ||
732 | |||
733 | bool udi_hid_raw_receive_report(void) { | ||
734 | if (!main_b_raw_enable) { | ||
735 | return false; | ||
736 | } | ||
737 | |||
738 | return udd_ep_run(UDI_HID_RAW_EP_OUT | USB_EP_DIR_OUT, false, udi_hid_raw_report_recv, UDI_HID_RAW_REPORT_SIZE, udi_hid_raw_report_rcvd); | ||
739 | } | ||
740 | |||
741 | static void udi_hid_raw_report_rcvd(udd_ep_status_t status, iram_size_t nb_rcvd, udd_ep_id_t ep) { | ||
742 | UNUSED(ep); | ||
743 | |||
744 | if (status == UDD_EP_TRANSFER_OK && nb_rcvd == UDI_HID_RAW_REPORT_SIZE) { | ||
745 | UDI_HID_RAW_RECEIVE(udi_hid_raw_report_recv, UDI_HID_RAW_REPORT_SIZE); | ||
746 | } | ||
747 | } | ||
748 | |||
749 | #endif //RAW | ||
723 | 750 | ||
724 | //******************************************************************************************** | 751 | //******************************************************************************************** |
725 | // CON | 752 | // 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 82b1cbfe0..6dc1fed3e 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h +++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h | |||
@@ -111,6 +111,7 @@ bool udi_hid_mou_send_report(void); | |||
111 | #ifdef RAW | 111 | #ifdef RAW |
112 | extern UDC_DESC_STORAGE udi_api_t udi_api_hid_raw; | 112 | extern UDC_DESC_STORAGE udi_api_t udi_api_hid_raw; |
113 | bool udi_hid_raw_send_report(void); | 113 | bool udi_hid_raw_send_report(void); |
114 | bool udi_hid_raw_receive_report(void); | ||
114 | #endif // RAW | 115 | #endif // RAW |
115 | 116 | ||
116 | //@} | 117 | //@} |
diff --git a/tmk_core/protocol/arm_atsam/usb/usb_main.h b/tmk_core/protocol/arm_atsam/usb/usb_main.h index e1ffa3e18..3191b2fc1 100644 --- a/tmk_core/protocol/arm_atsam/usb/usb_main.h +++ b/tmk_core/protocol/arm_atsam/usb/usb_main.h | |||
@@ -97,6 +97,7 @@ void main_mou_disable(void); | |||
97 | extern volatile bool main_b_raw_enable; | 97 | extern volatile bool main_b_raw_enable; |
98 | bool main_raw_enable(void); | 98 | bool main_raw_enable(void); |
99 | void main_raw_disable(void); | 99 | void main_raw_disable(void); |
100 | void main_raw_receive(uint8_t *buffer, uint8_t len); | ||
100 | #endif // RAW | 101 | #endif // RAW |
101 | 102 | ||
102 | #endif // _MAIN_H_ | 103 | #endif // _MAIN_H_ |