gpio.c 561 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "gpio.h"
  4. #include "log.h"
  5. int gpio_init(int gpio, int io, int hl)
  6. {
  7. if(io==GPIO_IN) {
  8. rt_pin_mode(gpio, PIN_MODE_INPUT);
  9. }
  10. else {
  11. rt_pin_mode(gpio, PIN_MODE_OUTPUT);
  12. rt_pin_write(gpio, (hl>0)?PIN_HIGH:PIN_LOW);
  13. }
  14. return 0;
  15. }
  16. int gpio_deinit(int fd)
  17. {
  18. return 0;
  19. }
  20. int gpio_set(int gpio, int hl)
  21. {
  22. rt_pin_write(gpio, (hl>0)?PIN_HIGH:PIN_LOW);
  23. return 0;
  24. }
  25. int gpio_get(int gpio)
  26. {
  27. rt_ssize_t r = rt_pin_read(gpio);
  28. return (r==PIN_HIGH)?1:0;
  29. }