10#ifndef M5_UNIT_GESTURE_UNIT_PAJ7620U2_HPP
11#define M5_UNIT_GESTURE_UNIT_PAJ7620U2_HPP
13#include <M5UnitComponent.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
86 std::array<uint8_t, 2 + 4> raw{};
91 uint8_t proximity_brightness;
92 bool proximity_approach;
95 uint16_t cursor_x{}, cursor_y{};
114 return (data_mode == Mode::Proximity) ? proximity_brightness : 0;
119 return (data_mode == Mode::Proximity) ? proximity_approach :
false;
127 return (data_mode == Mode::Cursor) ? cursor_x : 0xFFFF;
132 return (data_mode == Mode::Cursor) ? cursor_y : 0xFFFF;
143class UnitPAJ7620U2 :
public Component,
public PeriodicMeasurementAdapter<UnitPAJ7620U2, paj7620u2::Data> {
169 : Component(addr), _data{new
m5::container::CircularBuffer<
paj7620u2::Data>(1)}
171 auto ccfg = component_config();
172 ccfg.clock = 400 * 1000U;
173 component_config(ccfg);
175 virtual ~UnitPAJ7620U2()
179 virtual bool begin()
override;
180 virtual void update(
const bool force =
false)
override;
201 return !empty() ? oldest().gesture() : paj7620u2::Gesture::None;
206 return !empty() ? oldest().brightness() : 0;
211 return !empty() ? oldest().approach() :
false;
216 return !empty() ? oldest().cursorX() : 0xFFFF;
221 return !empty() ? oldest().cursorY() : 0xFFFF;
234 return PeriodicMeasurementAdapter<UnitPAJ7620U2, paj7620u2::Data>::startPeriodicMeasurement(intervalMs);
244 const uint32_t intervalMs)
246 return PeriodicMeasurementAdapter<UnitPAJ7620U2, paj7620u2::Data>::startPeriodicMeasurement(intervalMs);
254 return PeriodicMeasurementAdapter<UnitPAJ7620U2, paj7620u2::Data>::stopPeriodicMeasurement();
280 _rotation = rot & 0x03;
429 bool enable(
const bool flag);
447 bool start_periodic_measurement(
const uint32_t intervalMs = 0);
449 const uint32_t intervalMs);
450 bool stop_periodic_measurement();
454 bool select_bank(
const uint8_t bank,
const bool force =
false);
456 bool read_banked_register(
const uint16_t reg, uint8_t* buf,
const size_t len);
457 bool read_banked_register8(
const uint16_t reg, uint8_t& value);
458 bool read_banked_register16(
const uint16_t reg, uint16_t& value);
459 bool write_banked_register(
const uint16_t reg,
const uint8_t* buf,
const size_t len);
460 bool write_banked_register8(
const uint16_t reg,
const uint8_t value);
461 bool write_banked_register16(
const uint16_t reg,
const uint16_t value);
472 bool read_chip_id(uint16_t&
id);
473 bool read_version(uint8_t& version);
476 uint8_t _current_bank{0xFF};
477 paj7620u2::Mode _mode{};
478 paj7620u2::Frequency _frequency{};
481 std::unique_ptr<m5::container::CircularBuffer<paj7620u2::Data>> _data{};
490constexpr uint8_t BANK_SEL{0xEF};
493constexpr uint16_t PART_ID_LOW{0x0000};
494constexpr uint16_t PART_ID_HIGH{0x0001};
495constexpr uint16_t VERSION_ID{0x0002};
496constexpr uint16_t SW_SUSPEND_ENL{0x0003};
498constexpr uint16_t CURSOR_CLAMP_CENTER_X_LOW{0X003B};
499constexpr uint16_t CURSOR_CLAMP_CENTER_X_HIGH{0X003C};
500constexpr uint16_t CURSOR_CLAMP_CENTER_Y_LOW{0X003D};
501constexpr uint16_t CURSOR_CLAMP_CENTER_Y_HIGH{0X003E};
503constexpr uint16_t INT_FLAG_1{0x0043};
504constexpr uint16_t INT_FLAG_2{0x0044};
506const uint16_t R_POX_UB{0X0069};
507const uint16_t R_POX_LB{0X006A};
508constexpr uint16_t S_STATE{0x006B};
509constexpr uint16_t S_AVGY{0x006C};
511constexpr uint16_t OBJECT_CENTER_X_LOW{0X00AC};
512constexpr uint16_t OBJECT_CENTER_X_HIGH{0X00AD};
513constexpr uint16_t OBJECT_CENTER_Y_LOW{0X00AE};
514constexpr uint16_t OBJECT_CENTER_Y_HIGH{0X00AF};
516constexpr uint16_t OBJECT_AVG_Y{0X00B0};
517constexpr uint16_t OBJECT_SIZE_LOW{0x00B1};
518constexpr uint16_t OBJECT_SIZE_HIGH{0x00B2};
519constexpr uint16_t WAVE_ABORT_COUNT{0x00B7};
520constexpr uint16_t NO_OBJECT_COUNT{0x00B8};
521constexpr uint16_t NO_MOTION_COUNT{0x00B9};
523constexpr uint16_t VEL_X_LOW{0x00C3};
524constexpr uint16_t VEL_X_HIGH{0x00C4};
525constexpr uint16_t VEL_Y_LOW{0x00C3};
526constexpr uint16_t VEL_Y_HIGH{0x00C4};
529constexpr uint16_t LS_COMP_DAVG_V{0x0104};
530constexpr uint16_t R_REF_CLK_CNT_LOW{0x0165};
531constexpr uint16_t R_TG_ENH{0x0172};
PAJ7620U2 unit.
Definition unit_PAJ7620U2.hpp:143
bool readProximity(uint8_t &brightness, uint8_t &approach)
Read proximity.
Definition unit_PAJ7620U2.cpp:516
bool readNoObjectCount(uint8_t &cnt)
State counter with no objects detected.
Definition unit_PAJ7620U2.cpp:498
paj7620u2::Frequency frequency() const
Gets the inner frequency.
Definition unit_PAJ7620U2.hpp:284
bool startPeriodicMeasurement(const paj7620u2::Mode mode, const paj7620u2::Frequency freq, const uint32_t intervalMs)
Start periodic measurement.
Definition unit_PAJ7620U2.hpp:243
uint8_t brightness() const
Oldest brightness if Proximity mode.
Definition unit_PAJ7620U2.hpp:204
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_PAJ7620U2.hpp:252
bool writeApproachThreshold(const uint8_t high, const uint8_t low)
Write the threshold for detect approach.
Definition unit_PAJ7620U2.cpp:636
void setRotate(const uint8_t rot)
Set the roptation.
Definition unit_PAJ7620U2.hpp:278
bool resume()
resume from suspended
Definition unit_PAJ7620U2.cpp:563
bool readGesture(paj7620u2::Gesture &gesture)
Read gesture.
Definition unit_PAJ7620U2.cpp:487
config_t config()
Gets the configration.
Definition unit_PAJ7620U2.hpp:185
void config(const config_t &cfg)
Set the configration.
Definition unit_PAJ7620U2.hpp:190
bool enable()
enable sensor
Definition unit_PAJ7620U2.hpp:431
bool writeVerticalFlip(const bool flip)
Write the vertical flipping.
Definition unit_PAJ7620U2.cpp:673
bool disable()
disable sensor
Definition unit_PAJ7620U2.hpp:436
bool readApproachThreshold(uint8_t &high, uint8_t &low)
Read the threshold for detect approach.
Definition unit_PAJ7620U2.cpp:631
bool readCursor(uint16_t &x, uint16_t &y)
Cursor position.
Definition unit_PAJ7620U2.cpp:541
bool readNoMotionCount(uint8_t &cnt)
State counter which a non-moving object is detected.
Definition unit_PAJ7620U2.cpp:504
bool readVerticalFlip(bool &flip)
Read the vertical flipping.
Definition unit_PAJ7620U2.cpp:652
bool suspend()
suspend
Definition unit_PAJ7620U2.cpp:558
bool writeHorizontalFlip(const bool flip)
Write the horizontal flipping.
Definition unit_PAJ7620U2.cpp:663
paj7620u2::Mode mode() const
Gets the detection mode.
Definition unit_PAJ7620U2.hpp:401
bool startPeriodicMeasurement(const uint32_t intervalMs=0)
Start periodic measurement in the current settings.
Definition unit_PAJ7620U2.hpp:232
bool writeFrequency(const paj7620u2::Frequency f)
Write the frequency.
Definition unit_PAJ7620U2.cpp:592
bool approach() const
Oldest approach status if Proximity mode.
Definition unit_PAJ7620U2.hpp:209
bool existsObject(bool &exists)
Is the object present within the detection range?
Definition unit_PAJ7620U2.hpp:333
bool readObjectCenter(uint16_t &x, uint16_t &y)
Object center position.
Definition unit_PAJ7620U2.cpp:528
bool readFrequency(uint8_t &raw)
Read the raw frequency.
Definition unit_PAJ7620U2.cpp:568
uint8_t rotation() const
Get the rotation.
Definition unit_PAJ7620U2.hpp:263
bool readHorizontalFlip(bool &flip)
Read the horizontal flipping.
Definition unit_PAJ7620U2.cpp:641
bool writeMode(const paj7620u2::Mode m)
Write the detection mode.
Definition unit_PAJ7620U2.cpp:601
uint16_t cursorY() const
Oldest cursor Y if Cursor mode.
Definition unit_PAJ7620U2.hpp:219
bool readObjectSize(uint16_t &sz)
Read gesture object size.
Definition unit_PAJ7620U2.cpp:510
uint16_t cursorX() const
Oldest cursor X if Cursor mode.
Definition unit_PAJ7620U2.hpp:214
paj7620u2::Gesture gesture() const
Oldest gesture.
Definition unit_PAJ7620U2.hpp:199
Top level namespace of M5stack.
Settings for begin.
Definition unit_PAJ7620U2.hpp:151
bool vflip
Flip verticl if start on bein.
Definition unit_PAJ7620U2.hpp:161
paj7620u2::Mode mode
Mode if start on bein.
Definition unit_PAJ7620U2.hpp:155
bool hflip
Flip horizontal if start on bein.
Definition unit_PAJ7620U2.hpp:159
bool start_periodic
Start periodic measurement on begin?
Definition unit_PAJ7620U2.hpp:153
uint8_t rotation
Rotation if start on begin.
Definition unit_PAJ7620U2.hpp:163
paj7620u2::Frequency frequency
Frequency if start on bein.
Definition unit_PAJ7620U2.hpp:157
bool store_on_change
Store only when value is a change.
Definition unit_PAJ7620U2.hpp:165
Measurement data group.
Definition unit_PAJ7620U2.hpp:76
Mode mode() const
Gets the operation mode.
Definition unit_PAJ7620U2.hpp:100
bool approach() const
Detect the approach?
Definition unit_PAJ7620U2.hpp:117
uint16_t cursorX() const
Gets the cursor X the any object.
Definition unit_PAJ7620U2.hpp:125
uint8_t brightness() const
Gets the brightness.
Definition unit_PAJ7620U2.hpp:112
Gesture gesture() const
Gets the gesture (Common)
Definition unit_PAJ7620U2.hpp:105
uint16_t cursorY() const
Gets the cursor Y the any object.
Definition unit_PAJ7620U2.hpp:130
Frequency
Frequency Operating frequency.
Definition unit_PAJ7620U2.hpp:66
Gesture
Gesture type.
Definition unit_PAJ7620U2.hpp:32
@ NoObject
No object (cursor mode)
@ Approach
Approach (proximity mode)
@ HasObject
Has object (cursor mode)
@ Forward
Closer to the sensor.
@ Confirm
Confirm (confirm mode)
@ Abort
Abort (confirm mode)
@ CounterClockwise
Counter clock wise.
@ WakeupTrigger
Wakeup (trigger mode)
@ Backward
Away from the sensor.
Mode
Operation Mode.
Definition unit_PAJ7620U2.hpp:56
@ Cursor
Detect XY cordinate.
@ Proximity
Detect proximity.