printer_i.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. enum printer_method {
  48. PROTO_RECV,
  49. PROTO_SEND,
  50. };
  51. /* Does not need to care about start bytes */
  52. struct packet {
  53. uint8_t cmd;
  54. uint8_t compress;
  55. uint16_t len; // This is stored in the flipper endianness, arrives LSB first from GB, unmodified in code
  56. uint8_t recv_data[PRINT_RECV_SZ]; // 640 bytes, enough for two lines of tiles
  57. uint16_t cksum; // This is stored in the flipper endianness, arrives LSB first from GB
  58. /* These are not part of the packet, but used by us */
  59. uint16_t cksum_calc;
  60. size_t recv_data_sz;
  61. uint16_t status;
  62. uint8_t zero_counter;
  63. enum packet_state state;
  64. uint32_t time;
  65. };
  66. #define THREAD_FLAGS_EXIT (1 << 0)
  67. #define THREAD_FLAGS_DATA (1 << 1)
  68. #define THREAD_FLAGS_PRINT (1 << 2)
  69. #define THREAD_FLAGS_COMPLETE (1 << 3)
  70. #define THREAD_FLAGS_ALL (THREAD_FLAGS_EXIT | THREAD_FLAGS_DATA | THREAD_FLAGS_PRINT | THREAD_FLAGS_COMPLETE)
  71. struct printer_proto {
  72. void *gblink_handle;
  73. void (*callback)(void *cb_context, struct gb_image *image, enum cb_reason reason);
  74. void *cb_context;
  75. struct packet *packet; //packet data used by send()/receive() for tracking
  76. struct gb_image *image; // Details of the current image being sent/received
  77. FuriThread *thread;
  78. };
  79. #endif // PRINTER_I_H