1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2017, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32 #include <stdint.h>
33 #include <ti/devices/msp432p4xx/driverlib/lcd_f.h>
34 #include <ti/devices/msp432p4xx/driverlib/interrupt.h>
35
36 /* Define to ensure that our current MSP432 has the LCD_F module. This
37 definition is included in the device specific header file */
38 #ifdef __MCU_HAS_LCD_F__
39
40 /* Configuration functions */
LCD_F_initModule(LCD_F_Config * initParams)41 void LCD_F_initModule(LCD_F_Config *initParams)
42 {
43 BITBAND_PERI(LCD_F->CTL,LCD_F_CTL_ON_OFS) = 0;
44
45 LCD_F->CTL = (LCD_F->CTL
46 & ~(LCD_F_CTL_MX_MASK | LCD_F_CTL_SSEL_MASK | LCD_F_CTL_LP
47 | LCD_F_CTL_ON | LCD_F_CTL_DIV_MASK | LCD_F_CTL_PRE_MASK
48 | LCD_F_CTL_SON))
49 | (initParams->muxRate | initParams->clockSource
50 | initParams->waveforms | initParams->segments
51 | initParams->clockDivider | initParams->clockPrescaler);
52 }
53
LCD_F_turnOn(void)54 void LCD_F_turnOn(void)
55 {
56 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 1;
57 }
58
LCD_F_turnOff(void)59 void LCD_F_turnOff(void)
60 {
61 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
62 }
63
64 /* Memory management functions */
LCD_F_clearAllMemory(void)65 void LCD_F_clearAllMemory(void)
66 {
67 BITBAND_PERI(LCD_F->BMCTL , LCD_F_BMCTL_CLRM_OFS) = 1;
68 }
69
LCD_F_clearAllBlinkingMemory(void)70 void LCD_F_clearAllBlinkingMemory(void)
71 {
72 BITBAND_PERI(LCD_F->BMCTL , LCD_F_BMCTL_CLRBM_OFS) = 1;
73 }
74
LCD_F_selectDisplayMemory(uint_fast16_t displayMemory)75 void LCD_F_selectDisplayMemory(uint_fast16_t displayMemory)
76 {
77 BITBAND_PERI(LCD_F->BMCTL , LCD_F_BMCTL_DISP_OFS) = displayMemory;
78 }
79
LCD_F_setBlinkingControl(uint_fast16_t clockPrescalar,uint_fast16_t divider,uint_fast16_t mode)80 void LCD_F_setBlinkingControl(uint_fast16_t clockPrescalar,
81 uint_fast16_t divider, uint_fast16_t mode)
82 {
83 LCD_F->BMCTL = (LCD_F->BMCTL
84 & ~(LCD_F_BMCTL_BLKPRE_MASK | LCD_F_BMCTL_BLKDIV_MASK
85 | LCD_F_BMCTL_BLKMOD_MASK)) | clockPrescalar | mode
86 | divider;
87 }
88
LCD_F_setAnimationControl(uint_fast16_t clockPrescalar,uint_fast16_t divider,uint_fast16_t frames)89 void LCD_F_setAnimationControl(uint_fast16_t clockPrescalar,
90 uint_fast16_t divider, uint_fast16_t frames)
91 {
92 LCD_F->ANMCTL = (LCD_F->ANMCTL
93 & ~(LCD_F_ANMCTL_ANMPRE_MASK | LCD_F_ANMCTL_ANMDIV_MASK
94 | LCD_F_ANMCTL_ANMSTP_MASK)) | clockPrescalar | divider
95 | frames;
96 }
97
LCD_F_enableAnimation(void)98 void LCD_F_enableAnimation(void)
99 {
100 BITBAND_PERI(LCD_F->ANMCTL, LCD_F_ANMCTL_ANMEN_OFS) = 1;
101 }
102
LCD_F_disableAnimation(void)103 void LCD_F_disableAnimation(void)
104 {
105 BITBAND_PERI(LCD_F->ANMCTL, LCD_F_ANMCTL_ANMEN_OFS) = 0;
106 }
107
LCD_F_clearAllAnimationMemory(void)108 void LCD_F_clearAllAnimationMemory(void)
109 {
110 BITBAND_PERI(LCD_F->ANMCTL, LCD_F_ANMCTL_ANMCLR_OFS) = 1;
111 }
112
113 /* Pin Configuration Functions */
LCD_F_setPinAsLCDFunction(uint_fast8_t pin)114 void LCD_F_setPinAsLCDFunction(uint_fast8_t pin)
115 {
116 uint32_t val = (pin & 0x1F);
117
118 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
119
120 if((pin >> 5) == 0)
121 {
122 BITBAND_PERI(LCD_F->PCTL0, val) = 1;
123 }
124 else
125 {
126 BITBAND_PERI(LCD_F->PCTL1, val) = 1;
127 }
128 }
129
LCD_F_setPinAsPortFunction(uint_fast8_t pin)130 void LCD_F_setPinAsPortFunction(uint_fast8_t pin)
131 {
132 uint32_t val = (pin & 0x1F);
133
134 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
135
136 if((pin >> 5) == 0)
137 {
138 BITBAND_PERI(LCD_F->PCTL0, val) = 0;
139 }
140 else
141 {
142 BITBAND_PERI(LCD_F->PCTL1, val) = 0;
143 }
144 }
145
LCD_F_setPinsAsLCDFunction(uint_fast8_t startPin,uint8_t endPin)146 void LCD_F_setPinsAsLCDFunction(uint_fast8_t startPin, uint8_t endPin)
147 {
148 uint32_t startIdx = startPin >> 5;
149 uint32_t endIdx = endPin >> 5;
150 uint32_t startPos = startPin & 0x1F;
151 uint32_t endPos = endPin & 0x1F;
152
153 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
154
155 if (startIdx == endIdx)
156 {
157 if (startIdx == 0)
158 {
159 LCD_F->PCTL0 |= (0xFFFFFFFF >> (31 - endPos))
160 & (0xFFFFFFFF << startPos);
161 } else
162 {
163 LCD_F->PCTL1 |= (0xFFFFFFFF >> (31 - endPos))
164 & (0xFFFFFFFF << startPos);
165 }
166 } else
167 {
168 LCD_F->PCTL0 |= (0xFFFFFFFF << startPos);
169 LCD_F->PCTL1 |= (0xFFFFFFFF >> (31 - endPos));
170 }
171 }
172
LCD_F_setPinAsCOM(uint8_t pin,uint_fast8_t com)173 void LCD_F_setPinAsCOM(uint8_t pin, uint_fast8_t com)
174 {
175 uint32_t val = (pin & 0x1F);
176
177 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
178
179 if((pin >> 5) == 0)
180 {
181 BITBAND_PERI(LCD_F->CSSEL0, val) = 1;
182 }
183 else
184 {
185 BITBAND_PERI(LCD_F->CSSEL1, val) = 1;
186 }
187
188 // Setting the relevant COM pin
189 HWREG8(LCD_F_BASE + OFS_LCDM0W + pin) |= com;
190 HWREG8(LCD_F_BASE + OFS_LCDBM0W + pin) |= com;
191
192 }
193
LCD_F_setPinAsSEG(uint_fast8_t pin)194 void LCD_F_setPinAsSEG(uint_fast8_t pin)
195 {
196 uint32_t val = (pin & 0x1F);
197
198 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
199
200 if((pin >> 5) == 0)
201 {
202 BITBAND_PERI(LCD_F->CSSEL0, val) = 0;
203 }
204 else
205 {
206 BITBAND_PERI(LCD_F->CSSEL1, val) = 0;
207 }
208 }
209
LCD_F_selectBias(uint_fast16_t bias)210 void LCD_F_selectBias(uint_fast16_t bias)
211 {
212 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
213 LCD_F->VCTL = (LCD_F->VCTL & ~LCD_F_VCTL_LCD2B) | bias;
214 }
215
LCD_F_setVLCDSource(uint_fast16_t v2v3v4Source,uint_fast16_t v5Source)216 void LCD_F_setVLCDSource(uint_fast16_t v2v3v4Source, uint_fast16_t v5Source)
217 {
218 BITBAND_PERI(LCD_F->CTL, LCD_F_CTL_ON_OFS) = 0;
219 LCD_F->VCTL = (LCD_F->VCTL
220 & ~(LCD_F_VCTL_REXT | LCD_F_VCTL_EXTBIAS
221 | LCD_F_VCTL_R03EXT)) | v2v3v4Source | v5Source;
222 }
223
224 /* Interrupt Management */
LCD_F_clearInterrupt(uint32_t mask)225 void LCD_F_clearInterrupt(uint32_t mask)
226 {
227 LCD_F->CLRIFG |= mask;
228 }
229
LCD_F_getInterruptStatus(void)230 uint32_t LCD_F_getInterruptStatus(void)
231 {
232 return LCD_F->IFG;
233 }
234
LCD_F_getEnabledInterruptStatus(void)235 uint32_t LCD_F_getEnabledInterruptStatus(void)
236 {
237 return (LCD_F->IFG & LCD_F->IE);
238 }
239
LCD_F_enableInterrupt(uint32_t mask)240 void LCD_F_enableInterrupt(uint32_t mask)
241 {
242 LCD_F->IE |= mask;
243 }
244
LCD_F_disableInterrupt(uint32_t mask)245 void LCD_F_disableInterrupt(uint32_t mask)
246 {
247 LCD_F->IE &= ~mask;
248 }
249
LCD_F_registerInterrupt(void (* intHandler)(void))250 void LCD_F_registerInterrupt(void (*intHandler)(void))
251 {
252 Interrupt_registerInterrupt(INT_LCD_F, intHandler);
253 Interrupt_enableInterrupt(INT_LCD_F);
254 }
255
LCD_F_unregisterInterrupt(void)256 void LCD_F_unregisterInterrupt(void)
257 {
258 Interrupt_disableInterrupt(INT_LCD_F);
259 Interrupt_unregisterInterrupt(INT_LCD_F);
260 }
261
262 #endif /* __MCU_HAS_LCD_F__ */
263