summaryrefslogtreecommitdiff
path: root/bsp/nxp/imx/imxrt/imxrt1170-nxp-evk/video/display/fbdev/fsl_fbdev.h
blob: 556efa74861462c4df3b982b7c5e4e220b3dc231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 * Copyright 2019-2021, 2023 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef _FSL_FBDEV_H_
#define _FSL_FBDEV_H_

#include "fsl_video_common.h"
#include "fsl_dc_fb.h"
#include "rtthread.h"

/*
 * Change Log:
 *
 * 1.0.3:
 *   - Bug Fixes:
 *     - Fixed the issue that frame buffer content changed when saved
 *       to free frame buffer list.
 *
 * 1.0.2:
 *   - Bug Fixes:
 *     - Fixed MISRA 2012 issues.
 *
 * 1.0.1:
 *   - Bug Fixes:
 *     - Fixed coverity warnings that return values unchedked.
 *
 * 1.0.0:
 *   - Initial version.
 */

/*!
 * @addtogroup fbdev
 * @{
 *
 * To use the fbdev, follow the workflow:
 *
   @code
   uint8_t layer = 0;
   fbdev_t fbdev;
   fbdev_fb_info_t fbInfo;
   extern const dc_fb_t dc;

   FBDEV_Open(&fbdev, &dc, layer);

   fbInfo.bufInfo.pixelFormat = DEMO_BUFFER_PIXEL_FORMAT;
   fbInfo.bufInfo.width       = DEMO_BUFFER_WIDTH;
   fbInfo.bufInfo.height      = DEMO_BUFFER_HEIGHT;
   fbInfo.bufInfo.strideBytes = DEMO_BUFFER_STRIDE_BYTE;
   fbInfo.buffers[0] = DEMO_BUFFER0_ADDR;
   fbInfo.buffers[1] = DEMO_BUFFER1_ADDR;

   FBDEV_SetFrameBufferInfo(&fbdev, &fbInfo);

   buffer = FBDEV_GetFrameBuffer(&fbdev, 0);

   fill the buffer here.

   FBDEV_SetFrameBuffer(&fbdev, buffer, 0);

   FBDEV_Enable(&fbdev);

   buffer = FBDEV_GetFrameBuffer(&fbdev, 0);

   fill the buffer here.

   FBDEV_SetFrameBuffer(&fbdev, buffer, 0);

   ...

   @endcode
 *
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/
/*! @brief How many frame buffers used in each fbdev. */
#ifndef FBDEV_MAX_FRAME_BUFFER
#define FBDEV_MAX_FRAME_BUFFER 3
#endif

#define FBDEV_DEFAULT_FRAME_BUFFER 2

/*! @brief Frame buffer information. */
typedef struct _fbdev_fb_info
{
    uint8_t bufferCount;                   /*!< How many frame buffers used. */
    void *buffers[FBDEV_MAX_FRAME_BUFFER]; /*!< Address of the frame buffers */
    dc_fb_info_t bufInfo;                  /*!< Frame buffers information */
} fbdev_fb_info_t;

/*! @brief FBDEV handle, user should not touch the members directly. */
typedef struct _fbdev
{
    fbdev_fb_info_t fbInfo;                /*!< Frame buffer information. */
    video_stack_t fbManager;               /*!< Manage the framebuffers used by this device. */
    void *buffers[FBDEV_MAX_FRAME_BUFFER]; /*!< Memory used by @ref fbManager, to save the free frame buffers. */
    const dc_fb_t *dc;                     /*!< Display controller handle. */
    uint8_t layer;                         /*!< Layer in the display controller. */
    bool enabled;                          /*!< The fbdev is enabled or not by @ref FBDEV_Enable. */
    rt_sem_t semaFbManager;                /*!< Semaphore for the @ref fbManager. */
    rt_sem_t semaFramePending;             /*!< Semaphore for the @ref framePending. */
} fbdev_t;

/*! @brief Flags used for FBDEV operations. */
enum _fbdev_flag
{
    kFBDEV_NoWait = (1 << 0), /*!< Don't wait until available, but return directly. */
};

/*******************************************************************************
 * API
 ******************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @brief Open the FBDEV.
 *
 * @param fbdev The FBDEV handle.
 * @param dc The display controller used.
 * @param layer The layer in the display controller.
 * @return Returns @ref kStatus_Success if success, otherwise returns
 * error code.
 */
status_t FBDEV_Open(fbdev_t *fbdev, const dc_fb_t *dc, uint8_t layer);

/*!
 * @brief Close the FBDEV.
 *
 * @param fbdev The FBDEV handle.
 * @return Returns @ref kStatus_Success if success, otherwise returns
 * error code.
 */
status_t FBDEV_Close(fbdev_t *fbdev);

/*!
 * @brief Enable the FBDEV.
 *
 * After enabled, the FBDEV will be shown in the panel. This function should be
 * called after @ref FBDEV_SetFrameBufferInfo.
 *
 * @param fbdev The FBDEV handle.
 * @return Returns @ref kStatus_Success if success, otherwise returns
 * error code.
 */
status_t FBDEV_Enable(fbdev_t *fbdev);

/*!
 * @brief Disable the FBDEV.
 *
 * After disabled, the FBDEV will not be shown in the panel. Don't call
 * @ref FBDEV_SetFrameBuffer when the FBDEV is disabled.
 *
 * @param fbdev The FBDEV handle.
 * @return Returns @ref kStatus_Success if success, otherwise returns
 * error code.
 */
status_t FBDEV_Disable(fbdev_t *fbdev);

/*!
 * @brief Get the frame buffer information of the FBDEV.
 *
 * @param fbdev The FBDEV handle.
 * @param info Pointer to the frame buffer information.
 */
void FBDEV_GetFrameBufferInfo(fbdev_t *fbdev, fbdev_fb_info_t *info);

/*!
 * @brief Set the frame buffer information of the FBDEV.
 *
 * This function could be used to configure the FRDEV, including set witdh, height,
 * pixel format, frame buffers, and so on. This function should only be called once
 * after @ref FBDEV_Open and before @ref FBDEV_Enable.
 *
 * @param fbdev The FBDEV handle.
 * @param info Pointer to the frame buffer information.
 * @return Returns @ref kStatus_Success if success, otherwise returns
 * error code.
 */
status_t FBDEV_SetFrameBufferInfo(fbdev_t *fbdev, fbdev_fb_info_t *info);

/*!
 * @brief Get available frame buffer from the FBDEV.
 *
 * Upper layer could call this function to get an available frame buffer from
 * the FBDEV, render send to show.
 *
 * @param fbdev The FBDEV handle.
 * @param flags OR'ed value of @ref _fbdev_flag. If @ref kFBDEV_NoWait is used,
 * the function returns NULL immediately if no available buffer. If @ref kFBDEV_NoWait
 * is not used, this function waits until available.
 *
 * @return Returns the address of the frame buffer. If no available, returns NULL.
 */
void *FBDEV_GetFrameBuffer(fbdev_t *fbdev, uint32_t flags);

/*!
 * @brief Send frame buffer to the FBDEV.
 *
 * Upper layer could call this function to send a frame buffer to the FBDEV. This
 * function should only be used when the FBDEV is enabled.
 *
 * @param fbdev The FBDEV handle.
 * @param flags OR'ed value of @ref _fbdev_flag. If @ref kFBDEV_NoWait is used,
 * the function returns NULL immediately if the previous frame buffer is pending.
 * If @ref kFBDEV_NoWait is not used, this function waits until previous frame
 * buffer not pending.
 *
 * @return Returns @ref kStatus_Success if success, otherwise returns
 * error code.
 */
status_t FBDEV_SetFrameBuffer(fbdev_t *fbdev, void *frameBuffer, uint32_t flags);

#if defined(__cplusplus)
}
#endif

/*! @} */

#endif /* _FSL_FBDEV_H_ */