diff options
| author | Joel Challis <git@zvecr.com> | 2021-07-16 17:08:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-16 17:08:34 +0100 |
| commit | 366be0f7e9b4f408b7494fcb68142ac70d909170 (patch) | |
| tree | 337dea5bb829226227eafbede608375cfc4a611a /tmk_core/protocol | |
| parent | 5fda0e2c0456114b7200f3037c12837d6955332d (diff) | |
| download | qmk_firmware-366be0f7e9b4f408b7494fcb68142ac70d909170.tar.gz qmk_firmware-366be0f7e9b4f408b7494fcb68142ac70d909170.zip | |
Migrate arm_atsam print logic to use common framework (#13554)
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/arm_atsam/main_arm_atsam.c | 54 |
1 files changed, 54 insertions, 0 deletions
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 |
