M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
m5_unit_imu_wiring.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
15#ifndef M5_UNIT_IMU_WIRING_M5_UNIT_IMU_WIRING_HPP
16#define M5_UNIT_IMU_WIRING_M5_UNIT_IMU_WIRING_HPP
17
18#include <M5Unified.h>
19#include <M5UnitUnified.h>
20
22// HP (high-performance) I2C port count: IDF >= 5.2 splits HP/LP counts (SOC_HP_I2C_NUM); older
23// cores (e.g. Arduino core 2.x on IDF 4.4) only define SOC_I2C_NUM, which IS the HP count there.
24#if defined(SOC_HP_I2C_NUM)
25#define M5_UNIT_IMU_HP_I2C_NUM SOC_HP_I2C_NUM
26#else
27#define M5_UNIT_IMU_HP_I2C_NUM SOC_I2C_NUM
28#endif
30
31namespace m5 {
32namespace unit {
33namespace imu {
34namespace wiring {
35
59inline bool i2cPortC(m5::unit::UnitUnified& units, m5::unit::Component& u, const bool bus_ready = false)
60{
61 const int sda = M5.getPin(m5::pin_name_t::port_c_pin2);
62 const int scl = M5.getPin(m5::pin_name_t::port_c_pin1);
63 if (sda < 0 || scl < 0) {
64 return false; // no Port C on this board (needs the M5GO/Fire base)
65 }
66#if M5_UNIT_IMU_HP_I2C_NUM >= 2
67 static m5::I2C_Class port_c_i2c;
68 if (!bus_ready && !port_c_i2c.begin(I2C_NUM_1, sda, scl)) {
69 return false;
70 }
71 return units.add(u, port_c_i2c);
72#else
73 (void)units;
74 (void)bus_ready;
75 return false; // single-HP-I2C SoC: never a classic Core
76#endif
77}
78
79} // namespace wiring
80} // namespace imu
81} // namespace unit
82} // namespace m5
83#endif
bool i2cPortC(m5::unit::UnitUnified &units, m5::unit::Component &u, const bool bus_ready=false)
Route a GROVE unit to classic M5Stack Core Port C on a dedicated I2C bus.
Definition m5_unit_imu_wiring.hpp:59
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26
Unit-related namespace.