AOUT module driver
The application interface (API) has been tailored around AOUT modules, which are part of the MIDIbox Hardware Platform (MBHP), and MIOS based applications like MIDIbox CV (CV control via MIDI), MIDIbox SEQ (CV control from a sequencer) and MIDIbox SID/FM (CV control from a synthesizer)
The two "internal DAC" channels of the STM32F103RE are supported as well (AOUT_IF_INTDAC)
Up to 32 analog outputs are supported (*) An interface to control digital pins is available as well (**)
Output voltages are managed in 16bit resolution. Although none of the current modules support the full resolution, from programming and performance perspective it makes sense to organize CV values this way.
If 7bit values should be output, the caller has to left-align the value, e.g.
AOUT_PinSet(0, value_7bit << 9); // left-align MSB to 16bit
Before voltage changes are transfered to the external hardware, the AOUT_PinSet function compares the new value with the current one. If equal, the register transfer will be omitted, otherwise it will be requested and performed once AOUT_Update() is called.
This method has two advantages:
(*) currently only limited by the aout_update_req variable. This could be enhanced in future if really required, but this would cost performance!
(**) currently only supported for MBHP_AOUT, since MAX525 provides such a digital output pin
Supported interface types:
Example for a complete module configuration:
// initialize AOUT module AOUT_Init(0); // configure interface // see AOUT module documentation for available interfaces and options aout_config_t config; config = AOUT_ConfigGet(); config.if_type = AOUT_IF_MAX525; config.if_option = 0; config.num_channels = 8; config.chn_inverted = 0; AOUT_ConfigSet(config); AOUT_IF_Init(0);
Hardware configuration (settings are located in aout.h, and can be overloaded in mios32_config.h if required):
For the default setup, the Module is connected to J19 of the MBHP_CORE_STM32 module:
Note that this is *not* an 1:1 pin assignment (an adapter has to be used)!
The voltage configuration jumper of J19 has to be set to 5V, and a 4x1k Pull-Up resistor array should be installed, since the IO pins are configured in open-drain mode for 3.3V->5V level shifting.
An usage example can be found under $MIOS32_PATH/apps/examples/aout
aout_cali_mode_t AOUT_CaliModeGet | ( | void | ) |
This function returns the current calibration mode
s32 AOUT_CaliModeSet | ( | u8 | pin, | |
aout_cali_mode_t | mode | |||
) |
This function enables calibration mode for a given pin
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
[in] | mode | the calibration mode |
const char* AOUT_CaliNameGet | ( | aout_cali_mode_t | mode | ) |
u8 AOUT_CaliPinGet | ( | void | ) |
This function returns the pin which is selected for calibration mode
gives direct access to the chn_hz_v field of the AOUT configuration
gives direct access to the chn_inverted field of the AOUT configuration
aout_config_t AOUT_ConfigGet | ( | void | ) |
Returns current AOUT configuration
s32 AOUT_ConfigSet | ( | aout_config_t | config | ) |
Configures the AOUT driver.
It is recommented to call AOUT_IF_Init() if a different AOUT interface type has been selected (e.g. switch from MBHP_AOUT to MBHP_AOUT_NG)
[in] | config | a structure with following members:
|
This function returns the state of a digital pin.
Currently only the MAX5225 based MBHP_AOUT module supports two digital pins
[in] | pin | the pin number (0..31) |
This function sets a digital pin of an AOUT module.
Currently only the MAX5225 based MBHP_AOUT module supports two digital pins
[in] | pin | the pin number (0..31) |
[in] | value | 0 or 1 |
u32 AOUT_DigitalPinsGet | ( | void | ) |
This function returns the state of all digital pins.
Currently only the MAX5225 based MBHP_AOUT module supports two digital pins
This function sets all digital pins of an AOUT module.
Currently only the MAX5225 based MBHP_AOUT module supports two digital pins
[in] | value | each pin has a dedicated flag |
This function re-initializes the AOUT module, and requests a refresh of all output channels according to the stored values in aout_values
The update will take place once AOUT_Update is called (e.g. from a periodically called task)
Background info: the AOUT_PinSet function only request an update if the output value has been changed (comparison between new and previous value) This improves performance a lot, especially when AOUT values are written periodically from a timer interrupt (see MIDIbox SID and MIDIbox FM)
However, sometimes it is useful to force a refresh, e.g. after a patch change, to ensure that all AOUT channels are up-to-date, because it allows to connect (or exchange) the AOUT module during runtime.
This function is also important after a configuration update, e.g. after a different AOUT interface type has been selected.
[in] | mode | currently only mode 0 supported |
const char* AOUT_IfNameGet | ( | aout_if_t | if_type | ) |
Initializes AOUT driver Should be called from Init() during startup
[in] | mode | currently only mode 0 supported |
This function returns the current (target) output value of an output channel.
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
This function returns the pitch offset of an output channel.
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
This function returns the pitch range of an output channel.
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
This function sets the pitch range for an output channel
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
[in] | value | the pitch range (0..127) - only values between 2..12 are really useful |
This function sets the pitch offset for an output channel
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
[in] | value | the pitch (-0x8000..+0x7fff) |
This function sets an output channel to a given 16-bit value.
The output value won't be transfered to the module immediately, but will be buffered instead. By calling AOUT_Update() the requested changes will take place.
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
[in] | value | the 16bit value |
This function returns the slew rate of an output channel.
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
This function sets the slew rate for an output channel
[in] | pin | the pin number (0..AOUT_NUM_CHANNELS-1) |
[in] | value | the slew rate (0..255 mS) |
s32 AOUT_SuspendGet | ( | void | ) |
This function allows to suspend any updates until suspend will be deactived
[in] | suspend | if 1: AOUT_Update() has no effect, if 0: module will be re-initialized via AOUT_IF_Init(0) and AOUT_Update() works again |
s32 AOUT_TerminalHelp | ( | void * | _output_function | ) |
s32 AOUT_TerminalParseLine | ( | char * | input, | |
void * | _output_function | |||
) |
s32 AOUT_TerminalPrintConfig | ( | void * | _output_function | ) |
s32 AOUT_Update | ( | void | ) |
Updates the output channels of the connected AOUT module
Should be called, whenever changes have been requested via AOUT_Pin*Set or AOUT_DigitalPin*Set