This post: ADC configuration
highlights a deficiency in the current AnalogIn and AnalogOut APIs in that they do not support hardware-based continuous sampling. This is a very common operation when using an ADC for just about anything beyond battery voltage readings, etc.
The API should be extended to include continuous sampling – it can work in a similar manner as asynchronous transfers do for I2C, SPI, etc.
The ADC or DAC could be double buffered. Provided with a set of buffers initially by the user when starting a continuous conversion stream, the API could call an application callback when one of the buffers is consumed. The application callback can do one of two things:
1.) Fill the buffer with new data
2.) Redirect the pointer to an existing buffer to use (maybe not? Some hardware targets may only support a contiguous buffer in hardware)
At the end, the application callback returns true or false – with true indicating the stream should continue and false indicating the stream should terminate after the last buffer is consumed.
There are a few caveats when implementing for specific targets. One of the largest hurdles will be multiple channels, either continuously interleaved or periodic samples interleaved with a continuous stream.
Some targets have mechanisms to support this kind of behavior while others it will be significantly more difficult. Multiple analog streams on the same peripheral could potentially be disallowed in these cases.