Coming along, I suppose
This commit is contained in:
parent
915d3c3510
commit
fbdeb0eac4
2 changed files with 86 additions and 2 deletions
82
avr/main.c
82
avr/main.c
|
@ -1,12 +1,67 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
#include <tabby/clock.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
6
include/tabby/avr.h
Normal file
6
include/tabby/avr.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef _TABBY_AVR_H
|
||||
#define _TABBY_AVR_H
|
||||
|
||||
#define TABBY_AVR_SERIAL_BAUD 115200
|
||||
|
||||
#endif /* _TABBY_AVR_H */
|
Loading…
Add table
Reference in a new issue