Skip to content

Commit

Permalink
feat(als): add support for bh1730
Browse files Browse the repository at this point in the history
mark data with a flag when LED in shroud are turned on, as they are
interfering with the ALS measurement.

Signed-off-by: Cyril Fougeray <[email protected]>
  • Loading branch information
fouge committed Jan 31, 2025
1 parent 13f8c3a commit 6db7862
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
6 changes: 3 additions & 3 deletions boards/tfh/diamond_main/diamond_main.dts
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@
#address-cells = <1>;
#size-cells = <0>;

front_unit_als: bu27030@38 {
compatible = "rohm,bu27030";
front_unit_als: bh1750@29 {
compatible = "rohm,bh1750";
status = "okay";
reg = <0x38>;
reg = <0x29>;
};

front_unit_tmp_sensor_shroud_rgb_top: tmp112@48 {
Expand Down
3 changes: 3 additions & 0 deletions main_board/boards/pearl_main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ CONFIG_CAN_ACCEPT_RTR=y
# LED Strips
CONFIG_LED_STRIP=y
CONFIG_WS2812_PWM_STM32=y

# ALS
CONFIG_BU27030=y
3 changes: 0 additions & 3 deletions main_board/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ CONFIG_ORB_LIB_THREAD_PRIORITY_CANBUS_TX=5
CONFIG_ORB_LIB_THREAD_PRIORITY_DFU=8
CONFIG_ORB_LIB_THREAD_STACK_SIZE_DFU=2048

# ALS
CONFIG_BU27030=y

# DMA
CONFIG_DMA=y
CONFIG_DMA_STM32=y
Expand Down
15 changes: 14 additions & 1 deletion main_board/src/ui/ambient_light/als.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "pubsub/pubsub.h"
#include "system/diag.h"
#include <errors.h>
#include <ui/rgb_leds/front_leds/front_leds.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/kernel.h>

Expand All @@ -28,6 +29,19 @@ als_thread()
k_msleep(1000);

if (k_mutex_lock(als_i2c_mux_mutex, K_MSEC(100)) == 0) {
als.flag = orb_mcu_main_AmbientLight_Flags_ALS_OK;

#if defined(CONFIG_BOARD_DIAMOND_MAIN)
// on Diamond EVT, ALS sensor is located on the front unit, close
// to the front LEDs and interferes with the ALS readings.
// Make sure to mark the ALS reading as invalid if the front LEDs
// are on.
if (front_leds_is_shroud_on()) {
als.flag =
orb_mcu_main_AmbientLight_Flags_ALS_ERR_LEDS_INTERFERENCE;
}
#endif

ret = sensor_sample_fetch_chan(als_device, SENSOR_CHAN_LIGHT);
k_mutex_unlock(als_i2c_mux_mutex);
if (ret != 0) {
Expand All @@ -43,7 +57,6 @@ als_thread()
continue;
} else {
als.ambient_light_lux = als_value.val1;
als.flag = orb_mcu_main_AmbientLight_Flags_ALS_OK;
}

LOG_INF("Ambient light: %s %u.%06u",
Expand Down
24 changes: 24 additions & 0 deletions main_board/src/ui/rgb_leds/front_leds/front_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,30 @@ update_parameters(orb_mcu_main_UserLEDsPattern_UserRgbLedPattern pattern,
CRITICAL_SECTION_EXIT(k);
}

#if defined(CONFIG_BOARD_DIAMOND_MAIN)
bool
front_leds_is_shroud_on(void)
{
if (k_sem_take(&leds_update_sem, K_MSEC(1)) == 0) {
for (size_t i = 0; i < ARRAY_SIZE(leds.part.center_leds); ++i) {
if (leds.part.center_leds[i].scratch != 0 &&
(leds.part.center_leds[i].r != 0 ||
leds.part.center_leds[i].g != 0 ||
leds.part.center_leds[i].b != 0)) {
k_sem_give(&leds_update_sem);
return true;
}
}
} else {
return true;
}

k_sem_give(&leds_update_sem);

return false;
}
#endif

ret_code_t
front_leds_set_pattern(orb_mcu_main_UserLEDsPattern_UserRgbLedPattern pattern,
uint32_t start_angle, int32_t angle_length,
Expand Down
9 changes: 9 additions & 0 deletions main_board/src/ui/rgb_leds/front_leds/front_leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
ret_code_t
front_leds_init(void);

/**
* Check the LED array for any non-zero LED in the shroud
* If the semaphore is not available, shroud is assumed to be on.
*
* @return true if at least one led is on in the shroud
*/
bool
front_leds_is_shroud_on(void);

/**
* @brief Set pattern for front LEDs
* Some arguments are optional because they are not used by some patterns.
Expand Down

0 comments on commit 6db7862

Please sign in to comment.