From 80cfbec7df660d1b1308690f118210e4beb010b3 Mon Sep 17 00:00:00 2001 From: Misaki Date: Sat, 23 Aug 2025 01:13:16 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B5=8B=E8=AF=95=E4=BA=86QMI8658=E7=9A=84?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=EF=BC=8C=E6=AD=A3=E5=B8=B8=E8=AF=BB=E5=87=BA?= =?UTF-8?q?x=EF=BC=8Cy,z=E8=BD=B4=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=BE=97?= =?UTF-8?q?=E5=88=B0=E7=9A=84pitch,=20roll,=20yaw=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/I2C_Driver/I2C_Driver.c | 54 ++++++ Lib/I2C_Driver/I2C_Driver.h | 23 +++ Lib/QMI8658/QMI8658.c | 303 ++++++++++++++++++++++++++++++++ Lib/QMI8658/QMI8658.h | 161 +++++++++++++++++ Lib/README.md | 3 + main/Bionic_sphere.c | 5 +- main/CMakeLists.txt | 9 +- test/driver_test/drivers_test.c | 21 +++ test/driver_test/drivers_test.h | 12 ++ 项目开发日志.md | 6 +- 10 files changed, 594 insertions(+), 3 deletions(-) create mode 100644 Lib/I2C_Driver/I2C_Driver.c create mode 100644 Lib/I2C_Driver/I2C_Driver.h create mode 100644 Lib/QMI8658/QMI8658.c create mode 100644 Lib/QMI8658/QMI8658.h create mode 100644 Lib/README.md create mode 100644 test/driver_test/drivers_test.c create mode 100644 test/driver_test/drivers_test.h diff --git a/Lib/I2C_Driver/I2C_Driver.c b/Lib/I2C_Driver/I2C_Driver.c new file mode 100644 index 0000000..7c8e2ed --- /dev/null +++ b/Lib/I2C_Driver/I2C_Driver.c @@ -0,0 +1,54 @@ +#include "I2C_Driver.h" + + +#define I2C_TRANS_BUF_MINIMUM_SIZE (sizeof(i2c_cmd_desc_t) + \ + sizeof(i2c_cmd_link_t) * 8) /* It is required to have allocate one i2c_cmd_desc_t per command: + * start + write (device address) + write buffer + + * start + write (device address) + read buffer + read buffer for NACK + + * stop */ +static const char *I2C_TAG = "I2C"; +/** + * @brief i2c master initialization + */ +static esp_err_t i2c_master_init(void) +{ + int i2c_master_port = I2C_MASTER_NUM; + + i2c_config_t conf = { + .mode = I2C_MODE_MASTER, + .sda_io_num = I2C_SDA_IO, + .scl_io_num = I2C_SCL_IO, + .sda_pullup_en = GPIO_PULLUP_ENABLE, + .scl_pullup_en = GPIO_PULLUP_ENABLE, + .master.clk_speed = I2C_MASTER_FREQ_HZ, + }; + + i2c_param_config(i2c_master_port, &conf); + + return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0); +} +void I2C_Init(void) +{ + /********************* I2C *********************/ + ESP_ERROR_CHECK(i2c_master_init()); + ESP_LOGI(I2C_TAG, "I2C initialized successfully"); +} + + +// Reg addr is 8 bit +esp_err_t I2C_Write(uint8_t Driver_addr, uint8_t Reg_addr, const uint8_t *Reg_data, uint32_t Length) +{ + uint8_t buf[Length+1]; + + buf[0] = Reg_addr; + // Copy Reg_data to buf starting at buf[1] + memcpy(&buf[1], Reg_data, Length); + return i2c_master_write_to_device(I2C_MASTER_NUM, Driver_addr, buf, Length+1, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); +} + + + +esp_err_t I2C_Read(uint8_t Driver_addr, uint8_t Reg_addr, uint8_t *Reg_data, uint32_t Length) +{ + return i2c_master_write_read_device(I2C_MASTER_NUM, Driver_addr, &Reg_addr, 1, Reg_data, Length, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); +} diff --git a/Lib/I2C_Driver/I2C_Driver.h b/Lib/I2C_Driver/I2C_Driver.h new file mode 100644 index 0000000..c3209f0 --- /dev/null +++ b/Lib/I2C_Driver/I2C_Driver.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include // For memcpy +#include "esp_log.h" +#include "driver/gpio.h" +#include "driver/i2c.h" + + +/********************* I2C *********************/ +#define I2C_SCL_IO 10 /*!< GPIO number used for I2C master clock */ +#define I2C_SDA_IO 11 /*!< GPIO number used for I2C master data */ +#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */ +#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */ +#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ +#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ +#define I2C_MASTER_TIMEOUT_MS 1000 + + +void I2C_Init(void); +// Reg addr is 8 bit +esp_err_t I2C_Write(uint8_t Driver_addr, uint8_t Reg_addr, const uint8_t *Reg_data, uint32_t Length); +esp_err_t I2C_Read(uint8_t Driver_addr, uint8_t Reg_addr, uint8_t *Reg_data, uint32_t Length); \ No newline at end of file diff --git a/Lib/QMI8658/QMI8658.c b/Lib/QMI8658/QMI8658.c new file mode 100644 index 0000000..7b47107 --- /dev/null +++ b/Lib/QMI8658/QMI8658.c @@ -0,0 +1,303 @@ +#include "QMI8658.h" + +IMUdata Accel; +IMUdata Gyro; + +uint8_t Device_addr ; // default for SD0/SA0 low, 0x6A if high +acc_scale_t acc_scale = ACC_RANGE_4G; +gyro_scale_t gyro_scale = GYR_RANGE_64DPS; +acc_odr_t acc_odr = acc_odr_norm_8000; +gyro_odr_t gyro_odr = gyro_odr_norm_8000; +sensor_state_t sensor_state = sensor_default; +lpf_t acc_lpf; + +float accelScales, gyroScales; +float accelScales = 0; +uint8_t readings[12]; +uint32_t reading_timestamp_us; // timestamp in arduino micros() time +/** + * Inialize Wire and send default configs + * @param addr I2C address of sensor, typically 0x6A or 0x6B + */ +void QMI8658_Init(void) +{ + uint8_t buf[1]; + Device_addr = QMI8658_L_SLAVE_ADDRESS; + I2C_Read(Device_addr, QMI8658_REVISION_ID, buf, 1); + printf("QMI8658 Device ID: %x\r\n",buf[0]); // Get chip id + setState(sensor_running); + + setAccScale(acc_scale); + setAccODR(acc_odr); + setAccLPF(LPF_MODE_0); + switch (acc_scale) { + // Possible accelerometer scales (and their register bit settings) are: + // 2 Gs (00), 4 Gs (01), 8 Gs (10), and 16 Gs (11). + // Here's a bit of an algorith to calculate DPS/(ADC tick) based on that + // 2-bit value: + case ACC_RANGE_2G: accelScales = 2.0 / 32768.0; break; + case ACC_RANGE_4G: accelScales = 4.0 / 32768.0; break; + case ACC_RANGE_8G: accelScales = 8.0 / 32768.0; break; + case ACC_RANGE_16G: accelScales = 16.0 / 32768.0; break; + } + + setGyroScale(gyro_scale); + setGyroODR(gyro_odr); + setGyroLPF(LPF_MODE_3); + switch (gyro_scale) { + // Possible gyro scales (and their register bit settings) are: + // 250 DPS (00), 500 DPS (01), 1000 DPS (10), and 2000 DPS (11). + // Here's a bit of an algorith to calculate DPS/(ADC tick) based on that + // 2-bit value: + case GYR_RANGE_16DPS: gyroScales = 16.0 / 32768.0; break; + case GYR_RANGE_32DPS: gyroScales = 32.0 / 32768.0; break; + case GYR_RANGE_64DPS: gyroScales = 64.0 / 32768.0; break; + case GYR_RANGE_128DPS: gyroScales = 128.0 / 32768.0; break; + case GYR_RANGE_256DPS: gyroScales = 256.0 / 32768.0; break; + case GYR_RANGE_512DPS: gyroScales = 512.0 / 32768.0; break; + case GYR_RANGE_1024DPS: gyroScales = 1024.0 / 32768.0; break; + } +} +void QMI8658_Loop(void) +{ + getAccelerometer(); +} + +/** + * Transmit one uint8_t of data to QMI8658. + * @param addr address of data to be written + * @param data the data to be written + */ +void QMI8658_transmit(uint8_t addr, uint8_t data) +{ + I2C_Write(Device_addr, addr, &data, 1); +} + +/** + * Receive one uint8_t of data from QMI8658. + * @param addr address of data to be read + * @return the uint8_t of data that was read + */ +uint8_t QMI8658_receive(uint8_t addr) +{ + uint8_t retval; + I2C_Read(Device_addr, addr, &retval, 1); + return retval; +} + +/** + * Writes data to CTRL9 (command register) and waits for ACK. + * @param command the command to be executed + */ +void QMI8658_CTRL9_Write(uint8_t command) +{ + // transmit command + QMI8658_transmit(QMI8658_CTRL9, command); + + // wait for command to be done + while (((QMI8658_receive(QMI8658_STATUSINT)) & 0x80) == 0x00); +} + +/** + * Set output data rate (ODR) of accelerometer. + * @param odr acc_odr_t variable representing new data rate + */ +void setAccODR(acc_odr_t odr) +{ + if (sensor_state != sensor_default) // If the device is not in the default state + { + uint8_t ctrl2 = QMI8658_receive(QMI8658_CTRL2); + ctrl2 &= ~QMI8658_AODR_MASK; // clear previous setting + ctrl2 |= odr; // OR in new setting + QMI8658_transmit(QMI8658_CTRL2, ctrl2); + } + acc_odr = odr; +} + +/** + * Set output data rate (ODR) of gyro. + * @param odr gyro_odr_t variable representing new data rate + */ +void setGyroODR(gyro_odr_t odr) +{ + if (sensor_state != sensor_default) + { + uint8_t ctrl3 = QMI8658_receive(QMI8658_CTRL3); + ctrl3 &= ~QMI8658_GODR_MASK; // clear previous setting + ctrl3 |= odr; // OR in new setting + QMI8658_transmit(QMI8658_CTRL3, ctrl3); + } + gyro_odr = odr; +} + +/** + * Set scale of accelerometer output. + * @param scale acc_scale_t variable representing new scale + */ +void setAccScale(acc_scale_t scale) +{ + if (sensor_state != sensor_default) + { + uint8_t ctrl2 = QMI8658_receive(QMI8658_CTRL2); + ctrl2 &= ~QMI8658_ASCALE_MASK; // clear previous setting + ctrl2 |= scale << QMI8658_ASCALE_OFFSET; // OR in new setting + QMI8658_transmit(QMI8658_CTRL2, ctrl2); + } + acc_scale = scale; +} + +/** + * Set scale of gyro output. + * @param scale gyro_scale_t variable representing new scale + */ +void setGyroScale(gyro_scale_t scale) +{ + if (sensor_state != sensor_default) + { + uint8_t ctrl3 = QMI8658_receive(QMI8658_CTRL3); + ctrl3 &= ~QMI8658_GSCALE_MASK; // clear previous setting + ctrl3 |= scale << QMI8658_GSCALE_OFFSET; // OR in new setting + QMI8658_transmit(QMI8658_CTRL3, ctrl3); + } + gyro_scale = scale; +} + +/** + * Set new low-pass filter value for accelerometer + * @param lp lpf_t variable representing new low-pass filter value + */ +void setAccLPF(lpf_t lpf) +{ + if (sensor_state != sensor_default) + { + uint8_t ctrl5 = QMI8658_receive(QMI8658_CTRL5); + ctrl5 &= !QMI8658_ALPF_MASK; + ctrl5 |= lpf << QMI8658_ALPF_OFFSET; + ctrl5 |= 0x01; // turn on acc low pass filter + QMI8658_transmit(QMI8658_CTRL5, ctrl5); + } + acc_lpf = lpf; +} + +/** + * Set new low-pass filter value for gyro + * @param lp lpf_t variable representing new low-pass filter value + */ +void setGyroLPF(lpf_t lpf) +{ + if (sensor_state != sensor_default) + { + uint8_t ctrl5 = QMI8658_receive(QMI8658_CTRL5); + ctrl5 &= !QMI8658_GLPF_MASK; + ctrl5 |= lpf << QMI8658_GLPF_OFFSET; + ctrl5 |= 0x10; // turn on gyro low pass filter + QMI8658_transmit(QMI8658_CTRL5, ctrl5); + } +} + +/** + * Set new state of QMI8658. + * @param state new state to transition to + */ +void setState(sensor_state_t state) +{ + uint8_t ctrl1; + switch (state) + { + case sensor_running: + ctrl1 = QMI8658_receive(QMI8658_CTRL1); + // enable 2MHz oscillator + ctrl1 &= 0xFE; + // enable auto address increment for fast block reads + ctrl1 |= 0x40; + QMI8658_transmit(QMI8658_CTRL1, ctrl1); + + // enable high speed internal clock, + // acc and gyro in full mode, and + // disable syncSample mode + QMI8658_transmit(QMI8658_CTRL7, 0x43); + + // disable AttitudeEngine Motion On Demand + QMI8658_transmit(QMI8658_CTRL6, 0x00); + break; + case sensor_power_down: + // disable high speed internal clock, + // acc and gyro powered down + QMI8658_transmit(QMI8658_CTRL7, 0x00); + + ctrl1 = QMI8658_receive(QMI8658_CTRL1); + // disable 2MHz oscillator + ctrl1|= 0x01; + QMI8658_transmit(QMI8658_CTRL1, ctrl1); + break; + case sensor_locking: + ctrl1 = QMI8658_receive(QMI8658_CTRL1); + // enable 2MHz oscillator + ctrl1 &= 0xFE; + // enable auto address increment for fast block reads + ctrl1 |= 0x40; + QMI8658_transmit(QMI8658_CTRL1, ctrl1); + + // enable high speed internal clock, + // acc and gyro in full mode, and + // enable syncSample mode + QMI8658_transmit(QMI8658_CTRL7, 0x83); + + // disable AttitudeEngine Motion On Demand + QMI8658_transmit(QMI8658_CTRL6, 0x00); + + // disable internal AHB clock gating: + QMI8658_transmit(QMI8658_CAL1_L, 0x01); + QMI8658_CTRL9_Write(0x12); + // re-enable clock gating + QMI8658_transmit(QMI8658_CAL1_L, 0x00); + QMI8658_CTRL9_Write(0x12); + break; + default: + break; + } + sensor_state = state; +} + + +void getAccelerometer(void) +{ + + uint8_t buf[6]; + I2C_Read(Device_addr, QMI8658_AX_L, buf, 6); + Accel.x = (float)((int16_t)((buf[1]<<8) | (buf[0]))); + Accel.y = (float)((int16_t)((buf[3]<<8) | (buf[2]))); + Accel.z = (float)((int16_t)((buf[5]<<8) | (buf[4]))); + Accel.x = Accel.x * accelScales; + Accel.y = Accel.y * accelScales; + Accel.z = Accel.z * accelScales; + +} +void getGyroscope(void) +{ + uint8_t buf[6]; + I2C_Read(Device_addr, QMI8658_GX_L, buf, 6); + Gyro.x = (float)((int16_t)((buf[1]<<8) | (buf[0]))); + Gyro.y = (float)((int16_t)((buf[3]<<8) | (buf[2]))); + Gyro.z = (float)((int16_t)((buf[5]<<8) | (buf[4]))); + Gyro.x = Gyro.x * gyroScales; + Gyro.y = Gyro.y * gyroScales; + Gyro.z = Gyro.z * gyroScales; +} + + + + + + + + + + + + + + + + + diff --git a/Lib/QMI8658/QMI8658.h b/Lib/QMI8658/QMI8658.h new file mode 100644 index 0000000..fd739ef --- /dev/null +++ b/Lib/QMI8658/QMI8658.h @@ -0,0 +1,161 @@ +#pragma once + +#include "I2C_Driver.h" + +//device address +#define QMI8658_L_SLAVE_ADDRESS (0x6B) +#define QMI8658_H_SLAVE_ADDRESS (0x6A) + +#define QMI8658_WHO_AM_I 0x00 // devide identifier +#define QMI8658_REVISION_ID 0x01 +#define QMI8658_CTRL1 0x02 // SPI interface and sensor enable +#define QMI8658_CTRL2 0x03 // Accelerometer settings +#define QMI8658_CTRL3 0x04 // Gyro settings +#define QMI8658_CTRL4 0x05 // reserved (we don't use this) +#define QMI8658_CTRL5 0x06 // Low-pass filter settings +#define QMI8658_CTRL6 0x07 // AttitudeEngine settings (we don't use these) +#define QMI8658_CTRL7 0x08 // Sensor enable +#define QMI8658_CTRL8 0x09 // Motion detection control (not in current lib version) +#define QMI8658_CTRL9 0x0A // Host commands (not in current lib version) + +#define QMI8658_CAL1_L 0x0B // calibration 1 register, lower bits +#define QMI8658_CAL1_H 0x0C // calibration 1 register, higher bits +#define QMI8658_CAL2_L 0x0D // calibration 2 register, lower bits +#define QMI8658_CAL2_H 0x0E // calibration 2 register, higher bits +#define QMI8658_CAL3_L 0x0F // calibration 3 register, lower bits +#define QMI8658_CAL3_H 0x10 // calibration 3 register, higher bits +#define QMI8658_CAL4_L 0x11 // calibration 4 register, lower bits +#define QMI8658_CAL4_H 0x12 // calibration 4 register, higher bits + +#define QMI8658_TEMP_L 0x33 // lower bits of temperature data +#define QMI8658_TEMP_H 0x34 // upper bits of temperature data + +#define QMI8658_STATUSINT 0x2D // status + interrupt register + +#define QMI8658_AX_L 0x35 // lower bits of x-axis acceleration +#define QMI8658_AX_H 0x36 // upper bits of x-axis acceleration +#define QMI8658_AY_L 0x37 // lower bits of y-axis acceleration +#define QMI8658_AY_H 0x38 // upper bits of y-axis acceleration +#define QMI8658_AZ_L 0x39 +#define QMI8658_AZ_H 0x3A +#define QMI8658_GX_L 0x3B // lower bits of x-axis angular velocity +#define QMI8658_GX_H 0x3C // upper bits of x-axis angular velocity +#define QMI8658_GY_L 0x3D +#define QMI8658_GY_H 0x3E +#define QMI8658_GZ_L 0x3F +#define QMI8658_GZ_H 0x40 + +#define QMI8658_AODR_MASK 0x0F // bits in acc data rate are 1, rest are 0 (CTRL2) +#define QMI8658_GODR_MASK 0x0F // bits in gyro data rate are 1, rest are 0 (CTRL3) +#define QMI8658_ASCALE_MASK 0x70 // bits in acc scale are 1, rest are 0 +#define QMI8658_GSCALE_MASK 0x70 // bits in gyro scale are 1, rest are 0 +#define QMI8658_ALPF_MASK 0x06 // bits in acc low pass filter setting +#define QMI8658_GLPF_MASK 0x60 // bits in gyro low pass filter setting +#define QMI8658_ASCALE_OFFSET 4 // offset to acc scale bits +#define QMI8658_GSCALE_OFFSET 4 // offset to gyro scale bits +#define QMI8658_ALPF_OFFSET 1 // offset to acc low pass filter bits +#define QMI8658_GLPF_OFFSET 5 // offset to gyro low pass filter bits + +#define QMI8658_COMM_TIMEOUT 50 // communication timeout, in ms + + +// delay between refreshes of sensor data in us +// applies to individual sensor readings while in locking mode +// has no effect in running mode +#define QMI8658_REFRESH_DELAY 2000 + +// control clock gating (necessary to use data locking) +#define QMI8658_CTRL_CMD_AHB_CLOCK_GATING 0x12 + + +typedef enum { + acc_odr_norm_8000 = 0x0, + acc_odr_norm_4000, + acc_odr_norm_2000, + acc_odr_norm_1000, + acc_odr_norm_500, + acc_odr_norm_250, + acc_odr_norm_120, + acc_odr_norm_60, + acc_odr_norm_30, + acc_odr_lp_128 = 0xC, + acc_odr_lp_21, + acc_odr_lp_11, + acc_odr_lp_3, +} acc_odr_t; + +typedef enum { + gyro_odr_norm_8000 = 0x0, + gyro_odr_norm_4000, + gyro_odr_norm_2000, + gyro_odr_norm_1000, + gyro_odr_norm_500, + gyro_odr_norm_250, + gyro_odr_norm_120, + gyro_odr_norm_60, + gyro_odr_norm_30 +} gyro_odr_t; + +typedef enum { + ACC_RANGE_2G = 0x0, + ACC_RANGE_4G, + ACC_RANGE_8G, + ACC_RANGE_16G +} acc_scale_t; + +typedef enum { + GYR_RANGE_16DPS = 0x0, + GYR_RANGE_32DPS, + GYR_RANGE_64DPS, + GYR_RANGE_128DPS, + GYR_RANGE_256DPS, + GYR_RANGE_512DPS, + GYR_RANGE_1024DPS +} gyro_scale_t; + +typedef enum { + LPF_MODE_0 = 0x0, //2.66% of ODR + LPF_MODE_1 = 0x2, //3.63% of ODR + LPF_MODE_2 = 0x4, //5.39% of ODR + LPF_MODE_3 = 0x6 //13.37% of ODR +} lpf_t; + +typedef enum { + sensor_default, + sensor_power_down, + sensor_running, + sensor_locking +} sensor_state_t; + +typedef struct __IMUdata { + float x; + float y; + float z; +} IMUdata; + +extern IMUdata Accel; +extern IMUdata Gyro; + +void QMI8658_Init(void); +void QMI8658_Loop(void); +void QMI8658_transmit(uint8_t addr, uint8_t data); +uint8_t QMI8658_receive(uint8_t addr); +void QMI8658_CTRL9_Write(uint8_t command); +void QMI8658_sensor_update(); +void QMI8658_update_if_needed(); +void setAccODR(acc_odr_t odr); +void setGyroODR(gyro_odr_t odr); +void setAccScale(acc_scale_t scale); +void setGyroScale(gyro_scale_t scale); +void setAccLPF(lpf_t lpf); +void setGyroLPF(lpf_t lpf); +void setState(sensor_state_t state); +void getRawReadings(int16_t* buf); +float getAccX(); +float getAccY(); +float getAccZ(); +float getGyroX(); +float getGyroY(); +float getGyroZ(); +void getAccelerometer(void); +void getGyroscope(void); \ No newline at end of file diff --git a/Lib/README.md b/Lib/README.md new file mode 100644 index 0000000..f7608bc --- /dev/null +++ b/Lib/README.md @@ -0,0 +1,3 @@ +### 本目录为各种外设驱动库,部分驱动库之间存在依赖关系,会在下面有所说明 + +#### 1. \ No newline at end of file diff --git a/main/Bionic_sphere.c b/main/Bionic_sphere.c index 3f73ee3..8522429 100644 --- a/main/Bionic_sphere.c +++ b/main/Bionic_sphere.c @@ -3,7 +3,10 @@ #include +#include + + void app_main(void) { - ESP_LOGI("main", "Now is Misaki"); + imu_test(); // imu测试 } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index b1a9b66..e4587b9 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,9 @@ idf_component_register(SRCS "Bionic_sphere.c" - INCLUDE_DIRS ".") + "../test/driver_test/drivers_test.c" # 测试用例 + "../Lib/I2C_Driver/I2C_Driver.c" # IIC底层驱动库 + "../Lib/QMI8658/QMI8658.c" # IMU驱动库 + INCLUDE_DIRS "." + "../test/driver_test" + "../Lib/I2C_Driver" + "../Lib/QMI8658" +) diff --git a/test/driver_test/drivers_test.c b/test/driver_test/drivers_test.c new file mode 100644 index 0000000..7e451c7 --- /dev/null +++ b/test/driver_test/drivers_test.c @@ -0,0 +1,21 @@ +// +// Created by misaki on 2025/8/23. +// + +#include + + +#include +#include +extern IMUdata Accel; +extern IMUdata Gyro; +void imu_test(void) +{ + I2C_Init(); + QMI8658_Init(); + while (1) { + QMI8658_Loop(); + ESP_LOGI("app_main", "Accel x: %f, y: %f, z: %f", Accel.x, Accel.y, Accel.z); + ESP_LOGD("app_main", "Gyro X: %f, Y: %f, Z: %f", Gyro.x, Gyro.y, Gyro.z); + } +} diff --git a/test/driver_test/drivers_test.h b/test/driver_test/drivers_test.h new file mode 100644 index 0000000..a620b27 --- /dev/null +++ b/test/driver_test/drivers_test.h @@ -0,0 +1,12 @@ +// +// Created by misaki on 2025/8/23. +// + +#ifndef BIONIC_SPHERE_DRIVERS_TEST_H +#define BIONIC_SPHERE_DRIVERS_TEST_H + +// imu测试 +void imu_test(void); + + +#endif //BIONIC_SPHERE_DRIVERS_TEST_H \ No newline at end of file diff --git a/项目开发日志.md b/项目开发日志.md index 2a5cb8e..14b07ef 100644 --- a/项目开发日志.md +++ b/项目开发日志.md @@ -2,5 +2,9 @@ #### 此文件用于记录本项目开发过程中所一步步完成的事情,以及遇到的一些问题及其对应的解决方案 +#### 2025.8.22 ~ 8.24 官方驱动测试 #### Day1 2025.8.22 -##### 测试开发板官方提供的例程中的驱动能否使用 +##### 主要目标:测试开发板官方提供的例程中的驱动能否使用 +实际完成任务: +- [x] 1. 实现了Linux下的esp idf的一键编译,烧录,与监视,并且监视具有交互能力 +- [x] 2. 测试了QMI8658的驱动,正常读出x,y,z轴数据,得到的pitch, roll, yaw正常