mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-20 08:40:57 +03:00
Added semi-HW 1-wire realisation (alpha-version)
This commit is contained in:
@@ -69,17 +69,26 @@ void SysTick_init(){
|
||||
void check_btns(){
|
||||
static uint8_t oldstate[2] = {1,1}; // old buttons state
|
||||
uint8_t newstate[2], i;
|
||||
static uint32_t Old_timer[2] = {0,0};
|
||||
newstate[0] = gpio_get(BTNS_PORT, BTN_S2_PIN) ? 1 : 0;
|
||||
newstate[1] = gpio_get(BTNS_PORT, BTN_S3_PIN) ? 1 : 0;
|
||||
for(i = 0; i < 2; i++){
|
||||
uint8_t new = newstate[i];
|
||||
if(new != oldstate[i]){
|
||||
P("Button S");
|
||||
usb_send('2' + i);
|
||||
if(new) P("pressed");
|
||||
else P("released");
|
||||
newline();
|
||||
oldstate[i] = new;
|
||||
// pause for 60ms
|
||||
uint32_t O = Old_timer[i];
|
||||
if(!O){
|
||||
if(Timer - O > 60 || O > Timer){
|
||||
P("Button S");
|
||||
usb_send('2' + i);
|
||||
if(new) P("released");
|
||||
else P("pressed");
|
||||
newline();
|
||||
oldstate[i] = new;
|
||||
Old_timer[i] = 0;
|
||||
}
|
||||
}
|
||||
else if(new != oldstate[i]){
|
||||
Old_timer[i] = Timer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user