luat_lcd_custom.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "luat_base.h"
  2. #include "luat_lcd.h"
  3. #include "luat_gpio.h"
  4. #include "luat_spi.h"
  5. #include "luat_malloc.h"
  6. #include "luat_timer.h"
  7. #define LUAT_LOG_TAG "custom"
  8. #include "luat_log.h"
  9. #define LCD_W 240
  10. #define LCD_H 320
  11. #define LCD_DIRECTION 0
  12. static int custom_init(luat_lcd_conf_t* conf) {
  13. if (conf->w == 0)
  14. conf->w = LCD_W;
  15. if (conf->h == 0)
  16. conf->h = LCD_H;
  17. if (conf->direction == 0)
  18. conf->direction = LCD_DIRECTION;
  19. if (conf->pin_pwr != 255)
  20. luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
  21. luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
  22. luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
  23. if (conf->pin_pwr != 255)
  24. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  25. luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
  26. luat_timer_mdelay(100);
  27. luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
  28. luat_timer_mdelay(120);
  29. luat_lcd_wakeup(conf);
  30. luat_timer_mdelay(120);
  31. // 发送初始化命令
  32. luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
  33. luat_lcd_execute_cmds(conf, cst->initcmd, cst->init_cmd_count);
  34. luat_lcd_wakeup(conf);
  35. /* wait for power stability */
  36. luat_timer_mdelay(100);
  37. luat_lcd_clear(conf,BLACK);
  38. /* display on */
  39. luat_lcd_display_on(conf);
  40. return 0;
  41. };
  42. const luat_lcd_opts_t lcd_opts_custom = {
  43. .name = "custom",
  44. .init = custom_init,
  45. };