aboutsummaryrefslogtreecommitdiffstats
path: root/fw/usb.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-10-02 14:45:56 -0400
committerSam Anthony <sam@samanthony.xyz>2025-10-02 14:45:56 -0400
commit99be520563834d51eb3ddd32b757a3dcd2486632 (patch)
tree7c31bcc262950d431a1676b62624b6ac82f30df3 /fw/usb.c
parentc91e3d96c90cd1c9b3b6155bc5e37954011cf0af (diff)
downloadcan-gauge-interface-99be520563834d51eb3ddd32b757a3dcd2486632.zip
spi systest
Diffstat (limited to 'fw/usb.c')
-rw-r--r--fw/usb.c56
1 files changed, 35 insertions, 21 deletions
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) {