mpu9250: add MPU6500 (#5767)

Signed-off-by: Yifei Ding <yifeiding@protonmail.com>
This commit is contained in:
Yifei Ding 2022-11-19 06:58:24 -08:00 committed by GitHub
parent 8a06528747
commit d17ef95a3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 23 deletions

View file

@ -9,8 +9,16 @@ from . import bus, motion_report, adxl345
MPU9250_ADDR = 0x68
MPU9250_DEV_ID = 0x73
MPU6050_DEV_ID = 0x68
MPU_DEV_IDS = {
0x74: "mpu-9515",
0x73: "mpu-9255",
0x71: "mpu-9250",
0x70: "mpu-6500",
0x68: "mpu-6050",
#everything above are normal MPU IDs
0x75: "mpu-unknown (DEFECTIVE! USE WITH CAUTION!)",
0x69: "mpu-unknown (DEFECTIVE! USE WITH CAUTION!)",
}
# MPU9250 registers
REG_DEVID = 0x75
@ -189,12 +197,14 @@ class MPU9250:
# In case of miswiring, testing MPU9250 device ID prevents treating
# noise or wrong signal as a correctly initialized device
dev_id = self.read_reg(REG_DEVID)
if dev_id != MPU9250_DEV_ID and dev_id != MPU6050_DEV_ID:
if dev_id not in MPU_DEV_IDS.keys():
raise self.printer.command_error(
"Invalid mpu9250/mpu6050 id (got %x).\n"
"Invalid mpu id (got %x).\n"
"This is generally indicative of connection problems\n"
"(e.g. faulty wiring) or a faulty chip."
% (dev_id))
else:
logging.info("Found %s with id %x"% (MPU_DEV_IDS[dev_id], dev_id))
# Setup chip in requested query rate
self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_WAKE)
self.set_reg(REG_PWR_MGMT_2, SET_PWR_MGMT_2_ACCEL_ON)