LibDriver PCF8591
Loading...
Searching...
No Matches
driver_pcf8591_increment.c
Go to the documentation of this file.
1
37
39
40static pcf8591_handle_t gs_handle;
41
52{
53 uint8_t res;
54
55 /* link functions */
63
64 /* set addr pin */
65 res = pcf8591_set_addr_pin(&gs_handle, addr);
66 if (res != 0)
67 {
68 pcf8591_interface_debug_print("pcf8591: set addr pin failed.\n");
69
70 return 1;
71 }
72
73 /* pcf8591 init */
74 res = pcf8591_init(&gs_handle);
75 if (res != 0)
76 {
77 pcf8591_interface_debug_print("pcf8591: init failed.\n");
78
79 return 1;
80 }
81
82 /* set mode */
83 res = pcf8591_set_mode(&gs_handle, mode);
84 if (res != 0)
85 {
86 pcf8591_interface_debug_print("pcf8591: set mode failed.\n");
87 (void)pcf8591_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* enable auto increment */
94 if (res != 0)
95 {
96 pcf8591_interface_debug_print("pcf8591: set auto increment failed.\n");
97 (void)pcf8591_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* set default reference voltage */
104 if (res != 0)
105 {
106 pcf8591_interface_debug_print("pcf8591: set reference voltage failed.\n");
107 (void)pcf8591_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 return 0;
113}
114
123{
124 /* close pcf8591 */
125 if (pcf8591_deinit(&gs_handle) != 0)
126 {
127 return 1;
128 }
129 else
130 {
131 return 0;
132 }
133}
134
145uint8_t pcf8591_increment_read(int16_t *raw, float *adc, uint8_t *len)
146{
147 if (pcf8591_multiple_read(&gs_handle, raw, adc, len) != 0)
148 {
149 return 1;
150 }
151 else
152 {
153 return 0;
154 }
155}
156
165uint8_t pcf8591_increment_write(float dac)
166{
167 uint8_t res;
168 uint8_t data;
169
170 /* convert to register data */
171 res = pcf8591_dac_convert_to_register(&gs_handle, dac, (uint8_t *)&data);
172 if (res != 0)
173 {
174 return 1;
175 }
176
177 /* write dac */
178 if (pcf8591_write(&gs_handle, data) != 0)
179 {
180 return 1;
181 }
182 else
183 {
184 return 0;
185 }
186}
driver pcf8591 increment header file
uint8_t pcf8591_dac_convert_to_register(pcf8591_handle_t *handle, float dac, uint8_t *reg)
convert a dac value to a register raw data
uint8_t pcf8591_set_addr_pin(pcf8591_handle_t *handle, pcf8591_address_t addr_pin)
set the address pin
uint8_t pcf8591_write(pcf8591_handle_t *handle, uint8_t data)
write to the dac
uint8_t pcf8591_init(pcf8591_handle_t *handle)
initialize the chip
pcf8591_mode_t
pcf8591 mode definition
uint8_t pcf8591_multiple_read(pcf8591_handle_t *handle, int16_t *raw, float *adc, uint8_t *len)
read the multiple channel data from the chip
uint8_t pcf8591_set_mode(pcf8591_handle_t *handle, pcf8591_mode_t mode)
set the adc mode
uint8_t pcf8591_set_reference_voltage(pcf8591_handle_t *handle, float ref_voltage)
set the adc reference voltage
pcf8591_address_t
pcf8591 address enumeration definition
uint8_t pcf8591_deinit(pcf8591_handle_t *handle)
close the chip
struct pcf8591_handle_s pcf8591_handle_t
pcf8591 handle structure definition
uint8_t pcf8591_set_auto_increment(pcf8591_handle_t *handle, pcf8591_bool_t enable)
set the adc auto increment read mode
@ PCF8591_BOOL_TRUE
uint8_t pcf8591_increment_init(pcf8591_address_t addr, pcf8591_mode_t mode)
increment example init
uint8_t pcf8591_increment_read(int16_t *raw, float *adc, uint8_t *len)
increment example read the adc
uint8_t pcf8591_increment_write(float dac)
increment example write the dac
#define PCF8591_INCREMENT_DEFAULT_REFERENCE_VOLTAGE
pcf8591 increment example default definition
uint8_t pcf8591_increment_deinit(void)
increment example deinit
uint8_t pcf8591_interface_iic_init(void)
interface iic bus init
void pcf8591_interface_delay_ms(uint32_t ms)
interface delay ms
void pcf8591_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t pcf8591_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t pcf8591_interface_iic_deinit(void)
interface iic bus deinit
uint8_t pcf8591_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command