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>
This commit is contained in:
Kevin O'Connor 2016-06-04 19:34:39 -04:00
parent 4326a3adce
commit 3eafc83458
10 changed files with 1239 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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<<COM1B1, GPIO('D', 4), 0 },
{ &OCR2A, &TCCR2A, &TCCR2B, 1<<COM2A1, GPIO('D', 7), GP_8BIT|GP_AFMT },
{ &OCR2B, &TCCR2A, &TCCR2B, 1<<COM2B1, GPIO('D', 6), GP_8BIT|GP_AFMT },
#elif CONFIG_MACH_at90usb1286
{ &OCR0A, &TCCR0A, &TCCR0B, 1<<COM0A1, GPIO('B', 7), GP_8BIT },
{ &OCR0B, &TCCR0A, &TCCR0B, 1<<COM0B1, GPIO('D', 0), GP_8BIT },
// { &OCR1A, &TCCR1A, &TCCR1B, 1<<COM1A1, GPIO('B', 5), 0 },
// { &OCR1B, &TCCR1A, &TCCR1B, 1<<COM1B1, GPIO('B', 6), 0 },
// { &OCR1C, &TCCR1A, &TCCR1B, 1<<COM1C1, GPIO('B', 7), 0 },
{ &OCR2A, &TCCR2A, &TCCR2B, 1<<COM2A1, GPIO('B', 4), GP_8BIT|GP_AFMT },
{ &OCR2B, &TCCR2A, &TCCR2B, 1<<COM2B1, GPIO('D', 1), GP_8BIT|GP_AFMT },
{ &OCR3A, &TCCR3A, &TCCR3B, 1<<COM3A1, GPIO('C', 6), 0 },
{ &OCR3B, &TCCR3A, &TCCR3B, 1<<COM3B1, GPIO('C', 5), 0 },
{ &OCR3C, &TCCR3A, &TCCR3B, 1<<COM3C1, GPIO('C', 4), 0 },
#elif CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
{ &OCR0A, &TCCR0A, &TCCR0B, 1<<COM0A1, GPIO('B', 7), GP_8BIT },
{ &OCR0B, &TCCR0A, &TCCR0B, 1<<COM0B1, GPIO('G', 5), GP_8BIT },
@ -95,6 +109,9 @@ static const struct gpio_adc_info adc_pins[] PROGMEM = {
#elif CONFIG_MACH_atmega644p
{ GPIO('A', 0) }, { GPIO('A', 1) }, { GPIO('A', 2) }, { GPIO('A', 3) },
{ GPIO('A', 4) }, { GPIO('A', 5) }, { GPIO('A', 6) }, { GPIO('A', 7) },
#elif CONFIG_MACH_at90usb1286
{ GPIO('F', 0) }, { GPIO('F', 1) }, { GPIO('F', 2) }, { GPIO('F', 3) },
{ GPIO('F', 4) }, { GPIO('F', 5) }, { GPIO('F', 6) }, { GPIO('F', 7) },
#elif CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
{ GPIO('F', 0) }, { GPIO('F', 1) }, { GPIO('F', 2) }, { GPIO('F', 3) },
{ GPIO('F', 4) }, { GPIO('F', 5) }, { GPIO('F', 6) }, { GPIO('F', 7) },
@ -107,7 +124,7 @@ static const struct gpio_adc_info adc_pins[] PROGMEM = {
static const uint8_t SS = GPIO('B', 2), SCK = GPIO('B', 5), MOSI = GPIO('B', 3);
#elif CONFIG_MACH_atmega644p
static const uint8_t SS = GPIO('B', 4), SCK = GPIO('B', 7), MOSI = GPIO('B', 5);
#elif CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
#elif CONFIG_MACH_at90usb1286 || CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
static const uint8_t SS = GPIO('B', 0), SCK = GPIO('B', 1), MOSI = GPIO('B', 2);
#endif

65
src/avr/usbserial.c Normal file
View file

@ -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();
}