printer_i.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef PRINTER_I_H
  2. #define PRINTER_I_H
  3. #include <protocols/printer/include/printer_proto.h>
  4. #define PKT_START_L 0x88
  5. #define PKT_START_H 0x33
  6. #define PRINTER_ID 0x81
  7. #define CMD_INIT 0x01
  8. #define CMD_PRINT 0x02
  9. #define CMD_TRANSFER 0x10
  10. #define CMD_DATA 0x04
  11. #define CMD_BREAK 0x08 // ??
  12. #define CMD_STATUS 0x0f
  13. #define STATUS_LOWBATT (1 << 7)
  14. #define STATUS_ERR (1 << 6)
  15. #define STATUS_JAM (1 << 5)
  16. #define STATUS_PKT_ERR (1 << 4)
  17. #define STATUS_READY (1 << 3)
  18. #define STATUS_FULL (1 << 2)
  19. #define STATUS_PRINTING (1 << 1)
  20. #define STATUS_CKSUM (1 << 0)
  21. // Extra status bits used not used by the printer
  22. #define STATUS_PRINT_CMD (1 << 8)
  23. #define STATUS_PRINTED (1 << 9)
  24. /* emulate printer's internal print receive buffer */
  25. #define TILE_SIZE 16 // 8x8 tile, 2bpp color
  26. #define WIDTH 20 // 20 tiles wide
  27. #define HEIGHT 18 // 18 tiles tall
  28. #define PRINT_RECV_SZ 640 // (TILE_SIZE * WIDTH * 2)
  29. #define PRINT_FULL_SZ 5760 // (PRINT_RECV_SZ * HEIGHT / 2)
  30. #define TRANSFER_RECV_SZ 3584 // (16*16*14) // Image minus frame
  31. //Note that TRANSFER uses a locked size, 16x14 tiles, 16*16*14
  32. //GB seems to use 2 second busy timeout? I think that is a go to busy/printing within 2 seconds?
  33. //20 second print timeout
  34. enum packet_state {
  35. START_L,
  36. START_H,
  37. COMMAND,
  38. COMPRESS,
  39. LEN_L,
  40. LEN_H,
  41. COMMAND_DAT,
  42. CKSUM_L,
  43. CKSUM_H,
  44. ALIVE,
  45. STATUS,
  46. };
  47. /* Does not need to care about start bytes */
  48. struct packet {
  49. uint8_t cmd;
  50. uint8_t compress;
  51. uint16_t len; // This is stored in the flipper endianness, arrives LSB first from GB, unmodified in code
  52. uint8_t recv_data[PRINT_RECV_SZ]; // 640 bytes, enough for two lines of tiles
  53. uint16_t cksum; // This is stored in the flipper endianness, arrives LSB first from GB
  54. /* These are not part of the packet, but used by us */
  55. uint16_t cksum_calc;
  56. size_t recv_data_sz;
  57. uint16_t status;
  58. uint8_t zero_counter;
  59. enum packet_state state;
  60. uint32_t time;
  61. };
  62. #define THREAD_FLAGS_EXIT (1 << 0)
  63. #define THREAD_FLAGS_DATA (1 << 1)
  64. #define THREAD_FLAGS_PRINT (1 << 2)
  65. #define THREAD_FLAGS_COMPLETE (1 << 3)
  66. #define THREAD_FLAGS_ALL (THREAD_FLAGS_EXIT | THREAD_FLAGS_DATA | THREAD_FLAGS_PRINT | THREAD_FLAGS_COMPLETE)
  67. struct printer_proto {
  68. void *gblink_handle;
  69. void (*callback)(void *cb_context, struct gb_image *image, enum cb_reason reason);
  70. void *cb_context;
  71. struct packet *packet; //packet data used by send()/receive() for tracking
  72. struct gb_image *image; // Details of the current image being sent/received
  73. FuriThread *thread;
  74. };
  75. #endif // PRINTER_I_H