luat_lib_disp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /*
  2. @module disp
  3. @summary 显示屏控制
  4. @version 1.0
  5. @date 2020.03.30
  6. */
  7. #include "luat_base.h"
  8. #include "luat_malloc.h"
  9. #include "luat_disp.h"
  10. #include "luat_gpio.h"
  11. #include "luat_timer.h"
  12. #include "luat_i2c.h"
  13. #include "u8g2.h"
  14. #include "u8g2_luat_fonts.h"
  15. #define LUAT_LOG_TAG "disp"
  16. #include "luat_log.h"
  17. static u8g2_t* u8g2;
  18. static int u8g2_lua_ref;
  19. static uint8_t i2c_id;
  20. //static uint8_t i2c_addr = 0x3C;
  21. //static uint8_t spi_id;
  22. /*
  23. 显示屏初始化
  24. @api disp.init(conf)
  25. @table 配置信息
  26. @return int 正常初始化1,已经初始化过2,内存不够3,初始化失败返回4
  27. @usage
  28. -- 初始化模拟i2c的ssd1306
  29. if disp.init({mode="i2c_sw", pin0=17, pin1=18}) == 1 then
  30. log.info("disp", "disp init complete")
  31. end
  32. -- 初始化硬件i2c0的ssd1306
  33. i2c.setup(0, i2c.FAST)
  34. if disp.init({mode="i2c_hw", i2c_id=0}) == 1 then
  35. log.info("disp", "disp init complete")
  36. end
  37. */
  38. static int l_disp_init(lua_State *L) {
  39. if (u8g2 != NULL) {
  40. LLOGW("disp is aready inited");
  41. lua_pushinteger(L, 2);
  42. return 1;
  43. }
  44. u8g2 = (u8g2_t*)lua_newuserdata(L, sizeof(u8g2_t));
  45. if (u8g2 == NULL) {
  46. LLOGE("lua_newuserdata return NULL, out of memory ?!");
  47. lua_pushinteger(L, 3);
  48. return 1;
  49. }
  50. // TODO: 暂时只支持SSD1306 12864, I2C接口-> i2c1soft, 软件模拟
  51. luat_disp_conf_t conf = {0};
  52. conf.pinType = 2; // I2C 硬件(或者是个假硬件)
  53. conf.ptr = u8g2;
  54. if (lua_istable(L, 1)) {
  55. // 参数解析
  56. lua_pushliteral(L, "mode");
  57. lua_gettable(L, 1);
  58. if (lua_isstring(L, -1)) {
  59. const char* mode = luaL_checkstring(L, -1);
  60. LLOGD("mode = [%s]", mode);
  61. if (strcmp("i2c_sw", mode) == 0) {
  62. LLOGD("using i2c_sw");
  63. conf.pinType = 1;
  64. }
  65. else if (strcmp("i2c_hw", mode) == 0) {
  66. LLOGD("using i2c_hw");
  67. conf.pinType = 2;
  68. }
  69. else if (strcmp("spi_sw_3pin", mode) == 0) {
  70. LLOGD("using spi_sw_3pin");
  71. conf.pinType = 3;
  72. }
  73. else if (strcmp("spi_sw_4pin", mode) == 0) {
  74. LLOGD("using spi_sw_4pin");
  75. conf.pinType = 4;
  76. }
  77. else if (strcmp("spi_hw_4pin", mode) == 0) {
  78. LLOGD("using spi_hw_4pin");
  79. conf.pinType = 5;
  80. }
  81. }
  82. lua_pop(L, 1);
  83. // 解析pin0 ~ pin7
  84. lua_pushliteral(L, "pin0");
  85. lua_gettable(L, 1);
  86. if (lua_isinteger(L, -1)) {
  87. conf.pin0 = luaL_checkinteger(L, -1);
  88. }
  89. lua_pop(L, 1);
  90. lua_pushliteral(L, "pin1");
  91. lua_gettable(L, 1);
  92. if (lua_isinteger(L, -1)) {
  93. conf.pin1 = luaL_checkinteger(L, -1);
  94. }
  95. lua_pop(L, 1);
  96. lua_pushliteral(L, "pin2");
  97. lua_gettable(L, 1);
  98. if (lua_isinteger(L, -1)) {
  99. conf.pin2 = luaL_checkinteger(L, -1);
  100. }
  101. lua_pop(L, 1);
  102. lua_pushliteral(L, "pin3");
  103. lua_gettable(L, 1);
  104. if (lua_isinteger(L, -1)) {
  105. conf.pin3 = luaL_checkinteger(L, -1);
  106. }
  107. lua_pop(L, 1);
  108. lua_pushliteral(L, "i2c_id");
  109. lua_gettable(L, 1);
  110. if (lua_isinteger(L, -1)) {
  111. i2c_id = luaL_checkinteger(L, -1);
  112. }
  113. lua_pop(L, 1);
  114. // lua_pushliteral(L, "i2c_addr");
  115. // lua_gettable(L, 1);
  116. // if (lua_isinteger(L, -1)) {
  117. // i2c_addr = luaL_checkinteger(L, -1);
  118. // }
  119. // lua_pop(L, 1);
  120. // lua_pushliteral(L, "spi_id");
  121. // lua_gettable(L, 1);
  122. // if (lua_isinteger(L, -1)) {
  123. // spi_id = luaL_checkinteger(L, -1);
  124. // }
  125. // lua_pop(L, 1);
  126. // pin4 ~ pin7暂时用不到,先不设置了
  127. }
  128. LLOGD("pinType=%d", conf.pinType);
  129. if (luat_disp_setup(&conf)) {
  130. u8g2 = NULL;
  131. LLOGW("disp init fail");
  132. lua_pushinteger(L, 4);
  133. return 1; // 初始化失败
  134. }
  135. u8g2_lua_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  136. u8g2_SetFont(u8g2, u8g2_font_ncenB08_tr); // 设置默认字体
  137. lua_pushinteger(L, 1);
  138. return 1;
  139. }
  140. /*
  141. 关闭显示屏
  142. @api disp.close()
  143. @usage
  144. -- 关闭disp,再次使用disp相关API的话,需要重新初始化
  145. disp.close()
  146. */
  147. static int l_disp_close(lua_State *L) {
  148. if (u8g2_lua_ref != 0) {
  149. lua_geti(L, LUA_REGISTRYINDEX, u8g2_lua_ref);
  150. if (lua_isuserdata(L, -1)) {
  151. luaL_unref(L, LUA_REGISTRYINDEX, u8g2_lua_ref);
  152. }
  153. u8g2_lua_ref = 0;
  154. }
  155. lua_gc(L, LUA_GCCOLLECT, 0);
  156. u8g2 = NULL;
  157. return 0;
  158. }
  159. /*
  160. @api disp.clear() 清屏
  161. @usage
  162. -- 清屏
  163. disp.clear()
  164. */
  165. static int l_disp_clear(lua_State *L) {
  166. if (u8g2 == NULL) return 0;
  167. u8g2_ClearBuffer(u8g2);
  168. return 0;
  169. }
  170. /*
  171. 把显示数据更新到屏幕
  172. @api disp.update()
  173. @usage
  174. -- 把显示数据更新到屏幕
  175. disp.update()
  176. */
  177. static int l_disp_update(lua_State *L) {
  178. if (u8g2 == NULL) return 0;
  179. u8g2_SendBuffer(u8g2);
  180. return 0;
  181. }
  182. /*
  183. 在显示屏上画一段文字,要调用disp.update才会更新到屏幕
  184. @api disp.drawStr(content, x, y)
  185. @string 文件内容
  186. @int 横坐标
  187. @int 竖坐标
  188. @usage
  189. disp.drawStr("wifi is ready", 10, 20)
  190. */
  191. static int l_disp_draw_text(lua_State *L) {
  192. if (u8g2 == NULL) {
  193. LLOGW("disp not init yet!!!");
  194. return 0;
  195. }
  196. size_t len;
  197. size_t x, y;
  198. const char* str = luaL_checklstring(L, 1, &len);
  199. x = luaL_checkinteger(L, 2);
  200. y = luaL_checkinteger(L, 3);
  201. u8g2_DrawUTF8(u8g2, x, y, str);
  202. return 0;
  203. }
  204. /*
  205. 设置字体
  206. @api disp.setFont(fontId)
  207. @int 字体id, 默认0,纯英文8x8字节. 如果支持中文支持, 那么1代表12x12的中文字体.
  208. @usage
  209. -- 设置为中文字体,对之后的drawStr有效
  210. disp.setFont(1)
  211. */
  212. static int l_disp_set_font(lua_State *L) {
  213. if (u8g2 == NULL) {
  214. LLOGI("disp not init yet!!!");
  215. lua_pushboolean(L, 0);
  216. return 1;
  217. }
  218. int font_id = luaL_checkinteger(L, 1);
  219. if (font_id < 0) {
  220. lua_pushboolean(L, 0);
  221. }
  222. else {
  223. switch (font_id)
  224. {
  225. case 0:
  226. u8g2_SetFont(u8g2, u8g2_font_ncenB08_tr);
  227. lua_pushboolean(L, 1);
  228. break;
  229. #if defined USE_U8G2_OPPOSANSM12_CHINESE
  230. case 1:
  231. u8g2_SetFont(u8g2, u8g2_font_opposansm12_chinese);
  232. lua_pushboolean(L, 1);
  233. break;
  234. #endif
  235. default:
  236. lua_pushboolean(L, 0);
  237. break;
  238. }
  239. }
  240. return 1;
  241. }
  242. #include "rotable2.h"
  243. static const rotable_Reg_t reg_disp[] =
  244. {
  245. { "init", ROREG_FUNC(l_disp_init)},
  246. { "close", ROREG_FUNC(l_disp_close)},
  247. { "clear", ROREG_FUNC(l_disp_clear)},
  248. { "update", ROREG_FUNC(l_disp_update)},
  249. { "drawStr", ROREG_FUNC(l_disp_draw_text)},
  250. { "setFont", ROREG_FUNC(l_disp_set_font)},
  251. { NULL, {}}
  252. };
  253. LUAMOD_API int luaopen_disp( lua_State *L ) {
  254. u8g2_lua_ref = 0;
  255. u8g2 = NULL;
  256. luat_newlib2(L, reg_disp);
  257. return 1;
  258. }
  259. //-----------------------------
  260. // 往下是一些U8G2方法的默认实现
  261. uint8_t luat_u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
  262. uint8_t luat_u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
  263. LUAT_WEAK int luat_disp_setup(luat_disp_conf_t *conf) {
  264. if (conf->pinType == 1) {
  265. u8g2_t* u8g2 = (u8g2_t*)conf->ptr;
  266. u8g2_Setup_ssd1306_i2c_128x64_noname_f( u8g2, U8G2_R0, u8x8_byte_sw_i2c, luat_u8x8_gpio_and_delay);
  267. u8g2->u8x8.pins[U8X8_PIN_I2C_CLOCK] = conf->pin0;
  268. u8g2->u8x8.pins[U8X8_PIN_I2C_DATA] = conf->pin1;
  269. LLOGD("setup disp i2c.sw SCL=%ld SDA=%ld", conf->pin0, conf->pin1);
  270. u8g2_InitDisplay(u8g2);
  271. u8g2_SetPowerSave(u8g2, 0);
  272. return 0;
  273. }
  274. else if (conf->pinType == 2) {
  275. u8g2_t* u8g2 = (u8g2_t*)conf->ptr;
  276. u8g2_Setup_ssd1306_i2c_128x64_noname_f( u8g2, U8G2_R0, luat_u8x8_byte_hw_i2c, luat_u8x8_gpio_and_delay);
  277. LLOGD("setup disp i2c.hw");
  278. u8g2_InitDisplay(u8g2);
  279. u8g2_SetPowerSave(u8g2, 0);
  280. return 0;
  281. }
  282. LLOGI("only i2c sw mode is support, by default impl");
  283. return -1;
  284. }
  285. LUAT_WEAK int luat_disp_close(luat_disp_conf_t *conf) {
  286. return 0;
  287. }
  288. LUAT_WEAK uint8_t luat_u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
  289. static uint8_t buffer[32]; /* u8g2/u8x8 will never send more than 32 bytes */
  290. static uint8_t buf_idx;
  291. uint8_t *data;
  292. switch(msg)
  293. {
  294. case U8X8_MSG_BYTE_SEND:
  295. data = (uint8_t *)arg_ptr;
  296. while( arg_int > 0 )
  297. {
  298. buffer[buf_idx++] = *data;
  299. data++;
  300. arg_int--;
  301. }
  302. break;
  303. case U8X8_MSG_BYTE_INIT:
  304. //i2c_init(u8x8); /* init i2c communication */
  305. break;
  306. case U8X8_MSG_BYTE_SET_DC:
  307. /* ignored for i2c */
  308. break;
  309. case U8X8_MSG_BYTE_START_TRANSFER:
  310. buf_idx = 0;
  311. break;
  312. case U8X8_MSG_BYTE_END_TRANSFER:
  313. luat_i2c_send(i2c_id, u8x8_GetI2CAddress(u8x8) >> 1, buffer, buf_idx);
  314. break;
  315. default:
  316. return 0;
  317. }
  318. return 1;
  319. }
  320. LUAT_WEAK uint8_t luat_u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  321. {
  322. switch(msg)
  323. {
  324. case U8X8_MSG_DELAY_NANO: // delay arg_int * 1 nano second
  325. __asm__ volatile("nop");
  326. break;
  327. case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds
  328. __asm__ volatile("nop");
  329. break;
  330. case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro seconds
  331. for (uint16_t n = 0; n < 320; n++)
  332. {
  333. __asm__ volatile("nop");
  334. }
  335. break;
  336. case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli second
  337. luat_timer_mdelay(arg_int);
  338. break;
  339. case U8X8_MSG_GPIO_AND_DELAY_INIT:
  340. // Function which implements a delay, arg_int contains the amount of ms
  341. // set spi pin mode
  342. if (u8x8->pins[U8X8_PIN_SPI_CLOCK] != 255) {
  343. luat_gpio_mode(u8x8->pins[U8X8_PIN_SPI_CLOCK],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);//d0 a5 15 d1 a7 17 res b0 18 dc b1 19 cs a4 14
  344. luat_gpio_mode(u8x8->pins[U8X8_PIN_SPI_DATA],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  345. luat_gpio_mode(u8x8->pins[U8X8_PIN_RESET],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  346. luat_gpio_mode(u8x8->pins[U8X8_PIN_DC],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  347. luat_gpio_mode(u8x8->pins[U8X8_PIN_CS],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  348. }
  349. // set i2c pin mode
  350. if (u8x8->pins[U8X8_PIN_I2C_DATA] != 255) {
  351. luat_gpio_mode(u8x8->pins[U8X8_PIN_I2C_DATA],Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
  352. luat_gpio_mode(u8x8->pins[U8X8_PIN_I2C_CLOCK],Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
  353. }
  354. // 反正还没支持,先注释掉吧
  355. // set 8080 pin mode
  356. // if (u8x8->pins[U8X8_PIN_D0] != 255) {
  357. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D0],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  358. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D1],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  359. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D2],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  360. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D3],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  361. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D4],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  362. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D5],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  363. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D6],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  364. // luat_gpio_mode(u8x8->pins[U8X8_PIN_D7],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  365. // luat_gpio_mode(u8x8->pins[U8X8_PIN_E],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  366. // luat_gpio_mode(u8x8->pins[U8X8_PIN_DC],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  367. // luat_gpio_mode(u8x8->pins[U8X8_PIN_RESET],Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  368. // }
  369. // set value
  370. //luat_gpio_set(u8x8->pins[U8X8_PIN_SPI_CLOCK],1);
  371. //luat_gpio_set(u8x8->pins[U8X8_PIN_SPI_DATA],1);
  372. //luat_gpio_set(u8x8->pins[U8X8_PIN_RESET],1);
  373. //luat_gpio_set(u8x8->pins[U8X8_PIN_DC],1);
  374. //luat_gpio_set(u8x8->pins[U8X8_PIN_CS],1);
  375. break;
  376. case U8X8_MSG_DELAY_I2C:
  377. // arg_int is the I2C speed in 100KHz, e.g. 4 = 400 KHz
  378. // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us
  379. for (uint16_t n = 0; n < (arg_int<=2?160:40); n++)
  380. {
  381. __asm__ volatile("nop");
  382. }
  383. break;
  384. //case U8X8_MSG_GPIO_D0: // D0 or SPI clock pin: Output level in arg_int
  385. //case U8X8_MSG_GPIO_SPI_CLOCK:
  386. //case U8X8_MSG_GPIO_D1: // D1 or SPI data pin: Output level in arg_int
  387. //case U8X8_MSG_GPIO_SPI_DATA:
  388. case U8X8_MSG_GPIO_D2: // D2 pin: Output level in arg_int
  389. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_D2],1);
  390. else luat_gpio_set(u8x8->pins[U8X8_PIN_D2],0);
  391. break;
  392. case U8X8_MSG_GPIO_D3: // D3 pin: Output level in arg_int
  393. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_D3],1);
  394. else luat_gpio_set(u8x8->pins[U8X8_PIN_D3],0);
  395. break;
  396. case U8X8_MSG_GPIO_D4: // D4 pin: Output level in arg_int
  397. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_D4],1);
  398. else luat_gpio_set(u8x8->pins[U8X8_PIN_D4],0);
  399. break;
  400. case U8X8_MSG_GPIO_D5: // D5 pin: Output level in arg_int
  401. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_D5],1);
  402. else luat_gpio_set(u8x8->pins[U8X8_PIN_D5],0);
  403. break;
  404. case U8X8_MSG_GPIO_D6: // D6 pin: Output level in arg_int
  405. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_D6],1);
  406. else luat_gpio_set(u8x8->pins[U8X8_PIN_D6],0);
  407. break;
  408. case U8X8_MSG_GPIO_D7: // D7 pin: Output level in arg_int
  409. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_D7],1);
  410. else luat_gpio_set(u8x8->pins[U8X8_PIN_D7],0);
  411. break;
  412. case U8X8_MSG_GPIO_E: // E/WR pin: Output level in arg_int
  413. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_E],1);
  414. else luat_gpio_set(u8x8->pins[U8X8_PIN_E],0);
  415. break;
  416. case U8X8_MSG_GPIO_I2C_CLOCK:
  417. // arg_int=0: Output low at I2C clock pin
  418. // arg_int=1: Input dir with pullup high for I2C clock pin
  419. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_I2C_CLOCK],1);
  420. else luat_gpio_set(u8x8->pins[U8X8_PIN_I2C_CLOCK],0);
  421. break;
  422. case U8X8_MSG_GPIO_I2C_DATA:
  423. // arg_int=0: Output low at I2C data pin
  424. // arg_int=1: Input dir with pullup high for I2C data pin
  425. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_I2C_DATA],1);
  426. else luat_gpio_set(u8x8->pins[U8X8_PIN_I2C_DATA],0);
  427. break;
  428. case U8X8_MSG_GPIO_SPI_CLOCK:
  429. //Function to define the logic level of the clockline
  430. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_SPI_CLOCK],1);
  431. else luat_gpio_set(u8x8->pins[U8X8_PIN_SPI_CLOCK],0);
  432. break;
  433. case U8X8_MSG_GPIO_SPI_DATA:
  434. //Function to define the logic level of the data line to the display
  435. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_SPI_DATA],1);
  436. else luat_gpio_set(u8x8->pins[U8X8_PIN_SPI_DATA],0);
  437. break;
  438. case U8X8_MSG_GPIO_CS:
  439. // Function to define the logic level of the CS line
  440. if(arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_CS],1);
  441. else luat_gpio_set(u8x8->pins[U8X8_PIN_CS],0);
  442. break;
  443. case U8X8_MSG_GPIO_DC:
  444. //Function to define the logic level of the Data/ Command line
  445. if(arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_DC],1);
  446. else luat_gpio_set(u8x8->pins[U8X8_PIN_DC],0);
  447. break;
  448. case U8X8_MSG_GPIO_RESET:
  449. //Function to define the logic level of the RESET line
  450. if (arg_int) luat_gpio_set(u8x8->pins[U8X8_PIN_RESET],1);
  451. else luat_gpio_set(u8x8->pins[U8X8_PIN_RESET],0);
  452. break;
  453. default:
  454. //A message was received which is not implemented, return 0 to indicate an error
  455. return 0;
  456. }
  457. return 1;
  458. }