1 /***************************************************************************//**
2 * \file cy_seglcd.h
3 * \version 1.10
4 *
5 * \brief
6 * Provides an API declaration of the Segment LCD driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2019-2020 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *     http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 
26 /**
27 * \addtogroup group_seglcd
28 * \{
29 * The Segment LCD Driver provides an API to configure and operate the MXLCD hardware block.
30 * The MXLCD block can be flexibly configured to drive a variety of LCD glass
31 * at different voltage levels with multiplex ratios.
32 *
33 * Features:
34 * * Digital Correlation and PWM at 1/2, 1/3, 1/4 and at 1/5 bias modes are supported
35 * * Drives STN/TN LCD-glass with up to eight COMs (device specific)
36 * * 30 to 150 Hz refresh rate
37 * * Supports both type A (standard) and type B (low-power) waveforms
38 * * The display pixel state can be inverted for a negative image
39 * * Operation in Deep Sleep Mode from ILO/MFO
40 * * All-digital contrast control using "Dead Period" digital modulation
41 * * A set of basic standard displays and fonts
42 * * The customizable display and font structures.
43 *
44 * \section group_seglcd_glossary Glossary
45 * * LCD - Liquid Crystal Display
46 * * Glass - An LCD glass with one or more displays
47 *   (e.g. one 7-segment display and one bar-graph display).
48 * * TN - A twisted nematic LCD glass.
49 * * STN - A super-twisted nematic LCD glass.
50 * * Display - A block of the same type of symbols on an LCD glass to indicate a multi-digital
51 *   number or character string. There may be one or more displays on a single LCD glass.
52 * * Symbol - A block of pixels on an LCD glass to indicate a single digit or character.
53 * * Pixel - A basic displaying item. This can be a segment of a 7-segment symbol (thus called a "segment"),
54 *   a pixel of a dot-matrix display, or a stand-alone arbitrarily-shaped display element.
55 *   Each pixel has a unique set of common and segment lines within one LCD glass.
56 *   The API offers pixel identifiers - the 32-bit items of the display pixel map
57 *   (to use in the display structure definition, see \ref cy_stc_seglcd_disp_t),
58 *   created by the \ref CY_SEGLCD_PIXEL macro.
59 * * Common line (Com/COM for short) - A common wire/signal from the PSoC chip to the LCD glass.
60 *   The API offers common line identifiers - the 32-bit items of the commons array
61 *   (to use in \ref Cy_SegLCD_ClrFrame and \ref Cy_SegLCD_InvFrame),
62 *   created by the \ref CY_SEGLCD_COMMON macro.
63 * * Segment line (Seg/SEG for short) - A segment wire/signal from the PSoC chip to the LCD glass.
64 * * Octet - A bunch of subsequent eight MXLCD terminals. Octets may not match GPIO ports.
65 * * Frame buffer - An array of registers to control the MXLCD signal generation for all the MXLCD terminals.
66 *
67 * \section group_seglcd_solution SegLCD Solution
68 * The Segment LCD Driver can be used either as a standalone library
69 * to manage the MXLCD hardware or as a part of the more complex software solution
70 * delivered within ModusToolbox:
71 * the Device Configurator SegLCD personality and the SegLCD Configurator tools.
72 *
73 * The SegLCD solution provides an easy method to configure
74 * an MXLCD block to drive your standard or custom LCD glass:
75 * \image html seglcd_solution.png
76 * The SegLCD solution includes:
77 * * The SegLCD Configurator tool, which is a display configuration wizard to create and
78 *   configure displays and generate commons array and display structures \ref cy_stc_seglcd_disp_t.
79 * * The ModusToolbox Device Configurator contains a SegLCD personality, which is an MXLCD block
80 *   configuration wizard. It helps to easily tune all the timing settings, operation modes,
81 *   provides a flexible GPIO pin assignment capability and generates the \ref cy_stc_seglcd_config_t
82 *   structure and the rest of accompanying definitions.
83 * * The SegLCD Driver API itself, which uses all the mentioned above generated code.
84 *
85 * \section group_seglcd_configuration Configuration Considerations
86 * To start working with an LCD, first initialize the MXLCD block, then initialize
87 * the frame buffer, and then enable the block:
88 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Config
89 * \note If you use ModusToolbox Device Configurator, a SegLCD configuration structure
90 * is generated automatically into the GeneratedSource/cycfg_peripherals.h/.c files.
91 * All you need is just to call \ref Cy_SegLCD_Init with a pointer to the structure.
92 *
93 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Init
94 *
95 * Contrast vs. Frame Rate (\ref cy_stc_seglcd_config_t.contrast vs. \ref cy_stc_seglcd_config_t.frRate)\n
96 * Some combinations of a frame rate and input frequency can restrict the valid contrast range
97 * because of the limited dividers size (for Low Speed mode - 8 bit, and for High Speed mode - 16 bit).
98 * For small values of contrast at small frame rates, the required divider values
99 * may be beyond permissible limits of the dividers size.
100 * For large High Speed clock frequencies, certain ratios between the contrast and frame
101 * rate cannot be achieved due to the limited divider size. The \ref Cy_SegLCD_Init function
102 * automatically restricts such incorrect combinations (returns \ref CY_SEGLCD_BAD_PARAM).
103 * The peripheral clock divider can be adjusted to clock the LCD block with proper clock frequency:
104 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Clock
105 *
106 * Speed Mode Switching (\ref cy_stc_seglcd_config_t.speed)\n
107 * The High Speed and Low Speed generators mostly duplicate each other,
108 * except that for MXLCD_ver1, the High Speed version has larger frequency dividers to generate
109 * the frame and sub-frame periods. This is because the clock of the High Speed block
110 * typically has a frequency 30-100 times bigger than the 32 KHz clock fed to the Low Speed block.
111 * For MXLCD_ver2, both High Speed and Low Speed generators have similar 16-bit dividers,
112 * because a possibility exists to source a Low Speed generator with a Medium Frequency clock
113 * (see \ref group_sysclk_mf_funcs) that may be much higher than 32 KHz ILO:
114 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_MF_Clock
115 * Switching between High Speed and Low Speed modes via the \ref Cy_SegLCD_Init function
116 * causes the dividers to reconfigure.
117 * Under possible restrictions related to certain ratios between contrast and frame rates
118 * (see Contrast vs. Frame Rate section above), switching between High Speed and the Low Speed modes
119 * via the \ref Cy_SegLCD_Init function may set new dividers values that don't give the same contrast value.
120 *
121 * Driving Modes (\ref cy_stc_seglcd_config_t.drive)\n
122 * SegLCD supports the following operating modes:
123 * * Digital Correlation - preferred for low clock speeds, low common lines count and low supply voltages.
124 * * PWM at 1/2, 1/3, 1/4 or 1/5 Bias - preferred for high clock speeds (e.g. over 1MHz), many common lines (e.g. over 4), and high voltages (e.g. 3.3V or higher).
125 * More precise preferences depend on a certain set of an LCD glass, power modes, the number of terminals, desired contrast/frame rate settings, etc.
126 *
127 * Conventional Waveforms (\ref cy_stc_seglcd_config_t.wave)\n
128 * Conventional LCD drivers apply waveforms to COM and SEG electrodes generated by switching
129 * between multiple different voltages. The following terms are used to define these waveforms:
130 * * Duty:  A driver operates in the 1/M-th duty when it drives M COM electrodes. Each COM electrode is effectively driven for the 1/M of the frame time.
131 * * Bias:  A driver uses the 1/B-th bias when its waveforms use the voltage steps of (1/B)*VDRV.
132 * * Frame: A frame is the time length to address all segments.
133 *   During a frame, the driver cycles through the commons in sequence.
134 *   All segments receive 0V DC when measured over the length of an entire frame.
135 * * Type-A Waveform:  The driver structures the frame into M sub-frames. COMi is addressed in sub-frame i.
136 * * Type-B Waveform:  The driver structures the frame into 2M sub-frames. COMi is addressed in sub-frames i and M+i.
137 *   The two sub-frames are inverse of each other.  Typically, type-B waveforms are slightly more power-efficient because they contain fewer transitions.
138 *
139 * The following figures show the conventional waveforms for COM and SEG electrodes for the 1/3rd bias and 1/4th duty. Only COM0/COM1 and SEG0/SEG1 are drawn.
140 * Conventional Type-A Waveform Example:
141 * \image html seglcd_waveA.png
142 * Conventional Type-B Waveform Example:
143 * \image html seglcd_waveB.png
144 * The generalized waveforms for individual sub-frames for any duty and bias are illustrated in the following figure.
145 * Note that these use 6 different voltages at most(including VSS and VDRV).
146 * Conventional Waveforms - Generalized:
147 * \image html seglcd_waveGen.png
148 * The effective RMS voltage for on and off segments can be calculated using these waveforms:
149 * \image html seglcd_Voff.png
150 * \image html seglcd_Von.png
151 * The resulting Discrimination Ratio (D) for various bias and duty combinations is illustrated in the following table.
152 * The bias choice (B) for each duty (M) with the highest possible value for D is colored green:
153 * \image html seglcd_descr.png
154 *
155 * Digital Correlation (\ref CY_SEGLCD_CORRELATION)\n
156 * The principles of operation are illustrated by the example waveforms shown in the following figures.
157 * Digital Correlation Example - Type-A:
158 * \image html seglcd_DCA.png
159 * Digital Correlation Example - Type-B:
160 * \image html seglcd_DCB.png
161 * As illustrated, instead of generating bias voltages between the rails, this approach takes advantage of the LCD displays characteristic:
162 * the LCD segments' on-ness and off-ness degree is determined by the RMS voltage across the segments. In this approach, the correlation
163 * coefficient between any given pair of COM and SEG signals determines whether the corresponding LCD segment is On or Off.
164 * Thus, by doubling the base drive frequency of the COM signals in their inactive sub-frame intervals, the phase relationship of the COM and SEG
165 * drive signals can be varied to turn segments on and off - rather than varying the DC levels of the signals as is used in the conventional approaches.
166 *
167 * PWM Drive (\ref CY_SEGLCD_PWM)\n
168 * This approach duplicates the multi-voltage drive signals of the conventional method with bias B using a PWM output signal together
169 * with the intrinsic resistance and capacitance of the LCD display to create a simple PWM DAC.
170 * This is illustrated in the following figure:
171 * \image html seglcd_PWM.png
172 * To drive a low-capacitance display with an acceptable ripple and rise/fall time, using a 32-kHz PWM an additional external
173 * series resistance of 100 k - 1 M ohm is required. External Resistors are not required for PWM frequencies of greater than ~1 MHz.
174 * The exact frequency depends on the display capacitance, the internal ITO resistance of the ITO routing traces,
175 * and the drive impedance of the I/O pins.
176 * The PWM method works for any bias value (B). NOTE As B gets higher, a higher PWM step frequency is required to maintain the
177 * same PWM output frequency (the RC response of the LCD depends on the PWM output frequency, NOT the step frequency).
178 * The PWM approach may also be used to drive a 1/2-bias display. This has the advantage that PWM is only required on the COM signals,
179 * as SEG signals of a 1/2-bias display use only logic levels. Therefore, PWM 1/2-bias can be supported at 32 kHz using just
180 * four external resistors.
181 * The power consumption of the approach (even for 1/2 bias) is substantially higher than that of other methods. Therefore, it is recommended
182 * power-sensitive customers use Digital Correlation drive in Deep Sleep mode, and change to PWM mode to gain the advantage of
183 * better contrast/viewing angle on TN displays in Active or Sleep mode.
184 *
185 * PWM1/2 LCD drive waveform:
186 * \image html seglcd_PWM2.png
187 * PWM1/3 LCD drive waveform:
188 * \image html seglcd_PWM3.png
189 *
190 * Digital Contrast Control\n
191 * In all modes, digital contrast control is available using the duty cycle/dead time method illustrated in the following figure:
192 * \image html seglcd_contrast.png
193 * This illustration shows the principle for 1/3 bias and 1/4 duty implementation, but the general approach of reducing contrast
194 * by reducing the percentage of time the glass is driven can be generalized and applied to any drive method.
195 * In all cases, during the dead time, all COM and SEG signals are set to a logic "1" state.
196 *
197 * When the block is configured, for further work with display, a display structure is needed:
198 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Display
199 * \note Using the SegLCD Configurator, display structures and the commons array are generated automatically into the
200 * GeneratedSource/cycfg_seglcd.h/.c files. All you need is just to include cycfg_seglcd.h into your application code.
201 *
202 * And now you can write multi-digit decimal and hexadecimal numbers and strings onto the initiated 7-segment display:
203 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_DecNum
204 * after which the next image on the glass appears:
205 * \image html seglcd_12.png
206 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_HexNum
207 * \image html seglcd_oooc.png
208 *
209 * Or even manage separate LCD pixels:
210 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_DefPixel
211 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_SetPixel
212 * after which the next image on the glass appears:
213 * \image html seglcd_heart.png
214 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_ClrPixel
215 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_InvPixel
216 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_ActPixel
217 *
218 * The basic use case of the bar-graph display type:
219 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_DefFrame
220 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_BarLength
221 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_BarGraphDisplay
222 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_BarGraphValue
223 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_SetFrame
224 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_BarGraph
225 * after which the next image on the glass appears:
226 * \image html seglcd_bargraph.png
227 *
228 * Also, you can customize basic fonts, for example:
229 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_CustomAsciiFont7seg
230 * And now you can write characters and strings on a standard 7-segment display:
231 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Char
232 * after which the next image on the glass appears:
233 * \image html seglcd_char.png
234 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_String
235 * \image html seglcd_font.png
236 *
237 * Also, you can customize or create your own displays, for example:
238 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Custom3x5
239 * And also different fonts for them:
240 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_CustomFont3x5
241 * And now use all that together:
242 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_Custom3x5_WriteNumber
243 * \image html seglcd_3x5.png
244 *
245 * There are LCD-GPIO terminal mapping definitions for different device families
246 * used in the mentioned above commons and display pixel arrays:
247 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_connectionRemapping
248 *
249 * \section group_seglcd_more_information More Information
250 * Refer to the technical reference manual (TRM) and the device datasheet.
251 *
252 * \section group_seglcd_changelog Changelog
253 * <table class="doxtable">
254 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
255 *   <tr>
256 *     <td>1.10</td>
257 *     <td>Fixed/Documented MISRA 2012 violations.</td>
258 *     <td>MISRA 2012 compliance.</td>
259 *   </tr>
260 *   <tr>
261 *     <td>1.0.1</td>
262 *     <td>Code snippets are extended to support the CY8C62x5 device family</td>
263 *     <td>User experience improvement</td>
264 *   </tr>
265 *   <tr>
266 *     <td>1.0</td>
267 *     <td>Initial version</td>
268 *     <td></td>
269 *   </tr>
270 * </table>
271 *
272 * \defgroup group_seglcd_macros    Macros
273 * \defgroup group_seglcd_functions Functions
274 * \{
275 *   \defgroup group_seglcd_functions_config  Block Configuration Functions
276 *   \defgroup group_seglcd_functions_frame   Frame/Pixel Management Functions
277 *   \defgroup group_seglcd_functions_display Display/Character Management Functions
278 * \}
279 * \defgroup group_seglcd_data_structures  Data Structures
280 * \defgroup group_seglcd_globals Global   Data
281 * \defgroup group_seglcd_enums Enumerated Types
282 */
283 
284 #if !defined(CY_SEGLCD_H)
285 #define CY_SEGLCD_H
286 
287 #include "cy_device.h"
288 
289 #if defined (CY_IP_MXLCD)
290 
291 #include "cy_syslib.h"
292 
293 #if defined(__cplusplus)
294 extern "C" {
295 #endif
296 
297 /** \addtogroup group_seglcd_macros
298 * \{
299 */
300 
301 /** Driver major version */
302 #define CY_SEGLCD_DRV_VERSION_MAJOR         1
303 
304 /** Driver minor version */
305 #define CY_SEGLCD_DRV_VERSION_MINOR         10
306 
307 /** SegLCD driver ID */
308 #define CY_SEGLCD_ID                        (CY_PDL_DRV_ID(0x40u))
309 
310 /** Specifies the pixel in the display pixel map array which is not connected */
311 #define CY_SEGLCD_NOT_CON                   (0xFFFFFFFFUL)
312 
313 /** \cond internal */
314 #define CY_SEGLCD_OCTET                     (8UL)
315 #define CY_SEGLCD_COM_Pos                   (16U)
316 #define CY_SEGLCD_COM_Msk                   ((uint32_t) 0xFUL << CY_SEGLCD_COM_Pos)
317 #define CY_SEGLCD_OCT_Pos                   (8U)
318 #define CY_SEGLCD_OCT_Msk                   ((uint32_t) 0x7UL << CY_SEGLCD_OCT_Pos)
319 #define CY_SEGLCD_NBL_Pos                   (0U)
320 #define CY_SEGLCD_NBL_Msk                   ((uint32_t) 0x7UL << CY_SEGLCD_NBL_Pos)
321 
322 #define CY_SEGLCD_ITEM(trmNum, comLine)     (_VAL2FLD(CY_SEGLCD_COM, (comLine))                  | \
323                                              _VAL2FLD(CY_SEGLCD_OCT, (trmNum) / CY_SEGLCD_OCTET) | \
324                                              _VAL2FLD(CY_SEGLCD_NBL, (trmNum) % CY_SEGLCD_OCTET))
325 
326 /* Extract the LCD common line number from the pixel value */
327 #define CY_SEGLCD_EXTR_COM(pixel)           (_FLD2VAL(CY_SEGLCD_COM, (pixel)))
328 /* Extract the LCD terminal octet number from the pixel value */
329 #define CY_SEGLCD_EXTR_OCT(pixel)           (_FLD2VAL(CY_SEGLCD_OCT, (pixel)))
330 /* Extract the LCD terminal nibble number from the pixel value */
331 #define CY_SEGLCD_EXTR_NBL(pixel)           (_FLD2VAL(CY_SEGLCD_NBL, (pixel)))
332 /* Extract the LCD terminal number from the pixel value */
333 #define CY_SEGLCD_EXTR_TRM(pixel)           ((CY_SEGLCD_EXTR_OCT(pixel) * CY_SEGLCD_OCTET) + \
334                                               CY_SEGLCD_EXTR_NBL(pixel))
335 /* Convert the locComNum from the machine range (0-14) into the natural range (2-16). */
336 #define CY_SEGLCD_COM_NUM(base)             (_FLD2VAL(LCD_CONTROL_COM_NUM, LCD_CONTROL(base)) + 2UL)
337 /** \endcond */
338 
339 
340 /**
341 * Makes the pixel identifier from the LCD segment terminal number and the user defined common line number.
342 * It should be used to display pixel map (pixMap) array definitions for \ref cy_stc_seglcd_disp_t.
343 */
344 #define CY_SEGLCD_PIXEL(segNum, comLine)    (CY_SEGLCD_ITEM(segNum, comLine))
345 
346 /**
347 * Makes the common line identifier from the LCD common terminal number and the user defined common line number.
348 * It should be used for commons array definitions for \ref Cy_SegLCD_ClrFrame and \ref Cy_SegLCD_InvFrame.
349 */
350 #define CY_SEGLCD_COMMON(comNum, comLine)   (CY_SEGLCD_ITEM(comNum, comLine))
351 
352 /** Space/blank/empty symbol code for the numeric type of fonts */
353 #define CY_SEGLCD_NUM_BLANK                 ((char_t)16)
354 
355 /** \} group_seglcd_macros */
356 
357 
358 /**
359 * \addtogroup group_seglcd_enums
360 * \{
361 */
362 
363 /** SegLCD driver error codes */
364 typedef enum
365 {
366     CY_SEGLCD_SUCCESS   = 0x0UL,                                         /**< Returned successful */
367     CY_SEGLCD_BAD_PARAM = CY_SEGLCD_ID | CY_PDL_STATUS_ERROR | 0x01UL,   /**< A bad parameter was passed (display/font pointer is NULL,
368                                                                           *   position is out of display area, etc.)
369                                                                           */
370     CY_SEGLCD_BAD_PIXEL = CY_SEGLCD_ID | CY_PDL_STATUS_ERROR | 0x02UL,   /**< The specified pixel value is wrong or the pixel is
371                                                                           *   specified as 'not connected' in the display pixMap array.
372                                                                           */
373     CY_SEGLCD_BAD_CHAR  = CY_SEGLCD_ID | CY_PDL_STATUS_ERROR | 0x04UL,   /**< The specified character (or at least one of characters in the
374                                                                           *   specified string) is not supported by the specified font.
375                                                                           */
376     CY_SEGLCD_EXCEED    = CY_SEGLCD_ID | CY_PDL_STATUS_WARNING | 0x08UL, /**< The string (length) or number (amount of dec/hex digits)
377                                                                           *   exceeds the display limits.
378                                                                           */
379     CY_SEGLCD_CUSTOM    = CY_SEGLCD_ID | CY_PDL_STATUS_INFO | 0x10UL,    /**< The display/font type is custom
380                                                                           *   (not defined by the \ref cy_en_seglcd_disp_t).
381                                                                           */
382 } cy_en_seglcd_status_t;
383 
384 /** SegLCD block speed mode */
385 typedef enum
386 {
387     CY_SEGLCD_SPEED_LOW  = 0x0UL, /**< Low Speed mode, works in Active, Sleep and DeepSleep power modes */
388     CY_SEGLCD_SPEED_HIGH = 0x1UL  /**< High Speed mode, works in Active and Sleep power modes */
389 } cy_en_seglcd_speed_t;
390 
391 /** SegLCD block low speed mode clock source selection  */
392 typedef enum
393 {
394     CY_SEGLCD_LSCLK_LF = 0x0UL, /**< Low Frequency source, usually connected to ILO */
395     CY_SEGLCD_LSCLK_MF = 0x1UL  /**< Middle Frequency source, usually connected to CLK_MF, \ref group_sysclk_mf_funcs */
396 } cy_en_seglcd_lsclk_t;
397 
398 /** SegLCD driving waveform type */
399 typedef enum
400 {
401     CY_SEGLCD_TYPE_A = 0x0UL, /**< Type A - Each frame addresses each COM pin only once with a balanced (DC=0) waveform. */
402     CY_SEGLCD_TYPE_B = 0x1UL  /**< Type B - Each frame addresses each COM pin twice in a sequence with a positive
403                                *            and negative waveform that together are balanced (DC=0).
404                                */
405 } cy_en_seglcd_wave_t;
406 
407 /** SegLCD driving mode configuration */
408 typedef enum
409 {
410     CY_SEGLCD_PWM         = 0x0UL, /**< PWM mode. */
411     CY_SEGLCD_CORRELATION = 0x1UL  /**< Digital Correlation mode. */
412 } cy_en_seglcd_drive_t;
413 
414 /** SegLCD PWM bias selection */
415 typedef enum
416 {
417     CY_SEGLCD_BIAS_HALF   = 0x0UL, /**< 1/2 Bias. */
418     CY_SEGLCD_BIAS_THIRD  = 0x1UL, /**< 1/3 Bias. */
419     CY_SEGLCD_BIAS_FOURTH = 0x2UL, /**< 1/4 Bias (not supported for \ref CY_SEGLCD_SPEED_LOW mode in MXLCD_ver1). */
420     CY_SEGLCD_BIAS_FIFTH  = 0x3UL, /**< 1/5 Bias (not supported for \ref CY_SEGLCD_SPEED_LOW mode in MXLCD_ver1). */
421 } cy_en_seglcd_bias_t;
422 
423 /** SegLCD segment display types */
424 typedef enum
425 {
426     CY_SEGLCD_BAR   = 1U,  /**< Bar Graph / Dial display */
427     CY_SEGLCD_7SEG  = 7U,  /**< Seven-segment display */
428     CY_SEGLCD_14SEG = 14U, /**< Fourteen-segment display */
429     CY_SEGLCD_16SEG = 16U, /**< Sixteen-segment display */
430     CY_SEGLCD_5X8DM = 40U  /**< Five-by-eight dot matrix display */
431 } cy_en_seglcd_disp_t;
432 
433 /** \} group_seglcd_enums */
434 
435 
436 /** \addtogroup group_seglcd_macros
437 * \{
438 */
439 
440 /* Font map array symbol sizes in bytes. Used for the basic font definitions (\ref group_seglcd_globals) and also can be used for custom font definitions */
441 #define CY_SEGLCD_14SEG_FONTMAP_SIZE       (CY_SYSLIB_DIV_ROUNDUP(CY_SEGLCD_14SEG, CY_SEGLCD_OCTET)) /**< 14-segment fontMap array item size (in bytes) */
442 #define CY_SEGLCD_16SEG_FONTMAP_SIZE       (CY_SYSLIB_DIV_ROUNDUP(CY_SEGLCD_16SEG, CY_SEGLCD_OCTET)) /**< 16-segment fontMap array item size (in bytes) */
443 #define CY_SEGLCD_5X8DM_FONTMAP_SIZE       (CY_SYSLIB_DIV_ROUNDUP(CY_SEGLCD_5X8DM, CY_SEGLCD_OCTET)) /**< 5x8 dot matrix fontMap array item size (in bytes) */
444 
445 /** \} group_seglcd_macros */
446 
447 
448 /***************************************
449 *       Configuration Structures
450 ***************************************/
451 
452 
453 /**
454 * \addtogroup group_seglcd_data_structures
455 * \{
456 */
457 
458 /** Configuration structure */
459 typedef struct
460 {
461     cy_en_seglcd_speed_t speed; /**< Speed mode selection, see: #cy_en_seglcd_speed_t. */
462     cy_en_seglcd_wave_t   wave; /**< Waveform type configuration, see: #cy_en_seglcd_wave_t. */
463     cy_en_seglcd_drive_t drive; /**< Driving mode configuration, see: #cy_en_seglcd_drive_t. */
464     cy_en_seglcd_bias_t   bias; /**< PWM bias selection, see: #cy_en_seglcd_bias_t. */
465     cy_en_seglcd_lsclk_t lsClk; /**< Low Speed Mode clock selection, see: #cy_en_seglcd_lsclk_t.
466                                  *   This is effective for MXLCD_ver2,
467                                  *   for MXLCD_ver1 it is ignored.
468                                  */
469     uint8_t             comNum; /**< The number of Common connections, the valid range is 2...16
470                                  *   however the maximum is dependent on PSoC device family -
471                                  *   there could be limitation to 4 or 8 commons, see the device TRM.
472                                  */
473     uint8_t             frRate; /**< The LCD frame rate, the valid range is 30...150 */
474     uint8_t           contrast; /**< The LCD contrast, the valid range is 0...100 */
475     uint32_t           clkFreq; /**< The LCD clock frequency (ignored for \ref CY_SEGLCD_LSCLK_LF mode,
476                                  *   or in \ref CY_SEGLCD_SPEED_LOW mode for MXLCD_ver1),
477                                  *   the valid range is 10000...100000000 (Hz)
478                                  */
479 } cy_stc_seglcd_config_t;
480 
481 /** Font structure */
482 typedef struct
483 {
484     char_t            first; /**< The first character code in the fontMap array */
485     char_t             last; /**< The last character code in the fontMap array */
486     bool              ascii; /**< Specifies whether the font map is indexed accordingly to ASCII character codes:
487                               *   true - the font is ASCII-coded alphanumeric (e.g. a basic set "space" (ASCII 0x20) - "tilde"(ASCII 0x7E));
488                               *   false - the font is e.g. pure numeric (0x0...0xF only), or any other custom character set.
489                               */
490     uint8_t const * fontMap; /**< The pointer to the font segment/pixel map array. */
491 } cy_stc_seglcd_font_t;
492 
493 /** Display structure */
494 typedef struct
495 {
496     uint16_t                     type; /**< The display type, one of \ref cy_en_seglcd_disp_t or custom. */
497     uint16_t                   symNum; /**< The number of symbols (digits, characters). */
498     bool                       invert; /**< Specifies whether the display is inverted or not. */
499     uint32_t           const * pixMap; /**< The pointer to the display pixel map array:
500                                         *   The array dimension is: uint32_t pixMap[symNum][type].
501                                         *   Each array item should be made using the \ref CY_SEGLCD_PIXEL macro.
502                                         */
503     cy_stc_seglcd_font_t const * font; /**< The pointer to the font structure suitable for this display.
504                                         *   Note that for the \ref CY_SEGLCD_BAR displays font is not used, so can be NULL.
505                                         */
506 } cy_stc_seglcd_disp_t;
507 
508 /** \} group_seglcd_data_structures */
509 
510 
511 /** \addtogroup group_seglcd_globals
512 * \{
513 */
514 
515 extern const cy_stc_seglcd_font_t cy_segLCD_7SegFont;  /**< Basic 7-segment font */
516 extern const cy_stc_seglcd_font_t cy_segLCD_14SegFont; /**< Basic 14-segment font */
517 extern const cy_stc_seglcd_font_t cy_segLCD_16SegFont; /**< Basic 16-segment font */
518 extern const cy_stc_seglcd_font_t cy_segLCD_5x8DmFont; /**< Basic 5x8 dot matrix font */
519 
520 /** \} group_seglcd_globals */
521 
522 
523 /***************************************
524 *        Function Prototypes
525 ***************************************/
526 
527 
528 /**
529 * \addtogroup group_seglcd_functions
530 * \{
531 */
532 
533 
534 /**
535 * \addtogroup group_seglcd_functions_config
536 * \{
537 */
538 cy_en_seglcd_status_t Cy_SegLCD_Init    (LCD_Type * base,                    cy_stc_seglcd_config_t const * config);
539 cy_en_seglcd_status_t Cy_SegLCD_Contrast(LCD_Type * base, uint32_t contrast, cy_stc_seglcd_config_t       * config);
540                  void Cy_SegLCD_Deinit  (LCD_Type * base);
541                  void Cy_SegLCD_Enable  (LCD_Type * base);
542                  void Cy_SegLCD_Disable (LCD_Type * base);
543 /** \} group_seglcd_functions_config */
544 
545 
546 /**
547 * \addtogroup group_seglcd_functions_display
548 * \{
549 */
550 cy_en_seglcd_status_t Cy_SegLCD_WriteChar  (LCD_Type * base, char_t      character, uint32_t position, cy_stc_seglcd_disp_t const * display);
551 cy_en_seglcd_status_t Cy_SegLCD_WriteString(LCD_Type * base, char_t const * string, uint32_t position, cy_stc_seglcd_disp_t const * display);
552 cy_en_seglcd_status_t Cy_SegLCD_WriteNumber(LCD_Type * base, uint32_t        value, uint32_t position, cy_stc_seglcd_disp_t const * display, bool zeroes, bool hex);
553 cy_en_seglcd_status_t Cy_SegLCD_BarGraph   (LCD_Type * base, uint32_t        value, uint32_t position, cy_stc_seglcd_disp_t const * display);
554 /** \} group_seglcd_functions_display */
555 
556 
557 /**
558 * \addtogroup group_seglcd_functions_frame
559 * \{
560 */
561                 cy_en_seglcd_status_t Cy_SegLCD_ClrFrame  (LCD_Type * base, uint32_t const * commons);
562                 cy_en_seglcd_status_t Cy_SegLCD_InvFrame  (LCD_Type * base, uint32_t const * commons);
563                 cy_en_seglcd_status_t Cy_SegLCD_WritePixel(LCD_Type * base, uint32_t pixel, bool value);
564                                  bool Cy_SegLCD_ReadPixel (LCD_Type * base, uint32_t pixel);
565 __STATIC_INLINE cy_en_seglcd_status_t Cy_SegLCD_SetPixel  (LCD_Type * base, uint32_t pixel);
566 __STATIC_INLINE cy_en_seglcd_status_t Cy_SegLCD_ClrPixel  (LCD_Type * base, uint32_t pixel);
567 __STATIC_INLINE cy_en_seglcd_status_t Cy_SegLCD_InvPixel  (LCD_Type * base, uint32_t pixel);
568 
569 
570 /*******************************************************************************
571 * Function Name: Cy_SegLCD_SetPixel
572 ****************************************************************************//**
573 *
574 * Sets (turns on) the specified pixel.
575 *
576 * \param base The base pointer to the LCD instance registers.
577 * \param pixel The predefined packed number that points to the pixel location
578 *              in the frame buffer.
579 * \return \ref cy_en_seglcd_status_t.
580 *
581 * \funcusage
582 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_DefPixel
583 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_SetPixel
584 *
585 *******************************************************************************/
Cy_SegLCD_SetPixel(LCD_Type * base,uint32_t pixel)586 __STATIC_INLINE cy_en_seglcd_status_t Cy_SegLCD_SetPixel(LCD_Type * base, uint32_t pixel)
587 {
588     return (Cy_SegLCD_WritePixel(base, pixel, true));
589 }
590 
591 
592 /*******************************************************************************
593 * Function Name: Cy_SegLCD_ClrPixel
594 ****************************************************************************//**
595 *
596 * Clears (turns off) the specified pixel.
597 *
598 * \param base The base pointer to the LCD instance registers.
599 * \param pixel The predefined packed number that points to the pixel location
600 *              in the frame buffer.
601 * \return \ref cy_en_seglcd_status_t.
602 *
603 * \funcusage
604 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_DefPixel
605 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_ClrPixel
606 *
607 *******************************************************************************/
Cy_SegLCD_ClrPixel(LCD_Type * base,uint32_t pixel)608 __STATIC_INLINE cy_en_seglcd_status_t Cy_SegLCD_ClrPixel(LCD_Type * base, uint32_t pixel)
609 {
610     return (Cy_SegLCD_WritePixel(base, pixel, false));
611 }
612 
613 
614 /*******************************************************************************
615 * Function Name: Cy_SegLCD_InvPixel
616 ****************************************************************************//**
617 *
618 * Inverts the state of the specified pixel.
619 *
620 * \param base The base pointer to the LCD instance registers.
621 * \param pixel The predefined packed number that points to the pixel location
622 *              in the frame buffer.
623 * \return \ref cy_en_seglcd_status_t.
624 *
625 * \funcusage
626 * \snippet seglcd/snippet/SegLCD_Snpt.h snippet_Cy_SegLCD_DefPixel
627 * \snippet seglcd/snippet/SegLCD_Snpt.c snippet_Cy_SegLCD_InvPixel
628 *
629 *******************************************************************************/
Cy_SegLCD_InvPixel(LCD_Type * base,uint32_t pixel)630 __STATIC_INLINE cy_en_seglcd_status_t Cy_SegLCD_InvPixel(LCD_Type * base, uint32_t pixel)
631 {
632     return (Cy_SegLCD_WritePixel(base, pixel, !Cy_SegLCD_ReadPixel(base, pixel)));
633 }
634 
635 /** \} group_seglcd_functions_frame */
636 
637 /** \} group_seglcd_functions */
638 
639 #if defined(__cplusplus)
640 }
641 #endif
642 
643 #endif /* CY_IP_MXLCD */
644 
645 #endif /* CY_SEGLCD_H */
646 
647 /** \} group_seglcd */
648 
649 /* [] END OF FILE */
650