|
| 1 | +/** |
| 2 | + * \file |
| 3 | + * |
| 4 | + * \brief SAM Peripheral Digital-to-Analog Converter Driver |
| 5 | + * |
| 6 | + * Copyright (C) 2012-2015 Atmel Corporation. All rights reserved. |
| 7 | + * |
| 8 | + * \asf_license_start |
| 9 | + * |
| 10 | + * \page License |
| 11 | + * |
| 12 | + * Redistribution and use in source and binary forms, with or without |
| 13 | + * modification, are permitted provided that the following conditions are met: |
| 14 | + * |
| 15 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 16 | + * this list of conditions and the following disclaimer. |
| 17 | + * |
| 18 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 19 | + * this list of conditions and the following disclaimer in the documentation |
| 20 | + * and/or other materials provided with the distribution. |
| 21 | + * |
| 22 | + * 3. The name of Atmel may not be used to endorse or promote products derived |
| 23 | + * from this software without specific prior written permission. |
| 24 | + * |
| 25 | + * 4. This software may only be redistributed and used in connection with an |
| 26 | + * Atmel microcontroller product. |
| 27 | + * |
| 28 | + * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
| 29 | + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 30 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
| 31 | + * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
| 32 | + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 33 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 34 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 35 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 36 | + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 37 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 38 | + * POSSIBILITY OF SUCH DAMAGE. |
| 39 | + * |
| 40 | + * \asf_license_stop |
| 41 | + * |
| 42 | + */ |
| 43 | +/* |
| 44 | + * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
| 45 | + */ |
| 46 | +#ifndef DAC_H_INCLUDED |
| 47 | +#define DAC_H_INCLUDED |
| 48 | + |
| 49 | + |
| 50 | +#ifdef __cplusplus |
| 51 | +extern "C" { |
| 52 | +#endif |
| 53 | + |
| 54 | +#include <compiler.h> |
| 55 | +#include <clock.h> |
| 56 | +#include <gclk.h> |
| 57 | + |
| 58 | +/** |
| 59 | + * \addtogroup asfdoc_sam0_dac_group |
| 60 | + * |
| 61 | + * @{ |
| 62 | + */ |
| 63 | + |
| 64 | +/** |
| 65 | + * Define DAC features set according to different device families. |
| 66 | + * @{ |
| 67 | + */ |
| 68 | +#if (SAMD21 || SAMD10 || SAMD11 || SAMDA1) |
| 69 | +# define FEATURE_DAC_DATABUF_WRITE_PROTECTION |
| 70 | +#endif |
| 71 | +/**@}*/ |
| 72 | + |
| 73 | +#ifndef DAC_TIMEOUT |
| 74 | +# define DAC_TIMEOUT 0xFFFF |
| 75 | +#endif |
| 76 | + |
| 77 | +#if DAC_CALLBACK_MODE == true |
| 78 | +# include <system_interrupt.h> |
| 79 | + |
| 80 | +/** Forward definition of the device instance. */ |
| 81 | +struct dac_module; |
| 82 | + |
| 83 | +#if !defined(__DOXYGEN__) |
| 84 | +extern struct dac_module *_dac_instances[DAC_INST_NUM]; |
| 85 | +#endif |
| 86 | + |
| 87 | +/** Type definition for a DAC module callback function. */ |
| 88 | +typedef void (*dac_callback_t)(uint8_t channel); |
| 89 | + |
| 90 | +/** Enum for the possible callback types for the DAC module. */ |
| 91 | +enum dac_callback { |
| 92 | + /** Callback type for when a DAC channel data empty condition occurs |
| 93 | + * (requires event triggered mode) */ |
| 94 | + DAC_CALLBACK_DATA_EMPTY, |
| 95 | + |
| 96 | + /** Callback type for when a DAC channel data underrun condition occurs |
| 97 | + * (requires event triggered mode) */ |
| 98 | + DAC_CALLBACK_DATA_UNDERRUN, |
| 99 | + |
| 100 | + /** Callback type for when a DAC channel write buffer job complete (requires |
| 101 | + * event triggered mode) */ |
| 102 | + DAC_CALLBACK_TRANSFER_COMPLETE, |
| 103 | +#if !defined(__DOXYGEN__) |
| 104 | + DAC_CALLBACK_N, |
| 105 | +#endif |
| 106 | +}; |
| 107 | + |
| 108 | +#endif |
| 109 | + |
| 110 | +#include <dac_feature.h> |
| 111 | + |
| 112 | +/** |
| 113 | + * \name Configuration and Initialization |
| 114 | + * @{ |
| 115 | + */ |
| 116 | + |
| 117 | +bool dac_is_syncing( |
| 118 | + struct dac_module *const dev_inst); |
| 119 | + |
| 120 | +void dac_get_config_defaults( |
| 121 | + struct dac_config *const config); |
| 122 | + |
| 123 | +enum status_code dac_init( |
| 124 | + struct dac_module *const dev_inst, |
| 125 | + Dac *const module, |
| 126 | + struct dac_config *const config); |
| 127 | + |
| 128 | +void dac_reset( |
| 129 | + struct dac_module *const dev_inst); |
| 130 | + |
| 131 | +void dac_enable( |
| 132 | + struct dac_module *const dev_inst); |
| 133 | + |
| 134 | +void dac_disable( |
| 135 | + struct dac_module *const dev_inst); |
| 136 | + |
| 137 | +void dac_enable_events( |
| 138 | + struct dac_module *const module_inst, |
| 139 | + struct dac_events *const events); |
| 140 | + |
| 141 | +void dac_disable_events( |
| 142 | + struct dac_module *const module_inst, |
| 143 | + struct dac_events *const events); |
| 144 | + |
| 145 | +/** @} */ |
| 146 | + |
| 147 | +/** |
| 148 | + * \name Configuration and Initialization (Channel) |
| 149 | + * @{ |
| 150 | + */ |
| 151 | + |
| 152 | +void dac_chan_get_config_defaults( |
| 153 | + struct dac_chan_config *const config); |
| 154 | + |
| 155 | +void dac_chan_set_config( |
| 156 | + struct dac_module *const dev_inst, |
| 157 | + const enum dac_channel channel, |
| 158 | + struct dac_chan_config *const config); |
| 159 | + |
| 160 | +void dac_chan_enable( |
| 161 | + struct dac_module *const dev_inst, |
| 162 | + enum dac_channel channel); |
| 163 | + |
| 164 | +void dac_chan_disable( |
| 165 | + struct dac_module *const dev_inst, |
| 166 | + enum dac_channel channel); |
| 167 | + |
| 168 | +/** @} */ |
| 169 | + |
| 170 | +/** |
| 171 | + * \name Channel Data Management |
| 172 | + * @{ |
| 173 | + */ |
| 174 | + |
| 175 | +enum status_code dac_chan_write( |
| 176 | + struct dac_module *const dev_inst, |
| 177 | + enum dac_channel channel, |
| 178 | + const uint16_t data); |
| 179 | + |
| 180 | +enum status_code dac_chan_write_buffer_wait( |
| 181 | + struct dac_module *const module_inst, |
| 182 | + enum dac_channel channel, |
| 183 | + uint16_t *buffer, |
| 184 | + uint32_t length); |
| 185 | + |
| 186 | +/** @} */ |
| 187 | + |
| 188 | +/** |
| 189 | + * \name Status Management |
| 190 | + * @{ |
| 191 | + */ |
| 192 | +uint32_t dac_get_status( |
| 193 | + struct dac_module *const module_inst); |
| 194 | +void dac_clear_status( |
| 195 | + struct dac_module *const module_inst, |
| 196 | + uint32_t status_flags); |
| 197 | + |
| 198 | +/** @} */ |
| 199 | + |
| 200 | +#ifdef __cplusplus |
| 201 | +} |
| 202 | +#endif |
| 203 | + |
| 204 | +/** @} */ |
| 205 | + |
| 206 | + |
| 207 | +#endif /* DAC_H_INCLUDED */ |
0 commit comments