SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
SensorPawA350 Class Reference

PAW-A350 Optical Finger Navigation Sensor Driver. More...

#include <SensorPawA350.hpp>

Inheritance diagram for SensorPawA350:
[legend]

Classes

struct  MotionData
 Motion Delta Data. More...
 

Public Types

enum class  CpiResolution : uint8_t {
  CPI_125 = 0 , CPI_250 = 1 , CPI_500 = 2 , CPI_750 = 3 ,
  CPI_1000 = 4 , CPI_1250 = 5
}
 Count Per Inch (CPI) Resolution. More...
 
enum class  MotionStatus : uint8_t { NO_MOTION = 0 , MOTION_DETECTED = 1 }
 Motion Detection Status. More...
 

Public Member Functions

 SensorPawA350 ()=default
 
const char * getChipName () const
 Get chip name.
 
int getProductID () const
 Get Product ID.
 
int getRevisionID () const
 Get Revision ID.
 
bool softReset ()
 Perform software reset.
 
bool checkMotion (MotionStatus &status)
 Check motion status.
 
bool getMotionData (MotionData &data)
 Get motion delta data.
 
bool setCpi (CpiResolution cpi)
 Set CPI resolution.
 
CpiResolution getCpi () const
 Get current CPI resolution.
 
bool setRunDownshiftTime (uint8_t rd)
 Set Run to Rest1 downshift time.
 
int getRunDownshiftTime () const
 Get Run to Rest1 downshift time.
 
bool setRest1Period (uint8_t period)
 Set Rest1 frame period.
 
int getRest1Period () const
 Get Rest1 frame period.
 
bool setRest1DownshiftTime (uint8_t r1d)
 Set Rest1 to Rest2 downshift time.
 
int getRest1DownshiftTime () const
 Get Rest1 to Rest2 downshift time.
 
bool setRest2Period (uint8_t period)
 Set Rest2 frame period.
 
int getRest2Period () const
 Get Rest2 frame period.
 
bool setRest2DownshiftTime (uint8_t r2d)
 Set Rest2 to Rest3 downshift time.
 
int getRest2DownshiftTime () const
 Get Rest2 to Rest3 downshift time.
 
bool setRest3Period (uint8_t period)
 Set Rest3 frame period.
 
int getRest3Period () const
 Get Rest3 frame period.
 
bool setLedOn (bool enable)
 Enable/disable LED always-on mode.
 
bool getLedOn () const
 Get LED always-on status.
 
bool setLedDriveCurrent (uint8_t current)
 Set LED drive current.
 
int getLedDriveCurrent () const
 Get LED drive current setting.
 
bool setShutterMax (uint16_t value)
 Set shutter maximum open time.
 
int getShutterMax () const
 Get shutter maximum open time.
 
bool setMotionInterruptThreshold (uint8_t threshold)
 Set motion interrupt threshold.
 
int getMotionInterruptThreshold () const
 Get motion interrupt threshold.
 
bool clearFingerState ()
 Clear finger presence detect flag.
 
bool isMotionDetected ()
 Quick check if motion detected.
 
uint32_t getRunDownshiftTimeMs () const
 Get Run downshift time in milliseconds.
 
uint32_t getRest1PeriodMs () const
 Get Rest1 period in milliseconds.
 
uint32_t getRest1DownshiftTimeMs () const
 Get Rest1 downshift time in milliseconds.
 
uint32_t getRest2PeriodMs () const
 Get Rest2 period in milliseconds.
 
uint32_t getRest2DownshiftTimeMs () const
 Get Rest2 downshift time in milliseconds.
 
uint32_t getRest3PeriodMs () const
 Get Rest3 period in milliseconds.
 
- Public Member Functions inherited from I2CDeviceWithHal
bool begin (SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
 Initialize the sensor using custom callback interface.
 
- Public Member Functions inherited from DeviceBeginCommon
virtual ~DeviceBeginCommon ()
 
uint8_t getAddress () const
 
uint8_t getInterface () const
 
- Public Member Functions inherited from SensorCommWrapper
 SensorCommWrapper ()=default
 
int readReg (uint8_t reg) const
 
int readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const
 
int readBuff (uint8_t *buf, size_t len) const
 
int writeReg (uint8_t reg, uint8_t val)
 
int writeRegBuff (uint8_t reg, uint8_t *buf, size_t len)
 
int writeBuff (uint8_t *buf, size_t len)
 
int writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
 
bool setRegBit (uint8_t reg, uint8_t bit)
 
bool clrRegBit (uint8_t reg, uint8_t bit)
 
bool getRegBit (uint8_t reg, uint8_t bit)
 
int updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted)
 
void setAddress (uint8_t address)
 
void setAck (bool enable)
 
- Public Member Functions inherited from SensorCommInterface
virtual ~SensorCommInterface ()=default
 

Protected Member Functions

bool initImpl (uint8_t param) override
 
- Protected Member Functions inherited from I2CDeviceWithHal
bool ensureValid () const override
 Ensure the communication interface is valid.
 
- Protected Member Functions inherited from DeviceBeginCommon
 DeviceBeginCommon ()=default
 
virtual SensorCommBasegetComm () const override
 
virtual void beforeBegin ()
 
virtual void afterCommReady ()
 
virtual void afterInitSuccess (uint8_t param)
 
virtual void onBeginFail ()
 
bool fail ()
 
void clearCommState ()
 
template<typename CreateComm >
bool beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm)
 

Protected Attributes

uint8_t cached_rest1_period = 1
 
- Protected Attributes inherited from DeviceBeginCommon
std::unique_ptr< SensorCommBasecomm
 
std::unique_ptr< SensorHalhal
 
std::unique_ptr< SensorCommStaticstaticComm
 
uint8_t _addr = 0
 
uint8_t _iface = COMM_CUSTOM
 

Detailed Description

PAW-A350 Optical Finger Navigation Sensor Driver.

Provides interface for Configuring and reading motion data from the PixArt PAW-A350 OFN sensor.

Count Per Inch (CPI) Resolution Options

Value CPI Description
0 125 Lowest resolution, highest precision
1 250 2x base resolution
2 500 Default resolution
3 750 1.5x default
4 1000 High resolution
5 1250 Highest resolution

Motion Detection Status

Value Description
NO_MOTION No motion detected since last read
MOTION_DETECTED Motion detected, data ready in Delta_X/Y registers

Motion Delta Structure

Contains signed movement deltas in counts. The actual distance in inches is calculated as: delta / CPI

Member Type Description
delta_x int8_t X axis movement (-128 to 127)
delta_y int8_t Y axis movement (-128 to 127)

Definition at line 135 of file SensorPawA350.hpp.

Member Enumeration Documentation

◆ CpiResolution

enum class SensorPawA350::CpiResolution : uint8_t
strong

Count Per Inch (CPI) Resolution.

Defines the sensor resolution in counts per inch. Higher CPI means more sensitivity but smaller range.

Note
The actual movement in inches = delta / CPI
Enumerator
CPI_125 

125 CPI - Lowest resolution, largest range

CPI_250 

250 CPI

CPI_500 

500 CPI - Default resolution

CPI_750 

750 CPI

CPI_1000 

1000 CPI - Recommended for most applications

CPI_1250 

1250 CPI - Highest resolution

Definition at line 147 of file SensorPawA350.hpp.

◆ MotionStatus

enum class SensorPawA350::MotionStatus : uint8_t
strong

Motion Detection Status.

Indicates whether motion has been detected since the last time the EVENT register was read.

Note
Reading Delta_X and Delta_Y registers clears the MOTION bit in the EVENT register.
Enumerator
NO_MOTION 

No motion detected.

MOTION_DETECTED 

Motion occurred, data ready for reading.

Definition at line 165 of file SensorPawA350.hpp.

Constructor & Destructor Documentation

◆ SensorPawA350()

SensorPawA350::SensorPawA350 ( )
default

Member Function Documentation

◆ checkMotion()

bool SensorPawA350::checkMotion ( MotionStatus status)

Check motion status.

Reads the EVENT register (0x02) to check if motion has been detected. The EVENT register contains multiple status bits:

  • Bit 7 (MOTION): Motion detected flag
  • Bit 3 (RESET_ST): Reset occurred flag
  • Bit 0 (FPD_ST): Finger state change flag
Parameters
[out]statusReference to store motion status
Returns
true if register read successful
Note
The MOTION bit is cleared when Delta_X and Delta_Y registers are read.
WRITE 0x00 to EVENT register to clear status bits.

Definition at line 61 of file SensorPawA350.cpp.

References MOTION_DETECTED, NO_MOTION, and SensorCommWrapper::readReg().

Referenced by isMotionDetected(), and loop().

◆ clearFingerState()

bool SensorPawA350::clearFingerState ( )

Clear finger presence detect flag.

Reads the FPD_FLAG register (0x7A) to clear the finger state change flag (FPD_ST) in the EVENT register.

Returns
true if read successful
Note
FPD_ST bit in EVENT register indicates finger state change (finger on/off). This function clears that flag.

Definition at line 215 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

◆ getChipName()

const char * SensorPawA350::getChipName ( ) const

Get chip name.

Returns
Chip name string "PAW-A350"

Definition at line 39 of file SensorPawA350.cpp.

Referenced by setup().

◆ getCpi()

SensorPawA350::CpiResolution SensorPawA350::getCpi ( ) const

Get current CPI resolution.

Returns
Current CPI resolution setting

Definition at line 85 of file SensorPawA350.cpp.

References CPI_500, and SensorCommWrapper::readReg().

Referenced by setup().

◆ getLedDriveCurrent()

int SensorPawA350::getLedDriveCurrent ( ) const

Get LED drive current setting.

Returns
Current drive current value

Definition at line 181 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getLedOn()

bool SensorPawA350::getLedOn ( ) const

Get LED always-on status.

Returns
true if LED is in always-on mode

Definition at line 168 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getMotionData()

bool SensorPawA350::getMotionData ( MotionData data)

Get motion delta data.

Reads Delta_X (0x03) and Delta_Y (0x04) registers sequentially to get motion deltas. Values are 8-bit signed integers in two's complement format.

Parameters
[out]dataReference to store motion data
Returns
true if read successful
Note
Registers are cleared after reading
Recommend reading both registers in one I2C transaction

Definition at line 69 of file SensorPawA350.cpp.

References SensorPawA350::MotionData::delta_x, SensorPawA350::MotionData::delta_y, SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().

Referenced by loop().

◆ getMotionInterruptThreshold()

int SensorPawA350::getMotionInterruptThreshold ( ) const

Get motion interrupt threshold.

Returns
Current threshold value

Definition at line 209 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getProductID()

int SensorPawA350::getProductID ( ) const

Get Product ID.

Reads the PRODUCT_ID register (0x00) which contains a unique identification number assigned to the PAW-A350. The value is fixed at 0x88 and can be used to verify I2C communication is working correctly.

Returns
Product ID (default: 0x88)
Note
Use this function in initImpl() to verify sensor is responding correctly on the I2C bus.

Definition at line 44 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by initImpl(), setup(), and softReset().

◆ getRest1DownshiftTime()

int SensorPawA350::getRest1DownshiftTime ( ) const

Get Rest1 to Rest2 downshift time.

Returns
Raw downshift register value

Definition at line 126 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by getRest1DownshiftTimeMs(), and setup().

◆ getRest1DownshiftTimeMs()

uint32_t SensorPawA350::getRest1DownshiftTimeMs ( ) const

Get Rest1 downshift time in milliseconds.

Returns
Rest1 to Rest2 downshift time in ms

Definition at line 239 of file SensorPawA350.cpp.

References getRest1DownshiftTime(), and getRest1Period().

Referenced by setup().

◆ getRest1Period()

int SensorPawA350::getRest1Period ( ) const

Get Rest1 frame period.

Returns
Raw period register value

Definition at line 114 of file SensorPawA350.cpp.

References cached_rest1_period.

Referenced by getRest1DownshiftTimeMs(), getRest1PeriodMs(), and setup().

◆ getRest1PeriodMs()

uint32_t SensorPawA350::getRest1PeriodMs ( ) const

Get Rest1 period in milliseconds.

Returns
Rest1 period in ms

Definition at line 233 of file SensorPawA350.cpp.

References getRest1Period().

Referenced by setup().

◆ getRest2DownshiftTime()

int SensorPawA350::getRest2DownshiftTime ( ) const

Get Rest2 to Rest3 downshift time.

Returns
Raw downshift register value

Definition at line 146 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by getRest2DownshiftTimeMs(), and setup().

◆ getRest2DownshiftTimeMs()

uint32_t SensorPawA350::getRest2DownshiftTimeMs ( ) const

Get Rest2 downshift time in milliseconds.

Returns
Rest2 to Rest3 downshift time in ms

Definition at line 252 of file SensorPawA350.cpp.

References getRest2DownshiftTime(), and getRest2Period().

Referenced by setup().

◆ getRest2Period()

int SensorPawA350::getRest2Period ( ) const

Get Rest2 frame period.

Returns
Raw period register value

Definition at line 136 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by getRest2DownshiftTimeMs(), getRest2PeriodMs(), and setup().

◆ getRest2PeriodMs()

uint32_t SensorPawA350::getRest2PeriodMs ( ) const

Get Rest2 period in milliseconds.

Returns
Rest2 period in ms

Definition at line 246 of file SensorPawA350.cpp.

References getRest2Period().

Referenced by setup().

◆ getRest3Period()

int SensorPawA350::getRest3Period ( ) const

Get Rest3 frame period.

Returns
Raw period register value

Definition at line 156 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by getRest3PeriodMs(), and setup().

◆ getRest3PeriodMs()

uint32_t SensorPawA350::getRest3PeriodMs ( ) const

Get Rest3 period in milliseconds.

Returns
Rest3 period in ms

Definition at line 259 of file SensorPawA350.cpp.

References getRest3Period().

Referenced by setup().

◆ getRevisionID()

int SensorPawA350::getRevisionID ( ) const

Get Revision ID.

Reads the REVISION_ID register (0x01) which contains the IC revision number. This value may change when new silicon versions are released.

Returns
Revision ID

Definition at line 49 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getRunDownshiftTime()

int SensorPawA350::getRunDownshiftTime ( ) const

Get Run to Rest1 downshift time.

Returns
Raw downshift register value

Definition at line 97 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by getRunDownshiftTimeMs(), and setup().

◆ getRunDownshiftTimeMs()

uint32_t SensorPawA350::getRunDownshiftTimeMs ( ) const

Get Run downshift time in milliseconds.

Calculates actual downshift time in ms based on Run_Downshift register value.

Returns
Time in milliseconds
Note
Formula: RD x 8 x 8ms

Definition at line 227 of file SensorPawA350.cpp.

References getRunDownshiftTime().

Referenced by setup().

◆ getShutterMax()

int SensorPawA350::getShutterMax ( ) const

Get shutter maximum open time.

Returns
Current shutter max value

Definition at line 194 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ initImpl()

bool SensorPawA350::initImpl ( uint8_t  param)
overrideprotectedvirtual

Implements DeviceBeginCommon.

Definition at line 265 of file SensorPawA350.cpp.

References cached_rest1_period, and getProductID().

◆ isMotionDetected()

bool SensorPawA350::isMotionDetected ( )

Quick check if motion detected.

Convenience function to check if motion flag is set in EVENT register.

Returns
true if motion detected

Definition at line 221 of file SensorPawA350.cpp.

References checkMotion(), and MOTION_DETECTED.

◆ setCpi()

bool SensorPawA350::setCpi ( CpiResolution  cpi)

Set CPI resolution.

Configures the CPI_SEL register (0x62) to set the count per inch resolution. Higher CPI provides more sensitivity but smaller usable range.

Parameters
cpiResolution setting
Returns
true if write successful
Note
Resolution affects delta output interpretation:
  • 125 CPI: 125 counts = 1 inch
  • 250 CPI: 250 counts = 1 inch
  • 500 CPI: 500 counts = 1 inch
  • 750 CPI: 750 counts = 1 inch
  • 1000 CPI: 1000 counts = 1 inch
  • 1250 CPI: 1250 counts = 1 inch

Definition at line 80 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ setLedDriveCurrent()

bool SensorPawA350::setLedDriveCurrent ( uint8_t  current)

Set LED drive current.

Configures LED drive current in LED_CTRL register (0x1A).

Parameters
currentDrive current (0=13mA, 2=9.6mA, 7=27mA)
Returns
true if write successful
Note
Available values:
  • 0: 13mA (default)
  • 2: 9.6mA
  • 7: 27mA

Definition at line 174 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().

Referenced by setup().

◆ setLedOn()

bool SensorPawA350::setLedOn ( bool  enable)

Enable/disable LED always-on mode.

Controls the LED_On bit in LED_CTRL register (0x1A). When disabled (default), LED operates normally. When enabled, LED stays always on.

Parameters
enabletrue to keep LED on, false for normal operation
Returns
true if write successful

Definition at line 161 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().

Referenced by setup().

◆ setMotionInterruptThreshold()

bool SensorPawA350::setMotionInterruptThreshold ( uint8_t  threshold)

Set motion interrupt threshold.

Configures MOTION_CTRL register (0x74) to set the motion interrupt threshold.

Parameters
thresholdThreshold value (0-7, default: 0)
Returns
true if write successful
Note
Motion interrupt triggers only when: |Delta_X| + |Delta_Y| > Threshold Default (0) triggers on any motion.

Definition at line 202 of file SensorPawA350.cpp.

References SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().

Referenced by setup().

◆ setRest1DownshiftTime()

bool SensorPawA350::setRest1DownshiftTime ( uint8_t  r1d)

Set Rest1 to Rest2 downshift time.

Writes to Rest1_Downshift register (0x15) to set the time before transitioning from Rest1 to Rest2.

Parameters
r1dDownshift time value (1-242, default: 31)
Returns
true if write successful
Note
Time formula: R1D[7:0] x 16 x Rest1_Period
  • Min: 1 x 16 x 20ms = 320ms
  • Default: 31 x 16 x 20ms = 9,920ms
  • Max: 242 x 16 x 2.56s = 9,912s

Definition at line 121 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ setRest1Period()

bool SensorPawA350::setRest1Period ( uint8_t  period)

Set Rest1 frame period.

Writes to Rest1_Period register (0x11) to set the frame period in Rest1 power state.

Parameters
periodPeriod value (1-256, default: 1)
Returns
true if write successful
Note
Time formula: (R1R[7:0] + 1) x 10ms
  • Min: 2 x 10ms = 20ms
  • Default: (1+1) x 10ms = 20ms
  • Max: 256 x 10ms = 2,560ms

Definition at line 102 of file SensorPawA350.cpp.

References cached_rest1_period, and SensorCommWrapper::writeReg().

Referenced by setup().

◆ setRest2DownshiftTime()

bool SensorPawA350::setRest2DownshiftTime ( uint8_t  r2d)

Set Rest2 to Rest3 downshift time.

Writes to Rest2_Downshift register (0x17) to set the time before transitioning from Rest2 to Rest3.

Parameters
r2dDownshift time value (1-242, default: 47)
Returns
true if write successful
Note
Time formula: R2D[7:0] x 128 x Rest2_Period
  • Min: 1 x 128 x 20ms = 2,560ms
  • Default: 47 x 128 x 100ms = 601,600ms
  • Max: 242 x 128 x 2.56s = 79,298s

Definition at line 141 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ setRest2Period()

bool SensorPawA350::setRest2Period ( uint8_t  period)

Set Rest2 frame period.

Writes to Rest2_Period register (0x16) to set the frame period in Rest2 power state.

Parameters
periodPeriod value (1-256, default: 9)
Returns
true if write successful
Note
Time formula: (R2R[7:0] + 1) x 10ms
  • Min: 2 x 10ms = 20ms
  • Default: (9+1) x 10ms = 100ms
  • Max: 256 x 10ms = 2,560ms

Definition at line 131 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ setRest3Period()

bool SensorPawA350::setRest3Period ( uint8_t  period)

Set Rest3 frame period.

Writes to Rest3_Period register (0x18) to set the frame period in Rest3 (lowest power) state.

Parameters
periodPeriod value (1-256, default: 49)
Returns
true if write successful
Note
Time formula: (R3R[7:0] + 1) x 10ms
  • Min: 2 x 10ms = 20ms
  • Default: (49+1) x 10ms = 500ms
  • Max: 256 x 10ms = 2,560ms

Definition at line 151 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ setRunDownshiftTime()

bool SensorPawA350::setRunDownshiftTime ( uint8_t  rd)

Set Run to Rest1 downshift time.

Writes to Run_Downshift register (0x13) to set the time before transitioning from Run state to Rest1 state when no motion is detected.

Parameters
rdDownshift time value (2-242, default: 4)
Returns
true if write successful
Note
Time formula: RD[7:0] x 8 x 8ms
  • Min: 2 x 8 x 8ms = 128ms
  • Default: 4 x 8 x 8ms = 256ms
  • Max: 242 x 8 x 8ms = 15,488ms

Definition at line 92 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ setShutterMax()

bool SensorPawA350::setShutterMax ( uint16_t  value)

Set shutter maximum open time.

Writes to Shutter_Max_Hi (0x3B) and Shutter_Max_Lo (0x3C) registers to set the maximum exposure time.

Parameters
valueShutter max value (0-2929, default: 2929)
Returns
true if write successful
Note
Shutter value represents pixel array exposure time in multiples of internal clock cycles. Max value: 2929 decimal (0x0B71)

Definition at line 187 of file SensorPawA350.cpp.

References SensorCommWrapper::writeReg().

Referenced by setup().

◆ softReset()

bool SensorPawA350::softReset ( )

Perform software reset.

Writes to the SOFT_RESET register (0x3A) with value 0x5A to trigger a software reset. After reset, all registers return to their default values.

Returns
true if reset successful and Product ID verified
Note
This function verifies the reset was successful by checking the Product ID matches the expected value (0x88).

Definition at line 54 of file SensorPawA350.cpp.

References getProductID(), and SensorCommWrapper::writeReg().

Referenced by setup().

Member Data Documentation

◆ cached_rest1_period

uint8_t SensorPawA350::cached_rest1_period = 1
protected

Definition at line 587 of file SensorPawA350.hpp.

Referenced by getRest1Period(), initImpl(), and setRest1Period().


The documentation for this class was generated from the following files: