st7735.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* vim: set ai et ts=4 sw=4: */
  2. #ifndef __ST7735_H__
  3. #define __ST7735_H__
  4. #include "fonts.h"
  5. #include <stdbool.h>
  6. #define ST7735_MADCTL_MY 0x80
  7. #define ST7735_MADCTL_MX 0x40
  8. #define ST7735_MADCTL_MV 0x20
  9. #define ST7735_MADCTL_ML 0x10
  10. #define ST7735_MADCTL_RGB 0x00
  11. #define ST7735_MADCTL_BGR 0x08
  12. #define ST7735_MADCTL_MH 0x04
  13. /*** Redefine if necessary ***/
  14. //#define ST7735_SPI_PORT hspi1
  15. //extern SPI_HandleTypeDef ST7735_SPI_PORT;
  16. /*#define ST7735_RES_Pin GPIO_PIN_7
  17. #define ST7735_RES_GPIO_Port GPIOC
  18. #define ST7735_CS_Pin GPIO_PIN_6
  19. #define ST7735_CS_GPIO_Port GPIOB
  20. #define ST7735_DC_Pin GPIO_PIN_9
  21. #define ST7735_DC_GPIO_Port GPIOA*/
  22. // AliExpress/eBay 1.8" display, default orientation
  23. /*
  24. #define ST7735_IS_160X128 1
  25. #define ST7735_WIDTH 128
  26. #define ST7735_HEIGHT 160
  27. #define ST7735_XSTART 0
  28. #define ST7735_YSTART 0
  29. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MY)
  30. */
  31. // AliExpress/eBay 1.8" display, rotate right
  32. /*
  33. #define ST7735_IS_160X128 1
  34. #define ST7735_WIDTH 160
  35. #define ST7735_HEIGHT 128
  36. #define ST7735_XSTART 0
  37. #define ST7735_YSTART 0
  38. #define ST7735_ROTATION (ST7735_MADCTL_MY | ST7735_MADCTL_MV)
  39. */
  40. // AliExpress/eBay 1.8" display, rotate left
  41. /*
  42. #define ST7735_IS_160X128 1
  43. #define ST7735_WIDTH 160
  44. #define ST7735_HEIGHT 128
  45. #define ST7735_XSTART 0
  46. #define ST7735_YSTART 0
  47. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MV)
  48. */
  49. // AliExpress/eBay 1.8" display, upside down
  50. /*
  51. #define ST7735_IS_160X128 1
  52. #define ST7735_WIDTH 128
  53. #define ST7735_HEIGHT 160
  54. #define ST7735_XSTART 0
  55. #define ST7735_YSTART 0
  56. #define ST7735_ROTATION (0)
  57. */
  58. // WaveShare ST7735S-based 1.8" display, default orientation
  59. /*
  60. #define ST7735_IS_160X128 1
  61. #define ST7735_WIDTH 128
  62. #define ST7735_HEIGHT 160
  63. #define ST7735_XSTART 2
  64. #define ST7735_YSTART 1
  65. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MY | ST7735_MADCTL_RGB)
  66. */
  67. // WaveShare ST7735S-based 1.8" display, rotate right
  68. /*
  69. #define ST7735_IS_160X128 1
  70. #define ST7735_WIDTH 160
  71. #define ST7735_HEIGHT 128
  72. #define ST7735_XSTART 1
  73. #define ST7735_YSTART 2
  74. #define ST7735_ROTATION (ST7735_MADCTL_MY | ST7735_MADCTL_MV | ST7735_MADCTL_RGB)
  75. */
  76. // WaveShare ST7735S-based 1.8" display, rotate left
  77. /*
  78. #define ST7735_IS_160X128 1
  79. #define ST7735_WIDTH 160
  80. #define ST7735_HEIGHT 128
  81. #define ST7735_XSTART 1
  82. #define ST7735_YSTART 2
  83. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MV | ST7735_MADCTL_RGB)
  84. */
  85. // WaveShare ST7735S-based 1.8" display, upside down
  86. /*
  87. #define ST7735_IS_160X128 1
  88. #define ST7735_WIDTH 128
  89. #define ST7735_HEIGHT 160
  90. #define ST7735_XSTART 2
  91. #define ST7735_YSTART 1
  92. #define ST7735_ROTATION (ST7735_MADCTL_RGB)
  93. */
  94. // 1.44" display, default orientation
  95. /*#define ST7735_IS_128X128 1
  96. #define ST7735_WIDTH 128
  97. #define ST7735_HEIGHT 128
  98. #define ST7735_XSTART 2
  99. #define ST7735_YSTART 3
  100. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MY | ST7735_MADCTL_BGR)
  101. */
  102. // 1.44" display, rotate right
  103. /*
  104. #define ST7735_IS_128X128 1
  105. #define ST7735_WIDTH 128
  106. #define ST7735_HEIGHT 128
  107. #define ST7735_XSTART 3
  108. #define ST7735_YSTART 2
  109. #define ST7735_ROTATION (ST7735_MADCTL_MY | ST7735_MADCTL_MV | ST7735_MADCTL_BGR)
  110. */
  111. // 1.44" display, rotate left
  112. /*
  113. #define ST7735_IS_128X128 1
  114. #define ST7735_WIDTH 128
  115. #define ST7735_HEIGHT 128
  116. #define ST7735_XSTART 1
  117. #define ST7735_YSTART 2
  118. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MV | ST7735_MADCTL_BGR)
  119. */
  120. // 1.44" display, upside down
  121. /*
  122. #define ST7735_IS_128X128 1
  123. #define ST7735_WIDTH 128
  124. #define ST7735_HEIGHT 128
  125. #define ST7735_XSTART 2
  126. #define ST7735_YSTART 1
  127. #define ST7735_ROTATION (ST7735_MADCTL_BGR)
  128. */
  129. // mini 160x80 display (it's unlikely you want the default orientation)
  130. /*#define ST7735_IS_160X80 1
  131. #define ST7735_XSTART 0
  132. #define ST7735_YSTART 24
  133. #define ST7735_WIDTH 160
  134. #define ST7735_HEIGHT 80
  135. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MV |ST7735_MADCTL_BGR)*/
  136. #define ST7735_IS_160X128 1
  137. #define ST7735_XSTART 0
  138. #define ST7735_YSTART 0
  139. #define ST7735_WIDTH 160
  140. #define ST7735_HEIGHT 128
  141. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MV |ST7735_MADCTL_RGB)
  142. // mini 160x80, rotate left
  143. /*#define ST7735_IS_160X80 1
  144. #define ST7735_XSTART 1
  145. #define ST7735_YSTART 26
  146. #define ST7735_WIDTH 160
  147. #define ST7735_HEIGHT 80
  148. #define ST7735_ROTATION (ST7735_MADCTL_MX | ST7735_MADCTL_MV | ST7735_MADCTL_BGR)
  149. */
  150. // mini 160x80, rotate right
  151. /*
  152. #define ST7735_IS_160X80 1
  153. #define ST7735_XSTART 1
  154. #define ST7735_YSTART 26
  155. #define ST7735_WIDTH 160
  156. #define ST7735_HEIGHT 80
  157. #define ST7735_ROTATION (ST7735_MADCTL_MY | ST7735_MADCTL_MV | ST7735_MADCTL_BGR)
  158. */
  159. /****************************/
  160. #define ST7735_NOP 0x00
  161. #define ST7735_SWRESET 0x01
  162. #define ST7735_RDDID 0x04
  163. #define ST7735_RDDST 0x09
  164. #define ST7735_SLPIN 0x10
  165. #define ST7735_SLPOUT 0x11
  166. #define ST7735_PTLON 0x12
  167. #define ST7735_NORON 0x13
  168. #define ST7735_INVOFF 0x20
  169. #define ST7735_INVON 0x21
  170. #define ST7735_DISPOFF 0x28
  171. #define ST7735_DISPON 0x29
  172. #define ST7735_CASET 0x2A
  173. #define ST7735_RASET 0x2B
  174. #define ST7735_RAMWR 0x2C
  175. #define ST7735_RAMRD 0x2E
  176. #define ST7735_PTLAR 0x30
  177. #define ST7735_COLMOD 0x3A
  178. #define ST7735_MADCTL 0x36
  179. #define ST7735_FRMCTR1 0xB1
  180. #define ST7735_FRMCTR2 0xB2
  181. #define ST7735_FRMCTR3 0xB3
  182. #define ST7735_INVCTR 0xB4
  183. #define ST7735_DISSET5 0xB6
  184. #define ST7735_PWCTR1 0xC0
  185. #define ST7735_PWCTR2 0xC1
  186. #define ST7735_PWCTR3 0xC2
  187. #define ST7735_PWCTR4 0xC3
  188. #define ST7735_PWCTR5 0xC4
  189. #define ST7735_VMCTR1 0xC5
  190. #define ST7735_RDID1 0xDA
  191. #define ST7735_RDID2 0xDB
  192. #define ST7735_RDID3 0xDC
  193. #define ST7735_RDID4 0xDD
  194. #define ST7735_PWCTR6 0xFC
  195. #define ST7735_GMCTRP1 0xE0
  196. #define ST7735_GMCTRN1 0xE1
  197. // Color definitions
  198. #define ST7735_BLACK 0x0000
  199. #define ST7735_BLUE 0x001F
  200. #define ST7735_RED 0xF800
  201. #define ST7735_GREEN 0x07E0
  202. #define ST7735_CYAN 0x07FF
  203. #define ST7735_MAGENTA 0xF81F
  204. #define ST7735_YELLOW 0xFFE0
  205. #define ST7735_WHITE 0xFFFF
  206. #define ST7735_COLOR565(r, g, b) (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3))
  207. // call before initializing any SPI devices
  208. void ST7735_Init(void);
  209. void ST7735_Init2(void);
  210. void ST7735_DrawPixel(uint16_t x, uint16_t y, uint16_t color);
  211. void ST7735_WriteString(uint16_t x, uint16_t y, unsigned char* str, FontDef *font, uint16_t color, uint16_t bgcolor);
  212. void ST7735_FillRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
  213. void ST7735_FillScreen(uint16_t color);
  214. void ST7735_DrawImage(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t* data);
  215. void ST7735_InvertColors(bool invert);
  216. void ST7735_Test(void);
  217. //unsigned char * i16_2s(int16_t value, unsigned char *buffer);
  218. //unsigned char * i32_2s(int32_t value, unsigned char *buffer);
  219. #endif // __ST7735_H__