Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM Digital-to-Analog (DAC) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the conversion of digital values to analog voltage.

The following driver API modes are covered by this manual:

The following peripheral is used by this module:

The following devices can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The Digital-to-Analog converter converts a digital value to analog voltage. The SAM DAC module has one channel with 10-bit resolution, and is capable of converting up to 350k samples per second (ksps).

A common use of DAC is to generate audio signals by connecting the DAC output to a speaker, or to generate a reference voltage; either for an external circuit or an internal peripheral such as the Analog Comparator.

After being set up, the DAC will convert new digital values written to the conversion data register (DATA) to an analog value either on the VOUT pin of the device, or internally for use as an input to the AC, ADC, and other analog modules.

Writing the DATA register will start a new conversion. It is also possible to trigger the conversion from the event system.

A simplified block diagram of the DAC can be seen in the figure below.

dac_block_diagram.svg
DAC Block Diagram

Conversion Range

The conversion range is between GND and the selected voltage reference. Available voltage references are:

Note
Internal references will be enabled by the driver, but not disabled. Any reference not used by the application should be disabled by the application.

The output voltage from a DAC channel is given as:

\[ V_{OUT} = \frac{DATA}{0x3FF} \times VREF \]

Conversion

The digital value written to the conversion data register (DATA) will be converted to an analog value. Writing the DATA register will start a new conversion. It is also possible to write the conversion data to the DATABUF register, the writing of the DATA register can then be triggered from the event system, which will load the value from DATABUF to DATA.

Analog Output

The analog output value can be output to either the VOUT pin or internally, but not both at the same time.

External Output

The output buffer must be enabled in order to drive the DAC output to the VOUT pin. Due to the output buffer, the DAC has high drive strength, and is capable of driving both resistive and capacitive loads, as well as loads which combine both.

Internal Output

The analog value can be internally available for use as input to the AC or ADC modules.

Events

Events generation and event actions are configurable in the DAC. The DAC has one event line input and one event output: Start Conversion and Data Buffer Empty.

If the Start Conversion input event is enabled in the module configuration, an incoming event will load data from the data buffer to the data register and start a new conversion. This method synchronizes conversions with external events (such as those from a timer module) and ensures regular and fixed conversion intervals.

If the Data Buffer Empty output event is enabled in the module configuration, events will be generated when the DAC data buffer register becomes empty and new data can be loaded to the buffer.

Note
The connection of events between modules requires the use of the event driver to route output event of one module to the input event of another. For more information on event routing, refer to the documentation SAM Event System (EVENTS) Driver.

Left and Right Adjusted Values

The 10-bit input value to the DAC is contained in a 16-bit register. This can be configured to be either left or right adjusted. In the figure below both options are shown, and the position of the most (MSB) and the least (LSB) significant bits are indicated. The unused bits should always be written to zero.

Clock Sources

The clock for the DAC interface (CLK_DAC) is generated by the Power Manager. This clock is turned on by default, and can be enabled and disabled in the Power Manager.

Additionally, an asynchronous clock source (GCLK_DAC) is required. These clocks are normally disabled by default. The selected clock source must be enabled in the Power Manager before it can be used by the DAC. The DAC core operates asynchronously from the user interface and peripheral bus. As a consequence, the DAC needs two clock cycles of both CLK_DAC and GCLK_DAC to synchronize the values written to some of the control and data registers. The oscillator source for the GCLK_DAC clock is selected in the System Control Interface (SCIF).

Special Considerations

Output Driver

The DAC can only do conversions in Active or Idle modes. However, if the output buffer is enabled it will draw current even if the system is in sleep mode. Therefore, always make sure that the output buffer is not enabled when it is not needed, to ensure minimum power consumption.

Conversion Time

DAC conversion time is approximately 2.85μs. The user must ensure that new data is not written to the DAC before the last conversion is complete. Conversions should be triggered by a periodic event from a Timer/Counter or another peripheral.

Extra Information

For extra information, see Extra Information for DAC Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for DAC Driver.

API Overview

Data Structures

struct  dac_chan_config
 DAC channel configuration structure. More...
 
struct  dac_config
 DAC configuration structure. More...
 
struct  dac_events
 DAC event enable/disable structure. More...
 
struct  dac_module
 DAC software device instance structure. More...
 

Macros

#define DAC_TIMEOUT   0xFFFF
 Define DAC features set according to different device families. More...
 

Typedefs

typedef void(* dac_callback_t )(uint8_t channel)
 Type definition for a DAC module callback function. More...
 

Enumerations

enum  dac_callback {
  DAC_CALLBACK_DATA_EMPTY,
  DAC_CALLBACK_DATA_UNDERRUN,
  DAC_CALLBACK_TRANSFER_COMPLETE
}
 Enum for the possible callback types for the DAC module. More...
 
enum  dac_channel { DAC_CHANNEL_0 }
 DAC channel selection enum. More...
 
enum  dac_output {
  DAC_OUTPUT_EXTERNAL = DAC_CTRLB_EOEN,
  DAC_OUTPUT_INTERNAL = DAC_CTRLB_IOEN,
  DAC_OUTPUT_NONE = 0
}
 DAC output selection enum. More...
 
enum  dac_reference {
  DAC_REFERENCE_INT1V = DAC_CTRLB_REFSEL(0),
  DAC_REFERENCE_AVCC = DAC_CTRLB_REFSEL(1),
  DAC_REFERENCE_AREF = DAC_CTRLB_REFSEL(2)
}
 DAC reference voltage enum. More...
 

Configuration and Initialization

bool dac_is_syncing (struct dac_module *const dev_inst)
 Determines if the hardware module(s) are currently synchronizing to the bus. More...
 
void dac_get_config_defaults (struct dac_config *const config)
 Initializes a DAC configuration structure to defaults. More...
 
enum status_code dac_init (struct dac_module *const dev_inst, Dac *const module, struct dac_config *const config)
 Initialize the DAC device struct. More...
 
void dac_reset (struct dac_module *const dev_inst)
 Resets the DAC module. More...
 
void dac_enable (struct dac_module *const dev_inst)
 Enable the DAC module. More...
 
void dac_disable (struct dac_module *const dev_inst)
 Disable the DAC module. More...
 
void dac_enable_events (struct dac_module *const module_inst, struct dac_events *const events)
 Enables a DAC event input or output. More...
 
void dac_disable_events (struct dac_module *const module_inst, struct dac_events *const events)
 Disables a DAC event input or output. More...
 

Configuration and Initialization (Channel)

void dac_chan_get_config_defaults (struct dac_chan_config *const config)
 Initializes a DAC channel configuration structure to defaults. More...
 
void dac_chan_set_config (struct dac_module *const dev_inst, const enum dac_channel channel, struct dac_chan_config *const config)
 Writes a DAC channel configuration to the hardware module. More...
 
void dac_chan_enable (struct dac_module *const dev_inst, enum dac_channel channel)
 Enable a DAC channel. More...
 
void dac_chan_disable (struct dac_module *const dev_inst, enum dac_channel channel)
 Disable a DAC channel. More...
 

Channel Data Management

enum status_code dac_chan_write (struct dac_module *const dev_inst, enum dac_channel channel, const uint16_t data)
 Write to the DAC. More...
 
enum status_code dac_chan_write_buffer_wait (struct dac_module *const module_inst, enum dac_channel channel, uint16_t *buffer, uint32_t length)
 Write to the DAC. More...
 

Status Management

uint32_t dac_get_status (struct dac_module *const module_inst)
 Retrieves the current module status. More...
 
void dac_clear_status (struct dac_module *const module_inst, uint32_t status_flags)
 Clears a module status flag. More...
 

Callback Configuration and Initialization

enum status_code dac_chan_write_buffer_job (struct dac_module *const module_inst, const enum dac_channel channel, uint16_t *buffer, uint32_t buffer_size)
 Convert a specific number digital data to analog through DAC. More...
 
enum status_code dac_chan_write_job (struct dac_module *const module_inst, const enum dac_channel channel, uint16_t data)
 Convert one digital data job. More...
 
enum status_code dac_register_callback (struct dac_module *const module, const enum dac_channel channel, const dac_callback_t callback, const enum dac_callback type)
 Registers an asynchronous callback function with the driver. More...
 
enum status_code dac_unregister_callback (struct dac_module *const module, const enum dac_channel channel, const enum dac_callback type)
 Unregisters an asynchronous callback function with the driver. More...
 

Callback Enabling and Disabling (Channel)

enum status_code dac_chan_enable_callback (struct dac_module *const module, const enum dac_channel channel, const enum dac_callback type)
 Enables asynchronous callback generation for a given channel and type. More...
 
enum status_code dac_chan_disable_callback (struct dac_module *const module, const enum dac_channel channel, const enum dac_callback type)
 Disables asynchronous callback generation for a given channel and type. More...
 
enum status_code dac_chan_get_job_status (struct dac_module *module_inst, const enum dac_channel channel)
 Gets the status of a job. More...
 
void dac_chan_abort_job (struct dac_module *module_inst, const enum dac_channel channel)
 Aborts an ongoing job. More...
 

DAC Status Flags

DAC status flags, returned by dac_get_status() and cleared by dac_clear_status().

#define DAC_STATUS_CHANNEL_0_EMPTY   (1UL << 0)
 Data Buffer Empty Channel 0 - Set when data is transferred from DATABUF to DATA by a start conversion event and DATABUF is ready for new data. More...
 
#define DAC_STATUS_CHANNEL_0_UNDERRUN   (1UL << 1)
 Under-run Channel 0 - Set when a start conversion event occurs when DATABUF is empty. More...
 

Configuration and Initialization (Channel)

void dac_chan_enable_output_buffer (struct dac_module *const dev_inst, const enum dac_channel channel)
 Enable the output buffer. More...
 
void dac_chan_disable_output_buffer (struct dac_module *const dev_inst, const enum dac_channel channel)
 Disable the output buffer. More...
 

#define DAC_STATUS_CHANNEL_0_EMPTY   (1UL << 0)

Data Buffer Empty Channel 0 - Set when data is transferred from DATABUF to DATA by a start conversion event and DATABUF is ready for new data.

Referenced by dac_clear_status(), and dac_get_status().

#define DAC_STATUS_CHANNEL_0_UNDERRUN   (1UL << 1)

Under-run Channel 0 - Set when a start conversion event occurs when DATABUF is empty.

Referenced by dac_clear_status(), and dac_get_status().

#define DAC_TIMEOUT   0xFFFF

Define DAC features set according to different device families.

Referenced by dac_chan_write_buffer_wait().

typedef void(* dac_callback_t)(uint8_t channel)

Type definition for a DAC module callback function.

Enum for the possible callback types for the DAC module.

Enumerator
DAC_CALLBACK_DATA_EMPTY 

Callback type for when a DAC channel data empty condition occurs (requires event triggered mode)

DAC_CALLBACK_DATA_UNDERRUN 

Callback type for when a DAC channel data underrun condition occurs (requires event triggered mode)

DAC_CALLBACK_TRANSFER_COMPLETE 

Callback type for when a DAC channel write buffer job complete (requires event triggered mode)

DAC channel selection enum.

Enum for the DAC channel selection.

Enumerator
DAC_CHANNEL_0 

DAC output channel 0.

enum dac_output

DAC output selection enum.

Enum for the DAC output selection.

Enumerator
DAC_OUTPUT_EXTERNAL 

DAC output to VOUT pin.

DAC_OUTPUT_INTERNAL 

DAC output as internal reference.

DAC_OUTPUT_NONE 

No output.

DAC reference voltage enum.

Enum for the possible reference voltages for the DAC.

Enumerator
DAC_REFERENCE_INT1V 

1V from the internal band-gap reference

DAC_REFERENCE_AVCC 

Analog VCC as reference.

DAC_REFERENCE_AREF 

External reference on AREF.

void dac_chan_abort_job ( struct dac_module module_inst,
const enum dac_channel  channel 
)

Aborts an ongoing job.

Aborts an ongoing job.

Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelLogical channel to enable callback function

References Assert, STATUS_ABORTED, and UNUSED.

void dac_chan_disable ( struct dac_module *const  module_inst,
enum dac_channel  channel 
)

Disable a DAC channel.

Disables the selected DAC channel.

Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelChannel to disable

References UNUSED.

enum status_code dac_chan_disable_callback ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
const enum dac_callback  type 
)

Disables asynchronous callback generation for a given channel and type.

Disables asynchronous callbacks for a given logical DAC channel and type.

Parameters
[in,out]dac_modulePointer to the DAC software instance struct
[in]channelLogical channel to disable callback function
[in]typeType of callback function callbacks to disable
Returns
Status of the callback disable operation.
Return values
STATUS_OKThe callback was disabled successfully
STATUS_ERR_UNSUPPORTED_DEVIf a callback that requires event driven mode was specified with a DAC instance configured in non-event mode

References Assert, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, and UNUSED.

void dac_chan_disable_output_buffer ( struct dac_module *const  module_inst,
enum dac_channel  channel 
)

Disable the output buffer.

Disables the output buffer.

Note
The output buffer(s) should be disabled when a channel's output is not currently needed, as it will draw current even if the system is in sleep mode.
Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelDAC channel to alter

References Assert, DAC_OUTPUT_EXTERNAL, and UNUSED.

void dac_chan_enable ( struct dac_module *const  module_inst,
enum dac_channel  channel 
)

Enable a DAC channel.

Enables the selected DAC channel.

Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelChannel to enable

References UNUSED.

Referenced by test_dac_init().

enum status_code dac_chan_enable_callback ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
const enum dac_callback  type 
)

Enables asynchronous callback generation for a given channel and type.

Enables asynchronous callbacks for a given logical DAC channel and type. This must be called before a DAC channel will generate callback events.

Parameters
[in,out]dac_modulePointer to the DAC software instance struct
[in]channelLogical channel to enable callback function
[in]typeType of callback function callbacks to enable
Returns
Status of the callback enable operation.
Return values
STATUS_OKThe callback was enabled successfully
STATUS_ERR_UNSUPPORTED_DEVIf a callback that requires event driven mode was specified with a DAC instance configured in non-event mode

References Assert, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, and UNUSED.

void dac_chan_enable_output_buffer ( struct dac_module *const  module_inst,
enum dac_channel  channel 
)

Enable the output buffer.

Enables the output buffer and drives the DAC output to the VOUT pin.

Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelDAC channel to alter

References Assert, DAC_OUTPUT_EXTERNAL, and UNUSED.

void dac_chan_get_config_defaults ( struct dac_chan_config *const  config)

Initializes a DAC channel configuration structure to defaults.

Initializes a given DAC channel configuration structure to a set of known default values. This function should be called on any new instance of the configuration structures before being modified by the user application.

The default configuration is as follows:

  • Start Conversion Event Input enabled
  • Start Data Buffer Empty Event Output disabled
Parameters
[out]configConfiguration structure to initialize to default values

References Assert.

Referenced by test_dac_init().

enum status_code dac_chan_get_job_status ( struct dac_module module_inst,
const enum dac_channel  channel 
)

Gets the status of a job.

Gets the status of an ongoing or the last job.

Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelLogical channel to enable callback function
Returns
Status of the job.

References Assert, and UNUSED.

void dac_chan_set_config ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
struct dac_chan_config *const  config 
)

Writes a DAC channel configuration to the hardware module.

Writes a given channel configuration to the hardware module.

Note
The DAC device instance structure must be initialized before calling this function.
Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelChannel to configure
[in]configPointer to the configuration struct

References UNUSED.

Referenced by test_dac_init().

enum status_code dac_chan_write ( struct dac_module *const  module_inst,
enum dac_channel  channel,
const uint16_t  data 
)

Write to the DAC.

This function writes to the DATA or DATABUF register. If the conversion is not event-triggered, the data will be written to the DATA register and the conversion will start. If the conversion is event-triggered, the data will be written to DATABUF and transferred to the DATA register and converted when a Start Conversion Event is issued. Conversion data must be right or left adjusted according to configuration settings.

Note
To be event triggered, the enable_start_on_event must be enabled in the configuration.
Parameters
[in]module_instPointer to the DAC software device struct
[in]channelDAC channel to write to
[in]dataConversion data
Returns
Status of the operation.
Return values
STATUS_OKIf the data was written

References Assert, dac_is_syncing(), STATUS_OK, and UNUSED.

Referenced by dac_chan_write_buffer_wait(), run_adc_average_mode_test(), run_adc_callback_mode_test(), run_adc_polled_mode_test(), run_adc_window_mode_test(), and setup_adc_window_mode_test().

enum status_code dac_chan_write_buffer_job ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
uint16_t *  buffer,
uint32_t  length 
)

Convert a specific number digital data to analog through DAC.

This function will perform a conversion of specific number of digital data. The conversion should be event-triggered, the data will be written to DATABUF and transferred to the DATA register and converted when a Start Conversion Event is issued. Conversion data must be right or left adjusted according to configuration settings.

Note
To be event triggered, the enable_start_on_event must be enabled in the configuration.
Parameters
[in]module_instPointer to the DAC software device struct
[in]channelDAC channel to write to
[in]bufferPointer to the digital data write buffer to be converted
[in]lengthSize of the write buffer
Returns
Status of the operation.
Return values
STATUS_OKIf the data was written
STATUS_ERR_UNSUPPORTED_DEVIf a callback that requires event driven mode was specified with a DAC instance configured in non-event mode
STATUS_BUSYThe DAC is busy to accept new job

References Assert, dac_is_syncing(), STATUS_BUSY, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, system_interrupt_enable(), SYSTEM_INTERRUPT_MODULE_DAC, and UNUSED.

Referenced by dac_chan_write_job().

enum status_code dac_chan_write_buffer_wait ( struct dac_module *const  module_inst,
enum dac_channel  channel,
uint16_t *  buffer,
uint32_t  length 
)

Write to the DAC.

This function converts a specific number of digital data. The conversion should be event-triggered, the data will be written to DATABUF and transferred to the DATA register and converted when a Start Conversion Event is issued. Conversion data must be right or left adjusted according to configuration settings.

Note
To be event triggered, the enable_start_on_event must be enabled in the configuration.
Parameters
[in]module_instPointer to the DAC software device struct
[in]channelDAC channel to write to
[in]bufferPointer to the digital data write buffer to be converted
[in]lengthLength of the write buffer
Returns
Status of the operation.
Return values
STATUS_OKIf the data was written or no data conversion required
STATUS_ERR_UNSUPPORTED_DEVThe DAC is not configured as using event trigger
STATUS_BUSYThe DAC is busy to convert

References Assert, dac_chan_write(), dac_is_syncing(), DAC_TIMEOUT, STATUS_BUSY, STATUS_ERR_TIMEOUT, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, and UNUSED.

enum status_code dac_chan_write_job ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
uint16_t  data 
)

Convert one digital data job.

This function will perform a conversion of specfic number of digital data. The conversion is event-triggered, the data will be written to DATABUF and transferred to the DATA register and converted when a Start Conversion Event is issued. Conversion data must be right or left adjusted according to configuration settings.

Note
To be event triggered, the enable_start_on_event must be enabled in the configuration.
Parameters
[in]module_instPointer to the DAC software device struct
[in]channelDAC channel to write to
[in]dataDigital data to be converted
Returns
Status of the operation.
Return values
STATUS_OKIf the data was written
STATUS_ERR_UNSUPPORTED_DEVIf a callback that requires event driven mode was specified with a DAC instance configured in non-event mode
STATUS_BUSYThe DAC is busy to accept new job

References Assert, dac_chan_write_buffer_job(), STATUS_BUSY, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, and UNUSED.

void dac_clear_status ( struct dac_module *const  module_inst,
uint32_t  status_flags 
)

Clears a module status flag.

Clears the given status flag of the module.

Parameters
[in]module_instPointer to the DAC software device struct
[in]status_flagsBit mask of status flags to clear

References Assert, DAC_STATUS_CHANNEL_0_EMPTY, and DAC_STATUS_CHANNEL_0_UNDERRUN.

void dac_disable ( struct dac_module *const  module_inst)

Disable the DAC module.

Disables the DAC interface and the output buffer.

Parameters
[in]module_instPointer to the DAC software instance struct

References Assert, and dac_is_syncing().

void dac_disable_events ( struct dac_module *const  module_inst,
struct dac_events *const  events 
)

Disables a DAC event input or output.

Disables one or more input or output events to or from the DAC module. See dac_events for a list of events this module supports.

Note
Events cannot be altered while the module is enabled.
Parameters
[in]module_instSoftware instance for the DAC peripheral
[in]eventsStruct containing flags of events to disable

References Assert, dac_events::generate_event_on_buffer_empty, and dac_events::on_event_start_conversion.

void dac_enable ( struct dac_module *const  module_inst)

Enable the DAC module.

Enables the DAC interface and the selected output. If any internal reference is selected it will be enabled.

Parameters
[in]module_instPointer to the DAC software instance struct

References Assert, dac_is_syncing(), DAC_REFERENCE_INT1V, SYSTEM_VOLTAGE_REFERENCE_BANDGAP, and system_voltage_reference_enable().

Referenced by test_dac_init().

void dac_enable_events ( struct dac_module *const  module_inst,
struct dac_events *const  events 
)

Enables a DAC event input or output.

Enables one or more input or output events to or from the DAC module. See dac_events for a list of events this module supports.

Note
Events cannot be altered while the module is enabled.
Parameters
[in]module_instSoftware instance for the DAC peripheral
[in]eventsStruct containing flags of events to enable

References Assert, dac_events::generate_event_on_buffer_empty, and dac_events::on_event_start_conversion.

void dac_get_config_defaults ( struct dac_config *const  config)

Initializes a DAC configuration structure to defaults.

Initializes a given DAC configuration structure to a set of known default values. This function should be called on any new instance of the configuration structures before being modified by the user application.

The default configuration is as follows:

  • 1V from internal bandgap reference
  • Drive the DAC output to the VOUT pin
  • Right adjust data
  • GCLK generator 0 (GCLK main) clock source
  • The output buffer is disabled when the chip enters STANDBY sleep mode
Parameters
[out]configConfiguration structure to initialize to default values

References Assert, dac_config::clock_source, DAC_OUTPUT_EXTERNAL, DAC_REFERENCE_INT1V, GCLK_GENERATOR_0, dac_config::left_adjust, dac_config::output, dac_config::reference, dac_config::run_in_standby, and dac_config::voltage_pump_disable.

Referenced by test_dac_init().

uint32_t dac_get_status ( struct dac_module *const  module_inst)

Retrieves the current module status.

Checks the status of the module and returns it as a bitmask of status flags.

Parameters
[in]module_instPointer to the DAC software device struct
Returns
Bitmask of status flags.
Return values
DAC_STATUS_CHANNEL_0_EMPTYData has been transferred from DATABUF to DATA by a start conversion event and DATABUF is ready for new data
DAC_STATUS_CHANNEL_0_UNDERRUNA start conversion event has occurred when DATABUF is empty

References Assert, DAC_STATUS_CHANNEL_0_EMPTY, and DAC_STATUS_CHANNEL_0_UNDERRUN.

enum status_code dac_init ( struct dac_module *const  module_inst,
Dac *const  module,
struct dac_config *const  config 
)

Initialize the DAC device struct.

Use this function to initialize the Digital to Analog Converter. Resets the underlying hardware module and configures it.

Note
The DAC channel must be configured separately.
Parameters
[out]module_instPointer to the DAC software instance struct
[in]modulePointer to the DAC module instance
[in]configPointer to the config struct, created by the user application
Returns
Status of initialization.
Return values
STATUS_OKModule initiated correctly
STATUS_ERR_DENIEDIf module is enabled
STATUS_BUSYIf module is busy resetting

References _dac_instances, _dac_set_config(), Assert, dac_config::clock_source, system_pinmux_config::direction, system_pinmux_config::input_pull, system_pinmux_config::mux_position, dac_config::reference, system_gclk_chan_config::source_generator, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_OK, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBC, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), system_gclk_chan_set_config(), system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_INPUT, SYSTEM_PINMUX_PIN_PULL_NONE, and system_pinmux_pin_set_config().

Referenced by test_dac_init().

bool dac_is_syncing ( struct dac_module *const  dev_inst)

Determines if the hardware module(s) are currently synchronizing to the bus.

Checks to see if the underlying hardware peripheral module(s) are currently synchronizing across multiple clock domains to the hardware bus. This function can be used to delay further operations on a module until such time that it is ready, to prevent blocking delays for synchronization in the user application.

Parameters
[in]dev_instPointer to the DAC software instance struct
Returns
Synchronization status of the underlying hardware module(s).
Return values
trueIf the module synchronization is ongoing
falseIf the module has completed synchronization

References Assert.

Referenced by _dac_set_config(), dac_chan_write(), dac_chan_write_buffer_job(), dac_chan_write_buffer_wait(), dac_disable(), dac_enable(), and dac_reset().

enum status_code dac_register_callback ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
const dac_callback_t  callback,
const enum dac_callback  type 
)

Registers an asynchronous callback function with the driver.

Registers an asynchronous callback with the DAC driver, fired when a callback condition occurs.

Parameters
[in,out]module_instPointer to the DAC software instance struct
[in]callbackPointer to the callback function to register
[in]channelLogical channel to register callback function
[in]typeType of callback function to register
Returns
Status of the registration operation.
Return values
STATUS_OKThe callback was registered successfully
STATUS_ERR_INVALID_ARGIf an invalid callback type was supplied
STATUS_ERR_UNSUPPORTED_DEVIf a callback that requires event driven mode was specified with a DAC instance configured in non-event mode

References Assert, STATUS_ERR_INVALID_ARG, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, and UNUSED.

void dac_reset ( struct dac_module *const  module_inst)

Resets the DAC module.

This function will reset the DAC module to its power on default values and disable it.

Parameters
[in]module_instPointer to the DAC software instance struct

References Assert, and dac_is_syncing().

enum status_code dac_unregister_callback ( struct dac_module *const  module_inst,
const enum dac_channel  channel,
const enum dac_callback  type 
)

Unregisters an asynchronous callback function with the driver.

Unregisters an asynchronous callback with the DAC driver, removing it from the internal callback registration table.

Parameters
[in,out]module_instPointer to the DAC software instance struct
[in]channelLogical channel to unregister callback function
[in]typeType of callback function to unregister
Returns
Status of the de-registration operation.
Return values
STATUS_OKThe callback was unregistered successfully
STATUS_ERR_INVALID_ARGIf an invalid callback type was supplied
STATUS_ERR_UNSUPPORTED_DEVIf a callback that requires event driven mode was specified with a DAC instance configured in non-event mode

References Assert, STATUS_ERR_INVALID_ARG, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, and UNUSED.