fsl_fbdev.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright 2019-2021, 2023 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_FBDEV_H_
  8. #define _FSL_FBDEV_H_
  9. #include "fsl_video_common.h"
  10. #include "fsl_dc_fb.h"
  11. #include "rtthread.h"
  12. /*
  13. * Change Log:
  14. *
  15. * 1.0.3:
  16. * - Bug Fixes:
  17. * - Fixed the issue that frame buffer content changed when saved
  18. * to free frame buffer list.
  19. *
  20. * 1.0.2:
  21. * - Bug Fixes:
  22. * - Fixed MISRA 2012 issues.
  23. *
  24. * 1.0.1:
  25. * - Bug Fixes:
  26. * - Fixed coverity warnings that return values unchedked.
  27. *
  28. * 1.0.0:
  29. * - Initial version.
  30. */
  31. /*!
  32. * @addtogroup fbdev
  33. * @{
  34. *
  35. * To use the fbdev, follow the workflow:
  36. *
  37. @code
  38. uint8_t layer = 0;
  39. fbdev_t fbdev;
  40. fbdev_fb_info_t fbInfo;
  41. extern const dc_fb_t dc;
  42. FBDEV_Open(&fbdev, &dc, layer);
  43. fbInfo.bufInfo.pixelFormat = DEMO_BUFFER_PIXEL_FORMAT;
  44. fbInfo.bufInfo.width = DEMO_BUFFER_WIDTH;
  45. fbInfo.bufInfo.height = DEMO_BUFFER_HEIGHT;
  46. fbInfo.bufInfo.strideBytes = DEMO_BUFFER_STRIDE_BYTE;
  47. fbInfo.buffers[0] = DEMO_BUFFER0_ADDR;
  48. fbInfo.buffers[1] = DEMO_BUFFER1_ADDR;
  49. FBDEV_SetFrameBufferInfo(&fbdev, &fbInfo);
  50. buffer = FBDEV_GetFrameBuffer(&fbdev, 0);
  51. fill the buffer here.
  52. FBDEV_SetFrameBuffer(&fbdev, buffer, 0);
  53. FBDEV_Enable(&fbdev);
  54. buffer = FBDEV_GetFrameBuffer(&fbdev, 0);
  55. fill the buffer here.
  56. FBDEV_SetFrameBuffer(&fbdev, buffer, 0);
  57. ...
  58. @endcode
  59. *
  60. */
  61. /*******************************************************************************
  62. * Definitions
  63. ******************************************************************************/
  64. /*! @brief How many frame buffers used in each fbdev. */
  65. #ifndef FBDEV_MAX_FRAME_BUFFER
  66. #define FBDEV_MAX_FRAME_BUFFER 3
  67. #endif
  68. #define FBDEV_DEFAULT_FRAME_BUFFER 2
  69. /*! @brief Frame buffer information. */
  70. typedef struct _fbdev_fb_info
  71. {
  72. uint8_t bufferCount; /*!< How many frame buffers used. */
  73. void *buffers[FBDEV_MAX_FRAME_BUFFER]; /*!< Address of the frame buffers */
  74. dc_fb_info_t bufInfo; /*!< Frame buffers information */
  75. } fbdev_fb_info_t;
  76. /*! @brief FBDEV handle, user should not touch the members directly. */
  77. typedef struct _fbdev
  78. {
  79. fbdev_fb_info_t fbInfo; /*!< Frame buffer information. */
  80. video_stack_t fbManager; /*!< Manage the framebuffers used by this device. */
  81. void *buffers[FBDEV_MAX_FRAME_BUFFER]; /*!< Memory used by @ref fbManager, to save the free frame buffers. */
  82. const dc_fb_t *dc; /*!< Display controller handle. */
  83. uint8_t layer; /*!< Layer in the display controller. */
  84. bool enabled; /*!< The fbdev is enabled or not by @ref FBDEV_Enable. */
  85. rt_sem_t semaFbManager; /*!< Semaphore for the @ref fbManager. */
  86. rt_sem_t semaFramePending; /*!< Semaphore for the @ref framePending. */
  87. } fbdev_t;
  88. /*! @brief Flags used for FBDEV operations. */
  89. enum _fbdev_flag
  90. {
  91. kFBDEV_NoWait = (1 << 0), /*!< Don't wait until available, but return directly. */
  92. };
  93. /*******************************************************************************
  94. * API
  95. ******************************************************************************/
  96. #if defined(__cplusplus)
  97. extern "C" {
  98. #endif
  99. /*!
  100. * @brief Open the FBDEV.
  101. *
  102. * @param fbdev The FBDEV handle.
  103. * @param dc The display controller used.
  104. * @param layer The layer in the display controller.
  105. * @return Returns @ref kStatus_Success if success, otherwise returns
  106. * error code.
  107. */
  108. status_t FBDEV_Open(fbdev_t *fbdev, const dc_fb_t *dc, uint8_t layer);
  109. /*!
  110. * @brief Close the FBDEV.
  111. *
  112. * @param fbdev The FBDEV handle.
  113. * @return Returns @ref kStatus_Success if success, otherwise returns
  114. * error code.
  115. */
  116. status_t FBDEV_Close(fbdev_t *fbdev);
  117. /*!
  118. * @brief Enable the FBDEV.
  119. *
  120. * After enabled, the FBDEV will be shown in the panel. This function should be
  121. * called after @ref FBDEV_SetFrameBufferInfo.
  122. *
  123. * @param fbdev The FBDEV handle.
  124. * @return Returns @ref kStatus_Success if success, otherwise returns
  125. * error code.
  126. */
  127. status_t FBDEV_Enable(fbdev_t *fbdev);
  128. /*!
  129. * @brief Disable the FBDEV.
  130. *
  131. * After disabled, the FBDEV will not be shown in the panel. Don't call
  132. * @ref FBDEV_SetFrameBuffer when the FBDEV is disabled.
  133. *
  134. * @param fbdev The FBDEV handle.
  135. * @return Returns @ref kStatus_Success if success, otherwise returns
  136. * error code.
  137. */
  138. status_t FBDEV_Disable(fbdev_t *fbdev);
  139. /*!
  140. * @brief Get the frame buffer information of the FBDEV.
  141. *
  142. * @param fbdev The FBDEV handle.
  143. * @param info Pointer to the frame buffer information.
  144. */
  145. void FBDEV_GetFrameBufferInfo(fbdev_t *fbdev, fbdev_fb_info_t *info);
  146. /*!
  147. * @brief Set the frame buffer information of the FBDEV.
  148. *
  149. * This function could be used to configure the FRDEV, including set witdh, height,
  150. * pixel format, frame buffers, and so on. This function should only be called once
  151. * after @ref FBDEV_Open and before @ref FBDEV_Enable.
  152. *
  153. * @param fbdev The FBDEV handle.
  154. * @param info Pointer to the frame buffer information.
  155. * @return Returns @ref kStatus_Success if success, otherwise returns
  156. * error code.
  157. */
  158. status_t FBDEV_SetFrameBufferInfo(fbdev_t *fbdev, fbdev_fb_info_t *info);
  159. /*!
  160. * @brief Get available frame buffer from the FBDEV.
  161. *
  162. * Upper layer could call this function to get an available frame buffer from
  163. * the FBDEV, render send to show.
  164. *
  165. * @param fbdev The FBDEV handle.
  166. * @param flags OR'ed value of @ref _fbdev_flag. If @ref kFBDEV_NoWait is used,
  167. * the function returns NULL immediately if no available buffer. If @ref kFBDEV_NoWait
  168. * is not used, this function waits until available.
  169. *
  170. * @return Returns the address of the frame buffer. If no available, returns NULL.
  171. */
  172. void *FBDEV_GetFrameBuffer(fbdev_t *fbdev, uint32_t flags);
  173. /*!
  174. * @brief Send frame buffer to the FBDEV.
  175. *
  176. * Upper layer could call this function to send a frame buffer to the FBDEV. This
  177. * function should only be used when the FBDEV is enabled.
  178. *
  179. * @param fbdev The FBDEV handle.
  180. * @param flags OR'ed value of @ref _fbdev_flag. If @ref kFBDEV_NoWait is used,
  181. * the function returns NULL immediately if the previous frame buffer is pending.
  182. * If @ref kFBDEV_NoWait is not used, this function waits until previous frame
  183. * buffer not pending.
  184. *
  185. * @return Returns @ref kStatus_Success if success, otherwise returns
  186. * error code.
  187. */
  188. status_t FBDEV_SetFrameBuffer(fbdev_t *fbdev, void *frameBuffer, uint32_t flags);
  189. #if defined(__cplusplus)
  190. }
  191. #endif
  192. /*! @} */
  193. #endif /* _FSL_FBDEV_H_ */