44#define CHIP_NAME "NXP PCA9685"
45#define MANUFACTURER_NAME "NXP"
46#define SUPPLY_VOLTAGE_MIN 2.3f
47#define SUPPLY_VOLTAGE_MAX 5.5f
48#define MAX_CURRENT 400.0f
49#define TEMPERATURE_MIN -40.0f
50#define TEMPERATURE_MAX 85.0f
51#define DRIVER_VERSION 1000
56#define PCA9685_REG_MODE1 0x00
57#define PCA9685_REG_MODE2 0x01
58#define PCA9685_REG_SUBADR1 0x02
59#define PCA9685_REG_SUBADR2 0x03
60#define PCA9685_REG_SUBADR3 0x04
61#define PCA9685_REG_ALLCALLADR 0x05
62#define PCA9685_REG_LED0_ON_L 0x06
63#define PCA9685_REG_LED0_ON_H 0x07
64#define PCA9685_REG_LED0_OFF_L 0x08
65#define PCA9685_REG_LED0_OFF_H 0x09
66#define PCA9685_REG_ALL_LED_ON_L 0xFA
67#define PCA9685_REG_ALL_LED_ON_H 0xFB
68#define PCA9685_REG_ALL_LED_OFF_L 0xFC
69#define PCA9685_REG_ALL_LED_OFF_H 0xFD
70#define PCA9685_REG_PRE_SCALE 0xFE
181 handle->
debug_print(
"pca9685: gpio write failed.\n");
217 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
226 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
262 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
299 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
308 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
344 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
381 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
390 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
426 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
463 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
472 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
508 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
545 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
554 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
590 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
627 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
636 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
672 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
709 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
718 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
754 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
791 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
800 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
836 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
873 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
882 handle->
debug_print(
"pca9685: write mode 2 register failed.\n");
918 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
955 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
964 handle->
debug_print(
"pca9685: write mode 2 register failed.\n");
1000 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
1037 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
1042 prev |= driver << 2;
1046 handle->
debug_print(
"pca9685: write mode 2 register failed.\n");
1082 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
1119 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
1128 handle->
debug_print(
"pca9685: write mode 2 register failed.\n");
1164 handle->
debug_print(
"pca9685: read mode 2 register failed.\n");
1200 handle->
debug_print(
"pca9685: write sub address 1 register failed.\n");
1235 handle->
debug_print(
"pca9685: read sub address 1 register failed.\n");
1270 handle->
debug_print(
"pca9685: write sub address 2 register failed.\n");
1305 handle->
debug_print(
"pca9685: read sub address 2 register failed.\n");
1340 handle->
debug_print(
"pca9685: write sub address 3 register failed.\n");
1375 handle->
debug_print(
"pca9685: read sub address 3 register failed.\n");
1410 handle->
debug_print(
"pca9685: write all call address register failed.\n");
1445 handle->
debug_print(
"pca9685: read all call address register failed.\n");
1480 if ((on_count > 4096) || (off_count > 4096))
1482 handle->
debug_print(
"pca9685: on_count or off_count is over 4096.\n");
1487 buf[0] = (on_count >> 0) & 0xFF;
1488 buf[1] = (on_count >> 8) & 0x1F;
1489 buf[2] = (off_count >> 0) & 0xFF;
1490 buf[3] = (off_count >> 8) & 0x1F;
1495 handle->
debug_print(
"pca9685: write led register failed.\n");
1530 memset(buf, 0,
sizeof(uint8_t) * 4);
1535 handle->
debug_print(
"pca9685: read led register failed.\n");
1539 *on_count = ((uint16_t)(buf[1]) & 0x1F) << 8 | buf[0];
1540 *off_count = ((uint16_t)(buf[3]) & 0x1F) << 8 | buf[2];
1571 if ((on_count > 4096) || (off_count > 4096))
1573 handle->
debug_print(
"pca9685: on_count or off_count is over 4096.\n");
1578 buf[0] = (on_count >> 0) & 0xFF;
1579 buf[1] = (on_count >> 8) & 0x1F;
1580 buf[2] = (off_count >> 0) & 0xFF;
1581 buf[3] = (off_count >> 8) & 0x1F;
1585 handle->
debug_print(
"pca9685: write all led register failed.\n");
1619 handle->
debug_print(
"pca9685: pre scale must be >= 3.\n");
1627 handle->
debug_print(
"pca9685: write pre scale register failed.\n");
1662 handle->
debug_print(
"pca9685: read pre scale register failed.\n");
1693 *reg = (uint8_t)(round((
double)oscillator / ((
double)output_freq * 4096.0))) - 1;
1721 *output_freq = (uint16_t)(round((
double)oscillator / ((reg + 1) * 4096.0)));
1743 uint16_t *on_count, uint16_t *off_count)
1753 if (delay_percent + high_duty_cycle_percent > 100.0f)
1755 handle->
debug_print(
"pca9685: delay_percent + high_duty_cycle_percent can't be over 100.0.\n");
1760 if (delay_percent < FLT_MIN)
1766 *on_count = (uint16_t)(roundf(delay_percent / 100.0f * 4096.0f)) - 1;
1768 if (high_duty_cycle_percent < FLT_MIN)
1774 *off_count = (uint16_t)(roundf((delay_percent + high_duty_cycle_percent) / 100.0f * 4096.0f)) - 1;
1795 float *delay_percent,
float *high_duty_cycle_percent)
1805 if ((on_count > 4096) || (off_count > 4096))
1807 handle->
debug_print(
"pca9685: on_count or off_count is over 4096.\n");
1814 *delay_percent = (float)(on_count + 1) / 4096.0f * 100.0f;
1818 *delay_percent = 0.0f;
1822 *high_duty_cycle_percent = (float)(off_count - on_count) / 4096.0f * 100.0f;
1826 *high_duty_cycle_percent = 0.0f;
1857 handle->
debug_print(
"pca9685: iic_init is null.\n");
1863 handle->
debug_print(
"pca9685: iic_deinit is null.\n");
1869 handle->
debug_print(
"pca9685: iic_read is null.\n");
1875 handle->
debug_print(
"pca9685: iic_write is null.\n");
1881 handle->
debug_print(
"pca9685: oe_gpio_init is null.\n");
1887 handle->
debug_print(
"pca9685: oe_gpio_deinit is null.\n");
1893 handle->
debug_print(
"pca9685: oe_gpio_write is null.\n");
1900 handle->
debug_print(
"pca9685: iic init failed.\n");
1906 handle->
debug_print(
"pca9685: oe gpio init failed.\n");
1915 handle->
debug_print(
"pca9685: read mode 1 register failed.\n");
1921 if ((prev & 0x80) != 0)
1927 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
1942 handle->
debug_print(
"pca9685: write mode 1 register failed.\n");
1981 handle->
debug_print(
"pca9685: power down failed failed.\n");
1989 handle->
debug_print(
"pca9685: power down failed failed.\n");
1995 handle->
debug_print(
"pca9685: oe gpio deinit failed.\n");
2001 handle->
debug_print(
"pca9685: iic deinit failed.\n");
#define PCA9685_REG_SUBADR3
#define PCA9685_REG_ALL_LED_ON_L
#define SUPPLY_VOLTAGE_MAX
#define PCA9685_REG_MODE2
#define PCA9685_REG_SUBADR1
#define PCA9685_REG_MODE1
chip register definition
#define PCA9685_REG_SUBADR2
#define PCA9685_REG_PRE_SCALE
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define PCA9685_REG_LED0_ON_L
#define CHIP_NAME
chip information definition
#define PCA9685_REG_ALLCALLADR
driver pca9685 header file
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
uint8_t pca9685_set_prescaler(pca9685_handle_t *handle, uint8_t prescaler)
set the clock pres cale
uint8_t pca9685_write_channel(pca9685_handle_t *handle, pca9685_channel_t channel, uint16_t on_count, uint16_t off_count)
write led channels
pca9685_bool_t
pca9685 bool enumeration definition
uint8_t pca9685_get_subaddress_1(pca9685_handle_t *handle, uint8_t *addr)
get the sub address 1
uint8_t pca9685_write_all_channel(pca9685_handle_t *handle, uint16_t on_count, uint16_t off_count)
write all led channels
pca9685_address_t
pca9685 address enumeration definition
uint8_t pca9685_get_addr_pin(pca9685_handle_t *handle, pca9685_address_t *addr_pin)
get the address pin
uint8_t pca9685_set_addr(pca9685_handle_t *handle, uint8_t addr)
set the address
uint8_t pca9685_get_respond_all_call(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the respond all call status
struct pca9685_handle_s pca9685_handle_t
pca9685 handle structure definition
uint8_t pca9685_set_respond_all_call(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable respond all call
uint8_t pca9685_init(pca9685_handle_t *handle)
initialize the chip
uint8_t pca9685_set_active(pca9685_handle_t *handle, pca9685_bool_t enable)
set the chip active
uint8_t pca9685_get_output_change(pca9685_handle_t *handle, pca9685_output_change_t *change)
get the output change type
uint8_t pca9685_get_all_call_address(pca9685_handle_t *handle, uint8_t *addr)
get the all call address
uint8_t pca9685_set_addr_pin(pca9685_handle_t *handle, pca9685_address_t addr_pin)
set the address pin
uint8_t pca9685_get_external_clock_pin(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the external clock pin status
pca9685_output_disable_type_t
pca9685 output disable type enumeration definition
uint8_t pca9685_get_restart(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the restart status
uint8_t pca9685_set_output_driver(pca9685_handle_t *handle, pca9685_output_driver_t driver)
set the output driver type
uint8_t pca9685_set_respond_subaddress_2(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable respond sub address 2
uint8_t pca9685_get_prescaler(pca9685_handle_t *handle, uint8_t *prescaler)
get the clock pre scale
uint8_t pca9685_get_addr(pca9685_handle_t *handle, uint8_t *addr)
get the address
uint8_t pca9685_get_sleep_mode(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the sleep mode status
uint8_t pca9685_set_output_disable_type(pca9685_handle_t *handle, pca9685_output_disable_type_t type)
set the output disable type
uint8_t pca9685_get_subaddress_3(pca9685_handle_t *handle, uint8_t *addr)
get the sub address 3
uint8_t pca9685_read_channel(pca9685_handle_t *handle, pca9685_channel_t channel, uint16_t *on_count, uint16_t *off_count)
read led channels
uint8_t pca9685_get_output_driver(pca9685_handle_t *handle, pca9685_output_driver_t *driver)
get the output driver type
uint8_t pca9685_set_subaddress_2(pca9685_handle_t *handle, uint8_t addr)
set the sub address 2
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
uint8_t pca9685_set_register_auto_increment(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable the register auto increment
uint8_t pca9685_set_respond_subaddress_3(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable respond sub address 3
uint8_t pca9685_info(pca9685_info_t *info)
get chip's information
uint8_t pca9685_set_output_invert(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable output invert
uint8_t pca9685_get_respond_subaddress_2(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the respond sub address 2 status
uint8_t pca9685_get_subaddress_2(pca9685_handle_t *handle, uint8_t *addr)
get the sub address 2
pca9685_channel_t
pca9685 channel enumeration definition
uint8_t pca9685_get_output_disable_type(pca9685_handle_t *handle, pca9685_output_disable_type_t *type)
get the output disable type
uint8_t pca9685_set_subaddress_1(pca9685_handle_t *handle, uint8_t addr)
set the sub address 1
uint8_t pca9685_set_restart(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable restart
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
pca9685_output_driver_t
pca9685 output driver enumeration definition
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
uint8_t pca9685_set_sleep_mode(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable the sleep mode
struct pca9685_info_s pca9685_info_t
pca9685 information structure definition
uint8_t pca9685_get_respond_subaddress_1(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the respond sub address 1 status
uint8_t pca9685_get_output_invert(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the output invert status
uint8_t pca9685_set_external_clock_pin(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable the external clock pin
pca9685_output_change_t
pca9685 output change enumeration definition
uint8_t pca9685_deinit(pca9685_handle_t *handle)
close the chip
uint8_t pca9685_get_respond_subaddress_3(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the respond sub address 3 status
uint8_t pca9685_set_respond_subaddress_1(pca9685_handle_t *handle, pca9685_bool_t enable)
enable or disable respond sub address 1
uint8_t pca9685_set_subaddress_3(pca9685_handle_t *handle, uint8_t addr)
set the sub address 3
uint8_t pca9685_set_all_call_address(pca9685_handle_t *handle, uint8_t addr)
set the all call address
uint8_t pca9685_set_output_change(pca9685_handle_t *handle, pca9685_output_change_t change)
set the output change type
uint8_t pca9685_get_register_auto_increment(pca9685_handle_t *handle, pca9685_bool_t *enable)
get the register auto increment status
uint8_t pca9685_set_reg(pca9685_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t pca9685_get_reg(pca9685_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
uint8_t(* oe_gpio_init)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* oe_gpio_deinit)(void)
uint8_t(* oe_gpio_write)(uint8_t value)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v