Skip to content

Commit

Permalink
Merge branch 'main' into fouge/memfault
Browse files Browse the repository at this point in the history
  • Loading branch information
fouge authored May 14, 2024
2 parents c49e16a + 5df6cec commit 4e32729
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 15 deletions.
12 changes: 9 additions & 3 deletions boards/arm/diamond_main/diamond_main.dts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@
supply-super-cap-enable-gpios = <&gpio_exp_pwr_brd 6 GPIO_ACTIVE_HIGH>;
supply-vbat-sw-enable-gpios = <&gpio_exp_pwr_brd 12 GPIO_ACTIVE_HIGH>;
front-unit-pvcc-enabled-gpios = <&gpio_exp_front_unit 0 GPIO_ACTIVE_HIGH>;
front-unit-fuse-reset-gpios = <&gpio_exp_front_unit 2 GPIO_ACTIVE_LOW>;
front-unit-fuse-active-gpios = <&gpio_exp_front_unit 6 GPIO_ACTIVE_LOW>;

// The signals FUSE_RST and FUSE_ACTIVE are available only on Front Unit 6.0 (PoC1) and 6.1 (PoC2)
// On Front Unit 6.2 (B3) the signal EN_5V_SWITCHED is connected to the port expander pin P02 instead.
front-unit-fuse-reset-gpios = <&gpio_exp_front_unit 2 GPIO_ACTIVE_LOW>; // PoC1 & PoC2 only
front-unit-fuse-active-gpios = <&gpio_exp_front_unit 6 GPIO_ACTIVE_LOW>; // PoC1 & PoC2 only
front-unit-en-5v-switched-gpios = <&gpio_exp_front_unit 2 GPIO_ACTIVE_HIGH>; // B3 only

supply-12v-caps-enable-gpios = <&gpio_exp_pwr_brd 4 GPIO_ACTIVE_LOW>;
supply-5v-rgb-enable-gpios = <&gpio_exp1 2 GPIO_ACTIVE_HIGH>;
Expand All @@ -93,6 +97,8 @@
cone-button-gpios = <&gpio_exp_cone 12 GPIO_ACTIVE_LOW>;
cone-5v-enable-gpios = <&gpio_exp_cone 0 GPIO_ACTIVE_HIGH>;

usb-hub-reset-gpios = <&gpio_exp2 2 GPIO_ACTIVE_LOW>;

// Voltage at VREF+ pin of STM32
vref-mv = <2048>;
};
Expand Down Expand Up @@ -464,7 +470,7 @@
// not actually used by the SPI driver
duplex = <SPI_HALF_DUPLEX>;

num-leds = <99>;
num-leds = <136>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/led_strip/Kconfig.spi_rgb_led
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ config SPI_RGB_LED_DIMMING
config SPI_RGB_LED_BUFFER_SIZE
int "Size of SPI RGB LED buffer"
depends on SPI_RGB_LED
default 396
default 544
help
Size of the SPI RGB LED buffer in bytes. This is the maximum
number of bytes that can be sent to the LED strip in one go.
Expand Down
41 changes: 34 additions & 7 deletions main_board/src/optics/ir_camera_system/ir_camera_system_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "optics/1d_tof/tof_1d.h"
#include "optics/liquid_lens/liquid_lens.h"
#include "optics/mirror/mirror.h"
#include "system/version/version.h"
#include "ui/rgb_leds/front_leds/front_leds.h"
#include <app_assert.h>
#include <app_config.h>
Expand Down Expand Up @@ -1031,6 +1032,7 @@ ir_camera_system_get_time_until_update_us_internal(void)
}

#if defined(CONFIG_BOARD_DIAMOND_MAIN)
// Fuse available on Front Unit versions 6.0 and 6.1 only!
static ret_code_t
reset_fuse(void)
{
Expand All @@ -1047,15 +1049,15 @@ reset_fuse(void)
return RET_ERROR_INTERNAL;
}

err_code = gpio_pin_configure_dt(&fuse_reset, GPIO_OUTPUT_INACTIVE);
if (err_code) {
ASSERT_SOFT(err_code);
return RET_ERROR_INTERNAL;
}

if (gpio_pin_get_dt(&fuse_active) == 0) {
LOG_WRN("Resetting blown fuse");

err_code = gpio_pin_configure_dt(&fuse_reset, GPIO_OUTPUT_INACTIVE);
if (err_code) {
ASSERT_SOFT(err_code);
return RET_ERROR_INTERNAL;
}

err_code = gpio_pin_set_dt(&fuse_reset, 1);
if (err_code) {
ASSERT_SOFT(err_code);
Expand All @@ -1072,6 +1074,24 @@ reset_fuse(void)

return RET_SUCCESS;
}

// 5V switch not available on Front Unit versions 6.0 and 6.1!
static ret_code_t
enable_5v_switched(void)
{
int err_code;

const struct gpio_dt_spec en_5v_switched =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), front_unit_en_5v_switched_gpios);

err_code = gpio_pin_configure_dt(&en_5v_switched, GPIO_OUTPUT_ACTIVE);
if (err_code) {
ASSERT_SOFT(err_code);
return RET_ERROR_INTERNAL;
}

return RET_SUCCESS;
}
#endif

ret_code_t
Expand Down Expand Up @@ -1213,7 +1233,14 @@ ir_camera_system_hw_init(void)
#endif

#if defined(CONFIG_BOARD_DIAMOND_MAIN)
reset_fuse();
Hardware_OrbVersion version = version_get_hardware_rev();

if (version == Hardware_OrbVersion_HW_VERSION_DIAMOND_POC1 ||
version == Hardware_OrbVersion_HW_VERSION_DIAMOND_POC2) {
reset_fuse();
} else {
enable_5v_switched();
}
#endif

return RET_SUCCESS;
Expand Down
35 changes: 35 additions & 0 deletions main_board/src/power/battery/battery_amber.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static_assert(
#define BQ4050_CMD_CYCLE_COUNT 0x17
#define BQ4050_CMD_SERIAL_NUMBER 0x1C
#define BQ4050_CMD_MANUFACTURER_BLOCK_ACCESS 0x44
#define BQ4050_CMD_STATE_OF_HEALTH 0x4F

#define BQ4050_BLK_CMD_FIRMWARE_VERSION 0x0002
#define BQ4050_BLK_CMD_LIFETIME_DATA_1 0x0060
Expand Down Expand Up @@ -256,6 +257,24 @@ bq4050_read_serial_number(uint16_t *serial_number)
}
}

static ret_code_t
bq4050_read_state_of_health(uint8_t *state_of_health_percentage)
{
if (state_of_health_percentage == NULL) {
return RET_ERROR_INVALID_PARAM;
}

uint16_t word = 0;
int ret = bq4050_read_word(BQ4050_CMD_STATE_OF_HEALTH, &word);

if (ret == 0) {
*state_of_health_percentage = (uint8_t)word;
return RET_SUCCESS;
} else {
return RET_ERROR_INTERNAL;
}
}

static void
publish_battery_voltages(BatteryVoltage *voltages)
{
Expand Down Expand Up @@ -560,6 +579,22 @@ battery_rx_thread()
}
}

{
uint8_t state_of_health_percentage;
ret = bq4050_read_state_of_health(&state_of_health_percentage);

if (ret == 0) {
LOG_DBG("Battery SoH: %d %%", state_of_health_percentage);

BatteryStateOfHealth state_of_health = {0};
state_of_health.percentage = state_of_health_percentage;

publish_new(&state_of_health, sizeof(state_of_health),
McuToJetson_battery_state_of_health_tag,
CONFIG_CAN_ADDRESS_DEFAULT_REMOTE);
}
}

if (!dev_mode) {
// check that we are still receiving messages from the battery
// and consider the battery as removed if no message
Expand Down
16 changes: 15 additions & 1 deletion main_board/src/power/boot/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ static const struct gpio_dt_spec supply_3v6_enable_gpio_spec =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), supply_3v6_enable_gpios);
static const struct gpio_dt_spec supply_5v_rgb_enable_gpio_spec =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), supply_5v_rgb_enable_gpios);

static const struct gpio_dt_spec usb_hub_reset_gpio_spec =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), usb_hub_reset_gpios);
#endif

K_SEM_DEFINE(sem_reboot, 0, 1);
Expand Down Expand Up @@ -265,7 +268,8 @@ power_configure_gpios(void)
!device_is_ready(supply_1v2_enable_gpio_spec.port) ||
!device_is_ready(supply_2v8_enable_gpio_spec.port) ||
!device_is_ready(supply_3v6_enable_gpio_spec.port) ||
!device_is_ready(supply_5v_rgb_enable_gpio_spec.port)) {
!device_is_ready(supply_5v_rgb_enable_gpio_spec.port) ||
!device_is_ready(usb_hub_reset_gpio_spec.port)) {
return RET_ERROR_INTERNAL;
}

Expand Down Expand Up @@ -310,6 +314,13 @@ power_configure_gpios(void)
ASSERT_SOFT(ret);
return RET_ERROR_INTERNAL;
}

ret = gpio_pin_configure_dt(&usb_hub_reset_gpio_spec,
GPIO_OUTPUT_ACTIVE);
if (ret != 0) {
ASSERT_SOFT(ret);
return RET_ERROR_INTERNAL;
}
#endif

return RET_SUCCESS;
Expand Down Expand Up @@ -784,6 +795,9 @@ boot_turn_on_jetson(void)
#if defined(CONFIG_BOARD_PEARL_MAIN)
LOG_INF("Enabling LTE, GPS, and USB");
gpio_pin_set_dt(&lte_gps_usb_reset_gpio_spec, 0);
#elif defined(CONFIG_BOARD_DIAMOND_MAIN)
LOG_INF("Enabling USB");
gpio_pin_set_dt(&usb_hub_reset_gpio_spec, 0);
#endif

shutdown_req_init();
Expand Down
3 changes: 3 additions & 0 deletions main_board/src/pubsub/pubsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const struct sub_message_s sub_prios[] = {
[McuToJetson_battery_info_max_values_tag] = {.priority = SUB_PRIO_STORE},
[McuToJetson_battery_info_soc_and_statistics_tag] = {.priority =
SUB_PRIO_STORE},
[McuToJetson_cone_present_tag] = {.priority = SUB_PRIO_DISCARD},
[McuToJetson_memfault_event_tag] = {.priority = SUB_PRIO_DISCARD},
[McuToJetson_battery_state_of_health_tag] = {.priority = SUB_PRIO_DISCARD},
};

/* ISO-TP addresses + one CAN-FD address */
Expand Down
7 changes: 4 additions & 3 deletions main_board/src/ui/rgb_leds/front_leds/front_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ static const struct device *const led_strip =
#define NUM_LEDS DT_PROP(DT_NODELABEL(front_unit_rgb_leds), num_leds)
#if defined(CONFIG_BOARD_PEARL_MAIN)
#define NUM_CENTER_LEDS 9
#define INDEX_RING_ZERO ((NUM_RING_LEDS * 3 / 4))
#define INDEX_RING_ZERO ((NUM_RING_LEDS * 3 / 4)) // 0º is at the 3 o'clock position
// Maximum amount of time for LED strip update
// It's also the minimum amount of time we need to trigger
// an LED strip update until the next IR LED pulse
#define LED_STRIP_MAXIMUM_UPDATE_TIME_US 10000
#else
#define NUM_CENTER_LEDS 23
#define INDEX_RING_ZERO 19 // 0º is at 19th LED
#define NUM_CENTER_LEDS 64
// 0º (3 o'clock position) is at 53rd LED on Front Unit 6.2
#define INDEX_RING_ZERO 53
#endif
#define NUM_RING_LEDS (NUM_LEDS - NUM_CENTER_LEDS)

Expand Down

0 comments on commit 4e32729

Please sign in to comment.