Skip to content

Commit

Permalink
Added debunce for i2c switches
Browse files Browse the repository at this point in the history
  • Loading branch information
g0orx committed Jan 24, 2022
1 parent b610373 commit 6f7c1ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ ENCODER encoders_controller2_v1[MAX_ENCODERS]={
};

ENCODER encoders_controller2_v2[MAX_ENCODERS]={
{TRUE,TRUE,5,1,6,1,0,RF_GAIN,R_START,TRUE,TRUE,26,1,20,1,0,AF_GAIN,R_START,TRUE,TRUE,22,MENU_BAND,0L},
{TRUE,TRUE,5,1,6,1,0,DRIVE,R_START,TRUE,TRUE,26,1,20,1,0,AF_GAIN,R_START,TRUE,TRUE,22,MENU_BAND,0L},
{TRUE,TRUE,9,1,7,1,0,ATTENUATION,R_START,TRUE,TRUE,21,1,4,1,0,AGC_GAIN,R_START,TRUE,TRUE,27,MENU_MODE,0L},
{TRUE,TRUE,11,1,10,1,0,IF_WIDTH,R_START,TRUE,TRUE,19,1,16,1,0,IF_SHIFT,R_START,TRUE,TRUE,23,MENU_FILTER,0L},
{TRUE,TRUE,13,1,12,1,0,XIT,R_START,TRUE,TRUE,8,1,25,1,0,RIT,R_START,TRUE,TRUE,24,MENU_FREQUENCY,0L},
Expand Down
26 changes: 26 additions & 0 deletions i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,38 @@ static void frequencyStep(int pos) {
vfo_step(pos);
}

static uint64_t epochMilli;

static void initialiseEpoch() {
struct timespec ts ;

clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ;
epochMilli = (uint64_t)ts.tv_sec * (uint64_t)1000 + (uint64_t)(ts.tv_nsec / 1000000L) ;
}

static uint32_t millis () {
uint64_t now ;
struct timespec ts ;
clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ;
now = (uint64_t)ts.tv_sec * (uint64_t)1000 + (uint64_t)(ts.tv_nsec / 1000000L) ;
return (uint32_t)(now - epochMilli) ;
}

static uint32_t debounce_time=50; // 50ms
static uint32_t t;
static uint32_t debounce=0;

void i2c_interrupt() {
unsigned int flags;
unsigned int ints;

t=millis();
do {
flags=read_word_data(0x0E);
if(flags) {
ints=read_word_data(0x10);
g_print("%s: flags=%04X ints=%04X\n",__FUNCTION__,flags,ints);
if(t<debounce) return;
if(ints) {
int i;
for(i=0;i<16;i++) {
Expand All @@ -101,6 +124,7 @@ g_print("%s: switches=%p sw=%d action=%d\n",__FUNCTION__,switches,i,switches[i].
}
}
} while(flags!=0);
debounce=t+debounce_time;
}

void i2c_init() {
Expand Down Expand Up @@ -169,6 +193,8 @@ void i2c_init() {
}
}
} while(flags!=0);

initialiseEpoch();

}
#endif

0 comments on commit 6f7c1ab

Please sign in to comment.