1 /**
2  * \file
3  *
4  * \brief ADC functionality declaration.
5  *
6  * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Subject to your compliance with these terms, you may use Microchip
13  * software and any derivatives exclusively with Microchip products.
14  * It is your responsibility to comply with third party license terms applicable
15  * to your use of third party software (including open source software) that
16  * may accompany Microchip software.
17  *
18  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19  * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20  * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22  * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23  * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24  * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25  * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
26  * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27  * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29  *
30  * \asf_license_stop
31  *
32  */
33 
34 #ifndef _HAL_ADC_SYNC_H_INCLUDED
35 #define _HAL_ADC_SYNC_H_INCLUDED
36 
37 #include <hpl_adc_sync.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * \addtogroup doc_driver_hal_adc_sync
45  *
46  * @{
47  */
48 
49 /**
50  * \brief ADC descriptor
51  *
52  * The ADC descriptor forward declaration.
53  */
54 struct adc_sync_descriptor;
55 
56 /**
57  * \brief ADC descriptor
58  */
59 struct adc_sync_descriptor {
60 	/** ADC device */
61 	struct _adc_sync_device device;
62 };
63 
64 /**
65  * \brief Initialize ADC
66  *
67  * This function initializes the given ADC descriptor.
68  * It checks if the given hardware is not initialized and if the given hardware
69  * is permitted to be initialized.
70  *
71  * \param[out] descr An ADC descriptor to initialize
72  * \param[in] hw     The pointer to hardware instance
73  * \param[in] func   The pointer to a set of functions pointers
74  *
75  * \return Initialization status.
76  */
77 int32_t adc_sync_init(struct adc_sync_descriptor *const descr, void *const hw, void *const func);
78 
79 /**
80  * \brief Deinitialize ADC
81  *
82  * This function deinitializes the given ADC descriptor.
83  * It checks if the given hardware is initialized and if the given hardware is
84  * permitted to be deinitialized.
85  *
86  * \param[in] descr An ADC descriptor to deinitialize
87  *
88  * \return De-initialization status.
89  */
90 int32_t adc_sync_deinit(struct adc_sync_descriptor *const descr);
91 
92 /**
93  * \brief Enable ADC
94  *
95  * Use this function to set the ADC peripheral to enabled state.
96  *
97  * \param[in] descr    Pointer to the ADC descriptor
98  * \param[in] channel  Channel number
99  *
100  * \return Operation status
101  *
102  */
103 int32_t adc_sync_enable_channel(struct adc_sync_descriptor *const descr, const uint8_t channel);
104 
105 /**
106  * \brief Disable ADC
107  *
108  * Use this function to set the ADC peripheral to disabled state.
109  *
110  * \param[in] descr   Pointer to the ADC descriptor
111  * \param[in] channel Channel number
112  *
113  * \return Operation status
114  *
115  */
116 int32_t adc_sync_disable_channel(struct adc_sync_descriptor *const descr, const uint8_t channel);
117 
118 /**
119  * \brief Read data from ADC
120  *
121  * \param[in] descr    The pointer to the ADC descriptor
122  * \param[in] channel  Channel number
123  * \param[in] buf      A buffer to read data to
124  * \param[in] length   The size of a buffer
125  *
126  * \return The number of bytes read.
127  */
128 int32_t adc_sync_read_channel(struct adc_sync_descriptor *const descr, const uint8_t channel, uint8_t *const buffer,
129                               const uint16_t length);
130 
131 /**
132  * \brief Set ADC reference source
133  *
134  * This function sets ADC reference source.
135  *
136  * \param[in] descr     The pointer to the ADC descriptor
137  * \param[in] reference A reference source to set
138  *
139  * \return Status of the ADC reference source setting.
140  */
141 int32_t adc_sync_set_reference(struct adc_sync_descriptor *const descr, const adc_reference_t reference);
142 
143 /**
144  * \brief Set ADC resolution
145  *
146  * This function sets ADC resolution.
147  *
148  * \param[in] descr      The pointer to the ADC descriptor
149  * \param[in] resolution A resolution to set
150  *
151  * \return Status of the ADC resolution setting.
152  */
153 int32_t adc_sync_set_resolution(struct adc_sync_descriptor *const descr, const adc_resolution_t resolution);
154 
155 /**
156  * \brief Set ADC input source of a channel
157  *
158  * This function sets ADC positive and negative input sources.
159  *
160  * \param[in] descr     The pointer to the ADC descriptor
161  * \param[in] pos_input A positive input source to set
162  * \param[in] neg_input A negative input source to set
163  * \param[in] channel   Channel number
164  *
165  * \return Status of the ADC channels setting.
166  */
167 int32_t adc_sync_set_inputs(struct adc_sync_descriptor *const descr, const adc_pos_input_t pos_input,
168                             const adc_neg_input_t neg_input, const uint8_t channel);
169 
170 /**
171  * \brief Set ADC conversion mode
172  *
173  * This function sets ADC conversion mode.
174  *
175  * \param[in] descr The pointer to the ADC descriptor
176  * \param[in] mode  A conversion mode to set
177  *
178  * \return Status of the ADC conversion mode setting.
179  */
180 int32_t adc_sync_set_conversion_mode(struct adc_sync_descriptor *const descr, const enum adc_conversion_mode mode);
181 
182 /**
183  * \brief Set ADC differential mode
184  *
185  * This function sets ADC differential mode.
186  *
187  * \param[in] descr   The pointer to the ADC descriptor
188  * \param[in] channel Channel number
189  * \param[in] mode    A differential mode to set
190  *
191  * \return Status of the ADC differential mode setting.
192  */
193 int32_t adc_sync_set_channel_differential_mode(struct adc_sync_descriptor *const descr, const uint8_t channel,
194                                                const enum adc_differential_mode mode);
195 
196 /**
197  * \brief Set ADC channel gain
198  *
199  * This function sets ADC channel gain.
200  *
201  * \param[in] descr   The pointer to the ADC descriptor
202  * \param[in] channel Channel number
203  * \param[in] gain    A gain to set
204  *
205  * \return Status of the ADC gain setting.
206  */
207 int32_t adc_sync_set_channel_gain(struct adc_sync_descriptor *const descr, const uint8_t channel,
208                                   const adc_gain_t gain);
209 
210 /**
211  * \brief Set ADC window mode
212  *
213  * This function sets ADC window mode.
214  *
215  * \param[in] descr The pointer to the ADC descriptor
216  * \param[in] mode  A window mode to set
217  *
218  * \return Status of the ADC window mode setting.
219  */
220 int32_t adc_sync_set_window_mode(struct adc_sync_descriptor *const descr, const adc_window_mode_t mode);
221 
222 /**
223  * \brief Set ADC thresholds
224  *
225  * This function sets ADC positive and negative thresholds.
226  *
227  * \param[in] descr         The pointer to the ADC descriptor
228  * \param[in] low_threshold A lower thresholds to set
229  * \param[in] up_threshold  An upper thresholds to set
230  *
231  * \return Status of the ADC thresholds setting.
232  */
233 int32_t adc_sync_set_thresholds(struct adc_sync_descriptor *const descr, const adc_threshold_t low_threshold,
234                                 const adc_threshold_t up_threshold);
235 
236 /**
237  * \brief Retrieve threshold state
238  *
239  * This function retrieves ADC threshold state.
240  *
241  * \param[in] descr  The pointer to the ADC descriptor
242  * \param[out] state The threshold state
243  *
244  * \return The state of ADC thresholds state retrieving.
245  */
246 int32_t adc_sync_get_threshold_state(const struct adc_sync_descriptor *const descr,
247                                      adc_threshold_status_t *const           state);
248 
249 /**
250  * \brief Check if conversion is complete
251  *
252  * This function checks if the ADC has finished the conversion.
253  *
254  * \param[in] descr   The pointer to the ADC descriptor
255  * \param[in] channel Channel number
256  *
257  * \return The status of ADC conversion completion checking.
258  * \retval 1 The conversion is complete
259  * \retval 0 The conversion is not complete
260  */
261 int32_t adc_sync_is_channel_conversion_complete(const struct adc_sync_descriptor *const descr, const uint8_t channel);
262 
263 /**
264  * \brief Retrieve the current driver version
265  *
266  * \return Current driver version.
267  */
268 uint32_t adc_sync_get_version(void);
269 /**@}*/
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #include <hpl_missing_features.h>
276 
277 #endif /* _HAL_ADC_SYNC_H_INCLUDED */
278