|
uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
ADC configuration and service functions. More...
#include <stddef.h>#include <avr/interrupt.h>#include <avr/pgmspace.h>#include "adc.h"#include "math.h"#include "midi.h"#include "leds.h"#include "usb.h"
Data Structures | |
| struct | adc_channel_regs |
| ADC channel configuration registers. More... | |
Functions | |
| static uint16_t | compensate_offset (uint16_t sample) |
| static uint16_t | perform_filtered_measurement (enum adc_channel channel) |
| 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_module (const struct adc_config *const config) |
| Initializes and calibrates the ADC. More... | |
| void | init_adc_conversion (const struct adc_conversion_config *const config) |
| Sets up an ADC conversion. 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 new_offset) |
| Sets the ADC offset. More... | |
| void | trigger_adc (enum adc_channel channel) |
| Triggers a conversion for the given channel. More... | |
| ISR (ADCA_CH0_vect) | |
| Interrupt service routine for ADC channel 0. More... | |
| static void | invoke_callbacks (enum adc_channel channel, uint16_t value) |
| Invokes registered callbacks for the given channels. More... | |
| ISR (ADCA_CH1_vect) | |
| Interrupt service routine for ADC channel 1. More... | |
| ISR (ADCA_CH2_vect) | |
| Interrupt service routine for ADC channel 2. More... | |
| ISR (ADCA_CH3_vect) | |
| Interrupt service routine for ADC channel 3. More... | |
Variables | |
| static const struct adc_channel_regs | adc_regs [] |
| Lookup table for ADC channel configuration registers. More... | |
| static uint16_t | offset |
| ADC offset. More... | |
| static uint16_t | sample_buffer [(1<<(8 *sizeof(adc_accumulator) - 12))] |
| Buffer for ADC conversion results of channel 0. More... | |
| static void(* | callbacks_signed [sizeof(adc_regs)/sizeof(struct adc_channel_regs)])(int16_t) |
| Conversion callbacks for signed values. More... | |
| static void(* | callbacks_unsigned [sizeof(adc_regs)/sizeof(struct adc_channel_regs)])(uint16_t) |
| Conversion callbacks for unsigned values. More... | |
| static struct linear_range * | adc_input_range |
| Conversion callbacks for unsigned values. More... | |
ADC configuration and service functions.
| uint16_t calibrate_adc_offset | ( | enum adc_channel | channel | ) |
Calibrates the ADC offset using the given channel.
| channel | the ADC channel |
|
static |
|
inline |
Disables the interrupt for an ADC channel.
| channel | the ADC channel |
|
inline |
Enables the interrupt for an ADC channel.
| channel | the ADC channel |
| 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.
| config | the ADC conversion configuration |
| 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
| config | the shared ADC configuration |
|
static |
Invokes registered callbacks for the given channels.
| channel | the ADC channel whose callbacks should be invoked |
| value | the ADC conversion result |
| ISR | ( | ADCA_CH0_vect | ) |
Interrupt service routine for ADC channel 0.
This routine is different from the others: It computes a mean value of the last ADC_SAMPLE_BUFFER_SIZE samples, converts the result to a valid MIDI value in the range [0, 127] and passes it to the callback for unsigned values. All this happens in an atomic block.
| ISR | ( | ADCA_CH1_vect | ) |
Interrupt service routine for ADC channel 1.
Calls the registered callback(s) for the channel in an atomic block.
| ISR | ( | ADCA_CH2_vect | ) |
Interrupt service routine for ADC channel 2.
Calls the registered callback(s) for the channel in an atomic block.
| ISR | ( | ADCA_CH3_vect | ) |
Interrupt service routine for ADC channel 3.
Calls the registered callback(s) for the channel in an atomic block.
|
static |
| void set_adc_channel0_max_value | ( | void | ) |
Defines the current ADC value as MIDI max value.
| void set_adc_channel0_min_value | ( | void | ) |
Defines the current ADC value as MIDI min value.
| void set_adc_offset | ( | uint16_t | offset | ) |
Sets the ADC offset.
| offset | the offset |
| void trigger_adc | ( | enum adc_channel | channel | ) |
Triggers a conversion for the given channel.
| channel | the ADC channel |
|
static |
Conversion callbacks for unsigned values.
Used in the interrupt service routines
|
static |
Lookup table for ADC channel configuration registers.
|
static |
Conversion callbacks for signed values.
Used in the interrupt service routines
|
static |
Conversion callbacks for unsigned values.
Used in the interrupt service routines
|
static |
ADC offset.
Set during offset calibration
|
static |
Buffer for ADC conversion results of channel 0.
1.8.13