refactor
This commit is contained in:
parent
aff8d10432
commit
60e3d01e0d
@ -103,5 +103,6 @@ void device_set_clock_rate(DEVICE_CLOCK_RATE param);
|
||||
// 0 otherwise.
|
||||
bool device_is_nfc();
|
||||
|
||||
void device_init_button();
|
||||
|
||||
#endif
|
||||
|
@ -105,6 +105,7 @@ void device_set_status(uint32_t status)
|
||||
|
||||
int device_is_button_pressed()
|
||||
{
|
||||
|
||||
return IS_BUTTON_PRESSED();
|
||||
}
|
||||
|
||||
@ -119,25 +120,17 @@ void device_reboot()
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int does_device_have_touch_sensor()
|
||||
void device_init_button()
|
||||
{
|
||||
int does;
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = 0;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
does = (LL_GPIO_ReadInputPort(GPIOB) & 1) == 0;
|
||||
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
return does;
|
||||
if (tsc_sensor_exists())
|
||||
{
|
||||
tsc_init();
|
||||
IS_BUTTON_PRESSED = is_touch_button_pressed;
|
||||
}
|
||||
else
|
||||
{
|
||||
IS_BUTTON_PRESSED = is_physical_button_pressed;
|
||||
}
|
||||
}
|
||||
|
||||
void device_init(int argc, char *argv[])
|
||||
@ -156,16 +149,7 @@ void device_init(int argc, char *argv[])
|
||||
printf1(TAG_NFC, "Have NO NFC\r\n");
|
||||
hw_init(HIGH_FREQUENCY);
|
||||
isLowFreq = 0;
|
||||
|
||||
if (does_device_have_touch_sensor())
|
||||
{
|
||||
tsc_init();
|
||||
IS_BUTTON_PRESSED = is_touch_button_pressed;
|
||||
}
|
||||
else
|
||||
{
|
||||
IS_BUTTON_PRESSED = is_physical_button_pressed;
|
||||
}
|
||||
device_init_button();
|
||||
}
|
||||
|
||||
usbhid_init();
|
||||
|
@ -127,28 +127,21 @@ uint32_t tsc_read_button(uint32_t index)
|
||||
return tsc_read(1) < 50;
|
||||
}
|
||||
|
||||
void sense_run()
|
||||
int tsc_sensor_exists()
|
||||
{
|
||||
static uint32_t tlim = 0;
|
||||
uint32_t t1,t2;
|
||||
uint32_t but0,but1;
|
||||
int does;
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = 0;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
if (!_has_init)
|
||||
{
|
||||
tsc_init();
|
||||
_has_init = 1;
|
||||
}
|
||||
|
||||
if ((millis() - tlim) > 200)
|
||||
{
|
||||
t1 = millis();
|
||||
but0 = tsc_read_button(0);
|
||||
but1 = tsc_read_button(1);
|
||||
t2 = millis();
|
||||
|
||||
printf1(TAG_GREEN, "but0: %02d but1: %02d (%d ms)\r\n", but0, but1, t2-t1);
|
||||
t1 = millis();
|
||||
|
||||
tlim = millis();
|
||||
}
|
||||
does = (LL_GPIO_ReadInputPort(GPIOB) & 1) == 0;
|
||||
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
return does;
|
||||
}
|
||||
|
@ -7,9 +7,8 @@ extern int _run_sense_app;
|
||||
|
||||
void tsc_init();
|
||||
|
||||
int tsc_sensor_exists();
|
||||
|
||||
uint32_t tsc_read_button(uint32_t index);
|
||||
|
||||
// For testing
|
||||
void sense_run();
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user