HAL_LCD.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. ******************************************************************************
  3. * @file HAL_LCD.c
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief LCD HAL module driver.
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (LCD).
  9. * @ Initialization and de-initialization functions
  10. * @ IO operation functions
  11. * @ Peripheral Control functions
  12. ******************************************************************************
  13. */
  14. #include "ACM32Fxx_HAL.h"
  15. /*********************************************************************************
  16. * Function : HAL_LCD_MspInit
  17. * Description : Initialize the LCD MSP.
  18. * Input : hcan : pointer to a LCD structure that contains
  19. * the configuration information for LCD module
  20. * Output :
  21. * Author : CWT Data : 2020年
  22. **********************************************************************************/
  23. __weak void HAL_LCD_MspInit(LCD_HandleTypeDef *hlcd)
  24. {
  25. /* NOTE : This function only enable lcd clk and config NVIC
  26. Because lcd's SEG and COM is different,so the gpio of lcd need user config self.*/
  27. /* Enable LCD clock */
  28. System_Module_Enable(EN_LCD);
  29. /* Enable the LCD Frame interrupt */
  30. hlcd->Instance->CR1 |= LCD_CR1_IE;
  31. NVIC_ClearPendingIRQ(LCD_IRQn);
  32. NVIC_SetPriority(LCD_IRQn, 5);
  33. NVIC_EnableIRQ(LCD_IRQn);
  34. }
  35. /*********************************************************************************
  36. * Function : HAL_LCD_MspDeInit
  37. * Description : DeInitialize the LCD MSP.
  38. * Input : hcan : pointer to a LCD structure that contains
  39. * the configuration information for LCD module
  40. * Output :
  41. * Author : CWT Data : 2020年
  42. **********************************************************************************/
  43. void HAL_LCD_MspDeInit(LCD_HandleTypeDef *hlcd)
  44. {
  45. /* Disable LCD clock */
  46. System_Module_Disable(EN_LCD);
  47. }
  48. /*********************************************************************************
  49. * Function : HAL_LCD_Init
  50. * Description : Initialize the LCD.
  51. * Input : hcan : pointer to a LCD structure that contains
  52. * the configuration information for LCD module
  53. * Output :
  54. * Author : CWT Data : 2020年
  55. **********************************************************************************/
  56. HAL_StatusTypeDef HAL_LCD_Init(LCD_HandleTypeDef *hlcd)
  57. {
  58. /* Check the parameters */
  59. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  60. if(!IS_LCD_DUTY(hlcd->Init.Duty)) return HAL_ERROR;
  61. if(!IS_LCD_BIAS(hlcd->Init.Bias)) return HAL_ERROR;
  62. if(!IS_LCD_Driving_Waveform(hlcd->Init.Driving_Waveform)) return HAL_ERROR;
  63. if(!IS_LCD_BiasSrc(hlcd->Init.BiasSrc)) return HAL_ERROR;
  64. if(!IS_LCD_DisplayMode(hlcd->Init.DisplayMode)) return HAL_ERROR;
  65. if(!IS_LCD_LCDFrequency(hlcd->Init.LCDFrequency)) return HAL_ERROR;
  66. if(!IS_LCD_BlinkEN(hlcd->Init.BlinkEN)) return HAL_ERROR;
  67. if(!IS_LCD_BlinkFrequency(hlcd->Init.BlinkFrequency)) return HAL_ERROR;
  68. /* Reset the RST_LCD */
  69. System_Module_Reset(RST_LCD);
  70. HAL_LCD_MspInit(hlcd);
  71. hlcd->Instance->CR0|=(LCD_CR0_LCDEN|hlcd->Init.LCDFrequency|hlcd->Init.Bias|hlcd->Init.Duty|hlcd->Init.BiasSrc|hlcd->Init.Driving_Waveform);
  72. hlcd->Instance->CR1|=(hlcd->Init.BlinkEN|hlcd->Init.BlinkFrequency|hlcd->Init.DisplayMode);
  73. if(hlcd->Init.Driving_Waveform==LCD_Driving_Waveform_A)
  74. {
  75. hlcd->Instance->CR0&=~(LCD_CR0_WSEL);
  76. }
  77. if(hlcd->Init.Duty==LCD_DUTY_STATIC)
  78. {
  79. if(!IS_LCD_StaticPower(hlcd->Init.StaticPower)) return HAL_ERROR;
  80. hlcd->Instance->CR0|=hlcd->Init.StaticPower;
  81. }
  82. else
  83. {
  84. hlcd->Instance->CR0&=~(LCD_CR0_STATIC);//当DUTY选择非静态时,该位必须设置为0
  85. }
  86. return HAL_OK;
  87. }
  88. /*********************************************************************************
  89. * Function : HAL_LCD_DeInit
  90. * Description : DeInitialize the LCD.
  91. * Input : hcan : pointer to a LCD structure that contains
  92. * the configuration information for LCD module
  93. * Output :
  94. * Author : CWT Data : 2020年
  95. **********************************************************************************/
  96. HAL_StatusTypeDef HAL_LCD_DeInit(LCD_HandleTypeDef *hlcd)
  97. {
  98. /* Check the parameters */
  99. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  100. /* Reset the CAN peripheral */
  101. CLEAR_BIT(hlcd->Instance->CR0, LCD_CR0_LCDEN);
  102. HAL_LCD_MspDeInit(hlcd);
  103. /* Return function status */
  104. return HAL_OK;
  105. }
  106. /*********************************************************************************
  107. * Function : HAL_LCD_InResConfig
  108. * Description : Initialize the LCD When LCD BiasSrc is LCD_BiasSrc_InRes_Seg31_35_Normal or LCD_BiasSrc_InRes_Seg31_35_Cap.
  109. * Input : hlcd : pointer to a LCD structure that contains
  110. * the configuration information for LCD module
  111. * LCD_InResInitStruct:LCD_InResInitTypeDef
  112. * Output :
  113. * Author : CWT Data : 2020年
  114. **********************************************************************************/
  115. HAL_StatusTypeDef HAL_LCD_InResConfig(LCD_HandleTypeDef *hlcd,LCD_InResInitTypeDef* LCD_InResInitStruct)
  116. {
  117. /* Check the parameters */
  118. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  119. /* Config when BiasSrc is Inside Resistance Mod */
  120. if(hlcd->Init.BiasSrc!=LCD_BiasSrc_ExRes_Seg31_35_Cap)
  121. {
  122. /* Check the parameters */
  123. if(!IS_LCD_BiasRes(LCD_InResInitStruct->BiasRes)) return HAL_ERROR;
  124. if(!IS_LCD_DriveMod(LCD_InResInitStruct->DriveMod)) return HAL_ERROR;
  125. if(!IS_LCD_FastCharge(LCD_InResInitStruct->FastCharge)) return HAL_ERROR;
  126. if(!IS_LCD_Contrast(LCD_InResInitStruct->Contrast)) return HAL_ERROR;
  127. /* Config LCD Contrast and Bias Resistance and DriveMod */
  128. hlcd->Instance->CR0|=(LCD_InResInitStruct->Contrast);
  129. hlcd->Instance->CR1|=(LCD_InResInitStruct->BiasRes|LCD_InResInitStruct->DriveMod);
  130. /* Config LCD PONTime when DriveMod is Fast Charge and Fast Charge(FCC) is Enable. */
  131. if(LCD_InResInitStruct->FastCharge==LCD_FastCharge_Enable && LCD_InResInitStruct->DriveMod==LCD_DriveMod_FC)
  132. {
  133. if(!IS_LCD_PONTime(LCD_InResInitStruct->PONTime)) return HAL_ERROR;
  134. hlcd->Instance->CR1|=(LCD_InResInitStruct->PONTime<<18);
  135. }
  136. }
  137. return HAL_OK;
  138. }
  139. /*********************************************************************************
  140. * Function : HAL_LCD_SegComConfig
  141. * Description : Config the LCD SEG and COM enable/disable.
  142. * Input : hlcd : pointer to a LCD structure that contains
  143. * the configuration information for LCD module
  144. * SegCom:LCD_SegComInitTypeDef
  145. * Output :
  146. * Author : CWT Data : 2020年
  147. **********************************************************************************/
  148. HAL_StatusTypeDef HAL_LCD_SegComConfig(LCD_HandleTypeDef *hlcd,LCD_SegComInitTypeDef *SegCom)
  149. {
  150. /* Check the parameters */
  151. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  152. hlcd->Instance->LCD_POEN0=SegCom->SEG0_31;
  153. hlcd->Instance->LCD_POEN1=SegCom->Stc_SEG32_39_COM0_8.SEG32_39_COM0_8;
  154. return HAL_OK;
  155. }
  156. /*********************************************************************************
  157. * Function : HAL_LCD_Write
  158. * Description : Write LCD RAMx.
  159. * Input : hlcd : pointer to a LCD structure that contains
  160. * the configuration information for LCD module
  161. * LCDRAMIndex:LCD RAM index
  162. * Data:The data you want to write
  163. * Output :
  164. * Author : CWT Data : 2020年
  165. **********************************************************************************/
  166. HAL_StatusTypeDef HAL_LCD_Write(LCD_HandleTypeDef *hlcd, uint32_t LCDRAMIndex, uint32_t Data)
  167. {
  168. /* Check the parameters */
  169. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  170. if(LCDRAMIndex>15) return HAL_ERROR;
  171. /* Wrete Data bytes to LCD RAM register */
  172. hlcd->Instance->LCD_RAM[LCDRAMIndex]=Data;
  173. return HAL_OK;
  174. }
  175. /*********************************************************************************
  176. * Function : HAL_LCD_Clear
  177. * Description : Clear LCD RAMx.
  178. * Input : hlcd : pointer to a LCD structure that contains
  179. * the configuration information for LCD module
  180. * Output :
  181. * Author : CWT Data : 2020年
  182. **********************************************************************************/
  183. HAL_StatusTypeDef HAL_LCD_Clear(LCD_HandleTypeDef *hlcd)
  184. {
  185. uint8_t LCDRAMIndex=0;
  186. /* Check the parameters */
  187. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  188. /* Clear the LCD_RAM registers */
  189. for(LCDRAMIndex = 0; LCDRAMIndex <= 15; LCDRAMIndex++)
  190. {
  191. hlcd->Instance->LCD_RAM[LCDRAMIndex] = 0U;
  192. }
  193. return HAL_OK;
  194. }
  195. /*********************************************************************************
  196. * Function : HAL_LCD_Start_DMA
  197. * Description : Start lcd dma transfer
  198. * Input : hlcd : pointer to a LCD structure that contains
  199. * the configuration information for LCD module
  200. * pData:The data want to transfer
  201. * Length:transfer Size
  202. * Output :
  203. * Author : CWT Data : 2020年
  204. **********************************************************************************/
  205. HAL_StatusTypeDef HAL_LCD_Start_DMA(LCD_HandleTypeDef *hlcd, uint32_t *pData, uint32_t Length)
  206. {
  207. /* Check the parameters */
  208. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  209. hlcd->Instance->CR1 |= LCD_CR1_DMAEN;
  210. if (HAL_DMA_Start_IT(hlcd->DMA_Handle,(uint32_t)pData,(uint32_t)(&hlcd->Instance->LCD_RAM[0]), Length))
  211. {
  212. return HAL_ERROR;
  213. }
  214. return HAL_OK;
  215. }
  216. /*********************************************************************************
  217. * Function : HAL_LCD_Stop_DMA
  218. * Description : Stop lcd dma transfer
  219. * Input : hlcd : pointer to a LCD structure that contains
  220. * the configuration information for LCD module
  221. * pData:The data want to transfer
  222. * Length:transfer Size
  223. * Output :
  224. * Author : CWT Data : 2020年
  225. **********************************************************************************/
  226. HAL_StatusTypeDef HAL_LCD_Stop_DMA(LCD_HandleTypeDef *hlcd)
  227. {
  228. HAL_StatusTypeDef status = HAL_OK;
  229. /* Check the parameters */
  230. if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
  231. hlcd->Instance->CR1 &=~ LCD_CR1_DMAEN;
  232. status = HAL_DMA_Abort(hlcd->DMA_Handle);
  233. return status;
  234. }
  235. /*********************************************************************************
  236. * Function : HAL_LCD_IRQHandler
  237. * Description : HAL_LCD_IRQHandler
  238. * Input : hlcd : pointer to a LCD structure that contains
  239. * the configuration information for LCD module
  240. * Output :
  241. * Author : CWT Data : 2020年
  242. **********************************************************************************/
  243. void HAL_LCD_IRQHandler(LCD_HandleTypeDef *hlcd)
  244. {
  245. hlcd->Instance->INTCLR &=~ (LCD_INTCLR_INTFT);
  246. }