From fbdeb0eac46dc374ed7f1eab9ae372ef4a87054d Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 25 May 2016 23:28:06 -0500 Subject: [PATCH] Coming along, I suppose --- avr/main.c | 82 +++++++++++++++++++++++++++++++++++++++++++-- include/tabby/avr.h | 6 ++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 include/tabby/avr.h diff --git a/avr/main.c b/avr/main.c index 66c95ba..26d386d 100644 --- a/avr/main.c +++ b/avr/main.c @@ -1,12 +1,67 @@ +#include + #include +#include #include +static volatile uint8_t bits = 0; +static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */ +static volatile uint8_t value_out = 0x00; /* Data going out from host */ + uint16_t timer_counter_intervals[4] = { 1953, 977, 61, 31 }; -void setup_internal_clock(tabby_clock_speed speed) { +/* + * Internal clock source interrupt vector + */ +ISR(TIM0_COMPB_vect) { + /* + * Strobe the SCK pin + */ + PORTB |= (1 << PORTB1); + PORTB &= ~(1 << PORTB1); + + value_in >>= 1; + + if (PORTB & (1 << PORTB2)) { + value_in |= 0x80; + } + + if (value_out & 0x80) { + PORTB |= (1 << PORTB3); + } else { + PORTB &= ~(1 << PORTB3); + } + + value_out <<= 1; + + if (--bits == 0) { + putchar(value_in); + + value_out = getchar(); + + bits = 8; + } +} + +static void clock_internal_setup(tabby_clock_speed speed) { + /* + * Configure MISO as output + */ + DDB3 |= (1 << PORTB3); + + /* + * Configure MOSI as input + */ + DDB2 &= ~(1 << PORTB2); + + /* + * Configure SCK pin as output + */ + DDB1 |= (1 << PORTB1); + /* * Enable timer interrupt vector */ @@ -28,7 +83,7 @@ void setup_internal_clock(tabby_clock_speed speed) { TCCR1B = (1 << CS10); } -void setup_external_clock() { +static void clock_external_setup() { /* * Disable internal timer interrupts */ @@ -37,6 +92,29 @@ void setup_external_clock() { TIMSK = 0; } +static void snooze() { + set_sleep_mode(mode); + sleep_enable(); + sleep_mode(); + sleep_disable(); +} + int main() { + /* + * By default, the Game Boy link port is configured to monitor for external + * clock pulses, so we'll go ahead and do that in this case. + */ + clock_external_setup(); + + /* + * We do actually want to globally enable interrupts here, so here's that + * one assembly instruction to do so. + */ + sei(); + + while (1) { + snooze(); + } + return 0; } diff --git a/include/tabby/avr.h b/include/tabby/avr.h new file mode 100644 index 0000000..a13b370 --- /dev/null +++ b/include/tabby/avr.h @@ -0,0 +1,6 @@ +#ifndef _TABBY_AVR_H +#define _TABBY_AVR_H + +#define TABBY_AVR_SERIAL_BAUD 115200 + +#endif /* _TABBY_AVR_H */