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.

39 lines
982 B

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