A totally not-working WIP
This commit is contained in:
parent
f8a3cf8d6b
commit
7059d688ac
3 changed files with 67 additions and 33 deletions
82
avr/send.c
82
avr/send.c
|
@ -63,7 +63,10 @@ static uint16_t checksum(tabby_printer_packet *header, uint8_t *body) {
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_send_packet(uint8_t type, uint8_t *body, uint16_t size) {
|
static void spi_send_packet(uint8_t type,
|
||||||
|
uint8_t *body,
|
||||||
|
uint16_t size,
|
||||||
|
tabby_printer_response *response) {
|
||||||
tabby_printer_packet header = {
|
tabby_printer_packet header = {
|
||||||
.preamble = { TABBY_PRINTER_SYNC_1, TABBY_PRINTER_SYNC_2 },
|
.preamble = { TABBY_PRINTER_SYNC_1, TABBY_PRINTER_SYNC_2 },
|
||||||
.type = type,
|
.type = type,
|
||||||
|
@ -86,41 +89,44 @@ static void spi_send_packet(uint8_t type, uint8_t *body, uint16_t size) {
|
||||||
(void)spi_send_byte( sum & 0x00ff);
|
(void)spi_send_byte( sum & 0x00ff);
|
||||||
(void)spi_send_byte((sum & 0xff00) >> 8);
|
(void)spi_send_byte((sum & 0xff00) >> 8);
|
||||||
|
|
||||||
(void)spi_send_byte(0);
|
response->device = spi_send_byte(0);
|
||||||
(void)spi_send_byte(0);
|
response->status = spi_send_byte(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_send_init() {
|
static void spi_send_init(tabby_printer_response *response) {
|
||||||
spi_send_packet(TABBY_PRINTER_PACKET_INIT, NULL, 0);
|
spi_send_packet(TABBY_PRINTER_PACKET_INIT, NULL, 0, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_send_job(uint8_t sheets,
|
static void spi_send_inquiry(tabby_printer_response *response) {
|
||||||
uint8_t linefeeds,
|
spi_send_packet(TABBY_PRINTER_PACKET_INQUIRY, NULL, 0, response);
|
||||||
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) {
|
static void spi_send_job(tabby_printer_job *job,
|
||||||
spi_send_packet(TABBY_PRINTER_PACKET_DATA, data, size);
|
tabby_printer_response *response) {
|
||||||
|
spi_send_packet(TABBY_PRINTER_PACKET_JOB,
|
||||||
|
job->data,
|
||||||
|
sizeof(job),
|
||||||
|
response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_send_sheet(uint8_t *sheet, uint16_t size) {
|
static void spi_send_data(uint8_t *data,
|
||||||
|
uint16_t size,
|
||||||
|
tabby_printer_response *response) {
|
||||||
|
spi_send_packet(TABBY_PRINTER_PACKET_DATA, data, size, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spi_send_sheet(uint8_t *sheet,
|
||||||
|
uint16_t size,
|
||||||
|
tabby_printer_response *response) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
spi_send_init();
|
spi_send_init(response);
|
||||||
|
|
||||||
for (i=0; i<size; i+=TABBY_PRINTER_BAND_SIZE) {
|
for (i=0; i<size; i+=TABBY_PRINTER_BAND_SIZE) {
|
||||||
spi_send_data(sheet + i, TABBY_PRINTER_BAND_SIZE);
|
spi_send_data(sheet + i, TABBY_PRINTER_BAND_SIZE, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_send_data(NULL, 0);
|
spi_send_data(NULL, 0, response);
|
||||||
|
|
||||||
spi_send_job(1, 0x13, 0x00, 0x40);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -134,6 +140,13 @@ int main() {
|
||||||
.size = 0
|
.size = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tabby_printer_response response = {
|
||||||
|
.device = TABBY_PRINTER_DEVICE_ID,
|
||||||
|
.status = TABBY_PRINTER_OK
|
||||||
|
};
|
||||||
|
|
||||||
|
tabby_printer_job job;
|
||||||
|
|
||||||
uint8_t sheet[TABBY_PRINTER_SHEET_SIZE];
|
uint8_t sheet[TABBY_PRINTER_SHEET_SIZE];
|
||||||
|
|
||||||
uart_init();
|
uart_init();
|
||||||
|
@ -226,7 +239,12 @@ int main() {
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
if (b < header.size) {
|
if (b < header.size) {
|
||||||
sheet[sheet_offset++] = c;
|
if (header.type == TABBY_PRINTER_PACKET_JOB) {
|
||||||
|
job.data[b] = c;
|
||||||
|
} else if (header.type == TABBY_PRINTER_PACKET_DATA) {
|
||||||
|
sheet[sheet_offset++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
b++;
|
b++;
|
||||||
} else if (b == header.size) {
|
} else if (b == header.size) {
|
||||||
b++;
|
b++;
|
||||||
|
@ -234,18 +252,18 @@ int main() {
|
||||||
i = 0;
|
i = 0;
|
||||||
b = 0;
|
b = 0;
|
||||||
|
|
||||||
switch (header.type) {
|
if (header.type == TABBY_PRINTER_PACKET_JOB) {
|
||||||
case TABBY_PRINTER_PACKET_DATA: {
|
spi_send_sheet(sheet, sheet_offset, &response);
|
||||||
if (header.size == 0) {
|
|
||||||
spi_send_sheet(sheet, sheet_offset);
|
|
||||||
|
|
||||||
sheet_offset = 0;
|
spi_send_job(&job, &response);
|
||||||
}
|
|
||||||
}
|
sheet_offset = 0;
|
||||||
|
} else if (header.type == TABBY_PRINTER_PACKET_INQUIRY) {
|
||||||
|
spi_send_inquiry(&response);
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_putchar(TABBY_PRINTER_DEVICE_ID, NULL);
|
uart_putchar(response.device, NULL);
|
||||||
uart_putchar(0x00, NULL);
|
uart_putchar(response.status, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,8 @@ int main(int argc, char **argv) {
|
||||||
printf("Sent sheet, got response %02x%02x\n",
|
printf("Sent sheet, got response %02x%02x\n",
|
||||||
response.device, response.status);
|
response.device, response.status);
|
||||||
|
|
||||||
|
tabby_printer_job_start(fd, 1, 0x13, 0x00, 0x40, &response);
|
||||||
|
|
||||||
while (response.status & TABBY_PRINTER_UNTRAN) {
|
while (response.status & TABBY_PRINTER_UNTRAN) {
|
||||||
tabby_printer_send_inquiry(fd, &response);
|
tabby_printer_send_inquiry(fd, &response);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ typedef enum {
|
||||||
TABBY_PRINTER_UNTRAN = (1 << 3),
|
TABBY_PRINTER_UNTRAN = (1 << 3),
|
||||||
TABBY_PRINTER_FULL = (1 << 2),
|
TABBY_PRINTER_FULL = (1 << 2),
|
||||||
TABBY_PRINTER_BUSY = (1 << 1),
|
TABBY_PRINTER_BUSY = (1 << 1),
|
||||||
TABBY_PRINTER_SUM = (1 << 0)
|
TABBY_PRINTER_SUM = (1 << 0),
|
||||||
|
TABBY_PRINTER_OK = 0
|
||||||
} tabby_printer_status;
|
} tabby_printer_status;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -56,6 +57,19 @@ typedef struct _tabby_printer_packet {
|
||||||
};
|
};
|
||||||
} tabby_printer_packet;
|
} tabby_printer_packet;
|
||||||
|
|
||||||
|
typedef struct _tabby_printer_job {
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
uint8_t sheets,
|
||||||
|
linefeeds,
|
||||||
|
palette,
|
||||||
|
density;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t data[4];
|
||||||
|
};
|
||||||
|
} tabby_printer_job;
|
||||||
|
|
||||||
typedef struct _tabby_printer_buffer {
|
typedef struct _tabby_printer_buffer {
|
||||||
tabby_printer_packet header;
|
tabby_printer_packet header;
|
||||||
uint8_t body[TABBY_PRINTER_PACKET_MAX_SIZE];
|
uint8_t body[TABBY_PRINTER_PACKET_MAX_SIZE];
|
||||||
|
|
Loading…
Add table
Reference in a new issue