Skip to content

Commit

Permalink
Migrate arm_atsam print logic to use common framework (#13554)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored Jul 16, 2021
1 parent 5fda0e2 commit 366be0f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 114 deletions.
34 changes: 0 additions & 34 deletions tmk_core/common/arm_atsam/_print.h

This file was deleted.

72 changes: 0 additions & 72 deletions tmk_core/common/arm_atsam/printf.c

This file was deleted.

7 changes: 0 additions & 7 deletions tmk_core/common/arm_atsam/printf.h

This file was deleted.

1 change: 0 additions & 1 deletion tmk_core/common/arm_atsam/printf.mk

This file was deleted.

54 changes: 54 additions & 0 deletions tmk_core/protocol/arm_atsam/main_arm_atsam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 366be0f

Please sign in to comment.