LibDriver PCA9685  1.0.0
PCA9685 full-featured driver
driver_pca9685.h
Go to the documentation of this file.
1 
37 #ifndef DRIVER_PCA9685_H
38 #define DRIVER_PCA9685_H
39 
40 #include <stdio.h>
41 #include <stdint.h>
42 #include <string.h>
43 
44 #ifdef __cplusplus
45 extern "C"{
46 #endif
47 
62 #ifndef PCA9685_OSCILLATOR_INTERNAL_FREQUENCY
63  #define PCA9685_OSCILLATOR_INTERNAL_FREQUENCY 25000000
64 #endif
65 
69 typedef enum
70 {
136 
140 typedef enum
141 {
145 
149 typedef enum
150 {
154 
158 typedef enum
159 {
163 
167 typedef enum
168 {
174 
178 typedef enum
179 {
197 
201 typedef struct pca9685_handle_s
202 {
203  uint8_t iic_addr;
204  uint8_t (*iic_init)(void);
205  uint8_t (*iic_deinit)(void);
206  uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
207  uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
208  uint8_t (*oe_gpio_init)(void);
209  uint8_t (*oe_gpio_deinit)(void);
210  uint8_t (*oe_gpio_write)(uint8_t value);
211  void (*delay_ms)(uint32_t ms);
212  void (*debug_print)(const char *const fmt, ...);
213  uint8_t inited;
215 
219 typedef struct pca9685_info_s
220 {
221  char chip_name[32];
222  char manufacturer_name[32];
223  char interface[8];
229  uint32_t driver_version;
231 
249 #define DRIVER_PCA9685_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
250 
257 #define DRIVER_PCA9685_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
258 
265 #define DRIVER_PCA9685_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
266 
273 #define DRIVER_PCA9685_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
274 
281 #define DRIVER_PCA9685_LINK_IIC_WEITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
282 
289 #define DRIVER_PCA9685_LINK_OE_GPIO_INIT(HANDLE, FUC) (HANDLE)->oe_gpio_init = FUC
290 
297 #define DRIVER_PCA9685_LINK_OE_GPIO_DEINIT(HANDLE, FUC) (HANDLE)->oe_gpio_deinit = FUC
298 
305 #define DRIVER_PCA9685_LINK_OE_GPIO_WRITE(HANDLE, FUC) (HANDLE)->oe_gpio_write = FUC
306 
313 #define DRIVER_PCA9685_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
314 
321 #define DRIVER_PCA9685_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
322 
342 uint8_t pca9685_info(pca9685_info_t *info);
343 
353 uint8_t pca9685_set_addr_pin(pca9685_handle_t *handle, pca9685_address_t addr_pin);
354 
364 uint8_t pca9685_get_addr_pin(pca9685_handle_t *handle, pca9685_address_t *addr_pin);
365 
375 uint8_t pca9685_set_addr(pca9685_handle_t *handle, uint8_t addr);
376 
386 uint8_t pca9685_get_addr(pca9685_handle_t *handle, uint8_t *addr);
387 
399 uint8_t pca9685_init(pca9685_handle_t *handle);
400 
412 uint8_t pca9685_deinit(pca9685_handle_t *handle);
413 
428 uint8_t pca9685_write_channel(pca9685_handle_t *handle, pca9685_channel_t channel, uint16_t on_count, uint16_t off_count);
429 
443 uint8_t pca9685_read_channel(pca9685_handle_t *handle, pca9685_channel_t channel, uint16_t *on_count, uint16_t *off_count);
444 
458 uint8_t pca9685_write_all_channel(pca9685_handle_t *handle, uint16_t on_count, uint16_t off_count);
459 
476 uint8_t pca9685_pwm_convert_to_register(pca9685_handle_t *handle, float delay_percent, float high_duty_cycle_percent,
477  uint16_t *on_count, uint16_t *off_count);
478 
493 uint8_t pca9685_pwm_convert_to_data(pca9685_handle_t *handle, uint16_t on_count, uint16_t off_count,
494  float *delay_percent, float *high_duty_cycle_percent);
495 
507 uint8_t pca9685_set_active(pca9685_handle_t *handle, pca9685_bool_t enable);
508 
521 uint8_t pca9685_set_prescaler(pca9685_handle_t *handle, uint8_t prescaler);
522 
534 uint8_t pca9685_get_prescaler(pca9685_handle_t *handle, uint8_t *prescaler);
535 
548 uint8_t pca9685_output_frequency_convert_to_register(pca9685_handle_t *handle, uint32_t oscillator, uint16_t output_freq, uint8_t *reg);
549 
562 uint8_t pca9685_output_frequency_convert_to_data(pca9685_handle_t *handle, uint32_t oscillator, uint8_t reg, uint16_t *output_freq);
563 
575 uint8_t pca9685_set_restart(pca9685_handle_t *handle, pca9685_bool_t enable);
576 
588 uint8_t pca9685_get_restart(pca9685_handle_t *handle, pca9685_bool_t *enable);
589 
602 
615 
628 
641 
654 
666 uint8_t pca9685_get_sleep_mode(pca9685_handle_t *handle, pca9685_bool_t *enable);
667 
680 
693 
706 
719 
732 
745 
758 
771 
784 
797 
810 
823 
836 
849 
862 
875 
887 uint8_t pca9685_set_subaddress_1(pca9685_handle_t *handle, uint8_t addr);
888 
900 uint8_t pca9685_get_subaddress_1(pca9685_handle_t *handle, uint8_t *addr);
901 
913 uint8_t pca9685_set_subaddress_2(pca9685_handle_t *handle, uint8_t addr);
914 
926 uint8_t pca9685_get_subaddress_2(pca9685_handle_t *handle, uint8_t *addr);
927 
939 uint8_t pca9685_set_subaddress_3(pca9685_handle_t *handle, uint8_t addr);
940 
952 uint8_t pca9685_get_subaddress_3(pca9685_handle_t *handle, uint8_t *addr);
953 
965 uint8_t pca9685_set_all_call_address(pca9685_handle_t *handle, uint8_t addr);
966 
978 uint8_t pca9685_get_all_call_address(pca9685_handle_t *handle, uint8_t *addr);
979 
1004 uint8_t pca9685_set_reg(pca9685_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
1005 
1019 uint8_t pca9685_get_reg(pca9685_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
1020 
1029 #ifdef __cplusplus
1030 }
1031 #endif
1032 
1033 #endif
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)
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
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
@ PCA9685_BOOL_FALSE
@ PCA9685_BOOL_TRUE
@ PCA9685_ADDRESS_A011101
@ PCA9685_ADDRESS_A001000
@ PCA9685_ADDRESS_A100010
@ PCA9685_ADDRESS_A100100
@ PCA9685_ADDRESS_A010100
@ PCA9685_ADDRESS_A010001
@ PCA9685_ADDRESS_A100101
@ PCA9685_ADDRESS_A001011
@ PCA9685_ADDRESS_A011001
@ PCA9685_ADDRESS_A110010
@ PCA9685_ADDRESS_A110011
@ PCA9685_ADDRESS_A101000
@ PCA9685_ADDRESS_A000011
@ PCA9685_ADDRESS_A010011
@ PCA9685_ADDRESS_A110000
@ PCA9685_ADDRESS_A010110
@ PCA9685_ADDRESS_A010010
@ PCA9685_ADDRESS_A100110
@ PCA9685_ADDRESS_A001100
@ PCA9685_ADDRESS_A001101
@ PCA9685_ADDRESS_A111000
@ PCA9685_ADDRESS_A100000
@ PCA9685_ADDRESS_A101001
@ PCA9685_ADDRESS_A110100
@ PCA9685_ADDRESS_A000000
@ PCA9685_ADDRESS_A010101
@ PCA9685_ADDRESS_A011011
@ PCA9685_ADDRESS_A011000
@ PCA9685_ADDRESS_A111101
@ PCA9685_ADDRESS_A011100
@ PCA9685_ADDRESS_A010000
@ PCA9685_ADDRESS_A111010
@ PCA9685_ADDRESS_A000111
@ PCA9685_ADDRESS_A100011
@ PCA9685_ADDRESS_A101011
@ PCA9685_ADDRESS_A110001
@ PCA9685_ADDRESS_A110101
@ PCA9685_ADDRESS_A000101
@ PCA9685_ADDRESS_A110111
@ PCA9685_ADDRESS_A111001
@ PCA9685_ADDRESS_A011010
@ PCA9685_ADDRESS_A110110
@ PCA9685_ADDRESS_A101010
@ PCA9685_ADDRESS_A001010
@ PCA9685_ADDRESS_A000001
@ PCA9685_ADDRESS_A000010
@ PCA9685_ADDRESS_A100111
@ PCA9685_ADDRESS_A010111
@ PCA9685_ADDRESS_A001111
@ PCA9685_ADDRESS_A000100
@ PCA9685_ADDRESS_A101101
@ PCA9685_ADDRESS_A111100
@ PCA9685_ADDRESS_A011111
@ PCA9685_ADDRESS_A111011
@ PCA9685_ADDRESS_A011110
@ PCA9685_ADDRESS_A111111
@ PCA9685_ADDRESS_A001110
@ PCA9685_ADDRESS_A100001
@ PCA9685_ADDRESS_A101100
@ PCA9685_ADDRESS_A101111
@ PCA9685_ADDRESS_A111110
@ PCA9685_ADDRESS_A101110
@ PCA9685_ADDRESS_A000110
@ PCA9685_ADDRESS_A001001
@ PCA9685_OUTPUT_DISABLE_TYPE_LEDN_LOW
@ PCA9685_OUTPUT_DISABLE_TYPE_OUTDRV_1_LEDN_LOW_OUTDRV_0_HIGH_IMPEDANCE
@ PCA9685_OUTPUT_DISABLE_TYPE_HIGH_IMPEDANCE
@ PCA9685_CHANNEL_9
@ PCA9685_CHANNEL_2
@ PCA9685_CHANNEL_15
@ PCA9685_CHANNEL_14
@ PCA9685_CHANNEL_11
@ PCA9685_CHANNEL_8
@ PCA9685_CHANNEL_1
@ PCA9685_CHANNEL_3
@ PCA9685_CHANNEL_13
@ PCA9685_CHANNEL_4
@ PCA9685_CHANNEL_12
@ PCA9685_CHANNEL_0
@ PCA9685_CHANNEL_7
@ PCA9685_CHANNEL_6
@ PCA9685_CHANNEL_10
@ PCA9685_CHANNEL_5
@ PCA9685_OUTPUT_DRIVER_TOTEM_POLE
@ PCA9685_OUTPUT_DRIVER_OPEN_DRAIN
@ PCA9685_OUTPUT_CHANGE_STOP
@ PCA9685_OUTPUT_CHANGE_ACK
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
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]