From 99be520563834d51eb3ddd32b757a3dcd2486632 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 2 Oct 2025 14:45:56 -0400 Subject: spi systest --- fw/usb.c | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'fw/usb.c') diff --git a/fw/usb.c b/fw/usb.c index d793d31..ad78d79 100644 --- a/fw/usb.c +++ b/fw/usb.c @@ -59,6 +59,41 @@ static U8 txBuf[CDC_DATA_IN_EP_SIZE]; /***** Function Definitions *****/ +void +usbInit(void) { + USBDeviceInit(); + USBDeviceAttach(); +} + +void +usbTask(void) { + static State state = {idleState}; + + USBDeviceTasks(); + + if (USBGetDeviceState() < CONFIGURED_STATE) { + return; + } + if (USBIsDeviceSuspended()) { + return; + } + + if (USBUSARTIsTxTrfReady()) { + // Execute action and transition to next state + state = *state.next(); + } + + CDCTxService(); +} + +void +usbPrint(char *s) { + while (!USBUSARTIsTxTrfReady()) { + usbTask(); + } + putsUSBUSART(s); +} + // Rx a char from USB. // Returns FAIL if no data. static Status @@ -95,27 +130,6 @@ getcharBlock(char *c, U8 retries) { return FAIL; } -void -usbTask(void) { - static State state = {idleState}; - - USBDeviceTasks(); - - if (USBGetDeviceState() < CONFIGURED_STATE) { - return; - } - if (USBIsDeviceSuspended()) { - return; - } - - if (USBUSARTIsTxTrfReady()) { - // Execute action and transition to next state - state = *state.next(); - } - - CDCTxService(); -} - // Read (the start of) a command from USB. static State * idleState(void) { -- cgit v1.2.3