luat_lcd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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) luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
  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. if (conf->opts->user_ctrl_init)
  135. {
  136. conf->opts->user_ctrl_init(conf);
  137. goto INIT_DONE;
  138. }
  139. luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
  140. luat_rtos_task_sleep(100);
  141. luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
  142. luat_rtos_task_sleep(120);
  143. luat_lcd_wakeup(conf);
  144. luat_rtos_task_sleep(120);
  145. // 发送初始化命令
  146. if (conf->opts->init){
  147. conf->opts->init(conf);
  148. }else{
  149. luat_lcd_execute_cmds(conf);
  150. if(strcmp(conf->opts->name,"custom") == 0){
  151. luat_heap_free(conf->opts->init_cmds);
  152. }
  153. luat_lcd_set_direction(conf,conf->direction);
  154. }
  155. luat_lcd_wakeup(conf);
  156. /* wait for power stability */
  157. luat_rtos_task_sleep(100);
  158. luat_lcd_clear(conf,LCD_BLACK);
  159. /* display on */
  160. luat_lcd_display_on(conf);
  161. INIT_DONE:
  162. conf->is_init_done = 1;
  163. for (size_t i = 0; i < LUAT_LCD_CONF_COUNT; i++){
  164. if (confs[i] == NULL) {
  165. confs[i] = conf;
  166. return 0;
  167. }
  168. }
  169. return -1;
  170. }
  171. LUAT_WEAK int luat_lcd_init(luat_lcd_conf_t* conf) {
  172. return luat_lcd_init_default(conf);
  173. }
  174. int luat_lcd_close(luat_lcd_conf_t* conf) {
  175. if (conf->pin_pwr != LUAT_GPIO_NONE)
  176. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  177. return 0;
  178. }
  179. int luat_lcd_display_off(luat_lcd_conf_t* conf) {
  180. if (conf->pin_pwr != LUAT_GPIO_NONE)
  181. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  182. lcd_write_cmd_data(conf,0x28, NULL, 0);
  183. return 0;
  184. }
  185. int luat_lcd_display_on(luat_lcd_conf_t* conf) {
  186. if (conf->pin_pwr != LUAT_GPIO_NONE)
  187. luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
  188. lcd_write_cmd_data(conf,0x29, NULL, 0);
  189. return 0;
  190. }
  191. int luat_lcd_sleep(luat_lcd_conf_t* conf) {
  192. if (conf->pin_pwr != LUAT_GPIO_NONE)
  193. luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
  194. luat_rtos_task_sleep(5);
  195. lcd_write_cmd_data(conf,conf->opts->sleep_cmd?conf->opts->sleep_cmd:LUAT_LCD_DEFAULT_SLEEP, NULL, 0);
  196. return 0;
  197. }
  198. int luat_lcd_wakeup(luat_lcd_conf_t* conf) {
  199. if (conf->pin_pwr != LUAT_GPIO_NONE)
  200. luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
  201. luat_rtos_task_sleep(5);
  202. lcd_write_cmd_data(conf,conf->opts->wakeup_cmd?conf->opts->wakeup_cmd:LUAT_LCD_DEFAULT_WAKEUP, NULL, 0);
  203. return 0;
  204. }
  205. int luat_lcd_inv_off(luat_lcd_conf_t* conf) {
  206. lcd_write_cmd_data(conf,0x20, NULL, 0);
  207. return 0;
  208. }
  209. int luat_lcd_inv_on(luat_lcd_conf_t* conf) {
  210. lcd_write_cmd_data(conf,0x21, NULL, 0);
  211. return 0;
  212. }
  213. int luat_lcd_set_address(luat_lcd_conf_t* conf,int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
  214. uint8_t data_x[] = {(x1+conf->xoffset)>>8,x1+conf->xoffset,(x2+conf->xoffset)>>8,x2+conf->xoffset};
  215. lcd_write_cmd_data(conf,0x2a, data_x, 4);
  216. uint8_t data_y[] = {(y1+conf->yoffset)>>8,y1+conf->yoffset,(y2+conf->yoffset)>>8,y2+conf->yoffset};
  217. lcd_write_cmd_data(conf,0x2b, data_y, 4);
  218. lcd_write_cmd_data(conf,0x2c, NULL, 0);
  219. return 0;
  220. }
  221. int luat_lcd_set_color(luat_color_t back, luat_color_t fore){
  222. BACK_COLOR = back;
  223. FORE_COLOR = fore;
  224. return 0;
  225. }
  226. int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction){
  227. uint8_t direction_date = 0;
  228. if(direction==0) direction_date = conf->opts->direction0;
  229. else if(direction==1) direction_date = conf->opts->direction90;
  230. else if(direction==2) direction_date = conf->opts->direction180;
  231. else direction_date = conf->opts->direction270;
  232. lcd_write_cmd_data(conf,0x36, &direction_date, 1);
  233. return 0;
  234. }
  235. #ifndef LUAT_USE_LCD_CUSTOM_DRAW
  236. int luat_lcd_flush_default(luat_lcd_conf_t* conf) {
  237. if (conf->buff == NULL) {
  238. return 0;
  239. }
  240. //LLOGD("luat_lcd_flush range %d %d", conf->flush_y_min, conf->flush_y_max);
  241. if (conf->flush_y_max < conf->flush_y_min) {
  242. // 没有需要刷新的内容,直接跳过
  243. //LLOGD("luat_lcd_flush no need");
  244. return 0;
  245. }
  246. if (conf->opts->lcd_draw) {
  247. //LLOGD("luat_lcd_flush user flush");
  248. if (conf->opts->no_ram_mode)
  249. {
  250. conf->opts->lcd_draw(conf, 0, 0, 0, 0, conf->buff);
  251. }
  252. else
  253. {
  254. 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]);
  255. }
  256. } else {
  257. uint32_t size = conf->w * (conf->flush_y_max - conf->flush_y_min + 1) * 2;
  258. luat_lcd_set_address(conf, 0, conf->flush_y_min, conf->w - 1, conf->flush_y_max);
  259. const char* tmp = (const char*)(conf->buff + conf->flush_y_min * conf->w);
  260. if (conf->port == LUAT_LCD_SPI_DEVICE){
  261. luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), tmp, size);
  262. }else{
  263. luat_spi_send(conf->port, tmp, size);
  264. }
  265. }
  266. // 重置为不需要刷新的状态
  267. conf->flush_y_max = 0;
  268. conf->flush_y_min = conf->h;
  269. return 0;
  270. }
  271. LUAT_WEAK int luat_lcd_flush(luat_lcd_conf_t* conf) {
  272. return luat_lcd_flush_default(conf);
  273. }
  274. 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) {
  275. if (x1 >= conf->w || y1 >= conf->h || x2 < 0 || y2 < 0 || x2 < x1 || y2 < y1) {
  276. // LLOGE("out of lcd buff range %d %d %d %d", x1, y1, x2, y2);
  277. // LLOGE("out of lcd buff range %d %d %d %d %d", x1 >= conf->w, y1 >= conf->h, y2 < 0, x2 < x1, y2 < y1);
  278. return 0;
  279. }
  280. if (y2 >= conf->h) {
  281. y2 = conf->h - 1;
  282. }
  283. // 直接刷屏模式
  284. if (conf->buff == NULL) {
  285. // 常规数据, 整体传输
  286. if (x1 >= 0 && y1 >= 0 && x2 <= conf->w && y2 <= conf->h) {
  287. if (conf->opts->lcd_draw) {
  288. conf->opts->lcd_draw(conf, x1, y1, x2, y2, color);
  289. } else {
  290. uint32_t size = (x2 - x1 + 1) * (y2 - y1 + 1);
  291. // LLOGD("draw %dx%d %dx%d %d", x1, y1, x2, y2, size);
  292. luat_lcd_set_address(conf, x1, y1, x2, y2);
  293. if (conf->port == LUAT_LCD_SPI_DEVICE){
  294. luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)color, size* sizeof(luat_color_t));
  295. }else{
  296. luat_spi_send(conf->port, (const char*)color, size * sizeof(luat_color_t));
  297. }
  298. }
  299. }
  300. // 超出边界的数据, 按行传输
  301. else {
  302. int line_size = (x2 - x1 + 1);
  303. // LLOGD("want draw %dx%d %dx%d %d", x1, y1, x2, y2, line_size);
  304. luat_color_t* ptr = (luat_color_t*)color;
  305. for (int i = y1; i <= y2; i++)
  306. {
  307. if (i < 0) {
  308. ptr += line_size;
  309. continue;
  310. }
  311. luat_color_t* line = ptr;
  312. int lsize = line_size;
  313. int tmp_x1 = x1;
  314. int tmp_x2 = x2;
  315. if (x1 < 0) {
  316. line += ( - x1);
  317. lsize += (x1);
  318. tmp_x1 = 0;
  319. }
  320. if (x2 > conf->w) {
  321. lsize -= (x2 - conf->w);
  322. tmp_x2 = conf->w;
  323. }
  324. if (conf->opts->lcd_draw) {
  325. conf->opts->lcd_draw(conf, tmp_x1, i, tmp_x2, i, line);
  326. } else {
  327. // LLOGD("action draw %dx%d %dx%d %d", tmp_x1, i, tmp_x2, i, lsize);
  328. luat_lcd_set_address(conf, tmp_x1, i, tmp_x2, i);
  329. if (conf->port == LUAT_LCD_SPI_DEVICE){
  330. luat_spi_device_send((luat_spi_device_t*)(conf->lcd_spi_device), (const char*)line, lsize * sizeof(luat_color_t));
  331. }else{
  332. luat_spi_send(conf->port, (const char*)line, lsize * sizeof(luat_color_t));
  333. }
  334. }
  335. ptr += line_size;
  336. }
  337. // TODO
  338. // LLOGD("超出边界,特殊处理");
  339. }
  340. return 0;
  341. }
  342. // buff模式
  343. int16_t x_end = x2 >= conf->w? (conf->w - 1):x2;
  344. luat_color_t* dst = (conf->buff);
  345. size_t lsize = (x2 - x1 + 1);
  346. for (int16_t x = x1; x <= x2; x++)
  347. {
  348. if (x < 0 || x >= conf->w)
  349. continue;
  350. for (int16_t y = y1; y <= y2; y++)
  351. {
  352. if (y < 0 || y >= conf->h)
  353. continue;
  354. memcpy((char*)(dst + (conf->w * y + x)), (char*)(color + (lsize * (y-y1) + (x-x1))), sizeof(luat_color_t));
  355. }
  356. }
  357. // 存储需要刷新的区域
  358. if (y1 < conf->flush_y_min) {
  359. if (y1 >= 0)
  360. conf->flush_y_min = y1;
  361. else
  362. conf->flush_y_min = 0;
  363. }
  364. if (y2 > conf->flush_y_max) {
  365. conf->flush_y_max = y2;
  366. }
  367. return 0;
  368. }
  369. 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) {
  370. return luat_lcd_draw_default(conf, x1, y1, x2, y2, color);
  371. }
  372. #endif
  373. int luat_lcd_draw_point(luat_lcd_conf_t* conf, int16_t x, int16_t y, luat_color_t color) {
  374. luat_color_t tmp = color;
  375. if (conf->port < LUAT_LCD_HW_ID_0 || conf->port == LUAT_LCD_SPI_DEVICE)
  376. tmp = color_swap(color);// 注意, 这里需要把颜色swap了
  377. return luat_lcd_draw(conf, x, y, x, y, &tmp);
  378. }
  379. int luat_lcd_clear(luat_lcd_conf_t* conf, luat_color_t color){
  380. luat_lcd_draw_fill(conf, 0, 0, conf->w - 1, conf->h, color);
  381. return 0;
  382. }
  383. 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) {
  384. int16_t i;
  385. for(i=y1;i<y2;i++)
  386. {
  387. luat_lcd_draw_line(conf, x1, i, x2, i, color);
  388. }
  389. return 0;
  390. }
  391. int luat_lcd_draw_vline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t h, luat_color_t color) {
  392. if (h<=0) return 0;
  393. return luat_lcd_draw_line(conf, x, y, x, y + h - 1, color);
  394. }
  395. int luat_lcd_draw_hline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t w, luat_color_t color) {
  396. if (w<=0) return 0;
  397. return luat_lcd_draw_line(conf, x, y, x + w - 1, y, color);
  398. }
  399. 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) {
  400. luat_color_t tmp = color;
  401. int16_t t;
  402. uint32_t i = 0;
  403. int xerr = 0, yerr = 0, delta_x, delta_y, distance;
  404. int incx, incy, row, col;
  405. if (x1 == x2 || y1 == y2) // 直线
  406. {
  407. size_t dots = (x2 - x1 + 1) * (y2 - y1 + 1);//点数量
  408. luat_color_t* line_buf = (luat_color_t*) luat_heap_malloc(dots * sizeof(luat_color_t));
  409. if (conf->port < LUAT_LCD_HW_ID_0 || conf->port == LUAT_LCD_SPI_DEVICE)
  410. tmp = color_swap(color);// 颜色swap
  411. if (line_buf) {
  412. for (i = 0; i < dots; i++)
  413. {
  414. line_buf[i] = tmp;
  415. }
  416. luat_lcd_draw(conf, x1, y1, x2, y2, line_buf);
  417. luat_heap_free(line_buf);
  418. return 0;
  419. }
  420. }
  421. delta_x = x2 - x1;
  422. delta_y = y2 - y1;
  423. row = x1;
  424. col = y1;
  425. if (delta_x > 0)incx = 1;
  426. else if (delta_x == 0)incx = 0;
  427. else
  428. {
  429. incx = -1;
  430. delta_x = -delta_x;
  431. }
  432. if (delta_y > 0)incy = 1;
  433. else if (delta_y == 0)incy = 0;
  434. else
  435. {
  436. incy = -1;
  437. delta_y = -delta_y;
  438. }
  439. if (delta_x > delta_y)distance = delta_x;
  440. else distance = delta_y;
  441. for (t = 0; t <= distance + 1; t++)
  442. {
  443. luat_lcd_draw_point(conf,row, col,color);
  444. xerr += delta_x ;
  445. yerr += delta_y ;
  446. if (xerr > distance)
  447. {
  448. xerr -= distance;
  449. row += incx;
  450. }
  451. if (yerr > distance)
  452. {
  453. yerr -= distance;
  454. col += incy;
  455. }
  456. }
  457. return 0;
  458. }
  459. 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){
  460. luat_lcd_draw_line(conf,x1, y1, x2, y1, color);
  461. luat_lcd_draw_line(conf,x1, y1, x1, y2, color);
  462. luat_lcd_draw_line(conf,x1, y2, x2, y2, color);
  463. luat_lcd_draw_line(conf,x2, y1, x2, y2, color);
  464. return 0;
  465. }
  466. int luat_lcd_draw_circle(luat_lcd_conf_t* conf,int16_t x0, int16_t y0, uint8_t r, luat_color_t color){
  467. int a, b;
  468. int di;
  469. a = 0;
  470. b = r;
  471. di = 3 - (r << 1);
  472. while (a <= b)
  473. {
  474. luat_lcd_draw_point(conf,x0 - b, y0 - a,color);
  475. luat_lcd_draw_point(conf,x0 + b, y0 - a,color);
  476. luat_lcd_draw_point(conf,x0 - a, y0 + b,color);
  477. luat_lcd_draw_point(conf,x0 - b, y0 - a,color);
  478. luat_lcd_draw_point(conf,x0 - a, y0 - b,color);
  479. luat_lcd_draw_point(conf,x0 + b, y0 + a,color);
  480. luat_lcd_draw_point(conf,x0 + a, y0 - b,color);
  481. luat_lcd_draw_point(conf,x0 + a, y0 + b,color);
  482. luat_lcd_draw_point(conf,x0 - b, y0 + a,color);
  483. a++;
  484. //Bresenham
  485. if (di < 0)di += 4 * a + 6;
  486. else
  487. {
  488. di += 10 + 4 * (a - b);
  489. b--;
  490. }
  491. luat_lcd_draw_point(conf,x0 + a, y0 + b,color);
  492. }
  493. return 0;
  494. }