|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
LSM6DSO IMU + MAX17048 fuel-gauge device models on the I2C bus. More...
Go to the source code of this file.
Data Structures | |
| struct | lsm6dso_state_t |
| One ST LSM6DSO IMU device: a flat auto-incrementing register file. More... | |
| struct | battery_state_t |
| User-settable battery state surfaced by the MAX17048 fuel gauge. More... | |
| struct | max17048_state_t |
| One MAX17048 fuel gauge: a flat big-endian register file + read pointer. More... | |
Enumerations | |
| enum | lsm6dso_const_t : uint32_t { k_lsm6dso_addr_7b = 0x6BU , k_lsm6dso_reg_who_am_i = 0x0FU , k_lsm6dso_who_am_i_val = 0x6CU , k_lsm6dso_reg_outx_l_g = 0x22U , k_lsm6dso_reg_outz_l_a = 0x2CU , k_lsm6dso_reg_file = 0x100U , k_lsm6dso_seed_accel_z = 0x4000U , k_lsm6dso_seed_gyro_x = 0x0100U } |
| ST LSM6DSO 6-DoF IMU constants (libs/ra8_lsm6dso, DS12140 Rev 4). More... | |
| enum | max17048_const_t : uint32_t { k_max17048_addr_7b = 0x36U , k_max17048_reg_vcell = 0x02U , k_max17048_reg_soc = 0x04U , k_max17048_reg_version = 0x08U , k_max17048_reg_crate = 0x16U , k_max17048_reg_file = 0x100U , k_battery_soc_default = 72U , k_battery_soc_max = 100U , k_battery_vcell_default = 0xBE00U , k_battery_version_val = 0x0012U , k_battery_crate_mag = 0x0018U , k_battery_byte_shift = 8U , k_battery_byte_mask = 0xFFU } |
| Maxim MAX17048 fuel-gauge constants (battery state-of-charge over I2C). More... | |
Functions | |
| static RA8_INTERNAL void | internal_lsm6dso_seed16 (lsm6dso_state_t *s, uint8_t reg, uint16_t val) |
| Perform lsm6dso seed16 for the board periph I2C devices model. | |
| static RA8_INTERNAL void | internal_lsm6dso_reset_regs (lsm6dso_state_t *s) |
| Reset the register file: WHO_AM_I + synthetic accel/gyro samples. | |
| static RA8_INTERNAL void | internal_lsm6dso_write (void *ctx, uint8_t byte) |
| Controller -> LSM6DSO: start register first, then config payload. | |
| static RA8_INTERNAL uint32_t | internal_lsm6dso_read (void *ctx, uint8_t *buf, uint32_t max) |
| LSM6DSO -> controller: burst from the pointer, auto-incrementing. | |
| static RA8_INTERNAL void | internal_lsm6dso_stop (void *ctx) |
| STOP / transfer end: re-arm pointer capture for the next transfer. | |
| static RA8_INTERNAL void | internal_fuelgauge_put16 (max17048_state_t *s, uint8_t reg, uint16_t val) |
Write a big-endian 16-bit value at register reg of s. | |
| static RA8_INTERNAL void | internal_fuelgauge_seed (max17048_state_t *s) |
| Lay the MAX17048 register file from the current s_battery state. | |
| static RA8_INTERNAL void | internal_fuelgauge_write (void *ctx, uint8_t byte) |
| MAX17048 write: first byte is the register pointer, then it advances. | |
| static RA8_INTERNAL uint32_t | internal_fuelgauge_read (void *ctx, uint8_t *buf, uint32_t max) |
| MAX17048 read: serve consecutive register bytes (auto-increment). | |
| static RA8_INTERNAL void | internal_fuelgauge_stop (void *ctx) |
| MAX17048 STOP: re-arm the register-pointer capture. | |
| void | board_periph_battery_set (uint8_t soc_pct, bool charging) |
| Set the emulated battery state surfaced by the MAX17048 fuel gauge. | |
| void | board_periph_battery_get (uint8_t *out_soc, bool *out_charging) |
| Read back the emulated battery state (for the status overlay). | |
| void | priv_board_i2c_imu_fuel_reset (void) |
| Implementation of priv_board_i2c_imu_fuel_reset() – re-lay register files. | |
| void | priv_board_i2c_imu_fuel_register (void) |
| Implementation of priv_board_i2c_imu_fuel_register() – bus attach. | |
| uint32_t | priv_board_i2c_imu_reads (void) |
| Implementation of priv_board_i2c_imu_reads() – report telemetry. | |
Variables | |
| static lsm6dso_state_t | s_lsm6dso |
| static battery_state_t | s_battery = {.soc_pct = (uint8_t)k_battery_soc_default, .charging = false} |
| Battery state + the fuel-gauge device that exposes it over I2C. | |
| static max17048_state_t | s_fuelgauge |
LSM6DSO IMU + MAX17048 fuel-gauge device models on the I2C bus.
The two flat-register-file bus devices (the ST LSM6DSO 6-DoF IMU at 0x6B and the MAX17048-class fuel gauge at 0x36, backed by the CLI-settable battery state) – moved verbatim out of board_periph_i2c.c. They register themselves on the modelled bus through the module-internal registry.
Definition in file board_periph_i2c_devices.c.
| enum lsm6dso_const_t : uint32_t |
ST LSM6DSO 6-DoF IMU constants (libs/ra8_lsm6dso, DS12140 Rev 4).
The MikroE 6DOF IMU 12 Click ties SA0 high, so the part answers at 7-bit 0x6B. Unlike the GT911, the LSM6DSO uses an 8-bit register pointer that auto-increments across a burst read, so the model is a flat register file: the driver writes the start register, then reads N consecutive bytes (WHO_AM_I, then 6-byte gyro / accel bursts). WHO_AM_I (0x0F) must read back 0x6C or ra8_lsm6dso_init() rejects the part.
Definition at line 32 of file board_periph_i2c_devices.c.
| enum max17048_const_t : uint32_t |
Maxim MAX17048 fuel-gauge constants (battery state-of-charge over I2C).
The carrier's MAX17048-class fuel gauge answers at 7-bit 0x36 with a flat register file of big-endian 16-bit values. The firmware writes a register pointer then reads two bytes: VCELL (cell voltage, 78.125 uV/LSB), SOC (state-of-charge, high byte = integer percent), VERSION, and CRATE (charge rate, signed – positive while charging). The emulator drives SOC + the CRATE sign from the user-settable battery state (--battery / --charge).
Definition at line 54 of file board_periph_i2c_devices.c.
| void board_periph_battery_get | ( | uint8_t * | out_soc, |
| bool * | out_charging ) |
Read back the emulated battery state (for the status overlay).
| [out] | out_soc | Receives the state-of-charge percent (NULL ok). |
| [out] | out_charging | Receives the charging flag (NULL ok). |
Read back the emulated battery state (for the status overlay); this step is contained within the board periph model and uses bounded caller or module-owned storage.
Definition at line 334 of file board_periph_i2c_devices.c.
References s_battery.
Referenced by apply_battery_click(), internal_fill_status_hw(), and internal_main_apply_button_battery().
| void board_periph_battery_set | ( | uint8_t | soc_pct, |
| bool | charging ) |
Set the emulated battery state surfaced by the MAX17048 fuel gauge.
The firmware reads state-of-charge + charge direction from a MAX17048-class fuel gauge at I2C 0x36; this drives that device's register file. Set from the CLI (--battery <pct> / --charge) before the run. soc_pct is clamped to 0..100.
| [in] | soc_pct | State-of-charge percent (clamped to [0, 100]). |
| [in] | charging | true marks the charger attached (CRATE reads positive). |
Definition at line 327 of file board_periph_i2c_devices.c.
References internal_fuelgauge_seed(), k_battery_soc_max, s_battery, and s_fuelgauge.
Referenced by apply_battery_click(), and internal_main_apply_button_battery().
|
static |
Write a big-endian 16-bit value at register reg of s.
Write a big-endian 16-bit value at register reg of s; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | s | Module state instance processed by the operation. |
| [in] | reg | Register index or value selected by the operation. |
| [in] | val | Register or payload value processed by the operation. |
Definition at line 231 of file board_periph_i2c_devices.c.
References k_battery_byte_mask, k_battery_byte_shift, RA8_INTERNAL, and max17048_state_t::regs.
Referenced by internal_fuelgauge_seed().
|
static |
MAX17048 read: serve consecutive register bytes (auto-increment).
Max17048 read: serve consecutive register bytes (auto-increment); this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | ctx | Opaque callback context identifying module-owned device state. |
| [in,out] | buf | Bounded byte buffer read or updated by the operation. |
| [in] | max | Capacity of the destination or operation in elements. |
| value | The operation-specific fuelgauge read value. |
Definition at line 301 of file board_periph_i2c_devices.c.
References k_max17048_reg_file, RA8_INTERNAL, max17048_state_t::reads, max17048_state_t::reg_ptr, and max17048_state_t::regs.
Referenced by priv_board_i2c_imu_fuel_register().
|
static |
Lay the MAX17048 register file from the current s_battery state.
Lay the max17048 register file from the current s_battery state; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | s | Module state instance processed by the operation. |
Definition at line 246 of file board_periph_i2c_devices.c.
References internal_fuelgauge_put16(), k_battery_byte_shift, k_battery_crate_mag, k_battery_vcell_default, k_battery_version_val, k_max17048_reg_crate, k_max17048_reg_file, k_max17048_reg_soc, k_max17048_reg_vcell, k_max17048_reg_version, RA8_INTERNAL, max17048_state_t::regs, and s_battery.
Referenced by board_periph_battery_set(), and priv_board_i2c_imu_fuel_reset().
|
static |
MAX17048 STOP: re-arm the register-pointer capture.
Max17048 stop: re-arm the register-pointer capture; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | ctx | Opaque callback context identifying module-owned device state. |
Definition at line 321 of file board_periph_i2c_devices.c.
References max17048_state_t::ptr_set, and RA8_INTERNAL.
Referenced by priv_board_i2c_imu_fuel_register().
|
static |
MAX17048 write: first byte is the register pointer, then it advances.
Max17048 write: first byte is the register pointer, then it advances; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | ctx | Opaque callback context identifying module-owned device state. |
| [in] | byte | One data byte received from or sent to the emulated interface. |
Definition at line 274 of file board_periph_i2c_devices.c.
References k_max17048_reg_file, max17048_state_t::ptr_set, RA8_INTERNAL, max17048_state_t::reg_ptr, and max17048_state_t::regs.
Referenced by priv_board_i2c_imu_fuel_register().
|
static |
LSM6DSO -> controller: burst from the pointer, auto-incrementing.
Lsm6dso -> controller: burst from the pointer, auto-incrementing; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | ctx | Opaque callback context identifying module-owned device state. |
| [in,out] | buf | Bounded byte buffer read or updated by the operation. |
| [in] | max | Capacity of the destination or operation in elements. |
| value | The operation-specific lsm6dso read value. |
Definition at line 194 of file board_periph_i2c_devices.c.
References k_lsm6dso_reg_file, RA8_INTERNAL, lsm6dso_state_t::reads, lsm6dso_state_t::reg_ptr, and lsm6dso_state_t::regs.
Referenced by priv_board_i2c_imu_fuel_register().
|
static |
Reset the register file: WHO_AM_I + synthetic accel/gyro samples.
Reset the register file: who_am_i + synthetic accel/gyro samples; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | s | Module state instance processed by the operation. |
Definition at line 144 of file board_periph_i2c_devices.c.
References internal_lsm6dso_seed16(), k_lsm6dso_reg_file, k_lsm6dso_reg_outx_l_g, k_lsm6dso_reg_outz_l_a, k_lsm6dso_reg_who_am_i, k_lsm6dso_seed_accel_z, k_lsm6dso_seed_gyro_x, k_lsm6dso_who_am_i_val, lsm6dso_state_t::ptr_set, RA8_INTERNAL, lsm6dso_state_t::reads, lsm6dso_state_t::reg_ptr, and lsm6dso_state_t::regs.
Referenced by priv_board_i2c_imu_fuel_reset().
|
static |
Perform lsm6dso seed16 for the board periph I2C devices model.
Perform lsm6dso seed16 for the board periph i2c devices model; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | s | Module state instance processed by the operation. |
| [in] | reg | Register index or value selected by the operation. |
| [in] | val | Register or payload value processed by the operation. |
Definition at line 129 of file board_periph_i2c_devices.c.
References k_i3c_dev_byte_mask, RA8_INTERNAL, and lsm6dso_state_t::regs.
Referenced by internal_lsm6dso_reset_regs().
|
static |
STOP / transfer end: re-arm pointer capture for the next transfer.
Stop / transfer end: re-arm pointer capture for the next transfer; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | ctx | Opaque callback context identifying module-owned device state. |
Definition at line 214 of file board_periph_i2c_devices.c.
References lsm6dso_state_t::ptr_set, and RA8_INTERNAL.
Referenced by priv_board_i2c_imu_fuel_register().
|
static |
Controller -> LSM6DSO: start register first, then config payload.
Controller -> lsm6dso: start register first, then config payload; this step is contained within the board periph I2C devices model and uses bounded caller or module-owned storage.
| [in,out] | ctx | Opaque callback context identifying module-owned device state. |
| [in] | byte | One data byte received from or sent to the emulated interface. |
Definition at line 167 of file board_periph_i2c_devices.c.
References k_lsm6dso_reg_file, lsm6dso_state_t::ptr_set, RA8_INTERNAL, lsm6dso_state_t::reg_ptr, and lsm6dso_state_t::regs.
Referenced by priv_board_i2c_imu_fuel_register().
| void priv_board_i2c_imu_fuel_register | ( | void | ) |
Implementation of priv_board_i2c_imu_fuel_register() – bus attach.
Register the LSM6DSO + MAX17048 devices on the modelled bus.
Definition at line 353 of file board_periph_i2c_devices.c.
References internal_fuelgauge_read(), internal_fuelgauge_stop(), internal_fuelgauge_write(), internal_lsm6dso_read(), internal_lsm6dso_stop(), internal_lsm6dso_write(), k_lsm6dso_addr_7b, k_max17048_addr_7b, priv_i2c_device_register(), s_fuelgauge, and s_lsm6dso.
Referenced by internal_i3c_reset().
| void priv_board_i2c_imu_fuel_reset | ( | void | ) |
Implementation of priv_board_i2c_imu_fuel_reset() – re-lay register files.
Re-lay the IMU + fuel-gauge register files (block reset path).
Definition at line 345 of file board_periph_i2c_devices.c.
References internal_fuelgauge_seed(), internal_lsm6dso_reset_regs(), s_fuelgauge, and s_lsm6dso.
Referenced by internal_i3c_reset().
| uint32_t priv_board_i2c_imu_reads | ( | void | ) |
Implementation of priv_board_i2c_imu_reads() – report telemetry.
IMU register reads answered this run (report telemetry).
Definition at line 370 of file board_periph_i2c_devices.c.
References s_lsm6dso.
Referenced by internal_i3c_report().
|
static |
Battery state + the fuel-gauge device that exposes it over I2C.
Definition at line 115 of file board_periph_i2c_devices.c.
Referenced by board_periph_battery_get(), board_periph_battery_set(), and internal_fuelgauge_seed().
|
static |
Definition at line 116 of file board_periph_i2c_devices.c.
Referenced by board_periph_battery_set(), priv_board_i2c_imu_fuel_register(), and priv_board_i2c_imu_fuel_reset().
|
static |
Definition at line 112 of file board_periph_i2c_devices.c.
Referenced by priv_board_i2c_imu_fuel_register(), priv_board_i2c_imu_fuel_reset(), and priv_board_i2c_imu_reads().