Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(als): add support for bh1730 #150

Draft
wants to merge 1 commit into
base: fouge/zephyr-4.0.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ manifest:
remote: memfault
revision: 1.19.0
- name: orb-messages
revision: 62bb55b26f162eefcf7ab1c6075d7aa3969cf386
revision: bb6d1844d7561e4832ef170a3c9be67ba0ed61a0
path: modules/orb-messages/public
- name: priv-orb-messages
revision: 814f52429ced94c8180f3fbe17eeec1f1a01b556
Expand Down