aboutsummaryrefslogtreecommitdiffstats
path: root/src/generic/usb_cdc.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-05-24 12:49:23 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-05-28 10:43:39 -0400
commitcb4e165071ad56c4cf881f5221f02eeefde5de53 (patch)
tree0d88bd5e3ebaf53526cda428eebf3d7ad61876bf /src/generic/usb_cdc.c
parent2a55741ea883e6a9958a64c3463b4c3d60c21b63 (diff)
downloadkutter-cb4e165071ad56c4cf881f5221f02eeefde5de53.tar.gz
kutter-cb4e165071ad56c4cf881f5221f02eeefde5de53.tar.xz
kutter-cb4e165071ad56c4cf881f5221f02eeefde5de53.zip
command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengths
Prefer using 'uint8_t' buffers as it is too easy to run into C sign extension problems with 'char' buffers. Prefer using 'uint_fast8_t' for buffer lengths as gcc does a better job compiling them on 32bit mcus. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/generic/usb_cdc.c')
-rw-r--r--src/generic/usb_cdc.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c
index fea567ec..49bb483e 100644
--- a/src/generic/usb_cdc.c
+++ b/src/generic/usb_cdc.c
@@ -23,8 +23,7 @@
****************************************************************/
static struct task_wake usb_bulk_in_wake;
-static char transmit_buf[96];
-static uint8_t transmit_pos;
+static uint8_t transmit_buf[96], transmit_pos;
void
usb_notify_bulk_in(void)
@@ -65,8 +64,8 @@ console_sendf(const struct command_encoder *ce, va_list args)
return;
// Generate message
- char *buf = &transmit_buf[tpos];
- uint8_t msglen = command_encodef(buf, ce, args);
+ uint8_t *buf = &transmit_buf[tpos];
+ uint_fast8_t msglen = command_encodef(buf, ce, args);
command_add_frame(buf, msglen);
// Start message transmit
@@ -80,8 +79,7 @@ console_sendf(const struct command_encoder *ce, va_list args)
****************************************************************/
static struct task_wake usb_bulk_out_wake;
-static char receive_buf[128];
-static uint8_t receive_pos;
+static uint8_t receive_buf[128], receive_pos;
void
usb_notify_bulk_out(void)
@@ -95,8 +93,7 @@ usb_bulk_out_task(void)
if (!sched_check_wake(&usb_bulk_out_wake))
return;
// Process any existing message blocks
- uint_fast8_t rpos = receive_pos;
- uint8_t pop_count;
+ uint_fast8_t rpos = receive_pos, pop_count;
int_fast8_t ret = command_find_block(receive_buf, rpos, &pop_count);
if (ret > 0)
command_dispatch(receive_buf, pop_count);