I2C_Drivers (ARM) 1.1
SMFSW collection of HAL I2C Drivers for ARM
Loading...
Searching...
No Matches
PCA9685_ex.h File Reference

PCA9685 Driver extensions. More...

#include "sarmfsw.h"
#include "PCA9685.h"
Include dependency graph for PCA9685_ex.h:
This graph shows which files directly or indirectly include this file:

Macros

#define PCA9685_FREQ_HZ_MIN   24U
 Lower admissible frequency (when internal clock used)
 
#define PCA9685_FREQ_HZ_MAX   1526U
 Upper admissible frequency (when internal clock used)
 
#define PCA9685_CLOCK_FREQ   25000000UL
 PCA9685 Internal clock frequency.
 
#define DefBitFullOnOff   0x10U
 Full ON / OFF bit on LEDxx_xxx_H.
 
#define LED_OFFSET_H(chan)
 Macro for address offset computation ON_H for PWM channels.
 
#define LED_OFFSET_L(chan)
 Macro for address offset computation ON_L for PWM channels.
 

Functions

FctERR PCA9685_CalcVal (uint8_t val[4], const uint16_t duty, const uint16_t delay)
 Computes values for PCA9685 registers (4bytes) following duty and delay.
 
FctERR PCA9685_CalcVal_NoDelay (uint8_t val[4], const uint16_t duty)
 Computes values for PCA9685 registers (4bytes) following duty (without delay)
 
FctERR PCA9685_Freq_To_Byte (const PCA9685_t *const pCpnt, uint8_t *const byte, const uint16_t freq)
 Convert Frequency to Prescaler byte register.
 
float PCA9685_Byte_To_Freq (PCA9685_t *const pCpnt, const uint8_t reg)
 Convert Prescaler byte register to Frequency (in Hz)
 
FctERR PCA9685_Set_Latch (PCA9685_t *const pCpnt, const PCA96xx_latch latch)
 Set latch type for PCA9685 peripheral.
 
FctERR PCA9685_Set_Frequency (PCA9685_t *const pCpnt, const uint16_t freq)
 Set frequency for PCA9685 peripheral.
 
FctERR PCA9685_ReadVal (PCA9685_t *const pCpnt, const PCA9xxx_chan chan, uint16_t *duty)
 Read I2C lighting values from a LED and Computes the corresponding duty cycle value (12b)
 
FctERR PCA9685_ReadValByte (PCA9685_t *const pCpnt, const PCA9xxx_chan chan, uint8_t *duty)
 Read I2C lighting values from a LED and Computes the corresponding duty cycle value (Byte)
 
FctERR PCA9685_PutVal (PCA9685_t *const pCpnt, const PCA9xxx_chan chan, const uint16_t duty, const uint16_t delay)
 Compute and send PWM lighting values to apply on a PCA9685 channel or all channels (12b)
 
FctERR PCA9685_PutValByte (PCA9685_t *const pCpnt, const PCA9xxx_chan chan, const uint8_t duty, const uint8_t delay)
 Compute and send PWM lighting values to apply on a PCA9685 channel or all channels (Byte)
 
FctERR PCA9685_PutValPerc (PCA9685_t *const pCpnt, const PCA9xxx_chan chan, const float duty, const float delay)
 Compute and send PWM lighting values to apply on a PCA9685 channel or all channels (Percent)
 
FctERR PCA9685_SetVal (PCA9685_t *const pCpnt, const PCA9xxx_chan chan)
 Compute and send PWM Full ON value to apply on a PCA9685 channel or all channels (no delay)
 
FctERR PCA9685_ClrVal (PCA9685_t *const pCpnt, const PCA9xxx_chan chan)
 Compute and send PWM Full OFF value to apply on a PCA9685 channel or all channels (no delay)
 
FctERR PCA9685_Reset (PCA9685_t *const pCpnt)
 Reset for PCA9685 peripheral.
 
FctERR PCA9685_Reset_All (I2C_HandleTypeDef *const hi2c)
 General call reset function for PCA9685.
 
FctERR PCA9685_ReadRegister (PCA9685_t *const pCpnt, const PCA9685_reg reg, uint8_t *const val)
 Reads register from PCA9685.
 
void PCA9685_OE_GPIO_Init (PCA9685_t *const pCpnt, GPIO_TypeDef *const GPIOx, const uint16_t GPIO_Pin, const GPIO_PinState GPIO_Active)
 Output Enable GPIO pin init for PCA9685.
 
void PCA9685_OE_GPIO_Set (PCA9685_t *const pCpnt, const bool state)
 Output Enable GPIO pin setter for PCA9685.
 

Detailed Description

PCA9685 Driver extensions.

Author
SMFSW

PCA9685: 16-channel, 12-bit PWM Fm+ I2C-bus LED controller

Macro Definition Documentation

◆ DefBitFullOnOff

#define DefBitFullOnOff   0x10U

Full ON / OFF bit on LEDxx_xxx_H.

◆ LED_OFFSET_H

#define LED_OFFSET_H ( chan)
Value:
((uint8_t) (PCA9685__LED0_ON_H + LSHIFT(chan, 2U)))
@ PCA9685__LED0_ON_H
register LED 0 ON High
Definition PCA9685.h:53

Macro for address offset computation ON_H for PWM channels.

4 registers per channel -> 2 shifts left for next address

◆ LED_OFFSET_L

#define LED_OFFSET_L ( chan)
Value:
((uint8_t) (PCA9685__LED0_ON_L + LSHIFT(chan, 2U)))
@ PCA9685__LED0_ON_L
register LED 0 ON Low
Definition PCA9685.h:52

Macro for address offset computation ON_L for PWM channels.

◆ PCA9685_CLOCK_FREQ

#define PCA9685_CLOCK_FREQ   25000000UL

PCA9685 Internal clock frequency.

◆ PCA9685_FREQ_HZ_MAX

#define PCA9685_FREQ_HZ_MAX   1526U

Upper admissible frequency (when internal clock used)

◆ PCA9685_FREQ_HZ_MIN

#define PCA9685_FREQ_HZ_MIN   24U

Lower admissible frequency (when internal clock used)

Function Documentation

◆ PCA9685_Byte_To_Freq()

float PCA9685_Byte_To_Freq ( PCA9685_t *const pCpnt,
const uint8_t reg )
inline

Convert Prescaler byte register to Frequency (in Hz)

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]reg- Prescaler register value
Returns
Frequency of PCA9685 outputs
Here is the caller graph for this function:

◆ PCA9685_CalcVal()

FctERR PCA9685_CalcVal ( uint8_t val[4],
const uint16_t duty,
const uint16_t delay )

Computes values for PCA9685 registers (4bytes) following duty and delay.

Note
Useful to manually fill an array with registers values to send multiple channels at once in one I2C transaction
If no delay is required, PCA9685_CalcVal_NoDelay may be used instead
Parameters
[in,out]val- Pointer to 4 bytes array output
[in]duty- Duty cycle coded on 12b (0-4095)
[in]delay- Delay coded on 12b (0-<4095)
Returns
FctERR - error code
Here is the caller graph for this function:

◆ PCA9685_CalcVal_NoDelay()

FctERR PCA9685_CalcVal_NoDelay ( uint8_t val[4],
const uint16_t duty )

Computes values for PCA9685 registers (4bytes) following duty (without delay)

Note
Useful to manually fill an array with registers values to send multiple channels at once in one I2C transaction
Parameters
[in,out]val- Pointer to 4 bytes array output
[in]duty- Duty cycle coded on 12b (0-4095)
Returns
FctERR - error code

◆ PCA9685_ClrVal()

FctERR PCA9685_ClrVal ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan )

Compute and send PWM Full OFF value to apply on a PCA9685 channel or all channels (no delay)

Note
No configured delay
Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- Channel number (1 to 16 / PCA9685_ALLCALL can be used to address all channels at the same time)
Returns
FctERR - ErrorCode
Here is the call graph for this function:

◆ PCA9685_Freq_To_Byte()

FctERR PCA9685_Freq_To_Byte ( const PCA9685_t *const pCpnt,
uint8_t *const byte,
const uint16_t freq )

Convert Frequency to Prescaler byte register.

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in,out]byte- Pointer to output value
[in]freq- Outputs frequency in Hz
Returns
FctERR - error code
Here is the caller graph for this function:

◆ PCA9685_OE_GPIO_Init()

void PCA9685_OE_GPIO_Init ( PCA9685_t *const pCpnt,
GPIO_TypeDef *const GPIOx,
const uint16_t GPIO_Pin,
const GPIO_PinState GPIO_Active )

Output Enable GPIO pin init for PCA9685.

Weak Functions
PCA9685 Output Enable GPIO pin init may be user implemented if needed
Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]GPIOx- OE port
[in]GPIO_Pin- OE pin
[in]GPIO_ActiveOE pin active state
Here is the call graph for this function:

◆ PCA9685_OE_GPIO_Set()

void PCA9685_OE_GPIO_Set ( PCA9685_t *const pCpnt,
const bool state )

Output Enable GPIO pin setter for PCA9685.

Weak Functions
PCA9685 Output Enable GPIO pin setter may be user implemented if needed
Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]state- state to write on OE pin (0: inactive, 1: active)
Here is the call graph for this function:

◆ PCA9685_PutVal()

FctERR PCA9685_PutVal ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan,
const uint16_t duty,
const uint16_t delay )

Compute and send PWM lighting values to apply on a PCA9685 channel or all channels (12b)

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- Channel number (1 to 16 / PCA9685_ALLCALL can be used to address all channels at the same time)
[in]duty- Duty cycle coded on 12b (0-4095)
[in]delay- Delay coded on 12b (0-<4095)
Returns
FctERR - ErrorCode
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCA9685_PutValByte()

FctERR PCA9685_PutValByte ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan,
const uint8_t duty,
const uint8_t delay )
inline

Compute and send PWM lighting values to apply on a PCA9685 channel or all channels (Byte)

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- Channel number (1 to 16 / PCA9685_ALLCALL can be used to address all channels at the same time)
[in]duty- Duty cycle coded on uint8_t (0-255)
[in]delay- Delay coded on uint8_t (0-<255)
Returns
FctERR - ErrorCode
Here is the call graph for this function:

◆ PCA9685_PutValPerc()

FctERR PCA9685_PutValPerc ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan,
const float duty,
const float delay )

Compute and send PWM lighting values to apply on a PCA9685 channel or all channels (Percent)

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- Channel number (1 to 16 / PCA9685_ALLCALL can be used to address all channels at the same time)
[in]duty- Duty cycle coded on float (0.0-100.0%)
[in]delay- Delay coded on float (0.0-<100.0%)
Returns
FctERR - ErrorCode
Here is the call graph for this function:

◆ PCA9685_ReadRegister()

FctERR PCA9685_ReadRegister ( PCA9685_t *const pCpnt,
const PCA9685_reg reg,
uint8_t *const val )

Reads register from PCA9685.

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]reg- Register address to read from
[in,out]val- Pointer to the data for receive
Returns
FctERR - ErrorCode
Here is the call graph for this function:

◆ PCA9685_ReadVal()

FctERR PCA9685_ReadVal ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan,
uint16_t * duty )

Read I2C lighting values from a LED and Computes the corresponding duty cycle value (12b)

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- Channel number (1 to 16)
[in,out]duty- Pointer to the DutyCycle data for receive coded on 12b
Returns
FctERR - ErrorCode
Here is the call graph for this function:

◆ PCA9685_ReadValByte()

FctERR PCA9685_ReadValByte ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan,
uint8_t * duty )

Read I2C lighting values from a LED and Computes the corresponding duty cycle value (Byte)

Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- chan number (1 to 16)
[in,out]duty- Pointer to the DutyCycle data for receive coded on a Byte
Returns
FctERR - ErrorCode
Here is the call graph for this function:

◆ PCA9685_Reset()

FctERR PCA9685_Reset ( PCA9685_t *const pCpnt)

Reset for PCA9685 peripheral.

Parameters
[in]pCpnt- Pointer to PCA9685 component
Returns
FctERR - error code

◆ PCA9685_Reset_All()

FctERR PCA9685_Reset_All ( I2C_HandleTypeDef *const hi2c)

General call reset function for PCA9685.

Parameters
[in]hi2c- pointer to general call I2C instance
Returns
FctERR - error code

◆ PCA9685_Set_Frequency()

FctERR PCA9685_Set_Frequency ( PCA9685_t *const pCpnt,
const uint16_t freq )

Set frequency for PCA9685 peripheral.

Note
Prescaler is calculated according to the use of PCA9685 internal oscillator
Freq(Hz) = Clock / ((PSCx(8b) + 1) * 4096) -> Internal clock is 25000000
Warning
beware for higher frequencies, using internal clock: 1526Hz max (3 in reg) drops to 1220Hz (4 in reg), 1017Hz (5 in reg)....
Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]freq- Frequency to apply (in Hz)
Returns
FctERR - error code
Here is the call graph for this function:

◆ PCA9685_Set_Latch()

FctERR PCA9685_Set_Latch ( PCA9685_t *const pCpnt,
const PCA96xx_latch latch )

Set latch type for PCA9685 peripheral.

Parameters
[in,out]pCpnt- Pointer to PCA9685 component
[in]latch- Latch type
Returns
FctERR - error code
Here is the call graph for this function:

◆ PCA9685_SetVal()

FctERR PCA9685_SetVal ( PCA9685_t *const pCpnt,
const PCA9xxx_chan chan )

Compute and send PWM Full ON value to apply on a PCA9685 channel or all channels (no delay)

Note
No configured delay
Parameters
[in]pCpnt- Pointer to PCA9685 component
[in]chan- Channel number (1 to 16 / PCA9685_ALLCALL can be used to address all channels at the same time)
Returns
FctERR - ErrorCode
Here is the call graph for this function: