diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-10-02 14:45:56 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-10-02 14:45:56 -0400 |
| commit | 99be520563834d51eb3ddd32b757a3dcd2486632 (patch) | |
| tree | 7c31bcc262950d431a1676b62624b6ac82f30df3 /fw/usb.c | |
| parent | c91e3d96c90cd1c9b3b6155bc5e37954011cf0af (diff) | |
| download | can-gauge-interface-99be520563834d51eb3ddd32b757a3dcd2486632.zip | |
spi systest
Diffstat (limited to 'fw/usb.c')
| -rw-r--r-- | fw/usb.c | 56 |
1 files changed, 35 insertions, 21 deletions
@@ -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) { |