1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include "driver/lcd_types.h" 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 24 25 /* @brief Overview about this API header 26 * 27 */ 28 29 /** 30 * @brief LCD API 31 * @{ 32 */ 33 34 /** 35 * @brief This API select LCD module clk source 36 * - config video power 37 * - open lcd sys interrupt/clk enable 38 * @return 39 * - BK_OK: succeed 40 * - others: other errors. 41 */ 42 bk_err_t bk_lcd_driver_init(lcd_clk_t clk); 43 44 45 /** 46 * @brief This API init the 8080 lcd interface 47 * - Set lcd display mode is 8080 interface 48 * - init 8080 lcd gpio 49 * - enable 8080 display 50 * -enable 8080 end of frame interrupt 51 * - if you want enable start of frame interrupt, please use API bk_lcd_8080_int_enable 52 * 53 * @param 54 * - x_pixel user can set by any value, can be lcd size x or picture size x 55 * - y_pixel user can set by any value, can be lcd size y or picture size y 56 * - input_data_format, lcd module input data format, can be rgb565, yuyv, uvyy or other lcd_data_format_t member 57 * 58 * @return 59 * - BK_OK: succeed 60 * - others: other errors. 61 */ 62 bk_err_t bk_lcd_8080_init(uint16_t x_pixel, uint16_t y_pixel, lcd_data_format_t input_data_format); 63 64 65 /** 66 * @brief 8080 lcd interface reg deinit 67 * - This API reset all lcd reg include power 68 * - close 8080 lcd enable and display 69 * - reset x pixel and y pixel zero 70 * - unregister lcd isr 71 * 72 * @return 73 * - BK_OK: succeed 74 * - others: other errors. 75 */ 76 bk_err_t bk_lcd_8080_deinit(void); 77 78 /** 79 * @brief This API config lcd display x size and y size 80 * 81 * @param 82 * - x_pixel user can set by any value, can be lcd size x or picture size x 83 * - y_pixel user can set by any value, can be lcd size y or picture size y 84 * 85 * @return 86 * - BK_OK: succeed 87 * - others: other errors. 88 */ 89 bk_err_t bk_lcd_pixel_config(uint16_t x_pixel, uint16_t y_pixel); 90 91 92 /** 93 * @brief This API config 8080 lcd interrupt 94 95 * @param 96 * - is_sof_en enable start of frame interrupt 97 * - is_eof_en enable end of frame interrupt 98 * 99 * @attention 8080 end of frame int is open in API bk_lcd_8080_init 100 * 101 * @return 102 * - BK_OK: succeed 103 * - others: other errors. 104 */ 105 bk_err_t bk_lcd_8080_int_enable(bool is_sof_en, bool is_eof_en); 106 107 108 /** 109 * @brief This API start mcu 8080 lcd transfer data to display 110 * 111 * @param start_transfer 112 * - 1:data start transfer to lcd display on; 113 * - 0:stop transfer 114 * @return 115 * - BK_OK: succeed 116 * - others: other errors. 117 */ 118 bk_err_t bk_lcd_8080_start_transfer(bool start); 119 120 121 /** 122 * @brief rgb lcd interface reg deinit 123 * - This API reset all lcd reg include power 124 * - close rgb lcd enable and display 125 * - reset x pixel and y pixel zero 126 * - unregister lcd isr 127 * 128 * @return 129 * - BK_OK: succeed 130 * - others: other errors. 131 */ 132 bk_err_t bk_lcd_rgb_deinit(void); 133 134 /** 135 * @brief enable rgb lcd enable 136 * @param bool en 137 * - 1: enable rgb display 138 * - 0: disable rgb display 139 * 140 * @return 141 * - BK_OK: succeed 142 * - others: other errors. 143 */ 144 bk_err_t bk_lcd_rgb_display_en(bool en); 145 146 147 /** 148 * @brief This API config rgb lcd interrupt 149 150 * @param 151 * - is_sof_en enable start of frame interrupt 152 * - is_eof_en enable end of frame interrupt 153 * 154 * @attention rgb end of frame int is open in API bk_lcd_rgb_init 155 * 156 * @return 157 * - BK_OK: succeed 158 * - others: other errors. 159 */ 160 bk_err_t bk_lcd_rgb_int_enable(bool is_sof_en, bool is_eof_en); 161 162 #if (USE_LCD_REGISTER_CALLBACKS == 1) 163 164 /** 165 * @brief This API register 8080/rgb lcd int isr 166 * 167 * @param 168 * - int_type include 8080/rgb end of frame int and 8080/rgb start of frame int 169 * - isr: isr function 170 * 171 * Usage example: 172 * 173 * bk_lcd_isr_register(I8080_OUTPUT_EOF, lcd_i8080_isr); //register 8080 end of frame isr 174 * 175 * @return 176 * - BK_OK: succeed 177 * - others: other errors. 178 */ 179 bk_err_t bk_lcd_isr_register(lcd_int_type_t int_type, lcd_isr_t isr); 180 #else 181 182 /** 183 * @brief This API register lcd isr, user should check int status in isr function, and clear status 184 * 185 * @param 186 * - isr: isr function 187 * 188 * @return 189 * - BK_OK: succeed 190 * - others: other errors. 191 */ 192 bk_err_t bk_lcd_isr_register(lcd_isr_t lcd_isr); 193 194 /** 195 * @brief This API used to get lcd int status 196 * 197 * @return 198 * - status value. 199 * 200 * 8080 Usage example: 201 * if (bk_lcd_int_status_get()&I8080_OUTPUT_EOF == 1), present 8080 eof int triggerd 202 * if (bk_lcd_int_status_get()&RGB_OUTPUT_EOF == 1), present rgb eof int triggerd 203 * 204 */ 205 uint32_t bk_lcd_int_status_get(void); 206 207 /** 208 * @brief This API used to clr lcd int status 209 * 210 * @param 211 * - int_type value. 212 * 213 * @return 214 * - BK_OK: succeed 215 * - others: other errors. 216 */ 217 bk_err_t bk_lcd_int_status_clear(lcd_int_type_t int_type); 218 #endif 219 220 221 /** 222 * @brief This API init the rgb lcd interface 223 * - Set lcd display mode is rgb interface 224 * - init rgb lcd gpio 225 * - enable rgb display 226 * - enable rgb end of frame interrupt 227 * 228 * @param 229 * - lcd_device_id_t: lcd type select from lcd_device_id_t 230 * - x_pixel 231 * - y_pixel 232 * - input_data_format: input_data_format select rgb565 data, yuyv, yyuv or other yuv * mode from struct lcd_data_format_t 233 * 234 * @return 235 * - BK_OK: succeed 236 * - others: other errors. 237 */ 238 bk_err_t bk_lcd_rgb_init(lcd_device_id_t id, uint16_t x_pixel, uint16_t y_pixel, lcd_data_format_t input_data_format); 239 240 241 /** 242 * @brief This API used send 8080 lcd init cmd 243 * 244 * @param 245 * - param_count: cmd parameter number 246 * - command: command 247 * - param: the cmd parameter 248 * 249 * Usage example: 250 * 251 * #define COMMAND_1 0xf 252 * uint32_t param_command1[2] = {0xc3, 0x29}; 253 * bk_lcd_8080_send_cmd(2, COMMAND_1, param_command1); 254 * 255 * @return 256 * - BK_OK: succeed 257 * - others: other errors. 258 */ 259 bk_err_t bk_lcd_8080_send_cmd(uint8_t param_count, uint32_t command, uint32_t *param); 260 261 /** 262 * @brief This API used get lcd display base addr 263 * 264 * @return lcd display addr 265 */ 266 uint32_t bk_lcd_get_display_base_addr(void); 267 268 /** 269 * @brief This API used for display partical area 270 * 271 * @param 272 * - partial_clum_l: 273 * - partial_clum_r: 274 * - partial_line_l: 275 * - partial_line_r: 276 * 277 * 8080 Usage example: 278 * 279 * #define PARTICAL_XS 101 280 * #define PARTICAL_XE 220 281 * #define PARTICAL_YS 101 282 * #define PARTICAL_YE 380 283 * bk_lcd_set_partical_display(EDGE_PARTICAL_XS, EDGE_PARTICAL_XE, EDGE_PARTICAL_YS, EDGE_PARTICAL_YE); 284 * bk_lcd_8080_send_cmd(2, COMMAND_1, param_command1); 285 * 286 * @return 287 * - BK_OK: succeed 288 * - others: other errors. 289 */ 290 bk_err_t bk_lcd_set_partical_display(bool en, uint16_t partial_clum_l, uint16_t partial_clum_r, uint16_t partial_line_l, uint16_t partial_line_r); 291 292 293 /** 294 * @brief This API used for 8080 mcu lcd 0x2c/0x3c. ram write cmd send 295 * 296 * @return 297 * - BK_OK: succeed 298 * - others: other errors. 299 */ 300 bk_err_t bk_lcd_8080_ram_write(uint32_t cmd); 301 302 303 /****************************next API exampel please refer to ./complent/media/lcd demo*****************/ 304 /** 305 * @brief This API used for init lcd 306 * 307 * 308 * @param lcd_config_t 309 * 310 * @return 311 * - BK_OK: succeed 312 * - others: other errors. 313 * 314 * Usage example: 315 * lcd_config_t lcd_config; 316 * lcd_config.device = get_lcd_device_by_id(LCD_DEVICE_ST7282); 317 * lcd_config.complete_callback = lcd_complete_callback; 318 * lcd_config.fmt = VUYY_DATA; 319 * lcd_config.pixel_x = 640; 320 * lcd_config.pixel_y = 480; 321 * lcd_driver_init(&lcd_config); 322 * 323 */ 324 bk_err_t lcd_driver_init(const lcd_config_t *config); 325 326 /** 327 * @brief this api used to get lcd device interface 328 * 329 * @param select lcd_device_id_t member 330 * @return lcd device infermation, include: 331 * .id = LCD_DEVICE_HX8282, 332 * .name = "hx8282", 333 * .type = LCD_TYPE_RGB565, 334 * .ppi = PPI_1024X600, 335 * .rgb = &lcd_rgb 336 * .init = NULL, 337 */ 338 const lcd_device_t *get_lcd_device_by_id(lcd_device_id_t id); 339 340 /** 341 * @brief this api used to init lcd backlight 342 * 343 * @param pwm_id gpio7-->PWM_ID_1 gpio8-->PWM_ID_2 344 * - percent: from 0~100 345 * @return 346 * - BK_OK: succeed 347 * - others: other errors. 348 */ 349 bk_err_t lcd_driver_backlight_init(uint8_t pwm_id, uint8_t percent); 350 351 /** 352 * @brief this api used to deinit lcd backlight 353 * 354 * @param pwm_id gpio7-->PWM_ID_1 gpio8-->PWM_ID_2 355 * 356 * @return 357 * - BK_OK: succeed 358 * - others: other errors. 359 */ 360 bk_err_t lcd_driver_backlight_deinit(uint8_t pwm_id); 361 362 /** 363 * @brief this api used to set lcd backlight 364 * 365 * @param percent rang from 0~100 366 * @return 367 * - BK_OK: succeed 368 * - others: other errors. 369 */ 370 bk_err_t lcd_driver_set_backlight(uint8_t percent); 371 372 /** 373 * @brief this api used to enable lcd display 374 * 375 * @return 376 * - BK_OK: succeed 377 * - others: other errors. 378 */ 379 bk_err_t lcd_driver_display_enable(void); 380 381 /** 382 * @brief this api used to clear eof int and diaplay continue 383 * 384 * @return 385 * - BK_OK: succeed 386 * - others: other errors. 387 */ 388 bk_err_t lcd_driver_display_continue(void); 389 390 /** 391 * @brief this api used to set lcd display addr 392 * 393 * @param disp_base_addr sram or psram 394 * 395 * @return 396 * - BK_OK: succeed 397 * - others: other errors. 398 */ 399 bk_err_t lcd_driver_set_display_base_addr(uint32_t disp_base_addr); 400 401 /** 402 * @brief this api used to close lcd 403 * 404 * @return 405 * - BK_OK: succeed 406 * - others: other errors. 407 */ 408 bk_err_t lcd_driver_deinit(void); 409 410 /** 411 * @brief lcd fill color 412 * 413 * @param lcd_disp 414 * 415 * @return 416 * - BK_OK: succeed 417 * - others: other errors. 418 */ 419 bk_err_t bk_lcd_fill_color(lcd_device_id_t id, lcd_disp_framebuf_t *lcd_disp, uint32_t color); 420 421 /** 422 * @brief lcd fill data, adapt large amount of data transfer 423 * 424 * @param lcd_disp 425 * 426 * @return 427 * - BK_OK: succeed 428 * - others: other errors. 429 */ 430 bk_err_t bk_lcd_fill_data(lcd_device_id_t id, lcd_disp_framebuf_t *lcd_disp); 431 432 433 /** 434 * @brief this api used to draw point or adapt small amount of data 435 * 436 * 437 * @param disp_base_addr sram or psram 438 * 439 * @return 440 * - BK_OK: succeed 441 * - others: other errors. 442 */ 443 bk_err_t bk_lcd_draw_point(lcd_device_id_t id, uint16_t x, uint16_t y, uint16_t pixel); 444 445 446 /** 447 * @} 448 */ 449 450 #ifdef __cplusplus 451 } 452 #endif 453 454 455 456 457 458