Subversion Repositories DashDisplay

Rev

Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61 Rev 77
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_dac_ex.c
3
  * @file    stm32l1xx_hal_dac_ex.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   Extended DAC HAL module driver.
5
  * @brief   Extended DAC HAL module driver.
6
  *          This file provides firmware functions to manage the extended
6
  *          This file provides firmware functions to manage the extended
7
  *          functionalities of the DAC peripheral.
7
  *          functionalities of the DAC peripheral.
8
  *
8
  *
9
  *
9
  *
10
  @verbatim
10
  ******************************************************************************
11
  ==============================================================================
11
  * @attention
12
                      ##### How to use this driver #####
12
  *
13
  ==============================================================================
13
  * Copyright (c) 2016 STMicroelectronics.
14
    [..]
14
  * All rights reserved.
15
 
15
  *
16
     *** Dual mode IO operation ***
16
  * This software is licensed under terms that can be found in the LICENSE file
17
     ==============================
17
  * in the root directory of this software component.
18
     [..]
18
  * If no LICENSE file comes with this software, it is provided AS-IS.
19
      (+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) :
19
  *
20
          Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
20
  ******************************************************************************
21
          HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in
21
  @verbatim
22
          Channel 1 and Channel 2.
22
  ==============================================================================
23
 
23
                      ##### How to use this driver #####
24
     *** Signal generation operation ***
24
  ==============================================================================
25
     ===================================
25
    [..]
26
     [..]
26
     *** Signal generation operation ***
27
      (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
27
     ===================================
28
      (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
28
     [..]
29
 
29
      (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
30
 @endverbatim
30
      (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
31
  ******************************************************************************
31
 
32
  * @attention
32
 @endverbatim
33
  *
33
  ******************************************************************************
34
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
34
  */
35
  * All rights reserved.</center></h2>
35
 
36
  *
36
 
37
  * This software component is licensed by ST under BSD 3-Clause license,
37
/* Includes ------------------------------------------------------------------*/
38
  * the "License"; You may not use this file except in compliance with the
38
#include "stm32l1xx_hal.h"
39
  * License. You may obtain a copy of the License at:
39
 
40
  *                        opensource.org/licenses/BSD-3-Clause
40
/** @addtogroup STM32L1xx_HAL_Driver
41
  *
41
  * @{
42
  ******************************************************************************
42
  */
43
  */
43
 
44
 
44
#ifdef HAL_DAC_MODULE_ENABLED
45
 
45
 
46
/* Includes ------------------------------------------------------------------*/
46
#if defined(DAC1)
47
#include "stm32l1xx_hal.h"
47
 
48
 
48
/** @defgroup DACEx DACEx
49
/** @addtogroup STM32L1xx_HAL_Driver
49
  * @brief DAC Extended HAL module driver
50
  * @{
50
  * @{
51
  */
51
  */
52
 
52
 
53
#ifdef HAL_DAC_MODULE_ENABLED
53
/* Private typedef -----------------------------------------------------------*/
54
 
54
/* Private define ------------------------------------------------------------*/
55
#if defined(DAC1)
55
 
56
 
56
/* Private macro -------------------------------------------------------------*/
57
/** @defgroup DACEx DACEx
57
/* Private variables ---------------------------------------------------------*/
58
  * @brief DAC Extended HAL module driver
58
/* Private function prototypes -----------------------------------------------*/
59
  * @{
59
/* Exported functions --------------------------------------------------------*/
60
  */
60
 
61
 
61
/** @defgroup DACEx_Exported_Functions DACEx Exported Functions
62
/* Private typedef -----------------------------------------------------------*/
62
  * @{
63
/* Private define ------------------------------------------------------------*/
63
  */
64
/* Private macro -------------------------------------------------------------*/
64
 
65
/* Private variables ---------------------------------------------------------*/
65
/** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
66
/* Private function prototypes -----------------------------------------------*/
66
  *  @brief    Extended IO operation functions
67
/* Exported functions --------------------------------------------------------*/
67
  *
68
 
68
@verbatim
69
/** @defgroup DACEx_Exported_Functions DACEx Exported Functions
69
  ==============================================================================
70
  * @{
70
                 ##### Extended features functions #####
71
  */
71
  ==============================================================================
72
 
72
    [..]  This section provides functions allowing to:
73
/** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
73
      (+) Start conversion.
74
  *  @brief    Extended IO operation functions
74
      (+) Stop conversion.
75
  *
75
      (+) Start conversion and enable DMA transfer.
76
@verbatim
76
      (+) Stop conversion and disable DMA transfer.
77
  ==============================================================================
77
      (+) Get result of conversion.
78
                 ##### Extended features functions #####
78
      (+) Get result of dual mode conversion.
79
  ==============================================================================
79
 
80
    [..]  This section provides functions allowing to:
80
@endverbatim
81
      (+) Start conversion.
81
  * @{
82
      (+) Stop conversion.
82
  */
83
      (+) Start conversion and enable DMA transfer.
83
 
84
      (+) Stop conversion and disable DMA transfer.
84
 
85
      (+) Get result of conversion.
85
/**
86
      (+) Get result of dual mode conversion.
86
  * @brief  Enables DAC and starts conversion of both channels.
87
 
87
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
88
@endverbatim
88
  *         the configuration information for the specified DAC.
89
  * @{
89
  * @retval HAL status
90
  */
90
  */
91
 
91
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac)
92
 
92
{
93
/**
93
  uint32_t tmp_swtrig = 0UL;
94
  * @brief  Enables DAC and starts conversion of both channels.
94
 
95
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
95
  /* Check the DAC peripheral handle */
96
  *         the configuration information for the specified DAC.
96
  if (hdac == NULL)
97
  * @retval HAL status
97
  {
98
  */
98
    return HAL_ERROR;
99
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac)
99
  }
100
{
100
 
101
  uint32_t tmp_swtrig = 0UL;
101
 
102
 
102
  /* Process locked */
103
 
103
  __HAL_LOCK(hdac);
104
  /* Process locked */
104
 
105
  __HAL_LOCK(hdac);
105
  /* Change DAC state */
106
 
106
  hdac->State = HAL_DAC_STATE_BUSY;
107
  /* Change DAC state */
107
 
108
  hdac->State = HAL_DAC_STATE_BUSY;
108
  /* Enable the Peripheral */
109
 
109
  __HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1);
110
  /* Enable the Peripheral */
110
  __HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2);
111
  __HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1);
111
 
112
  __HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2);
112
  /* Check if software trigger enabled */
113
 
113
  if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE)
114
  /* Check if software trigger enabled */
114
  {
115
  if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE)
115
    tmp_swtrig |= DAC_SWTRIGR_SWTRIG1;
116
  {
116
  }
117
    tmp_swtrig |= DAC_SWTRIGR_SWTRIG1;
117
  if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL)))
118
  }
118
  {
119
  if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL)))
119
    tmp_swtrig |= DAC_SWTRIGR_SWTRIG2;
120
  {
120
  }
121
    tmp_swtrig |= DAC_SWTRIGR_SWTRIG2;
121
  /* Enable the selected DAC software conversion*/
122
  }
122
  SET_BIT(hdac->Instance->SWTRIGR, tmp_swtrig);
123
  /* Enable the selected DAC software conversion*/
123
 
124
  SET_BIT(hdac->Instance->SWTRIGR, tmp_swtrig);
124
  /* Change DAC state */
125
 
125
  hdac->State = HAL_DAC_STATE_READY;
126
  /* Change DAC state */
126
 
127
  hdac->State = HAL_DAC_STATE_READY;
127
  /* Process unlocked */
128
 
128
  __HAL_UNLOCK(hdac);
129
  /* Process unlocked */
129
 
130
  __HAL_UNLOCK(hdac);
130
  /* Return function status */
131
 
131
  return HAL_OK;
132
  /* Return function status */
132
}
133
  return HAL_OK;
133
 
134
}
134
/**
135
 
135
  * @brief  Disables DAC and stop conversion of both channels.
136
/**
136
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
137
  * @brief  Disables DAC and stop conversion of both channels.
137
  *         the configuration information for the specified DAC.
138
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
138
  * @retval HAL status
139
  *         the configuration information for the specified DAC.
139
  */
140
  * @retval HAL status
140
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac)
141
  */
141
{
142
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac)
142
  /* Check the DAC peripheral handle */
143
{
143
  if (hdac == NULL)
144
 
144
  {
145
  /* Disable the Peripheral */
145
    return HAL_ERROR;
146
  __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1);
146
  }
147
  __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
147
 
148
 
148
 
149
  /* Change DAC state */
149
  /* Disable the Peripheral */
150
  hdac->State = HAL_DAC_STATE_READY;
150
  __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1);
151
 
151
  __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
152
  /* Return function status */
152
 
153
  return HAL_OK;
153
  /* Change DAC state */
154
}
154
  hdac->State = HAL_DAC_STATE_READY;
155
 
155
 
156
 
156
  /* Return function status */
157
/**
157
  return HAL_OK;
158
  * @brief  Enable or disable the selected DAC channel wave generation.
158
}
159
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
159
 
160
  *         the configuration information for the specified DAC.
160
 
161
  * @param  Channel The selected DAC channel.
161
/**
162
  *          This parameter can be one of the following values:
162
  * @brief  Enable or disable the selected DAC channel wave generation.
163
  *            @arg DAC_CHANNEL_1: DAC Channel1 selected
163
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
164
  *            @arg DAC_CHANNEL_2: DAC Channel2 selected
164
  *         the configuration information for the specified DAC.
165
  * @param  Amplitude Select max triangle amplitude.
165
  * @param  Channel The selected DAC channel.
166
  *          This parameter can be one of the following values:
166
  *          This parameter can be one of the following values:
167
  *            @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
167
  *            @arg DAC_CHANNEL_1: DAC Channel1 selected
168
  *            @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
168
  *            @arg DAC_CHANNEL_2: DAC Channel2 selected
169
  *            @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
169
  * @param  Amplitude Select max triangle amplitude.
170
  *            @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
170
  *          This parameter can be one of the following values:
171
  *            @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
171
  *            @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
172
  *            @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
172
  *            @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
173
  *            @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
173
  *            @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
174
  *            @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
174
  *            @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
175
  *            @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
175
  *            @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
176
  *            @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
176
  *            @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
177
  *            @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
177
  *            @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
178
  *            @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
178
  *            @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
179
  * @retval HAL status
179
  *            @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
180
  */
180
  *            @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
181
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
181
  *            @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
182
{
182
  *            @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
183
  /* Check the parameters */
183
  * @retval HAL status
184
  assert_param(IS_DAC_CHANNEL(Channel));
184
  */
185
  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
185
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
186
 
186
{
187
  /* Process locked */
187
  /* Check the DAC peripheral handle */
188
  __HAL_LOCK(hdac);
188
  if (hdac == NULL)
189
 
189
  {
190
  /* Change DAC state */
190
    return HAL_ERROR;
191
  hdac->State = HAL_DAC_STATE_BUSY;
191
  }
192
 
192
 
193
  /* Enable the triangle wave generation for the selected DAC channel */
193
  /* Check the parameters */
194
  MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
194
  assert_param(IS_DAC_CHANNEL(Channel));
195
             (DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
195
  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
196
 
196
 
197
  /* Change DAC state */
197
  /* Process locked */
198
  hdac->State = HAL_DAC_STATE_READY;
198
  __HAL_LOCK(hdac);
199
 
199
 
200
  /* Process unlocked */
200
  /* Change DAC state */
201
  __HAL_UNLOCK(hdac);
201
  hdac->State = HAL_DAC_STATE_BUSY;
202
 
202
 
203
  /* Return function status */
203
  /* Enable the triangle wave generation for the selected DAC channel */
204
  return HAL_OK;
204
  MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
205
}
205
             (DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
206
 
206
 
207
/**
207
  /* Change DAC state */
208
  * @brief  Enable or disable the selected DAC channel wave generation.
208
  hdac->State = HAL_DAC_STATE_READY;
209
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
209
 
210
  *         the configuration information for the specified DAC.
210
  /* Process unlocked */
211
  * @param  Channel The selected DAC channel.
211
  __HAL_UNLOCK(hdac);
212
  *          This parameter can be one of the following values:
212
 
213
  *            @arg DAC_CHANNEL_1: DAC Channel1 selected
213
  /* Return function status */
214
  *            @arg DAC_CHANNEL_2: DAC Channel2 selected
214
  return HAL_OK;
215
  * @param  Amplitude Unmask DAC channel LFSR for noise wave generation.
215
}
216
  *          This parameter can be one of the following values:
216
 
217
  *            @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
217
/**
218
  *            @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
218
  * @brief  Enable or disable the selected DAC channel wave generation.
219
  *            @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
219
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
220
  *            @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
220
  *         the configuration information for the specified DAC.
221
  *            @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
221
  * @param  Channel The selected DAC channel.
222
  *            @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
222
  *          This parameter can be one of the following values:
223
  *            @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
223
  *            @arg DAC_CHANNEL_1: DAC Channel1 selected
224
  *            @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
224
  *            @arg DAC_CHANNEL_2: DAC Channel2 selected
225
  *            @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
225
  * @param  Amplitude Unmask DAC channel LFSR for noise wave generation.
226
  *            @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
226
  *          This parameter can be one of the following values:
227
  *            @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
227
  *            @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
228
  *            @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
228
  *            @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
229
  * @retval HAL status
229
  *            @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
230
  */
230
  *            @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
231
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
231
  *            @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
232
{
232
  *            @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
233
  /* Check the parameters */
233
  *            @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
234
  assert_param(IS_DAC_CHANNEL(Channel));
234
  *            @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
235
  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
235
  *            @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
236
 
236
  *            @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
237
  /* Process locked */
237
  *            @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
238
  __HAL_LOCK(hdac);
238
  *            @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
239
 
239
  * @retval HAL status
240
  /* Change DAC state */
240
  */
241
  hdac->State = HAL_DAC_STATE_BUSY;
241
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
242
 
242
{
243
  /* Enable the noise wave generation for the selected DAC channel */
243
  /* Check the DAC peripheral handle */
244
  MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
244
  if (hdac == NULL)
245
             (DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
245
  {
246
 
246
    return HAL_ERROR;
247
  /* Change DAC state */
247
  }
248
  hdac->State = HAL_DAC_STATE_READY;
248
 
249
 
249
  /* Check the parameters */
250
  /* Process unlocked */
250
  assert_param(IS_DAC_CHANNEL(Channel));
251
  __HAL_UNLOCK(hdac);
251
  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
252
 
252
 
253
  /* Return function status */
253
  /* Process locked */
254
  return HAL_OK;
254
  __HAL_LOCK(hdac);
255
}
255
 
256
 
256
  /* Change DAC state */
257
 
257
  hdac->State = HAL_DAC_STATE_BUSY;
258
/**
258
 
259
  * @brief  Set the specified data holding register value for dual DAC channel.
259
  /* Enable the noise wave generation for the selected DAC channel */
260
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
260
  MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
261
  *               the configuration information for the specified DAC.
261
             (DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
262
  * @param  Alignment Specifies the data alignment for dual channel DAC.
262
 
263
  *          This parameter can be one of the following values:
263
  /* Change DAC state */
264
  *            DAC_ALIGN_8B_R: 8bit right data alignment selected
264
  hdac->State = HAL_DAC_STATE_READY;
265
  *            DAC_ALIGN_12B_L: 12bit left data alignment selected
265
 
266
  *            DAC_ALIGN_12B_R: 12bit right data alignment selected
266
  /* Process unlocked */
267
  * @param  Data1 Data for DAC Channel1 to be loaded in the selected data holding register.
267
  __HAL_UNLOCK(hdac);
268
  * @param  Data2 Data for DAC Channel2 to be loaded in the selected data  holding register.
268
 
269
  * @note   In dual mode, a unique register access is required to write in both
269
  /* Return function status */
270
  *          DAC channels at the same time.
270
  return HAL_OK;
271
  * @retval HAL status
271
}
272
  */
272
 
273
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
273
 
274
{
274
/**
275
  uint32_t data;
275
  * @brief  Set the specified data holding register value for dual DAC channel.
276
  uint32_t tmp;
276
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
277
 
277
  *               the configuration information for the specified DAC.
278
  /* Check the parameters */
278
  * @param  Alignment Specifies the data alignment for dual channel DAC.
279
  assert_param(IS_DAC_ALIGN(Alignment));
279
  *          This parameter can be one of the following values:
280
  assert_param(IS_DAC_DATA(Data1));
280
  *            DAC_ALIGN_8B_R: 8bit right data alignment selected
281
  assert_param(IS_DAC_DATA(Data2));
281
  *            DAC_ALIGN_12B_L: 12bit left data alignment selected
282
 
282
  *            DAC_ALIGN_12B_R: 12bit right data alignment selected
283
  /* Calculate and set dual DAC data holding register value */
283
  * @param  Data1 Data for DAC Channel1 to be loaded in the selected data holding register.
284
  if (Alignment == DAC_ALIGN_8B_R)
284
  * @param  Data2 Data for DAC Channel2 to be loaded in the selected data  holding register.
285
  {
285
  * @note   In dual mode, a unique register access is required to write in both
286
    data = ((uint32_t)Data2 << 8U) | Data1;
286
  *          DAC channels at the same time.
287
  }
287
  * @retval HAL status
288
  else
288
  */
289
  {
289
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
290
    data = ((uint32_t)Data2 << 16U) | Data1;
290
{
291
  }
291
  uint32_t data;
292
 
292
  uint32_t tmp;
293
  tmp = (uint32_t)hdac->Instance;
293
 
294
  tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
294
  /* Check the DAC peripheral handle */
295
 
295
  if (hdac == NULL)
296
  /* Set the dual DAC selected data holding register */
296
  {
297
  *(__IO uint32_t *)tmp = data;
297
    return HAL_ERROR;
298
 
298
  }
299
  /* Return function status */
299
 
300
  return HAL_OK;
300
  /* Check the parameters */
301
}
301
  assert_param(IS_DAC_ALIGN(Alignment));
302
 
302
  assert_param(IS_DAC_DATA(Data1));
303
/**
303
  assert_param(IS_DAC_DATA(Data2));
304
  * @brief  Conversion complete callback in non-blocking mode for Channel2.
304
 
305
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
305
  /* Calculate and set dual DAC data holding register value */
306
  *         the configuration information for the specified DAC.
306
  if (Alignment == DAC_ALIGN_8B_R)
307
  * @retval None
307
  {
308
  */
308
    data = ((uint32_t)Data2 << 8U) | Data1;
309
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac)
309
  }
310
{
310
  else
311
  /* Prevent unused argument(s) compilation warning */
311
  {
312
  UNUSED(hdac);
312
    data = ((uint32_t)Data2 << 16U) | Data1;
313
 
313
  }
314
  /* NOTE : This function should not be modified, when the callback is needed,
314
 
315
            the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
315
  tmp = (uint32_t)hdac->Instance;
316
   */
316
  tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
317
}
317
 
318
 
318
  /* Set the dual DAC selected data holding register */
319
/**
319
  *(__IO uint32_t *)tmp = data;
320
  * @brief  Conversion half DMA transfer callback in non-blocking mode for Channel2.
320
 
321
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
321
  /* Return function status */
322
  *         the configuration information for the specified DAC.
322
  return HAL_OK;
323
  * @retval None
323
}
324
  */
324
 
325
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac)
325
/**
326
{
326
  * @brief  Conversion complete callback in non-blocking mode for Channel2.
327
  /* Prevent unused argument(s) compilation warning */
327
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
328
  UNUSED(hdac);
328
  *         the configuration information for the specified DAC.
329
 
329
  * @retval None
330
  /* NOTE : This function should not be modified, when the callback is needed,
330
  */
331
            the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
331
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac)
332
   */
332
{
333
}
333
  /* Prevent unused argument(s) compilation warning */
334
 
334
  UNUSED(hdac);
335
/**
335
 
336
  * @brief  Error DAC callback for Channel2.
336
  /* NOTE : This function should not be modified, when the callback is needed,
337
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
337
            the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
338
  *         the configuration information for the specified DAC.
338
   */
339
  * @retval None
339
}
340
  */
340
 
341
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
341
/**
342
{
342
  * @brief  Conversion half DMA transfer callback in non-blocking mode for Channel2.
343
  /* Prevent unused argument(s) compilation warning */
343
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
344
  UNUSED(hdac);
344
  *         the configuration information for the specified DAC.
345
 
345
  * @retval None
346
  /* NOTE : This function should not be modified, when the callback is needed,
346
  */
347
            the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
347
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac)
348
   */
348
{
349
}
349
  /* Prevent unused argument(s) compilation warning */
350
 
350
  UNUSED(hdac);
351
/**
351
 
352
  * @brief  DMA underrun DAC callback for Channel2.
352
  /* NOTE : This function should not be modified, when the callback is needed,
353
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
353
            the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
354
  *         the configuration information for the specified DAC.
354
   */
355
  * @retval None
355
}
356
  */
356
 
357
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
357
/**
358
{
358
  * @brief  Error DAC callback for Channel2.
359
  /* Prevent unused argument(s) compilation warning */
359
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
360
  UNUSED(hdac);
360
  *         the configuration information for the specified DAC.
361
 
361
  * @retval None
362
  /* NOTE : This function should not be modified, when the callback is needed,
362
  */
363
            the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
363
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
364
   */
364
{
365
}
365
  /* Prevent unused argument(s) compilation warning */
366
 
366
  UNUSED(hdac);
367
 
367
 
368
 
368
  /* NOTE : This function should not be modified, when the callback is needed,
369
/**
369
            the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
370
  * @}
370
   */
371
  */
371
}
372
 
372
 
373
/** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
373
/**
374
  *  @brief    Extended Peripheral Control functions
374
  * @brief  DMA underrun DAC callback for Channel2.
375
  *
375
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
376
@verbatim
376
  *         the configuration information for the specified DAC.
377
  ==============================================================================
377
  * @retval None
378
             ##### Peripheral Control functions #####
378
  */
379
  ==============================================================================
379
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
380
    [..]  This section provides functions allowing to:
380
{
381
      (+) Set the specified data holding register value for DAC channel.
381
  /* Prevent unused argument(s) compilation warning */
382
 
382
  UNUSED(hdac);
383
@endverbatim
383
 
384
  * @{
384
  /* NOTE : This function should not be modified, when the callback is needed,
385
  */
385
            the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
386
 
386
   */
387
 
387
}
388
/**
388
 
389
  * @brief  Return the last data output value of the selected DAC channel.
389
 
390
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
390
 
391
  *         the configuration information for the specified DAC.
391
/**
392
  * @retval The selected DAC channel data output value.
392
  * @}
393
  */
393
  */
394
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac)
394
 
395
{
395
/** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
396
  uint32_t tmp = 0UL;
396
  *  @brief    Extended Peripheral Control functions
397
 
397
  *
398
  tmp |= hdac->Instance->DOR1;
398
@verbatim
399
 
399
  ==============================================================================
400
  tmp |= hdac->Instance->DOR2 << 16UL;
400
             ##### Peripheral Control functions #####
401
 
401
  ==============================================================================
402
  /* Returns the DAC channel data output register value */
402
    [..]  This section provides functions allowing to:
403
  return tmp;
403
      (+) Set the specified data holding register value for DAC channel.
404
}
404
 
405
 
405
@endverbatim
406
 
406
  * @{
407
/**
407
  */
408
  * @}
408
 
409
  */
409
 
410
/**
410
/**
411
  * @}
411
  * @brief  Return the last data output value of the selected DAC channel.
412
  */
412
  * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
413
 
413
  *         the configuration information for the specified DAC.
414
/* Private functions ---------------------------------------------------------*/
414
  * @retval The selected DAC channel data output value.
415
/** @defgroup DACEx_Private_Functions DACEx private functions
415
  */
416
  *  @brief    Extended private functions
416
uint32_t HAL_DACEx_DualGetValue(const DAC_HandleTypeDef *hdac)
417
  * @{
417
{
418
  */
418
  uint32_t tmp = 0UL;
419
 
419
 
420
 
420
  tmp |= hdac->Instance->DOR1;
421
/**
421
 
422
  * @brief  DMA conversion complete callback.
422
  tmp |= hdac->Instance->DOR2 << 16UL;
423
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
423
 
424
  *                the configuration information for the specified DMA module.
424
  /* Returns the DAC channel data output register value */
425
  * @retval None
425
  return tmp;
426
  */
426
}
427
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
427
 
428
{
428
 
429
  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
429
/**
430
 
430
  * @}
431
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
431
  */
432
  hdac->ConvCpltCallbackCh2(hdac);
432
/**
433
#else
433
  * @}
434
  HAL_DACEx_ConvCpltCallbackCh2(hdac);
434
  */
435
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
435
 
436
 
436
/* Private functions ---------------------------------------------------------*/
437
  hdac->State = HAL_DAC_STATE_READY;
437
/** @defgroup DACEx_Private_Functions DACEx private functions
438
}
438
  *  @brief    Extended private functions
439
 
439
  * @{
440
/**
440
  */
441
  * @brief  DMA half transfer complete callback.
441
 
442
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
442
 
443
  *                the configuration information for the specified DMA module.
443
/**
444
  * @retval None
444
  * @brief  DMA conversion complete callback.
445
  */
445
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
446
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
446
  *                the configuration information for the specified DMA module.
447
{
447
  * @retval None
448
  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
448
  */
449
  /* Conversion complete callback */
449
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
450
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
450
{
451
  hdac->ConvHalfCpltCallbackCh2(hdac);
451
  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
452
#else
452
 
453
  HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
453
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
454
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
454
  hdac->ConvCpltCallbackCh2(hdac);
455
}
455
#else
456
 
456
  HAL_DACEx_ConvCpltCallbackCh2(hdac);
457
/**
457
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
458
  * @brief  DMA error callback.
458
 
459
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
459
  hdac->State = HAL_DAC_STATE_READY;
460
  *                the configuration information for the specified DMA module.
460
}
461
  * @retval None
461
 
462
  */
462
/**
463
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
463
  * @brief  DMA half transfer complete callback.
464
{
464
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
465
  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
465
  *                the configuration information for the specified DMA module.
466
 
466
  * @retval None
467
  /* Set DAC error code to DMA error */
467
  */
468
  hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
468
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
469
 
469
{
470
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
470
  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
471
  hdac->ErrorCallbackCh2(hdac);
471
  /* Conversion complete callback */
472
#else
472
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
473
  HAL_DACEx_ErrorCallbackCh2(hdac);
473
  hdac->ConvHalfCpltCallbackCh2(hdac);
474
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
474
#else
475
 
475
  HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
476
  hdac->State = HAL_DAC_STATE_READY;
476
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
477
}
477
}
478
 
478
 
479
 
479
/**
480
/**
480
  * @brief  DMA error callback.
481
  * @}
481
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
482
  */
482
  *                the configuration information for the specified DMA module.
483
 
483
  * @retval None
484
/**
484
  */
485
  * @}
485
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
486
  */
486
{
487
 
487
  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
488
#endif /* DAC1 */
488
 
489
 
489
  /* Set DAC error code to DMA error */
490
#endif /* HAL_DAC_MODULE_ENABLED */
490
  hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
491
 
491
 
492
/**
492
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
493
  * @}
493
  hdac->ErrorCallbackCh2(hdac);
494
  */
494
#else
495
 
495
  HAL_DACEx_ErrorCallbackCh2(hdac);
496
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
496
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
-
 
497
 
-
 
498
  hdac->State = HAL_DAC_STATE_READY;
-
 
499
}
-
 
500
 
-
 
501
 
-
 
502
/**
-
 
503
  * @}
-
 
504
  */
-
 
505
 
-
 
506
/**
-
 
507
  * @}
-
 
508
  */
-
 
509
 
-
 
510
#endif /* DAC1 */
-
 
511
 
-
 
512
#endif /* HAL_DAC_MODULE_ENABLED */
-
 
513
 
-
 
514
/**
-
 
515
  * @}
-
 
516
  */