Migrate arm_atsam print logic to use common framework (#13554)

master
Joel Challis 2021-07-16 17:08:34 +01:00 committed by GitHub
parent 5fda0e2c04
commit 366be0f7e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 114 deletions

View File

@ -1,34 +0,0 @@
/* Copyright 2012 Jun Wako <wakojun@gmail.com> */
/* Very basic print functions, intended to be used with usb_debug_only.c
* http://www.pjrc.com/teensy/
* Copyright (c) 2008 PJRC.COM, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "arm_atsam/printf.h"
// Create user & normal print defines
#define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
#define print(s) __xprintf(s)
#define println(s) __xprintf(s "\r\n")
#define uprint(s) __xprintf(s)
#define uprintln(s) __xprintf(s "\r\n")
#define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)

View File

@ -1,72 +0,0 @@
/*
Copyright 2018 Massdrop Inc.
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 <http://www.gnu.org/licenses/>.
*/
#include "printf.h"
#include "sendchar.h"
#ifdef CONSOLE_ENABLE
# include "samd51j18a.h"
# include "arm_atsam_protocol.h"
# include <string.h>
# include <stdarg.h>
void console_printf(char *fmt, ...) {
while (udi_hid_con_b_report_trans_ongoing) {
} // Wait for any previous transfers to complete
static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; // Print and send buffer
va_list va;
int result;
va_start(va, fmt);
result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va);
va_end(va);
uint32_t irqflags;
char * pconbuf = console_printbuf; // Pointer to start send from
int send_out = CONSOLE_EPSIZE; // Bytes to send per transfer
while (result > 0) { // While not error and bytes remain
while (udi_hid_con_b_report_trans_ongoing) {
} // Wait for any previous transfers to complete
irqflags = __get_PRIMASK();
__disable_irq();
__DMB();
if (result < CONSOLE_EPSIZE) { // If remaining bytes are less than console epsize
memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); // Clear the buffer
send_out = result; // Send remaining size
}
memcpy(udi_hid_con_report, pconbuf, send_out); // Copy data into the send buffer
udi_hid_con_b_report_valid = 1; // Set report valid
udi_hid_con_send_report(); // Send report
__DMB();
__set_PRIMASK(irqflags);
result -= send_out; // Decrement result by bytes sent
pconbuf += send_out; // Increment buffer point by bytes sent
}
}
#endif // CONSOLE_ENABLE
void print_set_sendchar(sendchar_func_t send) {}

View File

@ -1,7 +0,0 @@
#pragma once
#define CONSOLE_PRINTBUF_SIZE 512
void console_printf(char *fmt, ...);
#define __xprintf console_printf

View File

@ -1 +0,0 @@
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c

View File

@ -140,6 +140,57 @@ void send_consumer(uint16_t data) {
#endif // EXTRAKEY_ENABLE
}
#ifdef CONSOLE_ENABLE
# define CONSOLE_PRINTBUF_SIZE 512
static char console_printbuf[CONSOLE_PRINTBUF_SIZE];
static uint16_t console_printbuf_len = 0;
int8_t sendchar(uint8_t c) {
if (console_printbuf_len >= CONSOLE_PRINTBUF_SIZE) return -1;
console_printbuf[console_printbuf_len++] = c;
return 0;
}
void main_subtask_console_flush(void) {
while (udi_hid_con_b_report_trans_ongoing) {
} // Wait for any previous transfers to complete
uint16_t result = console_printbuf_len;
uint32_t irqflags;
char * pconbuf = console_printbuf; // Pointer to start send from
int send_out = CONSOLE_EPSIZE; // Bytes to send per transfer
while (result > 0) { // While not error and bytes remain
while (udi_hid_con_b_report_trans_ongoing) {
} // Wait for any previous transfers to complete
irqflags = __get_PRIMASK();
__disable_irq();
__DMB();
if (result < CONSOLE_EPSIZE) { // If remaining bytes are less than console epsize
memset(udi_hid_con_report, 0, CONSOLE_EPSIZE); // Clear the buffer
send_out = result; // Send remaining size
}
memcpy(udi_hid_con_report, pconbuf, send_out); // Copy data into the send buffer
udi_hid_con_b_report_valid = 1; // Set report valid
udi_hid_con_send_report(); // Send report
__DMB();
__set_PRIMASK(irqflags);
result -= send_out; // Decrement result by bytes sent
pconbuf += send_out; // Increment buffer point by bytes sent
}
console_printbuf_len = 0;
}
#endif // CONSOLE_ENABLE
void main_subtask_usb_state(void) {
static uint64_t fsmstate_on_delay = 0; // Delay timer to be sure USB is actually operating before bringing up hardware
uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; // Current state from hardware register
@ -214,6 +265,9 @@ void main_subtasks(void) {
main_subtask_usb_state();
main_subtask_power_check();
main_subtask_usb_extra_device();
#ifdef CONSOLE_ENABLE
main_subtask_console_flush();
#endif
#ifdef RAW_ENABLE
main_subtask_raw();
#endif