Skip to content
Open
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
26 changes: 16 additions & 10 deletions components/flow3r_bsp/flow3r_bsp_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static tildagon_mux_i2c_obj_t* mux;
#define READ ( MP_MACHINE_I2C_FLAG_WRITE1 | MP_MACHINE_I2C_FLAG_READ | MP_MACHINE_I2C_FLAG_STOP )
#define WRITE MP_MACHINE_I2C_FLAG_STOP

static BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data,
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data,
uint32_t len, void *intf_ptr) {
flow3r_bsp_imu_t *imu = (flow3r_bsp_imu_t *)intf_ptr;

Expand All @@ -55,7 +55,7 @@ static BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data,
return BMI2_OK;
}

static BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr,
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr,
const uint8_t *reg_data,
uint32_t len, void *intf_ptr) {
flow3r_bsp_imu_t *imu = (flow3r_bsp_imu_t *)intf_ptr;
Expand Down Expand Up @@ -237,6 +237,20 @@ esp_err_t flow3r_bsp_imu_read_steps(flow3r_bsp_imu_t *imu, uint32_t *steps) {
return ESP_ERR_NOT_FOUND;
}

/*!
* @brief get the temperature of the device
*/
esp_err_t flow3r_bsp_imu_read_temperature(flow3r_bsp_imu_t *imu, float *temperature) {
uint16_t temp_data;
int8_t rslt = bmi2_get_temperature_data(&temp_data, &(imu->bmi));
bmi2_error_codes_print_result(rslt);
if (rslt != BMI2_OK) return ESP_FAIL;
const float scaling = 0.001953125F;
const float offset = 23.0F;
*temperature = ((float)temp_data * scaling ) + offset;
return ESP_OK;
}

/*!
* @brief Prints the execution status of the APIs.
*/
Expand Down Expand Up @@ -565,10 +579,6 @@ static int8_t set_accel_config(flow3r_bsp_imu_t *imu) {
/* Set the accel configurations. */
rslt = bmi2_set_sensor_config(&config, 1, &imu->bmi);
bmi2_error_codes_print_result(rslt);

/* Map data ready interrupt to interrupt pin. */
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, &imu->bmi);
bmi2_error_codes_print_result(rslt);
}

return rslt;
Expand Down Expand Up @@ -616,10 +626,6 @@ static int8_t set_gyro_config(flow3r_bsp_imu_t *imu) {

rslt = bmi2_set_sensor_config(&config, 1, &imu->bmi);
bmi2_error_codes_print_result(rslt);

/* Map data ready interrupt to interrupt pin. */
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, &imu->bmi);
bmi2_error_codes_print_result(rslt);
}

return rslt;
Expand Down
19 changes: 18 additions & 1 deletion components/flow3r_bsp/flow3r_bsp_imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ esp_err_t flow3r_bsp_imu_read_gyro_dps(flow3r_bsp_imu_t *imu, float *x,
// Returns ESP_ERR_NOT_FOUND if there is no new reading available.
// Returns ESP_FAIL if the sensor could not be read (e.g. I2C unavailable).
// Retrurns the number of steps counted.
esp_err_t flow3r_bsp_imu_read_steps(flow3r_bsp_imu_t *imu, uint32_t *steps);
esp_err_t flow3r_bsp_imu_read_steps(flow3r_bsp_imu_t *imu, uint32_t *steps);

// Get temperature
//
// Returns ESP_FAIL if the sensor could not be read (e.g. I2C unavailable).
// Returns temperature in 'C
esp_err_t flow3r_bsp_imu_read_temperature(flow3r_bsp_imu_t *imu, float *temperature);

// i2c write
// writes buffer to register address
// Returns bmi fault code
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr,const uint8_t *reg_data,
uint32_t len, void *intf_ptr);
// i2c read
// reads buffer from register address
// Returns bmi fault code
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data,
uint32_t len, void *intf_ptr);
33 changes: 25 additions & 8 deletions components/st3m/st3m_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ static const char *TAG = "st3m-imu";
#include "freertos/semphr.h"
#include "freertos/task.h"

static void _task(void *data);

static flow3r_bsp_imu_t _imu;

static SemaphoreHandle_t _mu;
Expand All @@ -20,20 +18,20 @@ static SemaphoreHandle_t _mu;

static float _acc_x, _acc_y, _acc_z;
static float _gyro_x, _gyro_y, _gyro_z;
static float _temperature;
static uint32_t _steps;

void st3m_imu_init() {
esp_err_t st3m_imu_init() {
_mu = xSemaphoreCreateMutex();
assert(_mu != NULL);

esp_err_t ret = flow3r_bsp_imu_init(&_imu);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "IMU init failed: %s", esp_err_to_name(ret));
return;
return ESP_FAIL;
}

xTaskCreate(&_task, "imu", 4096, NULL, configMAX_PRIORITIES - 2, NULL);
ESP_LOGI(TAG, "IMU task started");
return ESP_OK;
}

void st3m_imu_read_acc_mps(float *x, float *y, float *z) {
Expand All @@ -58,10 +56,24 @@ void st3m_imu_read_steps(uint32_t *steps) {
UNLOCK;
}

static void _task(void *data) {
void st3m_imu_read_temperature(float *temperature) {
LOCK;
*temperature = _temperature;
UNLOCK;
}

int st3m_imu_read(uint8_t reg_addr, uint8_t *reg_data, uint8_t len) {
return bmi2_i2c_read(reg_addr, reg_data, len, &_imu );
}

int st3m_imu_write(uint8_t reg_addr, uint8_t *reg_data, uint8_t len) {
return bmi2_i2c_write(reg_addr, reg_data, len, &_imu );
}

void st3m_imu_task(void *data) {
TickType_t last_wake = xTaskGetTickCount();
esp_err_t ret;
float a, b, c;
float a, b, c, temperature;
uint32_t steps;
while (1) {
vTaskDelayUntil(&last_wake, pdMS_TO_TICKS(10)); // 100 Hz
Expand Down Expand Up @@ -91,6 +103,11 @@ static void _task(void *data) {
_steps = steps;
}

ret = flow3r_bsp_imu_read_temperature(&_imu, &temperature);
if (ret == ESP_OK) {
_temperature = temperature;
}

UNLOCK;
}
}
14 changes: 9 additions & 5 deletions components/st3m/st3m_imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#include <stdbool.h>
#include <stdint.h>

void st3m_imu_init(void);
esp_err_t st3m_imu_init(void);

void st3m_imu_read_acc_mps(float *x, float *y, float *z);
void st3m_imu_read_gyro_dps(float *x, float *y, float *z);
void st3m_imu_read_pressure(float *pressure, float *temperature);
void st3m_imu_read_steps(uint32_t *steps);
extern void st3m_imu_task(void *data);
extern void st3m_imu_read_acc_mps(float *x, float *y, float *z);
extern void st3m_imu_read_gyro_dps(float *x, float *y, float *z);
extern void st3m_imu_read_pressure(float *pressure, float *temperature);
extern void st3m_imu_read_steps(uint32_t *steps);
extern void st3m_imu_read_temperature(float *temperature);
extern int st3m_imu_read(uint8_t reg_addr, uint8_t *reg_data, uint8_t len);
extern int st3m_imu_write(uint8_t reg_addr, uint8_t *reg_data, uint8_t len);
3 changes: 3 additions & 0 deletions drivers/micropython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/tildagon_i2c/tildagon_i2c.cmake)
# Add PMIC and usb PD and micropython power bindings
include(${CMAKE_CURRENT_LIST_DIR}/tildagon_power/tildagon_power.cmake)

# Add imu bindings
include(${CMAKE_CURRENT_LIST_DIR}/tildagon_imu/tildagon_imu.cmake)

# Add OTA helpers
include(${CMAKE_CURRENT_LIST_DIR}/ota/micropython.cmake)

Expand Down
16 changes: 0 additions & 16 deletions drivers/tildagon_helpers/micropython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,3 @@ target_sources(usermod_tildagon_helpers INTERFACE
target_link_libraries(usermod INTERFACE usermod_tildagon_helpers)



# Create an INTERFACE library for our C module.
add_library(usermod_imu INTERFACE)
# Add our source files to the lib
target_sources(usermod_imu INTERFACE
${CMAKE_CURRENT_LIST_DIR}/mp_imu.c
)

# Add the current directory as an include directory.
target_include_directories(usermod_imu INTERFACE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/../../components/st3m
)

# Link our INTERFACE library to the usermod target.
target_link_libraries(usermod INTERFACE usermod_imu)
55 changes: 0 additions & 55 deletions drivers/tildagon_helpers/mp_imu.c

This file was deleted.

Loading