1 /*
2  * Copyright 2019-2020 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_PRG_H_
9 #define _FSL_PRG_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup prg
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 /*! @brief Driver version. */
22 #define FSL_PRG_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
23 
24 /*!
25  * @brief Data type of the frame buffer.
26  */
27 typedef enum _prg_data_type
28 {
29     kPRG_DataType32Bpp = 0x0U, /*!< 32 bits per pixel. */
30     kPRG_DataType24Bpp,        /*!< 24 bits per pixel. */
31     kPRG_DataType16Bpp,        /*!< 16 bits per pixel. */
32     kPRG_DataType8Bpp,         /*!< 8 bits per pixel. */
33 } prg_data_type_t;
34 
35 /*!
36  * @brief Frame buffer configuration.
37  */
38 typedef struct _prg_buffer_config
39 {
40     uint16_t width;           /*!< Frame buffer width. */
41     uint16_t height;          /*!< Frame buffer height. */
42     uint16_t strideBytes;     /*!< Stride, must be 8 bytes aligned. */
43     prg_data_type_t dataType; /*!< Data type. */
44 } prg_buffer_config_t;
45 
46 /*******************************************************************************
47  * API
48  ******************************************************************************/
49 
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53 
54 /*!
55  * @brief Enables and configures the PRG peripheral module.
56  *
57  * @param base PRG peripheral address.
58  */
59 void PRG_Init(PRG_Type *base);
60 
61 /*!
62  * @brief Disables the PRG peripheral module.
63  *
64  * @param base PRG peripheral address.
65  */
66 void PRG_Deinit(PRG_Type *base);
67 
68 /*!
69  * @brief Enable or disable the PRG.
70  *
71  * If enabled, display controller fetches data from PRG. If disabled, display
72  * controller fetches data from frame buffer.
73  *
74  * @param base PRG peripheral address.
75  * @param enable Pass in true to enable, false to disable
76  */
PRG_Enable(PRG_Type * base,bool enable)77 static inline void PRG_Enable(PRG_Type *base, bool enable)
78 {
79     if (enable)
80     {
81         base->PRG_CTRL.CLR = PRG_PRG_CTRL_BYPASS_MASK;
82     }
83     else
84     {
85         base->PRG_CTRL.SET = PRG_PRG_CTRL_BYPASS_MASK;
86     }
87 }
88 
89 /*!
90  * @brief Enable or disable the shadow load.
91  *
92  * If disabled, the function @ref PRG_UpdateRegister makes the new configurations
93  * take effect immediately. If enabled, after calling @ref PRG_UpdateRegister,
94  * the new configurations take effect at next frame.
95  *
96  * @param base PRG peripheral address.
97  * @param enable Pass in true to enable, false to disable
98  */
PRG_EnableShadowLoad(PRG_Type * base,bool enable)99 static inline void PRG_EnableShadowLoad(PRG_Type *base, bool enable)
100 {
101     if (enable)
102     {
103         base->PRG_CTRL.SET = PRG_PRG_CTRL_SHADOW_EN_MASK;
104     }
105     else
106     {
107         base->PRG_CTRL.CLR = PRG_PRG_CTRL_SHADOW_EN_MASK;
108     }
109 }
110 
111 /*!
112  * @brief Update the registers.
113  *
114  * New configurations set to PRG registers will not take effect immediately until
115  * this function is called. If the shadow is disabled by @ref PRG_EnableShadowLoad,
116  * the new configurations take effect immediately after this function is called.
117  * If the shadow is enabled by @ref PRG_EnableShadowLoad, the new configurations
118  * take effect at next frame after this function is called.
119  *
120  * @param base PRG peripheral address.
121  */
PRG_UpdateRegister(PRG_Type * base)122 static inline void PRG_UpdateRegister(PRG_Type *base)
123 {
124     base->PRG_REG_UPDATE.RW = PRG_PRG_REG_UPDATE_REG_UPDATE_MASK;
125 }
126 
127 /*!
128  * @brief Set the frame buffer configuration.
129  *
130  * @param base PRG peripheral address.
131  * @param config Pointer to the configuration.
132  */
133 void PRG_SetBufferConfig(PRG_Type *base, const prg_buffer_config_t *config);
134 
135 /*!
136  * @brief Get the frame buffer default configuration.
137  *
138  * The default configuration is:
139  *
140  * @code
141     config->width = 1080U;
142     config->height = 1920U;
143     config->strideBytes = 4U * 1080U;
144     config->dataType = kPRG_DataType32Bpp;
145    @endcode
146  *
147  * @param config Pointer to the configuration.
148  */
149 void PRG_BufferGetDefaultConfig(prg_buffer_config_t *config);
150 
151 /*!
152  * @brief Set the frame buffer address.
153  *
154  * @param base PRG peripheral address.
155  * @param addr Frame buffer address.
156  */
PRG_SetBufferAddr(PRG_Type * base,uint32_t addr)157 static inline void PRG_SetBufferAddr(PRG_Type *base, uint32_t addr)
158 {
159     base->PRG_BADDR.RW = addr;
160 }
161 
162 #if defined(__cplusplus)
163 }
164 #endif
165 
166 /*!
167  * @}
168  */
169 #endif /* _FSL_PRG_H_ */
170