From 3eafc8345885ff7d58c0124e518b240cbbaa8ecc Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 4 Jun 2016 19:34:39 -0400 Subject: 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 --- src/avr/Kconfig | 8 +++++++ src/avr/Makefile | 1 + src/avr/gpio.c | 21 +++++++++++++++-- src/avr/usbserial.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/avr/usbserial.c (limited to 'src') diff --git a/src/avr/Kconfig b/src/avr/Kconfig index e0964676..5056e86a 100644 --- a/src/avr/Kconfig +++ b/src/avr/Kconfig @@ -12,6 +12,8 @@ choice bool "atmega168" config MACH_atmega644p bool "atmega644p" + config MACH_at90usb1286 + bool "at90usb1286" config MACH_atmega1280 bool "atmega1280" config MACH_atmega2560 @@ -22,6 +24,7 @@ config MCU string default "atmega168" if MACH_atmega168 default "atmega644p" if MACH_atmega644p + default "at90usb1286" if MACH_at90usb1286 default "atmega1280" if MACH_atmega1280 default "atmega2560" if MACH_atmega2560 @@ -49,7 +52,12 @@ config AVR_STACK_SIZE config AVR_WATCHDOG bool "Support for automated reset on watchdog timeout" default y +config AVR_USBSERIAL + bool + depends on MACH_at90usb1286 + default y config AVR_SERIAL + depends on !AVR_USBSERIAL bool default y config SERIAL_BAUD diff --git a/src/avr/Makefile b/src/avr/Makefile index 758443da..c5e5dba1 100644 --- a/src/avr/Makefile +++ b/src/avr/Makefile @@ -9,6 +9,7 @@ LDFLAGS-y += -Wl,--relax # Add avr source files src-y += avr/main.c avr/timer.c avr/gpio.c avr/alloc.c src-$(CONFIG_AVR_WATCHDOG) += avr/watchdog.c +src-$(CONFIG_AVR_USBSERIAL) += avr/usbserial.c ../lib/pjrc_usb_serial/usb_serial.c src-$(CONFIG_AVR_SERIAL) += avr/serial.c # Build the additional hex output file diff --git a/src/avr/gpio.c b/src/avr/gpio.c index d2cdfbd8..20598dc4 100644 --- a/src/avr/gpio.c +++ b/src/avr/gpio.c @@ -29,7 +29,10 @@ static volatile uint8_t * const digital_regs[] PROGMEM = { #endif &PINB, &PINC, &PIND, #ifdef PINE - &PINE, &PINF, &PING, &PINH, NULL, &PINJ, &PINK, &PINL + &PINE, &PINF, +#endif +#ifdef PING + &PING, &PINH, NULL, &PINJ, &PINK, &PINL #endif }; @@ -64,6 +67,17 @@ static const struct gpio_pwm_info pwm_regs[] PROGMEM = { // { &OCR1B, &TCCR1A, &TCCR1B, 1< +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include // USART0_RX_vect +#include // 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(); +} -- cgit v1.2.3-70-g09d2