From 5115383f96dbc6acb23afdeea5e4de72593426f8 Mon Sep 17 00:00:00 2001 From: marvin-g-neu <141779828+marvin-g-neu@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:51:28 -0500 Subject: [PATCH] intergated sht --- Core/Src/mpu.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Core/Src/mpu.c b/Core/Src/mpu.c index f1532c17..a57bde8d 100644 --- a/Core/Src/mpu.c +++ b/Core/Src/mpu.c @@ -30,6 +30,20 @@ static inline int write_reg(uint8_t *data, uint8_t reg, uint8_t length) HAL_MAX_DELAY); } +static inline int temp_read_reg(uint8_t *data, uint8_t reg, uint8_t length) +{ + return HAL_I2C_Mem_Read(hi2c, SHT30_I2C_ADDRESS, reg, + I2C_MEMADD_SIZE_8BIT, data, length, + HAL_MAX_DELAY); +} + +static inline int temp_write_reg(uint8_t *data, uint8_t reg, uint8_t length) +{ + return HAL_I2C_Mem_Write(hi2c, SHT30_I2C_ADDRESS, reg, + I2C_MEMADD_SIZE_8BIT, data, length, + HAL_MAX_DELAY); +} + mpu_t *init_mpu(ADC_HandleTypeDef *pedals_adc, ADC_HandleTypeDef *lv_adc, GPIO_TypeDef *led_gpio, GPIO_TypeDef *watchdog_gpio) { @@ -51,8 +65,8 @@ mpu_t *init_mpu(ADC_HandleTypeDef *pedals_adc, ADC_HandleTypeDef *lv_adc, /* Initialize the Onboard Temperature Sensor */ mpu->temp_sensor = malloc(sizeof(sht30_t)); assert(mpu->temp_sensor); - mpu->temp_sensor->i2c_handle = hi2c; - assert(!sht30_init(mpu->temp_sensor)); /* This is always connected */ + assert(!sht30_init(mpu->temp_sensor, temp_write_reg, + temp_read_reg)); /* This is always connected */ assert(!HAL_ADC_Start_DMA(mpu->pedals_adc, mpu->pedal_dma_buf, sizeof(mpu->pedal_dma_buf) /