printer_i.h 2.5 KB

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