49 #define DIR_WRITE 0x00 51 #if defined(PX4_SPIDEV_MPU) || defined(PX4_SPIDEV_ICM_20602) || defined(PX4_SPIDEV_ICM_20689) 68 #define MPU6000_LOW_SPI_BUS_SPEED 1000*1000 69 #define MPU6000_HIGH_SPI_BUS_SPEED 20*1000*1000 70 #define ICM20608_HIGH_SPI_BUS_SPEED 8*1000*1000 71 #define ICM20689_HIGH_SPI_BUS_SPEED 8*1000*1000 72 #define ICM20602_HIGH_SPI_BUS_SPEED 10*1000*1000 73 #define UNKNOWN_HIGH_SPI_BUS_SPEED 8*1000*1000 // Use the minimum 79 class MPU6000_SPI :
public device::SPI
82 MPU6000_SPI(
int bus, uint32_t
device,
int device_type);
83 ~MPU6000_SPI()
override =
default;
85 int read(
unsigned address,
void *
data,
unsigned count)
override;
86 int write(
unsigned address,
void *
data,
unsigned count)
override;
97 void set_bus_frequency(
unsigned ®_speed_reg_out);
103 int cs = SPIDEV_NONE(0);
108 #if defined(PX4_SPI_BUS_EXT) || defined(PX4_SPI_BUS_EXTERNAL) 110 switch (device_type) {
113 # if defined(PX4_SPIDEV_EXT_MPU) 114 cs = PX4_SPIDEV_EXT_MPU;
119 # if defined(PX4_SPIDEV_ICM_20602_EXT) 120 cs = PX4_SPIDEV_ICM_20602_EXT;
125 # if defined(PX4_SPIDEV_EXT_ICM) 126 cs = PX4_SPIDEV_EXT_ICM;
127 # elif defined(PX4_SPIDEV_ICM_20608_EXT) 128 cs = PX4_SPIDEV_ICM_20608_EXT;
133 # if defined(PX4_SPIDEV_ICM_20689_EXT) 134 cs = PX4_SPIDEV_ICM_20689_EXT;
146 switch (device_type) {
149 #if defined(PX4_SPIDEV_MPU) 155 #if defined(PX4_SPIDEV_ICM_20602) 156 cs = PX4_SPIDEV_ICM_20602;
161 #if defined(PX4_SPIDEV_ICM_20608) 162 cs = PX4_SPIDEV_ICM_20608;
167 # if defined(PX4_SPIDEV_ICM_20689) 168 cs = PX4_SPIDEV_ICM_20689;
176 if (cs != SPIDEV_NONE(0)) {
177 interface = new MPU6000_SPI(bus, cs, device_type);
183 MPU6000_SPI::MPU6000_SPI(
int bus, uint32_t
device,
int device_type) :
184 SPI(
"MPU6000", nullptr, bus, device,
SPIDEV_MODE3, MPU6000_LOW_SPI_BUS_SPEED),
185 _device_type(device_type)
190 MPU6000_SPI::set_bus_frequency(
unsigned ®_speed)
204 if (
sizeof(cmd) < (count + 1)) {
209 set_bus_frequency(reg_speed);
212 cmd[1] = *(uint8_t *)data;
214 return transfer(&cmd[0], &cmd[0], count + 1);
225 uint8_t cmd[3] = {0, 0, 0};
227 uint8_t *pbuff = count <
sizeof(
MPUReport) ? cmd : (uint8_t *)
data ;
234 set_bus_frequency(reg_speed);
240 int ret = transfer(pbuff, pbuff, count);
242 if (ret ==
OK && pbuff == &cmd[0]) {
248 memcpy(data, &cmd[1], count);
252 return ret ==
OK ? count : ret;
260 _max_frequency = UNKNOWN_HIGH_SPI_BUS_SPEED;
262 switch (_device_type) {
266 _max_frequency = MPU6000_HIGH_SPI_BUS_SPEED;
271 _max_frequency = ICM20602_HIGH_SPI_BUS_SPEED;
276 _max_frequency = ICM20608_HIGH_SPI_BUS_SPEED;
281 _max_frequency = ICM20689_HIGH_SPI_BUS_SPEED;
288 #endif // PX4_SPIDEV_MPU
device::Device * MPU6000_SPI_interface(int bus, int device_type, bool external_bus)
#define MPU_MAX_WRITE_BUFFER_SIZE
Namespace encapsulating all device framework classes, functions and data.
#define MPU6000_IS_HIGH_SPEED(r)
static void read(bootloader_app_shared_t *pshared)
Report conversation within the mpu, including command byte and interrupt status.
static void write(bootloader_app_shared_t *pshared)
Fundamental base class for all physical drivers (I2C, SPI).