dac.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /**
  2. * \file
  3. *
  4. * \brief Component description for DAC
  5. *
  6. * Copyright (c) 2018 Microchip Technology Inc.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the Licence at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. * \asf_license_stop
  27. *
  28. */
  29. #ifndef _SAMD11_DAC_COMPONENT_
  30. #define _SAMD11_DAC_COMPONENT_
  31. /* ========================================================================== */
  32. /** SOFTWARE API DEFINITION FOR DAC */
  33. /* ========================================================================== */
  34. /** \addtogroup SAMD11_DAC Digital Analog Converter */
  35. /*@{*/
  36. #define DAC_U2214
  37. #define REV_DAC 0x110
  38. /* -------- DAC_CTRLA : (DAC Offset: 0x0) (R/W 8) Control A -------- */
  39. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  40. typedef union {
  41. struct {
  42. uint8_t SWRST:1; /*!< bit: 0 Software Reset */
  43. uint8_t ENABLE:1; /*!< bit: 1 Enable */
  44. uint8_t RUNSTDBY:1; /*!< bit: 2 Run in Standby */
  45. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  46. } bit; /*!< Structure used for bit access */
  47. uint8_t reg; /*!< Type used for register access */
  48. } DAC_CTRLA_Type;
  49. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  50. #define DAC_CTRLA_OFFSET 0x0 /**< \brief (DAC_CTRLA offset) Control A */
  51. #define DAC_CTRLA_RESETVALUE _U_(0x00) /**< \brief (DAC_CTRLA reset_value) Control A */
  52. #define DAC_CTRLA_SWRST_Pos 0 /**< \brief (DAC_CTRLA) Software Reset */
  53. #define DAC_CTRLA_SWRST (_U_(0x1) << DAC_CTRLA_SWRST_Pos)
  54. #define DAC_CTRLA_ENABLE_Pos 1 /**< \brief (DAC_CTRLA) Enable */
  55. #define DAC_CTRLA_ENABLE (_U_(0x1) << DAC_CTRLA_ENABLE_Pos)
  56. #define DAC_CTRLA_RUNSTDBY_Pos 2 /**< \brief (DAC_CTRLA) Run in Standby */
  57. #define DAC_CTRLA_RUNSTDBY (_U_(0x1) << DAC_CTRLA_RUNSTDBY_Pos)
  58. #define DAC_CTRLA_MASK _U_(0x07) /**< \brief (DAC_CTRLA) MASK Register */
  59. /* -------- DAC_CTRLB : (DAC Offset: 0x1) (R/W 8) Control B -------- */
  60. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  61. typedef union {
  62. struct {
  63. uint8_t EOEN:1; /*!< bit: 0 External Output Enable */
  64. uint8_t IOEN:1; /*!< bit: 1 Internal Output Enable */
  65. uint8_t LEFTADJ:1; /*!< bit: 2 Left Adjusted Data */
  66. uint8_t VPD:1; /*!< bit: 3 Voltage Pump Disable */
  67. uint8_t BDWP:1; /*!< bit: 4 Bypass DATABUF Write Protection */
  68. uint8_t :1; /*!< bit: 5 Reserved */
  69. uint8_t REFSEL:2; /*!< bit: 6.. 7 Reference Selection */
  70. } bit; /*!< Structure used for bit access */
  71. uint8_t reg; /*!< Type used for register access */
  72. } DAC_CTRLB_Type;
  73. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  74. #define DAC_CTRLB_OFFSET 0x1 /**< \brief (DAC_CTRLB offset) Control B */
  75. #define DAC_CTRLB_RESETVALUE _U_(0x00) /**< \brief (DAC_CTRLB reset_value) Control B */
  76. #define DAC_CTRLB_EOEN_Pos 0 /**< \brief (DAC_CTRLB) External Output Enable */
  77. #define DAC_CTRLB_EOEN (_U_(0x1) << DAC_CTRLB_EOEN_Pos)
  78. #define DAC_CTRLB_IOEN_Pos 1 /**< \brief (DAC_CTRLB) Internal Output Enable */
  79. #define DAC_CTRLB_IOEN (_U_(0x1) << DAC_CTRLB_IOEN_Pos)
  80. #define DAC_CTRLB_LEFTADJ_Pos 2 /**< \brief (DAC_CTRLB) Left Adjusted Data */
  81. #define DAC_CTRLB_LEFTADJ (_U_(0x1) << DAC_CTRLB_LEFTADJ_Pos)
  82. #define DAC_CTRLB_VPD_Pos 3 /**< \brief (DAC_CTRLB) Voltage Pump Disable */
  83. #define DAC_CTRLB_VPD (_U_(0x1) << DAC_CTRLB_VPD_Pos)
  84. #define DAC_CTRLB_BDWP_Pos 4 /**< \brief (DAC_CTRLB) Bypass DATABUF Write Protection */
  85. #define DAC_CTRLB_BDWP (_U_(0x1) << DAC_CTRLB_BDWP_Pos)
  86. #define DAC_CTRLB_REFSEL_Pos 6 /**< \brief (DAC_CTRLB) Reference Selection */
  87. #define DAC_CTRLB_REFSEL_Msk (_U_(0x3) << DAC_CTRLB_REFSEL_Pos)
  88. #define DAC_CTRLB_REFSEL(value) (DAC_CTRLB_REFSEL_Msk & ((value) << DAC_CTRLB_REFSEL_Pos))
  89. #define DAC_CTRLB_REFSEL_INT1V_Val _U_(0x0) /**< \brief (DAC_CTRLB) Internal 1.0V reference */
  90. #define DAC_CTRLB_REFSEL_AVCC_Val _U_(0x1) /**< \brief (DAC_CTRLB) AVCC */
  91. #define DAC_CTRLB_REFSEL_VREFP_Val _U_(0x2) /**< \brief (DAC_CTRLB) External reference */
  92. #define DAC_CTRLB_REFSEL_INT1V (DAC_CTRLB_REFSEL_INT1V_Val << DAC_CTRLB_REFSEL_Pos)
  93. #define DAC_CTRLB_REFSEL_AVCC (DAC_CTRLB_REFSEL_AVCC_Val << DAC_CTRLB_REFSEL_Pos)
  94. #define DAC_CTRLB_REFSEL_VREFP (DAC_CTRLB_REFSEL_VREFP_Val << DAC_CTRLB_REFSEL_Pos)
  95. #define DAC_CTRLB_MASK _U_(0xDF) /**< \brief (DAC_CTRLB) MASK Register */
  96. /* -------- DAC_EVCTRL : (DAC Offset: 0x2) (R/W 8) Event Control -------- */
  97. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  98. typedef union {
  99. struct {
  100. uint8_t STARTEI:1; /*!< bit: 0 Start Conversion Event Input */
  101. uint8_t EMPTYEO:1; /*!< bit: 1 Data Buffer Empty Event Output */
  102. uint8_t :6; /*!< bit: 2.. 7 Reserved */
  103. } bit; /*!< Structure used for bit access */
  104. uint8_t reg; /*!< Type used for register access */
  105. } DAC_EVCTRL_Type;
  106. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  107. #define DAC_EVCTRL_OFFSET 0x2 /**< \brief (DAC_EVCTRL offset) Event Control */
  108. #define DAC_EVCTRL_RESETVALUE _U_(0x00) /**< \brief (DAC_EVCTRL reset_value) Event Control */
  109. #define DAC_EVCTRL_STARTEI_Pos 0 /**< \brief (DAC_EVCTRL) Start Conversion Event Input */
  110. #define DAC_EVCTRL_STARTEI (_U_(0x1) << DAC_EVCTRL_STARTEI_Pos)
  111. #define DAC_EVCTRL_EMPTYEO_Pos 1 /**< \brief (DAC_EVCTRL) Data Buffer Empty Event Output */
  112. #define DAC_EVCTRL_EMPTYEO (_U_(0x1) << DAC_EVCTRL_EMPTYEO_Pos)
  113. #define DAC_EVCTRL_MASK _U_(0x03) /**< \brief (DAC_EVCTRL) MASK Register */
  114. /* -------- DAC_INTENCLR : (DAC Offset: 0x4) (R/W 8) Interrupt Enable Clear -------- */
  115. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  116. typedef union {
  117. struct {
  118. uint8_t UNDERRUN:1; /*!< bit: 0 Underrun Interrupt Enable */
  119. uint8_t EMPTY:1; /*!< bit: 1 Data Buffer Empty Interrupt Enable */
  120. uint8_t SYNCRDY:1; /*!< bit: 2 Synchronization Ready Interrupt Enable */
  121. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  122. } bit; /*!< Structure used for bit access */
  123. uint8_t reg; /*!< Type used for register access */
  124. } DAC_INTENCLR_Type;
  125. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  126. #define DAC_INTENCLR_OFFSET 0x4 /**< \brief (DAC_INTENCLR offset) Interrupt Enable Clear */
  127. #define DAC_INTENCLR_RESETVALUE _U_(0x00) /**< \brief (DAC_INTENCLR reset_value) Interrupt Enable Clear */
  128. #define DAC_INTENCLR_UNDERRUN_Pos 0 /**< \brief (DAC_INTENCLR) Underrun Interrupt Enable */
  129. #define DAC_INTENCLR_UNDERRUN (_U_(0x1) << DAC_INTENCLR_UNDERRUN_Pos)
  130. #define DAC_INTENCLR_EMPTY_Pos 1 /**< \brief (DAC_INTENCLR) Data Buffer Empty Interrupt Enable */
  131. #define DAC_INTENCLR_EMPTY (_U_(0x1) << DAC_INTENCLR_EMPTY_Pos)
  132. #define DAC_INTENCLR_SYNCRDY_Pos 2 /**< \brief (DAC_INTENCLR) Synchronization Ready Interrupt Enable */
  133. #define DAC_INTENCLR_SYNCRDY (_U_(0x1) << DAC_INTENCLR_SYNCRDY_Pos)
  134. #define DAC_INTENCLR_MASK _U_(0x07) /**< \brief (DAC_INTENCLR) MASK Register */
  135. /* -------- DAC_INTENSET : (DAC Offset: 0x5) (R/W 8) Interrupt Enable Set -------- */
  136. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  137. typedef union {
  138. struct {
  139. uint8_t UNDERRUN:1; /*!< bit: 0 Underrun Interrupt Enable */
  140. uint8_t EMPTY:1; /*!< bit: 1 Data Buffer Empty Interrupt Enable */
  141. uint8_t SYNCRDY:1; /*!< bit: 2 Synchronization Ready Interrupt Enable */
  142. uint8_t :5; /*!< bit: 3.. 7 Reserved */
  143. } bit; /*!< Structure used for bit access */
  144. uint8_t reg; /*!< Type used for register access */
  145. } DAC_INTENSET_Type;
  146. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  147. #define DAC_INTENSET_OFFSET 0x5 /**< \brief (DAC_INTENSET offset) Interrupt Enable Set */
  148. #define DAC_INTENSET_RESETVALUE _U_(0x00) /**< \brief (DAC_INTENSET reset_value) Interrupt Enable Set */
  149. #define DAC_INTENSET_UNDERRUN_Pos 0 /**< \brief (DAC_INTENSET) Underrun Interrupt Enable */
  150. #define DAC_INTENSET_UNDERRUN (_U_(0x1) << DAC_INTENSET_UNDERRUN_Pos)
  151. #define DAC_INTENSET_EMPTY_Pos 1 /**< \brief (DAC_INTENSET) Data Buffer Empty Interrupt Enable */
  152. #define DAC_INTENSET_EMPTY (_U_(0x1) << DAC_INTENSET_EMPTY_Pos)
  153. #define DAC_INTENSET_SYNCRDY_Pos 2 /**< \brief (DAC_INTENSET) Synchronization Ready Interrupt Enable */
  154. #define DAC_INTENSET_SYNCRDY (_U_(0x1) << DAC_INTENSET_SYNCRDY_Pos)
  155. #define DAC_INTENSET_MASK _U_(0x07) /**< \brief (DAC_INTENSET) MASK Register */
  156. /* -------- DAC_INTFLAG : (DAC Offset: 0x6) (R/W 8) Interrupt Flag Status and Clear -------- */
  157. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  158. typedef union { // __I to avoid read-modify-write on write-to-clear register
  159. struct {
  160. __I uint8_t UNDERRUN:1; /*!< bit: 0 Underrun */
  161. __I uint8_t EMPTY:1; /*!< bit: 1 Data Buffer Empty */
  162. __I uint8_t SYNCRDY:1; /*!< bit: 2 Synchronization Ready */
  163. __I uint8_t :5; /*!< bit: 3.. 7 Reserved */
  164. } bit; /*!< Structure used for bit access */
  165. uint8_t reg; /*!< Type used for register access */
  166. } DAC_INTFLAG_Type;
  167. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  168. #define DAC_INTFLAG_OFFSET 0x6 /**< \brief (DAC_INTFLAG offset) Interrupt Flag Status and Clear */
  169. #define DAC_INTFLAG_RESETVALUE _U_(0x00) /**< \brief (DAC_INTFLAG reset_value) Interrupt Flag Status and Clear */
  170. #define DAC_INTFLAG_UNDERRUN_Pos 0 /**< \brief (DAC_INTFLAG) Underrun */
  171. #define DAC_INTFLAG_UNDERRUN (_U_(0x1) << DAC_INTFLAG_UNDERRUN_Pos)
  172. #define DAC_INTFLAG_EMPTY_Pos 1 /**< \brief (DAC_INTFLAG) Data Buffer Empty */
  173. #define DAC_INTFLAG_EMPTY (_U_(0x1) << DAC_INTFLAG_EMPTY_Pos)
  174. #define DAC_INTFLAG_SYNCRDY_Pos 2 /**< \brief (DAC_INTFLAG) Synchronization Ready */
  175. #define DAC_INTFLAG_SYNCRDY (_U_(0x1) << DAC_INTFLAG_SYNCRDY_Pos)
  176. #define DAC_INTFLAG_MASK _U_(0x07) /**< \brief (DAC_INTFLAG) MASK Register */
  177. /* -------- DAC_STATUS : (DAC Offset: 0x7) (R/ 8) Status -------- */
  178. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  179. typedef union {
  180. struct {
  181. uint8_t :7; /*!< bit: 0.. 6 Reserved */
  182. uint8_t SYNCBUSY:1; /*!< bit: 7 Synchronization Busy Status */
  183. } bit; /*!< Structure used for bit access */
  184. uint8_t reg; /*!< Type used for register access */
  185. } DAC_STATUS_Type;
  186. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  187. #define DAC_STATUS_OFFSET 0x7 /**< \brief (DAC_STATUS offset) Status */
  188. #define DAC_STATUS_RESETVALUE _U_(0x00) /**< \brief (DAC_STATUS reset_value) Status */
  189. #define DAC_STATUS_SYNCBUSY_Pos 7 /**< \brief (DAC_STATUS) Synchronization Busy Status */
  190. #define DAC_STATUS_SYNCBUSY (_U_(0x1) << DAC_STATUS_SYNCBUSY_Pos)
  191. #define DAC_STATUS_MASK _U_(0x80) /**< \brief (DAC_STATUS) MASK Register */
  192. /* -------- DAC_DATA : (DAC Offset: 0x8) (R/W 16) Data -------- */
  193. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  194. typedef union {
  195. struct {
  196. uint16_t DATA:16; /*!< bit: 0..15 Data value to be converted */
  197. } bit; /*!< Structure used for bit access */
  198. uint16_t reg; /*!< Type used for register access */
  199. } DAC_DATA_Type;
  200. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  201. #define DAC_DATA_OFFSET 0x8 /**< \brief (DAC_DATA offset) Data */
  202. #define DAC_DATA_RESETVALUE _U_(0x0000) /**< \brief (DAC_DATA reset_value) Data */
  203. #define DAC_DATA_DATA_Pos 0 /**< \brief (DAC_DATA) Data value to be converted */
  204. #define DAC_DATA_DATA_Msk (_U_(0xFFFF) << DAC_DATA_DATA_Pos)
  205. #define DAC_DATA_DATA(value) (DAC_DATA_DATA_Msk & ((value) << DAC_DATA_DATA_Pos))
  206. #define DAC_DATA_MASK _U_(0xFFFF) /**< \brief (DAC_DATA) MASK Register */
  207. /* -------- DAC_DATABUF : (DAC Offset: 0xC) (R/W 16) Data Buffer -------- */
  208. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  209. typedef union {
  210. struct {
  211. uint16_t DATABUF:16; /*!< bit: 0..15 Data Buffer */
  212. } bit; /*!< Structure used for bit access */
  213. uint16_t reg; /*!< Type used for register access */
  214. } DAC_DATABUF_Type;
  215. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  216. #define DAC_DATABUF_OFFSET 0xC /**< \brief (DAC_DATABUF offset) Data Buffer */
  217. #define DAC_DATABUF_RESETVALUE _U_(0x0000) /**< \brief (DAC_DATABUF reset_value) Data Buffer */
  218. #define DAC_DATABUF_DATABUF_Pos 0 /**< \brief (DAC_DATABUF) Data Buffer */
  219. #define DAC_DATABUF_DATABUF_Msk (_U_(0xFFFF) << DAC_DATABUF_DATABUF_Pos)
  220. #define DAC_DATABUF_DATABUF(value) (DAC_DATABUF_DATABUF_Msk & ((value) << DAC_DATABUF_DATABUF_Pos))
  221. #define DAC_DATABUF_MASK _U_(0xFFFF) /**< \brief (DAC_DATABUF) MASK Register */
  222. /** \brief DAC hardware registers */
  223. #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
  224. typedef struct {
  225. __IO DAC_CTRLA_Type CTRLA; /**< \brief Offset: 0x0 (R/W 8) Control A */
  226. __IO DAC_CTRLB_Type CTRLB; /**< \brief Offset: 0x1 (R/W 8) Control B */
  227. __IO DAC_EVCTRL_Type EVCTRL; /**< \brief Offset: 0x2 (R/W 8) Event Control */
  228. RoReg8 Reserved1[0x1];
  229. __IO DAC_INTENCLR_Type INTENCLR; /**< \brief Offset: 0x4 (R/W 8) Interrupt Enable Clear */
  230. __IO DAC_INTENSET_Type INTENSET; /**< \brief Offset: 0x5 (R/W 8) Interrupt Enable Set */
  231. __IO DAC_INTFLAG_Type INTFLAG; /**< \brief Offset: 0x6 (R/W 8) Interrupt Flag Status and Clear */
  232. __I DAC_STATUS_Type STATUS; /**< \brief Offset: 0x7 (R/ 8) Status */
  233. __IO DAC_DATA_Type DATA; /**< \brief Offset: 0x8 (R/W 16) Data */
  234. RoReg8 Reserved2[0x2];
  235. __IO DAC_DATABUF_Type DATABUF; /**< \brief Offset: 0xC (R/W 16) Data Buffer */
  236. } Dac;
  237. #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
  238. /*@}*/
  239. #endif /* _SAMD11_DAC_COMPONENT_ */