Skip to content

Commit

Permalink
IAQ-App:
Browse files Browse the repository at this point in the history
- Remove font
- Change data type for IAQ label to float without decimal places

ADPS9306:
- Enable ADPS9306 driver for hardware revision 3
- Move "DT_DRV_COMPAT" in ADPS9306 source file
- Fix typos in ADPS9306 driver
- Smaller layout changes

BMP581:
- Enable BMP581 driver for all hardware revisions
- Change BMP581 implementation to sensors subsystem
- Remove the old BMP581 driver
- Change path for BMP5 sensor API module to /ext_drivers

Sensors:
- Put directory for BMP5 sensor API to gitignore to prevent a listing in git
- Add CMakeLists for sensors
- Add ZBUS for light sensor
- Add ZBUS for environment sensor
- Connect sensor ZBUS events with period event
- Reorganize configuration options from project config to specific board configuration files

Signed-off-by: Daniel Kampert <[email protected]>
  • Loading branch information
Kampi committed Nov 2, 2023
1 parent 03c4a57 commit 9eb7b8f
Show file tree
Hide file tree
Showing 39 changed files with 688 additions and 581 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[submodule "app/src/ext_drivers/bmp581/BMP5-Sensor-API"]
path = app/src/ext_drivers/bmp581/BMP5-Sensor-API
[submodule "app/src/ext_drivers/BMP5-Sensor-API"]
path = app/src/ext_drivers/BMP5-Sensor-API
url = https://github.com/boschsensortec/BMP5-Sensor-API.git
[submodule "app/src/applications/2048/2048_lib"]
path = app/src/applications/2048/2048_lib
Expand Down
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ debug
!.vscode/extensions.json
!.vscode/*.code-snippets

src/ext_drivers/BSEC2
src/ext_drivers/BSEC2
src/ext_drivers/BMP5-Sensor-API
8 changes: 1 addition & 7 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ project(ZSWatchFW)

add_subdirectory(drivers)
add_subdirectory(src/applications)
add_subdirectory(src/sensors)
add_subdirectory(src/ext_drivers/bmi270)
add_subdirectory(src/ext_drivers/bmp581)

include_directories(src/)
include_directories(src/ui)
Expand Down Expand Up @@ -48,12 +48,6 @@ target_sources(app PRIVATE src/ble/ble_comm.c)
target_sources(app PRIVATE src/ble/ble_transport.c)
target_sources(app PRIVATE src/ble/zsw_gatt_sensor_server.c)

target_sources(app PRIVATE src/sensors/zsw_imu.c)
target_sources(app PRIVATE src/sensors/zsw_pressure_sensor.c)
target_sources(app PRIVATE src/sensors/zsw_magnetometer.c)
target_sources(app PRIVATE src/sensors/zsw_light_sensor.c)
target_sources(app PRIVATE src/sensors/zsw_environment_sensor.c)

target_sources(app PRIVATE src/ui/notification/zsw_popup_notifcation.c)
target_sources(app PRIVATE src/ui/popup/zsw_popup_window.c)
target_sources(app PRIVATE src/ui/utils/zsw_ui_utils.c)
Expand Down
4 changes: 4 additions & 0 deletions app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_3.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ CONFIG_SPI_NOR_SFDP_RUNTIME=y
CONFIG_SPI_NOR_IDLE_IN_DPD=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# APDS9306
CONFIG_APDS9306=y
CONFIG_APDS9306_IS_APDS9306_065=y

# Display RST is connected to NFC GPIO
CONFIG_NFCT_PINS_AS_GPIOS=y

Expand Down
20 changes: 18 additions & 2 deletions app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ CONFIG_SOC_SERIES_NRF53X=y
CONFIG_SOC_NRF5340_CPUAPP_QKAA=y
CONFIG_BOARD_ZSWATCH_NRF5340_CPUAPP=y

CONFIG_ZBUS=y
CONFIG_ZBUS_RUNTIME_OBSERVERS=y
CONFIG_ZBUS_CHANNEL_NAME=y
CONFIG_ZBUS_OBSERVER_NAME=y

CONFIG_SENSOR=y

CONFIG_INPUT=y

CONFIG_DISPLAY=y

# Enable MPU
CONFIG_ARM_MPU=y

Expand All @@ -13,8 +24,11 @@ CONFIG_HW_STACK_PROTECTION=y
# Enable TrustZone-M
CONFIG_ARM_TRUSTZONE_M=y

# Enable GPIO
CONFIG_GPIO=y
CONFIG_I2C=y
CONFIG_ADC=y
CONFIG_PWM=y
CONFIG_SPI=y

# Enable console
CONFIG_CONSOLE=y
Expand All @@ -27,4 +41,6 @@ CONFIG_PINCTRL=y

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
# Ensure GPIO P0.01 and P0.00 can be used
CONFIG_SOC_ENABLE_LFXO=n
CONFIG_SOC_ENABLE_LFXO=n

CONFIG_BMP581=y
3 changes: 2 additions & 1 deletion app/drivers/sensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
# -> target with the same name already exists. The existing target is a static...
#
add_subdirectory_ifdef(CONFIG_APDS9306 apds9306)
add_subdirectory_ifdef(CONFIG_BME68X_IAQ bme68x_iaq)
add_subdirectory_ifdef(CONFIG_BME68X_IAQ bme68x_iaq)
add_subdirectory_ifdef(CONFIG_BMP581 bmp581)
1 change: 1 addition & 0 deletions app/drivers/sensor/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if SENSOR
rsource "apds9306/Kconfig"
rsource "bme68x_iaq/Kconfig"
rsource "bmp581/Kconfig"
endif
2 changes: 1 addition & 1 deletion app/drivers/sensor/apds9306/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ menuconfig APDS9306
#depends on DT_HAS_AVAGO_APDS9306_ENABLED
select I2C
help
Enable the driver for the APDS9306 digital light sensor.
Enable the driver for the APDS9306 digital light sensor.

if APDS9306
config APDS9306_IS_APDS9306_065
Expand Down
100 changes: 50 additions & 50 deletions app/drivers/sensor/apds9306/apds9306.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
#define APDS9306_BIT_POWER_ON_STATUS BIT(0x05)

#ifdef CONFIG_APDS9306_IS_APDS9306_065
#define APDS_9306_CHIP_ID 0xB3
#define APDS_9306_CHIP_ID 0xB3
#else
#define APDS_9306_CHIP_ID 0xB1
#define APDS_9306_CHIP_ID 0xB1
#endif

#define DT_DRV_COMPAT avago_apds9306

LOG_MODULE_REGISTER(apds9306, CONFIG_SENSOR_LOG_LEVEL);

#if(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0)
Expand All @@ -73,7 +75,7 @@ struct sensor_worker_item_t {
const struct device *dev;
} apds9306_worker_item;

uint32_t apds9306_last_measurement;
static struct apds9306_data last_measurement;

/** @brief Get the conversion time for a given sensor resolution.
* @param value Sensor resolution
Expand Down Expand Up @@ -163,6 +165,48 @@ static int apds9306_attr_set(const struct device *p_dev, enum sensor_channel cha
return 0;
}

/** @brief
* @param
* @return
*/
static int apds9306_attr_get(const struct device *p_dev, enum sensor_channel channel, enum sensor_attribute attribute,
struct sensor_value *p_value)
{
uint8_t mask;
uint8_t value;
uint8_t reg;
const struct apds9306_config *config = p_dev->config;

__ASSERT_NO_MSG(p_value != NULL);

if (channel != SENSOR_CHAN_LIGHT) {
return -ENOTSUP;
}

if (attribute == SENSOR_ATTR_SAMPLING_FREQUENCY) {
reg = APDS9306_REGISTER_ALS_MEAS_RATE;
mask = 0x00;
} else if (attribute == SENSOR_APDS9306_ATTR_GAIN) {
reg = APDS9306_REGISTER_ALS_GAIN;
mask = 0x00;
} else if (attribute == SENSOR_APDS9306_ATTR_RESOLUTION) {
reg = APDS9306_REGISTER_ALS_MEAS_RATE;
mask = 0x04;
} else {
return -ENOTSUP;
}

if (i2c_reg_read_byte_dt(&config->i2c, reg, &value)) {
LOG_ERR("Failed to read sensor attribute!");
return -EIO;
}

p_value->val1 = (value >> mask) & 0x07;
p_value->val2 = 0;

return 0;
}

/** @brief Sensor worker handler.
* @param p_work Pointer to worker object
*/
Expand Down Expand Up @@ -225,57 +269,13 @@ static void apds9306_worker(struct k_work *p_work)
return;
}

apds9306_last_measurement = sys_get_le24(buffer);
last_measurement.light = sys_get_le24(buffer);

LOG_DBG("Last measurement: %u", apds9306_last_measurement);
LOG_DBG("Last measurement: %u", last_measurement.light);

return;
}

/** @brief
* @param
* @return
*/
static int apds9306_attr_get(const struct device *p_dev, enum sensor_channel channel, enum sensor_attribute attribute,
struct sensor_value *p_value)
{
uint8_t mask;
uint8_t value;
uint8_t reg;
const struct apds9306_config *config = p_dev->config;

__ASSERT_NO_MSG(p_value != NULL);

if (channel != SENSOR_CHAN_LIGHT) {
return -ENOTSUP;
}

if (attribute == SENSOR_ATTR_SAMPLING_FREQUENCY) {
reg = APDS9306_REGISTER_ALS_MEAS_RATE;
mask = 0x00;
} else if (attribute == SENSOR_APDS9306_ATTR_GAIN) {
reg = APDS9306_REGISTER_ALS_GAIN;
mask = 0x00;
} else if (attribute == SENSOR_APDS9306_ATTR_RESOLUTION) {
reg = APDS9306_REGISTER_ALS_MEAS_RATE;
mask = 0x04;
} else {
return -ENOTSUP;
}

if (i2c_reg_read_byte_dt(&config->i2c, reg, &value)) {
LOG_ERR("Failed to read sensor attribute!");
return -EIO;
}

LOG_DBG("Attribute value: %u", value);

p_value->val1 = (value >> mask) & 0x07;
p_value->val2 = 0;

return 0;
}

/** @brief
* @param
* @return
Expand Down Expand Up @@ -312,7 +312,7 @@ static int apds9306_channel_get(const struct device *p_dev, enum sensor_channel

// TODO: Conversion to lux is missing here

p_value->val1 = apds9306_last_measurement;
p_value->val1 = last_measurement.light;
p_value->val2 = 0;

return 0;
Expand Down
2 changes: 0 additions & 2 deletions app/drivers/sensor/apds9306/apds9306.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#include <zephyr/drivers/sensor.h>

#define DT_DRV_COMPAT avago_apds9306

/** @brief Attribute to set the gain range.
*/
#define SENSOR_APDS9306_ATTR_GAIN SENSOR_ATTR_PRIV_START + 1
Expand Down
12 changes: 12 additions & 0 deletions app/drivers/sensor/bmp581/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2023, Daniel Kampert
#
# SPDX-License-Identifier: Apache-2.0
#

# TODO: Doesn´t work with CMakeList.txt of the drivers directory -> Check it
#zephyr_library()

zephyr_library_include_directories(${PROJECT_SOURCE_DIR}/src/ext_drivers/BMP5-Sensor-API)
zephyr_sources(${PROJECT_SOURCE_DIR}/src/ext_drivers/BMP5-Sensor-API/bmp5.c)

zephyr_sources(bmp581.c)
16 changes: 16 additions & 0 deletions app/drivers/sensor/bmp581/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# APDS-9306 light sensor configuration options.

# Copyright (c) 2023, Daniel Kampert
#
# SPDX-License-Identifier: Apache-2.0

menuconfig BMP581
bool "BMP581 Sensor"
default y
select I2C
help
Enable the driver for the BMP581 pressure sensor.

if BMP581

endif
Loading

0 comments on commit 9eb7b8f

Please sign in to comment.