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 an analog voltage. The DAC Controller can operate as two independent DACs or as a single DAC in differential mode. Each DAC has a 12-bit resolution and it is capable of converting up to 1M samples per second (Msps).

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 (DATA0 or DATA1) to an analog value either on the DAC output (VOUT0 or VOUT1) 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_saml.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_{OUTx} = \frac{DATAx}{0x3FF} \times VREF \]

The differential output voltage is given as:

\[ V_{OUT} = \frac{DATA0}{0x1FF} \times VREF = (V_{OUT0}-V_{OUT1}) \]

Conversion

The conversion digital value written to the DATA register will be converted to an analog value. Writing the DATA register will start a new conversion. It is also possible to write the conversion value 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 the VOUTx converted by DACx, and each data conversion can be started independently.

In differential mode, DAC0 and DAC1 are operating synchronously to convert value. VOUT0 is the positive output and VOUT1 the negative output.

VOUT0 signal is internally connected so that it can be used as input for AC, ADC, or OPAMP modules when DAC0 is enabled.

Note
The pin VOUT0 will be dedicated to internal input and cannot be configured as alternate function.

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 SAM Event System Driver (EVENTS) to route output event of one module to the the input event of another. For more information on event routing, refer to the event driver documentation.

Left and Right Adjusted Values

The 12-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 Supply Control Interface (SUPC).

Special Considerations

Sleep Mode

The DAC can do conversions in Active or Idle modes, and will continue the conversions in standby sleep mode if the RUNSTDBY bit in the DACCTRLx register is set. Otherwise, the DACx will stop conversions.

If DACx conversion is stopped in standby sleep mode, DACx is disabled to reduce power consumption. When exiting standby sleep mode, DACx is enabled therefore startup time is required before starting a new conversion.

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_1
}
 DAC channel selection enum. More...
 
enum  dac_current_ctrl {
  DAC_CURRENT_100K = DAC_DACCTRL_CCTRL(0),
  DAC_CURRENT_1M = DAC_DACCTRL_CCTRL(1),
  DAC_CURRENT_12M = DAC_DACCTRL_CCTRL(2),
  DAC_CURRENT_RESERVED = DAC_DACCTRL_CCTRL(3)
}
 DAC current control enum. More...
 
enum  dac_reference {
  DAC_REFERENCE_VREFPU = DAC_CTRLB_REFSEL(0),
  DAC_REFERENCE_VDDANA = DAC_CTRLB_REFSEL(1),
  DAC_REFERENCE_VREFPB = DAC_CTRLB_REFSEL(2),
  DAC_REFERENCE_INTREF = DAC_CTRLB_REFSEL(3)
}
 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)
 
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_1_EMPTY   (1UL << 1)
 Data Buffer Empty Channel 1 - 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 << 2)
 Underrun Channel 0 - Set when a start conversion event occurs when DATABUF is empty. More...
 
#define DAC_STATUS_CHANNEL_1_UNDERRUN   (1UL << 3)
 Underrun Channel 1 - Set when a start conversion event occurs when DATABUF is empty. More...
 

Status Management (Channel)

bool dac_chan_is_end_of_conversion (struct dac_module *const module_inst, enum dac_channel channel)
 Retrieves the status of DAC channel end of conversion. 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 << 2)

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

Referenced by dac_clear_status(), and dac_get_status().

#define DAC_STATUS_CHANNEL_1_EMPTY   (1UL << 1)

Data Buffer Empty Channel 1 - 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_1_UNDERRUN   (1UL << 3)

Underrun Channel 1 - 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.

DAC_CHANNEL_1 

DAC output channel 1.

DAC current control enum.

Enum for the current in output buffer according the conversion rate.

Enumerator
DAC_CURRENT_100K 

GCLK_DAC <= 1.2MHz.

DAC_CURRENT_1M 

1.2MHz < GCLK_DAC <= 6MHz

DAC_CURRENT_12M 

6MHz < GCLK_DAC <= 12MHz

DAC_CURRENT_RESERVED 

Reserved.

DAC reference voltage enum.

Enum for the possible reference voltages for the DAC.

Enumerator
DAC_REFERENCE_VREFPU 

Unbuffered external voltage reference.

DAC_REFERENCE_VDDANA 

Analog VCC as reference.

DAC_REFERENCE_VREFPB 

Buffered external voltage reference.

DAC_REFERENCE_INTREF 

Internal bandgap reference.

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, DAC_CHANNEL_0, DAC_CHANNEL_1, and STATUS_ABORTED.

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 Assert.

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_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 Assert.

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, and STATUS_OK.

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.

bool dac_chan_is_end_of_conversion ( struct dac_module *const  module_inst,
enum dac_channel  channel 
)

Retrieves the status of DAC channel end of conversion.

Checks if the conversion is completed or not and returns boolean flag of status.

Parameters
[in]module_instPointer to the DAC software instance struct
[in]channelChannel to disable
Return values
trueConversion is complete, VOUT is stable
falseNo conversion completed since last load of DATA

References Assert.

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 out 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 Assert, dac_chan_config::current, DAC_CHANNEL_0, DAC_CHANNEL_1, system_pinmux_config::direction, dac_chan_config::dither_mode, system_pinmux_config::input_pull, dac_chan_config::left_adjust, system_pinmux_config::mux_position, dac_chan_config::refresh_period, dac_chan_config::run_in_standby, 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().

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(), and STATUS_OK.

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 and can not accept a new job

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

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 and can not do the conversion

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

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 and can not accept a new job

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

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, DAC_STATUS_CHANNEL_0_UNDERRUN, DAC_STATUS_CHANNEL_1_EMPTY, and DAC_STATUS_CHANNEL_1_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 Struct 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_CHANNEL_0, DAC_CHANNEL_1, dac_events::generate_event_on_chan0_buffer_empty, dac_events::on_event_chan0_start_conversion, and dac_events::on_event_chan1_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_CHANNEL_0, DAC_CHANNEL_1, dac_is_syncing(), DAC_REFERENCE_INTREF, system_voltage_reference_enable(), and SYSTEM_VOLTAGE_REFERENCE_OUTPUT.

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 Struct 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_CHANNEL_0, DAC_CHANNEL_1, dac_events::generate_event_on_chan0_buffer_empty, dac_events::generate_event_on_chan0_falling_edge, dac_events::generate_event_on_chan1_buffer_empty, dac_events::generate_event_on_chan1_falling_edge, dac_events::on_event_chan0_start_conversion, and dac_events::on_event_chan1_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_REFERENCE_INTREF, dac_config::differential_mode, GCLK_GENERATOR_0, and dac_config::reference.

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, DAC_STATUS_CHANNEL_0_UNDERRUN, DAC_STATUS_CHANNEL_1_EMPTY, and DAC_STATUS_CHANNEL_1_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, 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(), and system_gclk_chan_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_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, and STATUS_OK.

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, and STATUS_OK.