Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
904 B

  1. /*
  2. GPIO MODULE
  3. Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. bool _gpio_locked[16] = {false};
  6. bool gpioValid(unsigned char gpio) {
  7. if (0 <= gpio && gpio <= 5) return true;
  8. if (12 <= gpio && gpio <= 15) return true;
  9. return false;
  10. }
  11. bool gpioGetLock(unsigned char gpio) {
  12. if (gpioValid(gpio)) {
  13. if (!_gpio_locked[gpio]) {
  14. _gpio_locked[gpio] = true;
  15. DEBUG_MSG_P(PSTR("[GPIO] GPIO%d locked\n"), gpio);
  16. return true;
  17. }
  18. }
  19. DEBUG_MSG_P(PSTR("[GPIO] Failed getting lock for GPIO%d\n"), gpio);
  20. return false;
  21. }
  22. bool gpioReleaseLock(unsigned char gpio) {
  23. if (gpioValid(gpio)) {
  24. _gpio_locked[gpio] = false;
  25. DEBUG_MSG_P(PSTR("[GPIO] GPIO%d lock released\n"), gpio);
  26. return true;
  27. }
  28. DEBUG_MSG_P(PSTR("[GPIO] Failed releasing lock for GPIO%d\n"), gpio);
  29. return false;
  30. }