LibDriver ADS1115
Loading...
Searching...
No Matches
driver_ads1115.h
Go to the documentation of this file.
1
37
38#ifndef DRIVER_ADS1115_H
39#define DRIVER_ADS1115_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
70
74typedef enum
75{
79
92
107
122
126
131
135typedef enum
136{
140
149
160
164
169
173typedef struct ads1115_handle_s
174{
175 uint8_t iic_addr;
176 uint8_t (*iic_init)(void);
177 uint8_t (*iic_deinit)(void);
178 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
179 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
180 void (*delay_ms)(uint32_t ms);
181 void (*debug_print)(const char *const fmt, ...);
182 uint8_t inited;
184
200
204
211
218#define DRIVER_ADS1115_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
219
226#define DRIVER_ADS1115_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
227
234#define DRIVER_ADS1115_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
235
242#define DRIVER_ADS1115_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
243
250#define DRIVER_ADS1115_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
251
258#define DRIVER_ADS1115_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
259
266#define DRIVER_ADS1115_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
267
271
278
287uint8_t ads1115_info(ads1115_info_t *info);
288
300
312
323uint8_t ads1115_init(ads1115_handle_t *handle);
324
336uint8_t ads1115_deinit(ads1115_handle_t *handle);
337
350uint8_t ads1115_single_read(ads1115_handle_t *handle, int16_t *raw, float *v);
351
363
375
389uint8_t ads1115_continuous_read(ads1115_handle_t *handle,int16_t *raw, float *v);
390
403
416
429
441uint8_t ads1115_get_range(ads1115_handle_t *handle, ads1115_range_t *range);
442
455
467uint8_t ads1115_get_rate(ads1115_handle_t *handle, ads1115_rate_t *rate);
468
472
479
492
505
518
531
544
557
570
582uint8_t ads1115_get_compare(ads1115_handle_t *handle, ads1115_bool_t *enable);
583
596uint8_t ads1115_set_compare_threshold(ads1115_handle_t *handle, int16_t high_threshold, int16_t low_threshold);
597
610uint8_t ads1115_get_compare_threshold(ads1115_handle_t *handle, int16_t *high_threshold, int16_t *low_threshold);
611
624uint8_t ads1115_convert_to_register(ads1115_handle_t *handle, float s, int16_t *reg);
625
638uint8_t ads1115_convert_to_data(ads1115_handle_t *handle, int16_t reg, float *s);
639
643
650
663uint8_t ads1115_set_reg(ads1115_handle_t *handle, uint8_t reg, int16_t value);
664
677uint8_t ads1115_get_reg(ads1115_handle_t *handle, uint8_t reg, int16_t *value);
678
682
686
687#ifdef __cplusplus
688}
689#endif
690
691#endif
uint8_t ads1115_get_channel(ads1115_handle_t *handle, ads1115_channel_t *channel)
get the adc channel
uint8_t ads1115_set_addr_pin(ads1115_handle_t *handle, ads1115_address_t addr_pin)
set the iic address pin
uint8_t ads1115_get_addr_pin(ads1115_handle_t *handle, ads1115_address_t *addr_pin)
get the iic address pin
uint8_t ads1115_start_continuous_read(ads1115_handle_t *handle)
start the chip reading
ads1115_channel_t
ads1115 channel enumeration definition
uint8_t ads1115_init(ads1115_handle_t *handle)
initialize the chip
uint8_t ads1115_set_rate(ads1115_handle_t *handle, ads1115_rate_t rate)
set the sample rate
ads1115_address_t
ads1115 address enumeration definition
uint8_t ads1115_get_rate(ads1115_handle_t *handle, ads1115_rate_t *rate)
get the sample rate
uint8_t ads1115_deinit(ads1115_handle_t *handle)
close the chip
uint8_t ads1115_set_range(ads1115_handle_t *handle, ads1115_range_t range)
set the adc range
struct ads1115_info_s ads1115_info_t
ads1115 information structure definition
ads1115_rate_t
ads1115 channel rate enumeration definition
uint8_t ads1115_get_range(ads1115_handle_t *handle, ads1115_range_t *range)
get the adc range
uint8_t ads1115_single_read(ads1115_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
ads1115_bool_t
ads1115 bool enumeration definition
struct ads1115_handle_s ads1115_handle_t
ads1115 handle structure definition
uint8_t ads1115_info(ads1115_info_t *info)
get chip's information
uint8_t ads1115_stop_continuous_read(ads1115_handle_t *handle)
stop the chip reading
ads1115_range_t
ads1115 range enumeration definition
uint8_t ads1115_set_channel(ads1115_handle_t *handle, ads1115_channel_t channel)
set the adc channel
uint8_t ads1115_continuous_read(ads1115_handle_t *handle, int16_t *raw, float *v)
read data from the chip continuously
@ ADS1115_CHANNEL_AIN1_GND
@ ADS1115_CHANNEL_AIN1_AIN3
@ ADS1115_CHANNEL_AIN0_AIN1
@ ADS1115_CHANNEL_AIN0_GND
@ ADS1115_CHANNEL_AIN3_GND
@ ADS1115_CHANNEL_AIN2_GND
@ ADS1115_CHANNEL_AIN0_AIN3
@ ADS1115_CHANNEL_AIN2_AIN3
@ ADS1115_ADDR_VCC
@ ADS1115_ADDR_SDA
@ ADS1115_ADDR_SCL
@ ADS1115_ADDR_GND
@ ADS1115_RATE_250SPS
@ ADS1115_RATE_475SPS
@ ADS1115_RATE_860SPS
@ ADS1115_RATE_8SPS
@ ADS1115_RATE_32SPS
@ ADS1115_RATE_128SPS
@ ADS1115_RATE_64SPS
@ ADS1115_RATE_16SPS
@ ADS1115_BOOL_TRUE
@ ADS1115_BOOL_FALSE
@ ADS1115_RANGE_0P256V
@ ADS1115_RANGE_0P512V
@ ADS1115_RANGE_6P144V
@ ADS1115_RANGE_1P024V
@ ADS1115_RANGE_2P048V
@ ADS1115_RANGE_4P096V
uint8_t ads1115_get_reg(ads1115_handle_t *handle, uint8_t reg, int16_t *value)
get the chip register
uint8_t ads1115_set_reg(ads1115_handle_t *handle, uint8_t reg, int16_t value)
set the chip register
uint8_t ads1115_set_alert_pin(ads1115_handle_t *handle, ads1115_pin_t pin)
set the alert pin active status
uint8_t ads1115_get_alert_pin(ads1115_handle_t *handle, ads1115_pin_t *pin)
get the alert pin active status
uint8_t ads1115_set_compare(ads1115_handle_t *handle, ads1115_bool_t enable)
enable or disable the interrupt compare
uint8_t ads1115_get_comparator_queue(ads1115_handle_t *handle, ads1115_comparator_queue_t *comparator_queue)
get the interrupt comparator queue
uint8_t ads1115_convert_to_register(ads1115_handle_t *handle, float s, int16_t *reg)
convert a adc value to a register raw data
uint8_t ads1115_set_compare_threshold(ads1115_handle_t *handle, int16_t high_threshold, int16_t low_threshold)
set the interrupt compare threshold
uint8_t ads1115_set_compare_mode(ads1115_handle_t *handle, ads1115_compare_t compare)
set the interrupt compare mode
ads1115_comparator_queue_t
ads1115 comparator queue enumeration definition
uint8_t ads1115_set_comparator_queue(ads1115_handle_t *handle, ads1115_comparator_queue_t comparator_queue)
set the interrupt comparator queue
ads1115_compare_t
ads1115 compare mode enumeration definition
uint8_t ads1115_get_compare_threshold(ads1115_handle_t *handle, int16_t *high_threshold, int16_t *low_threshold)
get the interrupt compare threshold
uint8_t ads1115_get_compare_mode(ads1115_handle_t *handle, ads1115_compare_t *compare)
get the interrupt compare mode
uint8_t ads1115_get_compare(ads1115_handle_t *handle, ads1115_bool_t *enable)
get the interrupt compare status
uint8_t ads1115_convert_to_data(ads1115_handle_t *handle, int16_t reg, float *s)
convert a register raw data to a converted adc data
ads1115_pin_t
ads1115 pin enumeration definition
@ ADS1115_COMPARATOR_QUEUE_NONE_CONV
@ ADS1115_COMPARATOR_QUEUE_2_CONV
@ ADS1115_COMPARATOR_QUEUE_1_CONV
@ ADS1115_COMPARATOR_QUEUE_4_CONV
@ ADS1115_COMPARE_THRESHOLD
@ ADS1115_COMPARE_WINDOW
@ ADS1115_PIN_HIGH
@ ADS1115_PIN_LOW
ads1115 handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
ads1115 information structure definition
uint32_t driver_version
char manufacturer_name[32]