luat_pin_air101.c 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "wm_gpio_afsel.h"
  2. #include "luat_base.h"
  3. #define LUAT_LOG_TAG "pin"
  4. #include "luat_log.h"
  5. static int get_pin_index(lua_State *L){
  6. char pin_sn[3]={0};
  7. int pin_n;
  8. const char* pin_name = luaL_checkstring(L, 1);
  9. if (memcmp("PA",pin_name, 2)==0){
  10. strncpy(pin_sn, pin_name+2, 2);
  11. pin_n = atoi(pin_sn);
  12. if (pin_n >= 0 && pin_n < 16){
  13. lua_pushinteger(L,pin_n);
  14. return 1;
  15. }else
  16. goto error;
  17. }else if(memcmp("PB",pin_name, 2)==0){
  18. strncpy(pin_sn, pin_name+2, 2);
  19. pin_n = atoi(pin_sn);
  20. if (pin_n >= 0 && pin_n < 16){
  21. lua_pushinteger(L,pin_n+16);
  22. return 1;
  23. }else
  24. goto error;
  25. }
  26. error:
  27. LLOGW("pin does not exist");
  28. return 0;
  29. }
  30. #include "rotable.h"
  31. static const rotable_Reg reg_pin[] =
  32. {
  33. {"__index", get_pin_index, 0},
  34. { NULL, NULL , 0}
  35. };
  36. LUAMOD_API int luaopen_pin( lua_State *L ) {
  37. luat_newlib(L, reg_pin);
  38. return 1;
  39. }