efm32_lcd.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Liquid Crystal Display (LCD) peripheral API for EFM32
  4. * @author Energy Micro AS
  5. * @version 1.3.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_LCD_H
  29. #define __EFM32_LCD_H
  30. #include "efm32.h"
  31. #if defined(LCD_COUNT) && (LCD_COUNT > 0)
  32. #include <stdint.h>
  33. #include <stdbool.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /***************************************************************************//**
  38. * @addtogroup EFM32_Library
  39. * @{
  40. ******************************************************************************/
  41. /***************************************************************************//**
  42. * @addtogroup LCD
  43. * @{
  44. ******************************************************************************/
  45. /*******************************************************************************
  46. ******************************** ENUMS ************************************
  47. ******************************************************************************/
  48. /** MUX setting */
  49. typedef enum
  50. {
  51. /** Static (segments can be multiplexed with LCD_COM[0]) */
  52. lcdMuxStatic = LCD_DISPCTRL_MUX_STATIC,
  53. /** Duplex / 1/2 Duty cycle (segments can be multiplexed with LCD_COM[0:1]) */
  54. lcdMuxDuplex = LCD_DISPCTRL_MUX_DUPLEX,
  55. /** Triplex / 1/3 Duty cycle (segments can be multiplexed with LCD_COM[0:2]) */
  56. lcdMuxTriplex = LCD_DISPCTRL_MUX_TRIPLEX,
  57. /** Quadruplex / 1/4 Duty cycle (segments can be multiplexed with LCD_COM[0:3]) */
  58. lcdMuxQuadruplex = LCD_DISPCTRL_MUX_QUADRUPLEX
  59. } LCD_Mux_TypeDef;
  60. /** Bias setting */
  61. typedef enum
  62. {
  63. /** Static (2 levels) */
  64. lcdBiasStatic = LCD_DISPCTRL_BIAS_STATIC,
  65. /** 1/2 Bias (3 levels) */
  66. lcdBiasOneHalf = LCD_DISPCTRL_BIAS_ONEHALF,
  67. /** 1/3 Bias (4 levels) */
  68. lcdBiasOneThird = LCD_DISPCTRL_BIAS_ONETHIRD
  69. } LCD_Bias_TypeDef;
  70. /** Wave type */
  71. typedef enum
  72. {
  73. /** Low power optimized waveform output */
  74. lcdWaveLowPower = LCD_DISPCTRL_WAVE_LOWPOWER,
  75. /** Regular waveform output */
  76. lcdWaveNormal = LCD_DISPCTRL_WAVE_NORMAL
  77. } LCD_Wave_TypeDef;
  78. /** VLCD Voltage Source */
  79. typedef enum
  80. {
  81. /** VLCD Powered by VDD */
  82. lcdVLCDSelVDD = LCD_DISPCTRL_VLCDSEL_VDD,
  83. /** VLCD Powered by external VDD / Voltage Boost */
  84. lcdVLCDSelVExtBoost = LCD_DISPCTRL_VLCDSEL_VEXTBOOST
  85. } LCD_VLCDSel_TypeDef;
  86. /** Contrast Configuration */
  87. typedef enum
  88. {
  89. /** Contrast is adjusted relative to VDD (VLCD) */
  90. lcdConConfVLCD = LCD_DISPCTRL_CONCONF_VLCD,
  91. /** Contrast is adjusted relative to Ground */
  92. lcdConConfGND = LCD_DISPCTRL_CONCONF_GND
  93. } LCD_ConConf_TypeDef;
  94. /** Voltage Boost Level - Datasheets document setting for each part number */
  95. typedef enum
  96. {
  97. lcdVBoostLevel0 = LCD_DISPCTRL_VBLEV_LEVEL0, /**< Voltage boost LEVEL0 */
  98. lcdVBoostLevel1 = LCD_DISPCTRL_VBLEV_LEVEL1, /**< Voltage boost LEVEL1 */
  99. lcdVBoostLevel2 = LCD_DISPCTRL_VBLEV_LEVEL2, /**< Voltage boost LEVEL2 */
  100. lcdVBoostLevel3 = LCD_DISPCTRL_VBLEV_LEVEL3, /**< Voltage boost LEVEL3 */
  101. lcdVBoostLevel4 = LCD_DISPCTRL_VBLEV_LEVEL4, /**< Voltage boost LEVEL4 */
  102. lcdVBoostLevel5 = LCD_DISPCTRL_VBLEV_LEVEL5, /**< Voltage boost LEVEL5 */
  103. lcdVBoostLevel6 = LCD_DISPCTRL_VBLEV_LEVEL6, /**< Voltage boost LEVEL6 */
  104. lcdVBoostLevel7 = LCD_DISPCTRL_VBLEV_LEVEL7 /**< Voltage boost LEVEL7 */
  105. } LCD_VBoostLevel_TypeDef;
  106. /** Frame Counter Clock Prescaler, FC-CLK = FrameRate (Hz) / this factor */
  107. typedef enum
  108. {
  109. /** Prescale Div 1 */
  110. lcdFCPrescDiv1 = LCD_BACTRL_FCPRESC_DIV1,
  111. /** Prescale Div 2 */
  112. lcdFCPrescDiv2 = LCD_BACTRL_FCPRESC_DIV2,
  113. /** Prescale Div 4 */
  114. lcdFCPrescDiv4 = LCD_BACTRL_FCPRESC_DIV4,
  115. /** Prescale Div 8 */
  116. lcdFCPrescDiv8 = LCD_BACTRL_FCPRESC_DIV8
  117. } LCD_FCPreScale_TypeDef;
  118. /** Segment selection */
  119. typedef enum
  120. {
  121. /** Select segment lines 0 to 3 */
  122. lcdSegment0_3 = (1 << 0),
  123. /** Select segment lines 4 to 7 */
  124. lcdSegment4_7 = (1 << 1),
  125. /** Select segment lines 8 to 11 */
  126. lcdSegment8_11 = (1 << 2),
  127. /** Select segment lines 12 to 15 */
  128. lcdSegment12_15 = (1 << 3),
  129. /** Select segment lines 16 to 19 */
  130. lcdSegment16_19 = (1 << 4),
  131. /** Select segment lines 20 to 23 */
  132. lcdSegment20_23 = (1 << 5),
  133. /** Select segment lines 24 to 27 */
  134. lcdSegment24_27 = (1 << 6),
  135. /** Select segment lines 28 to 31 */
  136. lcdSegment28_31 = (1 << 7),
  137. /** Select segment lines 32 to 35 */
  138. lcdSegment32_35 = (1 << 8),
  139. /** Select segment lines 36 to 39 */
  140. lcdSegment36_39 = (1 << 9),
  141. /** Select all segment lines */
  142. lcdSegmentAll = (0x3ff)
  143. } LCD_SegmentRange_TypeDef;
  144. /** Update Data Control */
  145. typedef enum
  146. {
  147. /** Regular update, data transfer done immediately */
  148. lcdUpdateCtrlRegular = LCD_CTRL_UDCTRL_REGULAR,
  149. /** Data transfer done at Frame Counter event */
  150. lcdUpdateCtrlFCEvent = LCD_CTRL_UDCTRL_FCEVENT,
  151. /** Data transfer done at Frame Start */
  152. lcdUpdateCtrlFrameStart = LCD_CTRL_UDCTRL_FRAMESTART
  153. } LCD_UpdateCtrl_TypeDef;
  154. /** Animation Shift operation; none, left or right */
  155. typedef enum
  156. {
  157. /** No shift */
  158. lcdAnimShiftNone = _LCD_BACTRL_AREGASC_NOSHIFT,
  159. /** Shift segment bits left */
  160. lcdAnimShiftLeft = _LCD_BACTRL_AREGASC_SHIFTLEFT,
  161. /** Shift segment bits right */
  162. lcdAnimShiftRight = _LCD_BACTRL_AREGASC_SHIFTRIGHT
  163. } LCD_AnimShift_TypeDef;
  164. /** Animation Logic Control, how AReg and BReg should be combined */
  165. typedef enum
  166. {
  167. /** Use logical AND to mix animation register A (AREGA) and B (AREGB) */
  168. lcdAnimLogicAnd = LCD_BACTRL_ALOGSEL_AND,
  169. /** Use logical OR to mix animation register A (AREGA) and B (AREGB) */
  170. lcdAnimLogicOr = LCD_BACTRL_ALOGSEL_OR
  171. } LCD_AnimLogic_TypeDef;
  172. /*******************************************************************************
  173. ******************************* STRUCTS ***********************************
  174. ******************************************************************************/
  175. /** LCD Animation Configuration */
  176. typedef struct
  177. {
  178. /** Enable Animation at end of initialization */
  179. bool enable;
  180. /** Initial Animation Register A Value */
  181. uint32_t AReg;
  182. /** Shift operation of Animation Register A */
  183. LCD_AnimShift_TypeDef AShift;
  184. /** Initial Animation Register B Value */
  185. uint32_t BReg;
  186. /** Shift operation of Animation Register B */
  187. LCD_AnimShift_TypeDef BShift;
  188. /** A and B Logical Operation to use for mixing and outputting resulting segments */
  189. LCD_AnimLogic_TypeDef animLogic;
  190. } LCD_AnimInit_TypeDef;
  191. /** LCD Frame Control Initialization */
  192. typedef struct
  193. {
  194. /** Enable at end */
  195. bool enable;
  196. /** Frame Counter top value */
  197. uint32_t top;
  198. /** Frame Counter clock prescaler */
  199. LCD_FCPreScale_TypeDef prescale;
  200. } LCD_FrameCountInit_TypeDef;
  201. /** LCD Controller Initialization structure */
  202. typedef struct
  203. {
  204. /** Enable controller at end of initialization */
  205. bool enable;
  206. /** Mux configuration */
  207. LCD_Mux_TypeDef mux;
  208. /** Bias configuration */
  209. LCD_Bias_TypeDef bias;
  210. /** Wave configuration */
  211. LCD_Wave_TypeDef wave;
  212. /** VLCD Select */
  213. LCD_VLCDSel_TypeDef vlcd;
  214. /** Contrast Configuration */
  215. LCD_ConConf_TypeDef contrast;
  216. } LCD_Init_TypeDef;
  217. /** Default config for LCD init structure, enables all 160 segments */
  218. #define LCD_INIT_DEFAULT \
  219. { true, \
  220. lcdMuxQuadruplex, \
  221. lcdBiasOneThird, \
  222. lcdWaveLowPower, \
  223. lcdVLCDSelVDD, \
  224. lcdConConfVLCD \
  225. }
  226. /*******************************************************************************
  227. ***************************** PROTOTYPES **********************************
  228. ******************************************************************************/
  229. void LCD_Init(const LCD_Init_TypeDef *lcdInit);
  230. void LCD_VLCDSelect(LCD_VLCDSel_TypeDef vlcd);
  231. void LCD_UpdateCtrl(LCD_UpdateCtrl_TypeDef ud);
  232. void LCD_FrameCountInit(const LCD_FrameCountInit_TypeDef *fcInit);
  233. void LCD_AnimInit(const LCD_AnimInit_TypeDef *animInit);
  234. void LCD_SegmentRangeEnable(LCD_SegmentRange_TypeDef segment, bool enable);
  235. void LCD_SegmentSet(int com, int bit, bool enable);
  236. void LCD_SegmentSetLow(int com, uint32_t mask, uint32_t bits);
  237. void LCD_SegmentSetHigh(int com, uint32_t mask, uint32_t bits);
  238. void LCD_ContrastSet(int level);
  239. void LCD_VBoostSet(LCD_VBoostLevel_TypeDef vboost);
  240. /***************************************************************************//**
  241. * @brief
  242. * Enable or disable LCD controller
  243. *
  244. * @param[in] enable
  245. * If true, enables LCD controller with current configuration, if false
  246. * disables LCD controller. CMU clock for LCD must be enabled for correct
  247. * operation.
  248. ******************************************************************************/
  249. static __INLINE void LCD_Enable(bool enable)
  250. {
  251. if (enable)
  252. {
  253. LCD->CTRL |= LCD_CTRL_EN;
  254. }
  255. else
  256. {
  257. LCD->CTRL &= ~(LCD_CTRL_EN);
  258. }
  259. }
  260. /***************************************************************************//**
  261. * @brief
  262. * Enables or disables LCD Animation feature
  263. *
  264. * @param[in] enable
  265. * Boolean true enables animation, false disables animation
  266. ******************************************************************************/
  267. static __INLINE void LCD_AnimEnable(bool enable)
  268. {
  269. if (enable)
  270. {
  271. LCD->BACTRL |= LCD_BACTRL_AEN;
  272. }
  273. else
  274. {
  275. LCD->BACTRL &= ~(LCD_BACTRL_AEN);
  276. }
  277. }
  278. /***************************************************************************//**
  279. * @brief
  280. * Enables or disables LCD blink
  281. *
  282. * @param[in] enable
  283. * Boolean true enables blink, false disables blink
  284. ******************************************************************************/
  285. static __INLINE void LCD_BlinkEnable(bool enable)
  286. {
  287. if (enable)
  288. {
  289. LCD->BACTRL |= LCD_BACTRL_BLINKEN;
  290. }
  291. else
  292. {
  293. LCD->BACTRL &= ~(LCD_BACTRL_BLINKEN);
  294. }
  295. }
  296. /***************************************************************************//**
  297. * @brief
  298. * Disables all segments, while keeping segment state
  299. *
  300. * @param[in] enable
  301. * Boolean true clears all segments, boolean false restores all segment lines
  302. ******************************************************************************/
  303. static __INLINE void LCD_BlankEnable(bool enable)
  304. {
  305. if (enable)
  306. {
  307. LCD->BACTRL |= LCD_BACTRL_BLANK;
  308. }
  309. else
  310. {
  311. LCD->BACTRL &= ~(LCD_BACTRL_BLANK);
  312. }
  313. }
  314. /***************************************************************************//**
  315. * @brief
  316. * Enables or disables LCD Frame Control
  317. *
  318. * @param[in] enable
  319. * Boolean true enables frame counter, false disables frame counter
  320. ******************************************************************************/
  321. static __INLINE void LCD_FrameCountEnable(bool enable)
  322. {
  323. if (enable)
  324. {
  325. LCD->BACTRL |= LCD_BACTRL_FCEN;
  326. }
  327. else
  328. {
  329. LCD->BACTRL &= ~(LCD_BACTRL_FCEN);
  330. }
  331. }
  332. /***************************************************************************//**
  333. * @brief
  334. * Returns current animation state
  335. *
  336. * @return
  337. * Animation state, in range 0-15
  338. ******************************************************************************/
  339. static __INLINE int LCD_AnimState(void)
  340. {
  341. return (int)(LCD->STATUS & _LCD_STATUS_ASTATE_MASK) >> _LCD_STATUS_ASTATE_SHIFT;
  342. }
  343. /***************************************************************************//**
  344. * @brief
  345. * Returns current blink state
  346. *
  347. * @return
  348. * Return value is 1 if segments are enabled, 0 if disabled
  349. ******************************************************************************/
  350. static __INLINE int LCD_BlinkState(void)
  351. {
  352. return (int)(LCD->STATUS & _LCD_STATUS_BLINK_MASK) >> _LCD_STATUS_BLINK_SHIFT;
  353. }
  354. /***************************************************************************//**
  355. * @brief
  356. * When set, LCD registers will not be updated until cleared,
  357. *
  358. * @param[in] enable
  359. * When enable is true, update is stopped, when false all registers are
  360. * updated
  361. ******************************************************************************/
  362. static __INLINE void LCD_FreezeEnable(bool enable)
  363. {
  364. if (enable)
  365. {
  366. LCD->FREEZE = LCD_FREEZE_REGFREEZE_FREEZE;
  367. }
  368. else
  369. {
  370. LCD->FREEZE = LCD_FREEZE_REGFREEZE_UPDATE;
  371. }
  372. }
  373. /***************************************************************************//**
  374. * @brief
  375. * Returns SYNCBUSY bits, indicating which registers have pending updates
  376. *
  377. * @return
  378. * Bit fields for LCD registers which have pending updates
  379. ******************************************************************************/
  380. static __INLINE uint32_t LCD_SyncBusyGet(void)
  381. {
  382. return(LCD->SYNCBUSY);
  383. }
  384. /***************************************************************************//**
  385. * @brief
  386. * Polls LCD SYNCBUSY flags, until flag has been cleared
  387. *
  388. * @param[in] flags
  389. * Bit fields for LCD registers that shall be updated before we continue
  390. ******************************************************************************/
  391. static __INLINE void LCD_SyncBusyDelay(uint32_t flags)
  392. {
  393. while (LCD->SYNCBUSY & flags) ;
  394. }
  395. /***************************************************************************//**
  396. * @brief
  397. * Get pending LCD interrupt flags
  398. *
  399. * @return
  400. * Pending LCD interrupts, which need to be cleared.
  401. ******************************************************************************/
  402. static __INLINE uint32_t LCD_IntGet(void)
  403. {
  404. return(LCD->IF);
  405. }
  406. /***************************************************************************//**
  407. * @brief
  408. * Set one or more pending LCD interrupts from SW.
  409. *
  410. * @param[in] flags
  411. * Bit field for interrupts to set
  412. ******************************************************************************/
  413. static __INLINE void LCD_IntSet(uint32_t flags)
  414. {
  415. LCD->IFS = flags;
  416. }
  417. /***************************************************************************//**
  418. * @brief
  419. * Enable LCD (Frame Counter) interrupt
  420. *
  421. * @param[in] flags
  422. * LCD_IF_FC, which is the only supported interrupt for the LCD controller
  423. ******************************************************************************/
  424. static __INLINE void LCD_IntEnable(uint32_t flags)
  425. {
  426. LCD->IEN |= flags;
  427. }
  428. /***************************************************************************//**
  429. * @brief
  430. * Disable LCD (Frame Counter) interrupt
  431. *
  432. * @param[in] flags
  433. * LCD_IF_FC, which is the only supported interrupt for the LCD controller
  434. ******************************************************************************/
  435. static __INLINE void LCD_IntDisable(uint32_t flags)
  436. {
  437. LCD->IEN &= ~(flags);
  438. }
  439. /***************************************************************************//**
  440. * @brief
  441. * Clear one or more interrupt flags
  442. *
  443. * @param[in] flags
  444. * LCD_IF_FC, which is the only supported interrupt for the LCD controller
  445. ******************************************************************************/
  446. static __INLINE void LCD_IntClear(uint32_t flags)
  447. {
  448. LCD->IFC = flags;
  449. }
  450. /** @} (end addtogroup LCD) */
  451. /** @} (end addtogroup EFM32_Library) */
  452. #ifdef __cplusplus
  453. }
  454. #endif
  455. #endif /* defined(LCD_COUNT) && (LCD_COUNT > 0) */
  456. #endif /* __EFM32_LCD_H */