123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- /***************************************************************************//**
- * @file
- * @brief Liquid Crystal Display (LCD) peripheral API for EFM32
- * @author Energy Micro AS
- * @version 1.3.0
- *******************************************************************************
- * @section License
- * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
- *******************************************************************************
- *
- * This source code is the property of Energy Micro AS. The source and compiled
- * code may only be used on Energy Micro "EFM32" microcontrollers.
- *
- * This copyright notice may not be removed from the source code nor changed.
- *
- * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
- * obligation to support this Software. Energy Micro AS is providing the
- * Software "AS IS", with no express or implied warranties of any kind,
- * including, but not limited to, any implied warranties of merchantability
- * or fitness for any particular purpose or warranties against infringement
- * of any proprietary rights of a third party.
- *
- * Energy Micro AS will not be liable for any consequential, incidental, or
- * special damages, or any other relief, or for any claim by any third party,
- * arising from your use of this Software.
- *
- ******************************************************************************/
- #ifndef __EFM32_LCD_H
- #define __EFM32_LCD_H
- #include "efm32.h"
- #if defined(LCD_COUNT) && (LCD_COUNT > 0)
- #include <stdint.h>
- #include <stdbool.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /***************************************************************************//**
- * @addtogroup EFM32_Library
- * @{
- ******************************************************************************/
- /***************************************************************************//**
- * @addtogroup LCD
- * @{
- ******************************************************************************/
- /*******************************************************************************
- ******************************** ENUMS ************************************
- ******************************************************************************/
- /** MUX setting */
- typedef enum
- {
- /** Static (segments can be multiplexed with LCD_COM[0]) */
- lcdMuxStatic = LCD_DISPCTRL_MUX_STATIC,
- /** Duplex / 1/2 Duty cycle (segments can be multiplexed with LCD_COM[0:1]) */
- lcdMuxDuplex = LCD_DISPCTRL_MUX_DUPLEX,
- /** Triplex / 1/3 Duty cycle (segments can be multiplexed with LCD_COM[0:2]) */
- lcdMuxTriplex = LCD_DISPCTRL_MUX_TRIPLEX,
- /** Quadruplex / 1/4 Duty cycle (segments can be multiplexed with LCD_COM[0:3]) */
- lcdMuxQuadruplex = LCD_DISPCTRL_MUX_QUADRUPLEX
- } LCD_Mux_TypeDef;
- /** Bias setting */
- typedef enum
- {
- /** Static (2 levels) */
- lcdBiasStatic = LCD_DISPCTRL_BIAS_STATIC,
- /** 1/2 Bias (3 levels) */
- lcdBiasOneHalf = LCD_DISPCTRL_BIAS_ONEHALF,
- /** 1/3 Bias (4 levels) */
- lcdBiasOneThird = LCD_DISPCTRL_BIAS_ONETHIRD
- } LCD_Bias_TypeDef;
- /** Wave type */
- typedef enum
- {
- /** Low power optimized waveform output */
- lcdWaveLowPower = LCD_DISPCTRL_WAVE_LOWPOWER,
- /** Regular waveform output */
- lcdWaveNormal = LCD_DISPCTRL_WAVE_NORMAL
- } LCD_Wave_TypeDef;
- /** VLCD Voltage Source */
- typedef enum
- {
- /** VLCD Powered by VDD */
- lcdVLCDSelVDD = LCD_DISPCTRL_VLCDSEL_VDD,
- /** VLCD Powered by external VDD / Voltage Boost */
- lcdVLCDSelVExtBoost = LCD_DISPCTRL_VLCDSEL_VEXTBOOST
- } LCD_VLCDSel_TypeDef;
- /** Contrast Configuration */
- typedef enum
- {
- /** Contrast is adjusted relative to VDD (VLCD) */
- lcdConConfVLCD = LCD_DISPCTRL_CONCONF_VLCD,
- /** Contrast is adjusted relative to Ground */
- lcdConConfGND = LCD_DISPCTRL_CONCONF_GND
- } LCD_ConConf_TypeDef;
- /** Voltage Boost Level - Datasheets document setting for each part number */
- typedef enum
- {
- lcdVBoostLevel0 = LCD_DISPCTRL_VBLEV_LEVEL0, /**< Voltage boost LEVEL0 */
- lcdVBoostLevel1 = LCD_DISPCTRL_VBLEV_LEVEL1, /**< Voltage boost LEVEL1 */
- lcdVBoostLevel2 = LCD_DISPCTRL_VBLEV_LEVEL2, /**< Voltage boost LEVEL2 */
- lcdVBoostLevel3 = LCD_DISPCTRL_VBLEV_LEVEL3, /**< Voltage boost LEVEL3 */
- lcdVBoostLevel4 = LCD_DISPCTRL_VBLEV_LEVEL4, /**< Voltage boost LEVEL4 */
- lcdVBoostLevel5 = LCD_DISPCTRL_VBLEV_LEVEL5, /**< Voltage boost LEVEL5 */
- lcdVBoostLevel6 = LCD_DISPCTRL_VBLEV_LEVEL6, /**< Voltage boost LEVEL6 */
- lcdVBoostLevel7 = LCD_DISPCTRL_VBLEV_LEVEL7 /**< Voltage boost LEVEL7 */
- } LCD_VBoostLevel_TypeDef;
- /** Frame Counter Clock Prescaler, FC-CLK = FrameRate (Hz) / this factor */
- typedef enum
- {
- /** Prescale Div 1 */
- lcdFCPrescDiv1 = LCD_BACTRL_FCPRESC_DIV1,
- /** Prescale Div 2 */
- lcdFCPrescDiv2 = LCD_BACTRL_FCPRESC_DIV2,
- /** Prescale Div 4 */
- lcdFCPrescDiv4 = LCD_BACTRL_FCPRESC_DIV4,
- /** Prescale Div 8 */
- lcdFCPrescDiv8 = LCD_BACTRL_FCPRESC_DIV8
- } LCD_FCPreScale_TypeDef;
- /** Segment selection */
- typedef enum
- {
- /** Select segment lines 0 to 3 */
- lcdSegment0_3 = (1 << 0),
- /** Select segment lines 4 to 7 */
- lcdSegment4_7 = (1 << 1),
- /** Select segment lines 8 to 11 */
- lcdSegment8_11 = (1 << 2),
- /** Select segment lines 12 to 15 */
- lcdSegment12_15 = (1 << 3),
- /** Select segment lines 16 to 19 */
- lcdSegment16_19 = (1 << 4),
- /** Select segment lines 20 to 23 */
- lcdSegment20_23 = (1 << 5),
- /** Select segment lines 24 to 27 */
- lcdSegment24_27 = (1 << 6),
- /** Select segment lines 28 to 31 */
- lcdSegment28_31 = (1 << 7),
- /** Select segment lines 32 to 35 */
- lcdSegment32_35 = (1 << 8),
- /** Select segment lines 36 to 39 */
- lcdSegment36_39 = (1 << 9),
- /** Select all segment lines */
- lcdSegmentAll = (0x3ff)
- } LCD_SegmentRange_TypeDef;
- /** Update Data Control */
- typedef enum
- {
- /** Regular update, data transfer done immediately */
- lcdUpdateCtrlRegular = LCD_CTRL_UDCTRL_REGULAR,
- /** Data transfer done at Frame Counter event */
- lcdUpdateCtrlFCEvent = LCD_CTRL_UDCTRL_FCEVENT,
- /** Data transfer done at Frame Start */
- lcdUpdateCtrlFrameStart = LCD_CTRL_UDCTRL_FRAMESTART
- } LCD_UpdateCtrl_TypeDef;
- /** Animation Shift operation; none, left or right */
- typedef enum
- {
- /** No shift */
- lcdAnimShiftNone = _LCD_BACTRL_AREGASC_NOSHIFT,
- /** Shift segment bits left */
- lcdAnimShiftLeft = _LCD_BACTRL_AREGASC_SHIFTLEFT,
- /** Shift segment bits right */
- lcdAnimShiftRight = _LCD_BACTRL_AREGASC_SHIFTRIGHT
- } LCD_AnimShift_TypeDef;
- /** Animation Logic Control, how AReg and BReg should be combined */
- typedef enum
- {
- /** Use logical AND to mix animation register A (AREGA) and B (AREGB) */
- lcdAnimLogicAnd = LCD_BACTRL_ALOGSEL_AND,
- /** Use logical OR to mix animation register A (AREGA) and B (AREGB) */
- lcdAnimLogicOr = LCD_BACTRL_ALOGSEL_OR
- } LCD_AnimLogic_TypeDef;
- /*******************************************************************************
- ******************************* STRUCTS ***********************************
- ******************************************************************************/
- /** LCD Animation Configuration */
- typedef struct
- {
- /** Enable Animation at end of initialization */
- bool enable;
- /** Initial Animation Register A Value */
- uint32_t AReg;
- /** Shift operation of Animation Register A */
- LCD_AnimShift_TypeDef AShift;
- /** Initial Animation Register B Value */
- uint32_t BReg;
- /** Shift operation of Animation Register B */
- LCD_AnimShift_TypeDef BShift;
- /** A and B Logical Operation to use for mixing and outputting resulting segments */
- LCD_AnimLogic_TypeDef animLogic;
- } LCD_AnimInit_TypeDef;
- /** LCD Frame Control Initialization */
- typedef struct
- {
- /** Enable at end */
- bool enable;
- /** Frame Counter top value */
- uint32_t top;
- /** Frame Counter clock prescaler */
- LCD_FCPreScale_TypeDef prescale;
- } LCD_FrameCountInit_TypeDef;
- /** LCD Controller Initialization structure */
- typedef struct
- {
- /** Enable controller at end of initialization */
- bool enable;
- /** Mux configuration */
- LCD_Mux_TypeDef mux;
- /** Bias configuration */
- LCD_Bias_TypeDef bias;
- /** Wave configuration */
- LCD_Wave_TypeDef wave;
- /** VLCD Select */
- LCD_VLCDSel_TypeDef vlcd;
- /** Contrast Configuration */
- LCD_ConConf_TypeDef contrast;
- } LCD_Init_TypeDef;
- /** Default config for LCD init structure, enables all 160 segments */
- #define LCD_INIT_DEFAULT \
- { true, \
- lcdMuxQuadruplex, \
- lcdBiasOneThird, \
- lcdWaveLowPower, \
- lcdVLCDSelVDD, \
- lcdConConfVLCD \
- }
- /*******************************************************************************
- ***************************** PROTOTYPES **********************************
- ******************************************************************************/
- void LCD_Init(const LCD_Init_TypeDef *lcdInit);
- void LCD_VLCDSelect(LCD_VLCDSel_TypeDef vlcd);
- void LCD_UpdateCtrl(LCD_UpdateCtrl_TypeDef ud);
- void LCD_FrameCountInit(const LCD_FrameCountInit_TypeDef *fcInit);
- void LCD_AnimInit(const LCD_AnimInit_TypeDef *animInit);
- void LCD_SegmentRangeEnable(LCD_SegmentRange_TypeDef segment, bool enable);
- void LCD_SegmentSet(int com, int bit, bool enable);
- void LCD_SegmentSetLow(int com, uint32_t mask, uint32_t bits);
- void LCD_SegmentSetHigh(int com, uint32_t mask, uint32_t bits);
- void LCD_ContrastSet(int level);
- void LCD_VBoostSet(LCD_VBoostLevel_TypeDef vboost);
- /***************************************************************************//**
- * @brief
- * Enable or disable LCD controller
- *
- * @param[in] enable
- * If true, enables LCD controller with current configuration, if false
- * disables LCD controller. CMU clock for LCD must be enabled for correct
- * operation.
- ******************************************************************************/
- static __INLINE void LCD_Enable(bool enable)
- {
- if (enable)
- {
- LCD->CTRL |= LCD_CTRL_EN;
- }
- else
- {
- LCD->CTRL &= ~(LCD_CTRL_EN);
- }
- }
- /***************************************************************************//**
- * @brief
- * Enables or disables LCD Animation feature
- *
- * @param[in] enable
- * Boolean true enables animation, false disables animation
- ******************************************************************************/
- static __INLINE void LCD_AnimEnable(bool enable)
- {
- if (enable)
- {
- LCD->BACTRL |= LCD_BACTRL_AEN;
- }
- else
- {
- LCD->BACTRL &= ~(LCD_BACTRL_AEN);
- }
- }
- /***************************************************************************//**
- * @brief
- * Enables or disables LCD blink
- *
- * @param[in] enable
- * Boolean true enables blink, false disables blink
- ******************************************************************************/
- static __INLINE void LCD_BlinkEnable(bool enable)
- {
- if (enable)
- {
- LCD->BACTRL |= LCD_BACTRL_BLINKEN;
- }
- else
- {
- LCD->BACTRL &= ~(LCD_BACTRL_BLINKEN);
- }
- }
- /***************************************************************************//**
- * @brief
- * Disables all segments, while keeping segment state
- *
- * @param[in] enable
- * Boolean true clears all segments, boolean false restores all segment lines
- ******************************************************************************/
- static __INLINE void LCD_BlankEnable(bool enable)
- {
- if (enable)
- {
- LCD->BACTRL |= LCD_BACTRL_BLANK;
- }
- else
- {
- LCD->BACTRL &= ~(LCD_BACTRL_BLANK);
- }
- }
- /***************************************************************************//**
- * @brief
- * Enables or disables LCD Frame Control
- *
- * @param[in] enable
- * Boolean true enables frame counter, false disables frame counter
- ******************************************************************************/
- static __INLINE void LCD_FrameCountEnable(bool enable)
- {
- if (enable)
- {
- LCD->BACTRL |= LCD_BACTRL_FCEN;
- }
- else
- {
- LCD->BACTRL &= ~(LCD_BACTRL_FCEN);
- }
- }
- /***************************************************************************//**
- * @brief
- * Returns current animation state
- *
- * @return
- * Animation state, in range 0-15
- ******************************************************************************/
- static __INLINE int LCD_AnimState(void)
- {
- return (int)(LCD->STATUS & _LCD_STATUS_ASTATE_MASK) >> _LCD_STATUS_ASTATE_SHIFT;
- }
- /***************************************************************************//**
- * @brief
- * Returns current blink state
- *
- * @return
- * Return value is 1 if segments are enabled, 0 if disabled
- ******************************************************************************/
- static __INLINE int LCD_BlinkState(void)
- {
- return (int)(LCD->STATUS & _LCD_STATUS_BLINK_MASK) >> _LCD_STATUS_BLINK_SHIFT;
- }
- /***************************************************************************//**
- * @brief
- * When set, LCD registers will not be updated until cleared,
- *
- * @param[in] enable
- * When enable is true, update is stopped, when false all registers are
- * updated
- ******************************************************************************/
- static __INLINE void LCD_FreezeEnable(bool enable)
- {
- if (enable)
- {
- LCD->FREEZE = LCD_FREEZE_REGFREEZE_FREEZE;
- }
- else
- {
- LCD->FREEZE = LCD_FREEZE_REGFREEZE_UPDATE;
- }
- }
- /***************************************************************************//**
- * @brief
- * Returns SYNCBUSY bits, indicating which registers have pending updates
- *
- * @return
- * Bit fields for LCD registers which have pending updates
- ******************************************************************************/
- static __INLINE uint32_t LCD_SyncBusyGet(void)
- {
- return(LCD->SYNCBUSY);
- }
- /***************************************************************************//**
- * @brief
- * Polls LCD SYNCBUSY flags, until flag has been cleared
- *
- * @param[in] flags
- * Bit fields for LCD registers that shall be updated before we continue
- ******************************************************************************/
- static __INLINE void LCD_SyncBusyDelay(uint32_t flags)
- {
- while (LCD->SYNCBUSY & flags) ;
- }
- /***************************************************************************//**
- * @brief
- * Get pending LCD interrupt flags
- *
- * @return
- * Pending LCD interrupts, which need to be cleared.
- ******************************************************************************/
- static __INLINE uint32_t LCD_IntGet(void)
- {
- return(LCD->IF);
- }
- /***************************************************************************//**
- * @brief
- * Set one or more pending LCD interrupts from SW.
- *
- * @param[in] flags
- * Bit field for interrupts to set
- ******************************************************************************/
- static __INLINE void LCD_IntSet(uint32_t flags)
- {
- LCD->IFS = flags;
- }
- /***************************************************************************//**
- * @brief
- * Enable LCD (Frame Counter) interrupt
- *
- * @param[in] flags
- * LCD_IF_FC, which is the only supported interrupt for the LCD controller
- ******************************************************************************/
- static __INLINE void LCD_IntEnable(uint32_t flags)
- {
- LCD->IEN |= flags;
- }
- /***************************************************************************//**
- * @brief
- * Disable LCD (Frame Counter) interrupt
- *
- * @param[in] flags
- * LCD_IF_FC, which is the only supported interrupt for the LCD controller
- ******************************************************************************/
- static __INLINE void LCD_IntDisable(uint32_t flags)
- {
- LCD->IEN &= ~(flags);
- }
- /***************************************************************************//**
- * @brief
- * Clear one or more interrupt flags
- *
- * @param[in] flags
- * LCD_IF_FC, which is the only supported interrupt for the LCD controller
- ******************************************************************************/
- static __INLINE void LCD_IntClear(uint32_t flags)
- {
- LCD->IFC = flags;
- }
- /** @} (end addtogroup LCD) */
- /** @} (end addtogroup EFM32_Library) */
- #ifdef __cplusplus
- }
- #endif
- #endif /* defined(LCD_COUNT) && (LCD_COUNT > 0) */
- #endif /* __EFM32_LCD_H */
|