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.
|
// 0 otherwise.
|
||||||
bool device_is_nfc();
|
bool device_is_nfc();
|
||||||
|
|
||||||
|
void device_init_button();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,6 +105,7 @@ void device_set_status(uint32_t status)
|
|||||||
|
|
||||||
int device_is_button_pressed()
|
int device_is_button_pressed()
|
||||||
{
|
{
|
||||||
|
|
||||||
return IS_BUTTON_PRESSED();
|
return IS_BUTTON_PRESSED();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,25 +120,17 @@ void device_reboot()
|
|||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void device_init_button()
|
||||||
|
|
||||||
static int does_device_have_touch_sensor()
|
|
||||||
{
|
{
|
||||||
int does;
|
if (tsc_sensor_exists())
|
||||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
{
|
||||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
tsc_init();
|
||||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
IS_BUTTON_PRESSED = is_touch_button_pressed;
|
||||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
}
|
||||||
GPIO_InitStruct.OutputType = 0;
|
else
|
||||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
{
|
||||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
IS_BUTTON_PRESSED = is_physical_button_pressed;
|
||||||
|
}
|
||||||
does = (LL_GPIO_ReadInputPort(GPIOB) & 1) == 0;
|
|
||||||
|
|
||||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
||||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
return does;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_init(int argc, char *argv[])
|
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");
|
printf1(TAG_NFC, "Have NO NFC\r\n");
|
||||||
hw_init(HIGH_FREQUENCY);
|
hw_init(HIGH_FREQUENCY);
|
||||||
isLowFreq = 0;
|
isLowFreq = 0;
|
||||||
|
device_init_button();
|
||||||
if (does_device_have_touch_sensor())
|
|
||||||
{
|
|
||||||
tsc_init();
|
|
||||||
IS_BUTTON_PRESSED = is_touch_button_pressed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IS_BUTTON_PRESSED = is_physical_button_pressed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usbhid_init();
|
usbhid_init();
|
||||||
|
@ -127,28 +127,21 @@ uint32_t tsc_read_button(uint32_t index)
|
|||||||
return tsc_read(1) < 50;
|
return tsc_read(1) < 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sense_run()
|
int tsc_sensor_exists()
|
||||||
{
|
{
|
||||||
static uint32_t tlim = 0;
|
int does;
|
||||||
uint32_t t1,t2;
|
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
uint32_t but0,but1;
|
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)
|
does = (LL_GPIO_ReadInputPort(GPIOB) & 1) == 0;
|
||||||
{
|
|
||||||
tsc_init();
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||||
_has_init = 1;
|
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
}
|
|
||||||
|
return does;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,8 @@ extern int _run_sense_app;
|
|||||||
|
|
||||||
void tsc_init();
|
void tsc_init();
|
||||||
|
|
||||||
|
int tsc_sensor_exists();
|
||||||
|
|
||||||
uint32_t tsc_read_button(uint32_t index);
|
uint32_t tsc_read_button(uint32_t index);
|
||||||
|
|
||||||
// For testing
|
|
||||||
void sense_run();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user