#include #include #include #include #include #include #include static volatile tabby_printer_packet header; static volatile uint16_t i, b; /* * SPI byte receipt interrupt vector */ ISR(SPI_STC_vect) { uint8_t in = SPDR, out = 0; uart_putchar(in, NULL); switch (i) { case 0: { if (in == TABBY_PRINTER_SYNC_1) { header.preamble[0] = in; i++; b = 0; } break; } case 1: { if (in == TABBY_PRINTER_SYNC_2) { header.preamble[1] = in; i++; } else { i = 0; } break; } case 2: { header.type = in; i++; break; } case 3: { header.compression = in; i++; break; } case 4: { header.size = in; i++; break; } case 5: { header.size |= in << 8; i++; if (header.size > TABBY_PRINTER_PACKET_MAX_SIZE) { i = 0; } break; } default: { if (b <= header.size) { b++; } else if (b == header.size + 1) { b++; out = TABBY_PRINTER_DEVICE_ID; } else if (b == header.size + 2) { b++; out = TABBY_PRINTER_OK; } else if (b == header.size + 3) { i = 0; } } } SPDR = out; } int main() { uart_init(); tabby_avr_link_init_slave(); sei(); while (1) { sleep_mode(); } return 0; }