EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
em_lcd.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_LCD_H
34 #define EM_LCD_H
35 
36 #include "em_device.h"
37 
38 #if defined(LCD_COUNT) && (LCD_COUNT > 0)
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
56 /*******************************************************************************
57  ******************************** ENUMS ************************************
58  ******************************************************************************/
59 
61 typedef enum
62 {
64  lcdMuxStatic = LCD_DISPCTRL_MUX_STATIC,
66  lcdMuxDuplex = LCD_DISPCTRL_MUX_DUPLEX,
68  lcdMuxTriplex = LCD_DISPCTRL_MUX_TRIPLEX,
70  lcdMuxQuadruplex = LCD_DISPCTRL_MUX_QUADRUPLEX,
71 #if defined(LCD_DISPCTRL_MUXE_MUXE)
72 
73  lcdMuxSextaplex = LCD_DISPCTRL_MUXE_MUXE | LCD_DISPCTRL_MUX_DUPLEX,
75  lcdMuxOctaplex = LCD_DISPCTRL_MUXE_MUXE | LCD_DISPCTRL_MUX_QUADRUPLEX
76 #endif
77 } LCD_Mux_TypeDef;
78 
80 typedef enum
81 {
83  lcdBiasStatic = LCD_DISPCTRL_BIAS_STATIC,
85  lcdBiasOneHalf = LCD_DISPCTRL_BIAS_ONEHALF,
87  lcdBiasOneThird = LCD_DISPCTRL_BIAS_ONETHIRD,
88 #if defined(LCD_DISPCTRL_BIAS_ONEFOURTH)
89 
90  lcdBiasOneFourth = LCD_DISPCTRL_BIAS_ONEFOURTH,
91 #endif
92 } LCD_Bias_TypeDef;
93 
95 typedef enum
96 {
98  lcdWaveLowPower = LCD_DISPCTRL_WAVE_LOWPOWER,
100  lcdWaveNormal = LCD_DISPCTRL_WAVE_NORMAL
101 } LCD_Wave_TypeDef;
102 
104 typedef enum
105 {
107  lcdVLCDSelVDD = LCD_DISPCTRL_VLCDSEL_VDD,
109  lcdVLCDSelVExtBoost = LCD_DISPCTRL_VLCDSEL_VEXTBOOST
110 } LCD_VLCDSel_TypeDef;
111 
113 typedef enum
114 {
116  lcdConConfVLCD = LCD_DISPCTRL_CONCONF_VLCD,
118  lcdConConfGND = LCD_DISPCTRL_CONCONF_GND
119 } LCD_ConConf_TypeDef;
120 
122 typedef enum
123 {
124  lcdVBoostLevel0 = LCD_DISPCTRL_VBLEV_LEVEL0,
125  lcdVBoostLevel1 = LCD_DISPCTRL_VBLEV_LEVEL1,
126  lcdVBoostLevel2 = LCD_DISPCTRL_VBLEV_LEVEL2,
127  lcdVBoostLevel3 = LCD_DISPCTRL_VBLEV_LEVEL3,
128  lcdVBoostLevel4 = LCD_DISPCTRL_VBLEV_LEVEL4,
129  lcdVBoostLevel5 = LCD_DISPCTRL_VBLEV_LEVEL5,
130  lcdVBoostLevel6 = LCD_DISPCTRL_VBLEV_LEVEL6,
131  lcdVBoostLevel7 = LCD_DISPCTRL_VBLEV_LEVEL7
132 } LCD_VBoostLevel_TypeDef;
133 
135 typedef enum
136 {
138  lcdFCPrescDiv1 = LCD_BACTRL_FCPRESC_DIV1,
140  lcdFCPrescDiv2 = LCD_BACTRL_FCPRESC_DIV2,
142  lcdFCPrescDiv4 = LCD_BACTRL_FCPRESC_DIV4,
144  lcdFCPrescDiv8 = LCD_BACTRL_FCPRESC_DIV8
145 } LCD_FCPreScale_TypeDef;
146 
148 typedef enum
149 {
151  lcdSegment0_3 = (1 << 0),
153  lcdSegment4_7 = (1 << 1),
155  lcdSegment8_11 = (1 << 2),
157  lcdSegment12_15 = (1 << 3),
159  lcdSegment16_19 = (1 << 4),
161  lcdSegment20_23 = (1 << 5),
162 #if defined(_LCD_SEGD0L_MASK) && (_LCD_SEGD0L_MASK == 0x00FFFFFFUL)
163 
164  lcdSegmentAll = (0x003f)
165 #elif defined(_LCD_SEGD0H_MASK) && (_LCD_SEGD0H_MASK == 0x000000FFUL)
167  lcdSegment24_27 = (1 << 6),
169  lcdSegment28_31 = (1 << 7),
171  lcdSegment32_35 = (1 << 8),
173  lcdSegment36_39 = (1 << 9),
175  lcdSegmentAll = (0x03ff)
176 #endif
177 } LCD_SegmentRange_TypeDef;
178 
180 typedef enum
181 {
183  lcdUpdateCtrlRegular = LCD_CTRL_UDCTRL_REGULAR,
185  lcdUpdateCtrlFCEvent = LCD_CTRL_UDCTRL_FCEVENT,
187  lcdUpdateCtrlFrameStart = LCD_CTRL_UDCTRL_FRAMESTART
188 } LCD_UpdateCtrl_TypeDef;
189 
191 typedef enum
192 {
194  lcdAnimShiftNone = _LCD_BACTRL_AREGASC_NOSHIFT,
196  lcdAnimShiftLeft = _LCD_BACTRL_AREGASC_SHIFTLEFT,
198  lcdAnimShiftRight = _LCD_BACTRL_AREGASC_SHIFTRIGHT
199 } LCD_AnimShift_TypeDef;
200 
202 typedef enum
203 {
205  lcdAnimLogicAnd = LCD_BACTRL_ALOGSEL_AND,
207  lcdAnimLogicOr = LCD_BACTRL_ALOGSEL_OR
208 } LCD_AnimLogic_TypeDef;
209 
210 
211 /*******************************************************************************
212  ******************************* STRUCTS ***********************************
213  ******************************************************************************/
214 
216 typedef struct
217 {
219  bool enable;
221  uint32_t AReg;
223  LCD_AnimShift_TypeDef AShift;
225  uint32_t BReg;
227  LCD_AnimShift_TypeDef BShift;
229  LCD_AnimLogic_TypeDef animLogic;
230 #if defined(LCD_BACTRL_ALOC)
231 
232  int startSeg;
233 #endif
234 } LCD_AnimInit_TypeDef;
235 
237 typedef struct
238 {
240  bool enable;
242  uint32_t top;
244  LCD_FCPreScale_TypeDef prescale;
245 } LCD_FrameCountInit_TypeDef;
246 
248 typedef struct
249 {
251  bool enable;
253  LCD_Mux_TypeDef mux;
255  LCD_Bias_TypeDef bias;
257  LCD_Wave_TypeDef wave;
259  LCD_VLCDSel_TypeDef vlcd;
261  LCD_ConConf_TypeDef contrast;
262 } LCD_Init_TypeDef;
263 
265 #define LCD_INIT_DEFAULT \
266 { \
267  true, \
268  lcdMuxQuadruplex, \
269  lcdBiasOneThird, \
270  lcdWaveLowPower, \
271  lcdVLCDSelVDD, \
272  lcdConConfVLCD \
273 }
274 
275 /*******************************************************************************
276  ***************************** PROTOTYPES **********************************
277  ******************************************************************************/
278 
279 void LCD_Init(const LCD_Init_TypeDef *lcdInit);
280 void LCD_VLCDSelect(LCD_VLCDSel_TypeDef vlcd);
281 void LCD_UpdateCtrl(LCD_UpdateCtrl_TypeDef ud);
282 void LCD_FrameCountInit(const LCD_FrameCountInit_TypeDef *fcInit);
283 void LCD_AnimInit(const LCD_AnimInit_TypeDef *animInit);
284 
285 void LCD_SegmentRangeEnable(LCD_SegmentRange_TypeDef segment, bool enable);
286 void LCD_SegmentSet(int com, int bit, bool enable);
287 void LCD_SegmentSetLow(int com, uint32_t mask, uint32_t bits);
288 #if defined(_LCD_SEGD0H_MASK)
289 void LCD_SegmentSetHigh(int com, uint32_t mask, uint32_t bits);
290 #endif
291 void LCD_ContrastSet(int level);
292 void LCD_VBoostSet(LCD_VBoostLevel_TypeDef vboost);
293 
294 #if defined(LCD_CTRL_DSC)
295 void LCD_BiasSegmentSet(int segment, int biasLevel);
296 void LCD_BiasComSet(int com, int biasLevel);
297 #endif
298 
299 /***************************************************************************/
308 __STATIC_INLINE void LCD_Enable(bool enable)
309 {
310  if (enable)
311  {
312  LCD->CTRL |= LCD_CTRL_EN;
313  }
314  else
315  {
316  LCD->CTRL &= ~LCD_CTRL_EN;
317  }
318 }
319 
320 
321 /***************************************************************************/
328 __STATIC_INLINE void LCD_AnimEnable(bool enable)
329 {
330  if (enable)
331  {
332  LCD->BACTRL |= LCD_BACTRL_AEN;
333  }
334  else
335  {
336  LCD->BACTRL &= ~LCD_BACTRL_AEN;
337  }
338 }
339 
340 
341 /***************************************************************************/
348 __STATIC_INLINE void LCD_BlinkEnable(bool enable)
349 {
350  if (enable)
351  {
352  LCD->BACTRL |= LCD_BACTRL_BLINKEN;
353  }
354  else
355  {
356  LCD->BACTRL &= ~LCD_BACTRL_BLINKEN;
357  }
358 }
359 
360 
361 /***************************************************************************/
368 __STATIC_INLINE void LCD_BlankEnable(bool enable)
369 {
370  if (enable)
371  {
372  LCD->BACTRL |= LCD_BACTRL_BLANK;
373  }
374  else
375  {
376  LCD->BACTRL &= ~LCD_BACTRL_BLANK;
377  }
378 }
379 
380 
381 /***************************************************************************/
388 __STATIC_INLINE void LCD_FrameCountEnable(bool enable)
389 {
390  if (enable)
391  {
392  LCD->BACTRL |= LCD_BACTRL_FCEN;
393  }
394  else
395  {
396  LCD->BACTRL &= ~LCD_BACTRL_FCEN;
397  }
398 }
399 
400 
401 /***************************************************************************/
408 __STATIC_INLINE int LCD_AnimState(void)
409 {
410  return (int)(LCD->STATUS & _LCD_STATUS_ASTATE_MASK) >> _LCD_STATUS_ASTATE_SHIFT;
411 }
412 
413 
414 /***************************************************************************/
421 __STATIC_INLINE int LCD_BlinkState(void)
422 {
423  return (int)(LCD->STATUS & _LCD_STATUS_BLINK_MASK) >> _LCD_STATUS_BLINK_SHIFT;
424 }
425 
426 
427 /***************************************************************************/
435 __STATIC_INLINE void LCD_FreezeEnable(bool enable)
436 {
437  if (enable)
438  {
439  LCD->FREEZE = LCD_FREEZE_REGFREEZE_FREEZE;
440  }
441  else
442  {
443  LCD->FREEZE = LCD_FREEZE_REGFREEZE_UPDATE;
444  }
445 }
446 
447 
448 /***************************************************************************/
455 __STATIC_INLINE uint32_t LCD_SyncBusyGet(void)
456 {
457  return LCD->SYNCBUSY;
458 }
459 
460 
461 /***************************************************************************/
468 __STATIC_INLINE void LCD_SyncBusyDelay(uint32_t flags)
469 {
470  while (LCD->SYNCBUSY & flags)
471  ;
472 }
473 
474 
475 /***************************************************************************/
483 __STATIC_INLINE uint32_t LCD_IntGet(void)
484 {
485  return LCD->IF;
486 }
487 
488 
489 /***************************************************************************/
507 __STATIC_INLINE uint32_t LCD_IntGetEnabled(void)
508 {
509  uint32_t ien;
510 
511  /* Store LCD->IEN in temporary variable in order to define explicit order
512  * of volatile accesses. */
513  ien = LCD->IEN;
514 
515  /* Bitwise AND of pending and enabled interrupts */
516  return LCD->IF & ien;
517 }
518 
519 
520 /***************************************************************************/
529 __STATIC_INLINE void LCD_IntSet(uint32_t flags)
530 {
531  LCD->IFS = flags;
532 }
533 
534 
535 /***************************************************************************/
544 __STATIC_INLINE void LCD_IntEnable(uint32_t flags)
545 {
546  LCD->IEN |= flags;
547 }
548 
549 
550 /***************************************************************************/
559 __STATIC_INLINE void LCD_IntDisable(uint32_t flags)
560 {
561  LCD->IEN &= ~flags;
562 }
563 
564 
565 /***************************************************************************/
574 __STATIC_INLINE void LCD_IntClear(uint32_t flags)
575 {
576  LCD->IFC = flags;
577 }
578 
579 
580 #if defined(LCD_CTRL_DSC)
581 /***************************************************************************/
590 __STATIC_INLINE void LCD_DSCEnable(bool enable)
591 {
592  if (enable)
593  {
594  LCD->CTRL |= LCD_CTRL_DSC;
595  }
596  else
597  {
598  LCD->CTRL &= ~LCD_CTRL_DSC;
599  }
600 }
601 #endif
602 
606 #ifdef __cplusplus
607 }
608 #endif
609 
610 #endif /* defined(LCD_COUNT) && (LCD_COUNT > 0) */
611 
612 #endif /* EM_LCD_H */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.