LibDriver PCA9685  1.0.0
PCA9685 full-featured driver
driver_pca9685.c File Reference

driver pca9685 source file More...

#include "driver_pca9685.h"
#include <math.h>

Go to the source code of this file.

Macros

#define CHIP_NAME   "NXP PCA9685"
 chip information definition More...
 
#define MANUFACTURER_NAME   "NXP"
 
#define SUPPLY_VOLTAGE_MIN   2.3f
 
#define SUPPLY_VOLTAGE_MAX   5.5f
 
#define MAX_CURRENT   400.0f
 
#define TEMPERATURE_MIN   -40.0f
 
#define TEMPERATURE_MAX   85.0f
 
#define DRIVER_VERSION   1000
 
#define PCA9685_REG_MODE1   0x00
 chip register definition More...
 
#define PCA9685_REG_MODE2   0x01
 
#define PCA9685_REG_SUBADR1   0x02
 
#define PCA9685_REG_SUBADR2   0x03
 
#define PCA9685_REG_SUBADR3   0x04
 
#define PCA9685_REG_ALLCALLADR   0x05
 
#define PCA9685_REG_LED0_ON_L   0x06
 
#define PCA9685_REG_LED0_ON_H   0x07
 
#define PCA9685_REG_LED0_OFF_L   0x08
 
#define PCA9685_REG_LED0_OFF_H   0x09
 
#define PCA9685_REG_ALL_LED_ON_L   0xFA
 
#define PCA9685_REG_ALL_LED_ON_H   0xFB
 
#define PCA9685_REG_ALL_LED_OFF_L   0xFC
 
#define PCA9685_REG_ALL_LED_OFF_H   0xFD
 
#define PCA9685_REG_PRE_SCALE   0xFE
 

Functions

uint8_t pca9685_set_addr_pin (pca9685_handle_t *handle, pca9685_address_t addr_pin)
 set the address pin More...
 
uint8_t pca9685_get_addr_pin (pca9685_handle_t *handle, pca9685_address_t *addr_pin)
 get the address pin More...
 
uint8_t pca9685_set_addr (pca9685_handle_t *handle, uint8_t addr)
 set the address More...
 
uint8_t pca9685_get_addr (pca9685_handle_t *handle, uint8_t *addr)
 get the address More...
 
uint8_t pca9685_set_active (pca9685_handle_t *handle, pca9685_bool_t enable)
 set the chip active More...
 
uint8_t pca9685_set_restart (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable restart More...
 
uint8_t pca9685_get_restart (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the restart status More...
 
uint8_t pca9685_set_external_clock_pin (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable the external clock pin More...
 
uint8_t pca9685_get_external_clock_pin (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the external clock pin status More...
 
uint8_t pca9685_set_register_auto_increment (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable the register auto increment More...
 
uint8_t pca9685_get_register_auto_increment (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the register auto increment status More...
 
uint8_t pca9685_set_sleep_mode (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable the sleep mode More...
 
uint8_t pca9685_get_sleep_mode (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the sleep mode status More...
 
uint8_t pca9685_set_respond_subaddress_1 (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable respond sub address 1 More...
 
uint8_t pca9685_get_respond_subaddress_1 (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the respond sub address 1 status More...
 
uint8_t pca9685_set_respond_subaddress_2 (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable respond sub address 2 More...
 
uint8_t pca9685_get_respond_subaddress_2 (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the respond sub address 2 status More...
 
uint8_t pca9685_set_respond_subaddress_3 (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable respond sub address 3 More...
 
uint8_t pca9685_get_respond_subaddress_3 (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the respond sub address 3 status More...
 
uint8_t pca9685_set_respond_all_call (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable respond all call More...
 
uint8_t pca9685_get_respond_all_call (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the respond all call status More...
 
uint8_t pca9685_set_output_invert (pca9685_handle_t *handle, pca9685_bool_t enable)
 enable or disable output invert More...
 
uint8_t pca9685_get_output_invert (pca9685_handle_t *handle, pca9685_bool_t *enable)
 get the output invert status More...
 
uint8_t pca9685_set_output_change (pca9685_handle_t *handle, pca9685_output_change_t change)
 set the output change type More...
 
uint8_t pca9685_get_output_change (pca9685_handle_t *handle, pca9685_output_change_t *change)
 get the output change type More...
 
uint8_t pca9685_set_output_driver (pca9685_handle_t *handle, pca9685_output_driver_t driver)
 set the output driver type More...
 
uint8_t pca9685_get_output_driver (pca9685_handle_t *handle, pca9685_output_driver_t *driver)
 get the output driver type More...
 
uint8_t pca9685_set_output_disable_type (pca9685_handle_t *handle, pca9685_output_disable_type_t type)
 set the output disable type More...
 
uint8_t pca9685_get_output_disable_type (pca9685_handle_t *handle, pca9685_output_disable_type_t *type)
 get the output disable type More...
 
uint8_t pca9685_set_subaddress_1 (pca9685_handle_t *handle, uint8_t addr)
 set the sub address 1 More...
 
uint8_t pca9685_get_subaddress_1 (pca9685_handle_t *handle, uint8_t *addr)
 get the sub address 1 More...
 
uint8_t pca9685_set_subaddress_2 (pca9685_handle_t *handle, uint8_t addr)
 set the sub address 2 More...
 
uint8_t pca9685_get_subaddress_2 (pca9685_handle_t *handle, uint8_t *addr)
 get the sub address 2 More...
 
uint8_t pca9685_set_subaddress_3 (pca9685_handle_t *handle, uint8_t addr)
 set the sub address 3 More...
 
uint8_t pca9685_get_subaddress_3 (pca9685_handle_t *handle, uint8_t *addr)
 get the sub address 3 More...
 
uint8_t pca9685_set_all_call_address (pca9685_handle_t *handle, uint8_t addr)
 set the all call address More...
 
uint8_t pca9685_get_all_call_address (pca9685_handle_t *handle, uint8_t *addr)
 set the all call address More...
 
uint8_t pca9685_write_channel (pca9685_handle_t *handle, pca9685_channel_t channel, uint16_t on_count, uint16_t off_count)
 write led channels More...
 
uint8_t pca9685_read_channel (pca9685_handle_t *handle, pca9685_channel_t channel, uint16_t *on_count, uint16_t *off_count)
 read led channels More...
 
uint8_t pca9685_write_all_channel (pca9685_handle_t *handle, uint16_t on_count, uint16_t off_count)
 write all led channels More...
 
uint8_t pca9685_set_prescaler (pca9685_handle_t *handle, uint8_t prescaler)
 set the clock pres cale More...
 
uint8_t pca9685_get_prescaler (pca9685_handle_t *handle, uint8_t *prescaler)
 get the clock pre scale More...
 
uint8_t pca9685_output_frequency_convert_to_register (pca9685_handle_t *handle, uint32_t oscillator, uint16_t output_freq, uint8_t *reg)
 convert the output frequency to the register raw data More...
 
uint8_t pca9685_output_frequency_convert_to_data (pca9685_handle_t *handle, uint32_t oscillator, uint8_t reg, uint16_t *output_freq)
 convert the register raw data to the output frequency More...
 
uint8_t pca9685_pwm_convert_to_register (pca9685_handle_t *handle, float delay_percent, float high_duty_cycle_percent, uint16_t *on_count, uint16_t *off_count)
 convert the pwm to the register raw data More...
 
uint8_t pca9685_pwm_convert_to_data (pca9685_handle_t *handle, uint16_t on_count, uint16_t off_count, float *delay_percent, float *high_duty_cycle_percent)
 convert the register raw data to the pwm More...
 
uint8_t pca9685_init (pca9685_handle_t *handle)
 initialize the chip More...
 
uint8_t pca9685_deinit (pca9685_handle_t *handle)
 close the chip More...
 
uint8_t pca9685_set_reg (pca9685_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
 set the chip register More...
 
uint8_t pca9685_get_reg (pca9685_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
 get the chip register More...
 
uint8_t pca9685_info (pca9685_info_t *info)
 get chip's information More...
 

Detailed Description

driver pca9685 source file

Copyright (c) 2015 - present LibDriver All rights reserved

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version
1.0.0
Author
Shifeng Li
Date
2022-02-20

history

Date Version Author Description
2022/02/20 1.0 Shifeng Li first upload

Definition in file driver_pca9685.c.

Macro Definition Documentation

◆ CHIP_NAME

#define CHIP_NAME   "NXP PCA9685"

chip information definition

chip name

Definition at line 43 of file driver_pca9685.c.

◆ DRIVER_VERSION

#define DRIVER_VERSION   1000

driver version

Definition at line 50 of file driver_pca9685.c.

◆ MANUFACTURER_NAME

#define MANUFACTURER_NAME   "NXP"

manufacturer name

Definition at line 44 of file driver_pca9685.c.

◆ MAX_CURRENT

#define MAX_CURRENT   400.0f

chip max current

Definition at line 47 of file driver_pca9685.c.

◆ PCA9685_REG_ALL_LED_OFF_H

#define PCA9685_REG_ALL_LED_OFF_H   0xFD

load all the led_off registers byte 1

Definition at line 68 of file driver_pca9685.c.

◆ PCA9685_REG_ALL_LED_OFF_L

#define PCA9685_REG_ALL_LED_OFF_L   0xFC

load all the led_off registers byte 0

Definition at line 67 of file driver_pca9685.c.

◆ PCA9685_REG_ALL_LED_ON_H

#define PCA9685_REG_ALL_LED_ON_H   0xFB

load all the led_on registers byte 1

Definition at line 66 of file driver_pca9685.c.

◆ PCA9685_REG_ALL_LED_ON_L

#define PCA9685_REG_ALL_LED_ON_L   0xFA

load all the led_on registers byte 0

Definition at line 65 of file driver_pca9685.c.

◆ PCA9685_REG_ALLCALLADR

#define PCA9685_REG_ALLCALLADR   0x05

led all call iic bus address

Definition at line 60 of file driver_pca9685.c.

◆ PCA9685_REG_LED0_OFF_H

#define PCA9685_REG_LED0_OFF_H   0x09

led0 output and brightness control byte 3

Definition at line 64 of file driver_pca9685.c.

◆ PCA9685_REG_LED0_OFF_L

#define PCA9685_REG_LED0_OFF_L   0x08

led0 output and brightness control byte 2

Definition at line 63 of file driver_pca9685.c.

◆ PCA9685_REG_LED0_ON_H

#define PCA9685_REG_LED0_ON_H   0x07

led0 output and brightness control byte 1

Definition at line 62 of file driver_pca9685.c.

◆ PCA9685_REG_LED0_ON_L

#define PCA9685_REG_LED0_ON_L   0x06

led0 output and brightness control byte 0

Definition at line 61 of file driver_pca9685.c.

◆ PCA9685_REG_MODE1

#define PCA9685_REG_MODE1   0x00

chip register definition

mode register 1

Definition at line 55 of file driver_pca9685.c.

◆ PCA9685_REG_MODE2

#define PCA9685_REG_MODE2   0x01

mode register 2

Definition at line 56 of file driver_pca9685.c.

◆ PCA9685_REG_PRE_SCALE

#define PCA9685_REG_PRE_SCALE   0xFE

pre scale for pwm output frequency

Definition at line 69 of file driver_pca9685.c.

◆ PCA9685_REG_SUBADR1

#define PCA9685_REG_SUBADR1   0x02

iic bus sub address 1

Definition at line 57 of file driver_pca9685.c.

◆ PCA9685_REG_SUBADR2

#define PCA9685_REG_SUBADR2   0x03

iic bus sub address 2

Definition at line 58 of file driver_pca9685.c.

◆ PCA9685_REG_SUBADR3

#define PCA9685_REG_SUBADR3   0x04

iic bus sub address 3

Definition at line 59 of file driver_pca9685.c.

◆ SUPPLY_VOLTAGE_MAX

#define SUPPLY_VOLTAGE_MAX   5.5f

chip max supply voltage

Definition at line 46 of file driver_pca9685.c.

◆ SUPPLY_VOLTAGE_MIN

#define SUPPLY_VOLTAGE_MIN   2.3f

chip min supply voltage

Definition at line 45 of file driver_pca9685.c.

◆ TEMPERATURE_MAX

#define TEMPERATURE_MAX   85.0f

chip max operating temperature

Definition at line 49 of file driver_pca9685.c.

◆ TEMPERATURE_MIN

#define TEMPERATURE_MIN   -40.0f

chip min operating temperature

Definition at line 48 of file driver_pca9685.c.