api-hal-gpio.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "api-hal-gpio.h"
  2. #include <stdio.h>
  3. // init GPIO
  4. void hal_gpio_init(
  5. const GpioPin* gpio,
  6. const GpioMode mode,
  7. const GpioPull pull,
  8. const GpioSpeed speed) {
  9. // TODO more mode
  10. if(gpio->pin != 0) {
  11. switch(mode) {
  12. case GpioModeInput:
  13. printf("[GPIO] %s%d input\n", gpio->port, gpio->pin);
  14. break;
  15. case GpioModeOutputPushPull:
  16. printf("[GPIO] %s%d push pull\n", gpio->port, gpio->pin);
  17. break;
  18. case GpioModeOutputOpenDrain:
  19. printf("[GPIO] %s%d open drain\n", gpio->port, gpio->pin);
  20. break;
  21. default:
  22. printf("[GPIO] %s%d mode %d unsupported\n", gpio->port, gpio->pin, mode);
  23. break;
  24. }
  25. } else {
  26. printf("[GPIO] no pin\n");
  27. }
  28. }
  29. // write value to GPIO, false = LOW, true = HIGH
  30. void hal_gpio_write(const GpioPin* gpio, const bool state) {
  31. if(gpio->pin != 0) {
  32. if(state) {
  33. printf("[GPIO] %s%d on\n", gpio->port, gpio->pin);
  34. } else {
  35. printf("[GPIO] %s%d off\n", gpio->port, gpio->pin);
  36. }
  37. } else {
  38. printf("[GPIO] no pin\n");
  39. }
  40. }
  41. // read value from GPIO, false = LOW, true = HIGH
  42. bool hal_gpio_read(const GpioPin* gpio) {
  43. // TODO emulate pin state?
  44. return false;
  45. }