This code is violently stupid, but SOON I will be able to handle incoming packet data

This commit is contained in:
XANTRONIX Development 2016-05-25 23:44:21 -05:00
parent fbdeb0eac4
commit e4ab4045f6
4 changed files with 54 additions and 8 deletions

View file

@ -4,6 +4,7 @@
#include <avr/sleep.h>
#include <tabby/clock.h>
#include <tabby/avr/uart.h>
static volatile uint8_t bits = 0;
static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */
@ -38,9 +39,9 @@ ISR(TIM0_COMPB_vect) {
value_out <<= 1;
if (--bits == 0) {
putchar(value_in);
uart_putchar(value_in, NULL);
value_out = getchar();
value_out = uart_getchar(NULL);
bits = 8;
}
@ -100,6 +101,11 @@ static void snooze() {
}
int main() {
/*
* Best turn on the serial UART!
*/
uart_init();
/*
* 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.

34
avr/uart.c Normal file
View file

@ -0,0 +1,34 @@
#include <stdio.h>
#include <tabby/avr/uart.h>
#define F_CPU 16000000UL
#define BAUD TABBY_AVR_UART_BAUD
#include <util/setbaud.h>
void uart_init() {
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= _BV(U2X0);
#else
UCSR0A &= ~(_BV(U2X0));
#endif
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
}
void uart_putchar(char c, FILE *fh) {
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
}
char uart_getchar(FILE *fh) {
loop_until_bit_is_set(UCSR0A, RXC0);
return UDR0;
}

View file

@ -1,6 +0,0 @@
#ifndef _TABBY_AVR_H
#define _TABBY_AVR_H
#define TABBY_AVR_SERIAL_BAUD 115200
#endif /* _TABBY_AVR_H */

12
include/tabby/avr/uart.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef _TABBY_AVR_UART_H
#define _TABBY_AVR_UART_H
#define TABBY_AVR_UART_BAUD 115200
void uart_init();
void uart_putchar(char c, FILE *fh);
char uart_getchar(FILE *fh);
#endif /* _TABBY_AVR_UART_H */