Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/pbio/drv/button/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
*/
void pbdrv_button_init(void);

/**
* De-initializes the low level button driver.
*/
void pbdrv_button_deinit(void);

#else

#define pbdrv_button_init()
#define pbdrv_button_deinit()

#endif

Expand Down
19 changes: 16 additions & 3 deletions lib/pbio/drv/button/button_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <pbdrv/gpio.h>
#include <pbio/button.h>
#include <pbio/busy_count.h>
#include <pbio/config.h>
#include <pbio/error.h>
#include <pbio/os.h>
Expand Down Expand Up @@ -49,7 +50,9 @@ pbio_error_t pbdrv_button_process_thread(pbio_os_state_t *state, void *context)

pbio_os_timer_set(&timer, 10);

for (;;) {
// Loop until cancellation is requested on power off and buttons are released.
while (!pbdrv_button_process.request || pbdrv_button_state) {

PBIO_OS_AWAIT_UNTIL(state, pbio_os_timer_is_expired(&timer));

next = pbdrv_button_gpio_read();
Expand All @@ -64,8 +67,11 @@ pbio_error_t pbdrv_button_process_thread(pbio_os_state_t *state, void *context)
pbio_os_timer_extend(&timer);
}

// Unreachable
PBIO_OS_ASYNC_END(PBIO_ERROR_FAILED);
// Wait a while after release to prevent accidental power on.
PBIO_OS_AWAIT_MS(state, &timer, 200);
pbio_busy_count_down();

PBIO_OS_ASYNC_END(PBIO_ERROR_CANCELED);
}

#endif // PBDRV_CONFIG_BUTTON_GPIO_DEBOUNCE
Expand All @@ -90,4 +96,11 @@ void pbdrv_button_init(void) {
#endif
}

void pbdrv_button_deinit(void) {
#if PBDRV_CONFIG_BUTTON_GPIO_DEBOUNCE
pbio_busy_count_up();
pbio_os_process_make_request(&pbdrv_button_process, PBIO_OS_PROCESS_REQUEST_TYPE_CANCEL);
#endif
}

#endif // PBDRV_CONFIG_BUTTON_GPIO
3 changes: 3 additions & 0 deletions lib/pbio/drv/button/button_nxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
void pbdrv_button_init(void) {
}

void pbdrv_button_deinit(void) {
}

pbio_button_flags_t pbdrv_button_get_pressed(void) {

nx_avr_button_t button = nx_avr_get_button();
Expand Down
3 changes: 3 additions & 0 deletions lib/pbio/drv/button/button_resistor_ladder.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void pbdrv_button_init(void) {
pbio_os_process_start(&pbdrv_button_init_process, pbdrv_button_init_process_thread, NULL);
}

void pbdrv_button_deinit(void) {
}

pbio_button_flags_t pbdrv_button_get_pressed(void) {
pbdrv_resistor_ladder_ch_flags_t flags;
pbio_error_t err;
Expand Down
3 changes: 3 additions & 0 deletions lib/pbio/drv/button/button_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ void pbio_test_button_set_pressed(pbio_button_flags_t flags) {
void pbdrv_button_init(void) {
}

void pbdrv_button_deinit(void) {
}

pbio_button_flags_t pbdrv_button_get_pressed(void) {
return pbio_test_button_flags;
}
Expand Down
1 change: 1 addition & 0 deletions lib/pbio/drv/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void pbdrv_deinit(void) {

pbdrv_imu_deinit();
pbdrv_bluetooth_deinit();
pbdrv_button_deinit();

while (pbio_busy_count_busy()) {
pbio_os_run_processes_and_wait_for_event();
Expand Down