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.

41 lines
992 B

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