Skip to content

Commit

Permalink
Merge pull request #11 from tdk-invn-oss/release/4.2.5
Browse files Browse the repository at this point in the history
CMake support improvements and bug fixes.
  • Loading branch information
mhkline authored Sep 16, 2024
2 parents 5aac83e + 889a449 commit 2233908
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 127 deletions.
85 changes: 49 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,66 @@ message(STATUS "CMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}")
message(STATUS "")
message(STATUS "CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")

set(INCLUDE_SHASTA_SUPPORT OFF CACHE BOOL
"Build soniclib for shasta (ICU) targets. Default is whitney targets \
(chx01).")

set(CHIRP_MAX_NUM_SENSORS 4 CACHE STRING "Max number of supported sensors.")
set(CHIRP_NUM_BUSES 2 CACHE STRING "Number of I2C/SPI buses used by sesnors.")
set(CHIRP_SENSOR_INT_PIN 1 CACHE STRING
"Pin used for interrupts (shasta only).")
set(CHIRP_SENSOR_TRIG_PIN 1 CACHE STRING
"Pin used for triggers (shasta only).")
set(CHIRP_NUM_BUSES 2 CACHE STRING "Number of I2C/SPI buses used by sensors.")
set(INCLUDE_SHASTA_SUPPORT OFF CACHE BOOL
"Build soniclib for shasta (ICU) targets. Default is whitney targets \
(chx01).")
set(CHIRP_SENSOR_INT_PIN 1 CACHE STRING "Pin used for interrupts (shasta only).")
set(CHIRP_SENSOR_TRIG_PIN 1 CACHE STRING "Pin used for triggers (shasta only).")
set(CHIRP_INIT_FW_TYPE "FULL" CACHE STRING
"Type of init firmware (shasta only). NO_TX_OPTIMIZATION leaves out the \
transmit optimization feature but saves some space. NONE means no init \
firmware. Not all firmware variants support the NONE option.")
"Type of init firmware (shasta only). NO_TX_OPTIMIZATION leaves out the \
transmit optimization feature but saves some space. NONE means no init \
firmware. Not all firmware variants support the NONE option.")
set_property(CACHE CHIRP_INIT_FW_TYPE PROPERTY STRINGS FULL
NO_TX_OPTIMIZATION
NONE)

set(INCLUDE_ALGO_EXTERNAL OFF CACHE BOOL
"If set, do not include gpt (rangefinder) support")
NO_TX_OPTIMIZATION
NONE)
set(CHIRP_MAIN_FW_TYPE "NONE" CACHE STRING
"Main firmware to embed (if using one of the fw supplied with Soniclib)\
Can be one of the follwing : NONE (build with another fw),\
GPT, CH101_GPR, CH201_GPRMT, CHX01_FREQSWEEP")
set_property(CACHE CHIRP_MAIN_FW_TYPE PROPERTY STRINGS NONE, GPT,
CH101_GPR, CH201_GPRMT,
CHX01_FREQSWEEP)
set(INCLUDE_ALGO_EXTERNAL ON CACHE BOOL
"If set, do not include gpt (rangefinder) support (deprecated)")
set(CHIRP_LOG_LEVEL 4 CACHE STRING
"Define the log level to use for the Soniclib internal log messages (4 = CH_LOG_LEVEL_ERROR)")


"Define the log level to use for the Soniclib internal log messages \
(4 = CH_LOG_LEVEL_ERROR)")
set(RUN_UNIT_TEST OFF CACHE BOOL "If set, compile and run unit tests.")

message(RUN_UNIT_TEST "RUN_UNIT_TEST=${RUN_UNIT_TEST}")

if(RUN_UNIT_TEST)
set(CMAKE_C_FLAGS --coverage)
set(GCOV_LINK_FLAGS "--coverage")
endif()

message(STATUS "CHIRP_MAX_NUM_SENSORS=${CHIRP_MAX_NUM_SENSORS}")
message(STATUS "CHIRP_NUM_BUSES=${CHIRP_NUM_BUSES}")
message(STATUS "CHIRP_SENSOR_INT_PIN=${CHIRP_SENSOR_INT_PIN}")
message(STATUS "CHIRP_SENSOR_TRIG_PIN=${CHIRP_SENSOR_TRIG_PIN}")

message(STATUS "CHIRP_INIT_FW_TYPE=${CHIRP_INIT_FW_TYPE}")
message(STATUS "CHIRP_MAIN_FW_TYPE=${CHIRP_MAIN_FW_TYPE}")
message(STATUS "INCLUDE_ALGO_EXTERNAL=${INCLUDE_ALGO_EXTERNAL}")
message(STATUS "INCLUDE_SHASTA_SUPPORT=${INCLUDE_SHASTA_SUPPORT}")
message(STATUS "CHIRP_LOG_LEVEL=${CHIRP_LOG_LEVEL}")

message(STATUS "RUN_UNIT_TEST=${RUN_UNIT_TEST}")

set(SOURCES ${SRC_PATH}/chbsp_dummy.c
${SRC_PATH}/ch_api.c
${SRC_PATH}/ch_common.c
${SRC_PATH}/ch_driver.c
${SRC_PATH}/ch_math_utils.c
${SRC_PATH}/extra/ch_extra_display_utils.c)
${SRC_PATH}/ch_math_utils.c)

if (NOT ${CHIRP_LOG_LEVEL} EQUAL 6)
# Build ch_log module if CHIRP_LOG_LEVEL isn't CH_LOG_LEVEL_DISABLE
set(SOURCES ${SOURCES}
${SRC_PATH}/ch_log.c)
${SRC_PATH}/ch_log.c
${SRC_PATH}/extra/ch_extra_display_utils.c)
endif()

if(INCLUDE_SHASTA_SUPPORT)
if (NOT INCLUDE_ALGO_EXTERNAL)
if (CHIRP_MAIN_FW_TYPE STREQUAL "GPT" OR NOT INCLUDE_ALGO_EXTERNAL)
set(SOURCES ${SOURCES}
${SENS_FW_PATH}/icu_gpt/icu_gpt.c
${SENS_FW_PATH}/icu_gpt/icu_gpt_fw.c)
Expand All @@ -92,33 +98,40 @@ if(INCLUDE_SHASTA_SUPPORT)
endif()
else()
set(SOURCES ${SOURCES}
${SRC_PATH}/ch_rangefinder.c)
if (CHIRP_MAIN_FW_TYPE STREQUAL "CH101_GPR")
set(SOURCES ${SOURCES}
${SENS_FW_PATH}/ch101/ch101_gpr.c
${SENS_FW_PATH}/ch101/ch101_gpr_fw.c
${SENS_FW_PATH}/ch101/ch101_gpr_fw.c)
endif()
if (CHIRP_MAIN_FW_TYPE STREQUAL "CH201_GPRMT")
set(SOURCES ${SOURCES}
${SENS_FW_PATH}/ch201/ch201_gprmt.c
${SENS_FW_PATH}/ch201/ch201_gprmt_fw.c
${SENS_FW_PATH}/ch201/ch201_gprmt_fw.c)
endif()
if (CHIRP_MAIN_FW_TYPE STREQUAL "CHX01_FREQSWEEP")
set(SOURCES ${SOURCES}
${SENS_FW_PATH}/chx01/chx01_freqsweep.c
${SENS_FW_PATH}/chx01/chx01_freqsweep_fw.c
${SRC_PATH}/ch_rangefinder.c)
${SENS_FW_PATH}/chx01/chx01_freqsweep_fw.c)
endif()
endif()


add_library(${PROJ_NAME} STATIC ${SOURCES})


target_include_directories(${PROJ_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(${PROJ_NAME}
PRIVATE -DINVN_SONICLIB_INTERNAL_BOARD_CONFIG
PUBLIC -DINVN_SONICLIB_INTERNAL_BOARD_CONFIG
-DCHIRP_MAX_NUM_SENSORS=${CHIRP_MAX_NUM_SENSORS}
-DCHIRP_NUM_BUSES=${CHIRP_NUM_BUSES}
-DCH_LOG_MODULE_LEVEL=${CHIRP_LOG_LEVEL})

if(INCLUDE_SHASTA_SUPPORT)
target_compile_definitions(${PROJ_NAME} PUBLIC -DINCLUDE_SHASTA_SUPPORT
PRIVATE -DCHIRP_SENSOR_INT_PIN=${CHIRP_SENSOR_INT_PIN}
PUBLIC -DCHIRP_SENSOR_INT_PIN=${CHIRP_SENSOR_INT_PIN}
-DCHIRP_SENSOR_TRIG_PIN=${CHIRP_SENSOR_TRIG_PIN})
else()
target_compile_definitions(${PROJ_NAME} PRIVATE -DINCLUDE_WHITNEY_SUPPORT)
target_compile_definitions(${PROJ_NAME} PUBLIC -DINCLUDE_WHITNEY_SUPPORT)
endif()

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
Expand Down
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ Additionally, there are several CMake variables that control various build
options. These are as follows. See the
`invn/soniclib/details/chirp_board_config.h` header for details.

* `CHIRP_INIT_FW_TYPE`: One of `FULL`, `NO_TX_OPTIMIZATION`, or `NONE`.
* `CHIRP_MAX_NUM_SENSORS`: Maximum number of sensors supported.
* `CHIRP_NUM_BUSES`: Number of SPI/I2C buses supported.
* `CHIRP_SENSOR_INT_PIN`: (ICU-x0201 only) Pin to use for interrupts.
* `CHIRP_SENSOR_TRIG_PIN`: (ICU-x0201 only) Pin to use for triggers.
* `INCLUDE_SHASTA_SUPPORT`: Build for Shasta (ICU) architecture sensors.
* `CHIRP_MAIN_FW_TYPE` : Select the main firmware to build with, can be one of `NONE` (fw built externally) or one of the firmware embedded by default with Soniclib `GPT` (for shasta devices), `CH101_GPR`, `CH201_GPRMT` or `CHX01_FREQSWEEP`
* `CHIRP_INIT_FW_TYPE`: Select an init firmware to build, if necessary in one of `FULL`, `NO_TX_OPTIMIZATION`, or `NONE`.
* `CHIRP_LOG_LEVEL` : Define the log level to use for the Soniclib internal log messages

These variables can be set through the CMake GUI, through command line -D
options in the main CMake command, or manually through the `CMakeCache.txt` file
Expand All @@ -96,10 +97,28 @@ line-continuation.
```powershell
cmake -G "MinGW Makefiles" `
-DCMAKE_TOOLCHAIN_FILE="CMakeToolchains/arm-none-eabi-m4.cmake" `
-DINCLUDE_SHASTA_SUPPORT:BOOL=ON `
-DCHIRP_MAIN_FW_TYPE:STRING=GPT `
-DCHIRP_INIT_FW_TYPE:STRING=NO_TX_OPTIMIZATION `
-B build
```

To build Soniclib from a parent cmake project, you can follow this example :

```cmake
set(CHIRP_MAX_NUM_SENSORS 1 CACHE STRING "one sensor connected" FORCE)
set(CHIRP_NUM_BUSES 1 CACHE STRING "one sensor connected" FORCE)
set(INCLUDE_SHASTA_SUPPORT ON CACHE BOOL "using ICU sensors" FORCE)
set(CHIRP_SENSOR_INT_PIN 1 CACHE STRING "use INT1 in freerun mode" FORCE)
set(CHIRP_SENSOR_TRIG_PIN 1 CACHE STRING "use INT1 in freerun mode" FORCE)
set(CHIRP_INIT_FW_TYPE "NO_TX_OPTIMIZATION" CACHE STRING "using fw presencev2" FORCE)
set(CHIRP_LOG_LEVEL 2 CACHE STRING "log=info" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/invn/soniclib/)
...
target_link_libraries(app PRIVATE soniclib)
```

## Copyright
© Copyright 2016-2023, TDK/InvenSense. All rights reserved.
© Copyright 2016-2024, TDK/InvenSense. All rights reserved.
1 change: 1 addition & 0 deletions doc/soniclib-v4-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ uint8_t icu_gpt_set_static_filter(ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t
uint16_t icu_gpt_get_static_filter(ch_dev_t *dev_ptr, uint8_t meas_num)
uint8_t icu_gpt_set_filter_update(ch_dev_t *dev_ptr, uint8_t meas_num, uint8_t update_interval)
uint8_t icu_gpt_get_filter_update(ch_dev_t *dev_ptr, uint8_t meas_num)
```
#### New API
Expand Down
3 changes: 2 additions & 1 deletion invn/soniclib/ch_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@ void chdrv_int_callback(ch_group_t *grp_ptr, uint8_t dev_num) {
uint16_t last_meas_reg_addr = (uint16_t)(uintptr_t) & ((dev_ptr->sens_cfg_addr)->raw.last_measurement);

chdrv_read_byte(dev_ptr, last_meas_reg_addr, &last_meas);
dev_ptr->last_measurement = last_meas;
dev_ptr->last_measurement = last_meas & ~LAST_MEASUREMENT_CONTINUOUS;
dev_ptr->is_continuous = (last_meas & LAST_MEASUREMENT_CONTINUOUS) > 0;

uint8_t last_fmt;
uint16_t last_fmt_reg_addr = (uint16_t)(uintptr_t) & ((dev_ptr->sens_cfg_addr)->raw.iq_output_format);
Expand Down
4 changes: 3 additions & 1 deletion invn/soniclib/details/ch_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ extern "C" {

#endif /* INCLUDE_WHITNEY_SUPPORT */

#define NSEC_PER_SEC (1000000000U)
#ifndef NSEC_PER_SEC
#define NSEC_PER_SEC (1000000000U)
#endif
#define PMUT_FREQUENCY_ERROR_CODE (1) // this indicates some error in the frequency measurement

/* Function prototypes */
Expand Down
8 changes: 7 additions & 1 deletion invn/soniclib/soniclib.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extern "C" {
/* SonicLib API/Driver version */
#define SONICLIB_VER_MAJOR (4) /*!< SonicLib major version. */
#define SONICLIB_VER_MINOR (2) /*!< SonicLib minor version. */
#define SONICLIB_VER_REV (1) /*!< SonicLib revision. */
#define SONICLIB_VER_REV (5) /*!< SonicLib revision. */
#define SONICLIB_VER_SUFFIX "" /*!< SonicLib version suffix (contains pre-release info) */

/***** DO NOT MODIFY ANY VALUES BEYOND THIS POINT! *****/
Expand Down Expand Up @@ -3194,6 +3194,12 @@ void ch_meas_init_segment_count(ch_meas_segment_t *seg_ptr, uint16_t num_cycles,
*
* This function initializes the measurement segment descriptor specified by \a seg_ptr as
* a receive segment.
* The number of samples of added to the segments is limited by the maximum number of rx samples
* that firmware can read and by the number of cycles a segment can store.
* The length of segment in samples is converted to a number of cycles.
* A segment have a maximum length of 65535 cycles.
* If the number of sample exceeds the limitation, define the segments manually and import them
* to a measure queue using \a ch_meas_import()
*/
void ch_meas_init_segment_rx(ch_meas_segment_t *seg_ptr, uint16_t num_samples, ch_odr_t odr, uint8_t gain_reduce,
uint8_t atten, uint8_t int_enable);
Expand Down
Loading

0 comments on commit 2233908

Please sign in to comment.