HPM SDK
HPMicro Software Development Kit
hpm_lcdc_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 
9 #ifndef HPM_LCDC_DRV_H
10 #define HPM_LCDC_DRV_H
11 #include "hpm_display_common.h"
12 #include "hpm_soc_feature.h"
13 #include "hpm_lcdc_regs.h"
14 
23 #define LCDC_TEST_MODE_DISABLE (0U)
24 #define LCDC_TEST_MODE_BACKGROUND (1U)
25 #define LCDC_TEST_MODE_COLOR_BAR_COL (2U)
26 #define LCDC_TEST_MODE_COLOR_BAR_ROW (3U)
27 
28 /* @brief LCD driver specific status */
29 enum {
32 };
33 
34 /* @brief LCD line pattern */
35 typedef enum lcdc_line_pattern {
43 
44 /* @brief LCD display mode */
45 typedef enum lcdc_display_mode {
51 
52 /* @brief LCD layer transfer max bytes */
60 
61 /* @brief LCD control */
62 typedef struct lcdc_control {
67  bool invert_href;
68  bool invert_vsync;
69  bool invert_hsync;
71 
72 /* @brief LCD hsync/vsync config */
73 typedef struct lcdc_xsync_config {
74  uint16_t front_porch_pulse;
75  uint16_t back_porch_pulse;
76  uint16_t pulse_width;
78 
79 /* @brief LCD config */
80 typedef struct lcdc_config {
81  uint16_t resolution_x;
82  uint16_t resolution_y;
88 
89 /* @brief LCD layer config */
90 typedef struct lcdc_layer_config {
91  uint8_t max_ot;
98  uint16_t height;
99  uint16_t width;
100  uint16_t position_x;
101  uint16_t position_y;
103  uint32_t buffer;
104  uint32_t stride;
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110 
117 static inline void lcdc_software_reset(LCDC_Type *ptr)
118 {
119  ptr->CTRL |= LCDC_CTRL_SW_RST_MASK;
120  ptr->CTRL &= ~LCDC_CTRL_SW_RST_MASK;
121 }
122 
130 static inline void lcdc_enable_interrupt(LCDC_Type *ptr, uint32_t interrupt_mask)
131 {
132  ptr->INT_EN |= interrupt_mask;
133 }
134 
142 static inline void lcdc_disable_interrupt(LCDC_Type *ptr, uint32_t interrupt_mask)
143 {
144  ptr->INT_EN &= ~interrupt_mask;
145 }
146 
154 static inline void lcdc_clear_status(LCDC_Type *ptr, uint32_t mask)
155 {
156  ptr->ST = mask;
157 }
158 
166 static inline bool lcdc_layer_control_shadow_loaded(LCDC_Type *ptr, uint8_t layer_index)
167 {
168  return !(ptr->LAYER[layer_index].LAYCTRL & LCDC_LAYER_LAYCTRL_SHADOW_LOAD_EN_MASK);
169 }
170 
178 static inline uint32_t lcdc_get_dma_status(LCDC_Type *ptr)
179 {
180  return ptr->DMA_ST;
181 }
182 
192 static inline bool lcdc_check_dma_status(LCDC_Type *ptr, uint32_t mask)
193 {
194  return ((ptr->DMA_ST & mask) == mask);
195 }
196 
204 static inline void lcdc_clear_dma_status(LCDC_Type *ptr, uint32_t mask)
205 {
206  ptr->DMA_ST = mask;
207 }
208 
216 static inline uint32_t lcdc_get_status(LCDC_Type *ptr)
217 {
218  return ptr->ST;
219 }
220 
230 static inline bool lcdc_check_status(LCDC_Type *ptr, uint32_t mask)
231 {
232  return (ptr->ST & mask) == mask;
233 }
234 
243 static inline void lcdc_layer_set_next_buffer(LCDC_Type *ptr, uint32_t layer_index, uint32_t buffer)
244 {
245  ptr->LAYER[layer_index].START0 = LCDC_LAYER_START0_ADDR0_SET(buffer);
247 }
248 
257 static inline void lcdc_layer_update_background(LCDC_Type *ptr,
258  uint8_t layer_index, display_color_32b_t background)
259 {
260  ptr->LAYER[layer_index].BG_CL = LCDC_LAYER_BG_CL_ARGB_SET(background.u);
262 }
263 
273 static inline void lcdc_layer_update_position(LCDC_Type *ptr,
274  uint8_t layer_index, uint16_t x, uint32_t y)
275 {
276  ptr->LAYER[layer_index].LAYPOS = LCDC_LAYER_LAYPOS_X_SET(x)
279 }
280 
290 static inline void lcdc_layer_update_dimension(LCDC_Type *ptr,
291  uint8_t layer_index, uint8_t width, uint8_t height)
292 {
293  ptr->LAYER[layer_index].LAYSIZE = LCDC_LAYER_LAYSIZE_WIDTH_SET(width)
296 }
297 
309 static inline void lcdc_layer_set_region(LCDC_Type *ptr, uint8_t layer_index,
310  uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
311 {
312  ptr->LAYER[layer_index].LAYPOS = LCDC_LAYER_LAYPOS_X_SET(x1)
314  ptr->LAYER[layer_index].LAYSIZE = LCDC_LAYER_LAYSIZE_WIDTH_SET(x2 - x1 + 1)
315  | LCDC_LAYER_LAYSIZE_HEIGHT_SET(y2 - y1 + 1);
317 }
318 
326 static inline void lcdc_layer_update(LCDC_Type *ptr, uint8_t layer_index)
327 {
329 }
330 
338 static inline void lcdc_layer_enable(LCDC_Type *ptr, uint32_t layer_index)
339 {
340  ptr->LAYER[layer_index].LAYCTRL |=
342 }
343 
351 static inline void lcdc_layer_disable(LCDC_Type *ptr, uint32_t layer_index)
352 {
353  ptr->LAYER[layer_index].LAYCTRL =
354  (ptr->LAYER[layer_index].LAYCTRL & (~LCDC_LAYER_LAYCTRL_EN_MASK))
356 }
357 
365 static inline void lcdc_set_testmode(LCDC_Type *ptr, uint8_t test_mode)
366 {
367  ptr->CTRL = ((ptr->CTRL & ~LCDC_CTRL_DISP_MODE_MASK))
368  | LCDC_CTRL_DISP_MODE_SET(test_mode)
370 }
371 
379 static inline void lcdc_set_background(LCDC_Type *ptr,
380  display_color_32b_t color)
381 {
382  ptr->BGND_CL = LCDC_BGND_CL_R_SET(color.r)
383  | LCDC_BGND_CL_G_SET(color.g)
384  | LCDC_BGND_CL_B_SET(color.b);
385 }
386 
396 {
398 }
399 
409 {
411 }
422  lcdc_layer_config_t *layer, display_pixel_format_t pixel_format, uint8_t layer_index);
423 
432 
440 void lcdc_init(LCDC_Type *ptr, lcdc_config_t *config);
441 
451 hpm_stat_t lcdc_config_layer(LCDC_Type *ptr, uint8_t layer_index,
452  lcdc_layer_config_t *layer_config, bool enable_layer);
453 
461 
469 
470 #ifdef __cplusplus
471 }
472 #endif
477 #endif /* HPM_LCDC_DRV_H */
#define LCDC_LAYER_START0_ADDR0_SET(x)
Definition: hpm_lcdc_regs.h:638
#define LCDC_CTRL_DISP_MODE_MASK
Definition: hpm_lcdc_regs.h:99
#define LCDC_LAYER_LAYPOS_Y_SET(x)
Definition: hpm_lcdc_regs.h:617
#define LCDC_BGND_CL_R_SET(x)
Definition: hpm_lcdc_regs.h:192
#define LCDC_BGND_CL_G_SET(x)
Definition: hpm_lcdc_regs.h:202
#define LCDC_LAYER_LAYPOS_X_SET(x)
Definition: hpm_lcdc_regs.h:627
#define LCDC_LAYER_LAYSIZE_HEIGHT_SET(x)
Definition: hpm_lcdc_regs.h:595
#define LCDC_CTRL_DISP_MODE_SET(x)
Definition: hpm_lcdc_regs.h:101
#define LCDC_LAYER_BG_CL_ARGB_SET(x)
Definition: hpm_lcdc_regs.h:686
#define LCDC_CTRL_BGDCL4CLR_MASK
Definition: hpm_lcdc_regs.h:109
#define LCDC_LAYER_LAYCTRL_EN_MASK
Definition: hpm_lcdc_regs.h:561
#define LCDC_LAYER_LAYCTRL_SHADOW_LOAD_EN_MASK
Definition: hpm_lcdc_regs.h:461
#define LCDC_CTRL_SW_RST_MASK
Definition: hpm_lcdc_regs.h:48
#define LCDC_CTRL_DISP_ON_MASK
Definition: hpm_lcdc_regs.h:69
#define LCDC_BGND_CL_B_SET(x)
Definition: hpm_lcdc_regs.h:212
#define LCDC_LAYER_LAYSIZE_WIDTH_SET(x)
Definition: hpm_lcdc_regs.h:606
enum display_pixel_format display_pixel_format_t
display pixel format
enum display_yuv_format display_yuv_format_t
display yuv format
enum display_byteorder display_byteorder_t
display data byte order
uint32_t hpm_stat_t
Definition: hpm_common.h:126
#define MAKE_STATUS(group, code)
Definition: hpm_common.h:135
@ status_group_lcdc
Definition: hpm_common.h:151
static void lcdc_layer_set_next_buffer(LCDC_Type *ptr, uint32_t layer_index, uint32_t buffer)
Set next buffer for certain layer.
Definition: hpm_lcdc_drv.h:243
static void lcdc_layer_update_dimension(LCDC_Type *ptr, uint8_t layer_index, uint8_t width, uint8_t height)
Update specific layer dimension.
Definition: hpm_lcdc_drv.h:290
enum lcdc_layer_max_bytes_per_transfer lcdc_layer_max_bytes_per_transfer_t
struct lcdc_config lcdc_config_t
enum lcdc_display_mode lcdc_display_mode_t
static void lcdc_layer_update_position(LCDC_Type *ptr, uint8_t layer_index, uint16_t x, uint32_t y)
Update specific layer position.
Definition: hpm_lcdc_drv.h:273
lcdc_layer_max_bytes_per_transfer
Definition: hpm_lcdc_drv.h:53
static void lcdc_set_background(LCDC_Type *ptr, display_color_32b_t color)
Set background.
Definition: hpm_lcdc_drv.h:379
static uint32_t lcdc_get_dma_status(LCDC_Type *ptr)
Get DMA status.
Definition: hpm_lcdc_drv.h:178
static bool lcdc_layer_control_shadow_loaded(LCDC_Type *ptr, uint8_t layer_index)
Make layer control shadow registers take effect.
Definition: hpm_lcdc_drv.h:166
static void lcdc_set_testmode(LCDC_Type *ptr, uint8_t test_mode)
Set test mode.
Definition: hpm_lcdc_drv.h:365
static void lcdc_enable_interrupt(LCDC_Type *ptr, uint32_t interrupt_mask)
Enable interrupt according to the given mask.
Definition: hpm_lcdc_drv.h:130
struct lcdc_layer_config lcdc_layer_config_t
static void lcdc_layer_update_background(LCDC_Type *ptr, uint8_t layer_index, display_color_32b_t background)
Update specific layer background.
Definition: hpm_lcdc_drv.h:257
static void lcdc_layer_disable(LCDC_Type *ptr, uint32_t layer_index)
Disable specific layer.
Definition: hpm_lcdc_drv.h:351
static bool lcdc_check_status(LCDC_Type *ptr, uint32_t mask)
Check status against the given mask.
Definition: hpm_lcdc_drv.h:230
struct lcdc_xsync_config lcdc_xsync_config_t
struct lcdc_control lcdc_control_t
static void lcdc_clear_dma_status(LCDC_Type *ptr, uint32_t mask)
Clear DMA status according to the given mask.
Definition: hpm_lcdc_drv.h:204
static void lcdc_enable_background_in_alpha_blender(LCDC_Type *ptr)
enable background on alpha blender
Definition: hpm_lcdc_drv.h:395
void lcdc_turn_on_display(LCDC_Type *ptr)
Turn on display.
Definition: hpm_lcdc_drv.c:281
static bool lcdc_check_dma_status(LCDC_Type *ptr, uint32_t mask)
Check DMA status against the given mask.
Definition: hpm_lcdc_drv.h:192
void lcdc_get_default_layer_config(LCDC_Type *ptr, lcdc_layer_config_t *layer, display_pixel_format_t pixel_format, uint8_t layer_index)
Get default layer configuration value.
Definition: hpm_lcdc_drv.c:51
void lcdc_get_default_config(LCDC_Type *ptr, lcdc_config_t *config)
Get default configuration value.
Definition: hpm_lcdc_drv.c:113
static void lcdc_clear_status(LCDC_Type *ptr, uint32_t mask)
Clear specific status according to the given mask.
Definition: hpm_lcdc_drv.h:154
lcdc_line_pattern
Definition: hpm_lcdc_drv.h:35
static void lcdc_software_reset(LCDC_Type *ptr)
Layer config.
Definition: hpm_lcdc_drv.h:117
lcdc_display_mode
Definition: hpm_lcdc_drv.h:45
hpm_stat_t lcdc_config_layer(LCDC_Type *ptr, uint8_t layer_index, lcdc_layer_config_t *layer_config, bool enable_layer)
Configure specific layer.
Definition: hpm_lcdc_drv.c:192
static void lcdc_disable_background_in_alpha_blender(LCDC_Type *ptr)
disable background on alpha blender
Definition: hpm_lcdc_drv.h:408
static uint32_t lcdc_get_status(LCDC_Type *ptr)
Get status.
Definition: hpm_lcdc_drv.h:216
static void lcdc_layer_update(LCDC_Type *ptr, uint8_t layer_index)
Update specific layer configuration.
Definition: hpm_lcdc_drv.h:326
void lcdc_turn_off_display(LCDC_Type *ptr)
Turn off display.
Definition: hpm_lcdc_drv.c:261
static void lcdc_disable_interrupt(LCDC_Type *ptr, uint32_t interrupt_mask)
Disable interrupt according to the given mask.
Definition: hpm_lcdc_drv.h:142
static void lcdc_layer_enable(LCDC_Type *ptr, uint32_t layer_index)
Enable specific layer.
Definition: hpm_lcdc_drv.h:338
enum lcdc_line_pattern lcdc_line_pattern_t
void lcdc_init(LCDC_Type *ptr, lcdc_config_t *config)
Initialize LCD controller.
Definition: hpm_lcdc_drv.c:165
static void lcdc_layer_set_region(LCDC_Type *ptr, uint8_t layer_index, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Update specific layer region.
Definition: hpm_lcdc_drv.h:309
@ status_lcdc_no_active_layer_yet
Definition: hpm_lcdc_drv.h:30
@ status_lcdc_layer_not_supported
Definition: hpm_lcdc_drv.h:31
@ lcdc_layer_max_bytes_512
Definition: hpm_lcdc_drv.h:57
@ lcdc_layer_max_bytes_1024
Definition: hpm_lcdc_drv.h:58
@ lcdc_layer_max_bytes_256
Definition: hpm_lcdc_drv.h:56
@ lcdc_layer_max_bytes_64
Definition: hpm_lcdc_drv.h:54
@ lcdc_layer_max_bytes_128
Definition: hpm_lcdc_drv.h:55
@ lcdc_line_pattern_gbr
Definition: hpm_lcdc_drv.h:38
@ lcdc_line_pattern_bgr
Definition: hpm_lcdc_drv.h:41
@ lcdc_line_pattern_rbg
Definition: hpm_lcdc_drv.h:37
@ lcdc_line_pattern_rgb
Definition: hpm_lcdc_drv.h:36
@ lcdc_line_pattern_grb
Definition: hpm_lcdc_drv.h:39
@ lcdc_line_pattern_brg
Definition: hpm_lcdc_drv.h:40
@ lcdc_display_mode_test_mode_2
Definition: hpm_lcdc_drv.h:48
@ lcdc_display_mode_normal
Definition: hpm_lcdc_drv.h:46
@ lcdc_display_mode_test_mode_3
Definition: hpm_lcdc_drv.h:49
@ lcdc_display_mode_test_mode_1
Definition: hpm_lcdc_drv.h:47
Definition: hpm_lcdc_regs.h:12
__RW uint32_t BGND_CL
Definition: hpm_lcdc_regs.h:14
struct LCDC_Type::@514 LAYER[8]
__RW uint32_t LAYCTRL
Definition: hpm_lcdc_regs.h:24
__RW uint32_t BG_CL
Definition: hpm_lcdc_regs.h:31
__W uint32_t DMA_ST
Definition: hpm_lcdc_regs.h:18
__RW uint32_t LAYPOS
Definition: hpm_lcdc_regs.h:27
__W uint32_t ST
Definition: hpm_lcdc_regs.h:19
__RW uint32_t CTRL
Definition: hpm_lcdc_regs.h:13
__RW uint32_t LAYSIZE
Definition: hpm_lcdc_regs.h:26
__RW uint32_t START0
Definition: hpm_lcdc_regs.h:28
__RW uint32_t INT_EN
Definition: hpm_lcdc_regs.h:20
display data alphablend option
Definition: hpm_display_common.h:102
display yuv to rgb format conversion config
Definition: hpm_display_common.h:126
Definition: hpm_lcdc_drv.h:80
uint16_t resolution_x
Definition: hpm_lcdc_drv.h:81
lcdc_control_t control
Definition: hpm_lcdc_drv.h:86
lcdc_xsync_config_t vsync
Definition: hpm_lcdc_drv.h:84
uint16_t resolution_y
Definition: hpm_lcdc_drv.h:82
lcdc_xsync_config_t hsync
Definition: hpm_lcdc_drv.h:83
display_color_32b_t background
Definition: hpm_lcdc_drv.h:85
Definition: hpm_lcdc_drv.h:62
bool invert_pixel_data
Definition: hpm_lcdc_drv.h:65
lcdc_display_mode_t display_mode
Definition: hpm_lcdc_drv.h:64
bool invert_hsync
Definition: hpm_lcdc_drv.h:69
bool invert_href
Definition: hpm_lcdc_drv.h:67
lcdc_line_pattern_t line_pattern
Definition: hpm_lcdc_drv.h:63
bool invert_pixel_clock
Definition: hpm_lcdc_drv.h:66
bool invert_vsync
Definition: hpm_lcdc_drv.h:68
Definition: hpm_lcdc_drv.h:90
display_yuv2rgb_config_t csc_config
Definition: hpm_lcdc_drv.h:96
uint16_t height
Definition: hpm_lcdc_drv.h:98
display_yuv_format_t yuv
Definition: hpm_lcdc_drv.h:93
display_color_32b_t background
Definition: hpm_lcdc_drv.h:102
display_pixel_format_t pixel_format
Definition: hpm_lcdc_drv.h:94
display_alphablend_option_t alphablend
Definition: hpm_lcdc_drv.h:95
uint16_t position_x
Definition: hpm_lcdc_drv.h:100
uint32_t stride
Definition: hpm_lcdc_drv.h:104
uint16_t width
Definition: hpm_lcdc_drv.h:99
display_byteorder_t byteorder
Definition: hpm_lcdc_drv.h:92
uint16_t position_y
Definition: hpm_lcdc_drv.h:101
uint32_t buffer
Definition: hpm_lcdc_drv.h:103
uint8_t max_ot
Definition: hpm_lcdc_drv.h:91
lcdc_layer_max_bytes_per_transfer_t max_bytes
Definition: hpm_lcdc_drv.h:97
Definition: hpm_lcdc_drv.h:73
uint16_t front_porch_pulse
Definition: hpm_lcdc_drv.h:74
uint16_t pulse_width
Definition: hpm_lcdc_drv.h:76
uint16_t back_porch_pulse
Definition: hpm_lcdc_drv.h:75
display data 32 bits argb
Definition: hpm_display_common.h:80
uint8_t b
Definition: hpm_display_common.h:83
uint32_t u
Definition: hpm_display_common.h:81
uint8_t r
Definition: hpm_display_common.h:85
uint8_t g
Definition: hpm_display_common.h:84