LibDriver MCP4725
Loading...
Searching...
No Matches
driver_mcp4725.h
Go to the documentation of this file.
1
37
38#ifndef DRIVER_MCP4725_H
39#define DRIVER_MCP4725_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
68
72typedef enum
73{
77
88
92typedef struct mcp4725_handle_s
93{
94 uint8_t iic_addr;
95 uint8_t (*iic_init)(void);
96 uint8_t (*iic_deinit)(void);
97 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
98 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
99 void (*delay_ms)(uint32_t ms);
100 void (*debug_print)(const char *const fmt, ...);
101 uint8_t inited;
102 uint8_t mode;
103 uint8_t power_mode;
106
122
126
133
140#define DRIVER_MCP4725_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
141
148#define DRIVER_MCP4725_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
149
156#define DRIVER_MCP4725_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
157
164#define DRIVER_MCP4725_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
165
172#define DRIVER_MCP4725_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
173
180#define DRIVER_MCP4725_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
181
188#define DRIVER_MCP4725_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
189
193
200
209uint8_t mcp4725_info(mcp4725_info_t *info);
210
221
232
243uint8_t mcp4725_init(mcp4725_handle_t *handle);
244
255uint8_t mcp4725_deinit(mcp4725_handle_t *handle);
256
268uint8_t mcp4725_write(mcp4725_handle_t *handle, uint16_t value);
269
281uint8_t mcp4725_read(mcp4725_handle_t *handle, uint16_t *value);
282
295uint8_t mcp4725_convert_to_register(mcp4725_handle_t *handle, float s, uint16_t *reg);
296
309uint8_t mcp4725_convert_to_data(mcp4725_handle_t *handle, uint16_t reg, float *s);
310
322
333uint8_t mcp4725_get_mode(mcp4725_handle_t *handle, mcp4725_mode_t *mode);
334
346
358
369uint8_t mcp4725_set_reference_voltage(mcp4725_handle_t *handle, float ref_voltage);
370
381uint8_t mcp4725_get_reference_voltage(mcp4725_handle_t *handle, float *ref_voltage);
382
386
393
406uint8_t mcp4725_set_reg(mcp4725_handle_t *handle, uint8_t *buf, uint16_t len);
407
420uint8_t mcp4725_get_reg(mcp4725_handle_t *handle, uint8_t *buf, uint16_t len);
421
425
429
430#ifdef __cplusplus
431}
432#endif
433
434#endif
struct mcp4725_handle_s mcp4725_handle_t
mcp4725 handle structure definition
uint8_t mcp4725_get_reference_voltage(mcp4725_handle_t *handle, float *ref_voltage)
get the chip reference voltage
mcp4725_power_down_mode_t
mcp4725 power down enumeration definition
uint8_t mcp4725_convert_to_data(mcp4725_handle_t *handle, uint16_t reg, float *s)
convert the register data to the dac value
uint8_t mcp4725_deinit(mcp4725_handle_t *handle)
close the chip
uint8_t mcp4725_info(mcp4725_info_t *info)
get chip's information
uint8_t mcp4725_read(mcp4725_handle_t *handle, uint16_t *value)
read the dac value
uint8_t mcp4725_set_power_mode(mcp4725_handle_t *handle, mcp4725_power_down_mode_t mode)
set the chip power mode
uint8_t mcp4725_get_power_mode(mcp4725_handle_t *handle, mcp4725_power_down_mode_t *mode)
get the chip power mode
mcp4725_address_t
mcp4725 address enumeration definition
struct mcp4725_info_s mcp4725_info_t
mcp4725 information structure definition
uint8_t mcp4725_write(mcp4725_handle_t *handle, uint16_t value)
write the dac value
uint8_t mcp4725_convert_to_register(mcp4725_handle_t *handle, float s, uint16_t *reg)
convert the dac value to the register data
uint8_t mcp4725_get_addr_pin(mcp4725_handle_t *handle, mcp4725_address_t *addr_pin)
get the chip address pin
uint8_t mcp4725_init(mcp4725_handle_t *handle)
initialize the chip
uint8_t mcp4725_set_reference_voltage(mcp4725_handle_t *handle, float ref_voltage)
set the chip reference voltage
uint8_t mcp4725_set_mode(mcp4725_handle_t *handle, mcp4725_mode_t mode)
set the chip mode
mcp4725_mode_t
mcp4725 mode enumeration definition
uint8_t mcp4725_get_mode(mcp4725_handle_t *handle, mcp4725_mode_t *mode)
get the chip mode
uint8_t mcp4725_set_addr_pin(mcp4725_handle_t *handle, mcp4725_address_t addr_pin)
set the chip address pin
@ MCP4725_POWER_DOWN_MODE_NORMAL
@ MCP4725_POWER_DOWN_MODE_500K_GND
@ MCP4725_POWER_DOWN_MODE_1K_GND
@ MCP4725_POWER_DOWN_MODE_100K_GND
@ MCP4725_ADDR_A0_GND
@ MCP4725_ADDR_A0_VCC
@ MCP4725_MODE_DAC
@ MCP4725_MODE_EEPROM
uint8_t mcp4725_set_reg(mcp4725_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
uint8_t mcp4725_get_reg(mcp4725_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
mcp4725 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)
mcp4725 information structure definition
uint32_t driver_version
char manufacturer_name[32]