aboutsummaryrefslogtreecommitdiff
path: root/quantum/dip_switch.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/dip_switch.c')
-rw-r--r--quantum/dip_switch.c37
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))
30static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; 29static pin_t dip_switch_pad[] = DIP_SWITCH_PINS;
31static bool dip_switch_state[NUMBER_OF_DIP_SWITCHES] = { 0 }; 30static bool dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0};
32static bool last_dip_switch_state[NUMBER_OF_DIP_SWITCHES] = { 0 }; 31static 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) {}
36void 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); }
39void 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) {}
42void 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); }
45void dip_switch_update_mask_kb(uint32_t state) { dip_switch_update_mask_user(state); }
46 40
47void dip_switch_init(void) { 41void 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
55void dip_switch_read(bool forced) { 48void 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]);