From 985e556556409ca3db5e8041387ea3fc60a85a16 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 5 Jun 2016 22:51:28 -0500 Subject: [PATCH] Most amusingly I am achieving novel results with this ATmega2560 --- avr/Makefile | 4 +- avr/send.c | 111 +++++++++++++++++++++++++++++++++++--------- bin/main.c | 3 ++ include/tabby/avr.h | 16 +++---- 4 files changed, 101 insertions(+), 33 deletions(-) diff --git a/avr/Makefile b/avr/Makefile index fd4725f..6751637 100644 --- a/avr/Makefile +++ b/avr/Makefile @@ -7,7 +7,7 @@ HEADER_SUBDIR = tabby CROSS = avr- CC = $(CROSS)gcc -CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega328p -I$(INCLUDE_PATH) \ +CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega2560 -I$(INCLUDE_PATH) \ -DF_CPU=$(CLOCK_SPEED) -DUSE_2X LDFLAGS = @@ -16,7 +16,7 @@ OBJCOPY_FLAGS = -S AVRDUDE = avrdude AVRDUDE_DEVICE = /dev/cu.usbmodem1411 -AVRDUDE_FLAGS = -c arduino -p atmega328p -b 115200 -D -P $(AVRDUDE_DEVICE) +AVRDUDE_FLAGS = -c wiring -p atmega2560 -b 115200 -D -P $(AVRDUDE_DEVICE) HEADERS_LOCAL = HEADERS_BUILD = $(HEADERS_LOCAL) \ diff --git a/avr/send.c b/avr/send.c index aa65eb3..c91f3c7 100644 --- a/avr/send.c +++ b/avr/send.c @@ -7,15 +7,6 @@ #include #include -static tabby_printer_packet header; -static tabby_printer_response response; - -static uint8_t body[TABBY_PRINTER_PACKET_MAX_SIZE]; - -static uint8_t sheet[TABBY_PRINTER_SHEET_SIZE]; - -static uint16_t sum; - static void spi_init() { SC_OUTPUT(); SO_OUTPUT(); @@ -56,30 +47,95 @@ static uint8_t spi_send_byte(uint8_t value) { return ret; } -static void spi_send_packet() { +static uint16_t checksum(tabby_printer_packet *header, uint8_t *body) { + uint16_t sum = 0; + + int i; + + for (i=2; idata[i]; + } + + for (i=0; isize; i++) { + sum += body[i]; + } + + return sum; +} + +static void spi_send_packet(uint8_t type, uint8_t *body, uint16_t size) { + tabby_printer_packet header = { + .preamble = { TABBY_PRINTER_SYNC_1, TABBY_PRINTER_SYNC_2 }, + .type = type, + .compression = TABBY_PRINTER_COMPRESSION_NONE, + .size = size + }; + + uint16_t sum = checksum(&header, body); + int i; for (i=0; i> 8); - response.device = spi_send_byte(0); - response.status = spi_send_byte(0); + (void)spi_send_byte(0); + (void)spi_send_byte(0); +} + +static void spi_send_init() { + spi_send_packet(TABBY_PRINTER_PACKET_INIT, NULL, 0); +} + +static void spi_send_job(uint8_t sheets, + uint8_t linefeeds, + uint8_t palette, + uint8_t density) { + uint8_t job[4] = { + sheets, linefeeds, palette, density + }; + + spi_send_packet(TABBY_PRINTER_PACKET_JOB, job, sizeof(job)); +} + +static void spi_send_data(uint8_t *data, uint16_t size) { + spi_send_packet(TABBY_PRINTER_PACKET_DATA, data, size); +} + +static void spi_send_sheet(uint8_t *sheet, uint16_t size) { + int i; + + spi_send_init(); + + for (i=0; i