Skip to content

Commit 2233908

Browse files
authored
Merge pull request #11 from tdk-invn-oss/release/4.2.5
CMake support improvements and bug fixes.
2 parents 5aac83e + 889a449 commit 2233908

File tree

7 files changed

+176
-127
lines changed

7 files changed

+176
-127
lines changed

CMakeLists.txt

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,66 @@ message(STATUS "CMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}")
2222
message(STATUS "")
2323
message(STATUS "CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
2424

25-
set(INCLUDE_SHASTA_SUPPORT OFF CACHE BOOL
26-
"Build soniclib for shasta (ICU) targets. Default is whitney targets \
27-
(chx01).")
28-
2925
set(CHIRP_MAX_NUM_SENSORS 4 CACHE STRING "Max number of supported sensors.")
30-
set(CHIRP_NUM_BUSES 2 CACHE STRING "Number of I2C/SPI buses used by sesnors.")
31-
set(CHIRP_SENSOR_INT_PIN 1 CACHE STRING
32-
"Pin used for interrupts (shasta only).")
33-
set(CHIRP_SENSOR_TRIG_PIN 1 CACHE STRING
34-
"Pin used for triggers (shasta only).")
26+
set(CHIRP_NUM_BUSES 2 CACHE STRING "Number of I2C/SPI buses used by sensors.")
27+
set(INCLUDE_SHASTA_SUPPORT OFF CACHE BOOL
28+
"Build soniclib for shasta (ICU) targets. Default is whitney targets \
29+
(chx01).")
30+
set(CHIRP_SENSOR_INT_PIN 1 CACHE STRING "Pin used for interrupts (shasta only).")
31+
set(CHIRP_SENSOR_TRIG_PIN 1 CACHE STRING "Pin used for triggers (shasta only).")
3532
set(CHIRP_INIT_FW_TYPE "FULL" CACHE STRING
36-
"Type of init firmware (shasta only). NO_TX_OPTIMIZATION leaves out the \
37-
transmit optimization feature but saves some space. NONE means no init \
38-
firmware. Not all firmware variants support the NONE option.")
33+
"Type of init firmware (shasta only). NO_TX_OPTIMIZATION leaves out the \
34+
transmit optimization feature but saves some space. NONE means no init \
35+
firmware. Not all firmware variants support the NONE option.")
3936
set_property(CACHE CHIRP_INIT_FW_TYPE PROPERTY STRINGS FULL
40-
NO_TX_OPTIMIZATION
41-
NONE)
42-
43-
set(INCLUDE_ALGO_EXTERNAL OFF CACHE BOOL
44-
"If set, do not include gpt (rangefinder) support")
37+
NO_TX_OPTIMIZATION
38+
NONE)
39+
set(CHIRP_MAIN_FW_TYPE "NONE" CACHE STRING
40+
"Main firmware to embed (if using one of the fw supplied with Soniclib)\
41+
Can be one of the follwing : NONE (build with another fw),\
42+
GPT, CH101_GPR, CH201_GPRMT, CHX01_FREQSWEEP")
43+
set_property(CACHE CHIRP_MAIN_FW_TYPE PROPERTY STRINGS NONE, GPT,
44+
CH101_GPR, CH201_GPRMT,
45+
CHX01_FREQSWEEP)
46+
set(INCLUDE_ALGO_EXTERNAL ON CACHE BOOL
47+
"If set, do not include gpt (rangefinder) support (deprecated)")
4548
set(CHIRP_LOG_LEVEL 4 CACHE STRING
46-
"Define the log level to use for the Soniclib internal log messages (4 = CH_LOG_LEVEL_ERROR)")
47-
48-
49+
"Define the log level to use for the Soniclib internal log messages \
50+
(4 = CH_LOG_LEVEL_ERROR)")
4951
set(RUN_UNIT_TEST OFF CACHE BOOL "If set, compile and run unit tests.")
5052

51-
message(RUN_UNIT_TEST "RUN_UNIT_TEST=${RUN_UNIT_TEST}")
52-
5353
if(RUN_UNIT_TEST)
5454
set(CMAKE_C_FLAGS --coverage)
5555
set(GCOV_LINK_FLAGS "--coverage")
5656
endif()
5757

58+
message(STATUS "CHIRP_MAX_NUM_SENSORS=${CHIRP_MAX_NUM_SENSORS}")
59+
message(STATUS "CHIRP_NUM_BUSES=${CHIRP_NUM_BUSES}")
60+
message(STATUS "CHIRP_SENSOR_INT_PIN=${CHIRP_SENSOR_INT_PIN}")
61+
message(STATUS "CHIRP_SENSOR_TRIG_PIN=${CHIRP_SENSOR_TRIG_PIN}")
62+
5863
message(STATUS "CHIRP_INIT_FW_TYPE=${CHIRP_INIT_FW_TYPE}")
64+
message(STATUS "CHIRP_MAIN_FW_TYPE=${CHIRP_MAIN_FW_TYPE}")
5965
message(STATUS "INCLUDE_ALGO_EXTERNAL=${INCLUDE_ALGO_EXTERNAL}")
6066
message(STATUS "INCLUDE_SHASTA_SUPPORT=${INCLUDE_SHASTA_SUPPORT}")
6167
message(STATUS "CHIRP_LOG_LEVEL=${CHIRP_LOG_LEVEL}")
62-
68+
message(STATUS "RUN_UNIT_TEST=${RUN_UNIT_TEST}")
6369

6470
set(SOURCES ${SRC_PATH}/chbsp_dummy.c
6571
${SRC_PATH}/ch_api.c
6672
${SRC_PATH}/ch_common.c
6773
${SRC_PATH}/ch_driver.c
68-
${SRC_PATH}/ch_math_utils.c
69-
${SRC_PATH}/extra/ch_extra_display_utils.c)
74+
${SRC_PATH}/ch_math_utils.c)
7075

7176
if (NOT ${CHIRP_LOG_LEVEL} EQUAL 6)
7277
# Build ch_log module if CHIRP_LOG_LEVEL isn't CH_LOG_LEVEL_DISABLE
7378
set(SOURCES ${SOURCES}
74-
${SRC_PATH}/ch_log.c)
79+
${SRC_PATH}/ch_log.c
80+
${SRC_PATH}/extra/ch_extra_display_utils.c)
7581
endif()
7682

7783
if(INCLUDE_SHASTA_SUPPORT)
78-
if (NOT INCLUDE_ALGO_EXTERNAL)
84+
if (CHIRP_MAIN_FW_TYPE STREQUAL "GPT" OR NOT INCLUDE_ALGO_EXTERNAL)
7985
set(SOURCES ${SOURCES}
8086
${SENS_FW_PATH}/icu_gpt/icu_gpt.c
8187
${SENS_FW_PATH}/icu_gpt/icu_gpt_fw.c)
@@ -92,33 +98,40 @@ if(INCLUDE_SHASTA_SUPPORT)
9298
endif()
9399
else()
94100
set(SOURCES ${SOURCES}
101+
${SRC_PATH}/ch_rangefinder.c)
102+
if (CHIRP_MAIN_FW_TYPE STREQUAL "CH101_GPR")
103+
set(SOURCES ${SOURCES}
95104
${SENS_FW_PATH}/ch101/ch101_gpr.c
96-
${SENS_FW_PATH}/ch101/ch101_gpr_fw.c
105+
${SENS_FW_PATH}/ch101/ch101_gpr_fw.c)
106+
endif()
107+
if (CHIRP_MAIN_FW_TYPE STREQUAL "CH201_GPRMT")
108+
set(SOURCES ${SOURCES}
97109
${SENS_FW_PATH}/ch201/ch201_gprmt.c
98-
${SENS_FW_PATH}/ch201/ch201_gprmt_fw.c
110+
${SENS_FW_PATH}/ch201/ch201_gprmt_fw.c)
111+
endif()
112+
if (CHIRP_MAIN_FW_TYPE STREQUAL "CHX01_FREQSWEEP")
113+
set(SOURCES ${SOURCES}
99114
${SENS_FW_PATH}/chx01/chx01_freqsweep.c
100-
${SENS_FW_PATH}/chx01/chx01_freqsweep_fw.c
101-
${SRC_PATH}/ch_rangefinder.c)
115+
${SENS_FW_PATH}/chx01/chx01_freqsweep_fw.c)
116+
endif()
102117
endif()
103118

104-
105119
add_library(${PROJ_NAME} STATIC ${SOURCES})
106120

107-
108121
target_include_directories(${PROJ_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
109122

110123
target_compile_definitions(${PROJ_NAME}
111-
PRIVATE -DINVN_SONICLIB_INTERNAL_BOARD_CONFIG
124+
PUBLIC -DINVN_SONICLIB_INTERNAL_BOARD_CONFIG
112125
-DCHIRP_MAX_NUM_SENSORS=${CHIRP_MAX_NUM_SENSORS}
113126
-DCHIRP_NUM_BUSES=${CHIRP_NUM_BUSES}
114127
-DCH_LOG_MODULE_LEVEL=${CHIRP_LOG_LEVEL})
115128

116129
if(INCLUDE_SHASTA_SUPPORT)
117130
target_compile_definitions(${PROJ_NAME} PUBLIC -DINCLUDE_SHASTA_SUPPORT
118-
PRIVATE -DCHIRP_SENSOR_INT_PIN=${CHIRP_SENSOR_INT_PIN}
131+
PUBLIC -DCHIRP_SENSOR_INT_PIN=${CHIRP_SENSOR_INT_PIN}
119132
-DCHIRP_SENSOR_TRIG_PIN=${CHIRP_SENSOR_TRIG_PIN})
120133
else()
121-
target_compile_definitions(${PROJ_NAME} PRIVATE -DINCLUDE_WHITNEY_SUPPORT)
134+
target_compile_definitions(${PROJ_NAME} PUBLIC -DINCLUDE_WHITNEY_SUPPORT)
122135
endif()
123136

124137
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ Additionally, there are several CMake variables that control various build
7676
options. These are as follows. See the
7777
`invn/soniclib/details/chirp_board_config.h` header for details.
7878

79-
* `CHIRP_INIT_FW_TYPE`: One of `FULL`, `NO_TX_OPTIMIZATION`, or `NONE`.
8079
* `CHIRP_MAX_NUM_SENSORS`: Maximum number of sensors supported.
8180
* `CHIRP_NUM_BUSES`: Number of SPI/I2C buses supported.
8281
* `CHIRP_SENSOR_INT_PIN`: (ICU-x0201 only) Pin to use for interrupts.
8382
* `CHIRP_SENSOR_TRIG_PIN`: (ICU-x0201 only) Pin to use for triggers.
84-
* `INCLUDE_SHASTA_SUPPORT`: Build for Shasta (ICU) architecture sensors.
83+
* `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`
84+
* `CHIRP_INIT_FW_TYPE`: Select an init firmware to build, if necessary in one of `FULL`, `NO_TX_OPTIMIZATION`, or `NONE`.
85+
* `CHIRP_LOG_LEVEL` : Define the log level to use for the Soniclib internal log messages
8586

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

105+
To build Soniclib from a parent cmake project, you can follow this example :
106+
107+
```cmake
108+
set(CHIRP_MAX_NUM_SENSORS 1 CACHE STRING "one sensor connected" FORCE)
109+
set(CHIRP_NUM_BUSES 1 CACHE STRING "one sensor connected" FORCE)
110+
set(INCLUDE_SHASTA_SUPPORT ON CACHE BOOL "using ICU sensors" FORCE)
111+
set(CHIRP_SENSOR_INT_PIN 1 CACHE STRING "use INT1 in freerun mode" FORCE)
112+
set(CHIRP_SENSOR_TRIG_PIN 1 CACHE STRING "use INT1 in freerun mode" FORCE)
113+
set(CHIRP_INIT_FW_TYPE "NO_TX_OPTIMIZATION" CACHE STRING "using fw presencev2" FORCE)
114+
set(CHIRP_LOG_LEVEL 2 CACHE STRING "log=info" FORCE)
115+
116+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/invn/soniclib/)
117+
118+
...
119+
120+
target_link_libraries(app PRIVATE soniclib)
121+
```
122+
104123
## Copyright
105-
© Copyright 2016-2023, TDK/InvenSense. All rights reserved.
124+
© Copyright 2016-2024, TDK/InvenSense. All rights reserved.

doc/soniclib-v4-migration-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ uint8_t icu_gpt_set_static_filter(ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t
170170
uint16_t icu_gpt_get_static_filter(ch_dev_t *dev_ptr, uint8_t meas_num)
171171
uint8_t icu_gpt_set_filter_update(ch_dev_t *dev_ptr, uint8_t meas_num, uint8_t update_interval)
172172
uint8_t icu_gpt_get_filter_update(ch_dev_t *dev_ptr, uint8_t meas_num)
173+
```
173174
174175
#### New API
175176

invn/soniclib/ch_driver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ void chdrv_int_callback(ch_group_t *grp_ptr, uint8_t dev_num) {
689689
uint16_t last_meas_reg_addr = (uint16_t)(uintptr_t) & ((dev_ptr->sens_cfg_addr)->raw.last_measurement);
690690

691691
chdrv_read_byte(dev_ptr, last_meas_reg_addr, &last_meas);
692-
dev_ptr->last_measurement = last_meas;
692+
dev_ptr->last_measurement = last_meas & ~LAST_MEASUREMENT_CONTINUOUS;
693+
dev_ptr->is_continuous = (last_meas & LAST_MEASUREMENT_CONTINUOUS) > 0;
693694

694695
uint8_t last_fmt;
695696
uint16_t last_fmt_reg_addr = (uint16_t)(uintptr_t) & ((dev_ptr->sens_cfg_addr)->raw.iq_output_format);

invn/soniclib/details/ch_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ extern "C" {
150150

151151
#endif /* INCLUDE_WHITNEY_SUPPORT */
152152

153-
#define NSEC_PER_SEC (1000000000U)
153+
#ifndef NSEC_PER_SEC
154+
#define NSEC_PER_SEC (1000000000U)
155+
#endif
154156
#define PMUT_FREQUENCY_ERROR_CODE (1) // this indicates some error in the frequency measurement
155157

156158
/* Function prototypes */

invn/soniclib/soniclib.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extern "C" {
113113
/* SonicLib API/Driver version */
114114
#define SONICLIB_VER_MAJOR (4) /*!< SonicLib major version. */
115115
#define SONICLIB_VER_MINOR (2) /*!< SonicLib minor version. */
116-
#define SONICLIB_VER_REV (1) /*!< SonicLib revision. */
116+
#define SONICLIB_VER_REV (5) /*!< SonicLib revision. */
117117
#define SONICLIB_VER_SUFFIX "" /*!< SonicLib version suffix (contains pre-release info) */
118118

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

0 commit comments

Comments
 (0)