gd32f30x_dac.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /*!
  2. \file gd32f30x_dac.c
  3. \brief DAC driver
  4. \version 2023-12-30, V2.2.0, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #include "gd32f30x_dac.h"
  30. /* DAC register bit offset */
  31. #define OUT1_REG_OFFSET ((uint32_t)0x00000010U)
  32. #define DH_12BIT_OFFSET ((uint32_t)0x00000010U)
  33. #define DH_8BIT_OFFSET ((uint32_t)0x00000008U)
  34. /*!
  35. \brief deinitialize DAC
  36. \param[in] dac_periph: DACx(x=0)
  37. \param[out] none
  38. \retval none
  39. */
  40. void dac_deinit(uint32_t dac_periph)
  41. {
  42. switch(dac_periph){
  43. case DAC0:
  44. /* reset DAC0 */
  45. rcu_periph_reset_enable(RCU_DACRST);
  46. rcu_periph_reset_disable(RCU_DACRST);
  47. break;
  48. default:
  49. break;
  50. }
  51. }
  52. /*!
  53. \brief enable DAC
  54. \param[in] dac_periph: DACx(x=0)
  55. \param[in] dac_out: DAC_OUTx(x=0,1)
  56. \param[out] none
  57. \retval none
  58. */
  59. void dac_enable(uint32_t dac_periph, uint8_t dac_out)
  60. {
  61. if(DAC_OUT0 == dac_out){
  62. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DEN0;
  63. }else if(DAC_OUT1 == dac_out){
  64. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DEN1;
  65. }else{
  66. /* illegal parameters */
  67. }
  68. }
  69. /*!
  70. \brief disable DAC
  71. \param[in] dac_periph: DACx(x=0)
  72. \param[in] dac_out: DAC_OUTx(x=0,1)
  73. \param[out] none
  74. \retval none
  75. */
  76. void dac_disable(uint32_t dac_periph, uint8_t dac_out)
  77. {
  78. if(DAC_OUT0 == dac_out){
  79. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DEN0);
  80. }else if(DAC_OUT1 == dac_out){
  81. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DEN1);
  82. }else{
  83. /* illegal parameters */
  84. }
  85. }
  86. /*!
  87. \brief enable DAC DMA function
  88. \param[in] dac_periph: DACx(x=0)
  89. \param[in] dac_out: DAC_OUTx(x=0,1)
  90. \param[out] none
  91. \retval none
  92. */
  93. void dac_dma_enable(uint32_t dac_periph, uint8_t dac_out)
  94. {
  95. if(DAC_OUT0 == dac_out){
  96. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DDMAEN0;
  97. }else if(DAC_OUT1 == dac_out){
  98. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DDMAEN1;
  99. }else{
  100. /* illegal parameters */
  101. }
  102. }
  103. /*!
  104. \brief disable DAC DMA function
  105. \param[in] dac_periph: DACx(x=0)
  106. \param[in] dac_out: DAC_OUTx(x=0,1)
  107. \param[out] none
  108. \retval none
  109. */
  110. void dac_dma_disable(uint32_t dac_periph, uint8_t dac_out)
  111. {
  112. if(DAC_OUT0 == dac_out){
  113. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DDMAEN0);
  114. }else if(DAC_OUT1 == dac_out){
  115. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DDMAEN1);
  116. }else{
  117. /* illegal parameters */
  118. }
  119. }
  120. /*!
  121. \brief enable DAC output buffer
  122. \param[in] dac_periph: DACx(x=0)
  123. \param[in] dac_out: DAC_OUTx(x=0,1)
  124. \param[out] none
  125. \retval none
  126. */
  127. void dac_output_buffer_enable(uint32_t dac_periph, uint8_t dac_out)
  128. {
  129. if(DAC_OUT0 == dac_out){
  130. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DBOFF0);
  131. }else if(DAC_OUT1 == dac_out){
  132. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DBOFF1);
  133. }else{
  134. /* illegal parameters */
  135. }
  136. }
  137. /*!
  138. \brief disable DAC output buffer
  139. \param[in] dac_periph: DACx(x=0)
  140. \param[in] dac_out: DAC_OUTx(x=0,1)
  141. \param[out] none
  142. \retval none
  143. */
  144. void dac_output_buffer_disable(uint32_t dac_periph, uint8_t dac_out)
  145. {
  146. if(DAC_OUT0 == dac_out){
  147. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DBOFF0;
  148. }else if(DAC_OUT1 == dac_out){
  149. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DBOFF1;
  150. }else{
  151. /* illegal parameters */
  152. }
  153. }
  154. /*!
  155. \brief get DAC output value
  156. \param[in] dac_periph: DACx(x=0)
  157. \param[in] dac_out: DAC_OUTx(x=0,1)
  158. \param[out] none
  159. \retval DAC output data: 0~4095
  160. */
  161. uint16_t dac_output_value_get(uint32_t dac_periph, uint8_t dac_out)
  162. {
  163. uint16_t data = 0U;
  164. if(DAC_OUT0 == dac_out){
  165. /* store the DACx_OUT0 output value */
  166. data = (uint16_t)DAC_OUT0_DO(dac_periph);
  167. }else if(DAC_OUT1 == dac_out){
  168. /* store the DACx_OUT1 output value */
  169. data = (uint16_t)DAC_OUT1_DO(dac_periph);
  170. }else{
  171. /* illegal parameters */
  172. }
  173. return data;
  174. }
  175. /*!
  176. \brief set DAC data holding register value
  177. \param[in] dac_periph: DACx(x=0)
  178. \param[in] dac_out: DAC_OUTx(x=0,1)
  179. \param[in] dac_align: DAC data alignment mode
  180. only one parameter can be selected which is shown as below:
  181. \arg DAC_ALIGN_12B_R: 12-bit right-aligned data
  182. \arg DAC_ALIGN_12B_L: 12-bit left-aligned data
  183. \arg DAC_ALIGN_8B_R: 8-bit right-aligned data
  184. \param[in] data: data to be loaded(0~4095)
  185. \param[out] none
  186. \retval none
  187. */
  188. void dac_data_set(uint32_t dac_periph, uint8_t dac_out, uint32_t dac_align, uint16_t data)
  189. {
  190. /* DAC_OUT0 data alignment */
  191. if(DAC_OUT0 == dac_out){
  192. switch(dac_align){
  193. /* 12-bit right-aligned data */
  194. case DAC_ALIGN_12B_R:
  195. DAC_OUT0_R12DH(dac_periph) = data;
  196. break;
  197. /* 12-bit left-aligned data */
  198. case DAC_ALIGN_12B_L:
  199. DAC_OUT0_L12DH(dac_periph) = data;
  200. break;
  201. /* 8-bit right-aligned data */
  202. case DAC_ALIGN_8B_R:
  203. DAC_OUT0_R8DH(dac_periph) = data;
  204. break;
  205. default:
  206. break;
  207. }
  208. }else if(DAC_OUT1 == dac_out){
  209. /* DAC_OUT1 data alignment */
  210. switch(dac_align){
  211. /* 12-bit right-aligned data */
  212. case DAC_ALIGN_12B_R:
  213. DAC_OUT1_R12DH(dac_periph) = data;
  214. break;
  215. /* 12-bit left-aligned data */
  216. case DAC_ALIGN_12B_L:
  217. DAC_OUT1_L12DH(dac_periph) = data;
  218. break;
  219. /* 8-bit right-aligned data */
  220. case DAC_ALIGN_8B_R:
  221. DAC_OUT1_R8DH(dac_periph) = data;
  222. break;
  223. default:
  224. break;
  225. }
  226. }else{
  227. /* illegal parameters */
  228. }
  229. }
  230. /*!
  231. \brief enable DAC trigger
  232. \param[in] dac_periph: DACx(x=0)
  233. \param[in] dac_out: DAC_OUTx(x=0,1)
  234. \param[out] none
  235. \retval none
  236. */
  237. void dac_trigger_enable(uint32_t dac_periph, uint8_t dac_out)
  238. {
  239. if(DAC_OUT0 == dac_out){
  240. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DTEN0;
  241. }else if(DAC_OUT1 == dac_out){
  242. DAC_CTL0(dac_periph) |= (uint32_t)DAC_CTL0_DTEN1;
  243. }else{
  244. /* illegal parameters */
  245. }
  246. }
  247. /*!
  248. \brief disable DAC trigger
  249. \param[in] dac_periph: DACx(x=0)
  250. \param[in] dac_out: DAC_OUTx(x=0,1)
  251. \param[out] none
  252. \retval none
  253. */
  254. void dac_trigger_disable(uint32_t dac_periph, uint8_t dac_out)
  255. {
  256. if(DAC_OUT0 == dac_out){
  257. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DTEN0);
  258. }else if(DAC_OUT1 == dac_out){
  259. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DTEN1);
  260. }else{
  261. /* illegal parameters */
  262. }
  263. }
  264. /*!
  265. \brief configure DAC trigger source
  266. \param[in] dac_periph: DACx(x=0)
  267. \param[in] dac_out: DAC_OUTx(x=0,1)
  268. \param[in] triggersource: external trigger of DAC
  269. only one parameter can be selected which is shown as below:
  270. \arg DAC_TRIGGER_T5_TRGO: TIMER5 TRGO
  271. \arg DAC_TRIGGER_T2_TRGO: TIMER2 TRGO, only for GD32F30X_CL devices
  272. \arg DAC_TRIGGER_T7_TRGO: TIMER7 TRGO, only for GD32F30X_HD, GD32F30X_XD devices
  273. \arg DAC_TRIGGER_T6_TRGO: TIMER6 TRGO
  274. \arg DAC_TRIGGER_T4_TRGO: TIMER4 TRGO
  275. \arg DAC_TRIGGER_T1_TRGO: TIMER1 TRGO
  276. \arg DAC_TRIGGER_T3_TRGO: TIMER3 TRGO
  277. \arg DAC_TRIGGER_EXTI_9: EXTI interrupt line9 event
  278. \arg DAC_TRIGGER_SOFTWARE: software trigger
  279. \param[out] none
  280. \retval none
  281. */
  282. void dac_trigger_source_config(uint32_t dac_periph, uint8_t dac_out, uint32_t triggersource)
  283. {
  284. if(DAC_OUT0 == dac_out){
  285. /* configure DACx_OUT0 trigger source */
  286. DAC_CTL0(dac_periph) &= (uint32_t)(~(DAC_CTL0_DTSEL0));
  287. DAC_CTL0(dac_periph) |= triggersource;
  288. }else if(DAC_OUT1 == dac_out){
  289. /* configure DACx_OUT1 trigger source */
  290. DAC_CTL0(dac_periph) &= (uint32_t)(~(DAC_CTL0_DTSEL1));
  291. DAC_CTL0(dac_periph) |= (triggersource << OUT1_REG_OFFSET);
  292. }else{
  293. /* illegal parameters */
  294. }
  295. }
  296. /*!
  297. \brief enable DAC software trigger
  298. \param[in] dac_periph: DACx(x=0)
  299. \param[in] dac_out: DAC_OUTx(x=0,1)
  300. \retval none
  301. */
  302. void dac_software_trigger_enable(uint32_t dac_periph, uint8_t dac_out)
  303. {
  304. if(DAC_OUT0 == dac_out){
  305. DAC_SWT(dac_periph) |= (uint32_t)DAC_SWT_SWTR0;
  306. }else if(DAC_OUT1 == dac_out){
  307. DAC_SWT(dac_periph) |= (uint32_t)DAC_SWT_SWTR1;
  308. }else{
  309. /* illegal parameters */
  310. }
  311. }
  312. /*!
  313. \brief configure DAC wave mode
  314. \param[in] dac_periph: DACx(x=0)
  315. \param[in] dac_out: DAC_OUTx(x=0,1)
  316. \param[in] wave_mode: DAC wave mode
  317. only one parameter can be selected which is shown as below:
  318. \arg DAC_WAVE_DISABLE: wave mode disable
  319. \arg DAC_WAVE_MODE_LFSR: LFSR noise mode
  320. \arg DAC_WAVE_MODE_TRIANGLE: triangle noise mode
  321. \param[out] none
  322. \retval none
  323. */
  324. void dac_wave_mode_config(uint32_t dac_periph, uint8_t dac_out, uint32_t wave_mode)
  325. {
  326. if(DAC_OUT0 == dac_out){
  327. /* configure DACx_OUT0 wave mode */
  328. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DWM0);
  329. DAC_CTL0(dac_periph) |= wave_mode;
  330. }else if(DAC_OUT1 == dac_out){
  331. /* configure DACx_OUT1 wave mode */
  332. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DWM1);
  333. DAC_CTL0(dac_periph) |= (wave_mode << OUT1_REG_OFFSET);
  334. }else{
  335. /* illegal parameters */
  336. }
  337. }
  338. /*!
  339. \brief configure DAC LFSR noise mode
  340. \param[in] dac_periph: DACx(x=0)
  341. \param[in] dac_out: DAC_OUTx(x=0,1)
  342. \param[in] unmask_bits: LFSR noise unmask bits
  343. only one parameter can be selected which is shown as below:
  344. \arg DAC_LFSR_BIT0: unmask the LFSR bit0
  345. \arg DAC_LFSR_BITS1_0: unmask the LFSR bits[1:0]
  346. \arg DAC_LFSR_BITS2_0: unmask the LFSR bits[2:0]
  347. \arg DAC_LFSR_BITS3_0: unmask the LFSR bits[3:0]
  348. \arg DAC_LFSR_BITS4_0: unmask the LFSR bits[4:0]
  349. \arg DAC_LFSR_BITS5_0: unmask the LFSR bits[5:0]
  350. \arg DAC_LFSR_BITS6_0: unmask the LFSR bits[6:0]
  351. \arg DAC_LFSR_BITS7_0: unmask the LFSR bits[7:0]
  352. \arg DAC_LFSR_BITS8_0: unmask the LFSR bits[8:0]
  353. \arg DAC_LFSR_BITS9_0: unmask the LFSR bits[9:0]
  354. \arg DAC_LFSR_BITS10_0: unmask the LFSR bits[10:0]
  355. \arg DAC_LFSR_BITS11_0: unmask the LFSR bits[11:0]
  356. \param[out] none
  357. \retval none
  358. */
  359. void dac_lfsr_noise_config(uint32_t dac_periph, uint8_t dac_out, uint32_t unmask_bits)
  360. {
  361. if(DAC_OUT0 == dac_out){
  362. /* configure DACx_OUT0 LFSR noise mode */
  363. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DWBW0);
  364. DAC_CTL0(dac_periph) |= unmask_bits;
  365. }else if(DAC_OUT1 == dac_out){
  366. /* configure DACx_OUT1 LFSR noise mode */
  367. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DWBW1);
  368. DAC_CTL0(dac_periph) |= (unmask_bits << OUT1_REG_OFFSET);
  369. }else{
  370. /* illegal parameters */
  371. }
  372. }
  373. /*!
  374. \brief configure DAC triangle noise mode
  375. \param[in] dac_periph: DACx(x=0)
  376. \param[in] dac_out: DAC_OUTx(x=0,1)
  377. \param[in] amplitude: the amplitude of the triangle
  378. only one parameter can be selected which is shown as below:
  379. \arg DAC_TRIANGLE_AMPLITUDE_1: triangle amplitude is 1
  380. \arg DAC_TRIANGLE_AMPLITUDE_3: triangle amplitude is 3
  381. \arg DAC_TRIANGLE_AMPLITUDE_7: triangle amplitude is 7
  382. \arg DAC_TRIANGLE_AMPLITUDE_15: triangle amplitude is 15
  383. \arg DAC_TRIANGLE_AMPLITUDE_31: triangle amplitude is 31
  384. \arg DAC_TRIANGLE_AMPLITUDE_63: triangle amplitude is 63
  385. \arg DAC_TRIANGLE_AMPLITUDE_127: triangle amplitude is 127
  386. \arg DAC_TRIANGLE_AMPLITUDE_255: triangle amplitude is 255
  387. \arg DAC_TRIANGLE_AMPLITUDE_511: triangle amplitude is 511
  388. \arg DAC_TRIANGLE_AMPLITUDE_1023: triangle amplitude is 1023
  389. \arg DAC_TRIANGLE_AMPLITUDE_2047: triangle amplitude is 2047
  390. \arg DAC_TRIANGLE_AMPLITUDE_4095: triangle amplitude is 4095
  391. \param[out] none
  392. \retval none
  393. */
  394. void dac_triangle_noise_config(uint32_t dac_periph, uint8_t dac_out, uint32_t amplitude)
  395. {
  396. if(DAC_OUT0 == dac_out){
  397. /* configure DACx_OUT0 triangle noise mode */
  398. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DWBW0);
  399. DAC_CTL0(dac_periph) |= amplitude;
  400. }else if(DAC_OUT1 == dac_out){
  401. /* configure DACx_OUT1 triangle noise mode */
  402. DAC_CTL0(dac_periph) &= (uint32_t)(~DAC_CTL0_DWBW1);
  403. DAC_CTL0(dac_periph) |= (amplitude << OUT1_REG_OFFSET);
  404. }else{
  405. /* illegal parameters */
  406. }
  407. }
  408. /*!
  409. \brief enable DAC concurrent mode
  410. \param[in] dac_periph: DACx(x=0)
  411. \param[out] none
  412. \retval none
  413. */
  414. void dac_concurrent_enable(uint32_t dac_periph)
  415. {
  416. uint32_t ctl = 0U;
  417. ctl = (uint32_t)(DAC_CTL0_DEN0 | DAC_CTL0_DEN1);
  418. DAC_CTL0(dac_periph) |= (uint32_t)ctl;
  419. }
  420. /*!
  421. \brief disable DAC concurrent mode
  422. \param[in] dac_periph: DACx(x=0)
  423. \param[out] none
  424. \retval none
  425. */
  426. void dac_concurrent_disable(uint32_t dac_periph)
  427. {
  428. uint32_t ctl = 0U;
  429. ctl = (uint32_t)(DAC_CTL0_DEN0 | DAC_CTL0_DEN1);
  430. DAC_CTL0(dac_periph) &= (uint32_t)(~ctl);
  431. }
  432. /*!
  433. \brief enable DAC concurrent software trigger
  434. \param[in] dac_periph: DACx(x=0)
  435. \param[out] none
  436. \retval none
  437. */
  438. void dac_concurrent_software_trigger_enable(uint32_t dac_periph)
  439. {
  440. uint32_t swt = 0U;
  441. swt = (uint32_t)(DAC_SWT_SWTR0 | DAC_SWT_SWTR1);
  442. DAC_SWT(dac_periph) |= (uint32_t)swt;
  443. }
  444. /*!
  445. \brief enable DAC concurrent buffer function
  446. \param[in] dac_periph: DACx(x=0)
  447. \param[out] none
  448. \retval none
  449. */
  450. void dac_concurrent_output_buffer_enable(uint32_t dac_periph)
  451. {
  452. uint32_t ctl = 0U;
  453. ctl = (uint32_t)(DAC_CTL0_DBOFF0 | DAC_CTL0_DBOFF1);
  454. DAC_CTL0(dac_periph) &= (uint32_t)(~ctl);
  455. }
  456. /*!
  457. \brief disable DAC concurrent buffer function
  458. \param[in] dac_periph: DACx(x=0)
  459. \param[out] none
  460. \retval none
  461. */
  462. void dac_concurrent_output_buffer_disable(uint32_t dac_periph)
  463. {
  464. uint32_t ctl = 0U;
  465. ctl = (uint32_t)(DAC_CTL0_DBOFF0 | DAC_CTL0_DBOFF1);
  466. DAC_CTL0(dac_periph) |= (uint32_t)ctl;
  467. }
  468. /*!
  469. \brief set DAC concurrent mode data holding register value
  470. \param[in] dac_periph: DACx(x=0)
  471. \param[in] dac_align: DAC data alignment mode
  472. only one parameter can be selected which is shown as below:
  473. \arg DAC_ALIGN_12B_R: 12-bit right-aligned data
  474. \arg DAC_ALIGN_12B_L: 12-bit left-aligned data
  475. \arg DAC_ALIGN_8B_R: 8-bit right-aligned data
  476. \param[in] data0: data to be loaded(0~4095)
  477. \param[in] data1: data to be loaded(0~4095)
  478. \param[out] none
  479. \retval none
  480. */
  481. void dac_concurrent_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data0, uint16_t data1)
  482. {
  483. uint32_t data = 0U;
  484. switch(dac_align){
  485. /* 12-bit right-aligned data */
  486. case DAC_ALIGN_12B_R:
  487. data = (uint32_t)(((uint32_t)data1 << DH_12BIT_OFFSET) | data0);
  488. DACC_R12DH(dac_periph) = (uint32_t)data;
  489. break;
  490. /* 12-bit left-aligned data */
  491. case DAC_ALIGN_12B_L:
  492. data = (uint32_t)(((uint32_t)data1 << DH_12BIT_OFFSET) | data0);
  493. DACC_L12DH(dac_periph) = (uint32_t)data;
  494. break;
  495. /* 8-bit right-aligned data */
  496. case DAC_ALIGN_8B_R:
  497. data = (uint32_t)(((uint32_t)data1 << DH_8BIT_OFFSET) | data0);
  498. DACC_R8DH(dac_periph) = (uint32_t)data;
  499. break;
  500. default:
  501. break;
  502. }
  503. }