1 /*
2  * Copyright  2017-2018 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_DISPLAY_H_
10 #define _FSL_DISPLAY_H_
11 
12 #include "fsl_video_common.h"
13 
14 /*******************************************************************************
15  * Definitions
16  ******************************************************************************/
17 
18 /*! @brief Display common configuration. */
19 typedef struct _display_common_cfg_t
20 {
21     uint16_t width;
22     uint16_t height;
23     uint16_t hsw; /*!< HSYNC pulse width. */
24     uint16_t hfp; /*!< Horizontal front porch. */
25     uint16_t hbp; /*!< Horizontal back porch. */
26     uint16_t vsw; /*!< VSYNC pulse width. */
27     uint16_t vfp; /*!< Vrtical front porch. */
28     uint16_t vbp; /*!< Vertical back porch. */
29     uint32_t clock; /* !< pixecl clock in kHz>. */
30 } display_common_cfg;
31 
32 /*! @brief Display control flags. */
33 enum _display_flags
34 {
35     kDISPLAY_VsyncActiveLow         = 0U,         /*!< VSYNC active low. */
36     kDISPLAY_VsyncActiveHigh        = (1U << 0U), /*!< VSYNC active high. */
37     kDISPLAY_HsyncActiveLow         = 0U,         /*!< HSYNC active low. */
38     kDISPLAY_HsyncActiveHigh        = (1U << 1U), /*!< HSYNC active high. */
39     kDISPLAY_DataEnableActiveHigh   = 0U,         /*!< Data enable line active high. */
40     kDISPLAY_DataEnableActiveLow    = (1U << 2U), /*!< Data enable line active low. */
41     kDISPLAY_DataLatchOnRisingEdge  = 0U,         /*!< Latch data on rising clock edge. */
42     kDISPLAY_DataLatchOnFallingEdge = (1U << 3U), /*!< Latch data on falling clock edge. */
43 };
44 
45 /*! @brief Display configuration. */
46 typedef struct _display_config
47 {
48     uint32_t resolution;              /*!< Resolution, see @ref video_resolution_t and @ref FSL_VIDEO_RESOLUTION. */
49     uint16_t hsw;                     /*!< HSYNC pulse width. */
50     uint16_t hfp;                     /*!< Horizontal front porch. */
51     uint16_t hbp;                     /*!< Horizontal back porch. */
52     uint16_t vsw;                     /*!< VSYNC pulse width. */
53     uint16_t vfp;                     /*!< Vrtical front porch. */
54     uint16_t vbp;                     /*!< Vertical back porch. */
55     uint32_t controlFlags;            /*!< Control flags, OR'ed value of @ref _display_flags. */
56     uint8_t dsiLanes;                 /*!< MIPI DSI data lanes number. */
57     uint32_t pixelClock_Hz;           /*!< Pixel clock in Hz. */
58     video_pixel_format_t pixelFormat; /*!< Pixel format. */
59 } display_config_t;
60 
61 typedef struct _display_handle display_handle_t;
62 
63 /*! @brief Display device operations. */
64 typedef struct _display_operations
65 {
66     status_t (*init)(display_handle_t *handle, const display_config_t *config); /*!< Init the device. */
67     status_t (*deinit)(display_handle_t *handle);                               /*!< Deinit the device. */
68     status_t (*start)(display_handle_t *handle);                                /*!< Start the device. */
69     status_t (*stop)(display_handle_t *handle);                                 /*!< Stop the device. */
70 } display_operations_t;
71 
72 /*! @brief Display handle. */
73 struct _display_handle
74 {
75     const void *resource;
76     const display_operations_t *ops;
77     uint16_t width;
78     uint16_t height;
79     video_pixel_format_t pixelFormat;
80 };
81 
82 /*******************************************************************************
83  * API
84  ******************************************************************************/
85 
86 #if defined(__cplusplus)
87 extern "C" {
88 #endif
89 
90 /*!
91  * @brief Initializes the display device with user defined configuration.
92  *
93  * @param handle Display device handle.
94  * @param config Pointer to the user-defined configuration structure.
95  * @return Returns @ref kStatus_Success if initialize success, otherwise returns
96  * error code.
97  */
DISPLAY_Init(display_handle_t * handle,const display_config_t * config)98 static inline status_t DISPLAY_Init(display_handle_t *handle, const display_config_t *config)
99 {
100     return handle->ops->init(handle, config);
101 }
102 
103 /*!
104  * @brief Deinitialize the display device.
105  *
106  * @param handle Display device handle.
107  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
108  */
DISPLAY_Deinit(display_handle_t * handle)109 static inline status_t DISPLAY_Deinit(display_handle_t *handle)
110 {
111     return handle->ops->deinit(handle);
112 }
113 
114 /*!
115  * @brief Start the display device.
116  *
117  * @param handle Display device handle.
118  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
119  */
DISPLAY_Start(display_handle_t * handle)120 static inline status_t DISPLAY_Start(display_handle_t *handle)
121 {
122     return handle->ops->start(handle);
123 }
124 
125 /*!
126  * @brief Stop the display device.
127  *
128  * @param handle Display device handle.
129  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
130  */
DISPLAY_Stop(display_handle_t * handle)131 static inline status_t DISPLAY_Stop(display_handle_t *handle)
132 {
133     return handle->ops->stop(handle);
134 }
135 
136 #if defined(__cplusplus)
137 }
138 #endif
139 
140 #endif /* _FSL_DISPLAY_H_ */
141