pcd8544.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef __FW_PCD8544__
  15. #define __FW_PCD8544__
  16. #include "fw_hal.h"
  17. /**
  18. * PCD8544
  19. *
  20. * Philips – PCD8544 is a single-chip low-power CMOS LCD driver controller
  21. * The chip is designed to drive a graphic display of 84×48 pixels with SPI interface.
  22. * Display Data RAM = 6 banks x 84 segments x 8 bits = 4032 bits = 504 bytes
  23. * Each bank contains 84 columns/segments (from 0 to 83)
  24. * Each column can store 8 bits of data (from 0 to 7)
  25. */
  26. #define PCD8544_CS P35
  27. #define PCD8544_MOSI P34
  28. #define PCD8544_SCK P32
  29. #define PCD8544_RES P37
  30. #define PCD8544_DC P36
  31. #define PCD8544_BL P12
  32. // X width
  33. #define PCD8544_WIDTH 84
  34. // Y height
  35. #define PCD8544_HEIGHT 48
  36. // Display RAM Pages
  37. #define PCD8544_PAGES 6
  38. #define PCD8544_FUNCTIONSET 0x20 // Function set
  39. #define PCD8544_POWERDOWN 0x04 // Function set, power down mode
  40. #define PCD8544_ENTRYMODE 0x02 // Function set, entry mode (vertical addressing)
  41. #define PCD8544_EXT_INSTRUCTION 0x01 // Function set, extended instruction set control
  42. #define PCD8544_DISPLAY_CONTROL 0x08 // Basic instruction set - Set display configuration
  43. #define PCD8544_DISPLAY_BLANK 0x00 // Display control, blank
  44. #define PCD8544_DISPLAY_NORMAL 0x04 // Display control, normal mode
  45. #define PCD8544_DISPLAY_ALLON 0x01 // Display control, all segments on
  46. #define PCD8544_DISPLAY_INVERTED 0x05 // Display control, inverse mode
  47. #define PCD8544_SET_YADDR 0x40 // Basic instruction set - Set Y address of RAM, 0 <= Y <= 5
  48. #define PCD8544_SET_XADDR 0x80 // Basic instruction set - Set X address of RAM, 0 <= X <= 83
  49. #define PCD8544_SET_TEMP 0x04 // Extended instruction set - Set temperature coefficient
  50. #define PCD8544_SET_BIAS 0x10 // Extended instruction set - Set bias system
  51. #define PCD8544_SET_VOP 0x80 // Extended instruction set - Write Vop to register
  52. typedef struct {
  53. uint8_t width;
  54. uint8_t height;
  55. uint8_t order;
  56. uint8_t bytes;
  57. const uint8_t *dat;
  58. } FontDef_t;
  59. extern __CODE FontDef_t Font_3x5;
  60. extern __CODE FontDef_t Font_5x7;
  61. /**
  62. * @brief Turn PCD8544 LCD backlight on or off
  63. * @param state HAL_State_ON:on, HAL_State_OFF:off
  64. * @retval None
  65. */
  66. void PCD8544_SetBackLightState(HAL_State_t state);
  67. /**
  68. * @brief Writes single byte data to PCD8544
  69. * @param dat: data to be written
  70. * @retval None
  71. */
  72. void PCD8544_WriteData(uint8_t dat);
  73. void PCD8544_WriteSameData(uint8_t dat, uint32_t size);
  74. /**
  75. * @brief Write a single byte command to PCD8544
  76. * @param command: command to be written
  77. * @retval None
  78. */
  79. void PCD8544_WriteCommand(uint8_t command);
  80. /**
  81. * @brief Hardware reset PCD8544 LCD
  82. * @param None
  83. * @retval None
  84. */
  85. void PCD8544_Reset(void);
  86. /**
  87. * @brief Powerdown mode control
  88. * @param state HAL_State_ON:powerdown mode, HAL_State_OFF:work mode
  89. * @retval None
  90. */
  91. void PCD8544_SetPowerDownMode(HAL_State_t state);
  92. /**
  93. * @brief Set bias system level
  94. * @param val bias value, [0x00,0x07], small value may lead to totally blank display
  95. * @retval None
  96. */
  97. void PCD8544_SetBias(uint8_t val);
  98. /**
  99. * @brief Set TCx (temperature coefficient)
  100. * @param val TCx value, [0x00, 0x03]
  101. * @retval None
  102. */
  103. void PCD8544_SetTemperatureCoef(uint8_t val);
  104. /**
  105. * @brief Set the contrast level by adjusting Vlcd
  106. * @param bias, bias value, [0x00,0x07], small value may lead to totally blank display
  107. * @param val contrast level, [0x00, 0x7F]
  108. * @retval None
  109. */
  110. void PCD8544_SetContrast(uint8_t bias, uint8_t val);
  111. /**
  112. * @brief Set PCD8544 To Turn On All Segments
  113. * @param None
  114. * @retval None
  115. */
  116. void PCD8544_SetDisplayAllOn(void);
  117. /**
  118. * @brief Set PCD8544 Display Mode to Inverted
  119. * @param None
  120. * @retval None
  121. */
  122. void PCD8544_SetDisplayInverted(void);
  123. /**
  124. * @brief Set PCD8544 Display Mode to Blank
  125. * @param None
  126. * @retval None
  127. */
  128. void PCD8544_SetDisplayBlank(void);
  129. /**
  130. * @brief Set PCD8544 Display Mode to Normal
  131. * @param None
  132. * @retval None
  133. */
  134. void PCD8544_SetDisplayNormal(void);
  135. /**
  136. * @brief Initializes PCD8544 Display
  137. * @param None
  138. * @retval None
  139. */
  140. void PCD8544_Init(void);
  141. /**
  142. * @brief Fills entire LCD with specified color
  143. * @note @ref PCD8544_UpdateScreen() must be called after that in order to see updates
  144. * @param Color: Color to be used for screen fill, 0x00 or 0x01
  145. * @retval None
  146. */
  147. void PCD8544_Fill(uint8_t color);
  148. /**
  149. * @brief Update LCD display with changes
  150. * @note Call this function each time when display is changed
  151. * @param None
  152. * @retval None
  153. */
  154. void PCD8544_UpdateScreen(void);
  155. /**
  156. * @brief Draws pixel at desired location
  157. * @note @ref PCD8544_UpdateScreen() must called after that in order to show updates
  158. * @param x: X location, value between [0, PCD8544_WIDTH)
  159. * @param y: Y location, value between [0, PCD8544_HEIGHT)
  160. * @param color: Color to be used for screen fill, 0x00 or 0x01
  161. * @retval None
  162. */
  163. void PCD8544_DrawPixel(uint8_t x, uint8_t y, uint8_t color);
  164. /**
  165. * @brief Draws line on LCD
  166. * @note @ref PCD8544_UpdateScreen() must be called after that in order to show updates
  167. * @param x0: Line X start point, value between [0, PCD8544_WIDTH)
  168. * @param y0: Line Y start point, value between [0, PCD8544_HEIGHT)
  169. * @param x1: Line X end point, value between [0, PCD8544_WIDTH)
  170. * @param y1: Line Y end point, value between [0, PCD8544_HEIGHT)
  171. * @param color: Color to be used. 0x00 or 0x01
  172. * @retval None
  173. */
  174. void PCD8544_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t color);
  175. /**
  176. * @brief Sets cursor pointer to desired location for strings
  177. * @param x: X location, value between [0, PCD8544_WIDTH)
  178. * @param y: Y location, value between [0, PCD8544_HEIGHT)
  179. * @retval None
  180. */
  181. void PCD8544_GotoXY(uint8_t x, uint8_t y);
  182. /**
  183. * @brief Put one character to internal RAM
  184. * @note @ref PCD8544_UpdateScreen() must be called after that in order to show updates
  185. * @param ch: Character to be written
  186. * @param *Font: Pointer to @ref FontDef_t structure with used font
  187. * @param color: Color used for drawing. 0x00 or 0x01
  188. * @retval value of ch
  189. */
  190. char PCD8544_Putc(char ch, FontDef_t* font, uint8_t color);
  191. /**
  192. * @brief Puts string to internal RAM
  193. * @note @ref PCD8544_UpdateScreen() must be called after that in order to show updates
  194. * @param *str: String to be written
  195. * @param *Font: Pointer to @ref FontDef_t structure with used font
  196. * @param color: Color used for drawing. 0x00 or 0x01
  197. * @retval Zero on success or character value when function failed
  198. */
  199. char PCD8544_Puts(char* str, FontDef_t* Font, uint8_t color);
  200. #endif // __PCD8544_H_