uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Data Structures | Macros | Typedefs | Enumerations | Functions
adc.h File Reference

ADC configuration and service functions. More...

#include <stdint.h>
#include <avr/io.h>
#include "math.h"
Include dependency graph for adc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  adc_conversion_config
 ADC conversion configuration. More...
 
struct  adc_config
 ADC configuration common to all conversions. More...
 

Macros

#define ADC_RESOLUTION   12
 ADC resolution in bits. More...
 
#define ADC_SAMPLE_BUFFER_SIZE   (1 << (8*sizeof(adc_accumulator) - ADC_RESOLUTION))
 Size of the sample buffer for mean value computations. More...
 

Typedefs

typedef uint16_t adc_accumulator
 Data type for ADC mean value computations. More...
 

Enumerations

enum  adc_conversion_mode { ADC_MODE_UNSIGNED = 0x0, ADC_MODE_SIGNED = 0x1 }
 ADC conversion mode. More...
 
enum  adc_channel { ADC_CHANNEL_0 = 0, ADC_CHANNEL_1 = 1, ADC_CHANNEL_2 = 2, ADC_CHANNEL_3 = 3 }
 ADC channel. More...
 
enum  adc_input {
  ADC_INPUT_0 = ADC_CH_MUXPOS_PIN0_gc, ADC_INPUT_1 = ADC_CH_MUXPOS_PIN1_gc, ADC_INPUT_2 = ADC_CH_MUXPOS_PIN2_gc, ADC_INPUT_3 = ADC_CH_MUXPOS_PIN3_gc,
  ADC_INPUT_4 = ADC_CH_MUXPOS_PIN4_gc, ADC_INPUT_5 = ADC_CH_MUXPOS_PIN5_gc, ADC_INPUT_6 = ADC_CH_MUXPOS_PIN6_gc, ADC_INPUT_7 = ADC_CH_MUXPOS_PIN7_gc
}
 ADC input pin. More...
 

Functions

uint16_t calibrate_adc_offset (enum adc_channel channel)
 Calibrates the ADC offset using the given channel. More...
 
void disable_adc_interrupt (enum adc_channel channel)
 Disables the interrupt for an ADC channel. More...
 
void enable_adc_interrupt (enum adc_channel channel)
 Enables the interrupt for an ADC channel. More...
 
void init_adc_conversion (const struct adc_conversion_config *config)
 Sets up an ADC conversion. More...
 
void init_adc_module (const struct adc_config *config)
 Initializes and calibrates the ADC. More...
 
void set_adc_channel0_max_value (void)
 Defines the current ADC value as MIDI max value. More...
 
void set_adc_channel0_min_value (void)
 Defines the current ADC value as MIDI min value. More...
 
void set_adc_offset (uint16_t offset)
 Sets the ADC offset. More...
 
void trigger_adc (enum adc_channel channel)
 Triggers a conversion for the given channel. More...
 

Detailed Description

ADC configuration and service functions.

Macro Definition Documentation

◆ ADC_RESOLUTION

#define ADC_RESOLUTION   12

ADC resolution in bits.

◆ ADC_SAMPLE_BUFFER_SIZE

#define ADC_SAMPLE_BUFFER_SIZE   (1 << (8*sizeof(adc_accumulator) - ADC_RESOLUTION))

Size of the sample buffer for mean value computations.

Typedef Documentation

◆ adc_accumulator

typedef uint16_t adc_accumulator

Data type for ADC mean value computations.

Enumeration Type Documentation

◆ adc_channel

ADC channel.

Channel 0 is reserved for MIDI values

See also
ISR(ADCA_CH0_vect)
Enumerator
ADC_CHANNEL_0 

ADC channel 0.

ADC_CHANNEL_1 

ADC channel 1.

ADC_CHANNEL_2 

ADC channel 2.

ADC_CHANNEL_3 

ADC channel 3.

◆ adc_conversion_mode

ADC conversion mode.

Enumerator
ADC_MODE_UNSIGNED 

ADC conversion yields unsigned values.

ADC_MODE_SIGNED 

ADC conversion yields signed values.

◆ adc_input

enum adc_input

ADC input pin.

Enumerator
ADC_INPUT_0 

Use ADC input pin 0.

ADC_INPUT_1 

Use ADC input pin 1.

ADC_INPUT_2 

Use ADC input pin 2.

ADC_INPUT_3 

Use ADC input pin 3.

ADC_INPUT_4 

Use ADC input pin 4.

ADC_INPUT_5 

Use ADC input pin 5.

ADC_INPUT_6 

Use ADC input pin 6.

ADC_INPUT_7 

Use ADC input pin 7.

Function Documentation

◆ calibrate_adc_offset()

uint16_t calibrate_adc_offset ( enum adc_channel  channel)

Calibrates the ADC offset using the given channel.

Parameters
channelthe ADC channel
Returns
the measured offset

◆ disable_adc_interrupt()

void disable_adc_interrupt ( enum adc_channel  channel)
inline

Disables the interrupt for an ADC channel.

Parameters
channelthe ADC channel

◆ enable_adc_interrupt()

void enable_adc_interrupt ( enum adc_channel  channel)
inline

Enables the interrupt for an ADC channel.

Parameters
channelthe ADC channel

◆ init_adc_conversion()

void init_adc_conversion ( const struct adc_conversion_config config)

Sets up an ADC conversion.

Registers the callbacks, configures the input and performs a dummy-conversion. The GPIO pin is not configured here – this must be done through the GPIO module.

Parameters
configthe ADC conversion configuration
See also
init_gpio_module

◆ init_adc_module()

void init_adc_module ( const struct adc_config config)

Initializes and calibrates the ADC.

Selects the voltage reference, sets the clock prescaler and conversion mode and calibrates the ADC

Parameters
configthe shared ADC configuration

◆ set_adc_channel0_max_value()

void set_adc_channel0_max_value ( void  )

Defines the current ADC value as MIDI max value.

◆ set_adc_channel0_min_value()

void set_adc_channel0_min_value ( void  )

Defines the current ADC value as MIDI min value.

◆ set_adc_offset()

void set_adc_offset ( uint16_t  offset)

Sets the ADC offset.

Parameters
offsetthe offset

◆ trigger_adc()

void trigger_adc ( enum adc_channel  channel)

Triggers a conversion for the given channel.

Parameters
channelthe ADC channel