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.

55 lines
1.8 KiB

  1. /*
  2. * Copyright 2018 Jack Humbert <jack.humb@gmail.com>
  3. * Copyright 2018 Drashna Jaelre (Christopher Courtney) <drashna@live.com>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include "gpio.h"
  22. #include "util.h"
  23. #if defined(DIP_SWITCH_PINS)
  24. # define NUM_DIP_SWITCHES ARRAY_SIZE(((pin_t[])DIP_SWITCH_PINS))
  25. #elif defined(DIP_SWITCH_MATRIX_GRID)
  26. typedef struct matrix_intersection_t {
  27. uint8_t row;
  28. uint8_t col;
  29. } matrix_intersection_t;
  30. # define NUM_DIP_SWITCHES ARRAY_SIZE(((matrix_intersection_t[])DIP_SWITCH_MATRIX_GRID))
  31. #endif
  32. #ifndef NUM_DIP_SWITCHES
  33. # define NUM_DIP_SWITCHES 0
  34. #endif
  35. bool dip_switch_update_kb(uint8_t index, bool active);
  36. bool dip_switch_update_user(uint8_t index, bool active);
  37. bool dip_switch_update_mask_user(uint32_t state);
  38. bool dip_switch_update_mask_kb(uint32_t state);
  39. void dip_switch_read(bool forced);
  40. void dip_switch_init(void);
  41. void dip_switch_task(void);
  42. #ifdef DIP_SWITCH_MAP_ENABLE
  43. # define NUM_DIP_STATES 2
  44. # define DIP_SWITCH_OFF_ON(off, on) \
  45. { (off), (on) }
  46. extern const uint16_t dip_switch_map[NUM_DIP_SWITCHES][NUM_DIP_STATES];
  47. #endif // DIP_SWITCH_MAP_ENABLE