dac.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /**
  2. * \file
  3. *
  4. * \brief Component description for DAC
  5. *
  6. * Copyright (c) 2014-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 _SAMD21_DAC_COMPONENT_
  47. #define _SAMD21_DAC_COMPONENT_
  48. /* ========================================================================== */
  49. /** SOFTWARE API DEFINITION FOR DAC */
  50. /* ========================================================================== */
  51. /** \addtogroup SAMD21_DAC Digital Analog Converter */
  52. /*@{*/
  53. #define DAC_U2214
  54. #define REV_DAC 0x110
  55. /* -------- DAC_CTRLA : (DAC Offset: 0x0) (R/W 8) Control A -------- */
  56. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  57. typedef union {
  58. struct {
  59. uint8_t SWRST:1; /*!< bit: 0 Software Reset */
  60. uint8_t ENABLE:1; /*!< bit: 1 Enable */
  61. uint8_t RUNSTDBY:1; /*!< bit: 2 Run in Standby */
  62. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  63. } bit; /*!< Structure used for bit access */
  64. uint8_t reg; /*!< Type used for register access */
  65. } DAC_CTRLA_Type;
  66. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  67. #define DAC_CTRLA_OFFSET 0x0 /**< \brief (DAC_CTRLA offset) Control A */
  68. #define DAC_CTRLA_RESETVALUE 0x00ul /**< \brief (DAC_CTRLA reset_value) Control A */
  69. #define DAC_CTRLA_SWRST_Pos 0 /**< \brief (DAC_CTRLA) Software Reset */
  70. #define DAC_CTRLA_SWRST (0x1ul << DAC_CTRLA_SWRST_Pos)
  71. #define DAC_CTRLA_ENABLE_Pos 1 /**< \brief (DAC_CTRLA) Enable */
  72. #define DAC_CTRLA_ENABLE (0x1ul << DAC_CTRLA_ENABLE_Pos)
  73. #define DAC_CTRLA_RUNSTDBY_Pos 2 /**< \brief (DAC_CTRLA) Run in Standby */
  74. #define DAC_CTRLA_RUNSTDBY (0x1ul << DAC_CTRLA_RUNSTDBY_Pos)
  75. #define DAC_CTRLA_MASK 0x07ul /**< \brief (DAC_CTRLA) MASK Register */
  76. /* -------- DAC_CTRLB : (DAC Offset: 0x1) (R/W 8) Control B -------- */
  77. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  78. typedef union {
  79. struct {
  80. uint8_t EOEN:1; /*!< bit: 0 External Output Enable */
  81. uint8_t IOEN:1; /*!< bit: 1 Internal Output Enable */
  82. uint8_t LEFTADJ:1; /*!< bit: 2 Left Adjusted Data */
  83. uint8_t VPD:1; /*!< bit: 3 Voltage Pump Disable */
  84. uint8_t BDWP:1; /*!< bit: 4 Bypass DATABUF Write Protection */
  85. uint8_t :1; /*!< bit: 5 Reserved */
  86. uint8_t REFSEL:2; /*!< bit: 6.. 7 Reference Selection */
  87. } bit; /*!< Structure used for bit access */
  88. uint8_t reg; /*!< Type used for register access */
  89. } DAC_CTRLB_Type;
  90. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  91. #define DAC_CTRLB_OFFSET 0x1 /**< \brief (DAC_CTRLB offset) Control B */
  92. #define DAC_CTRLB_RESETVALUE 0x00ul /**< \brief (DAC_CTRLB reset_value) Control B */
  93. #define DAC_CTRLB_EOEN_Pos 0 /**< \brief (DAC_CTRLB) External Output Enable */
  94. #define DAC_CTRLB_EOEN (0x1ul << DAC_CTRLB_EOEN_Pos)
  95. #define DAC_CTRLB_IOEN_Pos 1 /**< \brief (DAC_CTRLB) Internal Output Enable */
  96. #define DAC_CTRLB_IOEN (0x1ul << DAC_CTRLB_IOEN_Pos)
  97. #define DAC_CTRLB_LEFTADJ_Pos 2 /**< \brief (DAC_CTRLB) Left Adjusted Data */
  98. #define DAC_CTRLB_LEFTADJ (0x1ul << DAC_CTRLB_LEFTADJ_Pos)
  99. #define DAC_CTRLB_VPD_Pos 3 /**< \brief (DAC_CTRLB) Voltage Pump Disable */
  100. #define DAC_CTRLB_VPD (0x1ul << DAC_CTRLB_VPD_Pos)
  101. #define DAC_CTRLB_BDWP_Pos 4 /**< \brief (DAC_CTRLB) Bypass DATABUF Write Protection */
  102. #define DAC_CTRLB_BDWP (0x1ul << DAC_CTRLB_BDWP_Pos)
  103. #define DAC_CTRLB_REFSEL_Pos 6 /**< \brief (DAC_CTRLB) Reference Selection */
  104. #define DAC_CTRLB_REFSEL_Msk (0x3ul << DAC_CTRLB_REFSEL_Pos)
  105. #define DAC_CTRLB_REFSEL(value) ((DAC_CTRLB_REFSEL_Msk & ((value) << DAC_CTRLB_REFSEL_Pos)))
  106. #define DAC_CTRLB_REFSEL_INT1V_Val 0x0ul /**< \brief (DAC_CTRLB) Internal 1.0V reference */
  107. #define DAC_CTRLB_REFSEL_AVCC_Val 0x1ul /**< \brief (DAC_CTRLB) AVCC */
  108. #define DAC_CTRLB_REFSEL_VREFP_Val 0x2ul /**< \brief (DAC_CTRLB) External reference */
  109. #define DAC_CTRLB_REFSEL_INT1V (DAC_CTRLB_REFSEL_INT1V_Val << DAC_CTRLB_REFSEL_Pos)
  110. #define DAC_CTRLB_REFSEL_AVCC (DAC_CTRLB_REFSEL_AVCC_Val << DAC_CTRLB_REFSEL_Pos)
  111. #define DAC_CTRLB_REFSEL_VREFP (DAC_CTRLB_REFSEL_VREFP_Val << DAC_CTRLB_REFSEL_Pos)
  112. #define DAC_CTRLB_MASK 0xDFul /**< \brief (DAC_CTRLB) MASK Register */
  113. /* -------- DAC_EVCTRL : (DAC Offset: 0x2) (R/W 8) Event Control -------- */
  114. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  115. typedef union {
  116. struct {
  117. uint8_t STARTEI:1; /*!< bit: 0 Start Conversion Event Input */
  118. uint8_t EMPTYEO:1; /*!< bit: 1 Data Buffer Empty Event Output */
  119. uint8_t :6; /*!< bit: 2.. 7 Reserved */
  120. } bit; /*!< Structure used for bit access */
  121. uint8_t reg; /*!< Type used for register access */
  122. } DAC_EVCTRL_Type;
  123. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  124. #define DAC_EVCTRL_OFFSET 0x2 /**< \brief (DAC_EVCTRL offset) Event Control */
  125. #define DAC_EVCTRL_RESETVALUE 0x00ul /**< \brief (DAC_EVCTRL reset_value) Event Control */
  126. #define DAC_EVCTRL_STARTEI_Pos 0 /**< \brief (DAC_EVCTRL) Start Conversion Event Input */
  127. #define DAC_EVCTRL_STARTEI (0x1ul << DAC_EVCTRL_STARTEI_Pos)
  128. #define DAC_EVCTRL_EMPTYEO_Pos 1 /**< \brief (DAC_EVCTRL) Data Buffer Empty Event Output */
  129. #define DAC_EVCTRL_EMPTYEO (0x1ul << DAC_EVCTRL_EMPTYEO_Pos)
  130. #define DAC_EVCTRL_MASK 0x03ul /**< \brief (DAC_EVCTRL) MASK Register */
  131. /* -------- DAC_INTENCLR : (DAC Offset: 0x4) (R/W 8) Interrupt Enable Clear -------- */
  132. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  133. typedef union {
  134. struct {
  135. uint8_t UNDERRUN:1; /*!< bit: 0 Underrun Interrupt Enable */
  136. uint8_t EMPTY:1; /*!< bit: 1 Data Buffer Empty Interrupt Enable */
  137. uint8_t SYNCRDY:1; /*!< bit: 2 Synchronization Ready Interrupt Enable */
  138. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  139. } bit; /*!< Structure used for bit access */
  140. uint8_t reg; /*!< Type used for register access */
  141. } DAC_INTENCLR_Type;
  142. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  143. #define DAC_INTENCLR_OFFSET 0x4 /**< \brief (DAC_INTENCLR offset) Interrupt Enable Clear */
  144. #define DAC_INTENCLR_RESETVALUE 0x00ul /**< \brief (DAC_INTENCLR reset_value) Interrupt Enable Clear */
  145. #define DAC_INTENCLR_UNDERRUN_Pos 0 /**< \brief (DAC_INTENCLR) Underrun Interrupt Enable */
  146. #define DAC_INTENCLR_UNDERRUN (0x1ul << DAC_INTENCLR_UNDERRUN_Pos)
  147. #define DAC_INTENCLR_EMPTY_Pos 1 /**< \brief (DAC_INTENCLR) Data Buffer Empty Interrupt Enable */
  148. #define DAC_INTENCLR_EMPTY (0x1ul << DAC_INTENCLR_EMPTY_Pos)
  149. #define DAC_INTENCLR_SYNCRDY_Pos 2 /**< \brief (DAC_INTENCLR) Synchronization Ready Interrupt Enable */
  150. #define DAC_INTENCLR_SYNCRDY (0x1ul << DAC_INTENCLR_SYNCRDY_Pos)
  151. #define DAC_INTENCLR_MASK 0x07ul /**< \brief (DAC_INTENCLR) MASK Register */
  152. /* -------- DAC_INTENSET : (DAC Offset: 0x5) (R/W 8) Interrupt Enable Set -------- */
  153. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  154. typedef union {
  155. struct {
  156. uint8_t UNDERRUN:1; /*!< bit: 0 Underrun Interrupt Enable */
  157. uint8_t EMPTY:1; /*!< bit: 1 Data Buffer Empty Interrupt Enable */
  158. uint8_t SYNCRDY:1; /*!< bit: 2 Synchronization Ready Interrupt Enable */
  159. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  160. } bit; /*!< Structure used for bit access */
  161. uint8_t reg; /*!< Type used for register access */
  162. } DAC_INTENSET_Type;
  163. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  164. #define DAC_INTENSET_OFFSET 0x5 /**< \brief (DAC_INTENSET offset) Interrupt Enable Set */
  165. #define DAC_INTENSET_RESETVALUE 0x00ul /**< \brief (DAC_INTENSET reset_value) Interrupt Enable Set */
  166. #define DAC_INTENSET_UNDERRUN_Pos 0 /**< \brief (DAC_INTENSET) Underrun Interrupt Enable */
  167. #define DAC_INTENSET_UNDERRUN (0x1ul << DAC_INTENSET_UNDERRUN_Pos)
  168. #define DAC_INTENSET_EMPTY_Pos 1 /**< \brief (DAC_INTENSET) Data Buffer Empty Interrupt Enable */
  169. #define DAC_INTENSET_EMPTY (0x1ul << DAC_INTENSET_EMPTY_Pos)
  170. #define DAC_INTENSET_SYNCRDY_Pos 2 /**< \brief (DAC_INTENSET) Synchronization Ready Interrupt Enable */
  171. #define DAC_INTENSET_SYNCRDY (0x1ul << DAC_INTENSET_SYNCRDY_Pos)
  172. #define DAC_INTENSET_MASK 0x07ul /**< \brief (DAC_INTENSET) MASK Register */
  173. /* -------- DAC_INTFLAG : (DAC Offset: 0x6) (R/W 8) Interrupt Flag Status and Clear -------- */
  174. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  175. typedef union {
  176. struct {
  177. uint8_t UNDERRUN:1; /*!< bit: 0 Underrun */
  178. uint8_t EMPTY:1; /*!< bit: 1 Data Buffer Empty */
  179. uint8_t SYNCRDY:1; /*!< bit: 2 Synchronization Ready */
  180. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  181. } bit; /*!< Structure used for bit access */
  182. uint8_t reg; /*!< Type used for register access */
  183. } DAC_INTFLAG_Type;
  184. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  185. #define DAC_INTFLAG_OFFSET 0x6 /**< \brief (DAC_INTFLAG offset) Interrupt Flag Status and Clear */
  186. #define DAC_INTFLAG_RESETVALUE 0x00ul /**< \brief (DAC_INTFLAG reset_value) Interrupt Flag Status and Clear */
  187. #define DAC_INTFLAG_UNDERRUN_Pos 0 /**< \brief (DAC_INTFLAG) Underrun */
  188. #define DAC_INTFLAG_UNDERRUN (0x1ul << DAC_INTFLAG_UNDERRUN_Pos)
  189. #define DAC_INTFLAG_EMPTY_Pos 1 /**< \brief (DAC_INTFLAG) Data Buffer Empty */
  190. #define DAC_INTFLAG_EMPTY (0x1ul << DAC_INTFLAG_EMPTY_Pos)
  191. #define DAC_INTFLAG_SYNCRDY_Pos 2 /**< \brief (DAC_INTFLAG) Synchronization Ready */
  192. #define DAC_INTFLAG_SYNCRDY (0x1ul << DAC_INTFLAG_SYNCRDY_Pos)
  193. #define DAC_INTFLAG_MASK 0x07ul /**< \brief (DAC_INTFLAG) MASK Register */
  194. /* -------- DAC_STATUS : (DAC Offset: 0x7) (R/ 8) Status -------- */
  195. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  196. typedef union {
  197. struct {
  198. uint8_t :7; /*!< bit: 0.. 6 Reserved */
  199. uint8_t SYNCBUSY:1; /*!< bit: 7 Synchronization Busy Status */
  200. } bit; /*!< Structure used for bit access */
  201. uint8_t reg; /*!< Type used for register access */
  202. } DAC_STATUS_Type;
  203. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  204. #define DAC_STATUS_OFFSET 0x7 /**< \brief (DAC_STATUS offset) Status */
  205. #define DAC_STATUS_RESETVALUE 0x00ul /**< \brief (DAC_STATUS reset_value) Status */
  206. #define DAC_STATUS_SYNCBUSY_Pos 7 /**< \brief (DAC_STATUS) Synchronization Busy Status */
  207. #define DAC_STATUS_SYNCBUSY (0x1ul << DAC_STATUS_SYNCBUSY_Pos)
  208. #define DAC_STATUS_MASK 0x80ul /**< \brief (DAC_STATUS) MASK Register */
  209. /* -------- DAC_DATA : (DAC Offset: 0x8) (R/W 16) Data -------- */
  210. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  211. typedef union {
  212. struct {
  213. uint16_t DATA:16; /*!< bit: 0..15 Data value to be converted */
  214. } bit; /*!< Structure used for bit access */
  215. uint16_t reg; /*!< Type used for register access */
  216. } DAC_DATA_Type;
  217. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  218. #define DAC_DATA_OFFSET 0x8 /**< \brief (DAC_DATA offset) Data */
  219. #define DAC_DATA_RESETVALUE 0x0000ul /**< \brief (DAC_DATA reset_value) Data */
  220. #define DAC_DATA_DATA_Pos 0 /**< \brief (DAC_DATA) Data value to be converted */
  221. #define DAC_DATA_DATA_Msk (0xFFFFul << DAC_DATA_DATA_Pos)
  222. #define DAC_DATA_DATA(value) ((DAC_DATA_DATA_Msk & ((value) << DAC_DATA_DATA_Pos)))
  223. #define DAC_DATA_MASK 0xFFFFul /**< \brief (DAC_DATA) MASK Register */
  224. /* -------- DAC_DATABUF : (DAC Offset: 0xC) (R/W 16) Data Buffer -------- */
  225. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  226. typedef union {
  227. struct {
  228. uint16_t DATABUF:16; /*!< bit: 0..15 Data Buffer */
  229. } bit; /*!< Structure used for bit access */
  230. uint16_t reg; /*!< Type used for register access */
  231. } DAC_DATABUF_Type;
  232. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  233. #define DAC_DATABUF_OFFSET 0xC /**< \brief (DAC_DATABUF offset) Data Buffer */
  234. #define DAC_DATABUF_RESETVALUE 0x0000ul /**< \brief (DAC_DATABUF reset_value) Data Buffer */
  235. #define DAC_DATABUF_DATABUF_Pos 0 /**< \brief (DAC_DATABUF) Data Buffer */
  236. #define DAC_DATABUF_DATABUF_Msk (0xFFFFul << DAC_DATABUF_DATABUF_Pos)
  237. #define DAC_DATABUF_DATABUF(value) ((DAC_DATABUF_DATABUF_Msk & ((value) << DAC_DATABUF_DATABUF_Pos)))
  238. #define DAC_DATABUF_MASK 0xFFFFul /**< \brief (DAC_DATABUF) MASK Register */
  239. /** \brief DAC hardware registers */
  240. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  241. typedef struct {
  242. __IO DAC_CTRLA_Type CTRLA; /**< \brief Offset: 0x0 (R/W 8) Control A */
  243. __IO DAC_CTRLB_Type CTRLB; /**< \brief Offset: 0x1 (R/W 8) Control B */
  244. __IO DAC_EVCTRL_Type EVCTRL; /**< \brief Offset: 0x2 (R/W 8) Event Control */
  245. RoReg8 Reserved1[0x1];
  246. __IO DAC_INTENCLR_Type INTENCLR; /**< \brief Offset: 0x4 (R/W 8) Interrupt Enable Clear */
  247. __IO DAC_INTENSET_Type INTENSET; /**< \brief Offset: 0x5 (R/W 8) Interrupt Enable Set */
  248. __IO DAC_INTFLAG_Type INTFLAG; /**< \brief Offset: 0x6 (R/W 8) Interrupt Flag Status and Clear */
  249. __I DAC_STATUS_Type STATUS; /**< \brief Offset: 0x7 (R/ 8) Status */
  250. __IO DAC_DATA_Type DATA; /**< \brief Offset: 0x8 (R/W 16) Data */
  251. RoReg8 Reserved2[0x2];
  252. __IO DAC_DATABUF_Type DATABUF; /**< \brief Offset: 0xC (R/W 16) Data Buffer */
  253. } Dac;
  254. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  255. /*@}*/
  256. #endif /* _SAMD21_DAC_COMPONENT_ */