1 /** 2 * @file clcd.h 3 * @brief Color LCD function prototypes and data types. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 /* Define to prevent redundant inclusion */ 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_CLCD_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_CLCD_H_ 29 30 /* **** Includes **** */ 31 #include "mxc_device.h" 32 #include "clcd_regs.h" 33 #include "mxc_sys.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * @defgroup clcd Color LCD 41 * @ingroup periphlibs 42 * @{ 43 */ 44 45 /* **** Definitions **** */ 46 /** 47 * @brief Enumeration type for setting the number Bits per Pixel for the LCD screen 48 * 49 */ 50 typedef enum { 51 MXC_CLCD_STN, 52 MXC_CLCD_TFT, 53 } mxc_clcd_disp_t; 54 55 /** 56 * @brief Enumeration type for the color mode used in 16bit color depth 57 * 58 */ 59 typedef enum { 60 RGB565, 61 BGR556, 62 } mxc_clcd_color_t; 63 64 /** 65 * @brief The information required to completely configure the CLCD to match 66 * a particular screen. 67 * 68 * This can be used with the CLCD_Config() function to configure the 69 * CLCD and prepare it for outputting data to the screen. 70 */ 71 typedef struct clcd_cfg { 72 uint32_t Width; ///< The visible width of the display in pixels 73 uint32_t Height; ///< The visible height of the display in pixels 74 uint32_t ClkFreq; ///< The requested bit clock frequency in Hz 75 uint32_t VertFrontPorch; ///< The vertical front porch size in lines 76 uint32_t VertBackPorch; ///< The vertical back porch size in lines 77 uint32_t VSYNCPulseWidth; ///< The width of the VSYNC pulse in line clocks 78 uint32_t HorizFrontPorch; ///< The horizontal front porch size in lines 79 uint32_t HorizBackPorch; ///< The horizontal back porch size in lines 80 uint32_t HSYNCPulseWidth; ///< The width of the HSYNC pulse in bit clocks 81 uint32_t *palette; ///< Pointer to the color palette data (used for bpp < 16) 82 uint32_t paletteSize; ///< Size of the color palette data (must be 768 bytes) 83 uint32_t bpp; ///< Number of bits per pixel (see users guide for values) 84 void *frameBuffer; ///< Pointer to the frame buffer, this must remain allocated 85 ///< the entire time the CLCD is in use, unless the frameBuffer 86 ///< pointer is changed with CLCD_SetFrameBuffer 87 } mxc_clcd_cfg_t; 88 89 /* **** Function Prototypes **** */ 90 91 /** 92 * @brief Initialize the clcd. 93 * 94 * @return See \ref MXC_Error_Codes for the list of error return codes. 95 */ 96 int MXC_CLCD_Init(void); 97 98 /** 99 * @brief Shutdown CLCD module. 100 * @return See \ref MXC_Error_Codes for the list of error return codes. 101 */ 102 int MXC_CLCD_Shutdown(void); 103 104 /** 105 * @brief Enable CLCD. 106 * @return See \ref MXC_Error_Codes for the list of error return codes. 107 */ 108 int MXC_CLCD_Enable(void); 109 110 /** 111 * @brief Disable CLCD. 112 * @return See \ref MXC_Error_Codes for the list of error return codes. 113 */ 114 int MXC_CLCD_Disable(void); 115 116 /** 117 * @brief Set the CLCD clock frequency 118 * 119 * @param hz The frequency of the CLCD_CLK in Hz 120 * 121 * @return The actual frequency set in Hz 122 */ 123 int MXC_CLCD_SetFrequency(int hz); 124 125 /** 126 * @brief Get the CLCD clock frequency 127 * @return The frequency in Hz 128 */ 129 int MXC_CLCD_GetFrequency(void); 130 131 /** 132 * @brief Set CLCD frame buffer address. 133 * @note The data at addr must remain valid while using the CLCD 134 * 135 * @param addr Pointer to the new framebuffer 136 */ 137 void MXC_CLCD_SetFrameAddr(void *addr); 138 139 /** 140 * @brief Get CLCD frame buffer address. 141 * @note The data at addr must remain valid while using the CLCD 142 * 143 * @return Pointer to the framebuffer 144 */ 145 void *MXC_CLCD_GetFrameAddr(void); 146 147 /** 148 * @brief Set CLCD Color Palette 149 * @note The color palette is not used in 16 and 24 bit color depth 150 * for either display type. 151 * 152 * @param palette Pointer to the color palette data, must be 768 bytes 153 * 154 * @return See \ref MXC_Error_Codes for the list of error return codes. 155 */ 156 int MXC_CLCD_SetColorPalette(uint32_t *palette); 157 158 /** 159 * @brief Get the status of power to the display 160 * 161 * @return 1 if display on (PWREN pin), 0 otherwise 162 */ 163 int MXC_CLCD_IsEnabled(void); 164 165 /** 166 * @brief Set the RGB mode used by the peripheral 167 * 168 * @param rgb565 See \ref mxc_clcd_color_t for a list of valid values 169 * 170 * @return See \ref MXC_Error_Codes for the list of error return codes. 171 */ 172 int MXC_CLCD_SetRGBMode(mxc_clcd_color_t rgb565); 173 174 /** 175 * @brief Get the current RGB mode 176 * 177 * @return See \ref mxc_clcd_color_t for return values 178 */ 179 mxc_clcd_color_t MXC_CLCD_GetRGBMode(void); 180 181 /** 182 * @brief Set the number of bits per pixel 183 * @note Valid values are detailed in the user guide 184 * 185 * @param bitsPerPixel number of bits per pixel (i.e. 8, 16, 24, etc) 186 * 187 * @return See \ref MXC_Error_Codes for the list of error return codes. 188 */ 189 int MXC_CLCD_SetBPP(int bitsPerPixel); 190 191 /** 192 * @brief Get the number of bits per pixel 193 * 194 * @return Number of bits per pixel 195 */ 196 int MXC_CLCD_GetBPP(void); 197 198 /** 199 * @brief Set the type of display to drive 200 * 201 * @param type See \ref mxc_clcd_disp_t for a list of display types 202 */ 203 void MXC_CLCD_SetDisplayType(mxc_clcd_disp_t type); 204 205 /** 206 * @brief Get the type of display being driven 207 * 208 * @return See \ref mxc_clcd_disp_t for a list of return values 209 */ 210 mxc_clcd_disp_t MXC_CLCD_GetDisplayType(void); 211 212 /** 213 * @brief Set frequency of the AC bias 214 * 215 * @param lines Set the number of line clocks per period of the AC bias clock 216 */ 217 void MXC_CLCD_SetACBias(int lines); 218 219 /** 220 * @brief Get the current frequency of the AC bias 221 * 222 * @return The number of line clocks per period of the AC bias output 223 */ 224 int MXC_CLCD_GetACBias(void); 225 226 /** 227 * @brief Get the interrupt flags 228 * 229 * @return Interrupt Flags 230 */ 231 int MXC_CLCD_GetFlags(void); 232 233 /** 234 * @brief Clear interrupt flags 235 * 236 * @param flags The interrupt flags to clear 237 */ 238 void MXC_CLCD_ClearFlags(int flags); 239 240 /** 241 * @brief Enable interrupts 242 * 243 * @param flags The interrupt flags to enable 244 */ 245 void MXC_CLCD_EnableInt(int flags); 246 247 /** 248 * @brief Disable interrupts 249 * 250 * @param flags The interrupt flags to disable 251 */ 252 void MXC_CLCD_DisableInt(int flags); 253 254 /** 255 * @brief Set Vertical Back Porch Size 256 * 257 * @param lines VBP size in lines 258 */ 259 void MXC_CLCD_SetVBPSize(int lines); 260 261 /** 262 * @brief Get Vertical Back Porch Size 263 * 264 * @return VBP size in lines 265 */ 266 int MXC_CLCD_GetVBPSize(void); 267 268 /** 269 * @brief Set Vertical Front Porch size 270 * 271 * @param lines VFP size in lines 272 */ 273 void MXC_CLCD_SetVFPSize(int lines); 274 275 /** 276 * @brief Get Vertical Front Porch size 277 * 278 * @return VFP size in lines 279 */ 280 int MXC_CLCD_GetVFPSize(void); 281 282 /** 283 * @brief Set Horizontal Back Porch size 284 * 285 * @param lines HBP Size in lines 286 */ 287 void MXC_CLCD_SetHBPSize(int lines); 288 289 /** 290 * @brief Get Horizontal Back Porch size 291 * 292 * @return HBP Size in lines 293 */ 294 int MXC_CLCD_GetHBPSize(void); 295 296 /** 297 * @brief Set Horizontal Front Porch size 298 * 299 * @param lines HFP size in lines 300 */ 301 void MXC_CLCD_SetHFPSize(int lines); 302 303 /** 304 * @brief Get Horizontal Front Porch size 305 * 306 * @return HFP size in lines 307 */ 308 int MXC_CLCD_GetHFPSize(void); 309 310 /** 311 * @brief Set the number of usable vertical pixels in the display 312 * 313 * @param pixels Number of usable vertical pixels 314 */ 315 void MXC_CLCD_SetVerticalSize(int pixels); 316 317 /** 318 * @brief Get the number of usable vertical pixels in the display 319 * 320 * @return Number of usable vertical pixels 321 */ 322 int MXC_CLCD_GetVerticalSize(void); 323 324 /** 325 * @brief Set the number of usable horizontal pixels in the display 326 * 327 * @param pixels Number of usable horizontal pixels 328 */ 329 void MXC_CLCD_SetHorizontalSize(int pixels); 330 331 /** 332 * @brief Get the number of usable horizontal pixels in the display 333 * 334 * @return Number of usable horizontal pixels 335 */ 336 int MXC_CLCD_GetHorizontalSize(void); 337 338 /** 339 * @brief Set the width of the VSYNC pulse 340 * 341 * @param lines Width of the VSYNC pulse in line clocks 342 */ 343 void MXC_CLCD_SetVSYNCWidth(int lines); 344 345 /** 346 * @brief Get the width of the VSYNC pulse 347 * 348 * @return Width of the VSYNC pulse in line clocks 349 */ 350 int MXC_CLCD_GetVSYNCWidth(void); 351 352 /** 353 * @brief Set the width of the HSYNC pulse 354 * 355 * @param lines Width of the HSYNC pulse in line clock 356 s */ 357 void MXC_CLCD_SetHSYNCWidth(int lines); 358 359 /** 360 * @brief Get the width of the HSYNC pulse 361 * 362 * @return Width of the HSYNC pulse in line clocks 363 */ 364 int MXC_CLCD_GetHSYNCWidth(void); 365 366 /** 367 * @brief Configure CLCD frame module. 368 * @return #E_NO_ERROR if successful, appropriate error otherwise 369 */ 370 int MXC_CLCD_Config(mxc_clcd_cfg_t *clcd_cfg); 371 372 /**@} end of group clcd */ 373 374 #ifdef __cplusplus 375 } 376 #endif 377 378 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_CLCD_H_ 379