Skip to content

Commit

Permalink
versions: diamond: read power board & front unit versions
Browse files Browse the repository at this point in the history
uses io expander on the boards
  • Loading branch information
fouge committed May 16, 2024
1 parent e28a4a9 commit 0c2090c
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 16 deletions.
4 changes: 3 additions & 1 deletion boards/arm/diamond_main/diamond_main.dts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
zephyr,user {
jetson_serial = <&usart1>;
// GPIO used to get hardware version dynamically
hw-version-gpios = <&gpio_exp2 8 GPIO_ACTIVE_HIGH>, <&gpio_exp2 9 GPIO_ACTIVE_HIGH>, <&gpio_exp2 10 GPIO_ACTIVE_HIGH>, <&gpio_exp2 11 GPIO_ACTIVE_HIGH>; // todo: replaced by digital configuration at IO expander; also add hw versions of Front Unit and Power Board
hw-version-main-board-gpios = <&gpio_exp2 8 GPIO_ACTIVE_HIGH>, <&gpio_exp2 9 GPIO_ACTIVE_HIGH>, <&gpio_exp2 10 GPIO_ACTIVE_HIGH>, <&gpio_exp2 11 GPIO_ACTIVE_HIGH>;
hw-version-front-unit-gpios = <&gpio_exp_front_unit 8 GPIO_ACTIVE_HIGH>, <&gpio_exp_front_unit 9 GPIO_ACTIVE_HIGH>, <&gpio_exp_front_unit 10 GPIO_ACTIVE_HIGH>, <&gpio_exp_front_unit 11 GPIO_ACTIVE_HIGH>;
hw-version-pwr-board-gpios = <&gpio_exp_pwr_brd 8 GPIO_ACTIVE_HIGH>, <&gpio_exp_pwr_brd 9 GPIO_ACTIVE_HIGH>, <&gpio_exp_pwr_brd 10 GPIO_ACTIVE_HIGH>, <&gpio_exp_pwr_brd 11 GPIO_ACTIVE_HIGH>;
sound-amp-mux-gpios = <&gpio_exp1 5 GPIO_ACTIVE_HIGH>;
i2c_clock_gpios = <&gpioa 15 GPIO_ACTIVE_HIGH>;
super-caps-charging-mode-gpios = <&gpio_exp_pwr_brd 3 GPIO_ACTIVE_LOW>;
Expand Down
124 changes: 109 additions & 15 deletions main_board/src/system/version/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,24 @@ LOG_MODULE_REGISTER(version, CONFIG_VERSION_LOG_LEVEL);
* GPIO logic level can then be used to get the hardware version
*
* # Diamond Orbs
* ## Main board
* Hardware version can be fetched using IO expander on the main board:
* - v4.0 p10 = 0
* - v4.1 p10 = 1
* - v4.2 p10 = 2
* - v4.0 p[13..10] = 0
* - v4.1 p[13..10] = 1
* - v4.2 p[13..10] = 2
*
* ## Front unit
* Hardware version can be fetched using IO expander on the front unit:
* - v6.0 p[13..10] = 0
* - v6.1 p[13..10] = 1
* - v6.2A p[13..10] = 2
* - v6.2B p[13..10] = 3
*
* ## Power board
* Hardware version can be fetched using IO expander on the power board:
* - v1.0: p[13..10] = 0
* - v1.1: p[13..10] = 1
* - v1.2: p[13..10] = 2
**/

#if defined(CONFIG_BOARD_PEARL_MAIN)
Expand All @@ -32,14 +46,33 @@ const struct adc_dt_spec adc_dt_spec = ADC_DT_SPEC_GET(DT_PATH(board_version));
#define ADC_REFERENCE ADC_REF_INTERNAL
#define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT
#elif defined(CONFIG_BOARD_DIAMOND_MAIN)
static const struct gpio_dt_spec hw_bit0 =
GPIO_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), hw_version_gpios, 0);
static const struct gpio_dt_spec hw_bit1 =
GPIO_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), hw_version_gpios, 1);
static const struct gpio_dt_spec hw_bit2 =
GPIO_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), hw_version_gpios, 2);
static const struct gpio_dt_spec hw_bit3 =
GPIO_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), hw_version_gpios, 3);
static const struct gpio_dt_spec hw_main_board_bit0 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_main_board_gpios, 0);
static const struct gpio_dt_spec hw_main_board_bit1 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_main_board_gpios, 1);
static const struct gpio_dt_spec hw_main_board_bit2 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_main_board_gpios, 2);
static const struct gpio_dt_spec hw_main_board_bit3 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_main_board_gpios, 3);

static const struct gpio_dt_spec hw_front_unit_bit0 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_front_unit_gpios, 0);
static const struct gpio_dt_spec hw_front_unit_bit1 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_front_unit_gpios, 1);
static const struct gpio_dt_spec hw_front_unit_bit2 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_front_unit_gpios, 2);
static const struct gpio_dt_spec hw_front_unit_bit3 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_front_unit_gpios, 3);

static const struct gpio_dt_spec hw_pwr_board_bit0 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_pwr_board_gpios, 0);
static const struct gpio_dt_spec hw_pwr_board_bit1 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_pwr_board_gpios, 1);
static const struct gpio_dt_spec hw_pwr_board_bit2 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_pwr_board_gpios, 2);
static const struct gpio_dt_spec hw_pwr_board_bit3 = GPIO_DT_SPEC_GET_BY_IDX(
DT_PATH(zephyr_user), hw_version_pwr_board_gpios, 3);

#endif

static Hardware_OrbVersion version = Hardware_OrbVersion_HW_VERSION_UNKNOWN;
Expand Down Expand Up @@ -143,10 +176,15 @@ version_fetch_hardware_rev(Hardware *hw_version)
}
}
#elif defined(CONFIG_BOARD_DIAMOND_MAIN)
gpio_pin_configure_dt(&hw_bit0, GPIO_INPUT);
int hw_bits =
gpio_pin_get_dt(&hw_bit3) << 3 | gpio_pin_get_dt(&hw_bit2) << 2 |
gpio_pin_get_dt(&hw_bit1) << 1 | gpio_pin_get_dt(&hw_bit0);
gpio_pin_configure_dt(&hw_main_board_bit0, GPIO_INPUT);
gpio_pin_configure_dt(&hw_main_board_bit1, GPIO_INPUT);
gpio_pin_configure_dt(&hw_main_board_bit2, GPIO_INPUT);
gpio_pin_configure_dt(&hw_main_board_bit3, GPIO_INPUT);

int hw_bits = gpio_pin_get_dt(&hw_main_board_bit3) << 3 |
gpio_pin_get_dt(&hw_main_board_bit2) << 2 |
gpio_pin_get_dt(&hw_main_board_bit1) << 1 |
gpio_pin_get_dt(&hw_main_board_bit0);

switch (hw_bits) {
case 0:
Expand All @@ -172,6 +210,62 @@ version_fetch_hardware_rev(Hardware *hw_version)
return RET_SUCCESS;
}

#if defined(CONFIG_BOARD_DIAMOND_MAIN)
enum front_unit_version_e
version_get_front_unit_rev(void)
{
gpio_pin_configure_dt(&hw_front_unit_bit0, GPIO_INPUT);
gpio_pin_configure_dt(&hw_front_unit_bit1, GPIO_INPUT);
gpio_pin_configure_dt(&hw_front_unit_bit2, GPIO_INPUT);
gpio_pin_configure_dt(&hw_front_unit_bit3, GPIO_INPUT);

int hw_bits = gpio_pin_get_dt(&hw_front_unit_bit3) << 3 |
gpio_pin_get_dt(&hw_front_unit_bit2) << 2 |
gpio_pin_get_dt(&hw_front_unit_bit1) << 1 |
gpio_pin_get_dt(&hw_front_unit_bit0);

switch (hw_bits) {
case 0:
return FRONT_UNIT_V6_0;
case 1:
return FRONT_UNIT_V6_1;
case 2:
return FRONT_UNIT_V6_2A;
case 3:
return FRONT_UNIT_V6_2B;
default:
LOG_ERR("Unknown front unit from IO expander: %d", hw_bits);
return FRONT_UNIT_UNKNOWN;
}
}

enum power_board_version_e
version_get_power_board_rev(void)
{
gpio_pin_configure_dt(&hw_pwr_board_bit0, GPIO_INPUT);
gpio_pin_configure_dt(&hw_pwr_board_bit1, GPIO_INPUT);
gpio_pin_configure_dt(&hw_pwr_board_bit2, GPIO_INPUT);
gpio_pin_configure_dt(&hw_pwr_board_bit3, GPIO_INPUT);

int hw_bits = gpio_pin_get_dt(&hw_pwr_board_bit3) << 3 |
gpio_pin_get_dt(&hw_pwr_board_bit2) << 2 |
gpio_pin_get_dt(&hw_pwr_board_bit1) << 1 |
gpio_pin_get_dt(&hw_pwr_board_bit0);

switch (hw_bits) {
case 0:
return POWER_BOARD_V1_0;
case 1:
return POWER_BOARD_V1_1;
case 2:
return POWER_BOARD_V1_2;
default:
LOG_ERR("Unknown power board from IO expander: %d", hw_bits);
return POWER_BOARD_UNKNOWN;
}
}
#endif

Hardware_OrbVersion
version_get_hardware_rev(void)
{
Expand Down
29 changes: 29 additions & 0 deletions main_board/src/system/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ version_hw_send(uint32_t remote);
Hardware_OrbVersion
version_get_hardware_rev(void);

enum front_unit_version_e {
FRONT_UNIT_V6_0 = 0,
FRONT_UNIT_V6_1,
FRONT_UNIT_V6_2A,
FRONT_UNIT_V6_2B,
FRONT_UNIT_UNKNOWN = 0xFF,
};

enum power_board_version_e {
POWER_BOARD_V1_0 = 0,
POWER_BOARD_V1_1,
POWER_BOARD_V1_2,
POWER_BOARD_UNKNOWN = 0xFF,
};

/**
* @brief Get the front unit hardware version
* @return The front unit hardware version
*/
enum front_unit_version_e
version_get_front_unit_rev(void);

/**
* @brief Get the power board hardware version
* @return The power board hardware version
*/
enum power_board_version_e
version_get_power_board_rev(void);

/**
* @brief Fetch hardware version by reading voltage and guessing mounted
* resistors
Expand Down

0 comments on commit 0c2090c

Please sign in to comment.