From ce69dec56ffa2d79f34dd58377c041e8645a78b9 Mon Sep 17 00:00:00 2001 From: Andrey Perminov Date: Thu, 23 Apr 2020 09:24:37 -0700 Subject: [PATCH] Moved LEDs control completely to HAL Change-Id: Ie420cd40d969d1776804dd837caf970c1b4e4c0b --- BMLite_example/inc/bmlite_hal.h | 3 +- BMLite_example/inc/platform.h | 16 ++------- BMLite_example/src/main.c | 47 +++++++------------------ BMLite_example/src/platform.c | 4 --- HAL_Driver/src/hal_leds.c | 62 ++++++++++++++++++++++++++++++++- HAL_Driver/src/hal_spi.c | 2 -- 6 files changed, 78 insertions(+), 56 deletions(-) diff --git a/BMLite_example/inc/bmlite_hal.h b/BMLite_example/inc/bmlite_hal.h index 990a8d8..a280d00 100755 --- a/BMLite_example/inc/bmlite_hal.h +++ b/BMLite_example/inc/bmlite_hal.h @@ -82,8 +82,9 @@ uint32_t hal_get_button_press_time(); /* * @brief Set LED(s) status * @param[in] Status + * @param[in] Status modifier */ -void hal_set_leds(uint8_t status); +void hal_set_leds(platform_led_status_t status, uint16_t mode); #endif /* BMLITE_H */ diff --git a/BMLite_example/inc/platform.h b/BMLite_example/inc/platform.h index 83bfbb7..89ca9f4 100644 --- a/BMLite_example/inc/platform.h +++ b/BMLite_example/inc/platform.h @@ -27,7 +27,6 @@ #include #include "fpc_com_result.h" -#include "bmlite_hal.h" /** * @brief LED status. @@ -37,11 +36,10 @@ typedef enum { BMLITE_LED_STATUS_READY = 0, BMLITE_LED_STATUS_MATCH, - BMLITE_LED_STATUS_NOMATCH, BMLITE_LED_STATUS_WAITTOUCH, - BMLITE_LED_STATUS_STARTENROLL, - BMLITE_LED_STATUS_FINISHENROLL, - BMLITE_LED_STATUS_DELETE_TEMPLATES + BMLITE_LED_STATUS_ENROLL, + BMLITE_LED_STATUS_DELETE_TEMPLATES, + BMLITE_LED_STATUS_ERROR, } platform_led_status_t; /** @@ -91,14 +89,6 @@ void platform_halt_if_debug(void); */ void platform_sw_reset(void) __attribute__((__noreturn__)); -/** - * @brief Set LED to a given color and display status. - * - * @param[in] color Color of RGB LED. - * @param[in] status Status of LED. - */ -void platform_set_led(platform_led_status_t color); - /** * @brief Get button press time. * diff --git a/BMLite_example/src/main.c b/BMLite_example/src/main.c index 327bf95..a3fa340 100644 --- a/BMLite_example/src/main.c +++ b/BMLite_example/src/main.c @@ -30,22 +30,15 @@ #include "bep_host_if.h" #include "com_common.h" #include "platform.h" +#include "bmlite_hal.h" void bmlite_on_error(bmlite_error_t error, int32_t value) { if(value != FPC_BEP_RESULT_TIMEOUT) { - platform_set_led(3); - hal_timebase_busy_wait(500); - platform_set_led(0); - hal_timebase_busy_wait(500); - platform_set_led(3); - hal_timebase_busy_wait(500); - platform_set_led(0); - hal_timebase_busy_wait(500); + hal_set_leds(BMLITE_LED_STATUS_ERROR, false); } else { - platform_set_led(3); - hal_timebase_busy_wait(100); - platform_set_led(0); + // Timeout - not really an error here + hal_set_leds(BMLITE_LED_STATUS_ERROR, true); } } @@ -54,36 +47,27 @@ void bmlite_on_error(bmlite_error_t error, int32_t value) void bmlite_on_start_enroll() { - platform_set_led(1); - hal_timebase_busy_wait(500); - platform_set_led(2); - hal_timebase_busy_wait(500); + hal_set_leds(BMLITE_LED_STATUS_ENROLL, true); } void bmlite_on_finish_enroll() { - platform_set_led(1); - hal_timebase_busy_wait(100); - platform_set_led(0); - hal_timebase_busy_wait(100); - platform_set_led(1); - hal_timebase_busy_wait(100); - platform_set_led(0); + hal_set_leds(BMLITE_LED_STATUS_ENROLL, false); } void bmlite_on_start_enrollcapture() { - platform_set_led(3); + hal_set_leds(BMLITE_LED_STATUS_WAITTOUCH, true); } void bmlite_on_finish_enrollcapture() { - platform_set_led(0); + hal_set_leds(BMLITE_LED_STATUS_READY, false); } void bmlite_on_identify_start() { - platform_set_led(0); + hal_set_leds(BMLITE_LED_STATUS_READY, true); } // void bmlite_on_identify_finish(); @@ -111,11 +95,10 @@ int main (int argc, char **argv) memset(version, 0, 100); fpc_bep_result_t res = bep_version(&hcp_chain, version, 99); - platform_set_led(BMLITE_LED_STATUS_READY); - while (1) { uint32_t btn_time = platform_get_button_press_time(); + hal_set_leds(BMLITE_LED_STATUS_READY,0); if (btn_time < 200) { // nothing hapened } else if (btn_time < 5000) { @@ -124,19 +107,13 @@ int main (int argc, char **argv) res = bep_save_template(&hcp_chain, current_id++); } else { // Erase All templates - platform_set_led(BMLITE_LED_STATUS_DELETE_TEMPLATES); - hal_timebase_busy_wait(500); + hal_set_leds(BMLITE_LED_STATUS_DELETE_TEMPLATES, true); res = bep_delete_template(&hcp_chain, REMOVE_ID_ALL_TEMPLATES); } res = bep_identify_finger(&hcp_chain, &template_id, &match); if (res != FPC_BEP_RESULT_OK) continue; - if (match) { - platform_set_led(BMLITE_LED_STATUS_MATCH); - } else { - platform_set_led(BMLITE_LED_STATUS_NOMATCH); - } - hal_timebase_busy_wait(500); + hal_set_leds(BMLITE_LED_STATUS_MATCH, match); } } } diff --git a/BMLite_example/src/platform.c b/BMLite_example/src/platform.c index 04112fd..2f50243 100644 --- a/BMLite_example/src/platform.c +++ b/BMLite_example/src/platform.c @@ -65,7 +65,3 @@ fpc_com_result_t platform_bmlite_receive(uint16_t size, uint8_t *data, uint32_t return hal_bmlite_spi_write_read(buff, data, size, false); } -void platform_set_led(platform_led_status_t color) -{ - hal_set_leds(color); -} diff --git a/HAL_Driver/src/hal_leds.c b/HAL_Driver/src/hal_leds.c index 541488c..4cbefd1 100644 --- a/HAL_Driver/src/hal_leds.c +++ b/HAL_Driver/src/hal_leds.c @@ -28,7 +28,7 @@ /** LED blink time in ms */ #define LED_BLINK_TIME_MS 200 -void hal_set_leds(uint8_t color) +static void set_leds(uint8_t color) { uint32_t i; @@ -41,3 +41,63 @@ void hal_set_leds(uint8_t color) color = color >> 1; } } + +void hal_set_leds(platform_led_status_t status, uint16_t mode) +{ + switch(status) { + case BMLITE_LED_STATUS_READY: + set_leds(0); + break; + case BMLITE_LED_STATUS_MATCH: + if (mode) { + set_leds(1); + } else { + set_leds(2); + } + hal_timebase_busy_wait(500); + break; + case BMLITE_LED_STATUS_WAITTOUCH: + if (mode) { + set_leds(3); + } + break; + case BMLITE_LED_STATUS_ENROLL: + if (mode) { + // Start enroll + set_leds(1); + hal_timebase_busy_wait(500); + set_leds(2); + hal_timebase_busy_wait(500); + } else { + // Finish enroll + set_leds(1); + hal_timebase_busy_wait(100); + set_leds(0); + hal_timebase_busy_wait(100); + set_leds(2); + hal_timebase_busy_wait(100); + } + break; + case BMLITE_LED_STATUS_DELETE_TEMPLATES: + set_leds(4); + hal_timebase_busy_wait(100); + set_leds(0); + hal_timebase_busy_wait(100); + set_leds(4); + hal_timebase_busy_wait(100); + break; + case BMLITE_LED_STATUS_ERROR: + if (mode) { + set_leds(3); + hal_timebase_busy_wait(70); + } else { + set_leds(3); + hal_timebase_busy_wait(500); + set_leds(0); + hal_timebase_busy_wait(500); + set_leds(3); + hal_timebase_busy_wait(500); + } + break; + } +} diff --git a/HAL_Driver/src/hal_spi.c b/HAL_Driver/src/hal_spi.c index f159fcb..575c00c 100755 --- a/HAL_Driver/src/hal_spi.c +++ b/HAL_Driver/src/hal_spi.c @@ -25,11 +25,9 @@ #include "nrf_gpiote.h" #include "nrf_drv_gpiote.h" -//#include "platform.h" #include "bmlite_hal.h" #include "fpc_bep_types.h" - #define SPI_INSTANCE 0 /**< SPI instance index. */ #define BMLITE_CS_PIN ARDUINO_8_PIN