-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathads.h
180 lines (154 loc) · 5.58 KB
/
ads.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Created by cottley on 4/13/2018.
*
* Upper driver level API
*/
#ifndef ADS_H_
#define ADS_H_
#include <stdint.h>
#include <stdbool.h>
#include "ads_hal.h"
#include "ads_err.h"
#include "ads_util.h"
typedef void (*ads_callback)(float*,uint8_t); // Callback function prototype for interrupt mode
typedef enum {
ADS_CALIBRATE_FIRST = 0, // First calibration point, typically 0 degrees
ADS_CALIBRATE_SECOND, // Second calibration point, 45-255 degrees
ADS_CALIBRATE_CLEAR, // Clears user calibration, restores factory calibration
ADS_CALIBRATE_STRETCH_ZERO, // 0mm strain calibration point
ADS_CALIBRATE_STRETCH_SECOND, // Second calibration point for stretch, typically 30mm
} ADS_CALIBRATION_STEP_T;
/* Formula for converting ticks to samples per second is 16348/SamplesPerSecond = Ticks (nearest integer) */
typedef enum {
ADS_1_HZ = 16384, // 1 sample per second, Interrupt Mode
ADS_10_HZ = 1638, // 10 samples per second, Interrupt Mode
ADS_20_HZ = 819, // 20 samples per second, Interrupt Mode
ADS_50_HZ = 327, // 50 samples per second, Interrupt Mode
ADS_100_HZ = 163, // 100 samples per second, Interrupt Mode
ADS_200_HZ = 81, // 200 samples per second, Interrupt Mode, max rate for bend + stretch
ADS_333_HZ = 49, // 333 samples per second, Interrupt Mode
ADS_500_HZ = 32, // 500 samples per second, Interrupt Mode, max rate
} ADS_SPS_T;
/* Device ids */
typedef enum {
ADS_ONE_AXIS = 1,
ADS_TWO_AXIS = 2
} ADS_DEV_IDS_T;
typedef struct {
ADS_SPS_T sps; // Sample rate for interrupt mode
ads_callback ads_sample_callback; // Pointer to callback function
uint32_t reset_pin; // Pin number connected to ADS reset line
uint32_t datardy_pin; // Pin number connected to ADS interrupt line
uint8_t addr; // I2C 7-bit address of ADS sensor
} ads_init_t;
//######################## Afry code start ######################//
/**
* @brief Initializes the hardware abstraction layer and sample rate of the ADS
*
* @return ADS_OK if successful ADS_ERR if failed
*/
int ads();
/**
* @brief Read the data from the ADS sensor.
*
* @return returns an integer (sensor values in degrees).
*/
int ads_read();
//######################## Afry code End ######################//
/**
* @brief Reads ADS sample data when ADS is in polled mode
*
* @param sample[out] floating point array returns new sample
* @param data_type[out] returns if the data read is bend or stretch data
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_read_polled(float * sample, uint8_t * data_type);
/**
* @brief Places ADS in free run or sleep mode
*
* @param run true if activating ADS, false is putting in suspend mode
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_run(bool run);
/**
* @brief Places ADS in poll mode or sleep. Each time sensor data is read a new sample is taken
*
* @param poll true if activating ADS, false is putting in suspend mode
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_polled(bool poll);
/**
* @brief Enables and Disables the reading of linear displacment data
*
* @param enable true if enabling ADS to read stretch, false is disabling
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_stretch_en(bool enable);
/**
* @brief Sets the sample rate of the ADS in free run mode
*
* @param sps ADS_SPS_T sample rate
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_set_sample_rate(ADS_SPS_T sps);
/**
* @brief Enables the ADS data ready interrupt line
*
* @param run true if activating ADS, false is putting in suspend mode
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_enable_interrupt(bool enable);
/**
* @brief Updates the I2C address of the selected ADS. The default address
* is 0x12. Use this function to program an ADS to allow multiple
* devices on the same I2C bus.
*
* @param address new address of the ADS
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_update_device_address(uint8_t address);
/**
* @brief Initializes the hardware abstraction layer and sample rate of the ADS
*
* @param ads_init_t initialization structure of the ADS
* @return ADS_OK if successful ADS_ERR if failed
*/
int ads_init(ads_init_t * ads_init);
/**
* @brief Calibrates one axis ADS. ADS_CALIBRATE_FIRST should be at 0 degrees on
* ADS_CALIBRATE_SECOND can be at 45 - 255 degrees, recommended 90 degrees.
*
* @param ads_calibration_step ADS_CALIBRATE_STEP_T to perform
* @param degrees uint8_t angle at which sensor is bent when performing
* ADS_CALIBRATE_FIRST, and ADS_CALIBRATE_SECOND
* @return ADS_OK if successful ADS_ERR_IO or ADS_BAD_PARAM if failed
*/
int ads_calibrate(ADS_CALIBRATION_STEP_T ads_calibration_step, uint8_t degrees);
/**
* @brief Shutdown ADS. Requires reset to wake up from Shutdown. ~50nA in shutdwon
*
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_shutdown(void);
/**
* @brief Wakes up ADS from shutdown. Delay is necessary for ADS to reinitialize
*
* @return ADS_OK if successful ADS_ERR_IO if failed
*/
int ads_wake(void);
/**
* @brief Checks that the device id is ADS_ONE_AXIS. ADS should not be in free run
* when this function is called.
*
* @return ADS_OK if dev_id is ADS_ONE_AXIS, ADS_ERR_DEV_ID if not
*/
int ads_get_dev_id(void);
/**
* @brief Returns the device type in ads_dev_type. ADS should not be in free run
* when this function is called.
*
* @param ads_dev_type recipient of the device type
* @return ADS_OK if dev_id is one of ADS_DEV_TYPE_T, ADS_ERR_DEV_ID if not
*/
int ads_get_dev_type(ADS_DEV_TYPE_T * ads_dev_type);
#endif /* ADS_H_ */