M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
imu_detect.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
19#ifndef M5_UNIT_IMU_IMU_IMU_DETECT_HPP
20#define M5_UNIT_IMU_IMU_IMU_DETECT_HPP
21
22#include <cstdint>
23#include <initializer_list>
24
25namespace m5 {
26namespace unit {
27namespace imu {
28
30enum class ImuKind : uint8_t {
31 None,
32 MPU6050,
33 MPU6886,
34 MPU9250,
35 BMI270,
36 SH200Q,
37};
38
50template <class ReadReg>
52{
53 uint8_t id{};
54
55 // MPU family: WHO_AM_I at 0x68 register 0x75.
56 if (read(static_cast<uint8_t>(0x68), static_cast<uint8_t>(0x75), id)) {
57 switch (id) {
58 case 0x19:
59 return ImuKind::MPU6886;
60 case 0x68:
61 return ImuKind::MPU6050;
62 case 0x71:
63 return ImuKind::MPU9250;
64 default:
65 break; // not a known MPU id -> fall through to the BMI270 probe (BMI270 lives at 0x68 too)
66 }
67 }
68
69 // BMI270: CHIP_ID 0x24 at register 0x00, on either candidate address.
70 for (const uint8_t candidate : {static_cast<uint8_t>(0x68), static_cast<uint8_t>(0x69)}) {
71 if (read(candidate, static_cast<uint8_t>(0x00), id) && id == 0x24) {
72 return ImuKind::BMI270;
73 }
74 }
75
76 // SH200Q: WHO_AM_I 0x18 at 0x6C register 0x30.
77 if (read(static_cast<uint8_t>(0x6C), static_cast<uint8_t>(0x30), id) && id == 0x18) {
78 return ImuKind::SH200Q;
79 }
80
81 return ImuKind::None;
82}
83
84} // namespace imu
85} // namespace unit
86} // namespace m5
87#endif
ImuKind
Which built-in accel/gyro chip a host carries.
Definition imu_detect.hpp:30
@ MPU9250
InvenSense MPU9250 at 0x68 (WHO_AM_I 0x71), with an internal AK8963 mag.
@ SH200Q
Senodia SH200Q at 0x6C (WHO_AM_I 0x18)
@ MPU6886
InvenSense MPU6886 at 0x68 (WHO_AM_I 0x19)
@ None
No accel/gyro responded (e.g. an IMU-less M5Stack Basic)
@ BMI270
Bosch BMI270 at 0x68 or 0x69 (CHIP_ID 0x24)
@ MPU6050
InvenSense MPU6050 at 0x68 (WHO_AM_I 0x68)
ImuKind detectBuiltinImu(ReadReg read)
Probe the internal bus for a built-in accel/gyro chip.
Definition imu_detect.hpp:51
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26
Unit-related namespace.