2 Copyright 2018 Massdrop Inc.
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.
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.
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/>.
20 #include "samd51j18a.h"
21 #include "arm_atsam_protocol.h"
26 void console_printf(char *fmt, ...) {
27 while (udi_hid_con_b_report_trans_ongoing) {} //Wait for any previous transfers to complete
29 static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; //Print and send buffer
34 result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va);
38 char *pconbuf = console_printbuf; //Pointer to start send from
39 int send_out = CONSOLE_EPSIZE; //Bytes to send per transfer
41 while (result > 0) { //While not error and bytes remain
42 while (udi_hid_con_b_report_trans_ongoing) {} //Wait for any previous transfers to complete
44 irqflags = __get_PRIMASK();
48 if (result < CONSOLE_EPSIZE) { //If remaining bytes are less than console epsize
49 memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); //Clear the buffer
50 send_out = result; //Send remaining size
53 memcpy(udi_hid_con_report, pconbuf, send_out); //Copy data into the send buffer
55 udi_hid_con_b_report_valid = 1; //Set report valid
56 udi_hid_con_send_report(); //Send report
59 __set_PRIMASK(irqflags);
61 result -= send_out; //Decrement result by bytes sent
62 pconbuf += send_out; //Increment buffer point by bytes sent
66 #endif //CONSOLE_ENABLE