Don't forget to send device ID and status byte from Game Boy Printer to host

This commit is contained in:
XANTRONIX Development 2016-06-01 23:49:27 -05:00
parent 75b588a288
commit 4640fa8216

View file

@ -9,6 +9,12 @@
#define TIMER0_INTERVAL 1953
#define PACKET_BODY_SIZE 640
enum {
TABBY_SEND_READING = 0,
TABBY_SEND_BUFFERED = (1 << 0),
TABBY_SEND_COMPLETE = (1 << 1)
};
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 to Game Boy */
@ -25,7 +31,7 @@ static volatile uint16_t sum = 0x0000;
static volatile uint8_t device = 0x00,
status = 0x00,
buffered = 0;
flags = TABBY_SEND_READING;
static volatile uint16_t i = 0,
b = 0;
@ -34,7 +40,7 @@ static volatile uint16_t i = 0,
* Internal clock source interrupt vector
*/
ISR(TIMER0_COMPB_vect) {
if (!buffered) {
if (!(flags & TABBY_SEND_BUFFERED)) {
reti();
}
@ -75,7 +81,8 @@ ISR(TIMER0_COMPB_vect) {
i = 0;
b = 0;
buffered = 0;
flags &= ~TABBY_SEND_BUFFERED;
flags |= TABBY_SEND_COMPLETE;
}
bits = 8;
@ -154,10 +161,17 @@ int main() {
while (1) {
uint8_t c;
while (buffered) {
while (flags != TABBY_SEND_READING) {
sleep_mode();
}
if (flags & TABBY_SEND_COMPLETE) {
uart_putchar(device, NULL);
uart_putchar(status, NULL);
flags = TABBY_SEND_READING;
}
c = uart_getchar(NULL);
switch (i) {
@ -222,7 +236,7 @@ int main() {
if (sum == checksum()) {
i = 0;
b = 0;
buffered = 1;
flags |= TABBY_SEND_BUFFERED;
}
}
}