-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathADS1115_proc.h
125 lines (104 loc) · 4.45 KB
/
ADS1115_proc.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
/*!\file ADS1115_proc.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief ADS1115 Driver procedures
** \details ADS1115: Ultra-Small, Low-Power, 16-Bit Analog-to-Digital Converter with Internal Reference
** \note Compatibility with:
** - ADS1113 (restrictions given in datasheet)
** - ADS1114 (restrictions given in datasheet)
** - ADS1115
** \note Compatibility should be assured with:
** - ADS1x1x (check datasheets for compatibility informations)
**/
/****************************************************************/
#ifndef __ADS1115_PROC_H__
#define __ADS1115_PROC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#include "ADS1115.h"
#if defined(HAL_I2C_MODULE_ENABLED)
/****************************************************************/
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\enum ADS1115_func
** \brief Function enum for ADS1115
**/
typedef enum ADS1115_func {
ADS1115__FUNC_SINGLE_DIFF = 0, //!< Continuous conversion mode
ADS1115__FUNC_MULTIPLE_DIFF, //!< Power-down single-shot mode
ADS1115__FUNC_SINGLE_ENDED, //!< Power-down single-shot mode
} ADS1115_func;
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\struct ADS1115_t
** \brief ADS1115 user interface struct
**/
typedef struct ADS1115_t {
int16_t AIN[4]; //!< Conversion results
uint8_t AIN_idx; //!< Current AIN index
struct {
I2C_slave_t * slave_inst; //!< Slave structure
PeripheralGPIO_t RDY_GPIO; //!< Ready GPIO struct
ADS1115_func function; //!< Functional mode
ADS1115_mode mode; //!< Mode (single shot / Continuous conversion)
uint8_t nb; //!< Number of channels (irrelevant for ADS1115__FUNC_SINGLE_DIFF func)
uADS1115_REG__CFG Config; //!< Config register
int16_t Lo_Thresh; //!< Lo-thresh register
int16_t Hi_Thresh; //!< Hi-thresh register
} cfg;
} ADS1115_t;
extern ADS1115_t ADS1115[I2C_ADS1115_NB]; //!< ADS1115 User structure
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/******************/
/*** Procedures ***/
/******************/
/*!\brief Initialization Sequence for ADS1115 peripheral
** \weak ADS1115 Init sequence may be user implemented if custom initialization sequence needed
** \param[in] pCpnt - Pointer to ADS1115 component
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Init_Sequence(ADS1115_t * const pCpnt);
/*!\brief Handler for ADS1115 peripheral
** \weak ADS1115 handler may be user implemented to suit custom needs
** \note May be called periodically to handle ADS1115 tasks
** \note Alternately may be called when event occurs on ADS1115 pin (or by calling \ref ADS1115_handler_it instead)
** \param[in] pCpnt - Pointer to ADS1115 component
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_handler(ADS1115_t * const pCpnt);
/*!\brief Handler for ADS1115 peripheral GPIO interrupt
** \note \ref ADS1115_RDY_GPIO_Init has to be called at init before using interrupt handler function
** \weak ADS1115 GPIO interrupt handler may be user implemented to suit custom needs
** \note May be called periodically to handle ADS1115 tasks through interrupts
** \param[in] pCpnt - Pointer to ADS1115 component
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_handler_it(ADS1115_t * const pCpnt);
/*!\brief Handler for all ADS1115 peripherals
** \note May be called periodically to handle all ADS1115 tasks
**/
__INLINE void INLINE__ ADS1115_handler_all(void) {
for (ADS1115_t * pCpnt = ADS1115 ; pCpnt < &ADS1115[I2C_ADS1115_NB] ; pCpnt++) {
ADS1115_handler(pCpnt); }
}
/*!\brief Handler for all ADS1115 peripherals GPIO interrupt
** \note \ref ADS1115_RDY_GPIO_Init has to be called at init before using interrupt handler function
** \note May be called periodically to handle all ADS1115 tasks
**/
__INLINE void INLINE__ ADS1115_handler_it_all(void) {
for (ADS1115_t * pCpnt = ADS1115 ; pCpnt < &ADS1115[I2C_ADS1115_NB] ; pCpnt++) {
ADS1115_handler_it(pCpnt); }
}
/****************************************************************/
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ADS1115_PROC_H__ */
/****************************************************************/