luat_lcd.c 17 KB

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