aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-06-05 12:30:49 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-06-05 12:30:49 -0400
commitb8094de129de17280f58d1042e6dcdd48f9eaef3 (patch)
tree41ce9a9a9afec3e05c9367c10a996c000ff67e1d /src
parent73207a12bab0c52f56a804d2aa304772a7bd6a38 (diff)
downloadkutter-b8094de129de17280f58d1042e6dcdd48f9eaef3.tar.gz
kutter-b8094de129de17280f58d1042e6dcdd48f9eaef3.tar.xz
kutter-b8094de129de17280f58d1042e6dcdd48f9eaef3.zip
avr: Support using serial instead of usb on AT90USB1286
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/avr/Kconfig2
-rw-r--r--src/avr/serial.c42
2 files changed, 28 insertions, 16 deletions
diff --git a/src/avr/Kconfig b/src/avr/Kconfig
index 0f2233d0..3050963e 100644
--- a/src/avr/Kconfig
+++ b/src/avr/Kconfig
@@ -81,7 +81,7 @@ config AVR_WATCHDOG
depends on !SIMULAVR
default y
config AVR_USBSERIAL
- bool
+ bool "Use USB for communication (instead of serial)"
depends on MACH_at90usb1286
default y
config AVR_SERIAL
diff --git a/src/avr/serial.c b/src/avr/serial.c
index 3aff121f..3221b6f0 100644
--- a/src/avr/serial.c
+++ b/src/avr/serial.c
@@ -25,29 +25,41 @@ static uint8_t transmit_pos, transmit_max;
DECL_CONSTANT(SERIAL_BAUD, CONFIG_SERIAL_BAUD);
+// Define serial port registers on AT90USB1286
+#if !defined(UCSR0A) && defined(UCSR1A)
+#define UCSR0A UCSR1A
+#define UCSR0B UCSR1B
+#define UCSR0C UCSR1C
+#define UBRR0 UBRR1
+#define UDR0 UDR1
+#define UCSZ01 UCSZ11
+#define UCSZ00 UCSZ10
+#define U2X0 U2X1
+#define RXEN0 RXEN1
+#define TXEN0 TXEN1
+#define RXCIE0 RXCIE1
+#define UDRIE0 UDRIE1
+#define USART0_RX_vect USART1_RX_vect
+#define USART0_UDRE_vect USART1_UDRE_vect
+#endif
+
+// Define serial port registers on atmega168 / atmega328
+#if defined(USART_RX_vect)
+#define USART0_RX_vect USART_RX_vect
+#define USART0_UDRE_vect USART_UDRE_vect
+#endif
+
void
serial_init(void)
{
- if (CONFIG_SERIAL_BAUD_U2X) {
- UCSR0A = 1<<U2X0;
- UBRR0 = DIV_ROUND_CLOSEST(
- CONFIG_CLOCK_FREQ, 8UL * CONFIG_SERIAL_BAUD) - 1UL;
- } else {
- UCSR0A = 0;
- UBRR0 = DIV_ROUND_CLOSEST(
- CONFIG_CLOCK_FREQ, 16UL * CONFIG_SERIAL_BAUD) - 1UL;
- }
-
+ UCSR0A = CONFIG_SERIAL_BAUD_U2X ? (1<<U2X0) : 0;
+ uint32_t cm = CONFIG_SERIAL_BAUD_U2X ? 8 : 16;
+ UBRR0 = DIV_ROUND_CLOSEST(CONFIG_CLOCK_FREQ, cm * CONFIG_SERIAL_BAUD) - 1UL;
UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);
UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0) | (1<<UDRIE0);
}
DECL_INIT(serial_init);
-#ifdef USART_RX_vect
-#define USART0_RX_vect USART_RX_vect
-#define USART0_UDRE_vect USART_UDRE_vect
-#endif
-
// Rx interrupt - data available to be read.
ISR(USART0_RX_vect)
{