LibDriver PCF8591
Loading...
Searching...
No Matches
driver_pcf8591.h
Go to the documentation of this file.
1
37
38#ifndef DRIVER_PCF8591_H
39#define DRIVER_PCF8591_H
40
41#include <stdio.h>
42#include <stdint.h>
43#include <string.h>
44
45#ifdef __cplusplus
46extern "C"{
47#endif
48
54
59
74
78typedef enum
79{
83
94
105
109typedef struct pcf8591_handle_s
110{
111 uint8_t iic_addr;
112 uint8_t (*iic_init)(void);
113 uint8_t (*iic_deinit)(void);
114 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
115 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
116 void (*delay_ms)(uint32_t ms);
117 void (*debug_print)(const char *const fmt, ...);
118 uint8_t inited;
119 uint8_t conf;
122
138
142
149
156#define DRIVER_PCF8591_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
157
164#define DRIVER_PCF8591_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
165
172#define DRIVER_PCF8591_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
173
180#define DRIVER_PCF8591_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
181
188#define DRIVER_PCF8591_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
189
196#define DRIVER_PCF8591_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
197
204#define DRIVER_PCF8591_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
205
209
216
225uint8_t pcf8591_info(pcf8591_info_t *info);
226
237
248
259uint8_t pcf8591_init(pcf8591_handle_t *handle);
260
271uint8_t pcf8591_deinit(pcf8591_handle_t *handle);
272
285uint8_t pcf8591_read(pcf8591_handle_t *handle, int16_t *raw, float *adc);
286
300uint8_t pcf8591_multiple_read(pcf8591_handle_t *handle, int16_t *raw, float *adc, uint8_t *len);
301
313uint8_t pcf8591_write(pcf8591_handle_t *handle, uint8_t data);
314
326uint8_t pcf8591_dac_convert_to_register(pcf8591_handle_t *handle, float dac, uint8_t *reg);
327
338uint8_t pcf8591_set_reference_voltage(pcf8591_handle_t *handle, float ref_voltage);
339
350uint8_t pcf8591_get_reference_voltage(pcf8591_handle_t *handle, float *ref_voltage);
351
364
376
389
400uint8_t pcf8591_get_mode(pcf8591_handle_t *handle, pcf8591_mode_t *mode);
401
414
426
430
437
450uint8_t pcf8591_set_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len);
451
464uint8_t pcf8591_get_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len);
465
469
473
474#ifdef __cplusplus
475}
476#endif
477
478#endif
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
struct pcf8591_info_s pcf8591_info_t
pcf8591 information structure definition
uint8_t pcf8591_read(pcf8591_handle_t *handle, int16_t *raw, float *adc)
read data from the chip
uint8_t pcf8591_info(pcf8591_info_t *info)
get chip's information
uint8_t pcf8591_set_addr_pin(pcf8591_handle_t *handle, pcf8591_address_t addr_pin)
set the address pin
uint8_t pcf8591_get_channel(pcf8591_handle_t *handle, pcf8591_channel_t *channel)
get the adc channel
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_get_auto_increment(pcf8591_handle_t *handle, pcf8591_bool_t *enable)
get the adc auto increment read mode
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
pcf8591_bool_t
pcf8591 bool enumeration definition
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
uint8_t pcf8591_set_channel(pcf8591_handle_t *handle, pcf8591_channel_t channel)
set the adc channel
uint8_t pcf8591_get_addr_pin(pcf8591_handle_t *handle, pcf8591_address_t *addr_pin)
get the address pin
pcf8591_address_t
pcf8591 address enumeration definition
uint8_t pcf8591_get_mode(pcf8591_handle_t *handle, pcf8591_mode_t *mode)
get the adc mode
uint8_t pcf8591_get_reference_voltage(pcf8591_handle_t *handle, float *ref_voltage)
get the adc reference voltage
uint8_t pcf8591_deinit(pcf8591_handle_t *handle)
close the chip
struct pcf8591_handle_s pcf8591_handle_t
pcf8591 handle structure definition
pcf8591_channel_t
pcf8591 channel definition
uint8_t pcf8591_set_auto_increment(pcf8591_handle_t *handle, pcf8591_bool_t enable)
set the adc auto increment read mode
@ PCF8591_MODE_AIN0_AIN1_AND_ANI2_AIN3
@ PCF8591_MODE_AIN012_AIN3
@ PCF8591_MODE_AIN0123_GND
@ PCF8591_MODE_AIN0_GND_AND_AIN1_GND_AND_AIN2_AIN3
@ PCF8591_BOOL_FALSE
@ PCF8591_BOOL_TRUE
@ PCF8591_ADDRESS_A110
@ PCF8591_ADDRESS_A101
@ PCF8591_ADDRESS_A100
@ PCF8591_ADDRESS_A010
@ PCF8591_ADDRESS_A111
@ PCF8591_ADDRESS_A000
@ PCF8591_ADDRESS_A011
@ PCF8591_ADDRESS_A001
@ PCF8591_CHANNEL_3
@ PCF8591_CHANNEL_1
@ PCF8591_CHANNEL_0
@ PCF8591_CHANNEL_2
uint8_t pcf8591_get_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
uint8_t pcf8591_set_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
pcf8591 handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
pcf8591 information structure definition
uint32_t driver_version
char manufacturer_name[32]