libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
dac_common_all.h
Go to the documentation of this file.
1/** @addtogroup dac_defines
2
3@author @htmlonly © @endhtmlonly 2012
4Felix Held <felix-libopencm3@felixheld.de>
5@author @htmlonly &copy; @endhtmlonly 2020
6Ben Brewer <ben.brewer@codethink.co.uk>
7
8*/
9
10/*
11 * This file is part of the libopencm3 project.
12 *
13 * Copyright (C) 2012 Felix Held <felix-libopencm3@felixheld.de>
14 * Copyright (C) 2020 Ben Brewer <ben.brewer@codethink.co.uk>
15 *
16 * This library is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Lesser General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30/**@{*/
31
32/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA DAC.H
33The order of header inclusion is important. dac.h includes the device
34specific memorymap.h header before including this header file.*/
35
36/** @cond */
37#ifdef LIBOPENCM3_DAC_H
38/** @endcond */
39#ifndef LIBOPENCM3_DAC_COMMON_ALL_H
40#define LIBOPENCM3_DAC_COMMON_ALL_H
41
42/**@defgroup dac_registers DAC Registers
43 @{*/
44
45/** DAC control register (DAC_CR) */
46#define DAC_CR(dac) MMIO32((dac) + 0x00)
47
48/** DAC software trigger register (DAC_SWTRIGR) */
49#define DAC_SWTRIGR(dac) MMIO32((dac) + 0x04)
50
51/** DAC channel1 12-bit right-aligned data holding register (DAC_DHR12R1) */
52#define DAC_DHR12R1(dac) MMIO32((dac) + 0x08)
53
54/** DAC channel1 12-bit left aligned data holding register (DAC_DHR12L1) */
55#define DAC_DHR12L1(dac) MMIO32((dac) + 0x0C)
56
57/** DAC channel1 8-bit right aligned data holding register (DAC_DHR8R1) */
58#define DAC_DHR8R1(dac) MMIO32((dac) + 0x10)
59
60/** DAC channel2 12-bit right aligned data holding register (DAC_DHR12R2) */
61#define DAC_DHR12R2(dac) MMIO32((dac) + 0x14)
62
63/** DAC channel2 12-bit left aligned data holding register (DAC_DHR12L2) */
64#define DAC_DHR12L2(dac) MMIO32((dac) + 0x18)
65
66/** DAC channel2 8-bit right-aligned data holding register (DAC_DHR8R2) */
67#define DAC_DHR8R2(dac) MMIO32((dac) + 0x1C)
68
69/** Dual DAC 12-bit right-aligned data holding register (DAC_DHR12RD) */
70#define DAC_DHR12RD(dac) MMIO32((dac) + 0x20)
71
72/** DUAL DAC 12-bit left aligned data holding register (DAC_DHR12LD) */
73#define DAC_DHR12LD(dac) MMIO32((dac) + 0x24)
74
75/** DUAL DAC 8-bit right aligned data holding register (DAC_DHR8RD) */
76#define DAC_DHR8RD(dac) MMIO32((dac) + 0x28)
77
78/** DAC channel1 data output register (DAC_DOR1) */
79#define DAC_DOR1(dac) MMIO32((dac) + 0x2C)
80
81/** DAC channel2 data output register (DAC_DOR2) */
82#define DAC_DOR2(dac) MMIO32((dac) + 0x30)
83
84/** DAC status register.
85 * @note not available on F1
86 */
87#define DAC_SR(dac) MMIO32((dac) + 0x34)
88
89/**@}*/
90
91/** @defgroup dac_cr_values DAC_CR values
92 * @{
93 */
94
95/** DMAUDRIE2: DAC channel2 DMA underrun interrupt enable
96 * @note doesn't exist in most members of the STM32F1 family
97 */
98#define DAC_CR_DMAUDRIE2 (1 << 29)
99
100/** DMAEN2: DAC channel2 DMA enable */
101#define DAC_CR_DMAEN2 (1 << 28)
102
103/** MAMP2[3:0]: DAC channel2 mask/amplitude selector field position */
104#define DAC_CR_MAMP2_SHIFT 24
105
106/** Wave generation mode mask size */
107#define DAC_CR_WAVEx_MASK 0x3
108
109/** WAVE2[1:0]: DAC channel2 wave generation mode*/
110#define DAC_CR_WAVE2_SHIFT 22
111
112/** EN2: DAC channel2 enable */
113#define DAC_CR_EN2 (1 << 16)
114
115/** DMAUDRIE1: DAC channel1 DMA underrun interrupt enable
116 * @note doesn't exist in most members of the STM32F1 family
117 */
118#define DAC_CR_DMAUDRIE1 (1 << 13)
119
120/** DMAEN1: DAC channel1 DMA enable */
121#define DAC_CR_DMAEN1 (1 << 12)
122
123/** MAMP1[3:0]: DAC channel1 mask/amplitude selector field position */
124#define DAC_CR_MAMP1_SHIFT 8
125/** MAMP Mask/Amplitude selector field size */
126#define DAC_CR_MAMPx_MASK 0xf
127
128/** WAVE1[1:0]: DAC channel1 wave generation mode */
129#define DAC_CR_WAVE1_SHIFT 6
130
131/** EN1: DAC channel1 enable */
132#define DAC_CR_EN1 (1 << 0)
133/**@}*/
134
135/**@defgroup dac_swtrigr_values DAC_SWTRIGR Values
136 * @{
137 */
138/** SWTRIG2: DAC channel2 software trigger */
139#define DAC_SWTRIGR_SWTRIG2 (1 << 1)
140
141/** SWTRIG1: DAC channel1 software trigger */
142#define DAC_SWTRIGR_SWTRIG1 (1 << 0)
143/**@}*/
144
145
146/**@defgroup dac_dhrxxx_values DAC_DHRxxx Values
147 * @{
148 */
149/* --- DAC_DHR12R1 values -------------------------------------------------- */
150#define DAC_DHR12R1_DACC1DHR_SHIFT 0
151#define DAC_DHR12R1_DACC1DHR_MASK 0xFFF
152
153
154/* --- DAC_DHR12L1 values -------------------------------------------------- */
155#define DAC_DHR12L1_DACC1DHR_SHIFT 4
156#define DAC_DHR12L1_DACC1DHR_MASK 0xFFF
157
158
159/* --- DAC_DHR8R1 values --------------------------------------------------- */
160#define DAC_DHR8R1_DACC1DHR_SHIFT 0
161#define DAC_DHR8R1_DACC1DHR_MASK 0xFF
162
163
164/* --- DAC_DHR12R2 values -------------------------------------------------- */
165#define DAC_DHR12R2_DACC2DHR_SHIFT 0
166#define DAC_DHR12R2_DACC2DHR_MASK 0xFFF
167
168
169/* --- DAC_DHR12L2 values -------------------------------------------------- */
170#define DAC_DHR12L2_DACC2DHR_SHIFT 4
171#define DAC_DHR12L2_DACC2DHR_MASK 0xFFF
172
173
174/* --- DAC_DHR8R2 values --------------------------------------------------- */
175#define DAC_DHR8R2_DACC2DHR_SHIFT 0
176#define DAC_DHR8R2_DACC2DHR_MASK 0xFF
177
178
179/* --- DAC_DHR12RD values -------------------------------------------------- */
180#define DAC_DHR12RD_DACC2DHR_SHIFT 16
181#define DAC_DHR12RD_DACC2DHR_MASK 0xFFF
182#define DAC_DHR12RD_DACC1DHR_SHIFT 0
183#define DAC_DHR12RD_DACC1DHR_MSK 0xFFF
184
185
186/* --- DAC_DHR12LD values -------------------------------------------------- */
187#define DAC_DHR12LD_DACC2DHR_SHIFT 16
188#define DAC_DHR12LD_DACC2DHR_MSK 0xFFF
189#define DAC_DHR12LD_DACC1DHR_SHIFT 0
190#define DAC_DHR12LD_DACC1DHR_MSK 0xFFF
191
192
193/* --- DAC_DHR8RD values --------------------------------------------------- */
194#define DAC_DHR8RD_DACC2DHR_SHIFT 8
195#define DAC_DHR8RD_DACC2DHR_MSK 0xFF
196#define DAC_DHR8RD_DACC1DHR_SHIFT 0
197#define DAC_DHR8RD_DACC1DHR_MSK 0xFF
198/**@}*/
199
200
201/**@defgroup dac_dorx_values DAC_DORx Values
202 * @{
203 */
204/* --- DAC_DOR1 values ----------------------------------------------------- */
205#define DAC_DOR1_DACC1DOR_SHIFT 0
206#define DAC_DOR1_DACC1DOR_MSK 0xFFF
207
208
209/* --- DAC_DOR2 values ----------------------------------------------------- */
210#define DAC_DOR2_DACC2DOR_SHIFT 0
211#define DAC_DOR2_DACC2DOR_MSK 0xFFF
212
213/**@}*/
214
215/**@defgroup dac_sr_values DAC_SR Values
216 * @{
217 */
218/** DAC channel 1 DMA underrun flag */
219#define DAC_SR_DMAUDR1 (1 << 13)
220
221/** DAC channel 2 DMA underrun flag */
222#define DAC_SR_DMAUDR2 (1 << 29)
223/**@}*/
224
225/* --- Function prototypes ------------------------------------------------- */
226
227/** @defgroup dac_channel_id DAC Channel Identifier
228 * @note Not all parts have two channels, notably, some of the smaller F0's
229 * @{
230 */
231#define DAC_CHANNEL1 (1 << 0)
232#define DAC_CHANNEL2 (1 << 1)
233#define DAC_CHANNEL_BOTH (DAC_CHANNEL1 | DAC_CHANNEL2)
234/**@}*/
235
236/** DAC data size (8/12 bits), alignment (right/left) */
241};
242
243/** DAC waveform generation options.
244 * Not all wave shapes are available on all parts.
245 */
251};
252
254
255void dac_enable(uint32_t dac, int channel);
256void dac_disable(uint32_t dac, int channel);
257void dac_buffer_enable(uint32_t dac, int channel);
258void dac_buffer_disable(uint32_t dac, int channel);
259void dac_dma_enable(uint32_t dac, int channel);
260void dac_dma_disable(uint32_t dac, int channel);
261void dac_trigger_enable(uint32_t dac, int channel);
262void dac_trigger_disable(uint32_t dac, int channel);
263void dac_set_trigger_source(uint32_t dac, uint32_t source);
264void dac_set_waveform_generation(uint32_t dac, int channel, enum dac_wave wave);
265void dac_disable_waveform_generation(uint32_t dac, int channel);
266void dac_set_waveform_characteristics(uint32_t dac, int channel, int mamp);
267void dac_load_data_buffer_single(uint32_t dac, uint16_t data,
268 enum dac_align align, int channel);
269void dac_load_data_buffer_dual(uint32_t dac, uint16_t data1, uint16_t data2,
270 enum dac_align align);
271void dac_software_trigger(uint32_t dac, int channel);
272
274
275#endif
276/** @cond */
277#else
278#warning "dac_common_all.h should not be included explicitly, only via dac.h"
279#endif
280/** @endcond */
281
282/**@}*/
283
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void dac_disable_waveform_generation(uint32_t dac, int channel)
Disable DAC Channel Waveform Generation.
void dac_set_waveform_characteristics(uint32_t dac, int channel, int mamp)
Set DAC Channel LFSR Mask or Triangle Wave Amplitude.
void dac_set_trigger_source(uint32_t dac, uint32_t source)
Set DAC Channel Trigger Source.
void dac_set_waveform_generation(uint32_t dac, int channel, enum dac_wave wave)
Set DAC Channel Waveform Generation mode for one or both channels.
void dac_trigger_enable(uint32_t dac, int channel)
DAC Channel Trigger Enable.
void dac_load_data_buffer_single(uint32_t dac, uint16_t data, enum dac_align align, int channel)
Load DAC Data Register.
void dac_software_trigger(uint32_t dac, int channel)
Trigger the DAC by a Software Trigger.
void dac_buffer_disable(uint32_t dac, int channel)
DAC Channel Output Buffer Disable.
Definition: dac_common_v1.c:66
void dac_buffer_enable(uint32_t dac, int channel)
DAC Channel Output Buffer Enable.
Definition: dac_common_v1.c:42
void dac_disable(uint32_t dac, int channel)
DAC Channel Disable.
void dac_dma_enable(uint32_t dac, int channel)
DAC Channel DMA Enable.
void dac_load_data_buffer_dual(uint32_t dac, uint16_t data1, uint16_t data2, enum dac_align align)
Load DAC Dual Data Register.
dac_align
DAC data size (8/12 bits), alignment (right/left)
void dac_enable(uint32_t dac, int channel)
DAC Channel Enable.
void dac_trigger_disable(uint32_t dac, int channel)
DAC Channel Trigger Disable.
void dac_dma_disable(uint32_t dac, int channel)
DAC Channel DMA Disable.
dac_wave
DAC waveform generation options.
@ DAC_ALIGN_LEFT12
@ DAC_ALIGN_RIGHT12
@ DAC_ALIGN_RIGHT8
@ DAC_WAVE_DISABLE
@ DAC_WAVE_TRIANGLE
@ DAC_WAVE_SAWTOOTH
@ DAC_WAVE_NOISE