gpio.c 684 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "gpio.h"
  4. #include "rtdbg.h"
  5. #if 1
  6. #define LOGD LOG_D
  7. #define LOGE LOG_E
  8. #else
  9. #define LOGD printf
  10. #define LOGE printf
  11. #endif
  12. int gpio_init(int gpio, int io, int hl)
  13. {
  14. if(io==GPIO_IN) {
  15. rt_pin_mode(gpio, PIN_MODE_OUTPUT);
  16. }
  17. else {
  18. rt_pin_mode(gpio, PIN_MODE_OUTPUT);
  19. rt_pin_write(gpio, (hl>0)?PIN_HIGH:PIN_LOW);
  20. }
  21. return 0;
  22. }
  23. int gpio_deinit(int fd)
  24. {
  25. return 0;
  26. }
  27. int gpio_set(int gpio, int hl)
  28. {
  29. rt_pin_write(gpio, (hl>0)?PIN_HIGH:PIN_LOW);
  30. return 0;
  31. }
  32. int gpio_get(int gpio)
  33. {
  34. rt_ssize_t r = rt_pin_read(gpio);
  35. return (r==PIN_HIGH)?1:0;
  36. }