Code refactoring and README updating

Change-Id: Ie9c30fae0de67054f9cb5c6aa7b38e62ceb86a08
This commit is contained in:
Andrey Perminov 2020-05-05 18:50:15 -07:00
parent 00d00350ab
commit 9ec34a39ef
6 changed files with 42 additions and 41 deletions

View File

@ -8,8 +8,24 @@
#ifndef BMLITE_H
#define BMLITE_H
#include <stddef.h>
#include "fpc_bep_types.h"
#include "platform.h"
/**
* @brief LED status.
*
* Different LED status.
*/
typedef enum {
BMLITE_LED_STATUS_READY = 0,
BMLITE_LED_STATUS_MATCH,
BMLITE_LED_STATUS_WAITTOUCH,
BMLITE_LED_STATUS_ENROLL,
BMLITE_LED_STATUS_DELETE_TEMPLATES,
BMLITE_LED_STATUS_ERROR,
} platform_led_status_t;
/*
* @brief Board initialization
@ -63,17 +79,25 @@ uint32_t hal_timebase_get_tick(void);
*/
void hal_timebase_busy_wait(uint32_t ms);
/*
/**
* Optional functions for Buttons & Leds control
*/
/*
/**
* @brief Get button press time (msec)
*
* @return ::uint32_t
*/
uint32_t hal_get_button_press_time();
uint32_t hal_get_button_press_time(void);
/*
/**
* @brief Check if button was pressed and released.
*
* @return Button press time in milli seconds.
*/
uint32_t hal_check_button_pressed(void);
/**
* @brief Set LED(s) status
* @param[in] Status
* @param[in] Status modifier

View File

@ -28,20 +28,6 @@
#include "fpc_bep_types.h"
/**
* @brief LED status.
*
* Different LED status.
*/
typedef enum {
BMLITE_LED_STATUS_READY = 0,
BMLITE_LED_STATUS_MATCH,
BMLITE_LED_STATUS_WAITTOUCH,
BMLITE_LED_STATUS_ENROLL,
BMLITE_LED_STATUS_DELETE_TEMPLATES,
BMLITE_LED_STATUS_ERROR,
} platform_led_status_t;
/**
* @brief Initializes board
*
@ -89,19 +75,4 @@ void platform_halt_if_debug(void);
*/
void platform_sw_reset(void) __attribute__((__noreturn__));
/**
* @brief Get button press time.
*
* @return Button press time in milli seconds.
*/
uint32_t platform_get_button_press_time(void);
/**
* @brief Check if button was pressed and released.
*
* @return Button press time in milli seconds.
*/
uint32_t platform_check_button_pressed(void);
#endif /* PLATFORM_H */

View File

@ -104,7 +104,7 @@ int main (int argc, char **argv)
while (1)
{
uint32_t btn_time = platform_get_button_press_time();
uint32_t btn_time = hal_get_button_press_time();
hal_set_leds(BMLITE_LED_STATUS_READY,0);
if (btn_time < 200) {
// nothing hapened

View File

@ -57,7 +57,7 @@ fpc_bep_result_t platform_bmlite_receive(uint16_t size, uint8_t *data, uint32_t
// Wait for BM_Lite Ready for timeout or indefinitely if timeout is 0
while (!hal_bmlite_get_status() &&
(!timeout || (curr_time = hal_timebase_get_tick()) - start_time < timeout)) {
if(platform_check_button_pressed()) {
if(hal_check_button_pressed()) {
return FPC_BEP_RESULT_TIMEOUT;
}
}
@ -69,3 +69,8 @@ fpc_bep_result_t platform_bmlite_receive(uint16_t size, uint8_t *data, uint32_t
return hal_bmlite_spi_write_read(buff, data, size, false);
}
__attribute__((weak)) uint32_t hal_check_button_pressed()
{
return 0;
}

View File

@ -115,14 +115,14 @@ static void check_buttons()
}
}
uint32_t platform_get_button_press_time()
uint32_t hal_get_button_press_time()
{
uint32_t time = button_pressed_time;
button_pressed_time = 0;
return time;
}
uint32_t platform_check_button_pressed()
uint32_t hal_check_button_pressed()
{
uint32_t time = button_pressed_time;
return time;

View File

@ -17,10 +17,10 @@ Platform-independent interface implemented in [platform.c](BMLite_example/src/pl
| :-------- | :-------- |
| bool **platform_init**(uint32_t speed_hz) | Initilalizes hardware |
| void **platform_bmlite_reset**(void) | Implements BM-Lite HW Reset |
| fpc_bep_result_t **platform_bmlite_send**(uint16_t size, const uint8_t *data, uint32_t timeout, void *session) | Send data packet to FPC BM-LIte (session parameter is for compatibility and can be safely ignored) |
| fpc_bep_result_t **platform_bmlite_receive**(uint16_t size, uint8_t *data, uint32_t timeout, void *session) | Receive data packet from FPC BM-LIte (session parameter is for compatibility and can be safely ignored) |
| fpc_bep_result_t **platform_bmlite_send**(uint16_t size, const uint8_t *data, uint32_t timeout, void *session) | Send data packet to FPC BM-LIte |
| fpc_bep_result_t **platform_bmlite_receive**(uint16_t size, uint8_t *data, uint32_t timeout, void *session) | Receive data packet from FPC BM-LIte. If timeout = **0**, the function will wait for data from BM-Lite indefinitely. The waiting loop will be breaked if **platform_check_button_pressed()** returns non-zero value. It is recommended to do HW or SW reset of BM-Lite if **platform_bmlite_receive()** returns **FPC_BEP_RESULT_TIMEOUT** in order to return is into known state. |
Currently **platform_bmlite_send()** and **platform_bmlite_receive()** are implemented for SPI interface. For UART interface there is no need to wait **IRQ** pin ready. However because in UART mode there is no signal from FPC-BM-LIte that it will send data, I would recommend to use UART interrupt or DMA to receive data from UART and store it to a separate buffer and read data in **platform_bmlite_receive()** from that buffer. Activation UART data reading only inside **platform_bmlite_receive()** could lead to loosing some incoming data and causing HCP protocol errors.
Currently **platform_bmlite_send()** and **platform_bmlite_receive()** are implemented for SPI interface. For UART interface there is no need to wait for **IRQ** pin ready. However because in UART mode there is no signal from FPC-BM-LIte that it will send data, I would recommend to use UART interrupt or DMA to receive data from UART and store it to a separate buffer and read data in **platform_bmlite_receive()** from that buffer. Activation UART data reading only inside **platform_bmlite_receive()** could lead to loosing some incoming data and causing HCP protocol errors.
------------
@ -45,6 +45,7 @@ For porting the project to a new microcontroller, all functions from [bmlite_hal
| HAL Function | Description |
| :------------ | :------------ |
| uint32_t **hal_get_button_press_time**(void) | How long UI button was pressed last time. Also it should reset button pressed time counter |
| uint32_t **platform_check_button_pressed**(void) | Used for breaking waiting in **platform_bmlite_receive()** if returns not 0 |
| void **hal_set_leds**(platform_led_status_t status, uint16_t mode) | Set LED(s) state according to status and mode. |
------------