Low-level ADC peripheral driver interface.
More...
Low-level ADC peripheral driver interface.
This is a very simple ADC interface to allow platform independent access to a MCU's ADC unit(s). This interface is intentionally designed as simple as possible, to allow for very easy implementation and maximal portability.
As of now, the interface does not allow for any advanced ADC concepts (e.g. continuous mode, scan sequences, injections). It is to be determined, if these features will ever be integrated in this interface, or if it does make more sense to create a second, advanced ADC interface for this.
The ADC driver interface is built around the concept of ADC lines. An ADC line in this context is a tuple consisting out of a hardware ADC device (an ADC functional unit on the MCU) and an ADC channel connected to pin.
If a MCU has more than one hardware ADC unit, the ADC lines can be mapped in a way, that it is possible to sample multiple lines in parallel, given that the ADC implementation allows for interruption of the program flow while waiting for the result of a conversion (e.g. through putting the calling thread to sleep while waiting for the conversion results).
- Todo:
- Extend interface for continuous mode?
|
file | adc.h |
| Low-level ADC peripheral driver interface definitions.
|
|
|
#define | ADC_UNDEF (UINT_MAX) |
| Default ADC undefined value.
|
|
#define | ADC_LINE(x) (x) |
| Default ADC line access macro.
|
|
|
typedef unsigned int | adc_t |
| Define default ADC type identifier.
|
|
|
enum | adc_res_t {
ADC_RES_6BIT = (0xa00),
ADC_RES_7BIT = (0 << 4),
ADC_RES_8BIT = (0xb00),
ADC_RES_9BIT = (1 << 4),
ADC_RES_10BIT = (2 << 4),
ADC_RES_12BIT = (3 << 4),
ADC_RES_14BIT = (0xc00),
ADC_RES_16BIT = (0xd00),
ADC_RES_6BIT = 0xf0,
ADC_RES_8BIT = 0xf1,
ADC_RES_9BIT = 0,
ADC_RES_10BIT = 1,
ADC_RES_11BIT = 2,
ADC_RES_12BIT = 3,
ADC_RES_14BIT = 0xf2,
ADC_RES_16BIT = 0xf3,
ADC_RES_6BIT = 0xf0,
ADC_RES_8BIT = 0x00,
ADC_RES_10BIT = 0x02,
ADC_RES_12BIT = 0xf1,
ADC_RES_14BIT = 0xf2,
ADC_RES_16BIT = 0xf3,
ADC_RES_6BIT = 0xf0,
ADC_RES_8BIT = 0x00,
ADC_RES_10BIT = 0x01,
ADC_RES_12BIT = 0x02,
ADC_RES_14BIT = 0xf1,
ADC_RES_16BIT = 0xf2,
ADC_RES_6BIT = 0x1,
ADC_RES_8BIT = 0x2,
ADC_RES_10BIT = ADC_MR_LOWRES_BITS_10,
ADC_RES_12BIT = ADC_MR_LOWRES_BITS_12,
ADC_RES_14BIT = 0x4,
ADC_RES_16BIT = 0x8,
ADC_RES_6BIT = 0xff,
ADC_RES_8BIT = ADC_CTRLB_RESSEL_8BIT,
ADC_RES_10BIT = ADC_CTRLB_RESSEL_10BIT,
ADC_RES_12BIT = ADC_CTRLB_RESSEL_12BIT,
ADC_RES_14BIT = 0xfe,
ADC_RES_16BIT = 0xfd,
ADC_RES_6BIT = 0xff,
ADC_RES_8BIT = ADC_CTRLC_RESSEL_8BIT,
ADC_RES_10BIT = ADC_CTRLC_RESSEL_10BIT,
ADC_RES_12BIT = ADC_CTRLC_RESSEL_12BIT,
ADC_RES_14BIT = 0xfe,
ADC_RES_16BIT = 0xfd,
ADC_RES_6BIT = 0x03000000,
ADC_RES_8BIT = 0x02000000,
ADC_RES_10BIT = 0x01000000,
ADC_RES_12BIT = 0x00000000,
ADC_RES_14BIT = 1,
ADC_RES_16BIT = 2,
ADC_RES_6BIT = (ADC_CR1_RES_0 | ADC_CR1_RES_1),
ADC_RES_8BIT = (ADC_CR1_RES_1),
ADC_RES_10BIT = (ADC_CR1_RES_0),
ADC_RES_12BIT = (0x00),
ADC_RES_14BIT = (0xfe),
ADC_RES_16BIT = (0xff),
ADC_RES_6BIT = 0,
ADC_RES_8BIT,
ADC_RES_10BIT,
ADC_RES_12BIT,
ADC_RES_14BIT,
ADC_RES_16BIT
} |
| Possible ADC resolution settings. More...
|
|
◆ adc_res_t
Possible ADC resolution settings.
Enumerator |
---|
ADC_RES_6BIT | not supported by hardware
|
ADC_RES_7BIT | ADC resolution: 7 bit.
|
ADC_RES_8BIT | not supported by hardware
|
ADC_RES_9BIT | ADC resolution: 9 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | not supported by hardware
|
ADC_RES_16BIT | not supported by hardware
|
ADC_RES_6BIT | ADC resolution: 6 bit is not supported.
|
ADC_RES_8BIT | ADC resolution: 8 bit is not supported.
|
ADC_RES_9BIT | ADC resolution: 9 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_11BIT | ADC resolution: 11 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | ADC resolution: 14 bit is not supported.
|
ADC_RES_16BIT | ADC resolution: 16 bit is not supported.
|
ADC_RES_6BIT | ADC resolution: 6 bit (not supported)
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit (not supported)
|
ADC_RES_14BIT | ADC resolution: 14 bit (not supported)
|
ADC_RES_16BIT | ADC resolution: 16 bit (not supported)
|
ADC_RES_6BIT | not supported by hardware
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | supported with oversampling, not implemented
|
ADC_RES_16BIT | not supported by hardware
|
ADC_RES_6BIT | not applicable
|
ADC_RES_8BIT | not applicable
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | not applicable
|
ADC_RES_16BIT | not applicable
|
ADC_RES_6BIT | not supported
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | not supported
|
ADC_RES_16BIT | not supported
|
ADC_RES_6BIT | not supported
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | not supported
|
ADC_RES_16BIT | not supported
|
ADC_RES_6BIT | ADC resolution: 6 bit.
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | ADC resolution: 14 bit (not supported)
|
ADC_RES_16BIT | ADC resolution: 16 bit (not supported)
|
ADC_RES_6BIT | ADC resolution: 6 bit.
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | not applicable
|
ADC_RES_16BIT | not applicable
|
ADC_RES_6BIT | ADC resolution: 6 bit.
|
ADC_RES_8BIT | ADC resolution: 8 bit.
|
ADC_RES_10BIT | ADC resolution: 10 bit.
|
ADC_RES_12BIT | ADC resolution: 12 bit.
|
ADC_RES_14BIT | ADC resolution: 14 bit.
|
ADC_RES_16BIT | ADC resolution: 16 bit.
|
Definition at line 80 of file adc.h.
◆ adc_init()
int adc_init |
( |
adc_t |
line | ) |
|
Initialize the given ADC line.
The ADC line is initialized in synchronous, blocking mode.
- Parameters
-
[in] | line | line to initialize |
- Returns
- 0 on success
-
-1 on invalid ADC line
◆ adc_sample()
Sample a value from the given ADC line.
This function blocks until the conversion has finished. Please note, that if more than one line share the same ADC device, and if these lines are sampled at the same time (e.g. from different threads), the one called secondly waits for the first to finish before its conversion starts.
- Parameters
-
[in] | line | line to sample |
[in] | res | resolution to use for conversion |
- Returns
- the sampled value on success
-
-1 if resolution is not applicable