Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
PCA9685PWM Class Reference

Agragate of 16 PWM channels for a PCA9685PWM. More...

#include <PCA9685PWM.hxx>

Inheritance diagram for PCA9685PWM:
OSThread

Classes

struct  LedCtl
 Representation of the replicative 4 LED control register. More...
 
union  Mode1
 Represent the mode 1 register. More...
 
union  Mode2
 Represent the mode 2 register. More...
 

Public Member Functions

 PCA9685PWM ()
 Constructor.
 
void init (const char *name, uint8_t i2c_address, uint16_t pwm_freq=200, int32_t external_clock_freq=-1)
 Initialize device.
 
 ~PCA9685PWM ()
 Destructor.
 
- Public Member Functions inherited from OSThread
 OSThread (const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
 Create a thread.
 
 OSThread ()
 Creates a thread via inheritance.
 
void start (const char *name, int priority, size_t stack_size)
 Starts the thread.
 
virtual ~OSThread ()
 Default destructor.
 
bool is_created ()
 
void inherit ()
 Inherits the current thread.
 
os_thread_t get_handle ()
 
void lock_to_thread ()
 Sets the thread handle to the current calling thread's.
 
void unlock_from_thread ()
 Resets the thread handle to none.
 

Static Public Attributes

static constexpr size_t NUM_CHANNELS = 16
 maximum number of PWM channels supported by the PCA9685
 
static constexpr size_t MAX_PWM_COUNTS = 4096
 maximum number of PWM counts supported by the PCA9685
 

Private Types

enum  Registers { MODE1 = 0 , MODE2 , LED0_ON_L = 6 , PRE_SCALE = 254 }
 Important device register offsets. More...
 

Private Member Functions

void * entry () override
 User entry point for the created thread.
 
void bit_modify (Registers address, uint8_t data, uint8_t mask)
 Bit modify to an I2C register.
 
void set_pwm_duty (unsigned channel, uint16_t counts)
 Set the pwm duty cycle.
 
uint16_t get_pwm_duty (unsigned channel)
 Get the pwm duty cycle.
 
void write_pwm_duty (unsigned channel, uint16_t counts)
 Set the pwm duty cycle.
 
void register_write (Registers address, uint8_t data)
 Write to an I2C register.
 
void register_write_multiple (Registers address, void *data, size_t count)
 Write to multiple sequential I2C registers.
 
 DISALLOW_COPY_AND_ASSIGN (PCA9685PWM)
 

Private Attributes

friend PCA9685PWMBit
 Allow access to private members.
 
OSSem sem_
 Wakeup for the thread processing.
 
int i2c_
 I2C file descriptor.
 
std::array< uint16_t, NUM_CHANNELSduty_
 local cache of the duty cycles
 
uint16_t dirty_
 set if the duty_ value is updated (bit mask)
 
uint8_t i2cAddress_
 I2C address of the device.
 

Additional Inherited Members

- Static Public Member Functions inherited from OSThread
static int getpriority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority_min ()
 Get the minimum thread priority.
 
static int get_priority_max ()
 Get the maximum thread priority.
 

Detailed Description

Agragate of 16 PWM channels for a PCA9685PWM.

Definition at line 48 of file PCA9685PWM.hxx.

Member Enumeration Documentation

◆ Registers

enum PCA9685PWM::Registers
private

Important device register offsets.

Enumerator
MODE1 

mode 1 settings

MODE2 

mode 2 settings

LED0_ON_L 

first LED control register

PRE_SCALE 

clock prescale divider

Definition at line 119 of file PCA9685PWM.hxx.

Constructor & Destructor Documentation

◆ PCA9685PWM()

PCA9685PWM::PCA9685PWM ( )
inline

Constructor.

Definition at line 58 of file PCA9685PWM.hxx.

◆ ~PCA9685PWM()

PCA9685PWM::~PCA9685PWM ( )
inline

Destructor.

Definition at line 113 of file PCA9685PWM.hxx.

Member Function Documentation

◆ bit_modify()

void PCA9685PWM::bit_modify ( Registers  address,
uint8_t  data,
uint8_t  mask 
)
inlineprivate

Bit modify to an I2C register.

Parameters
addressaddress to modify
datadata to modify
maskmask of data to modify, bits where mask is 1 will be overwritten, bits where mask is zero will be kept

Definition at line 218 of file PCA9685PWM.hxx.

◆ entry()

void * PCA9685PWM::entry ( )
overrideprivatevirtual

User entry point for the created thread.

Returns
exit status

Reimplemented from OSThread.

Definition at line 39 of file PCA9685PWM.cxx.

◆ get_pwm_duty()

uint16_t PCA9685PWM::get_pwm_duty ( unsigned  channel)
inlineprivate

Get the pwm duty cycle.

Parameters
channelchannel index (0 through 15)
Returns
counts for PWM duty cycle

Definition at line 267 of file PCA9685PWM.hxx.

◆ init()

void PCA9685PWM::init ( const char *  name,
uint8_t  i2c_address,
uint16_t  pwm_freq = 200,
int32_t  external_clock_freq = -1 
)
inline

Initialize device.

Parameters
namename of the I2C device
i2c_addressI2C address of the device on the bus
pwm_frequencytarget PWM frequency (will truncate at minimum and maximum prescaler values)
external_clockfrequency of an external clock in Hz, -1 if internal clock is used

Definition at line 74 of file PCA9685PWM.hxx.

◆ register_write()

void PCA9685PWM::register_write ( Registers  address,
uint8_t  data 
)
inlineprivate

Write to an I2C register.

Parameters
addressaddress to write to
datadata to write

Definition at line 307 of file PCA9685PWM.hxx.

◆ register_write_multiple()

void PCA9685PWM::register_write_multiple ( Registers  address,
void *  data,
size_t  count 
)
inlineprivate

Write to multiple sequential I2C registers.

Parameters
addressaddress to start write at
dataarray of data to write
countnumber of data registers to write in sequence

Definition at line 317 of file PCA9685PWM.hxx.

◆ set_pwm_duty()

void PCA9685PWM::set_pwm_duty ( unsigned  channel,
uint16_t  counts 
)
inlineprivate

Set the pwm duty cycle.

Parameters
channelchannel index (0 through 15)
countscounts for PWM duty cycle

Definition at line 252 of file PCA9685PWM.hxx.

◆ write_pwm_duty()

void PCA9685PWM::write_pwm_duty ( unsigned  channel,
uint16_t  counts 
)
inlineprivate

Set the pwm duty cycle.

Parameters
channelchannel index (0 through 15)
countscounts for PWM duty cycle

Definition at line 276 of file PCA9685PWM.hxx.

Member Data Documentation

◆ dirty_

uint16_t PCA9685PWM::dirty_
private

set if the duty_ value is updated (bit mask)

Definition at line 338 of file PCA9685PWM.hxx.

◆ duty_

std::array<uint16_t, NUM_CHANNELS> PCA9685PWM::duty_
private

local cache of the duty cycles

Definition at line 335 of file PCA9685PWM.hxx.

◆ i2c_

int PCA9685PWM::i2c_
private

I2C file descriptor.

Definition at line 332 of file PCA9685PWM.hxx.

◆ i2cAddress_

uint8_t PCA9685PWM::i2cAddress_
private

I2C address of the device.

Definition at line 341 of file PCA9685PWM.hxx.

◆ MAX_PWM_COUNTS

constexpr size_t PCA9685PWM::MAX_PWM_COUNTS = 4096
staticconstexpr

maximum number of PWM counts supported by the PCA9685

Definition at line 55 of file PCA9685PWM.hxx.

◆ NUM_CHANNELS

constexpr size_t PCA9685PWM::NUM_CHANNELS = 16
staticconstexpr

maximum number of PWM channels supported by the PCA9685

Definition at line 52 of file PCA9685PWM.hxx.

◆ PCA9685PWMBit

friend PCA9685PWM::PCA9685PWMBit
private

Allow access to private members.

Definition at line 326 of file PCA9685PWM.hxx.

◆ sem_

OSSem PCA9685PWM::sem_
private

Wakeup for the thread processing.

Definition at line 329 of file PCA9685PWM.hxx.


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