diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-06-04 19:34:39 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-06-05 10:52:45 -0400 |
commit | 3eafc8345885ff7d58c0124e518b240cbbaa8ecc (patch) | |
tree | 8a97d30951000819dd7f3074721ab25b3731b68f /src/avr/usbserial.c | |
parent | 4326a3adced3788c774bf248d64776d730bafe0f (diff) | |
download | kutter-3eafc8345885ff7d58c0124e518b240cbbaa8ecc.tar.gz kutter-3eafc8345885ff7d58c0124e518b240cbbaa8ecc.tar.xz kutter-3eafc8345885ff7d58c0124e518b240cbbaa8ecc.zip |
avr: Initial support for Atmel AT90USB1286 mcu
Add GPIO definitions for the AT90USB1286. Add code for communicating
over USB port on AT90USB1286.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/avr/usbserial.c')
-rw-r--r-- | src/avr/usbserial.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c new file mode 100644 index 00000000..4cf1bd0f --- /dev/null +++ b/src/avr/usbserial.c @@ -0,0 +1,65 @@ +// Wrappers for AVR usb serial. +// +// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net> +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include <avr/interrupt.h> // USART0_RX_vect +#include <string.h> // memmove +#include "../lib/pjrc_usb_serial/usb_serial.h" +#include "sched.h" // DECL_INIT + +#define USBSERIAL_BUFFER_SIZE 64 +static char receive_buf[USBSERIAL_BUFFER_SIZE]; +static uint8_t receive_pos; +static char transmit_buf[USBSERIAL_BUFFER_SIZE]; + +static void +usbserial_init(void) +{ + usb_init(); +} +DECL_INIT(usbserial_init); + +// Return a buffer (and length) containing any incoming messages +char * +console_get_input(uint8_t *plen) +{ + for (;;) { + if (receive_pos >= sizeof(receive_buf)) + break; + int16_t ret = usb_serial_getchar(); + if (ret == -1) + break; + receive_buf[receive_pos++] = ret; + } + *plen = receive_pos; + return receive_buf; +} + +// Remove from the receive buffer the given number of bytes +void +console_pop_input(uint8_t len) +{ + uint8_t needcopy = receive_pos - len; + if (needcopy) + memmove(receive_buf, &receive_buf[len], needcopy); + receive_pos = needcopy; +} + +// Return an output buffer that the caller may fill with transmit messages +char * +console_get_output(uint8_t len) +{ + if (len > sizeof(transmit_buf)) + return NULL; + return transmit_buf; +} + +// Accept the given number of bytes added to the transmit buffer +void +console_push_output(uint8_t len) +{ + usb_serial_write((void*)transmit_buf, len); + usb_serial_flush_output(); +} |