diff --git a/BMLite_example/src/main.c b/BMLite_example/src/main.c index 64ead62..6e85d3b 100644 --- a/BMLite_example/src/main.c +++ b/BMLite_example/src/main.c @@ -12,10 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -/* - * 04/14/2020: Added SPI interfcae support + * + * Modified by Andrey Perminov + * for FPC BM-Lite applications + * + * 04/14/2020: Added SPI interface support */ diff --git a/BMLite_sdk/inc/bmlite_hal.h b/BMLite_sdk/inc/bmlite_hal.h index b926941..6c2fb74 100755 --- a/BMLite_sdk/inc/bmlite_hal.h +++ b/BMLite_sdk/inc/bmlite_hal.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 Andrey Perminov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /** * @file bmlite_hal.h * @brief BM-Lite HAL functions. diff --git a/BMLite_sdk/inc/bmlite_if.h b/BMLite_sdk/inc/bmlite_if.h index d5ebef3..a2977fd 100644 --- a/BMLite_sdk/inc/bmlite_if.h +++ b/BMLite_sdk/inc/bmlite_if.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 Andrey Perminov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef BMLITE_IF_H #define BMLITE_IF_H @@ -5,33 +21,28 @@ #include "bmlite_if_callbacks.h" /** - * @brief Build and send command to FPC BM-Lite and receive answer + * @brief Enroll finger. Created template must be saved to FLASH storage * - * @param[in] chain - HCP com chain - * @param[in] cmd - BM-Lite command - * @param[in] arg_type - Argument without parameters - * set to ARG_NONE if the command has no argument + * @param[in] chain - HCP com chain * * @return ::fpc_bep_result_t */ -fpc_bep_result_t bmlite_send_cmd(HCP_comm_t *chain, uint16_t cmd, uint16_t arg_type); +fpc_bep_result_t bep_enroll_finger(HCP_comm_t *chain); /** - * @brief Build and send command with additiona argument with parameters + * @brief Capture and identify finger against existing templates in Flash storage * - * @param[in] chain - HCP com chain - * @param[in] cmd - BM-Lite command - * @param[in] arg1_type - argument 1 without parameters - * set to ARG_NONE if the command has no argument without paramener - * @param[in] arg2_type - argument 2 - * @param[in] arg2_data - data pointer for argument 2 - * set to 0 if argument 2 has no parameter - * @param[in] arg2_length - length of data for argument 2 - * set to 0 if argument 2 has no parameter + * @param[in] chain - HCP com chain + * @param[in] timeout - timeout (msec). Maximum timeout 65535 msec + * set to 0 for waiting indefinitely + * + * @param[out] template_id - pointer for matched template ID + * @param[out] match - pointer to match result * * @return ::fpc_bep_result_t */ -fpc_bep_result_t bmlite_send_cmd_arg(HCP_comm_t *chain, uint16_t cmd, uint16_t arg1_type, uint16_t arg2_type, void *arg2_data, uint16_t arg2_length); +fpc_bep_result_t bep_identify_finger(HCP_comm_t *chain, uint32_t timeout, + uint16_t *template_id, bool *match); /** * @brief Wait for finger present on sensor" @@ -140,30 +151,6 @@ fpc_bep_result_t bep_image_extract(HCP_comm_t *chain); */ fpc_bep_result_t bep_identify(HCP_comm_t *chain); -/** - * @brief Enroll finger. Created template must be saved to FLASH storage - * - * @param[in] chain - HCP com chain - * - * @return ::fpc_bep_result_t - */ -fpc_bep_result_t bep_enroll_finger(HCP_comm_t *chain); - -/** - * @brief Capture and identify finger against existing templates in Flash storage - * - * @param[in] chain - HCP com chain - * @param[in] timeout - timeout (msec). Maximum timeout 65535 msec - * set to 0 for waiting indefinitely - * - * @param[out] template_id - pointer for matched template ID - * @param[out] match - pointer to match result - * - * @return ::fpc_bep_result_t - */ -fpc_bep_result_t bep_identify_finger(HCP_comm_t *chain, uint32_t timeout, - uint16_t *template_id, bool *match); - /** * @brief Save template after enroll is finished to FLASH storage * @@ -344,4 +331,35 @@ fpc_bep_result_t bep_uart_speed_get(HCP_comm_t *chain, uint32_t *speed); */ fpc_bep_result_t bep_sensor_reset(HCP_comm_t *chain); +/** + * @brief Build and send command to FPC BM-Lite and receive answer + * + * @param[in] chain - HCP com chain + * @param[in] cmd - BM-Lite command + * @param[in] arg_type - Argument without parameters + * set to ARG_NONE if the command has no argument + * + * @return ::fpc_bep_result_t + */ +fpc_bep_result_t bmlite_send_cmd(HCP_comm_t *chain, uint16_t cmd, uint16_t arg_type); + +/** + * @brief Build and send command with additiona argument with parameters + * + * @param[in] chain - HCP com chain + * @param[in] cmd - BM-Lite command + * @param[in] arg1_type - argument 1 without parameters + * set to ARG_NONE if the command has no argument without paramener + * @param[in] arg2_type - argument 2 + * @param[in] arg2_data - data pointer for argument 2 + * set to 0 if argument 2 has no parameter + * @param[in] arg2_length - length of data for argument 2 + * set to 0 if argument 2 has no parameter + * + * @return ::fpc_bep_result_t + */ +fpc_bep_result_t bmlite_send_cmd_arg(HCP_comm_t *chain, uint16_t cmd, uint16_t arg1_type, uint16_t arg2_type, void *arg2_data, uint16_t arg2_length); + + + #endif \ No newline at end of file diff --git a/BMLite_sdk/inc/bmlite_if_callbacks.h b/BMLite_sdk/inc/bmlite_if_callbacks.h index de22022..6f816f7 100644 --- a/BMLite_sdk/inc/bmlite_if_callbacks.h +++ b/BMLite_sdk/inc/bmlite_if_callbacks.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 Andrey Perminov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef BMLITE_IF_CALLBACKS_H #define BMLITE_IF_CALLBACKS_H #include diff --git a/BMLite_sdk/inc/hcp_tiny.h b/BMLite_sdk/inc/hcp_tiny.h index 2bbf3b4..d87226a 100644 --- a/BMLite_sdk/inc/hcp_tiny.h +++ b/BMLite_sdk/inc/hcp_tiny.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 Andrey Perminov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef HCP_H #define HCP_H @@ -127,6 +143,4 @@ fpc_bep_result_t bmlite_get_arg(HCP_comm_t *hcp_comm, uint16_t arg_type); */ fpc_bep_result_t bmlite_copy_arg(HCP_comm_t *hcp_comm, uint16_t arg_key, void *arg_data, uint16_t arg_data_size); - - #endif \ No newline at end of file diff --git a/BMLite_sdk/inc/platform.h b/BMLite_sdk/inc/platform.h index a3f2495..ef48c0d 100644 --- a/BMLite_sdk/inc/platform.h +++ b/BMLite_sdk/inc/platform.h @@ -12,8 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Modified by Andrey Perminov + * for FPC BM-Lite applications */ + #ifndef PLATFORM_H #define PLATFORM_H diff --git a/BMLite_sdk/src/bmlite_if.c b/BMLite_sdk/src/bmlite_if.c index c20ea70..3876b97 100644 --- a/BMLite_sdk/src/bmlite_if.c +++ b/BMLite_sdk/src/bmlite_if.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 Andrey Perminov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "hcp_tiny.h" #include "bmlite_if.h" #include "bmlite_hal.h" @@ -33,18 +49,73 @@ __attribute__((weak)) void bmlite_on_identify_start() {} __attribute__((weak)) void bmlite_on_identify_finish() {} #endif -fpc_bep_result_t bmlite_send_cmd(HCP_comm_t *chain, uint16_t cmd, uint16_t arg_type) +fpc_bep_result_t bep_enroll_finger(HCP_comm_t *chain) { - assert(bmlite_init_cmd(chain, cmd, arg_type)); - return bmlite_tranceive(chain); + uint32_t samples_remaining = 0; + fpc_bep_result_t bep_result = FPC_BEP_RESULT_OK; + bool enroll_done = false; + + bmlite_on_start_enroll(); + /* Enroll start */ + exit_if_err(bmlite_send_cmd(chain, CMD_ENROLL, ARG_START)); + + for (uint8_t i = 0; i < MAX_CAPTURE_ATTEMPTS; ++i) { + + bmlite_on_start_enrollcapture(); + bep_result = bep_capture(chain, CAPTURE_TIMEOUT); + bmlite_on_finish_enrollcapture(); + + if (bep_result != FPC_BEP_RESULT_OK) { + continue; + } + + /* Enroll add */ + bep_result = bmlite_send_cmd(chain, CMD_ENROLL, ARG_ADD); + if (bep_result != FPC_BEP_RESULT_OK) { + continue; + } + + bmlite_get_arg(chain, ARG_COUNT); + samples_remaining = *(uint32_t *)chain->arg.data; +// DEBUG("Enroll samples remaining: %d\n", samples_remaining); + + /* Break enrolling if we can't collect enough correct images for enroll*/ + if (samples_remaining == 0U) { + enroll_done = true; + break; + } + + sensor_wait_finger_not_present(chain, 0); + } + + bep_result = bmlite_send_cmd(chain, CMD_ENROLL, ARG_FINISH); + +exit: + bmlite_on_finish_enroll(); + return (!enroll_done) ? FPC_BEP_RESULT_GENERAL_ERROR : bep_result; } -fpc_bep_result_t bmlite_send_cmd_arg(HCP_comm_t *chain, uint16_t cmd, uint16_t arg1_type, uint16_t arg2_type, void *arg2_data, uint16_t arg2_length) +fpc_bep_result_t bep_identify_finger(HCP_comm_t *chain, uint32_t timeout, uint16_t *template_id, bool *match) { - assert(bmlite_init_cmd(chain, cmd, arg1_type)); - assert(bmlite_add_arg(chain, arg2_type, arg2_data, arg2_length)); + fpc_bep_result_t bep_result; + *match = false; - return bmlite_tranceive(chain); + bmlite_on_identify_start(); + + exit_if_err(bep_capture(chain, timeout)); + exit_if_err(bep_image_extract(chain)); + exit_if_err(bep_identify(chain)); + exit_if_err(bmlite_get_arg(chain, ARG_MATCH)); + *match = *(bool *)chain->arg.data; + if(*match) { + bmlite_get_arg(chain, ARG_ID); + *template_id = *(uint16_t *)chain->arg.data; + // Delay for possible updating template on BM-Lite + hal_timebase_busy_wait(50); + } +exit: + bmlite_on_identify_finish(); + return bep_result; } fpc_bep_result_t sensor_wait_finger_present(HCP_comm_t *chain, uint16_t timeout) @@ -132,79 +203,6 @@ fpc_bep_result_t bep_identify(HCP_comm_t *chain) return bmlite_send_cmd(chain, CMD_IDENTIFY, ARG_NONE); } -fpc_bep_result_t bep_enroll_finger(HCP_comm_t *chain) -{ - uint32_t samples_remaining = 0; - fpc_bep_result_t bep_result = FPC_BEP_RESULT_OK; - bool enroll_done = false; - - bmlite_on_start_enroll(); - /* Enroll start */ - exit_if_err(bmlite_send_cmd(chain, CMD_ENROLL, ARG_START)); - - for (uint8_t i = 0; i < MAX_CAPTURE_ATTEMPTS; ++i) { - - bmlite_on_start_enrollcapture(); - bep_result = bep_capture(chain, CAPTURE_TIMEOUT); - bmlite_on_finish_enrollcapture(); - - if (bep_result != FPC_BEP_RESULT_OK) { - continue; - } - - /* Enroll add */ - bep_result = bmlite_send_cmd(chain, CMD_ENROLL, ARG_ADD); - if (bep_result != FPC_BEP_RESULT_OK) { - continue; - } - - bmlite_get_arg(chain, ARG_COUNT); - samples_remaining = *(uint32_t *)chain->arg.data; - -// log_info("Enroll samples remaining: %d\n", samples_remaining); - - /* Break enrolling if we can't collect enough correct images for enroll*/ - if (samples_remaining == 0U) { - enroll_done = true; - break; - } - - sensor_wait_finger_not_present(chain, 0); - } - - bep_result = bmlite_send_cmd(chain, CMD_ENROLL, ARG_FINISH); - -exit: - bmlite_on_finish_enroll(); - return (!enroll_done) ? FPC_BEP_RESULT_GENERAL_ERROR : bep_result; -} - -fpc_bep_result_t bep_identify_finger(HCP_comm_t *chain, uint32_t timeout, uint16_t *template_id, bool *match) -{ - fpc_bep_result_t bep_result; - *match = false; - - bmlite_on_identify_start(); - - exit_if_err(bep_capture(chain, timeout)); - exit_if_err(bep_image_extract(chain)); - exit_if_err(bep_identify(chain)); - exit_if_err(bmlite_get_arg(chain, ARG_MATCH)); - *match = *(bool *)chain->arg.data; - if(*match) { - bmlite_get_arg(chain, ARG_ID); - *template_id = *(uint16_t *)chain->arg.data; - // Delay for possible updating template on BM-Lite - hal_timebase_busy_wait(50); - } - - bep_result = sensor_wait_finger_not_present(chain, 0); - -exit: - bmlite_on_identify_finish(); - return bep_result; -} - fpc_bep_result_t bep_template_save(HCP_comm_t *chain, uint16_t template_id) { return bmlite_send_cmd_arg(chain, CMD_TEMPLATE, ARG_SAVE, ARG_ID, &template_id, sizeof(template_id)); @@ -311,3 +309,17 @@ fpc_bep_result_t bep_sensor_reset(HCP_comm_t *chain) return bmlite_send_cmd(chain, CMD_SENSOR, ARG_RESET); } + +fpc_bep_result_t bmlite_send_cmd(HCP_comm_t *chain, uint16_t cmd, uint16_t arg_type) +{ + assert(bmlite_init_cmd(chain, cmd, arg_type)); + return bmlite_tranceive(chain); +} + +fpc_bep_result_t bmlite_send_cmd_arg(HCP_comm_t *chain, uint16_t cmd, uint16_t arg1_type, uint16_t arg2_type, void *arg2_data, uint16_t arg2_length) +{ + assert(bmlite_init_cmd(chain, cmd, arg1_type)); + assert(bmlite_add_arg(chain, arg2_type, arg2_data, arg2_length)); + + return bmlite_tranceive(chain); +} diff --git a/BMLite_sdk/src/hcp_tiny.c b/BMLite_sdk/src/hcp_tiny.c index 43bdab7..e915623 100644 --- a/BMLite_sdk/src/hcp_tiny.c +++ b/BMLite_sdk/src/hcp_tiny.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 Andrey Perminov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include "platform.h" @@ -261,7 +277,7 @@ fpc_bep_result_t bmlite_send(HCP_comm_t *hcp_comm) return bep_result; } -fpc_bep_result_t _tx_link(HCP_comm_t *hcp_comm) +static fpc_bep_result_t _tx_link(HCP_comm_t *hcp_comm) { fpc_bep_result_t bep_result; diff --git a/BMLite_sdk/src/platform.c b/BMLite_sdk/src/platform.c index 5d28d6a..9b4d011 100644 --- a/BMLite_sdk/src/platform.c +++ b/BMLite_sdk/src/platform.c @@ -12,14 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Modified by Andrey Perminov + * for BM-Lite applications */ + /** * @file platform.c * @brief Platform specific functions */ - #include "fpc_bep_types.h" #include "platform.h" #include "bmlite_hal.h" diff --git a/HAL_Driver/inc/platform_rpi.h b/HAL_Driver/inc/platform_rpi.h index e8be771..cfa0fe1 100644 --- a/HAL_Driver/inc/platform_rpi.h +++ b/HAL_Driver/inc/platform_rpi.h @@ -12,6 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Modified by Andrey Perminov + * for FPC BM-Lite applications */ #ifndef PLATFORM_RPI_H diff --git a/HAL_Driver/src/platform_linux.c b/HAL_Driver/src/platform_linux.c index f8e2d5c..c6055a8 100644 --- a/HAL_Driver/src/platform_linux.c +++ b/HAL_Driver/src/platform_linux.c @@ -12,6 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Modified by Andrey Perminov + * for FPC BM-Lite applications */ /** diff --git a/HAL_Driver/src/rpi_spi.c b/HAL_Driver/src/rpi_spi.c index 173bd8a..34ea760 100644 --- a/HAL_Driver/src/rpi_spi.c +++ b/HAL_Driver/src/rpi_spi.c @@ -12,6 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Modified by Andrey Perminov + * for FPC BM-Lite applications */ /**