aboutsummaryrefslogtreecommitdiffstats
path: root/fw/usb.c
diff options
context:
space:
mode:
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) {