summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/usb_serial.h2
-rw-r--r--firmware/usb_serial.c23
2 files changed, 25 insertions, 0 deletions
diff --git a/firmware/export/usb_serial.h b/firmware/export/usb_serial.h
index 5daefeeff2..32bb8525b4 100644
--- a/firmware/export/usb_serial.h
+++ b/firmware/export/usb_serial.h
@@ -22,5 +22,7 @@
void usb_serial_init(void);
void usb_serial_put_byte(int b);
int usb_serial_get_byte(void);
+int usb_serial_try_put_byte(int b);
+int usb_serial_try_get_byte(void);
#endif
diff --git a/firmware/usb_serial.c b/firmware/usb_serial.c
index acf19e3b1a..0c4fb9d896 100644
--- a/firmware/usb_serial.c
+++ b/firmware/usb_serial.c
@@ -1081,6 +1081,17 @@ int usb_serial_get_byte(void)
return fifo_get_byte(&serial_in_fifo);
}
+int usb_serial_try_get_byte(void)
+{
+ int r;
+ if (fifo_empty(&serial_in_fifo))
+ r = -1;
+ else
+ r = fifo_get_byte(&serial_in_fifo);
+ usb_serial_handle();
+ return r;
+}
+
/*
Not used:
static int usb_serial_out_full(void)
@@ -1097,6 +1108,18 @@ void usb_serial_put_byte(int b)
usb_serial_handle();
}
+int usb_serial_try_put_byte(int b)
+{
+ int r = -1;
+ if (!fifo_full(&serial_out_fifo))
+ {
+ fifo_put_byte(&serial_out_fifo, b);
+ r = 0;
+ }
+ usb_serial_handle();
+ return r;
+}
+
void usb_serial_init(void)
{
fifo_init(&serial_in_fifo);