aboutsummaryrefslogtreecommitdiffstats
path: root/src/gadc/gadc_driver.h
blob: 886062c918baaf4681e2827102412d9fe765b4b8 (plain)
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
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.io/license.html
 */

/**
 * @file    src/gadc/gadc_driver.h
 * @brief   GADC - Periodic ADC driver header file.
 *
 * @defgroup GADC_Driver Driver
 * @ingroup GADC
 *
 * @brief Driver interface for the GADC module.
 *
 * @{
 */

#ifndef _GADC_LLD_H
#define _GADC_LLD_H

#include "../../gfx.h"

#if GFX_USE_GADC || defined(__DOXYGEN__)

/*===========================================================================*/
/* Type definitions                                                          */
/*===========================================================================*/

/**
 * @brief				The structure passed to start a timer conversion
 * @{
 */
typedef struct GadcTimerJob_t {
	gU32		physdev;					// @< The physical device/s. The exact meaning of physdev is hardware dependent.
	gU32		frequency;					// @< The frequency to sample
	adcsample_t		*buffer;					// @< Where to put the samples
	gMemSize		todo;						// @< How many conversions to do
	gMemSize		done;						// @< How many conversions have already been done
} GadcTimerJob;
/** @} */

/**
 * @brief				The structure passed to do a single conversion
 * @{
 */
typedef struct GadcNonTimerJob_t {
	gU32				physdev;			// @< The physical device/s. The exact meaning of physdev is hardware dependent.
	adcsample_t				*buffer;			// @< Where to put the samples.
	} GadcNonTimerJob;
/** @} */

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief				These routines are the callbacks that the driver uses.
 * @details				Defined in the high level GADC code.
 *
 * @notapi
 * @{
 */
	/**
	 * @brief	Indicate that some data has been placed into the buffer for the current job
	 *
	 * @param[in] n		The number of samples placed in the buffer
	 *
	 * @note		Calling this with n = 0 causes the current job to be terminated early or aborted.
	 * 				It can be called in this mode on an ADC conversion error. Any job will then be
	 * 				restarted by the high level code as appropriate.
	 */
	void gadcGotDataI(gMemSize n);
/**
 * @}
 */

/**
 * @brief				Initialise the driver
 *
 * @api
 */
void gadc_lld_init(void);

/**
 * @brief				Using the hardware dependant "physdev", return the number of samples for each conversion
 *
 * @param[in] physdev	The hardware dependent physical device descriptor
 *
 * @return				The number of samples per conversion
 *
 * @api
 */
gMemSize gadc_lld_samplesperconversion(gU32 physdev);

/**
 * @brief				Start a periodic timer for high frequency conversions.
 *
 * @param[in] freq		The frequency for the timer
 *
 * @note				This will only be called if the timer is currently stopped.
 *
 * @api
 * @iclass
 */
void gadc_lld_start_timerI(gU32 freq);

/**
 * @brief				Stop the periodic timer for high frequency conversions.
 *
 * @note				This will only be called if the timer is currently running and all timer jobs
 * 						have been completed/aborted.
 *
 * @api
 * @iclass
 */
void gadc_lld_stop_timerI(void);

/**
 * @brief				Start a set of high frequency conversions.
 *
 * @note				This will only be called if the timer is currently running and the ADC should be ready for
 * 						a new job.
 *
 * @param[in] pjob		The job to be started.
 *
 * @api
 * @iclass
 */
void gadc_lld_timerjobI(GadcTimerJob *pjob);

/**
 * @brief				Start a non-timer conversion.
 *
 * @note				This will only be called if the ADC should be ready for a new job.
 *
 * @param[in] pjob		The job to be started
 *
 * @api
 * @iclass
 */
void gadc_lld_nontimerjobI(GadcNonTimerJob *pjob);

#ifdef __cplusplus
}
#endif

#endif /* GFX_USE_GADC */

#endif /* _GADC_LLD_H */
/** @} */