My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commands.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /****************
  2. * commands.cpp *
  3. ****************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <https://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. /****************************************************************************
  22. * FUNCTION MAP *
  23. * *
  24. * SPI and FT800/810 Commands *
  25. * *
  26. * CLCD::spi_select() Set CS line to 0 *
  27. * CLCD::spi_deselect() Set CS Line to 1 *
  28. * CLCD::reset() Toggle FT800/810 Power Down Line 50 ms *
  29. * CLCD::spi_init() Configure I/O Lines for SPI *
  30. * CLCD::spi_transfer() Send/Receive 1 SPI Byte *
  31. * CLCD::init() Set FT800/810 Registers *
  32. * CLCD::enable() Turn On FT800/810 PCLK *
  33. * CLCD::disable() Turn Off FT8880/810 PCLK *
  34. * CLCD::set_backlight() Set LCD Backlight Level *
  35. * *
  36. * MEMORY READ FUNCTIONS *
  37. * *
  38. * CLCD::mem_read_addr() Send 32-Bit Address *
  39. * CLCD::mem_read_8() Read 1 Byte *
  40. * CLCD::mem_read_16() Read 2 Bytes *
  41. * CLCD::mem_read_32() Read 4 Bytes *
  42. * *
  43. * MEMORY WRITE FUNCTIONS *
  44. * *
  45. * CLCD::mem_write_addr() Send 24-Bit Address *
  46. * CLCD::mem_write_8() Write 1 Byte *
  47. * CLCD::mem_write_16() Write 2 Bytes *
  48. * CLCD::mem_write_32() Write 4 Bytes *
  49. * *
  50. * HOST COMMAND FUNCTION *
  51. * *
  52. * CLCD::host_cmd() Send 24-Bit Host Command *
  53. * *
  54. * COMMAND BUFFER FUNCTIONS *
  55. * *
  56. * CLCD::cmd() Send 32-Bit Value(4 Bytes)CMD Buffer *
  57. * CLCD::cmd() Send Data Structure with 32-Bit Cmd *
  58. * CLCD::str() Send Text String in 32-Bit Multiples *
  59. * *
  60. * FT800/810 GRAPHIC COMMANDS *
  61. * *
  62. * class CLCD:CommandFifo {} Class to control Cmd FIFO *
  63. * CommandFifo::start() Wait for CP finish - Set FIFO Ptr *
  64. * CommandFifo::execute() Set REG_CMD_WRITE and start CP *
  65. * CommandFifo::reset() Set Cmd Buffer Pointers to 0 *
  66. *
  67. * CommandFifo::fgcolor Set Graphic Item Foreground Color *
  68. * CommandFifo::bgcolor Set Graphic Item Background Color *
  69. * CommandFifo::begin() Begin Drawing a Primative *
  70. * CommandFifo::mem_copy() Copy a Block of Memory *
  71. * CommandFifo::append() Append Commands to Current DL *
  72. * CommandFifo::gradient_color() Set 3D Button Highlight Color *
  73. * CommandFifo::button() Draw Button with Bulk Write *
  74. * CommandFifo::text() Draw Text with Bulk Write *
  75. *****************************************************************************/
  76. /**************************************************
  77. * RAM_G Graphics RAM Allocation *
  78. * *
  79. * Address Use *
  80. * *
  81. * 8000 Extruder Bitmap *
  82. * 8100 Bed Heat Bitmap *
  83. * 8200 Fan Bitmap *
  84. * 8300 Thumb Drive Symbol Bitmap *
  85. * 35000 Static DL Space (FT800) *
  86. * F5000 Static DL Space (FT810) *
  87. **************************************************/
  88. #pragma once
  89. typedef const __FlashStringHelper *progmem_str;
  90. class UIStorage;
  91. class CLCD {
  92. friend class UIStorage;
  93. public:
  94. typedef FTDI::ftdi_registers REG;
  95. typedef FTDI::ftdi_memory_map MAP;
  96. static void spi_write_addr (uint32_t reg_address);
  97. static void spi_read_addr (uint32_t reg_address);
  98. static uint8_t mem_read_8 (uint32_t reg_address);
  99. static uint16_t mem_read_16 (uint32_t reg_address);
  100. static uint32_t mem_read_32 (uint32_t reg_address);
  101. static void mem_read_bulk (uint32_t reg_address, uint8_t *data, uint16_t len);
  102. static void mem_write_8 (uint32_t reg_address, uint8_t w_data);
  103. static void mem_write_16 (uint32_t reg_address, uint16_t w_data);
  104. static void mem_write_32 (uint32_t reg_address, uint32_t w_data);
  105. static void mem_write_fill (uint32_t reg_address, uint8_t w_data, uint16_t len);
  106. static void mem_write_bulk (uint32_t reg_address, const void *data, uint16_t len, uint8_t padding = 0);
  107. static void mem_write_pgm (uint32_t reg_address, const void *data, uint16_t len, uint8_t padding = 0);
  108. static void mem_write_bulk (uint32_t reg_address, progmem_str str, uint16_t len, uint8_t padding = 0);
  109. static void mem_write_xbm (uint32_t reg_address, progmem_str str, uint16_t len, uint8_t padding = 0);
  110. public:
  111. class CommandFifo;
  112. class FontMetrics;
  113. static void init();
  114. static void default_touch_transform();
  115. static void default_display_orientation();
  116. static void turn_on_backlight();
  117. static void enable();
  118. static void disable();
  119. static void set_brightness (uint8_t brightness);
  120. static uint8_t get_brightness();
  121. static void host_cmd (unsigned char host_command, unsigned char byte2);
  122. static uint32_t dl_size() {return CLCD::mem_read_32(REG::CMD_DL) & 0x1FFF;}
  123. static void get_font_metrics (uint8_t font, struct FontMetrics &fm);
  124. static uint16_t get_text_width(const uint8_t font, const char *str);
  125. static uint16_t get_text_width_P(const uint8_t font, const char *str);
  126. static uint8_t get_tag () {return mem_read_8(REG::TOUCH_TAG);}
  127. static bool is_touching () {return (mem_read_32(REG::TOUCH_DIRECT_XY) & 0x80000000) == 0;}
  128. static uint8_t get_tracker (uint16_t &value) {
  129. uint32_t tracker = mem_read_32(REG::TRACKER);
  130. value = tracker >> 16;
  131. return tracker & 0xFF;
  132. }
  133. };
  134. /*************************** FT800/810 Font Metrics ****************************/
  135. class CLCD::FontMetrics {
  136. public:
  137. uint8_t char_widths[128];
  138. uint32_t format;
  139. uint32_t stride;
  140. uint32_t width;
  141. uint32_t height;
  142. uint32_t ptr;
  143. FontMetrics() {}
  144. FontMetrics(uint8_t font) {load(font);}
  145. void load(uint8_t font);
  146. // Returns width of string, up to a maximum of n characters.
  147. uint16_t get_text_width(const char *str, size_t n = SIZE_MAX) const;
  148. uint16_t get_text_width(progmem_str str, size_t n = SIZE_MAX) const;
  149. };
  150. /******************* FT800/810 Graphic Commands *********************************/
  151. class CLCD::CommandFifo {
  152. protected:
  153. #if FTDI_API_LEVEL >= 810
  154. uint32_t getRegCmdBSpace();
  155. #else
  156. static uint32_t command_write_ptr;
  157. template <class T> bool _write_unaligned(T data, uint16_t len);
  158. #endif
  159. void start();
  160. public:
  161. template <class T> bool write(T data, uint16_t len);
  162. public:
  163. CommandFifo() {start();}
  164. static void reset();
  165. static bool is_processing();
  166. static bool has_fault();
  167. void execute();
  168. void cmd(uint32_t cmd32);
  169. void cmd(void *data, uint16_t len);
  170. void dlstart() {cmd(FTDI::CMD_DLSTART);}
  171. void swap() {cmd(FTDI::CMD_SWAP);}
  172. void coldstart() {cmd(FTDI::CMD_COLDSTART);}
  173. void screensaver() {cmd(FTDI::CMD_SCREENSAVER);}
  174. void stop() {cmd(FTDI::CMD_STOP);}
  175. void loadidentity() {cmd(FTDI::CMD_LOADIDENTITY);}
  176. void setmatrix() {cmd(FTDI::CMD_SETMATRIX);}
  177. void fgcolor (uint32_t rgb);
  178. void bgcolor (uint32_t rgb);
  179. void gradcolor (uint32_t rgb);
  180. void track (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t tag);
  181. void clock (int16_t x, int16_t y, int16_t r, uint16_t options, int16_t h, int16_t m, int16_t s, int16_t ms);
  182. void gauge (int16_t x, int16_t y, int16_t r, uint16_t options, uint16_t major, uint16_t minor, uint16_t val, uint16_t range);
  183. void dial (int16_t x, int16_t y, int16_t r, uint16_t options, uint16_t val);
  184. void slider (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t options, uint16_t val, uint16_t range);
  185. void progress (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t options, uint16_t val, uint16_t range);
  186. void scrollbar (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t options, uint16_t val, uint16_t size, uint16_t range);
  187. void number (int16_t x, int16_t y, int16_t font, uint16_t options, int32_t n);
  188. void spinner (int16_t x, int16_t y, uint16_t style, uint16_t scale);
  189. void sketch (int16_t x, int16_t y, uint16_t w, uint16_t h, uint32_t ptr, uint16_t format);
  190. void gradient (int16_t x0, int16_t y0, uint32_t rgb0, int16_t x1, int16_t y1, uint32_t rgb1);
  191. void snapshot (uint32_t ptr);
  192. void loadimage (uint32_t ptr, uint32_t options);
  193. void getprops (uint32_t ptr, uint32_t width, uint32_t height);
  194. void scale (int32_t sx, int32_t sy);
  195. void rotate (int32_t a);
  196. void translate (int32_t tx, int32_t ty);
  197. #if FTDI_API_LEVEL >= 810
  198. void setbase (uint8_t base);
  199. void setrotate (uint8_t rotation);
  200. void setbitmap (uint32_t ptr, uint16_t fmt, uint16_t w, uint16_t h);
  201. void snapshot2 (uint32_t fmt, uint32_t ptr, int16_t x, int16_t y, uint16_t w, uint16_t h);
  202. void mediafifo (uint32_t ptr, uint32_t size);
  203. void playvideo (uint32_t options);
  204. void videostart();
  205. void videoframe(uint32_t dst, uint32_t ptr);
  206. void romfont (uint8_t font, uint8_t romslot);
  207. #endif
  208. // All the following must be followed by str()
  209. void text (int16_t x, int16_t y, int16_t font, uint16_t options);
  210. void button (int16_t x, int16_t y, int16_t w, int16_t h, int16_t font, uint16_t option);
  211. void toggle (int16_t x, int16_t y, int16_t w, int16_t font, uint16_t options, bool state);
  212. void keys (int16_t x, int16_t y, int16_t w, int16_t h, int16_t font, uint16_t options);
  213. // Sends the string portion of text, button, toggle and keys.
  214. void str (const char * data);
  215. void str (progmem_str data);
  216. void memzero (uint32_t ptr, uint32_t size);
  217. void memset (uint32_t ptr, uint32_t value, uint32_t size);
  218. void memcpy (uint32_t dst, uint32_t src, uint32_t size);
  219. void memcrc (uint32_t ptr, uint32_t num, uint32_t result);
  220. void memwrite (uint32_t ptr, uint32_t value);
  221. void inflate (uint32_t ptr);
  222. void getptr (uint32_t result);
  223. void append (uint32_t ptr, uint32_t size);
  224. };