diff options
author | QMK Bot <hello@qmk.fm> | 2021-07-16 16:09:10 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2021-07-16 16:09:10 +0000 |
commit | 4066662bdf88f2f95b17f4aa950417d97f6210e1 (patch) | |
tree | 08a99ac977d3929f0b86d5e2916b804f34d03de2 /tmk_core | |
parent | 7ed5ac4a6026939898810f9a9c706fb7a09db171 (diff) | |
parent | 366be0f7e9b4f408b7494fcb68142ac70d909170 (diff) | |
download | qmk_firmware-4066662bdf88f2f95b17f4aa950417d97f6210e1.tar.gz qmk_firmware-4066662bdf88f2f95b17f4aa950417d97f6210e1.zip |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/common/arm_atsam/_print.h | 34 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/printf.c | 72 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/printf.h | 7 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/printf.mk | 1 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/main_arm_atsam.c | 54 |
5 files changed, 54 insertions, 114 deletions
diff --git a/tmk_core/common/arm_atsam/_print.h b/tmk_core/common/arm_atsam/_print.h deleted file mode 100644 index 04320ee38..000000000 --- a/tmk_core/common/arm_atsam/_print.h +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | /* Copyright 2012 Jun Wako <wakojun@gmail.com> */ | ||
2 | /* Very basic print functions, intended to be used with usb_debug_only.c | ||
3 | * http://www.pjrc.com/teensy/ | ||
4 | * Copyright (c) 2008 PJRC.COM, LLC | ||
5 | * | ||
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | * of this software and associated documentation files (the "Software"), to deal | ||
8 | * in the Software without restriction, including without limitation the rights | ||
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | * copies of the Software, and to permit persons to whom the Software is | ||
11 | * furnished to do so, subject to the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be included in | ||
14 | * all copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
22 | * THE SOFTWARE. | ||
23 | */ | ||
24 | #pragma once | ||
25 | |||
26 | #include "arm_atsam/printf.h" | ||
27 | |||
28 | // Create user & normal print defines | ||
29 | #define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | ||
30 | #define print(s) __xprintf(s) | ||
31 | #define println(s) __xprintf(s "\r\n") | ||
32 | #define uprint(s) __xprintf(s) | ||
33 | #define uprintln(s) __xprintf(s "\r\n") | ||
34 | #define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | ||
diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c deleted file mode 100644 index 2cb59706a..000000000 --- a/tmk_core/common/arm_atsam/printf.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2018 Massdrop Inc. | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "printf.h" | ||
19 | #include "sendchar.h" | ||
20 | |||
21 | #ifdef CONSOLE_ENABLE | ||
22 | |||
23 | # include "samd51j18a.h" | ||
24 | # include "arm_atsam_protocol.h" | ||
25 | # include <string.h> | ||
26 | # include <stdarg.h> | ||
27 | |||
28 | void console_printf(char *fmt, ...) { | ||
29 | while (udi_hid_con_b_report_trans_ongoing) { | ||
30 | } // Wait for any previous transfers to complete | ||
31 | |||
32 | static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; // Print and send buffer | ||
33 | va_list va; | ||
34 | int result; | ||
35 | |||
36 | va_start(va, fmt); | ||
37 | result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va); | ||
38 | va_end(va); | ||
39 | |||
40 | uint32_t irqflags; | ||
41 | char * pconbuf = console_printbuf; // Pointer to start send from | ||
42 | int send_out = CONSOLE_EPSIZE; // Bytes to send per transfer | ||
43 | |||
44 | while (result > 0) { // While not error and bytes remain | ||
45 | while (udi_hid_con_b_report_trans_ongoing) { | ||
46 | } // Wait for any previous transfers to complete | ||
47 | |||
48 | irqflags = __get_PRIMASK(); | ||
49 | __disable_irq(); | ||
50 | __DMB(); | ||
51 | |||
52 | if (result < CONSOLE_EPSIZE) { // If remaining bytes are less than console epsize | ||
53 | memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); // Clear the buffer | ||
54 | send_out = result; // Send remaining size | ||
55 | } | ||
56 | |||
57 | memcpy(udi_hid_con_report, pconbuf, send_out); // Copy data into the send buffer | ||
58 | |||
59 | udi_hid_con_b_report_valid = 1; // Set report valid | ||
60 | udi_hid_con_send_report(); // Send report | ||
61 | |||
62 | __DMB(); | ||
63 | __set_PRIMASK(irqflags); | ||
64 | |||
65 | result -= send_out; // Decrement result by bytes sent | ||
66 | pconbuf += send_out; // Increment buffer point by bytes sent | ||
67 | } | ||
68 | } | ||
69 | |||
70 | #endif // CONSOLE_ENABLE | ||
71 | |||
72 | void print_set_sendchar(sendchar_func_t send) {} \ No newline at end of file | ||
diff --git a/tmk_core/common/arm_atsam/printf.h b/tmk_core/common/arm_atsam/printf.h deleted file mode 100644 index 95557f5b0..000000000 --- a/tmk_core/common/arm_atsam/printf.h +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #define CONSOLE_PRINTBUF_SIZE 512 | ||
4 | |||
5 | void console_printf(char *fmt, ...); | ||
6 | |||
7 | #define __xprintf console_printf | ||
diff --git a/tmk_core/common/arm_atsam/printf.mk b/tmk_core/common/arm_atsam/printf.mk deleted file mode 100644 index f70e02731..000000000 --- a/tmk_core/common/arm_atsam/printf.mk +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c | ||
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index ce0f54593..abea12134 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c | |||
@@ -140,6 +140,57 @@ void send_consumer(uint16_t data) { | |||
140 | #endif // EXTRAKEY_ENABLE | 140 | #endif // EXTRAKEY_ENABLE |
141 | } | 141 | } |
142 | 142 | ||
143 | #ifdef CONSOLE_ENABLE | ||
144 | # define CONSOLE_PRINTBUF_SIZE 512 | ||
145 | static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; | ||
146 | static uint16_t console_printbuf_len = 0; | ||
147 | |||
148 | int8_t sendchar(uint8_t c) { | ||
149 | if (console_printbuf_len >= CONSOLE_PRINTBUF_SIZE) return -1; | ||
150 | |||
151 | console_printbuf[console_printbuf_len++] = c; | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | void main_subtask_console_flush(void) { | ||
156 | while (udi_hid_con_b_report_trans_ongoing) { | ||
157 | } // Wait for any previous transfers to complete | ||
158 | |||
159 | uint16_t result = console_printbuf_len; | ||
160 | uint32_t irqflags; | ||
161 | char * pconbuf = console_printbuf; // Pointer to start send from | ||
162 | int send_out = CONSOLE_EPSIZE; // Bytes to send per transfer | ||
163 | |||
164 | while (result > 0) { // While not error and bytes remain | ||
165 | while (udi_hid_con_b_report_trans_ongoing) { | ||
166 | } // Wait for any previous transfers to complete | ||
167 | |||
168 | irqflags = __get_PRIMASK(); | ||
169 | __disable_irq(); | ||
170 | __DMB(); | ||
171 | |||
172 | if (result < CONSOLE_EPSIZE) { // If remaining bytes are less than console epsize | ||
173 | memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); // Clear the buffer | ||
174 | send_out = result; // Send remaining size | ||
175 | } | ||
176 | |||
177 | memcpy(udi_hid_con_report, pconbuf, send_out); // Copy data into the send buffer | ||
178 | |||
179 | udi_hid_con_b_report_valid = 1; // Set report valid | ||
180 | udi_hid_con_send_report(); // Send report | ||
181 | |||
182 | __DMB(); | ||
183 | __set_PRIMASK(irqflags); | ||
184 | |||
185 | result -= send_out; // Decrement result by bytes sent | ||
186 | pconbuf += send_out; // Increment buffer point by bytes sent | ||
187 | } | ||
188 | |||
189 | console_printbuf_len = 0; | ||
190 | } | ||
191 | |||
192 | #endif // CONSOLE_ENABLE | ||
193 | |||
143 | void main_subtask_usb_state(void) { | 194 | void main_subtask_usb_state(void) { |
144 | static uint64_t fsmstate_on_delay = 0; // Delay timer to be sure USB is actually operating before bringing up hardware | 195 | static uint64_t fsmstate_on_delay = 0; // Delay timer to be sure USB is actually operating before bringing up hardware |
145 | uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; // Current state from hardware register | 196 | uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; // Current state from hardware register |
@@ -214,6 +265,9 @@ void main_subtasks(void) { | |||
214 | main_subtask_usb_state(); | 265 | main_subtask_usb_state(); |
215 | main_subtask_power_check(); | 266 | main_subtask_power_check(); |
216 | main_subtask_usb_extra_device(); | 267 | main_subtask_usb_extra_device(); |
268 | #ifdef CONSOLE_ENABLE | ||
269 | main_subtask_console_flush(); | ||
270 | #endif | ||
217 | #ifdef RAW_ENABLE | 271 | #ifdef RAW_ENABLE |
218 | main_subtask_raw(); | 272 | main_subtask_raw(); |
219 | #endif | 273 | #endif |