From fa4b6ae0202bd7777d983553ce77fe65ce94ae6c Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sat, 4 Jun 2016 23:58:07 -0500 Subject: [PATCH] Ensure clock pulses occur at ~8192Hz MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Other changes: * Rip out checksum routine; it's a lot better to rely on the Game Boy Printer returning the device identifier and status bitfield to resend packets when checksum error bit is set * Ensure incoming value is read just ahead of rising edge (but I was already doing that so like yeah) * Ensure 270µs interval after packet transmission --- avr/Makefile | 2 +- avr/send.c | 35 ++++++++--------------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/avr/Makefile b/avr/Makefile index c1277a8..9daccfe 100644 --- a/avr/Makefile +++ b/avr/Makefile @@ -8,7 +8,7 @@ CROSS = avr- CC = $(CROSS)gcc CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega328p -I$(INCLUDE_PATH) \ - -DF_CPU=$(CLOCK_SPEED) + -DF_CPU=$(CLOCK_SPEED) -DUSE_2X LDFLAGS = OBJCOPY = $(CROSS)objcopy diff --git a/avr/send.c b/avr/send.c index be6442f..c0dac07 100644 --- a/avr/send.c +++ b/avr/send.c @@ -68,10 +68,10 @@ static uint8_t spi_send_byte(uint8_t value) { PORTB &= ~(1 << PORTB4); } - value <<= 1; - ret <<= 1; + _delay_us(61); - _delay_us(60); + ret <<= 1; + value <<= 1; if (PINB & (1 << PINB3)) { ret |= 1; @@ -79,11 +79,9 @@ static uint8_t spi_send_byte(uint8_t value) { PORTB |= (1 << PORTB5); - _delay_us(60); + _delay_us(61); } - _delay_us(150); - return ret; } @@ -104,22 +102,7 @@ static void spi_send_packet() { response.device = spi_send_byte(0); response.status = spi_send_byte(0); - _delay_us(270); -} - -static uint16_t checksum() { - uint16_t sum = 0; - size_t i; - - for (i=2; i<6; i++) { - sum += header.data[i]; - } - - for (i=0; i