PX4 Firmware
PX4 Autopilot Software http://px4.io
PCA9685 Class Reference
Inheritance diagram for PCA9685:
Collaboration diagram for PCA9685:

Public Member Functions

 PCA9685 (int bus=PCA9685_BUS, uint8_t address=ADDR)
 
virtual ~PCA9685 ()=default
 
virtual int init ()
 
virtual int ioctl (struct file *filp, int cmd, unsigned long arg)
 
virtual int info ()
 
virtual int reset ()
 
bool is_running ()
 

Private Member Functions

void Run () override
 Set to true after the first call of i2cpwm in mode IOX_MODE_ON. More...
 
int setPWMFreq (float freq)
 Helper function to set the pwm frequency. More...
 
int setPWM (uint8_t num, uint16_t on, uint16_t off)
 Helper function to set the demanded pwm value. More...
 
int setPin (uint8_t num, uint16_t val, bool invert=false)
 Sets pin without having to deal with on/off tick placement and properly handles a zero value as completely off. More...
 
int read8 (uint8_t addr, uint8_t &value)
 
int write8 (uint8_t addr, uint8_t value)
 

Private Attributes

enum IOX_MODE _mode
 
bool _running
 
uint64_t _i2cpwm_interval
 
bool _should_run
 
perf_counter_t _comms_errors
 
uint8_t _msg [6]
 
int _actuator_controls_sub
 
struct actuator_controls_s _actuator_controls
 
uint16_t _current_values [actuator_controls_s::NUM_ACTUATOR_CONTROLS]
 stores the current pwm output values as sent to the setPin() More...
 
bool _mode_on_initialized
 

Detailed Description

Definition at line 114 of file pca9685.cpp.

Constructor & Destructor Documentation

◆ PCA9685()

PCA9685::PCA9685 ( int  bus = PCA9685_BUS,
uint8_t  address = ADDR 
)

Definition at line 185 of file pca9685.cpp.

References _current_values, and _msg.

Referenced by pca9685_main().

Here is the caller graph for this function:

◆ ~PCA9685()

virtual PCA9685::~PCA9685 ( )
virtualdefault

Member Function Documentation

◆ info()

int PCA9685::info ( )
virtual

Definition at line 272 of file pca9685.cpp.

References _mode, is_running(), OK, and warnx.

Here is the call graph for this function:

◆ init()

int PCA9685::init ( )
virtual

Definition at line 202 of file pca9685.cpp.

References ToneAlarmInterface::init(), OK, PCA9685_PWMFREQ, reset(), and setPWMFreq().

Here is the call graph for this function:

◆ ioctl()

int PCA9685::ioctl ( struct file filp,
int  cmd,
unsigned long  arg 
)
virtual

Definition at line 223 of file pca9685.cpp.

References _mode, _running, IOX_MODE_OFF, IOX_MODE_ON, IOX_MODE_TEST_OUT, IOX_SET_MODE, OK, and warnx.

Referenced by pca9685_main().

Here is the caller graph for this function:

◆ is_running()

bool PCA9685::is_running ( )
inline

Definition at line 125 of file pca9685.cpp.

Referenced by info().

Here is the caller graph for this function:

◆ read8()

int PCA9685::read8 ( uint8_t  addr,
uint8_t &  value 
)
private

Definition at line 459 of file pca9685.cpp.

References _comms_errors, DEVICE_LOG, OK, and perf_count().

Referenced by setPWMFreq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

int PCA9685::reset ( void  )
virtual

Definition at line 486 of file pca9685.cpp.

References PCA9685_MODE1, warnx, and write8().

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Run()

void PCA9685::Run ( )
overrideprivate

Set to true after the first call of i2cpwm in mode IOX_MODE_ON.

Main loop function.

Definition at line 290 of file pca9685.cpp.

References _actuator_controls, _actuator_controls_sub, _current_values, _i2cpwm_interval, _mode, _mode_on_initialized, _running, _should_run, actuator_controls_s::control, DEVICE_DEBUG, f(), IOX_MODE_OFF, IOX_MODE_TEST_OUT, M_PI_F, orb_check(), orb_copy(), ORB_ID, orb_set_interval(), orb_subscribe(), PCA9685_PWMCENTER, PCA9685_PWMFREQ, PCA9685_PWMMAX, PCA9685_PWMMIN, PCA9685_SCALE, and setPin().

Here is the call graph for this function:

◆ setPin()

int PCA9685::setPin ( uint8_t  num,
uint16_t  val,
bool  invert = false 
)
private

Sets pin without having to deal with on/off tick placement and properly handles a zero value as completely off.

Optional invert parameter supports inverting the pulse for sinking to ground.

Parameters
numpwm output number
valshould be a value from 0 to 4095 inclusive.

Definition at line 371 of file pca9685.cpp.

References setPWM().

Referenced by Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPWM()

int PCA9685::setPWM ( uint8_t  num,
uint16_t  on,
uint16_t  off 
)
private

Helper function to set the demanded pwm value.

Parameters
numpwm output number

Definition at line 349 of file pca9685.cpp.

References _comms_errors, _msg, DEVICE_LOG, LED0_ON_L, OK, and perf_count().

Referenced by setPin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPWMFreq()

int PCA9685::setPWMFreq ( float  freq)
private

Helper function to set the pwm frequency.

Definition at line 409 of file pca9685.cpp.

References f(), OK, PCA9685_MODE1, PCA9685_PRESCALE, read8(), and write8().

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write8()

int PCA9685::write8 ( uint8_t  addr,
uint8_t  value 
)
private

Definition at line 494 of file pca9685.cpp.

References _comms_errors, _msg, DEVICE_LOG, OK, and perf_count().

Referenced by reset(), and setPWMFreq().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _actuator_controls

struct actuator_controls_s PCA9685::_actuator_controls
private

Definition at line 138 of file pca9685.cpp.

Referenced by Run().

◆ _actuator_controls_sub

int PCA9685::_actuator_controls_sub
private

Definition at line 137 of file pca9685.cpp.

Referenced by Run().

◆ _comms_errors

perf_counter_t PCA9685::_comms_errors
private

Definition at line 133 of file pca9685.cpp.

Referenced by read8(), setPWM(), and write8().

◆ _current_values

uint16_t PCA9685::_current_values[actuator_controls_s::NUM_ACTUATOR_CONTROLS]
private

stores the current pwm output values as sent to the setPin()

Definition at line 139 of file pca9685.cpp.

Referenced by PCA9685(), and Run().

◆ _i2cpwm_interval

uint64_t PCA9685::_i2cpwm_interval
private

Definition at line 131 of file pca9685.cpp.

Referenced by Run().

◆ _mode

enum IOX_MODE PCA9685::_mode
private

Definition at line 129 of file pca9685.cpp.

Referenced by info(), ioctl(), and Run().

◆ _mode_on_initialized

bool PCA9685::_mode_on_initialized
private

Definition at line 142 of file pca9685.cpp.

Referenced by Run().

◆ _msg

uint8_t PCA9685::_msg[6]
private

Definition at line 135 of file pca9685.cpp.

Referenced by PCA9685(), setPWM(), and write8().

◆ _running

bool PCA9685::_running
private

Definition at line 130 of file pca9685.cpp.

Referenced by ioctl(), and Run().

◆ _should_run

bool PCA9685::_should_run
private

Definition at line 132 of file pca9685.cpp.

Referenced by Run().


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