File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 77
88#if PBDRV_CONFIG_BUTTON_RESISTOR_LADDER
99
10+ #include <stddef.h>
11+
1012#include <pbdrv/resistor_ladder.h>
1113#include <pbio/button.h>
1214#include <pbio/error.h>
15+ #include <pbio/os.h>
16+
17+ #include "../core.h"
18+
19+ static pbio_os_process_t pbdrv_button_init_process ;
20+
21+ /**
22+ * Wait for the buttons to get ready before giving control to system code.
23+ *
24+ * The resistor ladders give unknown values for 10s of milliseconds after boot.
25+ *
26+ * This ensures that system level functions such as the UI don't need hacks to
27+ * wait for buttons to start working.
28+ */
29+ pbio_error_t pbdrv_button_init_process_thread (pbio_os_state_t * state , void * context ) {
30+
31+ static pbio_os_timer_t timer ;
32+ pbdrv_resistor_ladder_ch_flags_t flags ;
33+
34+ PBIO_OS_ASYNC_BEGIN (state );
35+
36+ while (pbdrv_resistor_ladder_get (0 , & flags ) != PBIO_SUCCESS || pbdrv_resistor_ladder_get (1 , & flags ) != PBIO_SUCCESS ) {
37+ PBIO_OS_AWAIT_MS (state , & timer , 10 );
38+ }
39+ PBIO_OS_AWAIT_MS (state , & timer , 30 );
40+
41+ pbdrv_init_busy_down ();
42+
43+ PBIO_OS_ASYNC_END (PBIO_SUCCESS );
44+ }
1345
1446void pbdrv_button_init (void ) {
47+ pbdrv_init_busy_up ();
48+ pbio_os_process_start (& pbdrv_button_init_process , pbdrv_button_init_process_thread , NULL );
1549}
1650
1751pbio_button_flags_t pbdrv_button_get_pressed (void ) {
You can’t perform that action at this time.
0 commit comments