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
|
CC = $(CROSS)gcc
|
||||||
CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega328p -I$(INCLUDE_PATH) \
|
CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega328p -I$(INCLUDE_PATH) \
|
||||||
-DF_CPU=$(CLOCK_SPEED)
|
-DF_CPU=$(CLOCK_SPEED) -DUSE_2X
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
OBJCOPY = $(CROSS)objcopy
|
OBJCOPY = $(CROSS)objcopy
|
||||||
|
|
29
avr/send.c
29
avr/send.c
|
@ -68,10 +68,10 @@ static uint8_t spi_send_byte(uint8_t value) {
|
||||||
PORTB &= ~(1 << PORTB4);
|
PORTB &= ~(1 << PORTB4);
|
||||||
}
|
}
|
||||||
|
|
||||||
value <<= 1;
|
_delay_us(61);
|
||||||
ret <<= 1;
|
|
||||||
|
|
||||||
_delay_us(60);
|
ret <<= 1;
|
||||||
|
value <<= 1;
|
||||||
|
|
||||||
if (PINB & (1 << PINB3)) {
|
if (PINB & (1 << PINB3)) {
|
||||||
ret |= 1;
|
ret |= 1;
|
||||||
|
@ -79,11 +79,9 @@ static uint8_t spi_send_byte(uint8_t value) {
|
||||||
|
|
||||||
PORTB |= (1 << PORTB5);
|
PORTB |= (1 << PORTB5);
|
||||||
|
|
||||||
_delay_us(60);
|
_delay_us(61);
|
||||||
}
|
}
|
||||||
|
|
||||||
_delay_us(150);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,22 +102,7 @@ static void spi_send_packet() {
|
||||||
response.device = spi_send_byte(0);
|
response.device = spi_send_byte(0);
|
||||||
response.status = spi_send_byte(0);
|
response.status = spi_send_byte(0);
|
||||||
|
|
||||||
_delay_us(270);
|
_delay_us(244);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -224,7 +207,6 @@ int main() {
|
||||||
i = 0;
|
i = 0;
|
||||||
b = 0;
|
b = 0;
|
||||||
|
|
||||||
if (sum == checksum()) {
|
|
||||||
spi_send_packet();
|
spi_send_packet();
|
||||||
|
|
||||||
uart_putchar(response.device, NULL);
|
uart_putchar(response.device, NULL);
|
||||||
|
@ -233,7 +215,6 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue