aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/driver_dc-fb-common.cmake24
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/driver_dc-fb-elcdif.cmake17
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.c263
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.h101
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/fsl_dc_fb.h80
5 files changed, 485 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/driver_dc-fb-common.cmake b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/driver_dc-fb-common.cmake
new file mode 100644
index 000000000..49fcb137d
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/driver_dc-fb-common.cmake
@@ -0,0 +1,24 @@
1if(NOT DRIVER_DC-FB-COMMON_INCLUDED)
2
3 set(DRIVER_DC-FB-COMMON_INCLUDED true CACHE BOOL "driver_dc-fb-common component is included.")
4
5 target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
6 )
7
8 target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
9 ${CMAKE_CURRENT_LIST_DIR}/.
10 )
11
12 #OR Logic component
13 if(${MCUX_DEVICE} STREQUAL "MIMXRT1052")
14 include(driver_video-common)
15 endif()
16 if(${MCUX_DEVICE} STREQUAL "MIMXRT1064")
17 include(driver_video-common)
18 endif()
19 if(${MCUX_DEVICE} STREQUAL "MIMXRT1062")
20 include(driver_video-common)
21 endif()
22
23
24endif() \ No newline at end of file
diff --git a/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/driver_dc-fb-elcdif.cmake b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/driver_dc-fb-elcdif.cmake
new file mode 100644
index 000000000..d39ac25f6
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/driver_dc-fb-elcdif.cmake
@@ -0,0 +1,17 @@
1if(NOT DRIVER_DC-FB-ELCDIF_INCLUDED)
2
3 set(DRIVER_DC-FB-ELCDIF_INCLUDED true CACHE BOOL "driver_dc-fb-elcdif component is included.")
4
5 target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
6 ${CMAKE_CURRENT_LIST_DIR}/fsl_dc_fb_elcdif.c
7 )
8
9 target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
10 ${CMAKE_CURRENT_LIST_DIR}/.
11 )
12
13
14 include(driver_dc-fb-common)
15 include(driver_elcdif)
16
17endif() \ No newline at end of file
diff --git a/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.c b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.c
new file mode 100644
index 000000000..17faf688f
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.c
@@ -0,0 +1,263 @@
1/*
2 * Copyright 2019-2020 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include "fsl_dc_fb_elcdif.h"
9
10/*******************************************************************************
11 * Definitions
12 ******************************************************************************/
13const dc_fb_ops_t g_dcFbOpsElcdif = {
14 .init = DC_FB_ELCDIF_Init,
15 .deinit = DC_FB_ELCDIF_Deinit,
16 .enableLayer = DC_FB_ELCDIF_EnableLayer,
17 .disableLayer = DC_FB_ELCDIF_DisableLayer,
18 .setLayerConfig = DC_FB_ELCDIF_SetLayerConfig,
19 .getLayerDefaultConfig = DC_FB_ELCDIF_GetLayerDefaultConfig,
20 .setFrameBuffer = DC_FB_ELCDIF_SetFrameBuffer,
21 .getProperty = DC_FB_ELCDIF_GetProperty,
22 .setCallback = DC_FB_ELCDIF_SetCallback,
23};
24
25typedef struct
26{
27 video_pixel_format_t videoFormat;
28 elcdif_pixel_format_t elcdifFormat;
29} dc_fb_elcdif_pixel_foramt_map_t;
30
31/*******************************************************************************
32 * Prototypes
33 ******************************************************************************/
34static status_t DC_FB_ELCDIF_GetPixelFormat(video_pixel_format_t input, elcdif_pixel_format_t *output);
35
36/*******************************************************************************
37 * Variables
38 ******************************************************************************/
39static const dc_fb_elcdif_pixel_foramt_map_t s_elcdifPixelFormatMap[] = {
40 {kVIDEO_PixelFormatRGB565, kELCDIF_PixelFormatRGB565},
41 {
42 kVIDEO_PixelFormatXRGB8888,
43 kELCDIF_PixelFormatXRGB8888,
44 },
45 {
46 kVIDEO_PixelFormatRGB888,
47 kELCDIF_PixelFormatRGB888,
48 }};
49
50/*******************************************************************************
51 * Code
52 ******************************************************************************/
53static status_t DC_FB_ELCDIF_GetPixelFormat(video_pixel_format_t input, elcdif_pixel_format_t *output)
54{
55 uint8_t i;
56
57 for (i = 0; i < ARRAY_SIZE(s_elcdifPixelFormatMap); i++)
58 {
59 if (s_elcdifPixelFormatMap[i].videoFormat == input)
60 {
61 *output = s_elcdifPixelFormatMap[i].elcdifFormat;
62 return kStatus_Success;
63 }
64 }
65
66 return kStatus_InvalidArgument;
67}
68
69status_t DC_FB_ELCDIF_Init(const dc_fb_t *dc)
70{
71 const dc_fb_elcdif_config_t *dcConfig;
72 elcdif_rgb_mode_config_t elcdifConfig = {0};
73
74 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
75
76 if (0U == dcHandle->initTimes++)
77 {
78 dcConfig = (const dc_fb_elcdif_config_t *)(dc->config);
79
80 elcdifConfig.panelWidth = dcConfig->width;
81 elcdifConfig.panelHeight = dcConfig->height;
82 elcdifConfig.hsw = (uint8_t)dcConfig->hsw;
83 elcdifConfig.hfp = (uint8_t)dcConfig->hfp;
84 elcdifConfig.hbp = (uint8_t)dcConfig->hbp;
85 elcdifConfig.vsw = (uint8_t)dcConfig->vsw;
86 elcdifConfig.vfp = (uint8_t)dcConfig->vfp;
87 elcdifConfig.vbp = (uint8_t)dcConfig->vbp;
88 elcdifConfig.bufferAddr = 0;
89 elcdifConfig.dataBus = dcConfig->dataBus;
90 elcdifConfig.pixelFormat = DC_FB_ELCDIF_DEFAULT_PIXEL_FORMAT_ELCDIF;
91 elcdifConfig.polarityFlags = dcConfig->polarityFlags;
92
93 dcHandle->height = dcConfig->height;
94 dcHandle->width = dcConfig->width;
95 dcHandle->elcdif = dcConfig->elcdif;
96
97 ELCDIF_RgbModeInit(dcHandle->elcdif, &elcdifConfig);
98 }
99
100 return kStatus_Success;
101}
102
103status_t DC_FB_ELCDIF_Deinit(const dc_fb_t *dc)
104{
105 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
106
107 if (dcHandle->initTimes > 0U)
108 {
109 if ((--dcHandle->initTimes) == 0U)
110 {
111 ELCDIF_Deinit(dcHandle->elcdif);
112 }
113 }
114
115 return kStatus_Success;
116}
117
118status_t DC_FB_ELCDIF_EnableLayer(const dc_fb_t *dc, uint8_t layer)
119{
120 assert(layer < DC_FB_ELCDIF_MAX_LAYER);
121
122 status_t status = kStatus_Success;
123 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
124
125 /* If the layer is already started. */
126 if (!dcHandle->layers[layer].enabled)
127 {
128 /* Must have valid frame buffer to show. */
129 if (dcHandle->layers[layer].activeBuffer == NULL)
130 {
131 status = kStatus_Fail;
132 }
133 else
134 {
135 ELCDIF_RgbModeStart(dcHandle->elcdif);
136 dcHandle->layers[layer].enabled = true;
137 ELCDIF_EnableInterrupts(dcHandle->elcdif, (uint32_t)kELCDIF_CurFrameDoneInterruptEnable);
138 }
139 }
140
141 return status;
142}
143
144status_t DC_FB_ELCDIF_DisableLayer(const dc_fb_t *dc, uint8_t layer)
145{
146 assert(layer < DC_FB_ELCDIF_MAX_LAYER);
147
148 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
149
150 if (dcHandle->layers[layer].enabled)
151 {
152 ELCDIF_RgbModeStop(dcHandle->elcdif);
153 dcHandle->layers[layer].enabled = false;
154 ELCDIF_DisableInterrupts(dcHandle->elcdif, (uint32_t)kELCDIF_CurFrameDoneInterruptEnable);
155 }
156
157 return kStatus_Success;
158}
159
160status_t DC_FB_ELCDIF_SetLayerConfig(const dc_fb_t *dc, uint8_t layer, dc_fb_info_t *fbInfo)
161{
162 assert(layer < DC_FB_ELCDIF_MAX_LAYER);
163
164 elcdif_pixel_format_t pixelFormat;
165 status_t status;
166
167 dc_fb_elcdif_handle_t *dcHandle = (dc_fb_elcdif_handle_t *)(dc->prvData);
168
169 assert(fbInfo->startX == 0U);
170 assert(fbInfo->startY == 0U);
171 assert(fbInfo->width == dcHandle->width);
172 assert(fbInfo->height == dcHandle->height);
173 assert(fbInfo->strideBytes == VIDEO_GetPixelSizeBits(fbInfo->pixelFormat) * dcHandle->width / 8U);
174
175 status = DC_FB_ELCDIF_GetPixelFormat(fbInfo->pixelFormat, &pixelFormat);
176 if (kStatus_Success != status)
177 {
178 return status;
179 }
180
181 ELCDIF_RgbModeSetPixelFormat(dcHandle->elcdif, pixelFormat);
182
183 return kStatus_Success;
184}
185
186status_t DC_FB_ELCDIF_GetLayerDefaultConfig(const dc_fb_t *dc, uint8_t layer, dc_fb_info_t *fbInfo)
187{
188 assert(layer < DC_FB_ELCDIF_MAX_LAYER);
189
190 dc_fb_elcdif_handle_t *dcHandle = (dc_fb_elcdif_handle_t *)(dc->prvData);
191
192 fbInfo->startX = 0;
193 fbInfo->startY = 0;
194 fbInfo->width = dcHandle->width;
195 fbInfo->height = dcHandle->height;
196 fbInfo->strideBytes = 2U * dcHandle->width;
197 fbInfo->pixelFormat = DC_FB_ELCDIF_DEFAULT_PIXEL_FORMAT;
198
199 return kStatus_Success;
200}
201
202status_t DC_FB_ELCDIF_SetFrameBuffer(const dc_fb_t *dc, uint8_t layer, void *frameBuffer)
203{
204 assert(layer < DC_FB_ELCDIF_MAX_LAYER);
205 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
206
207 ELCDIF_SetNextBufferAddr(dcHandle->elcdif, (uint32_t)(uint8_t *)frameBuffer);
208 dcHandle->layers[layer].inactiveBuffer = frameBuffer;
209
210 /*
211 * If the layer is not started, set the current buffer and next buffer to
212 * new frame buffer, there is not pending frame.
213 * If the layer already started, only set the next buffer, and the new frameBuffer
214 * is pending until current buffer switched out.
215 */
216 if (!dcHandle->layers[layer].enabled)
217 {
218 dcHandle->elcdif->CUR_BUF = (uint32_t)(uint8_t *)frameBuffer;
219 dcHandle->layers[layer].activeBuffer = frameBuffer;
220 }
221 else
222 {
223 dcHandle->layers[layer].framePending = true;
224 }
225
226 return kStatus_Success;
227}
228
229void DC_FB_ELCDIF_SetCallback(const dc_fb_t *dc, uint8_t layer, dc_fb_callback_t callback, void *param)
230{
231 assert(layer < DC_FB_ELCDIF_MAX_LAYER);
232 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
233
234 dcHandle->layers[layer].callback = callback;
235 dcHandle->layers[layer].cbParam = param;
236}
237
238uint32_t DC_FB_ELCDIF_GetProperty(const dc_fb_t *dc)
239{
240 return (uint32_t)kDC_FB_ReserveFrameBuffer;
241}
242
243void DC_FB_ELCDIF_IRQHandler(const dc_fb_t *dc)
244{
245 dc_fb_elcdif_handle_t *dcHandle = dc->prvData;
246 dc_fb_elcdif_layer_t *layer;
247 void *oldActiveBuffer;
248 ELCDIF_ClearInterruptStatus(dcHandle->elcdif, (uint32_t)kELCDIF_CurFrameDone);
249
250 for (uint8_t i = 0; i < DC_FB_ELCDIF_MAX_LAYER; i++)
251 {
252 if (dcHandle->layers[i].framePending)
253 {
254 layer = &dcHandle->layers[i];
255
256 oldActiveBuffer = layer->activeBuffer;
257 layer->activeBuffer = layer->inactiveBuffer;
258 dcHandle->layers[i].framePending = false;
259
260 layer->callback(layer->cbParam, oldActiveBuffer);
261 }
262 }
263}
diff --git a/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.h b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.h
new file mode 100644
index 000000000..09be21405
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/elcdif/fsl_dc_fb_elcdif.h
@@ -0,0 +1,101 @@
1/*
2 * Copyright 2019-2020 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _FSL_DC_FB_ELCDIF_H_
9#define _FSL_DC_FB_ELCDIF_H_
10
11#include "fsl_dc_fb.h"
12#include "fsl_elcdif.h"
13
14/*
15 * Change log:
16 *
17 * 1.0.1
18 * - Fixed MISRA-C 2012 issues.
19 *
20 * 1.0.0
21 * - Initial version
22 */
23
24/*!
25 * @addtogroup dc_fb_elcdif
26 * @{
27 */
28
29/*******************************************************************************
30 * Definitions
31 ******************************************************************************/
32
33#define DC_FB_ELCDIF_MAX_LAYER 1U /* Only support one layer currently. */
34#define DC_FB_ELCDIF_DEFAULT_PIXEL_FORMAT kVIDEO_PixelFormatRGB565
35#define DC_FB_ELCDIF_DEFAULT_PIXEL_FORMAT_ELCDIF kELCDIF_PixelFormatRGB565
36
37/*! @brief Data for ELCDIF display controller layer. */
38typedef struct _dc_fb_elcdif_layer
39{
40 bool enabled; /*!< The layer is enabled. */
41 volatile bool framePending; /*!< New frame pending. */
42 void *activeBuffer; /*!< The frame buffer which is shown. */
43 void *inactiveBuffer; /*!< The frame buffer which will be shown. */
44 dc_fb_callback_t callback; /*!< Callback for buffer switch off. */
45 void *cbParam; /*!< Callback parameter. */
46} dc_fb_elcdif_layer_t;
47
48/*! @brief Data for ELCDIF display controller driver handle. */
49typedef struct _dc_fb_elcdif_handle
50{
51 LCDIF_Type *elcdif; /*!< eLCDIF peripheral. */
52 uint8_t initTimes; /*!< How many times the DC is initialized. */
53 uint16_t height; /*!< Panel height. */
54 uint16_t width; /*!< Panel width. */
55 dc_fb_elcdif_layer_t layers[DC_FB_ELCDIF_MAX_LAYER]; /*!< Information of the layer. */
56} dc_fb_elcdif_handle_t;
57
58/*! @brief Configuration for ELCDIF display controller driver handle. */
59typedef struct _dc_fb_elcdif_config
60{
61 LCDIF_Type *elcdif; /*!< ELCDIF peripheral. */
62 uint16_t width; /*!< Width of the panel. */
63 uint16_t height; /*!< Height of the panel. */
64 uint16_t hsw; /*!< HSYNC pulse width. */
65 uint16_t hfp; /*!< Horizontal front porch. */
66 uint16_t hbp; /*!< Horizontal back porch. */
67 uint16_t vsw; /*!< VSYNC pulse width. */
68 uint16_t vfp; /*!< Vertical front porch. */
69 uint16_t vbp; /*!< Vertical back porch. */
70 uint32_t polarityFlags; /*!< Control flags, OR'ed value of @ref _elcdif_polarity_flags. */
71 elcdif_lcd_data_bus_t dataBus; /*!< LCD data bus. */
72} dc_fb_elcdif_config_t;
73
74extern const dc_fb_ops_t g_dcFbOpsElcdif;
75
76/*******************************************************************************
77 * API
78 ******************************************************************************/
79
80#if defined(__cplusplus)
81extern "C" {
82#endif
83
84status_t DC_FB_ELCDIF_Init(const dc_fb_t *dc);
85status_t DC_FB_ELCDIF_Deinit(const dc_fb_t *dc);
86status_t DC_FB_ELCDIF_EnableLayer(const dc_fb_t *dc, uint8_t layer);
87status_t DC_FB_ELCDIF_DisableLayer(const dc_fb_t *dc, uint8_t layer);
88status_t DC_FB_ELCDIF_SetLayerConfig(const dc_fb_t *dc, uint8_t layer, dc_fb_info_t *fbInfo);
89status_t DC_FB_ELCDIF_GetLayerDefaultConfig(const dc_fb_t *dc, uint8_t layer, dc_fb_info_t *fbInfo);
90status_t DC_FB_ELCDIF_SetFrameBuffer(const dc_fb_t *dc, uint8_t layer, void *frameBuffer);
91uint32_t DC_FB_ELCDIF_GetProperty(const dc_fb_t *dc);
92void DC_FB_ELCDIF_SetCallback(const dc_fb_t *dc, uint8_t layer, dc_fb_callback_t callback, void *param);
93void DC_FB_ELCDIF_IRQHandler(const dc_fb_t *dc);
94
95#if defined(__cplusplus)
96}
97#endif
98
99/*! @} */
100
101#endif /* _FSL_DC_FB_ELCDIF_H_ */
diff --git a/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/fsl_dc_fb.h b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/fsl_dc_fb.h
new file mode 100644
index 000000000..a81b15b93
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/components/video/display/dc/fsl_dc_fb.h
@@ -0,0 +1,80 @@
1/*
2 * Copyright 2019 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _FSL_DC_FB_H_
9#define _FSL_DC_FB_H_
10
11#include "fsl_video_common.h"
12
13/*!
14 * @addtogroup dc_fb
15 * @{
16 */
17
18/*******************************************************************************
19 * Definitions
20 ******************************************************************************/
21/*! @brief frame buffer information. */
22typedef struct _dc_fb_info
23{
24 uint16_t startX; /*!< The start position in the panel. */
25 uint16_t startY; /*!< The start position in the panel. */
26 uint16_t width; /*!< How many pixels in one line of the frame buffer.*/
27 uint16_t height; /*!< How many lines in one frame buffer. */
28 uint16_t strideBytes; /*!< Stride of the frame buffer */
29 video_pixel_format_t pixelFormat; /*!< Pixel format of the frame buffer */
30} dc_fb_info_t;
31
32/*! @brief Display controller frame callback. */
33typedef void (*dc_fb_callback_t)(void *param, void *inactiveBuffer);
34
35/*! @brief Display controller. */
36typedef struct _dc_fb dc_fb_t;
37
38/*! @brief Display controller operations. */
39typedef struct _dc_fb_ops
40{
41 status_t (*init)(const dc_fb_t *dc);
42 status_t (*deinit)(const dc_fb_t *dc);
43 status_t (*enableLayer)(const dc_fb_t *dc, uint8_t layer);
44 status_t (*disableLayer)(const dc_fb_t *dc, uint8_t layer);
45 status_t (*setLayerConfig)(const dc_fb_t *dc, uint8_t layer, dc_fb_info_t *fbInfo);
46 status_t (*getLayerDefaultConfig)(const dc_fb_t *dc, uint8_t layer, dc_fb_info_t *fbInfo);
47 status_t (*setFrameBuffer)(const dc_fb_t *dc, uint8_t layer, void *frameBuffer);
48 uint32_t (*getProperty)(const dc_fb_t *dc);
49 void (*setCallback)(const dc_fb_t *dc, uint8_t layer, dc_fb_callback_t callback, void *param);
50} dc_fb_ops_t;
51
52/*! @brief Display controller property. */
53enum _dc_fb_property
54{
55 kDC_FB_ReserveFrameBuffer = (1 << 0), /*< One frame buffer is always used as the DC active buffer. */
56};
57
58/*! @brief Display controller driver handle. */
59struct _dc_fb
60{
61 const dc_fb_ops_t *ops; /* Display controller operations. */
62 void *prvData; /* Private data for the display controller. */
63 const void *config; /* Configuration for the display controller. */
64};
65
66/*******************************************************************************
67 * API
68 ******************************************************************************/
69
70#if defined(__cplusplus)
71extern "C" {
72#endif
73
74#if defined(__cplusplus)
75}
76#endif
77
78/*! @} */
79
80#endif /* _FSL_DC_FB_H_ */