luat_lcd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. #include "luat_base.h"
  2. #include "luat_lcd.h"
  3. #include "luat_gpio.h"
  4. #include "luat_spi.h"
  5. #include "luat_mem.h"
  6. #include "luat_rtos.h"
  7. #define LUAT_LOG_TAG "lcd"
  8. #include "luat_log.h"
  9. luat_color_t BACK_COLOR = LCD_WHITE, FORE_COLOR = LCD_BLACK;
  10. luat_lcd_conf_t* confs[LUAT_LCD_CONF_COUNT] = {0};
  11. void luat_lcd_execute_cmds(luat_lcd_conf_t* conf) {
  12. uint16_t cmd = 0,cmd_len = 0;
  13. uint8_t cmd_send = 0;
  14. uint8_t cmds[32]={0};
  15. for (size_t i = 0; i < conf->opts->init_cmds_len; i++){
  16. cmd = conf->opts->init_cmds[i];
  17. switch(((cmd >> 8) & 0xFF)) {
  18. case 0x0000:
  19. case 0x0002:
  20. if (i!=0){
  21. if (cmd_len){
  22. lcd_write_cmd_data(conf,cmd_send, cmds, cmd_len);
  23. }else{
  24. lcd_write_cmd_data(conf,cmd_send, NULL, 0);
  25. }
  26. }
  27. cmd_send = (uint8_t)(cmd & 0xFF);
  28. cmd_len = 0;
  29. break;
  30. case 0x0001:
  31. luat_rtos_task_sleep(cmd & 0xFF);
  32. break;
  33. case 0x0003:
  34. cmds[cmd_len]= (uint8_t)(cmd & 0xFF);
  35. cmd_len++;
  36. break;
  37. default:
  38. break;
  39. }
  40. if (i==conf->opts->init_cmds_len-1){
  41. if (cmd_len){
  42. lcd_write_cmd_data(conf,cmd_send, cmds, cmd_len);
  43. }else{
  44. lcd_write_cmd_data(conf,cmd_send, NULL, 0);
  45. }
  46. }
  47. }
  48. }
  49. int lcd_write_data(luat_lcd_conf_t* conf, const uint8_t data){
  50. size_t len;
  51. if (conf->port == LUAT_LCD_SPI_DEVICE){
  52. len = luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)&data, 1);
  53. }else{
  54. len = luat_spi_send(conf->port, (const char*)&data, 1);
  55. }
  56. if (len != 1){
  57. LLOGI("lcd_write_data error. %d", len);
  58. return -1;
  59. }else{
  60. return 0;
  61. }
  62. }
  63. int lcd_write_cmd_data(luat_lcd_conf_t* conf,const uint8_t cmd, const uint8_t *data, uint8_t data_len){
  64. if (conf->opts->write_cmd_data){
  65. return conf->opts->write_cmd_data(conf,cmd,data,data_len);
  66. }
  67. size_t len;
  68. if (conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_I || conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_II){
  69. luat_gpio_set(conf->pin_dc, Luat_GPIO_LOW);
  70. }
  71. #ifdef LUAT_LCD_CMD_DELAY_US
  72. if (conf->dc_delay_us){
  73. luat_timer_us_delay(conf->dc_delay_us);
  74. }
  75. #endif
  76. if (conf->port == LUAT_LCD_SPI_DEVICE){
  77. len = luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)&cmd, 1);
  78. }else{
  79. len = luat_spi_send(conf->port, (const char*)&cmd, 1);
  80. }
  81. if (conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_I || conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_II){
  82. luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
  83. }
  84. if (len != 1){
  85. LLOGI("lcd_write_cmd error. %d", len);
  86. return -1;
  87. }else{
  88. #ifdef LUAT_LCD_CMD_DELAY_US
  89. if (conf->dc_delay_us){
  90. luat_timer_us_delay(conf->dc_delay_us);
  91. }
  92. #endif
  93. }
  94. if (data_len){
  95. if (conf->port == LUAT_LCD_SPI_DEVICE){
  96. len = luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)data, data_len);
  97. }else{
  98. len = luat_spi_send(conf->port, (const char*)data, data_len);
  99. }
  100. if (len != data_len){
  101. LLOGI("lcd_write_data error. %d", len);
  102. return -1;
  103. }
  104. }
  105. return 0;
  106. }
  107. luat_lcd_conf_t* luat_lcd_get_default(void) {
  108. for (size_t i = 0; i < LUAT_LCD_CONF_COUNT; i++){
  109. if (confs[i] != NULL) {
  110. return confs[i];
  111. }
  112. }
  113. return NULL;
  114. }
  115. const char* luat_lcd_name(luat_lcd_conf_t* conf) {
  116. return conf->opts->name;
  117. }
  118. LUAT_WEAK int luat_lcd_init_default(luat_lcd_conf_t* conf) {
  119. conf->is_init_done = 0;
  120. if (conf->w == 0)
  121. conf->w = LCD_W;
  122. if (conf->h == 0)
  123. conf->h = LCD_H;
  124. if (conf->pin_pwr != LUAT_GPIO_NONE)
  125. luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
  126. if (conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_I || conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_II){
  127. if (conf->pin_dc != LUAT_GPIO_NONE) {
  128. luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
  129. }
  130. }
  131. luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
  132. if (conf->pin_pwr != LUAT_GPIO_NONE) {
  133. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  134. }
  135. if (conf->opts->user_ctrl_init)
  136. {
  137. conf->opts->user_ctrl_init(conf);
  138. goto INIT_DONE;
  139. }
  140. luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
  141. luat_rtos_task_sleep(100);
  142. luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
  143. luat_rtos_task_sleep(120);
  144. luat_lcd_wakeup(conf);
  145. luat_rtos_task_sleep(120);
  146. // 发送初始化命令
  147. if (conf->opts->init){
  148. conf->opts->init(conf);
  149. }else{
  150. luat_lcd_execute_cmds(conf);
  151. if(strcmp(conf->opts->name,"custom") == 0){
  152. luat_heap_free(conf->opts->init_cmds);
  153. }
  154. luat_lcd_set_direction(conf,conf->direction);
  155. }
  156. luat_lcd_wakeup(conf);
  157. /* wait for power stability */
  158. luat_rtos_task_sleep(100);
  159. luat_lcd_clear(conf,LCD_BLACK);
  160. /* display on */
  161. luat_lcd_display_on(conf);
  162. INIT_DONE:
  163. conf->is_init_done = 1;
  164. for (size_t i = 0; i < LUAT_LCD_CONF_COUNT; i++){
  165. if (confs[i] == NULL) {
  166. confs[i] = conf;
  167. return 0;
  168. }
  169. }
  170. return -1;
  171. }
  172. LUAT_WEAK int luat_lcd_init(luat_lcd_conf_t* conf) {
  173. return luat_lcd_init_default(conf);
  174. }
  175. int luat_lcd_close(luat_lcd_conf_t* conf) {
  176. if (conf->pin_pwr != LUAT_GPIO_NONE)
  177. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  178. return 0;
  179. }
  180. int luat_lcd_display_off(luat_lcd_conf_t* conf) {
  181. if (conf->pin_pwr != LUAT_GPIO_NONE)
  182. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  183. lcd_write_cmd_data(conf,0x28, NULL, 0);
  184. return 0;
  185. }
  186. int luat_lcd_display_on(luat_lcd_conf_t* conf) {
  187. if (conf->pin_pwr != LUAT_GPIO_NONE)
  188. luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
  189. lcd_write_cmd_data(conf,0x29, NULL, 0);
  190. return 0;
  191. }
  192. int luat_lcd_sleep(luat_lcd_conf_t* conf) {
  193. if (conf->pin_pwr != LUAT_GPIO_NONE)
  194. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  195. luat_rtos_task_sleep(5);
  196. lcd_write_cmd_data(conf,conf->opts->sleep_cmd?conf->opts->sleep_cmd:LUAT_LCD_DEFAULT_SLEEP, NULL, 0);
  197. return 0;
  198. }
  199. int luat_lcd_wakeup(luat_lcd_conf_t* conf) {
  200. if (conf->pin_pwr != LUAT_GPIO_NONE)
  201. luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
  202. luat_rtos_task_sleep(5);
  203. lcd_write_cmd_data(conf,conf->opts->wakeup_cmd?conf->opts->wakeup_cmd:LUAT_LCD_DEFAULT_WAKEUP, NULL, 0);
  204. return 0;
  205. }
  206. int luat_lcd_inv_off(luat_lcd_conf_t* conf) {
  207. lcd_write_cmd_data(conf,0x20, NULL, 0);
  208. return 0;
  209. }
  210. int luat_lcd_inv_on(luat_lcd_conf_t* conf) {
  211. lcd_write_cmd_data(conf,0x21, NULL, 0);
  212. return 0;
  213. }
  214. int luat_lcd_set_address(luat_lcd_conf_t* conf,int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
  215. uint8_t data_x[] = {(x1+conf->xoffset)>>8,x1+conf->xoffset,(x2+conf->xoffset)>>8,x2+conf->xoffset};
  216. lcd_write_cmd_data(conf,0x2a, data_x, 4);
  217. uint8_t data_y[] = {(y1+conf->yoffset)>>8,y1+conf->yoffset,(y2+conf->yoffset)>>8,y2+conf->yoffset};
  218. lcd_write_cmd_data(conf,0x2b, data_y, 4);
  219. lcd_write_cmd_data(conf,0x2c, NULL, 0);
  220. return 0;
  221. }
  222. int luat_lcd_set_color(luat_color_t back, luat_color_t fore){
  223. BACK_COLOR = back;
  224. FORE_COLOR = fore;
  225. return 0;
  226. }
  227. int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction){
  228. uint8_t direction_date = 0;
  229. if(direction==0) direction_date = conf->opts->direction0;
  230. else if(direction==1) direction_date = conf->opts->direction90;
  231. else if(direction==2) direction_date = conf->opts->direction180;
  232. else direction_date = conf->opts->direction270;
  233. lcd_write_cmd_data(conf,0x36, &direction_date, 1);
  234. return 0;
  235. }
  236. #ifndef LUAT_USE_LCD_CUSTOM_DRAW
  237. int luat_lcd_flush_default(luat_lcd_conf_t* conf) {
  238. if (conf->buff == NULL) {
  239. return 0;
  240. }
  241. //LLOGD("luat_lcd_flush range %d %d", conf->flush_y_min, conf->flush_y_max);
  242. if (conf->flush_y_max < conf->flush_y_min) {
  243. // 没有需要刷新的内容,直接跳过
  244. //LLOGD("luat_lcd_flush no need");
  245. return 0;
  246. }
  247. if (conf->opts->lcd_draw) {
  248. //LLOGD("luat_lcd_flush user flush");
  249. if (conf->opts->no_ram_mode)
  250. {
  251. conf->opts->lcd_draw(conf, 0, 0, 0, 0, conf->buff);
  252. }
  253. else
  254. {
  255. conf->opts->lcd_draw(conf, 0, conf->flush_y_min, conf->w - 1, conf->flush_y_max, &conf->buff[conf->flush_y_min * conf->w]);
  256. }
  257. } else {
  258. uint32_t size = conf->w * (conf->flush_y_max - conf->flush_y_min + 1) * 2;
  259. luat_lcd_set_address(conf, 0, conf->flush_y_min, conf->w - 1, conf->flush_y_max);
  260. const char* tmp = (const char*)(conf->buff + conf->flush_y_min * conf->w);
  261. if (conf->port == LUAT_LCD_SPI_DEVICE){
  262. luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), tmp, size);
  263. }else{
  264. luat_spi_send(conf->port, tmp, size);
  265. }
  266. }
  267. // 重置为不需要刷新的状态
  268. conf->flush_y_max = 0;
  269. conf->flush_y_min = conf->h;
  270. return 0;
  271. }
  272. LUAT_WEAK int luat_lcd_flush(luat_lcd_conf_t* conf) {
  273. return luat_lcd_flush_default(conf);
  274. }
  275. int luat_lcd_draw_default(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color) {
  276. if (x1 >= conf->w || y1 >= conf->h || x2 < 0 || y2 < 0 || x2 < x1 || y2 < y1) {
  277. // LLOGE("out of lcd buff range %d %d %d %d", x1, y1, x2, y2);
  278. // LLOGE("out of lcd buff range %d %d %d %d %d", x1 >= conf->w, y1 >= conf->h, y2 < 0, x2 < x1, y2 < y1);
  279. return 0;
  280. }
  281. if (y2 >= conf->h) {
  282. y2 = conf->h - 1;
  283. }
  284. // 直接刷屏模式
  285. if (conf->buff == NULL) {
  286. // 常规数据, 整体传输
  287. if (x1 >= 0 && y1 >= 0 && x2 <= conf->w && y2 <= conf->h) {
  288. if (conf->opts->lcd_draw) {
  289. conf->opts->lcd_draw(conf, x1, y1, x2, y2, color);
  290. } else {
  291. uint32_t size = (x2 - x1 + 1) * (y2 - y1 + 1);
  292. // LLOGD("draw %dx%d %dx%d %d", x1, y1, x2, y2, size);
  293. luat_lcd_set_address(conf, x1, y1, x2, y2);
  294. if (conf->port == LUAT_LCD_SPI_DEVICE){
  295. luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)color, size* sizeof(luat_color_t));
  296. }else{
  297. luat_spi_send(conf->port, (const char*)color, size * sizeof(luat_color_t));
  298. }
  299. }
  300. }
  301. // 超出边界的数据, 按行传输
  302. else {
  303. int line_size = (x2 - x1 + 1);
  304. // LLOGD("want draw %dx%d %dx%d %d", x1, y1, x2, y2, line_size);
  305. luat_color_t* ptr = (luat_color_t*)color;
  306. for (int i = y1; i <= y2; i++)
  307. {
  308. if (i < 0) {
  309. ptr += line_size;
  310. continue;
  311. }
  312. luat_color_t* line = ptr;
  313. int lsize = line_size;
  314. int tmp_x1 = x1;
  315. int tmp_x2 = x2;
  316. if (x1 < 0) {
  317. line += ( - x1);
  318. lsize += (x1);
  319. tmp_x1 = 0;
  320. }
  321. if (x2 > conf->w) {
  322. lsize -= (x2 - conf->w);
  323. tmp_x2 = conf->w;
  324. }
  325. if (conf->opts->lcd_draw) {
  326. conf->opts->lcd_draw(conf, tmp_x1, i, tmp_x2, i, line);
  327. } else {
  328. // LLOGD("action draw %dx%d %dx%d %d", tmp_x1, i, tmp_x2, i, lsize);
  329. luat_lcd_set_address(conf, tmp_x1, i, tmp_x2, i);
  330. if (conf->port == LUAT_LCD_SPI_DEVICE){
  331. luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)line, lsize * sizeof(luat_color_t));
  332. }else{
  333. luat_spi_send(conf->port, (const char*)line, lsize * sizeof(luat_color_t));
  334. }
  335. }
  336. ptr += line_size;
  337. }
  338. // TODO
  339. // LLOGD("超出边界,特殊处理");
  340. }
  341. return 0;
  342. }
  343. // buff模式
  344. #if 0
  345. int16_t x_end = x2 >= conf->w? (conf->w - 1):x2;
  346. luat_color_t* dst = (conf->buff);
  347. size_t lsize = (x2 - x1 + 1);
  348. for (int16_t x = x1; x <= x2; x++)
  349. {
  350. if (x < 0 || x >= conf->w)
  351. continue;
  352. for (int16_t y = y1; y <= y2; y++)
  353. {
  354. if (y < 0 || y >= conf->h)
  355. continue;
  356. memcpy((char*)(dst + (conf->w * y + x)), (char*)(color + (lsize * (y-y1) + (x-x1))), sizeof(luat_color_t));
  357. }
  358. }
  359. // 存储需要刷新的区域
  360. if (y1 < conf->flush_y_min) {
  361. if (y1 >= 0)
  362. conf->flush_y_min = y1;
  363. else
  364. conf->flush_y_min = 0;
  365. }
  366. if (y2 > conf->flush_y_max) {
  367. conf->flush_y_max = y2;
  368. }
  369. #endif
  370. //LLOGI("X1 %d Y1 %d X2 %d Y2 %d", x1, y1, x2, y2);
  371. int16_t x_end = (x2 >= conf->w)?(conf->w - 1):x2;
  372. int16_t y_end = (y2 >= conf->h)?(conf->h - 1):y2;
  373. luat_color_t* dst = (conf->buff);
  374. size_t fromlsize = (x2 - x1 + 1);
  375. size_t tolsize = (x_end - x1 + 1);
  376. for (int16_t y = y1; y <= y_end; y++)
  377. {
  378. if (y < 0) continue;
  379. //LLOGI("H%d L %d <- %d X2 %d Y2 %d", y, conf->w * y + x1, fromlsize * (y - y1));
  380. memcpy(&dst[(conf->w * y + x1)], &color[fromlsize * (y - y1)], tolsize * sizeof(luat_color_t));
  381. }
  382. // 存储需要刷新的区域
  383. if (y1 < conf->flush_y_min) {
  384. if (y1 >= 0)
  385. conf->flush_y_min = y1;
  386. else
  387. conf->flush_y_min = 0;
  388. }
  389. if (y_end > conf->flush_y_max) {
  390. conf->flush_y_max = y_end;
  391. }
  392. return 0;
  393. }
  394. LUAT_WEAK int luat_lcd_draw(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color) {
  395. return luat_lcd_draw_default(conf, x1, y1, x2, y2, color);
  396. }
  397. #endif
  398. int luat_lcd_draw_point(luat_lcd_conf_t* conf, int16_t x, int16_t y, luat_color_t color) {
  399. luat_color_t tmp = color;
  400. if (conf->port < LUAT_LCD_HW_ID_0 || conf->port == LUAT_LCD_SPI_DEVICE)
  401. tmp = color_swap(color);// 注意, 这里需要把颜色swap了
  402. return luat_lcd_draw(conf, x, y, x, y, &tmp);
  403. }
  404. int luat_lcd_clear(luat_lcd_conf_t* conf, luat_color_t color){
  405. luat_lcd_draw_fill(conf, 0, 0, conf->w - 1, conf->h, color);
  406. return 0;
  407. }
  408. int luat_lcd_draw_fill(luat_lcd_conf_t* conf,int16_t x1,int16_t y1,int16_t x2,int16_t y2, luat_color_t color) {
  409. int16_t i;
  410. for(i=y1;i<y2;i++)
  411. {
  412. luat_lcd_draw_line(conf, x1, i, x2, i, color);
  413. }
  414. return 0;
  415. }
  416. int luat_lcd_draw_vline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t h, luat_color_t color) {
  417. if (h<=0) return 0;
  418. return luat_lcd_draw_line(conf, x, y, x, y + h - 1, color);
  419. }
  420. int luat_lcd_draw_hline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t w, luat_color_t color) {
  421. if (w<=0) return 0;
  422. return luat_lcd_draw_line(conf, x, y, x + w - 1, y, color);
  423. }
  424. int luat_lcd_draw_line(luat_lcd_conf_t* conf,int16_t x1, int16_t y1, int16_t x2, int16_t y2,luat_color_t color) {
  425. luat_color_t tmp = color;
  426. int16_t t;
  427. uint32_t i = 0;
  428. int xerr = 0, yerr = 0, delta_x, delta_y, distance;
  429. int incx, incy, row, col;
  430. if (x1 == x2 || y1 == y2) // 直线
  431. {
  432. size_t dots = (x2 - x1 + 1) * (y2 - y1 + 1);//点数量
  433. luat_color_t* line_buf = (luat_color_t*) luat_heap_malloc(dots * sizeof(luat_color_t));
  434. if (conf->port < LUAT_LCD_HW_ID_0 || conf->port == LUAT_LCD_SPI_DEVICE)
  435. tmp = color_swap(color);// 颜色swap
  436. if (line_buf) {
  437. for (i = 0; i < dots; i++)
  438. {
  439. line_buf[i] = tmp;
  440. }
  441. luat_lcd_draw(conf, x1, y1, x2, y2, line_buf);
  442. luat_heap_free(line_buf);
  443. return 0;
  444. }
  445. }
  446. delta_x = x2 - x1;
  447. delta_y = y2 - y1;
  448. row = x1;
  449. col = y1;
  450. if (delta_x > 0)incx = 1;
  451. else if (delta_x == 0)incx = 0;
  452. else
  453. {
  454. incx = -1;
  455. delta_x = -delta_x;
  456. }
  457. if (delta_y > 0)incy = 1;
  458. else if (delta_y == 0)incy = 0;
  459. else
  460. {
  461. incy = -1;
  462. delta_y = -delta_y;
  463. }
  464. if (delta_x > delta_y)distance = delta_x;
  465. else distance = delta_y;
  466. for (t = 0; t <= distance + 1; t++)
  467. {
  468. luat_lcd_draw_point(conf,row, col,color);
  469. xerr += delta_x ;
  470. yerr += delta_y ;
  471. if (xerr > distance)
  472. {
  473. xerr -= distance;
  474. row += incx;
  475. }
  476. if (yerr > distance)
  477. {
  478. yerr -= distance;
  479. col += incy;
  480. }
  481. }
  482. return 0;
  483. }
  484. int luat_lcd_draw_rectangle(luat_lcd_conf_t* conf,int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t color){
  485. luat_lcd_draw_line(conf,x1, y1, x2, y1, color);
  486. luat_lcd_draw_line(conf,x1, y1, x1, y2, color);
  487. luat_lcd_draw_line(conf,x1, y2, x2, y2, color);
  488. luat_lcd_draw_line(conf,x2, y1, x2, y2, color);
  489. return 0;
  490. }
  491. int luat_lcd_draw_circle(luat_lcd_conf_t* conf,int16_t x0, int16_t y0, uint8_t r, luat_color_t color){
  492. int a, b;
  493. int di;
  494. a = 0;
  495. b = r;
  496. di = 3 - (r << 1);
  497. while (a <= b)
  498. {
  499. luat_lcd_draw_point(conf,x0 - b, y0 - a,color);
  500. luat_lcd_draw_point(conf,x0 + b, y0 - a,color);
  501. luat_lcd_draw_point(conf,x0 - a, y0 + b,color);
  502. luat_lcd_draw_point(conf,x0 - b, y0 - a,color);
  503. luat_lcd_draw_point(conf,x0 - a, y0 - b,color);
  504. luat_lcd_draw_point(conf,x0 + b, y0 + a,color);
  505. luat_lcd_draw_point(conf,x0 + a, y0 - b,color);
  506. luat_lcd_draw_point(conf,x0 + a, y0 + b,color);
  507. luat_lcd_draw_point(conf,x0 - b, y0 + a,color);
  508. a++;
  509. //Bresenham
  510. if (di < 0)di += 4 * a + 6;
  511. else
  512. {
  513. di += 10 + 4 * (a - b);
  514. b--;
  515. }
  516. luat_lcd_draw_point(conf,x0 + a, y0 + b,color);
  517. }
  518. return 0;
  519. }
  520. #ifndef LUAT_COMPILER_NOWEAK
  521. LUAT_WEAK int luat_lcd_qspi_config(luat_lcd_conf_t* conf, luat_lcd_qspi_conf_t *qspi_config) {
  522. return -1;
  523. };
  524. LUAT_WEAK int luat_lcd_qspi_auto_flush_on_off(luat_lcd_conf_t* conf, uint8_t on_off) {
  525. return -1;
  526. }
  527. LUAT_WEAK int luat_lcd_run_api_in_service(luat_lcd_api api, void *param, uint32_t param_len) {
  528. return -1;
  529. };
  530. #endif