diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-12-15 14:55:27 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-12-15 14:55:27 +0100 |
commit | 972126fd2406030dbd3abd1a705bb0ae1af9abb3 (patch) | |
tree | 74fea3d91fcaabebdd3c354fdc594ddedc09037e /src/arch/arduino-nano/driver | |
parent | bfcfa4cf67bad25ccba5ff735967d4c6abff899c (diff) |
Add AVR (Arduino Nano) support
Diffstat (limited to 'src/arch/arduino-nano/driver')
-rw-r--r-- | src/arch/arduino-nano/driver/gpio.cc | 24 | ||||
-rw-r--r-- | src/arch/arduino-nano/driver/stdout.cc | 32 | ||||
-rw-r--r-- | src/arch/arduino-nano/driver/uptime.cc | 3 |
3 files changed, 59 insertions, 0 deletions
diff --git a/src/arch/arduino-nano/driver/gpio.cc b/src/arch/arduino-nano/driver/gpio.cc new file mode 100644 index 0000000..66e24db --- /dev/null +++ b/src/arch/arduino-nano/driver/gpio.cc @@ -0,0 +1,24 @@ +#include "driver/gpio.h" +#include <avr/io.h> + +void GPIO::setup() +{ + DDRB = _BV(PB5); +} + +void GPIO::led_on(unsigned char id) +{ + PORTB |= _BV(PB5); +} + +void GPIO::led_off(unsigned char id) +{ + PORTB &= ~_BV(PB5); +} + +void GPIO::led_toggle(unsigned char id) +{ + PINB = _BV(PB5); +} + +GPIO gpio; diff --git a/src/arch/arduino-nano/driver/stdout.cc b/src/arch/arduino-nano/driver/stdout.cc new file mode 100644 index 0000000..a3d905d --- /dev/null +++ b/src/arch/arduino-nano/driver/stdout.cc @@ -0,0 +1,32 @@ +#include "driver/stdout.h" +#include <avr/io.h> +#include <avr/interrupt.h> + +#define BAUD 119200L +#include <util/setbaud.h> + +void StandardOutput::setup() +{ + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; + +#if USE_2X + UCSR0A |= _BV(U2X0); +#else + UCSR0A &= ~_BV(U2X0); +#endif + + UCSR0B |= _BV(RXEN0) | _BV(TXEN0); + UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); +} + +void StandardOutput::put(char c) +{ + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = c; + if (c == '\n') { + put('\r'); + } +} + +StandardOutput kout; diff --git a/src/arch/arduino-nano/driver/uptime.cc b/src/arch/arduino-nano/driver/uptime.cc new file mode 100644 index 0000000..388edb6 --- /dev/null +++ b/src/arch/arduino-nano/driver/uptime.cc @@ -0,0 +1,3 @@ +#include "driver/uptime.h" + +Uptime uptime; |