diff options
Diffstat (limited to 'quantum/dip_switch.c')
| -rw-r--r-- | quantum/dip_switch.c | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index 3b5a8dadc..ab74222d1 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c | |||
| @@ -21,40 +21,33 @@ | |||
| 21 | // for memcpy | 21 | // for memcpy |
| 22 | #include <string.h> | 22 | #include <string.h> |
| 23 | 23 | ||
| 24 | |||
| 25 | #if !defined(DIP_SWITCH_PINS) | 24 | #if !defined(DIP_SWITCH_PINS) |
| 26 | # error "No DIP switch pads defined by DIP_SWITCH_PINS" | 25 | # error "No DIP switch pads defined by DIP_SWITCH_PINS" |
| 27 | #endif | 26 | #endif |
| 28 | 27 | ||
| 29 | #define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad)/sizeof(pin_t)) | 28 | #define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) |
| 30 | static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; | 29 | static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; |
| 31 | static bool dip_switch_state[NUMBER_OF_DIP_SWITCHES] = { 0 }; | 30 | static bool dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0}; |
| 32 | static bool last_dip_switch_state[NUMBER_OF_DIP_SWITCHES] = { 0 }; | 31 | static bool last_dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0}; |
| 33 | |||
| 34 | 32 | ||
| 35 | __attribute__((weak)) | 33 | __attribute__((weak)) void dip_switch_update_user(uint8_t index, bool active) {} |
| 36 | void dip_switch_update_user(uint8_t index, bool active) {} | ||
| 37 | 34 | ||
| 38 | __attribute__((weak)) | 35 | __attribute__((weak)) void dip_switch_update_kb(uint8_t index, bool active) { dip_switch_update_user(index, active); } |
| 39 | void dip_switch_update_kb(uint8_t index, bool active) { dip_switch_update_user(index, active); } | ||
| 40 | 36 | ||
| 41 | __attribute__((weak)) | 37 | __attribute__((weak)) void dip_switch_update_mask_user(uint32_t state) {} |
| 42 | void dip_switch_update_mask_user(uint32_t state) {} | ||
| 43 | 38 | ||
| 44 | __attribute__((weak)) | 39 | __attribute__((weak)) void dip_switch_update_mask_kb(uint32_t state) { dip_switch_update_mask_user(state); } |
| 45 | void dip_switch_update_mask_kb(uint32_t state) { dip_switch_update_mask_user(state); } | ||
| 46 | 40 | ||
| 47 | void dip_switch_init(void) { | 41 | void dip_switch_init(void) { |
| 48 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { | 42 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { |
| 49 | setPinInputHigh(dip_switch_pad[i]); | 43 | setPinInputHigh(dip_switch_pad[i]); |
| 50 | } | 44 | } |
| 51 | dip_switch_read(true); | 45 | dip_switch_read(true); |
| 52 | } | 46 | } |
| 53 | 47 | ||
| 54 | |||
| 55 | void dip_switch_read(bool forced) { | 48 | void dip_switch_read(bool forced) { |
| 56 | bool has_dip_state_changed = false; | 49 | bool has_dip_state_changed = false; |
| 57 | uint32_t dip_switch_mask = 0; | 50 | uint32_t dip_switch_mask = 0; |
| 58 | 51 | ||
| 59 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { | 52 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { |
| 60 | dip_switch_state[i] = !readPin(dip_switch_pad[i]); | 53 | dip_switch_state[i] = !readPin(dip_switch_pad[i]); |
