Init: 导入AvaotaF1客户端源码

This commit is contained in:
Kevin Wong
2025-12-31 15:13:39 +08:00
parent 77acf96967
commit cadb16dfce
30 changed files with 7982 additions and 36 deletions

95
ESP32S3/ICM42688.cpp Normal file
View File

@@ -0,0 +1,95 @@
// --- START OF ICM42688.cpp ---
#include "ICM42688.h"
ICM42688::ICM42688(TwoWire &bus, uint8_t address) {
_bus = &bus;
_address = address;
_accelScale = 0.0f;
_gyroScale = 0.0f;
}
int ICM42688::begin() {
uint8_t who_am_i = 0;
readRegisters(ICM42688_WHO_AM_I, 1, &who_am_i);
if(who_am_i != ICM42688_DEVICE_ID) {
return -1; // Wrong device
}
// Reset device
writeRegister(0x4E, 0x01);
delay(100);
// Set accel and gyro to standby
writeRegister(0x4E, 0x1F);
delay(1);
// Set accel full scale
writeRegister(0x4F, (uint8_t)AFS::AFS_16G << 5 | (uint8_t)ODR::ODR_1KHZ);
_accelScale = 16.0f / 32768.0f;
// Set gyro full scale
writeRegister(0x50, (uint8_t)GFS::GFS_2000DPS << 5 | (uint8_t)ODR::ODR_1KHZ);
_gyroScale = 2000.0f / 32768.0f;
// Turn on accel and gyro
writeRegister(0x4E, 0x0F);
delay(100);
return 0;
}
int ICM42688::readSensor() {
uint8_t data[14];
readRegisters(0x1D, 14, data);
_t = (int16_t)data[0] << 8 | data[1];
_ax = (int16_t)data[2] << 8 | data[3];
_ay = (int16_t)data[4] << 8 | data[5];
_az = (int16_t)data[6] << 8 | data[7];
_gx = (int16_t)data[8] << 8 | data[9];
_gy = (int16_t)data[10] << 8 | data[11];
_gz = (int16_t)data[12] << 8 | data[13];
return 0;
}
float ICM42688::getAccelX_mss() { return (float)_ax * _accelScale * _G; }
float ICM42688::getAccelY_mss() { return (float)_ay * _accelScale * _G; }
float ICM42688::getAccelZ_mss() { return (float)_az * _accelScale * _G; }
float ICM42688::getGyroX_rads() { return (float)_gx * _gyroScale * _d2r; }
float ICM42688::getGyroY_rads() { return (float)_gy * _gyroScale * _d2r; }
float ICM42688::getGyroZ_rads() { return (float)_gz * _gyroScale * _d2r; }
float ICM42688::getGyroX_dps() { return (float)_gx * _gyroScale; }
float ICM42688::getGyroY_dps() { return (float)_gy * _gyroScale; }
float ICM42688::getGyroZ_dps() { return (float)_gz * _gyroScale; }
float ICM42688::getTemperature_C() { return ((float)_t / _tempScale) + _tempOffset; }
void ICM42688::writeRegister(uint8_t reg, uint8_t data) {
_bus->beginTransmission(_address);
_bus->write(reg);
_bus->write(data);
_bus->endTransmission();
}
uint8_t ICM42688::readRegister(uint8_t reg) {
_bus->beginTransmission(_address);
_bus->write(reg);
_bus->endTransmission(false);
_bus->requestFrom(_address, (uint8_t)1);
uint8_t data = _bus->read();
return data;
}
void ICM42688::readRegisters(uint8_t reg, uint8_t count, uint8_t *dest) {
_bus->beginTransmission(_address);
_bus->write(reg);
_bus->endTransmission(false);
_bus->requestFrom(_address, count);
for(uint8_t i = 0; i < count; i++){
dest[i] = _bus->read();
}
}
// --- END OF ICM42688.cpp ---

85
ESP32S3/ICM42688.h Normal file
View File

@@ -0,0 +1,85 @@
// --- START OF ICM42688.h ---
#ifndef ICM42688_H
#define ICM42688_H
#include "Arduino.h"
#include "Wire.h"
#include "SPI.h"
// See datasheet for details
#define ICM42688_DEVICE_ID 0x47
#define ICM42688_WHO_AM_I 0x75
/*
ICM42688_I2C class definition
*/
class ICM42688
{
public:
enum class AFS {
AFS_16G = 0,
AFS_8G,
AFS_4G,
AFS_2G
};
enum class GFS {
GFS_2000DPS = 0,
GFS_1000DPS,
GFS_500DPS,
GFS_250DPS,
GFS_125DPS,
GFS_62_5DPS,
GFS_31_25DPS,
GFS_15_625DPS
};
enum class ODR {
ODR_32KHZ = 0x01,
ODR_16KHZ = 0x02,
ODR_8KHZ = 0x03,
ODR_4KHZ = 0x04,
ODR_2KHZ = 0x05,
ODR_1KHZ = 0x06,
ODR_200HZ = 0x07,
ODR_100HZ = 0x08,
ODR_50HZ = 0x09,
ODR_25HZ = 0x0A,
ODR_12_5HZ = 0x0B,
ODR_500HZ = 0x0F
};
ICM42688(TwoWire &bus, uint8_t address);
int begin();
int readSensor();
float getAccelX_mss();
float getAccelY_mss();
float getAccelZ_mss();
float getGyroX_rads();
float getGyroY_rads();
float getGyroZ_rads();
float getGyroX_dps();
float getGyroY_dps();
float getGyroZ_dps();
float getTemperature_C();
private:
TwoWire *_bus;
uint8_t _address;
float _accelScale;
float _gyroScale;
const float _tempScale = 333.87f;
const float _tempOffset = 21.0f;
const float _G = 9.807f;
const float _d2r = 3.14159265359f/180.0f;
int16_t _ax, _ay, _az;
int16_t _gx, _gy, _gz;
int16_t _t;
void writeRegister(uint8_t reg, uint8_t data);
uint8_t readRegister(uint8_t reg);
void readRegisters(uint8_t reg, uint8_t count, uint8_t *dest);
};
#endif
// --- END OF ICM42688.h ---

60
ESP32S3/camera_pins.h Normal file
View File

@@ -0,0 +1,60 @@
#if defined(CAMERA_MODEL_XIAO_ESP32S3)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 10
#define SIOD_GPIO_NUM 40
#define SIOC_GPIO_NUM 39
#define Y9_GPIO_NUM 48
#define Y8_GPIO_NUM 11
#define Y7_GPIO_NUM 12
#define Y6_GPIO_NUM 14
#define Y5_GPIO_NUM 16
#define Y4_GPIO_NUM 18
#define Y3_GPIO_NUM 17
#define Y2_GPIO_NUM 15
#define VSYNC_GPIO_NUM 38
#define HREF_GPIO_NUM 47
#define PCLK_GPIO_NUM 13
#elif defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#elif defined(CAMERA_MODEL_M5STACK_PSRAM)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM 15
#define XCLK_GPIO_NUM 27
#define SIOD_GPIO_NUM 25
#define SIOC_GPIO_NUM 23
#define Y9_GPIO_NUM 19
#define Y8_GPIO_NUM 36
#define Y7_GPIO_NUM 18
#define Y6_GPIO_NUM 39
#define Y5_GPIO_NUM 5
#define Y4_GPIO_NUM 34
#define Y3_GPIO_NUM 35
#define Y2_GPIO_NUM 32
#define VSYNC_GPIO_NUM 22
#define HREF_GPIO_NUM 26
#define PCLK_GPIO_NUM 21
#else
#error "Camera model not selected"
#endif

1014
ESP32S3/compile.ino Normal file

File diff suppressed because it is too large Load Diff