Subversion Repositories DashDisplay

Rev

Rev 4 | Rev 6 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 8... Line 8...
8
} eGreyCode;
8
} eGreyCode;
9
 
9
 
10
typedef struct {
10
typedef struct {
11
GPIO_TypeDef * GPIO;
11
GPIO_TypeDef * GPIO;
12
uint16_t Pin;
12
uint16_t Pin;
-
 
13
uint16_t Debounce;
13
} sGPIOPin;
14
} sGPIOPin;
14
 
15
 
15
volatile int dial_pos[MAX_DIALS];
16
volatile int dial_pos[MAX_DIALS];
16
volatile int dial_last[MAX_DIALS]; // previous debounced switch position
17
volatile int dial_last[MAX_DIALS]; // previous debounced switch position
17
 
18
 
Line 19... Line 20...
19
 
20
 
20
volatile static int sw_newstate[MAX_SWITCHES]; //< debounced switch state
21
volatile static int sw_newstate[MAX_SWITCHES]; //< debounced switch state
21
volatile static int sw_count[MAX_SWITCHES]; //< debounce counter
22
volatile static int sw_count[MAX_SWITCHES]; //< debounce counter
22
 
23
 
23
static const sGPIOPin sw_arr[MAX_SWITCHES] =
24
static const sGPIOPin sw_arr[MAX_SWITCHES] =
24
        { { SW1_I_GPIO_Port, SW1_I_Pin }, // these two pins used to encode SW1 phase
25
        { { SW1_I_GPIO_Port, SW1_I_Pin , 5}, // these two pins used to encode SW1 phase
25
                        { SW1_Q_GPIO_Port, SW1_Q_Pin }, // "                             SW1 phase
26
                        { SW1_Q_GPIO_Port, SW1_Q_Pin, 5 }, // "                             SW1 phase
26
                        { SW2_I_GPIO_Port, SW2_I_Pin }, // these two pins used to encode SW2 phase
27
                        { SW2_I_GPIO_Port, SW2_I_Pin , 5}, // these two pins used to encode SW2 phase
27
                        { SW2_Q_GPIO_Port, SW2_Q_Pin }, // "                             SW2 phase
28
                        { SW2_Q_GPIO_Port, SW2_Q_Pin , 5}, // "                             SW2 phase
28
                        { SW1_PUSH_GPIO_Port, SW1_PUSH_Pin }, // two debounced switches
29
                        { SW1_PUSH_GPIO_Port, SW1_PUSH_Pin, 10 }, // two debounced switches
29
{ SW2_PUSH_GPIO_Port, SW2_PUSH_Pin }, };
30
{ SW2_PUSH_GPIO_Port, SW2_PUSH_Pin, 10 }, };
30
 
31
 
31
// call this to setup switch states
32
// call this to setup switch states
32
void InitSwitches(void) {
33
void InitSwitches(void) {
33
int i;
34
int i;
34
 
35
 
Line 99... Line 100...
99
          sw_count[i] = 0;
100
          sw_count[i] = 0;
100
    }
101
    }
101
    else
102
    else
102
    {
103
    {
103
        // count up to debounce time
104
        // count up to debounce time
104
          if (sw_count[i] < DEBOUNCE_TIME)
105
          if (sw_count[i] < sw_arr[i].Debounce)
105
          {
106
          {
106
                sw_count[i]++;
107
                sw_count[i]++;
107
 
108
 
108
                if (sw_count[i] == DEBOUNCE_TIME)
109
                if (sw_count[i] == sw_arr[i].Debounce)
109
                {
110
                {
110
                        sw_newstate[i] = sw;
111
                        sw_newstate[i] = sw;
111
                }
112
                }
112
         }
113
         }
113
    }
114
    }