dac.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * \file
  3. *
  4. * \brief SAM Peripheral Digital-to-Analog Converter Driver
  5. *
  6. * Copyright (C) 2012-2016 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. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. #include <compiler.h>
  52. #include <clock.h>
  53. #include <gclk.h>
  54. /**
  55. * \addtogroup asfdoc_sam0_dac_group
  56. *
  57. * @{
  58. */
  59. /**
  60. * Define DAC features set according to different device families.
  61. * @{
  62. */
  63. #if (SAMD21 || SAMD10 || SAMD11 || SAMDA1 || SAMHA1)
  64. # define FEATURE_DAC_DATABUF_WRITE_PROTECTION
  65. #endif
  66. /**@}*/
  67. #ifndef DAC_TIMEOUT
  68. # define DAC_TIMEOUT 0xFFFF
  69. #endif
  70. #if DAC_CALLBACK_MODE == true
  71. # include <system_interrupt.h>
  72. /** Forward definition of the device instance. */
  73. struct dac_module;
  74. #if !defined(__DOXYGEN__)
  75. extern struct dac_module *_dac_instances[DAC_INST_NUM];
  76. #endif
  77. /** Type definition for a DAC module callback function. */
  78. typedef void (*dac_callback_t)(uint8_t channel);
  79. /** Enum for the possible callback types for the DAC module. */
  80. enum dac_callback {
  81. /** Callback type for when a DAC channel data empty condition occurs
  82. * (requires event triggered mode) */
  83. DAC_CALLBACK_DATA_EMPTY,
  84. /** Callback type for when a DAC channel data underrun condition occurs
  85. * (requires event triggered mode) */
  86. DAC_CALLBACK_DATA_UNDERRUN,
  87. /** Callback type for when a DAC channel write buffer job complete (requires
  88. * event triggered mode) */
  89. DAC_CALLBACK_TRANSFER_COMPLETE,
  90. #if !defined(__DOXYGEN__)
  91. DAC_CALLBACK_N,
  92. #endif
  93. };
  94. #endif
  95. #include <dac_feature.h>
  96. /**
  97. * \name Configuration and Initialization
  98. * @{
  99. */
  100. bool dac_is_syncing(
  101. struct dac_module *const dev_inst);
  102. void dac_get_config_defaults(
  103. struct dac_config *const config);
  104. enum status_code dac_init(
  105. struct dac_module *const dev_inst,
  106. Dac *const module,
  107. struct dac_config *const config);
  108. void dac_reset(
  109. struct dac_module *const dev_inst);
  110. void dac_enable(
  111. struct dac_module *const dev_inst);
  112. void dac_disable(
  113. struct dac_module *const dev_inst);
  114. void dac_enable_events(
  115. struct dac_module *const module_inst,
  116. struct dac_events *const events);
  117. void dac_disable_events(
  118. struct dac_module *const module_inst,
  119. struct dac_events *const events);
  120. /** @} */
  121. /**
  122. * \name Configuration and Initialization (Channel)
  123. * @{
  124. */
  125. void dac_chan_get_config_defaults(
  126. struct dac_chan_config *const config);
  127. void dac_chan_set_config(
  128. struct dac_module *const dev_inst,
  129. const enum dac_channel channel,
  130. struct dac_chan_config *const config);
  131. void dac_chan_enable(
  132. struct dac_module *const dev_inst,
  133. enum dac_channel channel);
  134. void dac_chan_disable(
  135. struct dac_module *const dev_inst,
  136. enum dac_channel channel);
  137. /** @} */
  138. /**
  139. * \name Channel Data Management
  140. * @{
  141. */
  142. enum status_code dac_chan_write(
  143. struct dac_module *const dev_inst,
  144. enum dac_channel channel,
  145. const uint16_t data);
  146. enum status_code dac_chan_write_buffer_wait(
  147. struct dac_module *const module_inst,
  148. enum dac_channel channel,
  149. uint16_t *buffer,
  150. uint32_t length);
  151. /** @} */
  152. /**
  153. * \name Status Management
  154. * @{
  155. */
  156. uint32_t dac_get_status(
  157. struct dac_module *const module_inst);
  158. void dac_clear_status(
  159. struct dac_module *const module_inst,
  160. uint32_t status_flags);
  161. /** @} */
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. /** @} */
  166. #endif /* DAC_H_INCLUDED */