Moved LEDs control completely to HAL

Change-Id: Ie420cd40d969d1776804dd837caf970c1b4e4c0b
This commit is contained in:
Andrey Perminov 2020-04-23 09:24:37 -07:00
parent 22f24e6a82
commit ce69dec56f
6 changed files with 78 additions and 56 deletions

View File

@ -82,8 +82,9 @@ uint32_t hal_get_button_press_time();
/* /*
* @brief Set LED(s) status * @brief Set LED(s) status
* @param[in] 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 */ #endif /* BMLITE_H */

View File

@ -27,7 +27,6 @@
#include <stddef.h> #include <stddef.h>
#include "fpc_com_result.h" #include "fpc_com_result.h"
#include "bmlite_hal.h"
/** /**
* @brief LED status. * @brief LED status.
@ -37,11 +36,10 @@
typedef enum { typedef enum {
BMLITE_LED_STATUS_READY = 0, BMLITE_LED_STATUS_READY = 0,
BMLITE_LED_STATUS_MATCH, BMLITE_LED_STATUS_MATCH,
BMLITE_LED_STATUS_NOMATCH,
BMLITE_LED_STATUS_WAITTOUCH, BMLITE_LED_STATUS_WAITTOUCH,
BMLITE_LED_STATUS_STARTENROLL, BMLITE_LED_STATUS_ENROLL,
BMLITE_LED_STATUS_FINISHENROLL, BMLITE_LED_STATUS_DELETE_TEMPLATES,
BMLITE_LED_STATUS_DELETE_TEMPLATES BMLITE_LED_STATUS_ERROR,
} platform_led_status_t; } platform_led_status_t;
/** /**
@ -91,14 +89,6 @@ void platform_halt_if_debug(void);
*/ */
void platform_sw_reset(void) __attribute__((__noreturn__)); 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. * @brief Get button press time.
* *

View File

@ -30,22 +30,15 @@
#include "bep_host_if.h" #include "bep_host_if.h"
#include "com_common.h" #include "com_common.h"
#include "platform.h" #include "platform.h"
#include "bmlite_hal.h"
void bmlite_on_error(bmlite_error_t error, int32_t value) void bmlite_on_error(bmlite_error_t error, int32_t value)
{ {
if(value != FPC_BEP_RESULT_TIMEOUT) { if(value != FPC_BEP_RESULT_TIMEOUT) {
platform_set_led(3); hal_set_leds(BMLITE_LED_STATUS_ERROR, false);
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);
} else { } else {
platform_set_led(3); // Timeout - not really an error here
hal_timebase_busy_wait(100); hal_set_leds(BMLITE_LED_STATUS_ERROR, true);
platform_set_led(0);
} }
} }
@ -54,36 +47,27 @@ void bmlite_on_error(bmlite_error_t error, int32_t value)
void bmlite_on_start_enroll() void bmlite_on_start_enroll()
{ {
platform_set_led(1); hal_set_leds(BMLITE_LED_STATUS_ENROLL, true);
hal_timebase_busy_wait(500);
platform_set_led(2);
hal_timebase_busy_wait(500);
} }
void bmlite_on_finish_enroll() void bmlite_on_finish_enroll()
{ {
platform_set_led(1); hal_set_leds(BMLITE_LED_STATUS_ENROLL, false);
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);
} }
void bmlite_on_start_enrollcapture() void bmlite_on_start_enrollcapture()
{ {
platform_set_led(3); hal_set_leds(BMLITE_LED_STATUS_WAITTOUCH, true);
} }
void bmlite_on_finish_enrollcapture() void bmlite_on_finish_enrollcapture()
{ {
platform_set_led(0); hal_set_leds(BMLITE_LED_STATUS_READY, false);
} }
void bmlite_on_identify_start() void bmlite_on_identify_start()
{ {
platform_set_led(0); hal_set_leds(BMLITE_LED_STATUS_READY, true);
} }
// void bmlite_on_identify_finish(); // void bmlite_on_identify_finish();
@ -111,11 +95,10 @@ int main (int argc, char **argv)
memset(version, 0, 100); memset(version, 0, 100);
fpc_bep_result_t res = bep_version(&hcp_chain, version, 99); fpc_bep_result_t res = bep_version(&hcp_chain, version, 99);
platform_set_led(BMLITE_LED_STATUS_READY);
while (1) while (1)
{ {
uint32_t btn_time = platform_get_button_press_time(); uint32_t btn_time = platform_get_button_press_time();
hal_set_leds(BMLITE_LED_STATUS_READY,0);
if (btn_time < 200) { if (btn_time < 200) {
// nothing hapened // nothing hapened
} else if (btn_time < 5000) { } else if (btn_time < 5000) {
@ -124,19 +107,13 @@ int main (int argc, char **argv)
res = bep_save_template(&hcp_chain, current_id++); res = bep_save_template(&hcp_chain, current_id++);
} else { } else {
// Erase All templates // Erase All templates
platform_set_led(BMLITE_LED_STATUS_DELETE_TEMPLATES); hal_set_leds(BMLITE_LED_STATUS_DELETE_TEMPLATES, true);
hal_timebase_busy_wait(500);
res = bep_delete_template(&hcp_chain, REMOVE_ID_ALL_TEMPLATES); res = bep_delete_template(&hcp_chain, REMOVE_ID_ALL_TEMPLATES);
} }
res = bep_identify_finger(&hcp_chain, &template_id, &match); res = bep_identify_finger(&hcp_chain, &template_id, &match);
if (res != FPC_BEP_RESULT_OK) if (res != FPC_BEP_RESULT_OK)
continue; continue;
if (match) { hal_set_leds(BMLITE_LED_STATUS_MATCH, match);
platform_set_led(BMLITE_LED_STATUS_MATCH);
} else {
platform_set_led(BMLITE_LED_STATUS_NOMATCH);
}
hal_timebase_busy_wait(500);
} }
} }
} }

View File

@ -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); return hal_bmlite_spi_write_read(buff, data, size, false);
} }
void platform_set_led(platform_led_status_t color)
{
hal_set_leds(color);
}

View File

@ -28,7 +28,7 @@
/** LED blink time in ms */ /** LED blink time in ms */
#define LED_BLINK_TIME_MS 200 #define LED_BLINK_TIME_MS 200
void hal_set_leds(uint8_t color) static void set_leds(uint8_t color)
{ {
uint32_t i; uint32_t i;
@ -41,3 +41,63 @@ void hal_set_leds(uint8_t color)
color = color >> 1; 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;
}
}

View File

@ -25,11 +25,9 @@
#include "nrf_gpiote.h" #include "nrf_gpiote.h"
#include "nrf_drv_gpiote.h" #include "nrf_drv_gpiote.h"
//#include "platform.h"
#include "bmlite_hal.h" #include "bmlite_hal.h"
#include "fpc_bep_types.h" #include "fpc_bep_types.h"
#define SPI_INSTANCE 0 /**< SPI instance index. */ #define SPI_INSTANCE 0 /**< SPI instance index. */
#define BMLITE_CS_PIN ARDUINO_8_PIN #define BMLITE_CS_PIN ARDUINO_8_PIN