Most amusingly I am achieving novel results with this ATmega2560
This commit is contained in:
parent
3e2a43529a
commit
985e556556
4 changed files with 101 additions and 33 deletions
|
@ -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) \
|
||||
|
|
109
avr/send.c
109
avr/send.c
|
@ -7,15 +7,6 @@
|
|||
#include <tabby/avr/uart.h>
|
||||
#include <tabby/avr.h>
|
||||
|
||||
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; i<sizeof(*header); i++) {
|
||||
sum += header->data[i];
|
||||
}
|
||||
|
||||
for (i=0; i<header->size; 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<sizeof(header); i++) {
|
||||
(void)spi_send_byte(header.data[i]);
|
||||
}
|
||||
|
||||
for (i=0; i<header.size; i++) {
|
||||
for (i=0; i<size; i++) {
|
||||
(void)spi_send_byte(body[i]);
|
||||
}
|
||||
|
||||
(void)spi_send_byte( sum & 0x00ff);
|
||||
(void)spi_send_byte((sum & 0xff00) >> 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<size; i+=TABBY_PRINTER_BAND_SIZE) {
|
||||
spi_send_data(sheet + i, TABBY_PRINTER_BAND_SIZE);
|
||||
}
|
||||
|
||||
spi_send_data(NULL, 0);
|
||||
|
||||
spi_send_job(1, 0x13, 0x00, 0x40);
|
||||
}
|
||||
|
||||
int main() {
|
||||
uint16_t i = 0,
|
||||
b = 0;
|
||||
b = 0,
|
||||
sheet_offset = 0;
|
||||
|
||||
uint8_t c;
|
||||
|
||||
tabby_printer_packet header = {
|
||||
.size = 0
|
||||
};
|
||||
|
||||
uint8_t sheet[TABBY_PRINTER_SHEET_SIZE];
|
||||
|
||||
uart_init();
|
||||
spi_init();
|
||||
|
||||
|
@ -125,8 +181,11 @@ int main() {
|
|||
switch (c) {
|
||||
case TABBY_PRINTER_PACKET_INIT:
|
||||
case TABBY_PRINTER_PACKET_JOB:
|
||||
case TABBY_PRINTER_PACKET_CANCEL: {
|
||||
sheet_offset = 0;
|
||||
}
|
||||
|
||||
case TABBY_PRINTER_PACKET_DATA:
|
||||
case TABBY_PRINTER_PACKET_CANCEL:
|
||||
case TABBY_PRINTER_PACKET_INQUIRY: {
|
||||
header.type = c;
|
||||
i++;
|
||||
|
@ -167,20 +226,26 @@ int main() {
|
|||
|
||||
default: {
|
||||
if (b < header.size) {
|
||||
body[b++] = c;
|
||||
sheet[sheet_offset++] = c;
|
||||
b++;
|
||||
} else if (b == header.size) {
|
||||
sum = c;
|
||||
b++;
|
||||
} else if (b == header.size + 1) {
|
||||
sum |= c << 8;
|
||||
|
||||
i = 0;
|
||||
b = 0;
|
||||
|
||||
spi_send_packet();
|
||||
switch (header.type) {
|
||||
case TABBY_PRINTER_PACKET_DATA: {
|
||||
if (header.size == 0) {
|
||||
spi_send_sheet(sheet, sheet_offset);
|
||||
|
||||
uart_putchar(response.device, NULL);
|
||||
uart_putchar(response.status, NULL);
|
||||
sheet_offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uart_putchar(TABBY_PRINTER_DEVICE_ID, NULL);
|
||||
uart_putchar(0x00, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,10 +63,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
tabby_printer_link_init(fd);
|
||||
|
||||
printf("Link initialized\n");
|
||||
|
||||
do {
|
||||
tabby_printer_init(fd, &response);
|
||||
|
||||
usleep(100000);
|
||||
printf("Got response %02x%02x\n", response.device, response.status);
|
||||
} while (response.device != TABBY_PRINTER_DEVICE_ID);
|
||||
|
||||
tabby_printer_send_sheet(fd, tile, &response);
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
* SC -- Serial Clock
|
||||
*/
|
||||
#define SC_DDR DDRB
|
||||
#define SC_DDB DDB5
|
||||
#define SC_DDB DDB1
|
||||
#define SC_PORT PORTB
|
||||
#define SC_PORT_PIN PORTB5
|
||||
#define SC_PORT_PIN PORTB1
|
||||
|
||||
#define SC_INPUT() \
|
||||
(SC_DDR |= ~(1 << SC_DDB))
|
||||
|
@ -40,11 +40,11 @@
|
|||
* SI -- Serial In
|
||||
*/
|
||||
#define SI_DDR DDRB
|
||||
#define SI_DDB DDB3
|
||||
#define SI_DDB DDB2
|
||||
#define SI_PIN_REG PINB
|
||||
#define SI_PIN PINB3
|
||||
#define SI_PIN PINB2
|
||||
#define SI_PORT PORTB
|
||||
#define SI_PORT_PIN PORTB3
|
||||
#define SI_PORT_PIN PORTB2
|
||||
|
||||
#define SI_INPUT() \
|
||||
(SI_DDR &= ~(1 << SI_DDB))
|
||||
|
@ -59,9 +59,9 @@
|
|||
* SO -- Serial Out
|
||||
*/
|
||||
#define SO_DDR DDRB
|
||||
#define SO_DDB DDB4
|
||||
#define SO_DDB DDB3
|
||||
#define SO_PORT PORTB
|
||||
#define SO_PORT_PIN PORTB4
|
||||
#define SO_PORT_PIN PORTB3
|
||||
|
||||
#define SO_OUTPUT() \
|
||||
(SO_DDR |= (1 << SO_DDB))
|
||||
|
@ -73,7 +73,7 @@
|
|||
(SO_PORT &= ~(1 << SO_PORT_PIN))
|
||||
|
||||
#define SS_DDR DDRB
|
||||
#define SS_DDB DDB2
|
||||
#define SS_DDB DDB0
|
||||
|
||||
#define SS_INPUT() \
|
||||
(SS_DDR &= ~(1 << SS_DDB))
|
||||
|
|
Loading…
Add table
Reference in a new issue