PCA9633 I2C PWM controller

Device driver for the NXP PCA9633. More...

Detailed Description

Device driver for the NXP PCA9633.

Author
Hendrik van Essen hendr.nosp@m.ik.v.nosp@m.e@fu-.nosp@m.berl.nosp@m.in.de

Files

file  pca9633.h
 
file  pca9633_regs.h
 Register definitions for the PCA9633 I2C PWM controller.
 

Data Structures

struct  pca9633_params_t
 PCA9633 device initialization parameters. More...
 
struct  pca9633_t
 PCA9633 PWM device data structure type. More...
 

Macros

#define PCA9633_BLINKING_PERIOD_MAX_MS   (10625)
 Blinking period with a maximum duration of ~10.73 s.
 
#define PCA9633_BLINKING_RATIO_BALANCED   128
 Ration between on/ off in blinking mode is balanced. More...
 

Enumerations

enum  { PCA9633_OK = 0, PCA9633_ERROR_I2C = 1 }
 PCA9633 driver error codes. More...
 
enum  pca9633_pwm_channel_t { PCA9633_PWM_CHANNEL_0 = PCA9633_REG_PWM0, PCA9633_PWM_CHANNEL_1 = PCA9633_REG_PWM1, PCA9633_PWM_CHANNEL_2 = PCA9633_REG_PWM2, PCA9633_PWM_CHANNEL_3 = PCA9633_REG_PWM3 }
 PCA9633 PWM channel definitions. More...
 
enum  pca9633_ldr_state_t { PCA9633_LDR_STATE_OFF, PCA9633_LDR_STATE_ON, PCA9633_LDR_STATE_IND, PCA9633_LDR_STATE_IND_GRP }
 LED driver output state, LEDOUT (page 14, below table 13) More...
 
enum  pca9633_auto_inc_option_t {
  PCA9633_AI_DISABLED, PCA9633_AI_ALL, PCA9633_AI_IND, PCA9633_AI_GBL,
  PCA9633_AI_IND_GBL
}
 Auto-Increment options (page 10, table 6) More...
 
enum  pca9633_group_control_mode_t { PCA9633_GROUP_CONTROL_MODE_BLINKING, PCA9633_GROUP_CONTROL_MODE_DIMMING }
 PCA9633 group control modes. More...
 

Functions

int pca9633_init (pca9633_t *dev, const pca9633_params_t *params)
 Initialization. More...
 
void pca9633_turn_on (pca9633_t *dev)
 Turn on all LEDs. More...
 
void pca9633_turn_off (pca9633_t *dev)
 Turn off all LEDs. More...
 
void pca9633_wakeup (pca9633_t *dev)
 Switch to normal mode. More...
 
void pca9633_sleep (pca9633_t *dev)
 Switch to low power mode. More...
 
void pca9633_set_pwm (pca9633_t *dev, pca9633_pwm_channel_t pwm_channel, uint8_t pwm)
 Set individual PWM signal for a given channel. More...
 
void pca9633_set_grp_pwm (pca9633_t *dev, uint8_t pwm)
 Set global PWM signal. More...
 
void pca9633_set_blinking (pca9633_t *dev, uint16_t blink_period_ms, uint8_t on_off_ratio)
 Set up values for blinking mode. More...
 
void pca9633_set_rgb (pca9633_t *dev, uint8_t r, uint8_t g, uint8_t b)
 Set PWM values for RGB. More...
 
void pca9633_set_rgba (pca9633_t *dev, uint8_t r, uint8_t g, uint8_t b, uint8_t w)
 Set PWM values for RGBA. More...
 
void pca9633_set_ldr_state (pca9633_t *dev, pca9633_ldr_state_t state, pca9633_pwm_channel_t pwm_channel)
 Set the LED driver output state for a given channel. More...
 
void pca9633_set_ldr_state_all (pca9633_t *dev, pca9633_ldr_state_t state)
 Set the LED driver output state for all channels. More...
 
void pca9633_set_auto_increment (pca9633_t *dev, pca9633_auto_inc_option_t option)
 Set an option for auto increment. More...
 
void pca9633_set_group_control_mode (pca9633_t *dev, pca9633_group_control_mode_t mode)
 Set the group control mode. More...
 

Macro Definition Documentation

◆ PCA9633_BLINKING_RATIO_BALANCED

#define PCA9633_BLINKING_RATIO_BALANCED   128

Ration between on/ off in blinking mode is balanced.

128 = 255 / 2

Definition at line 43 of file pca9633.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

PCA9633 driver error codes.

Enumerator
PCA9633_OK 

Success.

PCA9633_ERROR_I2C 

I2C communication error.

Definition at line 71 of file pca9633.h.

◆ pca9633_auto_inc_option_t

Auto-Increment options (page 10, table 6)

Enumerator
PCA9633_AI_DISABLED 

No Auto-Increment.

PCA9633_AI_ALL 

Auto-Increment for all registers.

D3, D2, D1, D0 roll over to ‘0000’ after the last register (1100) is accessed.

PCA9633_AI_IND 

Auto-Increment for individual brightness registers only.

D3, D2, D1, D0 roll over to ‘0010’ after the last register (0101) is accessed.

PCA9633_AI_GBL 

Auto-Increment for global control registers only.

D3, D2, D1, D0 roll over to ‘0110’ after the last register (0111) is accessed.

PCA9633_AI_IND_GBL 

Auto-Increment for individual and global control registers only.

D3, D2, D1, D0 roll over to ‘0010’ after the last register (0111) is accessed.

Definition at line 119 of file pca9633.h.

◆ pca9633_group_control_mode_t

PCA9633 group control modes.

Enumerator
PCA9633_GROUP_CONTROL_MODE_BLINKING 

Control mode for blinking.

PCA9633_GROUP_CONTROL_MODE_DIMMING 

Control mode for dimming.

Definition at line 155 of file pca9633.h.

◆ pca9633_ldr_state_t

LED driver output state, LEDOUT (page 14, below table 13)

Enumerator
PCA9633_LDR_STATE_OFF 

LED driver x is off.

PCA9633_LDR_STATE_ON 

LED driver x is fully on (individual brightness and group dimming/ blinking not controlled)

PCA9633_LDR_STATE_IND 

LED driver x individual brightness can be controlled through its PWMx register.

PCA9633_LDR_STATE_IND_GRP 

LED driver x individual brightness and group dimming/ blinking can be controlled through its PWMx register and the GRPPWM registers.

If using PCA9633_LDR_STATE_IND_GRP the controller takes the minimum value of PWM* and GRPPWM register

Definition at line 89 of file pca9633.h.

◆ pca9633_pwm_channel_t

PCA9633 PWM channel definitions.

Enumerator
PCA9633_PWM_CHANNEL_0 

PWM channel 0.

PCA9633_PWM_CHANNEL_1 

PWM channel 1.

PCA9633_PWM_CHANNEL_2 

PWM channel 2.

PCA9633_PWM_CHANNEL_3 

PWM channel 3.

Definition at line 79 of file pca9633.h.

Function Documentation

◆ pca9633_init()

int pca9633_init ( pca9633_t dev,
const pca9633_params_t params 
)

Initialization.

Parameters
[in]devDevice descriptor of the PCA9633
[in]paramsParameters for device initialization
Returns
PCA9633_OK on success
-PCA9633_ERROR_I2C if acquiring of I2C bus fails
-EIO When slave device doesn't ACK the byte
-ENXIO When no devices respond on the address sent on the bus
-ETIMEDOUT When timeout occurs before device's response
-EINVAL When an invalid argument is given
-EOPNOTSUPP When MCU driver doesn't support the flag operation
-EAGAIN When a lost bus arbitration occurs

◆ pca9633_set_auto_increment()

void pca9633_set_auto_increment ( pca9633_t dev,
pca9633_auto_inc_option_t  option 
)

Set an option for auto increment.

There are five options:

  • PCA9633_AI_DISABLED
  • PCA9633_AI_ALL
  • PCA9633_AI_IND
  • PCA9633_AI_GBL
  • PCA9633_AI_IND_GBL
Parameters
[in]devDevice descriptor of the PCA9633
[in]optionOne of the possible five options

◆ pca9633_set_blinking()

void pca9633_set_blinking ( pca9633_t dev,
uint16_t  blink_period_ms,
uint8_t  on_off_ratio 
)

Set up values for blinking mode.

Blinking mode needs to be activated manually by calling pca9633_set_group_control_mode(GROUP_CONTROL_MODE_BLINKING).

Parameters
[in]devDevice descriptor of the PCA9633
[in]blink_period_msPeriod in ms for one blink (turning off and on). Maximum period possible is PCA9633_BLINKING_PERIOD_MAX_MS ≈ 10.73 s. All values above this maximum will we capped to it.
[in]on_off_ratioValue between 0 and 255, where e.g. a value of 64 (255/4) means 1/4 of the time the LEDs are on and 3/4 of the time the LEDs are off.

◆ pca9633_set_group_control_mode()

void pca9633_set_group_control_mode ( pca9633_t dev,
pca9633_group_control_mode_t  mode 
)

Set the group control mode.

There are two modes:

  • PCA9633_GROUP_CONTROL_MODE_BLINKING
  • PCA9633_GROUP_CONTROL_MODE_DIMMING
Parameters
[in]devDevice descriptor of the PCA9633
[in]modeOne of the two possible modes

◆ pca9633_set_grp_pwm()

void pca9633_set_grp_pwm ( pca9633_t dev,
uint8_t  pwm 
)

Set global PWM signal.

Parameters
[in]devDevice descriptor of the PCA9633
[in]pwmPWM value

◆ pca9633_set_ldr_state()

void pca9633_set_ldr_state ( pca9633_t dev,
pca9633_ldr_state_t  state,
pca9633_pwm_channel_t  pwm_channel 
)

Set the LED driver output state for a given channel.

There are four states:

  • PCA9633_LDR_STATE_OFF
  • PCA9633_LDR_STATE_ON
  • PCA9633_LDR_STATE_IND
  • PCA9633_LDR_STATE_IND_GRP
Parameters
[in]devDevice descriptor of the PCA9633
[in]stateOne of the four possible states
[in]pwm_channelPWM channel belonging to LDR

◆ pca9633_set_ldr_state_all()

void pca9633_set_ldr_state_all ( pca9633_t dev,
pca9633_ldr_state_t  state 
)

Set the LED driver output state for all channels.

There are four states:

  • PCA9633_LDR_STATE_OFF
  • PCA9633_LDR_STATE_ON
  • PCA9633_LDR_STATE_IND
  • PCA9633_LDR_STATE_IND_GRP
Parameters
[in]devDevice descriptor of the PCA9633
[in]stateOne of the four possible states

◆ pca9633_set_pwm()

void pca9633_set_pwm ( pca9633_t dev,
pca9633_pwm_channel_t  pwm_channel,
uint8_t  pwm 
)

Set individual PWM signal for a given channel.

Parameters
[in]devDevice descriptor of the PCA9633
[in]pwm_channelPWM channel
[in]pwmPWM value

◆ pca9633_set_rgb()

void pca9633_set_rgb ( pca9633_t dev,
uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Set PWM values for RGB.

Parameters
[in]devDevice descriptor of the PCA9633
[in]rValue for red color channel
[in]gValue for green color channel
[in]bValue for blue color channel

◆ pca9633_set_rgba()

void pca9633_set_rgba ( pca9633_t dev,
uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  w 
)

Set PWM values for RGBA.

Parameters
[in]devDevice descriptor of the PCA9633
[in]rValue for red color channel
[in]gValue for green color channel
[in]bValue for blue color channel
[in]wValue for amber color channel

◆ pca9633_sleep()

void pca9633_sleep ( pca9633_t dev)

Switch to low power mode.

Parameters
[in]devDevice descriptor of the PCA9633

◆ pca9633_turn_off()

void pca9633_turn_off ( pca9633_t dev)

Turn off all LEDs.

Saves current settings for pca9633_turn_on(). For power saving, see pca9633_sleep().

WARNING: If you call pca9633_turn_off() twice, without calling pca9633_turn_on() in between, then the restored state will be PCA9633_LDR_STATE_OFF!

Parameters
[in]devDevice descriptor of the PCA9633

◆ pca9633_turn_on()

void pca9633_turn_on ( pca9633_t dev)

Turn on all LEDs.

Restores settings saved at pca9633_turn_off().

WARNING: If you call pca9633_turn_off() twice, without calling pca9633_turn_on() in between, then the restored state will be PCA9633_LDR_STATE_OFF!

Parameters
[in]devDevice descriptor of the PCA9633

◆ pca9633_wakeup()

void pca9633_wakeup ( pca9633_t dev)

Switch to normal mode.

Parameters
[in]devDevice descriptor of the PCA9633