LibDriver MCP3421
Loading...
Searching...
No Matches
driver_mcp3421.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_MCP3421_H
38#define DRIVER_MCP3421_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62typedef enum
63{
69
73typedef enum
74{
80
84typedef struct mcp3421_handle_s
85{
86 uint8_t (*iic_init)(void);
87 uint8_t (*iic_deinit)(void);
88 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
89 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
90 void (*delay_ms)(uint32_t ms);
91 void (*debug_print)(const char *const fmt, ...);
92 uint8_t config;
93 uint8_t inited;
95
111
115
122
129#define DRIVER_MCP3421_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
130
137#define DRIVER_MCP3421_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
138
145#define DRIVER_MCP3421_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
146
153#define DRIVER_MCP3421_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
154
161#define DRIVER_MCP3421_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
162
169#define DRIVER_MCP3421_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
170
177#define DRIVER_MCP3421_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
178
182
189
198uint8_t mcp3421_info(mcp3421_info_t *info);
199
210uint8_t mcp3421_init(mcp3421_handle_t *handle);
211
223uint8_t mcp3421_deinit(mcp3421_handle_t *handle);
224
238uint8_t mcp3421_single_read(mcp3421_handle_t *handle, int32_t *raw, double *v);
239
251
263
277uint8_t mcp3421_continuous_read(mcp3421_handle_t *handle, int32_t *raw, double *v);
278
290uint8_t mcp3421_set_adc_bit(mcp3421_handle_t *handle, mcp3421_bit_t adc_bit);
291
303uint8_t mcp3421_get_adc_bit(mcp3421_handle_t *handle, mcp3421_bit_t *adc_bit);
304
317
329uint8_t mcp3421_get_pga(mcp3421_handle_t *handle, mcp3421_pga_t *pga);
330
334
341
354uint8_t mcp3421_set_reg(mcp3421_handle_t *handle, uint8_t *buf, uint16_t len);
355
368uint8_t mcp3421_get_reg(mcp3421_handle_t *handle, uint8_t *buf, uint16_t len);
369
373
377
378#ifdef __cplusplus
379}
380#endif
381
382#endif
uint8_t mcp3421_get_adc_bit(mcp3421_handle_t *handle, mcp3421_bit_t *adc_bit)
get the adc bit
uint8_t mcp3421_set_pga(mcp3421_handle_t *handle, mcp3421_pga_t pga)
set the adc pga
uint8_t mcp3421_set_adc_bit(mcp3421_handle_t *handle, mcp3421_bit_t adc_bit)
set the adc bit
uint8_t mcp3421_start_continuous_read(mcp3421_handle_t *handle)
start the chip reading
mcp3421_pga_t
mcp3421 pga enumeration definition
uint8_t mcp3421_single_read(mcp3421_handle_t *handle, int32_t *raw, double *v)
read data from the chip once
uint8_t mcp3421_init(mcp3421_handle_t *handle)
initialize the chip
uint8_t mcp3421_deinit(mcp3421_handle_t *handle)
close the chip
uint8_t mcp3421_stop_continuous_read(mcp3421_handle_t *handle)
stop the chip reading
uint8_t mcp3421_continuous_read(mcp3421_handle_t *handle, int32_t *raw, double *v)
read data from the chip continuously
uint8_t mcp3421_get_pga(mcp3421_handle_t *handle, mcp3421_pga_t *pga)
get the adc pga
mcp3421_bit_t
mcp3421 bit enumeration definition
struct mcp3421_handle_s mcp3421_handle_t
mcp3421 handle structure definition
struct mcp3421_info_s mcp3421_info_t
mcp3421 information structure definition
uint8_t mcp3421_info(mcp3421_info_t *info)
get chip's information
@ MCP3421_PGA_2
@ MCP3421_PGA_4
@ MCP3421_PGA_1
@ MCP3421_PGA_8
@ MCP3421_BIT_16
@ MCP3421_BIT_12
@ MCP3421_BIT_18
@ MCP3421_BIT_14
uint8_t mcp3421_set_reg(mcp3421_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
uint8_t mcp3421_get_reg(mcp3421_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
mcp3421 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)
mcp3421 information structure definition
uint32_t driver_version
char manufacturer_name[32]