void MPU6000_SPI::set_bus_frequency(unsigned ®_speed) { /* Set the desired speed */ set_frequency(MPU6000_IS_HIGH_SPEED(reg_speed) ? MPU6000_HIGH_SPI_BUS_SPEED : MPU6000_LOW_SPI_BUS_SPEED); /* Isoolate the register on return */ reg_speed = MPU6000_REG(reg_speed); }
int MPU6000_I2C::write(unsigned reg_speed, void *data, unsigned count) { uint8_t cmd[MPU_MAX_WRITE_BUFFER_SIZE]; if (sizeof(cmd) < (count + 1)) { return -EIO; } cmd[0] = MPU6000_REG(reg_speed); cmd[1] = *(uint8_t *)data; return transfer(&cmd[0], count + 1, nullptr, 0); }
int MPU6000_I2C::read(unsigned reg_speed, void *data, unsigned count) { /* We want to avoid copying the data of MPUReport: So if the caller * supplies a buffer not MPUReport in size, it is assume to be a reg or * reg 16 read * Since MPUReport has a cmd at front, we must return the data * after that. Foe anthing else we must return it */ uint32_t offset = count < sizeof(MPUReport) ? 0 : offsetof(MPUReport, status); uint8_t cmd = MPU6000_REG(reg_speed); int ret = transfer(&cmd, 1, &((uint8_t *)data)[offset], count); return ret == OK ? count : ret; }