luat_lib_eink.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. @module eink
  3. @summary 墨水屏操作库
  4. @version 1.0
  5. @date 2020.11.14
  6. @demo eink
  7. */
  8. #include "luat_base.h"
  9. #include "luat_log.h"
  10. #include "luat_sys.h"
  11. #include "luat_msgbus.h"
  12. #include "luat_timer.h"
  13. #include "luat_malloc.h"
  14. #include "luat_spi.h"
  15. #include "luat_gpio.h"
  16. // #include "epd1in54.h"
  17. // #include "epd2in9.h"
  18. #include "epd.h"
  19. #include "epdpaint.h"
  20. #include "imagedata.h"
  21. #include "qrcodegen.h"
  22. #include <stdlib.h>
  23. #include "u8g2.h"
  24. #include "u8g2_luat_fonts.h"
  25. #include "luat_zbuff.h"
  26. int8_t u8g2_font_decode_get_signed_bits(u8g2_font_decode_t *f, uint8_t cnt);
  27. uint8_t u8g2_font_decode_get_unsigned_bits(u8g2_font_decode_t *f, uint8_t cnt);
  28. #define COLORED 0
  29. #define UNCOLORED 1
  30. #ifndef LUAT_LOG_TAG
  31. #define LUAT_LOG_TAG "eink"
  32. #endif
  33. typedef struct eink_ctx
  34. {
  35. uint32_t str_color;
  36. Paint paint;
  37. uint8_t fb[];
  38. }eink_ctx_t;
  39. static uint32_t ctx_index = 0;
  40. static eink_ctx_t *ctxs[2]; // 暂时只支持2种颜色, 有需要的话后续继续加
  41. static u8g2_t luat_eink_u8g2;
  42. // static uint32_t eink_str_color;
  43. // static EPD epd;
  44. // static Paint paint = {0};
  45. // static unsigned char* frame_buffer = NULL;
  46. // #ifdef econf
  47. // #undef econf
  48. // #endif
  49. eink_conf_t econf = {0};
  50. #define Pin_BUSY (econf.busy_pin)
  51. #define Pin_RES (econf.res_pin)
  52. #define Pin_DC (econf.dc_pin)
  53. #define Pin_CS (econf.cs_pin)
  54. #define SPI_ID (econf.spi_id)
  55. static int check_init(void) {
  56. if (ctxs[0] == NULL) {
  57. LLOGW("eink NOT init yet");
  58. return 0;
  59. }
  60. return 1;
  61. }
  62. /**
  63. 初始化eink
  64. @api eink.setup(full, spiid, pin_busy, pin_reset, pin_dc, pin_cs)
  65. @int 全屏刷新0,局部刷新1,默认是全屏刷新
  66. @int 所在的spi,默认是0
  67. @int Busy 忙信号管脚
  68. @int Reset 复位管脚
  69. @int DC 数据命令选择管脚
  70. @int CS 使能管脚
  71. @return boolean 成功返回true,否则返回false
  72. */
  73. static int l_eink_setup(lua_State *L) {
  74. int status = 0;
  75. econf.full_mode = luaL_optinteger(L, 1, 1);
  76. econf.spi_id = luaL_optinteger(L, 2, 0);
  77. econf.busy_pin = luaL_optinteger(L, 3, 18);
  78. econf.res_pin = luaL_optinteger(L, 4, 7);
  79. econf.dc_pin = luaL_optinteger(L, 5, 9);
  80. econf.cs_pin = luaL_optinteger(L, 6, 16);
  81. if (lua_type(L, 7) == LUA_TUSERDATA){
  82. //LLOGD("luat_spi_device_send");
  83. econf.userdata = (luat_spi_device_t*)lua_touserdata(L, 3);
  84. econf.port = LUAT_EINK_SPI_DEVICE;
  85. luat_gpio_mode(Pin_BUSY, Luat_GPIO_INPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  86. luat_gpio_mode(Pin_RES, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  87. luat_gpio_mode(Pin_DC, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  88. status = 0;
  89. }else{
  90. //LLOGD("luat_spi_send");
  91. luat_spi_t spi_config = {0};
  92. spi_config.bandrate = 2000000U;//luaL_optinteger(L, 1, 2000000U); // 2000000U
  93. spi_config.id = SPI_ID;
  94. spi_config.cs = 255; // 默认无
  95. spi_config.CPHA = 0; // CPHA0
  96. spi_config.CPOL = 0; // CPOL0
  97. spi_config.dataw = 8; // 8bit
  98. spi_config.bit_dict = 1; // MSB=1, LSB=0
  99. spi_config.master = 1; // master=1,slave=0
  100. spi_config.mode = 1; // FULL=1, half=0
  101. //先关了再开一遍
  102. luat_spi_close(spi_config.id);
  103. //LLOGD("setup GPIO for epd");
  104. status = luat_spi_setup(&spi_config);
  105. luat_gpio_mode(Pin_BUSY, Luat_GPIO_INPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  106. luat_gpio_mode(Pin_RES, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  107. luat_gpio_mode(Pin_DC, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  108. luat_gpio_mode(Pin_CS, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  109. }
  110. if (status != 0) {
  111. LLOGD("spi setup fail, eink init fail");
  112. return 0;
  113. }
  114. size_t epd_w = 0;
  115. size_t epd_h = 0;
  116. size_t colors = 0;
  117. if(status == 0)
  118. {
  119. if(econf.full_mode)
  120. status = EPD_Init(1, &epd_w, &epd_h, &colors);
  121. else
  122. status = EPD_Init(0, &epd_w, &epd_h, &colors);
  123. if (status != 0) {
  124. LLOGD("e-Paper init failed");
  125. return 0;
  126. }
  127. LLOGD("spi setup complete, now setup epd");
  128. if (colors > 2) {
  129. LLOGE("only 2 color eink supported yet");
  130. return 0;
  131. }
  132. for (size_t i = 0; i < colors; i++)
  133. {
  134. ctxs[i] = luat_heap_malloc( sizeof(eink_ctx_t) + (epd_w * epd_h + 7) / 8);
  135. if (ctxs[i] == NULL) {
  136. LLOGE("out of memory when malloc buff for eink");
  137. for (size_t j = 0; j < i - 1; j++)
  138. {
  139. luat_heap_free(ctxs[i]);
  140. ctxs[i] = NULL;
  141. }
  142. return 0;
  143. }
  144. Paint_Init(&ctxs[i]->paint, ctxs[i]->fb, epd_w, epd_h);
  145. Paint_Clear(&ctxs[i]->paint, UNCOLORED);
  146. ctxs[i]->paint.inited = 1;
  147. }
  148. }
  149. u8g2_SetFont(&(luat_eink_u8g2), u8g2_font_opposansm8);
  150. u8g2_SetFontMode(&(luat_eink_u8g2), 0);
  151. u8g2_SetFontDirection(&(luat_eink_u8g2), 0);
  152. //paint.inited = 1;
  153. //LLOGD("epd init complete");
  154. lua_pushboolean(L, 1);
  155. return 1;
  156. }
  157. /**
  158. 进入休眠模式,再次使用时需要重新初始化
  159. @api eink.sleep()
  160. */
  161. static int l_eink_sleep(lua_State *L)
  162. {
  163. EPD_Sleep();
  164. return 0;
  165. }
  166. /**
  167. 清除绘图缓冲区,默认不会马上刷新到设备
  168. @api eink.clear(color, force)
  169. @number color 可选,默认1。刷屏颜色
  170. @bool force 可选,默认false。如果为true则马上清屏
  171. @return nil 无返回值
  172. */
  173. static int l_eink_clear(lua_State *L)
  174. {
  175. int colored = luaL_optinteger(L, 1, 1);
  176. if (check_init() == 0)
  177. return 0;
  178. Paint_Clear(&ctxs[ctx_index]->paint, colored);
  179. if(lua_toboolean(L, 2))
  180. EPD_Clear();
  181. return 0;
  182. }
  183. /**
  184. 设置窗口
  185. @api eink.setWin(width, height, rotate)
  186. @int width 宽度
  187. @int height 高度
  188. @int rotate 显示方向,0/1/2/3, 相当于旋转0度/90度/180度/270度
  189. @return nil 无返回值
  190. */
  191. static int l_eink_setWin(lua_State *L)
  192. {
  193. int width = luaL_checkinteger(L, 1);
  194. int height = luaL_checkinteger(L, 2);
  195. int rotate = luaL_checkinteger(L, 3);
  196. if (check_init() == 0)
  197. return 0;
  198. Paint_SetWidth(&ctxs[ctx_index]->paint, width);
  199. Paint_SetHeight(&ctxs[ctx_index]->paint, height);
  200. Paint_SetRotate(&ctxs[ctx_index]->paint, rotate);
  201. return 0;
  202. }
  203. /**
  204. 获取窗口信息
  205. @api eink.getWin()
  206. @return int width 宽
  207. @return int height 高
  208. @return int rotate 旋转方向
  209. */
  210. static int l_eink_getWin(lua_State *L)
  211. {
  212. if (check_init() == 0)
  213. return 0;
  214. int width = Paint_GetWidth(&ctxs[ctx_index]->paint);
  215. int height = Paint_GetHeight(&ctxs[ctx_index]->paint);
  216. int rotate = Paint_GetRotate(&ctxs[ctx_index]->paint);
  217. lua_pushinteger(L, width);
  218. lua_pushinteger(L, height);
  219. lua_pushinteger(L, rotate);
  220. return 3;
  221. }
  222. static uint8_t utf8_state;
  223. static uint16_t encoding;
  224. static uint16_t utf8_next(uint8_t b)
  225. {
  226. if ( b == 0 ) /* '\n' terminates the string to support the string list procedures */
  227. return 0x0ffff; /* end of string detected, pending UTF8 is discarded */
  228. if ( utf8_state == 0 )
  229. {
  230. if ( b >= 0xfc ) /* 6 byte sequence */
  231. {
  232. utf8_state = 5;
  233. b &= 1;
  234. }
  235. else if ( b >= 0xf8 )
  236. {
  237. utf8_state = 4;
  238. b &= 3;
  239. }
  240. else if ( b >= 0xf0 )
  241. {
  242. utf8_state = 3;
  243. b &= 7;
  244. }
  245. else if ( b >= 0xe0 )
  246. {
  247. utf8_state = 2;
  248. b &= 15;
  249. }
  250. else if ( b >= 0xc0 )
  251. {
  252. utf8_state = 1;
  253. b &= 0x01f;
  254. }
  255. else
  256. {
  257. /* do nothing, just use the value as encoding */
  258. return b;
  259. }
  260. encoding = b;
  261. return 0x0fffe;
  262. }
  263. else
  264. {
  265. utf8_state--;
  266. /* The case b < 0x080 (an illegal UTF8 encoding) is not checked here. */
  267. encoding<<=6;
  268. b &= 0x03f;
  269. encoding |= b;
  270. if ( utf8_state != 0 )
  271. return 0x0fffe; /* nothing to do yet */
  272. }
  273. return encoding;
  274. }
  275. static void drawFastHLine(Paint* conf,int16_t x, int16_t y, int16_t len, uint16_t color){
  276. Paint_DrawHorizontalLine(conf,x, y, len,color);
  277. }
  278. static void drawFastVLine(Paint* conf,int16_t x, int16_t y, int16_t len, uint16_t color){
  279. Paint_DrawVerticalLine(conf,x, y, len,color);
  280. }
  281. static void u8g2_draw_hv_line(u8g2_t *u8g2, int16_t x, int16_t y, int16_t len, uint8_t dir, uint16_t color){
  282. switch(dir)
  283. {
  284. case 0:
  285. drawFastHLine(&ctxs[ctx_index]->paint,x,y,len,color);
  286. break;
  287. case 1:
  288. drawFastVLine(&ctxs[ctx_index]->paint,x,y,len,color);
  289. break;
  290. case 2:
  291. drawFastHLine(&ctxs[ctx_index]->paint,x-len+1,y,len,color);
  292. break;
  293. case 3:
  294. drawFastVLine(&ctxs[ctx_index]->paint,x,y-len+1,len,color);
  295. break;
  296. }
  297. }
  298. static void u8g2_font_decode_len(u8g2_t *u8g2, uint8_t len, uint8_t is_foreground){
  299. uint8_t cnt; /* total number of remaining pixels, which have to be drawn */
  300. uint8_t rem; /* remaining pixel to the right edge of the glyph */
  301. uint8_t current; /* number of pixels, which need to be drawn for the draw procedure */
  302. /* current is either equal to cnt or equal to rem */
  303. /* local coordinates of the glyph */
  304. uint8_t lx,ly;
  305. /* target position on the screen */
  306. int16_t x, y;
  307. u8g2_font_decode_t *decode = &(u8g2->font_decode);
  308. cnt = len;
  309. /* get the local position */
  310. lx = decode->x;
  311. ly = decode->y;
  312. for(;;){
  313. /* calculate the number of pixel to the right edge of the glyph */
  314. rem = decode->glyph_width;
  315. rem -= lx;
  316. /* calculate how many pixel to draw. This is either to the right edge */
  317. /* or lesser, if not enough pixel are left */
  318. current = rem;
  319. if ( cnt < rem )
  320. current = cnt;
  321. /* now draw the line, but apply the rotation around the glyph target position */
  322. //u8g2_font_decode_draw_pixel(u8g2, lx,ly,current, is_foreground);
  323. /* get target position */
  324. x = decode->target_x;
  325. y = decode->target_y;
  326. /* apply rotation */
  327. x = u8g2_add_vector_x(x, lx, ly, decode->dir);
  328. y = u8g2_add_vector_y(y, lx, ly, decode->dir);
  329. /* draw foreground and background (if required) */
  330. if ( current > 0 ) /* avoid drawing zero length lines, issue #4 */
  331. {
  332. if ( is_foreground )
  333. {
  334. u8g2_draw_hv_line(u8g2, x, y, current, decode->dir, ctxs[ctx_index]->str_color);
  335. }
  336. else if ( decode->is_transparent == 0 )
  337. {
  338. // u8g2_draw_hv_line(u8g2, x, y, current, decode->dir, decode->bg_color);
  339. }
  340. }
  341. /* check, whether the end of the run length code has been reached */
  342. if ( cnt < rem )
  343. break;
  344. cnt -= rem;
  345. lx = 0;
  346. ly++;
  347. }
  348. lx += cnt;
  349. decode->x = lx;
  350. decode->y = ly;
  351. }
  352. static void u8g2_font_setup_decode(u8g2_t *u8g2, const uint8_t *glyph_data)
  353. {
  354. u8g2_font_decode_t *decode = &(u8g2->font_decode);
  355. decode->decode_ptr = glyph_data;
  356. decode->decode_bit_pos = 0;
  357. /* 8 Nov 2015, this is already done in the glyph data search procedure */
  358. /*
  359. decode->decode_ptr += 1;
  360. decode->decode_ptr += 1;
  361. */
  362. decode->glyph_width = u8g2_font_decode_get_unsigned_bits(decode, u8g2->font_info.bits_per_char_width);
  363. decode->glyph_height = u8g2_font_decode_get_unsigned_bits(decode,u8g2->font_info.bits_per_char_height);
  364. }
  365. static int8_t u8g2_font_decode_glyph(u8g2_t *u8g2, const uint8_t *glyph_data){
  366. uint8_t a, b;
  367. int8_t x, y;
  368. int8_t d;
  369. int8_t h;
  370. u8g2_font_decode_t *decode = &(u8g2->font_decode);
  371. u8g2_font_setup_decode(u8g2, glyph_data);
  372. h = u8g2->font_decode.glyph_height;
  373. x = u8g2_font_decode_get_signed_bits(decode, u8g2->font_info.bits_per_char_x);
  374. y = u8g2_font_decode_get_signed_bits(decode, u8g2->font_info.bits_per_char_y);
  375. d = u8g2_font_decode_get_signed_bits(decode, u8g2->font_info.bits_per_delta_x);
  376. if ( decode->glyph_width > 0 )
  377. {
  378. decode->target_x = u8g2_add_vector_x(decode->target_x, x, -(h+y), decode->dir);
  379. decode->target_y = u8g2_add_vector_y(decode->target_y, x, -(h+y), decode->dir);
  380. //u8g2_add_vector(&(decode->target_x), &(decode->target_y), x, -(h+y), decode->dir);
  381. /* reset local x/y position */
  382. decode->x = 0;
  383. decode->y = 0;
  384. /* decode glyph */
  385. for(;;){
  386. a = u8g2_font_decode_get_unsigned_bits(decode, u8g2->font_info.bits_per_0);
  387. b = u8g2_font_decode_get_unsigned_bits(decode, u8g2->font_info.bits_per_1);
  388. do{
  389. u8g2_font_decode_len(u8g2, a, 0);
  390. u8g2_font_decode_len(u8g2, b, 1);
  391. } while( u8g2_font_decode_get_unsigned_bits(decode, 1) != 0 );
  392. if ( decode->y >= h )
  393. break;
  394. }
  395. }
  396. return d;
  397. }
  398. const uint8_t *u8g2_font_get_glyph_data(u8g2_t *u8g2, uint16_t encoding);
  399. static int16_t u8g2_font_draw_glyph(u8g2_t *u8g2, int16_t x, int16_t y, uint16_t encoding){
  400. int16_t dx = 0;
  401. u8g2->font_decode.target_x = x;
  402. u8g2->font_decode.target_y = y;
  403. const uint8_t *glyph_data = u8g2_font_get_glyph_data(u8g2, encoding);
  404. if ( glyph_data != NULL ){
  405. dx = u8g2_font_decode_glyph(u8g2, glyph_data);
  406. }
  407. return dx;
  408. }
  409. /**
  410. 设置字体
  411. @api eink.setFont(font)
  412. @userdata 字体
  413. @usage
  414. -- 设置为字体,对之后的print有效
  415. eink.setFont(eink.font_opposansm12_chinese)
  416. */
  417. static int l_eink_set_font(lua_State *L) {
  418. if (check_init() == 0) {
  419. return 0;
  420. }
  421. if (!lua_islightuserdata(L, 1)) {
  422. LLOGE("only font pointer is allow");
  423. return 0;
  424. }
  425. const uint8_t *ptr = (const uint8_t *)lua_touserdata(L, 1);
  426. if (ptr == NULL) {
  427. LLOGE("only font pointer is allow");
  428. return 0;
  429. }
  430. u8g2_SetFont(&(luat_eink_u8g2), ptr);
  431. lua_pushboolean(L, 1);
  432. return 1;
  433. }
  434. /**
  435. 绘制字符串
  436. @api eink.print(x, y, str, colored)
  437. @int x坐标
  438. @int y坐标
  439. @string 字符串
  440. @int 颜色, 可以是0或者1, 默认是0
  441. @return nil 无返回值
  442. @usage
  443. -- 先设置字体, 然后写字
  444. -- 可用字体取决于具体的固件, 如果没有你想要的大小,可以云编译一份自定义固件
  445. -- font_opposansm8_chinese
  446. -- font_opposansm10_chinese
  447. -- font_opposansm12_chinese
  448. -- font_opposansm14_chinese
  449. -- font_opposansm16_chinese
  450. eink.setFont(eink.font_opposansm12_chinese)
  451. eink.print(10, 20, "LuatOS")
  452. */
  453. static int l_eink_print(lua_State *L)
  454. {
  455. size_t len;
  456. int x = luaL_checkinteger(L, 1);
  457. int y = luaL_checkinteger(L, 2);
  458. const char *str = luaL_checklstring(L, 3, &len);
  459. if (check_init() == 0) {
  460. return 0;
  461. }
  462. ctxs[ctx_index]->str_color = luaL_optinteger(L, 4, 0);
  463. uint16_t e;
  464. int16_t delta, sum;
  465. utf8_state = 0;
  466. sum = 0;
  467. for(;;){
  468. e = utf8_next((uint8_t)*str);
  469. if ( e == 0x0ffff )
  470. break;
  471. str++;
  472. if ( e != 0x0fffe ){
  473. delta = u8g2_font_draw_glyph(&(luat_eink_u8g2), x, y, e);
  474. switch(luat_eink_u8g2.font_decode.dir){
  475. case 0:
  476. x += delta;
  477. break;
  478. case 1:
  479. y += delta;
  480. break;
  481. case 2:
  482. x -= delta;
  483. break;
  484. case 3:
  485. y -= delta;
  486. break;
  487. }
  488. sum += delta;
  489. }
  490. }
  491. return 0;
  492. }
  493. /**
  494. 将缓冲区图像输出到屏幕
  495. @api eink.show(x, y, noClear)
  496. @int x 输出的x坐标,默认0
  497. @int y 输出的y坐标,默认0
  498. @bool 可选,默认false。如果为true则不进行清屏,直接刷上新内容
  499. @return nil 无返回值
  500. */
  501. static int l_eink_show(lua_State *L)
  502. {
  503. // int x = luaL_optinteger(L, 1, 0);
  504. // int y = luaL_optinteger(L, 2, 0);
  505. int no_clear = lua_toboolean(L, 3);
  506. /* Display the frame_buffer */
  507. //EPD_SetFrameMemory(&epd, frame_buffer, x, y, Paint_GetWidth(&ctxs[ctx_index]->paint), Paint_GetHeight(&ctxs[ctx_index]->paint));
  508. //EPD_DisplayFrame(&epd);
  509. if (check_init() == 0) {
  510. return 0;
  511. }
  512. if(!no_clear)
  513. EPD_Clear();
  514. if (ctxs[1] == NULL)
  515. EPD_Display(ctxs[0]->fb, NULL);
  516. else
  517. EPD_Display(ctxs[0]->fb, ctxs[1]->fb);
  518. return 0;
  519. }
  520. /**
  521. 直接输出数据到屏幕,支持双色数据
  522. @api eink.draw(buff, buff2, noclear)
  523. @userdata zbuff指针
  524. @userdata zbuff指针
  525. @bool 可选,默认false。如果为true则不进行清屏,直接刷上新内容
  526. @return nil 无返回值
  527. */
  528. static int l_eink_draw(lua_State *L)
  529. {
  530. luat_zbuff_t* buff = tozbuff(L);
  531. luat_zbuff_t* buff2 = buff;
  532. int no_clear = lua_toboolean(L, 3);
  533. if (lua_isuserdata(L, 2)) {
  534. buff2 = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
  535. }
  536. if (check_init() == 0) {
  537. return 0;
  538. }
  539. if(!no_clear)
  540. EPD_Clear();
  541. EPD_Display(buff->addr, buff2->addr);
  542. return 0;
  543. }
  544. /**
  545. 缓冲区绘制线
  546. @api eink.line(x, y, x2, y2, colored)
  547. @int 起点x坐标
  548. @int 起点y坐标
  549. @int 终点x坐标
  550. @int 终点y坐标
  551. @return nil 无返回值
  552. @usage
  553. eink.line(0, 0, 10, 20, 0)
  554. */
  555. static int l_eink_line(lua_State *L)
  556. {
  557. int x = luaL_checkinteger(L, 1);
  558. int y = luaL_checkinteger(L, 2);
  559. int x2 = luaL_checkinteger(L, 3);
  560. int y2 = luaL_checkinteger(L, 4);
  561. int colored = luaL_optinteger(L, 5, 0);
  562. if (check_init() == 0) {
  563. return 0;
  564. }
  565. Paint_DrawLine(&ctxs[ctx_index]->paint, x, y, x2, y2, colored);
  566. return 0;
  567. }
  568. /**
  569. 缓冲区绘制矩形
  570. @api eink.rect(x, y, x2, y2, colored, fill)
  571. @int 左上顶点x坐标
  572. @int 左上顶点y坐标
  573. @int 右下顶点x坐标
  574. @int 右下顶点y坐标
  575. @int 默认是0
  576. @int 是否填充,默认是0,不填充
  577. @return nil 无返回值
  578. @usage
  579. eink.rect(0, 0, 10, 20)
  580. eink.rect(0, 0, 10, 20, 1) -- Filled
  581. */
  582. static int l_eink_rect(lua_State *L)
  583. {
  584. int x = luaL_checkinteger(L, 1);
  585. int y = luaL_checkinteger(L, 2);
  586. int x2 = luaL_checkinteger(L, 3);
  587. int y2 = luaL_checkinteger(L, 4);
  588. int colored = luaL_optinteger(L, 5, 0);
  589. int fill = luaL_optinteger(L, 6, 0);
  590. if (check_init() == 0) {
  591. return 0;
  592. }
  593. if(fill)
  594. Paint_DrawFilledRectangle(&ctxs[ctx_index]->paint, x, y, x2, y2, colored);
  595. else
  596. Paint_DrawRectangle(&ctxs[ctx_index]->paint, x, y, x2, y2, colored);
  597. return 0;
  598. }
  599. /**
  600. 缓冲区绘制圆形
  601. @api eink.circle(x, y, radius, colored, fill)
  602. @int 圆心x坐标
  603. @int 圆心y坐标
  604. @int 半径
  605. @int 默认是0
  606. @int 是否填充,默认是0,不填充
  607. @return nil 无返回值
  608. @usage
  609. eink.circle(0, 0, 10)
  610. eink.circle(0, 0, 10, 1, 1) -- Filled
  611. */
  612. static int l_eink_circle(lua_State *L)
  613. {
  614. int x = luaL_checkinteger(L, 1);
  615. int y = luaL_checkinteger(L, 2);
  616. int radius = luaL_checkinteger(L, 3);
  617. int colored = luaL_optinteger(L, 4, 0);
  618. int fill = luaL_optinteger(L, 5, 0);
  619. if (check_init() == 0) {
  620. return 0;
  621. }
  622. if(fill)
  623. Paint_DrawFilledCircle(&ctxs[ctx_index]->paint, x, y, radius, colored);
  624. else
  625. Paint_DrawCircle(&ctxs[ctx_index]->paint, x, y, radius, colored);
  626. return 0;
  627. }
  628. /**
  629. 缓冲区绘制QRCode
  630. @api eink.qrcode(x, y, str, size)
  631. @int x坐标
  632. @int y坐标
  633. @string 二维码的内容
  634. @int 可选,显示大小,不可小于21,默认21
  635. @return nil 无返回值
  636. */
  637. static int l_eink_qrcode(lua_State *L)
  638. {
  639. size_t len;
  640. int x = luaL_checkinteger(L, 1);
  641. int y = luaL_checkinteger(L, 2);
  642. const char* text = luaL_checklstring(L, 3, &len);
  643. int size = luaL_optinteger(L, 4,21);
  644. if (check_init() == 0) {
  645. return 0;
  646. }
  647. uint8_t *qrcode = luat_heap_malloc(qrcodegen_BUFFER_LEN_MAX);
  648. uint8_t *tempBuffer = luat_heap_malloc(qrcodegen_BUFFER_LEN_MAX);
  649. if (qrcode == NULL || tempBuffer == NULL) {
  650. if (qrcode)
  651. luat_heap_free(qrcode);
  652. if (tempBuffer)
  653. luat_heap_free(tempBuffer);
  654. LLOGE("qrcode out of memory");
  655. return 0;
  656. }
  657. bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode, qrcodegen_Ecc_MEDIUM,
  658. qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
  659. if (ok){
  660. int qr_size = qrcodegen_getSize(qrcode);
  661. int scale = size / qr_size ;
  662. int margin = (size - qr_size * scale) / 2;
  663. x+=margin;
  664. y+=margin;
  665. for (int j = 0; j < qr_size; j++) {
  666. for (int i = 0; i < qr_size; i++) {
  667. if (qrcodegen_getModule(qrcode, i, j))
  668. Paint_DrawFilledRectangle(&ctxs[ctx_index]->paint,x+i*scale,y+j*scale,x+(i+1)*scale,y+(j+1)*scale,0);
  669. }
  670. }
  671. }
  672. if (qrcode)
  673. luat_heap_free(qrcode);
  674. if (tempBuffer)
  675. luat_heap_free(tempBuffer);
  676. return 0;
  677. }
  678. /**
  679. 缓冲区绘制电池
  680. @api eink.bat(x, y, bat)
  681. @int x坐标
  682. @int y坐标
  683. @int 电池电压,单位毫伏
  684. @return nil 无返回值
  685. */
  686. static int l_eink_bat(lua_State *L)
  687. {
  688. int x = luaL_checkinteger(L, 1);
  689. int y = luaL_checkinteger(L, 2);
  690. int bat = luaL_checkinteger(L, 3);
  691. int batnum = 0;
  692. // eink.rect(0, 3, 2, 6)
  693. // eink.rect(2, 0, 20, 9)
  694. // eink.rect(9, 1, 19, 8, 0, 1)
  695. if(bat < 4200 && bat > 4080)batnum = 100;
  696. if(bat < 4080 && bat > 4000)batnum = 90;
  697. if(bat < 4000 && bat > 3930)batnum = 80;
  698. if(bat < 3930 && bat > 3870)batnum = 70;
  699. if(bat < 3870 && bat > 3820)batnum = 60;
  700. if(bat < 3820 && bat > 3790)batnum = 50;
  701. if(bat < 3790 && bat > 3770)batnum = 40;
  702. if(bat < 3770 && bat > 3730)batnum = 30;
  703. if(bat < 3730 && bat > 3700)batnum = 20;
  704. if(bat < 3700 && bat > 3680)batnum = 15;
  705. if(bat < 3680 && bat > 3500)batnum = 10;
  706. if(bat < 3500 && bat > 2500)batnum = 5;
  707. batnum = 20 - (int)(batnum / 5) + 3;
  708. if (check_init() == 0) {
  709. return 0;
  710. }
  711. // w外框
  712. Paint_DrawRectangle(&ctxs[ctx_index]->paint, x+0, y+3, x+2, y+6, COLORED);
  713. Paint_DrawRectangle(&ctxs[ctx_index]->paint, x+2, y+0, x+23, y+9, COLORED);
  714. // 3 ~21 100 / 5
  715. Paint_DrawFilledRectangle(&ctxs[ctx_index]->paint, x+batnum, y+1, x+22, y+8, COLORED);
  716. return 0;
  717. }
  718. /**
  719. 缓冲区绘制天气图标
  720. @api eink.weather_icon(x, y, code)
  721. @int x坐标
  722. @int y坐标
  723. @int 天气代号
  724. @return nil 无返回值
  725. */
  726. static int l_eink_weather_icon(lua_State *L)
  727. {
  728. size_t len;
  729. int x = luaL_checkinteger(L, 1);
  730. int y = luaL_checkinteger(L, 2);
  731. int code = luaL_checkinteger(L, 3);
  732. const char* str = luaL_optlstring(L, 4, "nil", &len);
  733. const unsigned char * icon = gImage_999;
  734. if (strcmp(str, "xue") == 0)code = 401;
  735. if (strcmp(str, "lei") == 0)code = 302;
  736. if (strcmp(str, "shachen") == 0)code = 503;
  737. if (strcmp(str, "wu") == 0)code = 501;
  738. if (strcmp(str, "bingbao") == 0)code = 504;
  739. if (strcmp(str, "yun") == 0)code = 103;
  740. if (strcmp(str, "yu") == 0)code = 306;
  741. if (strcmp(str, "yin") == 0)code = 101;
  742. if (strcmp(str, "qing") == 0)code = 100;
  743. // xue、lei、shachen、wu、bingbao、yun、yu、yin、qing
  744. //if(code == 64)
  745. // for(int i = 0; i < 64; i++)
  746. // {
  747. // for (int j = 0; j < 8; j++)
  748. // {
  749. // for (int k = 0; k < 8; k++)
  750. // (gImage_103[i*8+j] << k )& 0x80 ? Paint_DrawPixel(&ctxs[ctx_index]->paint, x+j*8+k, y+i, COLORED) : Paint_DrawPixel(&ctxs[ctx_index]->paint, x+j*8+k, y+i, UNCOLORED);
  751. // }
  752. // }
  753. if (check_init() == 0) {
  754. return 0;
  755. }
  756. switch (code)
  757. {
  758. case 100:icon = gImage_100;break;
  759. case 101:icon = gImage_101;break;
  760. case 102:icon = gImage_102;break;
  761. case 103:icon = gImage_103;break;
  762. case 104:icon = gImage_104;break;
  763. case 200:icon = gImage_200;break;
  764. case 201:icon = gImage_201;break;
  765. case 205:icon = gImage_205;break;
  766. case 208:icon = gImage_208;break;
  767. case 301:icon = gImage_301;break;
  768. case 302:icon = gImage_302;break;
  769. case 303:icon = gImage_303;break;
  770. case 304:icon = gImage_304;break;
  771. case 305:icon = gImage_305;break;
  772. case 306:icon = gImage_306;break;
  773. case 307:icon = gImage_307;break;
  774. case 308:icon = gImage_308;break;
  775. case 309:icon = gImage_309;break;
  776. case 310:icon = gImage_310;break;
  777. case 311:icon = gImage_311;break;
  778. case 312:icon = gImage_312;break;
  779. case 313:icon = gImage_313;break;
  780. case 400:icon = gImage_400;break;
  781. case 401:icon = gImage_401;break;
  782. case 402:icon = gImage_402;break;
  783. case 403:icon = gImage_403;break;
  784. case 404:icon = gImage_404;break;
  785. case 405:icon = gImage_405;break;
  786. case 406:icon = gImage_406;break;
  787. case 407:icon = gImage_407;break;
  788. case 500:icon = gImage_500;break;
  789. case 501:icon = gImage_501;break;
  790. case 502:icon = gImage_502;break;
  791. case 503:icon = gImage_503;break;
  792. case 504:icon = gImage_504;break;
  793. case 507:icon = gImage_507;break;
  794. case 508:icon = gImage_508;break;
  795. case 900:icon = gImage_900;break;
  796. case 901:icon = gImage_901;break;
  797. case 999:icon = gImage_999;break;
  798. default:
  799. break;
  800. }
  801. for(int i = 0; i < 48; i++)
  802. {
  803. for (int j = 0; j < 6; j++)
  804. {
  805. for (int k = 0; k < 8; k++)
  806. (icon[i*6+j] << k )& 0x80 ? Paint_DrawPixel(&ctxs[ctx_index]->paint, x+j*8+k, y+i, COLORED) : Paint_DrawPixel(&ctxs[ctx_index]->paint, x+j*8+k, y+i, UNCOLORED);
  807. }
  808. }
  809. return 0;
  810. }
  811. /**
  812. 设置墨水屏驱动型号
  813. @api eink.model(m)
  814. @int 型号名称, 例如 eink.model(eink.MODEL_1in54_V2)
  815. @return nil 无返回值
  816. */
  817. static int l_eink_model(lua_State *L) {
  818. EPD_Model(luaL_checkinteger(L, 1));
  819. return 0;
  820. }
  821. #ifdef LUAT_USE_GTFONT
  822. #include "GT5SLCD2E_1A.h"
  823. extern void gtfont_draw_w(unsigned char *pBits,unsigned int x,unsigned int y,unsigned int widt,unsigned int high,int(*point)(void*),void* userdata,int mode);
  824. extern void gtfont_draw_gray_hz(unsigned char *data,unsigned short x,unsigned short y,unsigned short w ,unsigned short h,unsigned char grade, unsigned char HB_par,int(*point)(void*,uint16_t, uint16_t, uint32_t),void* userdata,int mode);
  825. static int l_eink_draw_gtfont_gb2312(lua_State *L) {
  826. unsigned char buf[128];
  827. int len;
  828. int i = 0;
  829. uint8_t strhigh,strlow ;
  830. uint16_t str;
  831. const char *fontCode = luaL_checklstring(L, 1,&len);
  832. unsigned char size = luaL_checkinteger(L, 2);
  833. int x = luaL_checkinteger(L, 3);
  834. int y = luaL_checkinteger(L, 4);
  835. while ( i < len){
  836. strhigh = *fontCode;
  837. fontCode++;
  838. strlow = *fontCode;
  839. str = (strhigh<<8)|strlow;
  840. fontCode++;
  841. get_font(buf, 1, str, size, size, size);
  842. gtfont_draw_w(buf , x ,y , size , size,Paint_DrawPixel,&ctxs[ctx_index]->paint,1);
  843. x+=size;
  844. i+=2;
  845. }
  846. return 0;
  847. }
  848. static int l_eink_draw_gtfont_gb2312_gray(lua_State* L) {
  849. unsigned char buf[2048];
  850. int len;
  851. int i = 0;
  852. uint8_t strhigh,strlow ;
  853. uint16_t str;
  854. const char *fontCode = luaL_checklstring(L, 1,&len);
  855. unsigned char size = luaL_checkinteger(L, 2);
  856. unsigned char font_g = luaL_checkinteger(L, 3);
  857. int x = luaL_checkinteger(L, 4);
  858. int y = luaL_checkinteger(L, 5);
  859. while ( i < len){
  860. strhigh = *fontCode;
  861. fontCode++;
  862. strlow = *fontCode;
  863. str = (strhigh<<8)|strlow;
  864. fontCode++;
  865. get_font(buf, 1, str, size*font_g, size*font_g, size*font_g);
  866. Gray_Process(buf,size,size,font_g);
  867. gtfont_draw_gray_hz(buf, x, y, size , size, font_g, 1,Paint_DrawPixel,&ctxs[ctx_index]->paint,1);
  868. x+=size;
  869. i+=2;
  870. }
  871. return 0;
  872. }
  873. #ifdef LUAT_USE_GTFONT_UTF8
  874. extern unsigned short unicodetogb2312 ( unsigned short chr);
  875. static int l_eink_draw_gtfont_utf8(lua_State *L) {
  876. unsigned char buf[128];
  877. int len;
  878. int i = 0;
  879. uint8_t strhigh,strlow ;
  880. uint16_t e,str;
  881. const char *fontCode = luaL_checklstring(L, 1,&len);
  882. unsigned char size = luaL_checkinteger(L, 2);
  883. int x = luaL_checkinteger(L, 3);
  884. int y = luaL_checkinteger(L, 4);
  885. for(;;){
  886. e = utf8_next((uint8_t)*fontCode);
  887. if ( e == 0x0ffff )
  888. break;
  889. fontCode++;
  890. if ( e != 0x0fffe ){
  891. uint16_t str = unicodetogb2312(e);
  892. get_font(buf, 1, str, size, size, size);
  893. gtfont_draw_w(buf , x ,y , size , size,Paint_DrawPixel,&ctxs[ctx_index]->paint,1);
  894. x+=size;
  895. }
  896. }
  897. return 0;
  898. }
  899. static int l_eink_draw_gtfont_utf8_gray(lua_State* L) {
  900. unsigned char buf[2048];
  901. int len;
  902. int i = 0;
  903. uint8_t strhigh,strlow ;
  904. uint16_t e,str;
  905. const char *fontCode = luaL_checklstring(L, 1,&len);
  906. unsigned char size = luaL_checkinteger(L, 2);
  907. unsigned char font_g = luaL_checkinteger(L, 3);
  908. int x = luaL_checkinteger(L, 4);
  909. int y = luaL_checkinteger(L, 5);
  910. for(;;){
  911. e = utf8_next((uint8_t)*fontCode);
  912. if ( e == 0x0ffff )
  913. break;
  914. fontCode++;
  915. if ( e != 0x0fffe ){
  916. uint16_t str = unicodetogb2312(e);
  917. get_font(buf, 1, str, size*font_g, size*font_g, size*font_g);
  918. Gray_Process(buf,size,size,font_g);
  919. gtfont_draw_gray_hz(buf, x, y, size , size, font_g, 1,Paint_DrawPixel,&ctxs[ctx_index]->paint,1);
  920. x+=size;
  921. }
  922. }
  923. return 0;
  924. }
  925. #endif // LUAT_USE_GTFONT_UTF8
  926. #endif // LUAT_USE_GTFONT
  927. static void eink_DrawHXBM(uint16_t x, uint16_t y, uint16_t len, const uint8_t *b){
  928. uint8_t mask = 1;
  929. if (check_init() == 0) {
  930. return;
  931. }
  932. while(len > 0) {
  933. if ( *b & mask ) drawFastHLine(&ctxs[ctx_index]->paint, x, y, 1,COLORED);
  934. else drawFastVLine(&ctxs[ctx_index]->paint, x, y, 1,UNCOLORED);
  935. x++;
  936. mask <<= 1;
  937. if ( mask == 0 ){
  938. mask = 1;
  939. b++;
  940. }
  941. len--;
  942. }
  943. }
  944. /*
  945. 绘制位图
  946. @api eink.drawXbm(x, y, w, h, data)
  947. @int X坐标
  948. @int y坐标
  949. @int 位图宽
  950. @int 位图高
  951. @int 位图数据,每一位代表一个像素
  952. @usage
  953. -- 取模使用PCtoLCD2002软件即可
  954. -- 在(0,0)为左上角,绘制 16x16 "今" 的位图
  955. eink.drawXbm(0, 0, 16,16, string.char(
  956. 0x80,0x00,0x80,0x00,0x40,0x01,0x20,0x02,0x10,0x04,0x48,0x08,0x84,0x10,0x83,0x60,
  957. 0x00,0x00,0xF8,0x0F,0x00,0x08,0x00,0x04,0x00,0x04,0x00,0x02,0x00,0x01,0x80,0x00
  958. ))
  959. */
  960. static int l_eink_drawXbm(lua_State *L){
  961. int x = luaL_checkinteger(L, 1);
  962. int y = luaL_checkinteger(L, 2);
  963. int w = luaL_checkinteger(L, 3);
  964. int h = luaL_checkinteger(L, 4);
  965. size_t len = 0;
  966. const char* data = luaL_checklstring(L, 5, &len);
  967. if (h < 1) return 0; // 行数必须大于0
  968. if (len*8/h < w) return 0; // 起码要填满一行
  969. if (len != h*w/8)return 0;
  970. if (check_init() == 0) {
  971. return 0;
  972. }
  973. uint8_t blen;
  974. blen = w;
  975. blen += 7;
  976. blen >>= 3;
  977. while( h > 0 ){
  978. eink_DrawHXBM(x, y, w, (const uint8_t*)data);
  979. data += blen;
  980. y++;
  981. h--;
  982. }
  983. lua_pushboolean(L, 1);
  984. return 1;
  985. }
  986. /*
  987. 切换颜色画板, 适合多色墨水屏
  988. @api eink.setCtx(index)
  989. @int 颜色索引, 黑色为0, 红色为1
  990. @usage
  991. -- 仅适合多色墨水屏, 对单色墨水屏(只有黑白)的无效
  992. eink.setCtx(1)
  993. -- 切换后, 所有drawXXX都会操作在指定颜色的画板
  994. */
  995. static int l_eink_set_ctx(lua_State *L) {
  996. int index = luaL_checkinteger(L, 1);
  997. if (index < 0 || index > 1) {
  998. LLOGE("invaild ctx index %d", index);
  999. return 0;
  1000. }
  1001. if (ctxs[index] == NULL) {
  1002. LLOGE("invaild ctx index %d", index);
  1003. return 0;
  1004. }
  1005. ctx_index = index;
  1006. lua_pushboolean(L, 1);
  1007. return 1;
  1008. }
  1009. #include "rotable2.h"
  1010. static const rotable_Reg_t reg_eink[] =
  1011. {
  1012. { "setup", ROREG_FUNC(l_eink_setup)},
  1013. { "sleep", ROREG_FUNC(l_eink_sleep)},
  1014. { "clear", ROREG_FUNC(l_eink_clear)},
  1015. { "setWin", ROREG_FUNC(l_eink_setWin)},
  1016. { "getWin", ROREG_FUNC(l_eink_getWin)},
  1017. { "print", ROREG_FUNC(l_eink_print)},
  1018. { "show", ROREG_FUNC(l_eink_show)},
  1019. { "rect", ROREG_FUNC(l_eink_rect)},
  1020. { "circle", ROREG_FUNC(l_eink_circle)},
  1021. { "line", ROREG_FUNC(l_eink_line)},
  1022. { "setFont", ROREG_FUNC(l_eink_set_font)},
  1023. { "qrcode", ROREG_FUNC(l_eink_qrcode)},
  1024. { "bat", ROREG_FUNC(l_eink_bat)},
  1025. { "weather_icon", ROREG_FUNC(l_eink_weather_icon)},
  1026. { "model", ROREG_FUNC(l_eink_model)},
  1027. { "drawXbm", ROREG_FUNC(l_eink_drawXbm)},
  1028. { "draw", ROREG_FUNC(l_eink_draw)},
  1029. { "setCtx", ROREG_FUNC(l_eink_set_ctx)},
  1030. #ifdef LUAT_USE_GTFONT
  1031. { "drawGtfontGb2312", ROREG_FUNC(l_eink_draw_gtfont_gb2312)},
  1032. { "drawGtfontGb2312Gray", ROREG_FUNC(l_eink_draw_gtfont_gb2312_gray)},
  1033. #ifdef LUAT_USE_GTFONT_UTF8
  1034. { "drawGtfontUtf8", ROREG_FUNC(l_eink_draw_gtfont_utf8)},
  1035. { "drawGtfontUtf8Gray", ROREG_FUNC(l_eink_draw_gtfont_utf8_gray)},
  1036. #endif // LUAT_USE_GTFONT_UTF8
  1037. #endif // LUAT_USE_GTFONT
  1038. //@const MODEL_1in02d number 1.02寸d
  1039. { "MODEL_1in02d", ROREG_INT(MODEL_1in02d)},
  1040. //@const MODEL_1in54 number 1.54寸
  1041. { "MODEL_1in54", ROREG_INT(MODEL_1in54)},
  1042. //@const MODEL_1in54_V2 number 1.54寸_V2
  1043. { "MODEL_1in54_V2", ROREG_INT(MODEL_1in54_V2)},
  1044. //@const MODEL_1in54b number 1.54寸b
  1045. { "MODEL_1in54b", ROREG_INT(MODEL_1in54b)},
  1046. //@const MODEL_1in54b_V2 number 1.54寸b_V2
  1047. { "MODEL_1in54b_V2", ROREG_INT(MODEL_1in54b_V2)},
  1048. //@const MODEL_1in54_V3 number 1.54寸_V3
  1049. { "MODEL_1in54_V3", ROREG_INT(MODEL_1in54_V3)},
  1050. //@const MODEL_1in54c number 1.54寸c
  1051. { "MODEL_1in54c", ROREG_INT(MODEL_1in54c)},
  1052. //@const MODEL_1in54f number 1.54寸f
  1053. { "MODEL_1in54f", ROREG_INT(MODEL_1in54f)},
  1054. //@const MODEL_2in54b_V3 number 2.13寸b_V3
  1055. { "MODEL_2in54b_V3", ROREG_INT(MODEL_2in13b_V3)},
  1056. //@const MODEL_2in7 number 2.7寸
  1057. { "MODEL_2in7", ROREG_INT(MODEL_2in7)},
  1058. //@const MODEL_2in7b number 2.7寸b
  1059. { "MODEL_2in7b", ROREG_INT(MODEL_2in7b)},
  1060. //@const MODEL_2in9 number 2.9寸
  1061. { "MODEL_2in9", ROREG_INT(MODEL_2in9)},
  1062. //@const MODEL_2in9_V2 number 2.9寸_V2
  1063. { "MODEL_2in9_V2", ROREG_INT(MODEL_2in9_V2)},
  1064. //@const MODEL_2in9bc number 2.9寸bc
  1065. { "MODEL_2in9bc", ROREG_INT(MODEL_2in9bc)},
  1066. //@const MODEL_2in9b_V3 number 2.9寸b_V3
  1067. { "MODEL_2in9b_V3", ROREG_INT(MODEL_2in9b_V3)},
  1068. //@const MODEL_2in9d number 2.9寸d
  1069. { "MODEL_2in9d", ROREG_INT(MODEL_2in9d)},
  1070. //@const MODEL_2in9f number 2.9寸f
  1071. { "MODEL_2in9f", ROREG_INT(MODEL_2in9ff)},
  1072. //@const MODEL_3in7 number 3.7寸
  1073. { "MODEL_3in7", ROREG_INT(MODEL_3in7)},
  1074. // 默认只带8号字体
  1075. //@const font_opposansm8 font 8号字体
  1076. { "font_opposansm8", ROREG_PTR((void*)u8g2_font_opposansm8)},
  1077. #ifdef USE_U8G2_OPPOSANSM_ENGLISH
  1078. //@const font_unifont_t_symbols font 符号字体
  1079. { "font_unifont_t_symbols", ROREG_PTR((void*)u8g2_font_unifont_t_symbols)},
  1080. //@const font_open_iconic_weather_6x_t font 天气字体
  1081. { "font_open_iconic_weather_6x_t", ROREG_PTR((void*)u8g2_font_open_iconic_weather_6x_t)},
  1082. //@const font_opposansm10 font 10号字体
  1083. //@const font_opposansm12 font 12号字体
  1084. //@const font_opposansm16 font 16号字体
  1085. //@const font_opposansm18 font 18号字体
  1086. //@const font_opposansm20 font 20号字体
  1087. //@const font_opposansm22 font 22号字体
  1088. //@const font_opposansm24 font 24号字体
  1089. //@const font_opposansm32 font 32号字体
  1090. { "font_opposansm10", ROREG_PTR((void*)u8g2_font_opposansm10)},
  1091. { "font_opposansm12", ROREG_PTR((void*)u8g2_font_opposansm12)},
  1092. { "font_opposansm16", ROREG_PTR((void*)u8g2_font_opposansm16)},
  1093. { "font_opposansm18", ROREG_PTR((void*)u8g2_font_opposansm18)},
  1094. { "font_opposansm20", ROREG_PTR((void*)u8g2_font_opposansm20)},
  1095. { "font_opposansm22", ROREG_PTR((void*)u8g2_font_opposansm22)},
  1096. { "font_opposansm24", ROREG_PTR((void*)u8g2_font_opposansm24)},
  1097. { "font_opposansm32", ROREG_PTR((void*)u8g2_font_opposansm32)},
  1098. #endif
  1099. #ifdef USE_U8G2_OPPOSANSM8_CHINESE
  1100. //@const font_opposansm8_chinese font 8号中文字体
  1101. { "font_opposansm8_chinese", ROREG_PTR((void*)u8g2_font_opposansm8_chinese)},
  1102. #endif
  1103. #ifdef USE_U8G2_OPPOSANSM10_CHINESE
  1104. //@const font_opposansm8_chinese font 10号中文字体
  1105. { "font_opposansm10_chinese", ROREG_PTR((void*)u8g2_font_opposansm10_chinese)},
  1106. #endif
  1107. #ifdef USE_U8G2_OPPOSANSM12_CHINESE
  1108. //@const font_opposansm12_chinese font 12号中文字体
  1109. { "font_opposansm12_chinese", ROREG_PTR((void*)u8g2_font_opposansm12_chinese)},
  1110. #endif
  1111. #ifdef USE_U8G2_OPPOSANSM16_CHINESE
  1112. //@const font_opposansm16_chinese font 16号中文字体
  1113. { "font_opposansm16_chinese", ROREG_PTR((void*)u8g2_font_opposansm16_chinese)},
  1114. #endif
  1115. #ifdef USE_U8G2_OPPOSANSM18_CHINESE
  1116. //@const font_opposansm18_chinese font 18号中文字体
  1117. { "font_opposansm18_chinese", ROREG_PTR((void*)u8g2_font_opposansm18_chinese)},
  1118. #endif
  1119. #ifdef USE_U8G2_OPPOSANSM20_CHINESE
  1120. //@const font_opposansm20_chinese font 20号中文字体
  1121. { "font_opposansm20_chinese", ROREG_PTR((void*)u8g2_font_opposansm20_chinese)},
  1122. #endif
  1123. #ifdef USE_U8G2_OPPOSANSM22_CHINESE
  1124. //@const font_opposansm22_chinese font 22号中文字体
  1125. { "font_opposansm22_chinese", ROREG_PTR((void*)u8g2_font_opposansm22_chinese)},
  1126. #endif
  1127. #ifdef USE_U8G2_OPPOSANSM24_CHINESE
  1128. //@const font_opposansm24_chinese font 24号中文字体
  1129. { "font_opposansm24_chinese", ROREG_PTR((void*)u8g2_font_opposansm24_chinese)},
  1130. #endif
  1131. #ifdef USE_U8G2_OPPOSANSM32_CHINESE
  1132. //@const font_opposansm32_chinese font 32号中文字体
  1133. { "font_opposansm32_chinese", ROREG_PTR((void*)u8g2_font_opposansm32_chinese)},
  1134. #endif
  1135. { "MODEL_1in02d", ROREG_INT(MODEL_1in02d)},
  1136. { "MODEL_1in54", ROREG_INT(MODEL_1in54)},
  1137. { "MODEL_1in54b", ROREG_INT(MODEL_1in54b)},
  1138. { "MODEL_1in54b_V2", ROREG_INT(MODEL_1in54b_V2)},
  1139. { "MODEL_1in54c", ROREG_INT(MODEL_1in54c)},
  1140. { "MODEL_1in54f", ROREG_INT(MODEL_1in54f)},
  1141. { "MODEL_1in54_V2", ROREG_INT(MODEL_1in54_V2)},
  1142. { "MODEL_1in54_V3", ROREG_INT(MODEL_1in54_V3)},
  1143. { "MODEL_2in13", ROREG_INT(MODEL_2in13)},
  1144. { "MODEL_2in13bc", ROREG_INT(MODEL_2in13bc)},
  1145. { "MODEL_2in13b_V3", ROREG_INT(MODEL_2in13b_V3)},
  1146. { "MODEL_2in13d", ROREG_INT(MODEL_2in13d)},
  1147. { "MODEL_2in13_V2", ROREG_INT(MODEL_2in13_V2)},
  1148. { "MODEL_2in66", ROREG_INT(MODEL_2in66)},
  1149. { "MODEL_2in66b", ROREG_INT(MODEL_2in66b)},
  1150. { "MODEL_2in7", ROREG_INT(MODEL_2in7)},
  1151. { "MODEL_2in7b", ROREG_INT(MODEL_2in7b)},
  1152. { "MODEL_2in9", ROREG_INT(MODEL_2in9)},
  1153. { "MODEL_2in9bc", ROREG_INT(MODEL_2in9bc)},
  1154. { "MODEL_2in9b_V3", ROREG_INT(MODEL_2in9b_V3)},
  1155. { "MODEL_2in9d", ROREG_INT(MODEL_2in9d)},
  1156. { "MODEL_2in9ff", ROREG_INT(MODEL_2in9ff)},
  1157. { "MODEL_2in9_V2", ROREG_INT(MODEL_2in9_V2)},
  1158. { "MODEL_3in7", ROREG_INT(MODEL_3in7)},
  1159. { "MODEL_4in2", ROREG_INT(MODEL_4in2)},
  1160. { "MODEL_4in2bc", ROREG_INT(MODEL_4in2bc)},
  1161. { "MODEL_4in2b_V2", ROREG_INT(MODEL_4in2b_V2)},
  1162. { "MODEL_5in65f", ROREG_INT(MODEL_5in65f)},
  1163. { "MODEL_5in83", ROREG_INT(MODEL_5in83)},
  1164. { "MODEL_5in83bc", ROREG_INT(MODEL_5in83bc)},
  1165. { "MODEL_5in83b_V2", ROREG_INT(MODEL_5in83b_V2)},
  1166. { "MODEL_5in83_V2", ROREG_INT(MODEL_5in83_V2)},
  1167. { "MODEL_7in5", ROREG_INT(MODEL_7in5)},
  1168. { "MODEL_7in5bc", ROREG_INT(MODEL_7in5bc)},
  1169. { "MODEL_7in5b_HD", ROREG_INT(MODEL_7in5b_HD)},
  1170. { "MODEL_7in5b_V2", ROREG_INT(MODEL_7in5b_V2)},
  1171. { "MODEL_7in5_HD", ROREG_INT(MODEL_7in5_HD)},
  1172. { "MODEL_7in5_V2", ROREG_INT(MODEL_7in5_V2)},
  1173. { NULL, ROREG_INT(0)}
  1174. };
  1175. LUAMOD_API int luaopen_eink( lua_State *L ){
  1176. luat_newlib2(L, reg_eink);
  1177. return 1;
  1178. }