@ -32,7 +32,7 @@
@@ -32,7 +32,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @ file paw3902 . c pp
* @ file PAW3902 . h pp
*
* Driver for the Pixart PAW3902 & PAW3903 optical flow sensors connected via SPI .
*/
@ -50,27 +50,20 @@
@@ -50,27 +50,20 @@
# include <lib/perf/perf_counter.h>
# include <lib/parameters/param.h>
# include <drivers/drv_hrt.h>
# include <drivers/drv_range_finder.h>
# include <uORB/PublicationMulti.hpp>
# include <uORB/topics/optical_flow.h>
/* Configuration Constants */
# define PAW3902_SPI_BUS_SPEED (2000000L) // 2MHz
# define DIR_WRITE(a) ((a) | (1 << 7))
# define DIR_READ(a) ((a) & 0x7f)
using namespace time_literals ;
using namespace PixArt_PAW3902JF ;
// PAW3902JF-TXQT is PixArt Imaging
# define DIR_WRITE(a) ((a) | (1 << 7))
# define DIR_READ(a) ((a) & 0x7f)
class PAW3902 : public device : : SPI , public I2CSPIDriver < PAW3902 >
{
public :
PAW3902 ( I2CSPIBusOption bus_option , int bus , int devid , enum Rotation yaw_rotation , int bus_frequency ,
spi_mode_e spi_mode ) ;
PAW3902 ( I2CSPIBusOption bus_option , int bus , int devid , int bus_frequency , spi_mode_e spi_mode ,
float yaw_rotation_degrees = NAN ) ;
virtual ~ PAW3902 ( ) ;
static I2CSPIDriverBase * instantiate ( const BusCLIArguments & cli , const BusInstanceIterator & iterator ,
@ -83,37 +76,38 @@ public:
@@ -83,37 +76,38 @@ public:
void RunImpl ( ) ;
void start ( ) ;
protected :
int probe ( ) override ;
private :
int probe ( ) override ;
uint8_t registerRead ( uint8_t reg ) ;
void registerWrite ( uint8_t reg , uint8_t data ) ;
uint8_t RegisterRead ( uint8_t reg , int retries = 3 ) ;
void RegisterWrite ( uint8_t reg , uint8_t data ) ;
bool RegisterWriteVerified ( uint8_t reg , uint8_t data , int retries = 5 ) ;
bool r eset( ) ;
bool R eset( ) ;
bool m odeBright( ) ;
bool m odeLowLight( ) ;
bool m odeSuperLowLight( ) ;
bool M odeBright( ) ;
bool M odeLowLight( ) ;
bool M odeSuperLowLight( ) ;
bool c hangeMode( Mode newMode ) ;
bool C hangeMode( Mode newMode ) ;
uORB : : PublicationMulti < optical_flow_s > _optical_flow_pub { ORB_ID ( optical_flow ) } ;
perf_counter_t _sample_perf ;
perf_counter_t _comms_errors ;
perf_counter_t _dupe_count_perf ;
perf_counter_t _sample_perf { perf_alloc ( PC_ELAPSED , MODULE_NAME " : read " ) } ;
perf_counter_t _interval_perf { perf_alloc ( PC_INTERVAL , MODULE_NAME " : interval " ) } ;
perf_counter_t _comms_errors { perf_alloc ( PC_COUNT , MODULE_NAME " : com err " ) } ;
perf_counter_t _false_motion_perf { perf_alloc ( PC_COUNT , MODULE_NAME " : false motion report " ) } ;
perf_counter_t _mode_change_perf { perf_alloc ( PC_COUNT , MODULE_NAME " : mode change " ) } ;
perf_counter_t _register_write_fail_perf { perf_alloc ( PC_COUNT , MODULE_NAME " : verified register write failed " ) } ;
static constexpr uint64_t _collect_time { 15000 } ; // 15 milliseconds, optical flow data publish rate
static constexpr uint64_t COLLECT_TIME { 15000 } ; // 15 milliseconds, optical flow data publish rate
uint64_t _previous_collect_timestamp { 0 } ;
uint64_t _flow_dt_sum_usec { 0 } ;
unsigned _frame_count_since_last { 0 } ;
uint64_t _previous_collect_timestamp { 0 } ;
uint64_t _flow_dt_sum_usec { 0 } ;
uint8_t _flow_sample_counter { 0 } ;
uint16_t _flow_quality_sum { 0 } ;
enum Rotation _yaw_rotation { ROTATION_NONE } ;
matrix : : Dcmf _rotation ;
int _flow_sum_x { 0 } ;
int _flow_sum_y { 0 } ;
@ -123,5 +117,4 @@ private:
@@ -123,5 +117,4 @@ private:
uint8_t _low_to_superlow_counter { 0 } ;
uint8_t _low_to_bright_counter { 0 } ;
uint8_t _superlow_to_low_counter { 0 } ;
} ;