LibDriver MCP3421
Loading...
Searching...
No Matches
driver_mcp3421_shot.c
Go to the documentation of this file.
1
36
37#include "driver_mcp3421_shot.h"
38
39static mcp3421_handle_t gs_handle;
40
48uint8_t mcp3421_shot_init(void)
49{
50 uint8_t res;
51
52 /* link interface function */
60
61 /* mcp3421 init */
62 res = mcp3421_init(&gs_handle);
63 if (res != 0)
64 {
65 mcp3421_interface_debug_print("mcp3421: init failed.\n");
66
67 return 1;
68 }
69
70 /* set default pag */
72 if (res != 0)
73 {
74 mcp3421_interface_debug_print("mcp3421: set pga failed.\n");
75 (void)mcp3421_deinit(&gs_handle);
76
77 return 1;
78 }
79
80 /* set default adc bit */
82 if (res != 0)
83 {
84 mcp3421_interface_debug_print("mcp3421: set adc bit failed.\n");
85 (void)mcp3421_deinit(&gs_handle);
86
87 return 1;
88 }
89
90 return 0;
91}
92
101uint8_t mcp3421_shot_read(double *s)
102{
103 int32_t raw;
104
105 /* read data */
106 if (mcp3421_single_read(&gs_handle, (int32_t *)&raw, s) != 0)
107 {
108 return 1;
109 }
110
111 return 0;
112}
113
122{
123 uint8_t res;
124
125 /* deinit mcp3421 */
126 res = mcp3421_deinit(&gs_handle);
127 if (res != 0)
128 {
129 return 1;
130 }
131
132 return 0;
133}
driver mcp3421 shot header file
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_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
struct mcp3421_handle_s mcp3421_handle_t
mcp3421 handle structure definition
uint8_t mcp3421_shot_deinit(void)
shot example deinit
uint8_t mcp3421_shot_read(double *s)
shot example read
#define MCP3421_SHOT_DEFAULT_PGA
#define MCP3421_SHOT_DEFAULT_BIT
mcp3421 shot example default definition
uint8_t mcp3421_shot_init(void)
shot example init
uint8_t mcp3421_interface_iic_deinit(void)
interface iic bus deinit
uint8_t mcp3421_interface_iic_init(void)
interface iic bus init
uint8_t mcp3421_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t mcp3421_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void mcp3421_interface_delay_ms(uint32_t ms)
interface delay ms
void mcp3421_interface_debug_print(const char *const fmt,...)
interface print format data