Skip to content

Commit

Permalink
Add UnitPAJ7620U2(WIP)
Browse files Browse the repository at this point in the history
GOB52 committed Jun 19, 2024
1 parent d4caa79 commit 1f0fbbd
Showing 8 changed files with 3,240 additions and 1 deletion.
116 changes: 116 additions & 0 deletions examples/UnitGesture/gesture/gesture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Example using M5UnitUnified for PAJ7620U2
SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
SPDX-License-Identifier: MIT
*/

// #define USING_PAHUB (2) // Connection channel number for use via PaHub.
// #define USING_M5HAL // When using M5HAL

#include <M5Unified.h>
#include <M5UnitUnified.h>
#include <unit/unit_PAJ7620U2.hpp>
#if defined(USING_PAHUB)
#include <unit/unit_PaHub.hpp>
#endif

namespace {
auto& lcd = M5.Display;

m5::unit::UnitUnified Units;
m5::unit::UnitPAJ7620U2 unit;
#if defined(USING_PAHUB)
m5::unit::UnitPaHub unitPaHub;
#endif

} // namespace

void setup() {
M5.begin();

auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);

#if defined(USING_PAHUB)
#pragma message "Using via PaHub"
// Using via PaHub
#if defined(USING_M5HAL)
#pragma message "Using M5HAL"
// Using M5HAL
m5::hal::bus::I2CBusConfig i2c_cfg;
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);

if (!unitPaHub.add(unit, USING_PAHUB) ||
!Units.add(unitPaHub, i2c_bus ? i2c_bus.value() : nullptr) ||
!Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#else
// Using TwoWire
#pragma message "Using Wire"
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
if (!unitPaHub.add(unit, USING_PAHUB) || !Units.add(unitPaHub, Wire) ||
!Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#endif

#else
// Direct connection
#pragma message "Direct connection"
#if defined(USING_M5HAL)
#pragma message "Using M5HAL"
// Using M5HAL
m5::hal::bus::I2CBusConfig i2c_cfg;
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
if (!Units.add(unit, i2c_bus ? i2c_bus.value() : nullptr) ||
!Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#else
#pragma message "Using Wire"
// Using TwoWire
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
if (!Units.add(unit, Wire) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#endif
#endif

M5_LOGI("M5UnitUnified has been begun");
M5_LOGI("%s", Units.debugInfo().c_str());

lcd.clear(TFT_DARKGREEN);
}

void loop() {
M5.update();
Units.update();
if (unit.updated()) {
M5_LOGI("gesture:%x", unit.gesture());

}
}
Loading

0 comments on commit 1f0fbbd

Please sign in to comment.