Skip to content
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
1 change: 1 addition & 0 deletions boards/tfh/diamond_main/diamond_main.dts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
user-led0-3v3-gpios = <&gpio_exp2 0 GPIO_ACTIVE_LOW>;
user-led1-3v3-gpios = <&gpio_exp2 1 GPIO_ACTIVE_LOW>;

power-supply-connected-gpios = <&gpio_exp_pwr_brd 0 GPIO_ACTIVE_HIGH>;
supply-3v3-ssd-enable-gpios = <&gpio_exp_pwr_brd 2 GPIO_ACTIVE_HIGH>;
supply-3v3-wifi-enable-gpios = <&gpio_exp1 10 GPIO_ACTIVE_HIGH>;
supply-5v-enable-gpios = <&gpio_exp_pwr_brd 1 GPIO_ACTIVE_LOW>;
Expand Down
31 changes: 31 additions & 0 deletions main_board/src/power/battery/battery_amber.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "ui/rgb_leds/operator_leds/operator_leds.h"
#include "utils.h"
#include "voltage_measurement/voltage_measurement.h"
#include "zephyr/drivers/gpio.h"

#include <app_assert.h>
#include <stdlib.h>
#include <zephyr/device.h>
Expand Down Expand Up @@ -38,6 +40,8 @@ static struct k_thread rx_thread_data = {0};

static const struct i2c_dt_spec i2c_device_spec =
I2C_DT_SPEC_GET(DT_NODELABEL(bq4050));
static const struct gpio_dt_spec power_connected_gpio_spec =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), power_supply_connected_gpios);

static orb_mcu_main_BatteryCapacity battery_cap;
static orb_mcu_main_BatteryIsCharging is_charging;
Expand Down Expand Up @@ -377,10 +381,37 @@ battery_rx_thread()
uint32_t battery_messages_timeout = 0;
int shutdown_scheduled_sent = RET_ERROR_NOT_INITIALIZED;

static const struct gpio_dt_spec supply_vbat_sw_enable_gpio_spec =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), supply_vbat_sw_enable_gpios);
gpio_pin_configure_dt(&power_connected_gpio_spec, GPIO_INPUT);

while (1) {
uint32_t got_battery_voltage_message_local_counter = 0;
int ret;

ret = gpio_pin_get_dt(&power_connected_gpio_spec);
if (ret < 0) {
ASSERT_SOFT(ret);
} else {
if (ret == 0) {
LOG_WRN("Battery disconnected");

// turn off vbat_sw
gpio_pin_set_dt(&supply_vbat_sw_enable_gpio_spec, 0);

while (gpio_pin_get_dt(&power_connected_gpio_spec) != 1) {
k_usleep(500);
}

ret = gpio_pin_set_dt(&supply_vbat_sw_enable_gpio_spec, 1);
ASSERT_SOFT(ret);

LOG_WRN("Battery reconnected");
} else {
LOG_WRN("battery connected");
}
}

// The following sections are placed in {}-scopes because then the
// memory of the local variables can be reused by the subsequent code.
{
Expand Down