LibDriver ADS1118
Loading...
Searching...
No Matches
driver_ads1118_shot.c
Go to the documentation of this file.
1
36
37#include "driver_ads1118_shot.h"
38
39static ads1118_handle_t gs_handle;
40
51{
52 uint8_t res;
53
54 /* link interface function */
61
62 /* ads1118 init */
63 res = ads1118_init(&gs_handle);
64 if (res != 0)
65 {
66 ads1118_interface_debug_print("ads1118: init failed.\n");
67
68 return 1;
69 }
70
71 /* set channel */
72 res = ads1118_set_channel(&gs_handle, channel);
73 if (res != 0)
74 {
75 ads1118_interface_debug_print("ads1118: set channel failed.\n");
76 (void)ads1118_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set default range */
83 if (res != 0)
84 {
85 ads1118_interface_debug_print("ads1118: set range failed.\n");
86 (void)ads1118_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set default rate */
93 if (res != 0)
94 {
95 ads1118_interface_debug_print("ads1118: set rate failed.\n");
96 (void)ads1118_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set adc mode */
102 res = ads1118_set_mode(&gs_handle, mode);
103 if (res != 0)
104 {
105 ads1118_interface_debug_print("ads1118: set mode failed.\n");
106 (void)ads1118_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set default dout pull up */
113 if (res != 0)
114 {
115 ads1118_interface_debug_print("ads1118: set dout pull up failed.\n");
116 (void)ads1118_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 return 0;
122}
123
132uint8_t ads1118_shot_read(float *s)
133{
134 int16_t raw;
135
136 /* read data */
137 if (ads1118_single_read(&gs_handle, (int16_t *)&raw, s) != 0)
138 {
139 return 1;
140 }
141
142 return 0;
143}
144
154{
155 int16_t raw;
156
157 /* read data */
158 if (ads1118_single_read(&gs_handle, (int16_t *)&raw, deg) != 0)
159 {
160 return 1;
161 }
162
163 /* temperature convert */
164 if (ads1118_temperature_convert(&gs_handle, raw, deg) != 0)
165 {
166 return 1;
167 }
168
169 return 0;
170}
171
180{
181 uint8_t res;
182
183 /* deinit ads1118 */
184 res = ads1118_deinit(&gs_handle);
185 if (res != 0)
186 {
187 return 1;
188 }
189
190 return 0;
191}
driver ads1118 shot header file
uint8_t ads1118_single_read(ads1118_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
uint8_t ads1118_set_channel(ads1118_handle_t *handle, ads1118_channel_t channel)
set the adc channel
uint8_t ads1118_set_range(ads1118_handle_t *handle, ads1118_range_t range)
set the adc range
ads1118_mode_t
ads1118 mode enumeration definition
uint8_t ads1118_init(ads1118_handle_t *handle)
initialize the chip
uint8_t ads1118_set_dout_pull_up(ads1118_handle_t *handle, ads1118_bool_t enable)
enable or disable dout pull up
uint8_t ads1118_deinit(ads1118_handle_t *handle)
close the chip
struct ads1118_handle_s ads1118_handle_t
ads1118 handle structure definition
uint8_t ads1118_set_rate(ads1118_handle_t *handle, ads1118_rate_t rate)
set the sample rate
ads1118_channel_t
ads1118 channel enumeration definition
uint8_t ads1118_temperature_convert(ads1118_handle_t *handle, int16_t raw, float *deg)
temperature convert
uint8_t ads1118_set_mode(ads1118_handle_t *handle, ads1118_mode_t mode)
set the chip mode
#define ADS1118_SHOT_DEFAULT_DOUT_PULL_UP
uint8_t ads1118_shot_deinit(void)
shot example deinit
uint8_t ads1118_shot_read_temperature(float *deg)
shot example read
uint8_t ads1118_shot_init(ads1118_mode_t mode, ads1118_channel_t channel)
shot example init
#define ADS1118_SHOT_DEFAULT_RATE
uint8_t ads1118_shot_read(float *s)
shot example read
#define ADS1118_SHOT_DEFAULT_RANGE
ads1118 shot example default definition
void ads1118_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ads1118_interface_spi_transmit(uint8_t *tx, uint8_t *rx, uint16_t len)
interface spi bus transmit
uint8_t ads1118_interface_spi_deinit(void)
interface spi bus deinit
uint8_t ads1118_interface_spi_init(void)
interface spi bus init
void ads1118_interface_debug_print(const char *const fmt,...)
interface print format data