luat_gpio_legacy.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef LUAT_GPIO_LEGACY_H
  2. #define LUAT_GPIO_LEGACY_H
  3. #include "luat_base.h"
  4. #ifdef __LUATOS__
  5. #include "luat_msgbus.h"
  6. int l_gpio_handler(lua_State *L, void* ptr);
  7. #endif
  8. typedef int (*luat_gpio_irq_cb)(int pin, void* args);
  9. #define Luat_GPIO_LOW 0x00
  10. #define Luat_GPIO_HIGH 0x01
  11. #define Luat_GPIO_OUTPUT 0x00
  12. #define Luat_GPIO_INPUT 0x01
  13. #define Luat_GPIO_IRQ 0x02
  14. #define Luat_GPIO_DEFAULT 0x00
  15. #define Luat_GPIO_PULLUP 0x01
  16. #define Luat_GPIO_PULLDOWN 0x02
  17. #define Luat_GPIO_RISING 0x00
  18. #define Luat_GPIO_FALLING 0x01
  19. #define Luat_GPIO_BOTH 0x02
  20. #define Luat_GPIO_HIGH_IRQ 0x03 //高电平中断
  21. #define Luat_GPIO_LOW_IRQ 0x04 //低电平中断
  22. #define Luat_GPIO_MAX_ID 255
  23. typedef struct luat_gpio
  24. {
  25. int pin;/**<引脚*/
  26. int mode;/**<GPIO模式*/
  27. int pull;/**<GPIO上下拉模式*/
  28. int irq;/**<GPIO中断模式*/
  29. int lua_ref;
  30. luat_gpio_irq_cb irq_cb;/**<中断处理函数*/
  31. void* irq_args;
  32. int alt_func;
  33. } luat_gpio_t;
  34. int luat_gpio_setup(luat_gpio_t* gpio);
  35. void luat_gpio_mode(int pin, int mode, int pull, int initOutput);
  36. int luat_gpio_irq_default(int pin, void* args);
  37. #endif