|
Chrispy
High-performance multichannel ADC sampling and audio recording.
|
Data Structures | |
| struct | Adc |
| Singleton instance of the ADC. | |
| struct | AdcFrame |
| Private/static data member for use by the ISR. | |
| struct | Channel |
| Single ADC channel (pin + metadata). More... | |
| struct | State |
Enumerations | |
| enum struct | BitResolution : uint8_t { Eight = 8 , Ten = 10 } |
| Supported bit resolutions for ADC sampling. More... | |
| enum struct | AutotriggerSource : uint8_t { FreeRunning = 0b000 , AnalogComparator = 0b001 , ExternalIrq0 = 0b010 , TimCnt0CmpA = 0b011 , TimCnt0Ovf = 0b100 , TimCnt1CmpB = 0b101 , TimCnt1Ovf = 0b110 , TimCnt1Cap = 0b111 } |
| Potential sources for ADC interrupts to be triggered by. More... | |
Functions | |
| ISR (ADC_vect) | |
| Interrupt service routine responsible for reading samples from the ADC. | |
| int8_t | drain_buffer (uint8_t **buf, size_t &sz, size_t &ch_index) |
| NOT SAFE TO USE WHEN THE ADC IS ENABLED! | |
| int8_t | swap_buffer (uint8_t **buf, size_t &sz, size_t &ch_index) |
| Retrieve a buffer from the module belonging to a specific channel, writing the size and channel index to the reference arguments. | |
| bool | init (uint8_t _nchannels, Channel *_channels, uint8_t *_buf, size_t _sz) |
| Initialize ADC module with these parameters for sampling. | |
| void | on () |
| Activate internal board's ADC. | |
| void | off () |
| Turn off ADC. | |
| void | sleep () |
| Turn off ADC and enter sleep mode. | |
| int8_t | start (BitResolution res, uint32_t sample_rate, size_t ch_window_sz=1, uint32_t warmup_ms=100) |
| Start ADC sampling at a certain rate with a given bit resolution. | |
| uint32_t | collected () |
| uint32_t | stop () |
| Stops ADC sampling and performs cleanup on registers. | |
| size_t | bytes_per_sample (BitResolution res) |
Variables | |
| const size_t | MAX_CHANNEL_COUNT = 16 |
| Number of channels supported by the ADC (0 - 15). | |
|
strong |
|
strong |
| size_t adc::bytes_per_sample | ( | BitResolution | res | ) |
| uint32_t adc::collected | ( | ) |
| int8_t adc::drain_buffer | ( | uint8_t ** | buf, |
| size_t & | sz, | ||
| size_t & | ch_index | ||
| ) |
NOT SAFE TO USE WHEN THE ADC IS ENABLED!
Identical API as swap_buffer but this will also give the active buffer. Used to drain any remaining samples from the buffer.
| bool adc::init | ( | uint8_t | nchannels, |
| Channel * | channels, | ||
| uint8_t * | buf, | ||
| size_t | sz | ||
| ) |
Initialize ADC module with these parameters for sampling.
| adc::ISR | ( | ADC_vect | ) |
Interrupt service routine responsible for reading samples from the ADC.
| void adc::off | ( | ) |
Turn off ADC.
| void adc::on | ( | ) |
Activate internal board's ADC.
Wake up from sleep mode.
| void adc::sleep | ( | ) |
Turn off ADC and enter sleep mode.
| int8_t adc::start | ( | BitResolution | res, |
| uint32_t | sample_rate, | ||
| size_t | ch_window_sz = 1, |
||
| uint32_t | warmup_ms = 100 |
||
| ) |
Start ADC sampling at a certain rate with a given bit resolution.
| res | Bit resolution to use. |
| sample_rate | Sample rate in Hz to try and record at, |
| ch_window_sz | Size of each channel's window. Only checked when there are multiple channels being recorded from. Defaults to 8. |
| warmup_ms | Milliseconds to delay after starting ADC before ingesting samples. A small warmup helps prevent poor signal from channel switching noise. |
| uint32_t adc::stop | ( | ) |
Stops ADC sampling and performs cleanup on registers.
| int8_t adc::swap_buffer | ( | uint8_t ** | buf, |
| size_t & | sz, | ||
| size_t & | ch_index | ||
| ) |
Retrieve a buffer from the module belonging to a specific channel, writing the size and channel index to the reference arguments.
Intent: Call this in a busy loop starting with a nullptr and write data out to the appropriate channel as it comes in.
| buf | Pointer to buffer being swapped. If it is a null-pointer, will try to swap it with a currently full buffer without marking it as usable by the ISR. If it is one of the double buffers, will free the buffer for use again and try to exchange it for the other buffer if possible. |
| sz | Out-parameter for the number of bytes in the buffer. |
| ch_index | Out-paramter for the channel index this data is from. |
| const size_t adc::MAX_CHANNEL_COUNT = 16 |
Number of channels supported by the ADC (0 - 15).