From 15ff386d03a43882b75ab768cf24f22a7fe6b627 Mon Sep 17 00:00:00 2001 From: Daniel Kampert Date: Sun, 8 Oct 2023 18:52:56 +0200 Subject: [PATCH] - Enable default applications in Kconfig - Convert tabs to spaces - Fix typo `yn` in project Kconfig --- app/Kconfig | 6 +- app/drivers/sensor/apds9306/Kconfig | 20 +-- app/drivers/sensor/apds9306/apds9306.c | 214 ++++++++++++------------- 3 files changed, 120 insertions(+), 120 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 382ac7c8..e5bf7281 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -7,7 +7,7 @@ menu "ZSWatch" config APPLICATIONS_USE_2048 bool prompt "Activate the application '2048'" - default ny + default y config APPLICATIONS_USE_ACCELEROMETER bool @@ -32,12 +32,12 @@ menu "ZSWatch" config APPLICATIONS_USE_QR_CODE bool prompt "Activate the application 'QR-Code'" - default y + default n config APPLICATIONS_USE_X_RAY bool prompt "Activate the application 'X-Ray'" - default y + default n config APPLICATIONS_USE_ZDS bool diff --git a/app/drivers/sensor/apds9306/Kconfig b/app/drivers/sensor/apds9306/Kconfig index 8d520094..150b09c0 100644 --- a/app/drivers/sensor/apds9306/Kconfig +++ b/app/drivers/sensor/apds9306/Kconfig @@ -5,17 +5,17 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig APDS9306 - bool "APDS9306 Sensor" - default y - # TODO - #depends on DT_HAS_AVAGO_APDS9306_ENABLED - select I2C - help - Enable the driver for the APDS9306 digital light sensor. + bool "APDS9306 Sensor" + default y + # TODO + #depends on DT_HAS_AVAGO_APDS9306_ENABLED + select I2C + help + Enable the driver for the APDS9306 digital light sensor. if APDS9306 - config APDS9306_IS_APDS9306_065 - bool "Enable this option if you are using the APDS-9306-065" - default n + config APDS9306_IS_APDS9306_065 + bool "Enable this option if you are using the APDS-9306-065" + default n endif \ No newline at end of file diff --git a/app/drivers/sensor/apds9306/apds9306.c b/app/drivers/sensor/apds9306/apds9306.c index d7959177..c446b4be 100644 --- a/app/drivers/sensor/apds9306/apds9306.c +++ b/app/drivers/sensor/apds9306/apds9306.c @@ -57,15 +57,15 @@ LOG_MODULE_REGISTER(apds9306, CONFIG_SENSOR_LOG_LEVEL); #endif struct apds9306_data { - uint32_t light; + uint32_t light; }; struct apds9306_config { - struct i2c_dt_spec i2c; + struct i2c_dt_spec i2c; uint8_t Resolution; uint8_t Rate; uint8_t Gain; -}; +}; /** @brief Enable the ALS measurement. * @param p_Dev Pointer to sensor device @@ -73,12 +73,12 @@ struct apds9306_config { */ static int apds9306_enable(const struct device* p_Dev) { - const struct apds9306_config* Config = p_Dev->config; + const struct apds9306_config* Config = p_Dev->config; - if(i2c_reg_update_byte_dt(&Config->i2c, APDS9306_REGISTER_MAIN_CTRL, ADPS9306_BIT_ALS_EN, ADPS9306_BIT_ALS_EN)) + if(i2c_reg_update_byte_dt(&Config->i2c, APDS9306_REGISTER_MAIN_CTRL, ADPS9306_BIT_ALS_EN, ADPS9306_BIT_ALS_EN)) { - return -EIO; - } + return -EIO; + } return 0; } @@ -89,13 +89,13 @@ static int apds9306_enable(const struct device* p_Dev) */ static int apds9306_standby(const struct device* p_Dev) { - const struct apds9306_config* Config = p_Dev->config; + const struct apds9306_config* Config = p_Dev->config; - if(i2c_reg_update_byte_dt(&Config->i2c, APDS9306_REGISTER_MAIN_CTRL, ADPS9306_BIT_ALS_EN, 0x00)) + if(i2c_reg_update_byte_dt(&Config->i2c, APDS9306_REGISTER_MAIN_CTRL, ADPS9306_BIT_ALS_EN, 0x00)) { - LOG_ERR("Can not disable ALS!"); - return -EIO; - } + LOG_ERR("Can not disable ALS!"); + return -EIO; + } return 0; } @@ -107,9 +107,9 @@ static int apds9306_standby(const struct device* p_Dev) */ static int apds9306_read_light(const struct device* p_Dev, uint32_t* p_Value) { - int Error; - const struct apds9306_config* Config = p_Dev->config; - uint8_t Buffer[3]; + int Error; + const struct apds9306_config* Config = p_Dev->config; + uint8_t Buffer[3]; uint8_t Temp; uint8_t Register = APDS9306_REGISTER_ALS_DATA_0; uint32_t Now; @@ -117,8 +117,8 @@ static int apds9306_read_light(const struct device* p_Dev, uint32_t* p_Value) LOG_DBG("Start a new measurement..."); if(apds9306_enable(p_Dev) != 0) { - LOG_ERR("Can not enable ALS!"); - return -EIO; + LOG_ERR("Can not enable ALS!"); + return -EIO; } // Wait for the oscillator power up. This needs typically 5 ms, but we wait a bit longer to be sure. @@ -147,20 +147,20 @@ static int apds9306_read_light(const struct device* p_Dev, uint32_t* p_Value) if(apds9306_standby(p_Dev) != 0) { - LOG_ERR("Can not disable ALS!"); - return -EIO; + LOG_ERR("Can not disable ALS!"); + return -EIO; } // Read the results. - Error = i2c_write_read_dt(&Config->i2c, &Register, sizeof(Register), &Buffer, sizeof(Buffer)); - if(Error < 0) + Error = i2c_write_read_dt(&Config->i2c, &Register, sizeof(Register), &Buffer, sizeof(Buffer)); + if(Error < 0) { - return Error; - } + return Error; + } *p_Value = sys_get_le24(Buffer); - return 0; + return 0; } static int apds9306_attr_set(const struct device* p_Dev, enum sensor_channel Channel, enum sensor_attribute Attribute, const struct sensor_value* p_Value) @@ -168,16 +168,16 @@ static int apds9306_attr_set(const struct device* p_Dev, enum sensor_channel Cha uint8_t Mask; uint8_t Value; uint8_t Register; - const struct apds9306_config* Config = p_Dev->config; + const struct apds9306_config* Config = p_Dev->config; - __ASSERT_NO_MSG(p_Value != NULL); + __ASSERT_NO_MSG(p_Value != NULL); - if(Channel != SENSOR_CHAN_LIGHT) + if(Channel != SENSOR_CHAN_LIGHT) { - return -ENOTSUP; - } + return -ENOTSUP; + } - if(Attribute == SENSOR_ATTR_SAMPLING_FREQUENCY) + if(Attribute == SENSOR_ATTR_SAMPLING_FREQUENCY) { Register = APDS9306_REGISTER_ALS_MEAS_RATE; Mask = (0x07) << 0x00; @@ -200,13 +200,13 @@ static int apds9306_attr_set(const struct device* p_Dev, enum sensor_channel Cha return -ENOTSUP; } - if(i2c_reg_update_byte_dt(&Config->i2c, Register, Mask, Value)) + if(i2c_reg_update_byte_dt(&Config->i2c, Register, Mask, Value)) { - LOG_ERR("Failed to set sensor attribute!"); - return -EIO; - } + LOG_ERR("Failed to set sensor attribute!"); + return -EIO; + } - return 0; + return 0; } static int apds9306_attr_get(const struct device* p_Dev, enum sensor_channel Channel, enum sensor_attribute Attribute, struct sensor_value* p_Value) @@ -214,16 +214,16 @@ static int apds9306_attr_get(const struct device* p_Dev, enum sensor_channel Cha uint8_t Mask; uint8_t Value; uint8_t Register; - const struct apds9306_config* Config = p_Dev->config; + const struct apds9306_config* Config = p_Dev->config; - __ASSERT_NO_MSG(p_Value != NULL); + __ASSERT_NO_MSG(p_Value != NULL); - if(Channel != SENSOR_CHAN_LIGHT) + if(Channel != SENSOR_CHAN_LIGHT) { - return -ENOTSUP; - } + return -ENOTSUP; + } - if(Attribute == SENSOR_ATTR_SAMPLING_FREQUENCY) + if(Attribute == SENSOR_ATTR_SAMPLING_FREQUENCY) { Register = APDS9306_REGISTER_ALS_MEAS_RATE; Mask = 0x00; @@ -243,37 +243,37 @@ static int apds9306_attr_get(const struct device* p_Dev, enum sensor_channel Cha return -ENOTSUP; } - if(i2c_reg_read_byte_dt(&Config->i2c, Register, &Value)) + if(i2c_reg_read_byte_dt(&Config->i2c, Register, &Value)) { - LOG_ERR("Failed to read sensor attribute!"); - return -EIO; - } + 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; + return 0; } static int apds9306_sample_fetch(const struct device* p_Dev, enum sensor_channel Channel) { int Error; uint32_t Value; - struct apds9306_data* Data = p_Dev->data; - enum pm_device_state pm_state; + struct apds9306_data* Data = p_Dev->data; + enum pm_device_state pm_state; - (void)pm_device_state_get(p_Dev, &pm_state); - if(pm_state != PM_DEVICE_STATE_ACTIVE) + (void)pm_device_state_get(p_Dev, &pm_state); + if(pm_state != PM_DEVICE_STATE_ACTIVE) { - return -EIO; - } + return -EIO; + } - if((Channel != SENSOR_CHAN_ALL) && (Channel != SENSOR_CHAN_LIGHT)) + if((Channel != SENSOR_CHAN_ALL) && (Channel != SENSOR_CHAN_LIGHT)) { - return -ENOTSUP; - } + return -ENOTSUP; + } Error = apds9306_read_light(p_Dev, &Value); if(Error < 0) @@ -285,14 +285,14 @@ static int apds9306_sample_fetch(const struct device* p_Dev, enum sensor_channel LOG_DBG("Sensor value: %u", Data->light); - return 0; + return 0; } static int apds9306_channel_get(const struct device* p_Dev, enum sensor_channel Channel, struct sensor_value* p_Value) { - struct apds9306_data* Data = p_Dev->data; + struct apds9306_data* Data = p_Dev->data; - switch(Channel) + switch(Channel) { case SENSOR_CHAN_LIGHT: { @@ -305,14 +305,14 @@ static int apds9306_channel_get(const struct device* p_Dev, enum sensor_channel { return -ENOTSUP; } - } + } } static int apds9306_sensor_setup(const struct device* p_Dev) { uint32_t Now; - uint8_t Temp; - const struct apds9306_config* Config = p_Dev->config; + uint8_t Temp; + const struct apds9306_config* Config = p_Dev->config; // Wait for the device to become ready after a power cycle. Now = k_uptime_get_32(); @@ -330,71 +330,71 @@ static int apds9306_sensor_setup(const struct device* p_Dev) k_msleep(10); } while(Temp & APDS9306_BIT_POWER_ON_STATUS); - if(i2c_reg_read_byte_dt(&Config->i2c, APDS9306_REGISTER_PART_ID, &Temp)) + if(i2c_reg_read_byte_dt(&Config->i2c, APDS9306_REGISTER_PART_ID, &Temp)) { - LOG_ERR("Failed reading chip id!"); - return -EIO; - } + LOG_ERR("Failed reading chip id!"); + return -EIO; + } - if(Temp != APDS_9306_CHIP_ID) + if(Temp != APDS_9306_CHIP_ID) { - LOG_ERR("Invalid chip id! Found 0x%X, expect 0x%X", Temp, APDS_9306_CHIP_ID); - return -EIO; - } + LOG_ERR("Invalid chip id! Found 0x%X, expect 0x%X", Temp, APDS_9306_CHIP_ID); + return -EIO; + } - // Reset the sensor. - if(i2c_reg_write_byte_dt(&Config->i2c, APDS9306_REGISTER_MAIN_CTRL, APDS9306_BIT_SW_RESET)) + // Reset the sensor. + if(i2c_reg_write_byte_dt(&Config->i2c, APDS9306_REGISTER_MAIN_CTRL, APDS9306_BIT_SW_RESET)) { - LOG_ERR("Can not reset the sensor!"); - return -EIO; - } + LOG_ERR("Can not reset the sensor!"); + return -EIO; + } k_msleep(10); - return 0; + return 0; } static int apds9306_interrupt_setup(const struct device* p_Dev) { // TODO - return 0; + return 0; } static const struct sensor_driver_api apds9306_driver_api = { .attr_set = apds9306_attr_set, - .attr_get = apds9306_attr_get, - .sample_fetch = apds9306_sample_fetch, - .channel_get = apds9306_channel_get, + .attr_get = apds9306_attr_get, + .sample_fetch = apds9306_sample_fetch, + .channel_get = apds9306_channel_get, }; static int apds9306_init(const struct device* p_Dev) { - const struct apds9306_config* Config = p_Dev->config; + const struct apds9306_config* Config = p_Dev->config; LOG_DBG("Start to initialize APDS9306..."); - if(device_is_ready(Config->i2c.bus) == false) + if(device_is_ready(Config->i2c.bus) == false) { - LOG_ERR("Bus device is not ready"); - return -EINVAL; - } + LOG_ERR("Bus device is not ready"); + return -EINVAL; + } - if(apds9306_sensor_setup(p_Dev) < 0) + if(apds9306_sensor_setup(p_Dev) < 0) { - LOG_ERR("Failed to setup device!"); - return -EIO; - } + LOG_ERR("Failed to setup device!"); + return -EIO; + } - if(apds9306_interrupt_setup(p_Dev) < 0) + if(apds9306_interrupt_setup(p_Dev) < 0) { - LOG_ERR("Failed to setup interrupts!"); - return -EIO; - } + LOG_ERR("Failed to setup interrupts!"); + return -EIO; + } LOG_DBG("APDS9306 initialization successful!"); - return 0; + return 0; } #ifdef CONFIG_PM_DEVICE @@ -420,19 +420,19 @@ static int apds9306_init(const struct device* p_Dev) #endif #define APDS9306_INIT(inst) \ - static struct apds9306_data apds9306_data_##inst; \ - \ - static const struct apds9306_config apds9306_config_##inst = { \ - .i2c = I2C_DT_SPEC_INST_GET(inst), \ - }; \ - \ - PM_DEVICE_DT_INST_DEFINE(inst, apds9306_pm_action); \ - \ - SENSOR_DEVICE_DT_INST_DEFINE(inst, apds9306_init, \ - PM_DEVICE_DT_INST_GET(inst), \ - &apds9306_data_##inst, \ - &apds9306_config_##inst, POST_KERNEL, \ - CONFIG_SENSOR_INIT_PRIORITY, \ - &apds9306_driver_api); + static struct apds9306_data apds9306_data_##inst; \ + \ + static const struct apds9306_config apds9306_config_##inst = { \ + .i2c = I2C_DT_SPEC_INST_GET(inst), \ + }; \ + \ + PM_DEVICE_DT_INST_DEFINE(inst, apds9306_pm_action); \ + \ + SENSOR_DEVICE_DT_INST_DEFINE(inst, apds9306_init, \ + PM_DEVICE_DT_INST_GET(inst), \ + &apds9306_data_##inst, \ + &apds9306_config_##inst, POST_KERNEL, \ + CONFIG_SENSOR_INIT_PRIORITY, \ + &apds9306_driver_api); DT_INST_FOREACH_STATUS_OKAY(APDS9306_INIT) \ No newline at end of file