Ensure clock pulses occur at ~8192Hz
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
This commit is contained in:
parent
49463eb8f8
commit
fa4b6ae020
2 changed files with 9 additions and 28 deletions
|
@ -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
|
||||
|
|
35
avr/send.c
35
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<header.size; i++) {
|
||||
sum += body[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
_delay_us(244);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@ -224,12 +207,10 @@ int main() {
|
|||
i = 0;
|
||||
b = 0;
|
||||
|
||||
if (sum == checksum()) {
|
||||
spi_send_packet();
|
||||
spi_send_packet();
|
||||
|
||||
uart_putchar(response.device, NULL);
|
||||
uart_putchar(response.status, NULL);
|
||||
}
|
||||
uart_putchar(response.device, NULL);
|
||||
uart_putchar(response.status, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue