43 #define CHIP_NAME "NXP PCA9685"
44 #define MANUFACTURER_NAME "NXP"
45 #define SUPPLY_VOLTAGE_MIN 2.3f
46 #define SUPPLY_VOLTAGE_MAX 5.5f
47 #define MAX_CURRENT 400.0f
48 #define TEMPERATURE_MIN -40.0f
49 #define TEMPERATURE_MAX 85.0f
50 #define DRIVER_VERSION 1000
55 #define PCA9685_REG_MODE1 0x00
56 #define PCA9685_REG_MODE2 0x01
57 #define PCA9685_REG_SUBADR1 0x02
58 #define PCA9685_REG_SUBADR2 0x03
59 #define PCA9685_REG_SUBADR3 0x04
60 #define PCA9685_REG_ALLCALLADR 0x05
61 #define PCA9685_REG_LED0_ON_L 0x06
62 #define PCA9685_REG_LED0_ON_H 0x07
63 #define PCA9685_REG_LED0_OFF_L 0x08
64 #define PCA9685_REG_LED0_OFF_H 0x09
65 #define PCA9685_REG_ALL_LED_ON_L 0xFA
66 #define PCA9685_REG_ALL_LED_ON_H 0xFB
67 #define PCA9685_REG_ALL_LED_OFF_L 0xFC
68 #define PCA9685_REG_ALL_LED_OFF_H 0xFD
69 #define PCA9685_REG_PRE_SCALE 0xFE
180 handle->
debug_print(
"pcf8591: gpio write failed.\n");
216 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
225 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
261 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
298 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
307 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
343 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
380 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
389 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
425 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
462 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
471 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
507 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
544 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
553 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
589 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
626 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
635 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
671 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
708 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
717 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
753 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
790 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
799 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
835 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
872 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
881 handle->
debug_print(
"pcf8591: write mode 2 register failed.\n");
917 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
954 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
963 handle->
debug_print(
"pcf8591: write mode 2 register failed.\n");
999 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
1036 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
1041 prev |= driver << 2;
1045 handle->
debug_print(
"pcf8591: write mode 2 register failed.\n");
1081 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
1118 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
1127 handle->
debug_print(
"pcf8591: write mode 2 register failed.\n");
1163 handle->
debug_print(
"pcf8591: read mode 2 register failed.\n");
1199 handle->
debug_print(
"pcf8591: write sub address 1 register failed.\n");
1234 handle->
debug_print(
"pcf8591: read sub address 1 register failed.\n");
1269 handle->
debug_print(
"pcf8591: write sub address 2 register failed.\n");
1304 handle->
debug_print(
"pcf8591: read sub address 2 register failed.\n");
1339 handle->
debug_print(
"pcf8591: write sub address 3 register failed.\n");
1374 handle->
debug_print(
"pcf8591: read sub address 3 register failed.\n");
1409 handle->
debug_print(
"pcf8591: write all call address register failed.\n");
1444 handle->
debug_print(
"pcf8591: read all call address register failed.\n");
1479 if ((on_count > 4096) || (off_count > 4096))
1481 handle->
debug_print(
"pcf8591: on_count or off_count is over 4096.\n");
1486 buf[0] = (on_count >> 0) & 0xFF;
1487 buf[1] = (on_count >> 8) & 0x1F;
1488 buf[2] = (off_count >> 0) & 0xFF;
1489 buf[3] = (off_count >> 8) & 0x1F;
1494 handle->
debug_print(
"pcf8591: write led register failed.\n");
1529 memset(buf, 0,
sizeof(uint8_t) * 4);
1534 handle->
debug_print(
"pcf8591: read led register failed.\n");
1538 *on_count = ((uint16_t)(buf[1]) & 0x1F) << 8 | buf[0];
1539 *off_count = ((uint16_t)(buf[3]) & 0x1F) << 8 | buf[2];
1570 if ((on_count > 4096) || (off_count > 4096))
1572 handle->
debug_print(
"pcf8591: on_count or off_count is over 4096.\n");
1577 buf[0] = (on_count >> 0) & 0xFF;
1578 buf[1] = (on_count >> 8) & 0x1F;
1579 buf[2] = (off_count >> 0) & 0xFF;
1580 buf[3] = (off_count >> 8) & 0x1F;
1584 handle->
debug_print(
"pcf8591: write all led register failed.\n");
1618 handle->
debug_print(
"pcf8591: pre scale must be >= 3.\n");
1626 handle->
debug_print(
"pcf8591: write pre scale register failed.\n");
1661 handle->
debug_print(
"pcf8591: read pre scale register failed.\n");
1692 *reg = (uint8_t)(round((
double)oscillator / ((
double)output_freq * 4096.0))) - 1;
1720 *output_freq = (uint16_t)(round((
double)oscillator / ((reg + 1) * 4096.0)));
1742 uint16_t *on_count, uint16_t *off_count)
1752 if (delay_percent + high_duty_cycle_percent >=100.0f)
1754 handle->
debug_print(
"pcf8591: delay_percent + high_duty_cycle_percent can't be over 100.0.\n");
1759 *on_count = (uint16_t)(roundf(delay_percent / 100.0f * 4096.0f));
1760 *off_count = (uint16_t)(roundf((delay_percent + high_duty_cycle_percent) / 100.0f * 4096.0f));
1780 float *delay_percent,
float *high_duty_cycle_percent)
1790 if ((on_count > 4096) || (off_count > 4096))
1792 handle->
debug_print(
"pcf8591: on_count or off_count is over 4096.\n");
1797 *delay_percent = (float)(on_count) / 4096.0f * 100.0f;
1798 *high_duty_cycle_percent = (float)(off_count - on_count) / 4096.0f * 100.0f;
1828 handle->
debug_print(
"pca9685: iic_init is null.\n");
1834 handle->
debug_print(
"pca9685: iic_deinit is null.\n");
1840 handle->
debug_print(
"pca9685: iic_read is null.\n");
1846 handle->
debug_print(
"pca9685: iic_write is null.\n");
1852 handle->
debug_print(
"pca9685: oe_gpio_init is null.\n");
1858 handle->
debug_print(
"pca9685: oe_gpio_deinit is null.\n");
1864 handle->
debug_print(
"pca9685: oe_gpio_write is null.\n");
1871 handle->
debug_print(
"pca9685: iic init failed.\n");
1877 handle->
debug_print(
"pca9685: oe gpio init failed.\n");
1886 handle->
debug_print(
"pcf8591: read mode 1 register failed.\n");
1892 if ((prev & 0x80) != 0)
1898 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
1912 handle->
debug_print(
"pcf8591: write mode 1 register failed.\n");
1951 handle->
debug_print(
"pcf8591: power down failed failed.\n");
1959 handle->
debug_print(
"pcf8591: power down failed failed.\n");
1965 handle->
debug_print(
"pcf8591: oe gpio deinit failed.\n");
1971 handle->
debug_print(
"pcf8591: 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
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)
set 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
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
pca9685 handle structure definition
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)
pca9685 information structure definition
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v