mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L053R8/stm32l0xx_hal_dac_ex.c@323:9e901b0a5aa1, 2014-09-13 (annotated)
- Committer:
- shaoziyang
- Date:
- Sat Sep 13 14:25:46 2014 +0000
- Revision:
- 323:9e901b0a5aa1
- Parent:
- 181:a4cbdfbbd2f4
test with CLOCK_SETUP = 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 181:a4cbdfbbd2f4 | 1 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 2 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 3 | * @file stm32l0xx_hal_dac_ex.c |
mbed_official | 181:a4cbdfbbd2f4 | 4 | * @author MCD Application Team |
mbed_official | 181:a4cbdfbbd2f4 | 5 | * @version V1.0.0 |
mbed_official | 181:a4cbdfbbd2f4 | 6 | * @date 22-April-2014 |
mbed_official | 181:a4cbdfbbd2f4 | 7 | * @brief DAC HAL module driver. |
mbed_official | 181:a4cbdfbbd2f4 | 8 | * |
mbed_official | 181:a4cbdfbbd2f4 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 181:a4cbdfbbd2f4 | 10 | * functionalities of the Digital to Analog Converter (DAC) peripheral: |
mbed_official | 181:a4cbdfbbd2f4 | 11 | * + DAC wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 12 | * |
mbed_official | 181:a4cbdfbbd2f4 | 13 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 14 | |
mbed_official | 181:a4cbdfbbd2f4 | 15 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 16 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 17 | * @attention |
mbed_official | 181:a4cbdfbbd2f4 | 18 | * |
mbed_official | 181:a4cbdfbbd2f4 | 19 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 181:a4cbdfbbd2f4 | 20 | * |
mbed_official | 181:a4cbdfbbd2f4 | 21 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 181:a4cbdfbbd2f4 | 22 | * are permitted provided that the following conditions are met: |
mbed_official | 181:a4cbdfbbd2f4 | 23 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 24 | * this list of conditions and the following disclaimer. |
mbed_official | 181:a4cbdfbbd2f4 | 25 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 26 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 181:a4cbdfbbd2f4 | 27 | * and/or other materials provided with the distribution. |
mbed_official | 181:a4cbdfbbd2f4 | 28 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 181:a4cbdfbbd2f4 | 29 | * may be used to endorse or promote products derived from this software |
mbed_official | 181:a4cbdfbbd2f4 | 30 | * without specific prior written permission. |
mbed_official | 181:a4cbdfbbd2f4 | 31 | * |
mbed_official | 181:a4cbdfbbd2f4 | 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 181:a4cbdfbbd2f4 | 33 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 181:a4cbdfbbd2f4 | 34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 181:a4cbdfbbd2f4 | 35 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 181:a4cbdfbbd2f4 | 36 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 181:a4cbdfbbd2f4 | 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 181:a4cbdfbbd2f4 | 38 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 181:a4cbdfbbd2f4 | 39 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 181:a4cbdfbbd2f4 | 40 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 181:a4cbdfbbd2f4 | 41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 181:a4cbdfbbd2f4 | 42 | * |
mbed_official | 181:a4cbdfbbd2f4 | 43 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 44 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 45 | |
mbed_official | 181:a4cbdfbbd2f4 | 46 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 47 | #include "stm32l0xx_hal.h" |
mbed_official | 181:a4cbdfbbd2f4 | 48 | |
mbed_official | 181:a4cbdfbbd2f4 | 49 | /** @addtogroup STM32L0xx_HAL_Driver |
mbed_official | 181:a4cbdfbbd2f4 | 50 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 51 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 52 | |
mbed_official | 181:a4cbdfbbd2f4 | 53 | /** @defgroup DACEx |
mbed_official | 181:a4cbdfbbd2f4 | 54 | * @brief DAC driver modules |
mbed_official | 181:a4cbdfbbd2f4 | 55 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 56 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 57 | |
mbed_official | 181:a4cbdfbbd2f4 | 58 | #ifdef HAL_DAC_MODULE_ENABLED |
mbed_official | 181:a4cbdfbbd2f4 | 59 | #if !defined (STM32L051xx) && !defined (STM32L061xx) |
mbed_official | 181:a4cbdfbbd2f4 | 60 | |
mbed_official | 181:a4cbdfbbd2f4 | 61 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 62 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 63 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 64 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 65 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 66 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 67 | |
mbed_official | 181:a4cbdfbbd2f4 | 68 | /** @defgroup DACEx_Private_Functions |
mbed_official | 181:a4cbdfbbd2f4 | 69 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 70 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 71 | |
mbed_official | 181:a4cbdfbbd2f4 | 72 | |
mbed_official | 181:a4cbdfbbd2f4 | 73 | /** @defgroup DACEx_Group Peripheral Control functions |
mbed_official | 181:a4cbdfbbd2f4 | 74 | * @brief Peripheral Control functions |
mbed_official | 181:a4cbdfbbd2f4 | 75 | * |
mbed_official | 181:a4cbdfbbd2f4 | 76 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 77 | ============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 78 | ##### Peripheral Control functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 79 | ============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 80 | [..] This section provides functions allowing to: |
mbed_official | 181:a4cbdfbbd2f4 | 81 | (+) Configure Triangle wave generation. |
mbed_official | 181:a4cbdfbbd2f4 | 82 | (+) Configure Noise wave generation. |
mbed_official | 181:a4cbdfbbd2f4 | 83 | |
mbed_official | 181:a4cbdfbbd2f4 | 84 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 85 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 86 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 87 | |
mbed_official | 181:a4cbdfbbd2f4 | 88 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 89 | * @brief Enables or disables the selected DAC channel wave triangle generation. |
mbed_official | 181:a4cbdfbbd2f4 | 90 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 181:a4cbdfbbd2f4 | 91 | * the configuration information for the specified DAC. |
mbed_official | 181:a4cbdfbbd2f4 | 92 | * @param channel: The selected DAC channel. |
mbed_official | 181:a4cbdfbbd2f4 | 93 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 94 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 181:a4cbdfbbd2f4 | 95 | * @param Amplitude: Select max triangle amplitude. |
mbed_official | 181:a4cbdfbbd2f4 | 96 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 97 | * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1 |
mbed_official | 181:a4cbdfbbd2f4 | 98 | * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3 |
mbed_official | 181:a4cbdfbbd2f4 | 99 | * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7 |
mbed_official | 181:a4cbdfbbd2f4 | 100 | * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15 |
mbed_official | 181:a4cbdfbbd2f4 | 101 | * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31 |
mbed_official | 181:a4cbdfbbd2f4 | 102 | * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63 |
mbed_official | 181:a4cbdfbbd2f4 | 103 | * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127 |
mbed_official | 181:a4cbdfbbd2f4 | 104 | * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255 |
mbed_official | 181:a4cbdfbbd2f4 | 105 | * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511 |
mbed_official | 181:a4cbdfbbd2f4 | 106 | * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023 |
mbed_official | 181:a4cbdfbbd2f4 | 107 | * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047 |
mbed_official | 181:a4cbdfbbd2f4 | 108 | * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095 |
mbed_official | 181:a4cbdfbbd2f4 | 109 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 110 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 111 | HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t channel, uint32_t Amplitude) |
mbed_official | 181:a4cbdfbbd2f4 | 112 | { |
mbed_official | 181:a4cbdfbbd2f4 | 113 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 114 | assert_param(IS_DAC_CHANNEL(channel)); |
mbed_official | 181:a4cbdfbbd2f4 | 115 | assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); |
mbed_official | 181:a4cbdfbbd2f4 | 116 | |
mbed_official | 181:a4cbdfbbd2f4 | 117 | /* Process locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 118 | __HAL_LOCK(hdac); |
mbed_official | 181:a4cbdfbbd2f4 | 119 | |
mbed_official | 181:a4cbdfbbd2f4 | 120 | /* Change DAC state */ |
mbed_official | 181:a4cbdfbbd2f4 | 121 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 122 | |
mbed_official | 181:a4cbdfbbd2f4 | 123 | /* Enable the selected wave generation for the selected DAC channel */ |
mbed_official | 181:a4cbdfbbd2f4 | 124 | hdac->Instance->CR |= (DAC_WAVEGENERATION_TRIANGLE | Amplitude) << channel; |
mbed_official | 181:a4cbdfbbd2f4 | 125 | |
mbed_official | 181:a4cbdfbbd2f4 | 126 | /* Change DAC state */ |
mbed_official | 181:a4cbdfbbd2f4 | 127 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 128 | |
mbed_official | 181:a4cbdfbbd2f4 | 129 | /* Process unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 130 | __HAL_UNLOCK(hdac); |
mbed_official | 181:a4cbdfbbd2f4 | 131 | |
mbed_official | 181:a4cbdfbbd2f4 | 132 | /* Return function status */ |
mbed_official | 181:a4cbdfbbd2f4 | 133 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 134 | } |
mbed_official | 181:a4cbdfbbd2f4 | 135 | |
mbed_official | 181:a4cbdfbbd2f4 | 136 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 137 | * @brief Enables or disables the selected DAC channel wave noise generation. |
mbed_official | 181:a4cbdfbbd2f4 | 138 | * @param channel: The selected DAC channel. |
mbed_official | 181:a4cbdfbbd2f4 | 139 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 140 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 181:a4cbdfbbd2f4 | 141 | * @param Amplitude: Unmask DAC channel LFSR for noise wave generation. |
mbed_official | 181:a4cbdfbbd2f4 | 142 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 143 | * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 144 | * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 145 | * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 146 | * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 147 | * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 148 | * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 149 | * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 150 | * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 151 | * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 152 | * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 153 | * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 154 | * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation |
mbed_official | 181:a4cbdfbbd2f4 | 155 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 156 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 157 | HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t channel, uint32_t Amplitude) |
mbed_official | 181:a4cbdfbbd2f4 | 158 | { |
mbed_official | 181:a4cbdfbbd2f4 | 159 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 160 | assert_param(IS_DAC_CHANNEL(channel)); |
mbed_official | 181:a4cbdfbbd2f4 | 161 | assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); |
mbed_official | 181:a4cbdfbbd2f4 | 162 | |
mbed_official | 181:a4cbdfbbd2f4 | 163 | /* Process locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 164 | __HAL_LOCK(hdac); |
mbed_official | 181:a4cbdfbbd2f4 | 165 | |
mbed_official | 181:a4cbdfbbd2f4 | 166 | /* Change DAC state */ |
mbed_official | 181:a4cbdfbbd2f4 | 167 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 168 | |
mbed_official | 181:a4cbdfbbd2f4 | 169 | /* Enable the selected wave generation for the selected DAC channel */ |
mbed_official | 181:a4cbdfbbd2f4 | 170 | hdac->Instance->CR |= (DAC_WAVEGENERATION_NOISE | Amplitude) << channel; |
mbed_official | 181:a4cbdfbbd2f4 | 171 | |
mbed_official | 181:a4cbdfbbd2f4 | 172 | /* Change DAC state */ |
mbed_official | 181:a4cbdfbbd2f4 | 173 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 174 | |
mbed_official | 181:a4cbdfbbd2f4 | 175 | /* Process unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 176 | __HAL_UNLOCK(hdac); |
mbed_official | 181:a4cbdfbbd2f4 | 177 | |
mbed_official | 181:a4cbdfbbd2f4 | 178 | /* Return function status */ |
mbed_official | 181:a4cbdfbbd2f4 | 179 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 180 | } |
mbed_official | 181:a4cbdfbbd2f4 | 181 | |
mbed_official | 181:a4cbdfbbd2f4 | 182 | |
mbed_official | 181:a4cbdfbbd2f4 | 183 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 184 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 185 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 186 | |
mbed_official | 181:a4cbdfbbd2f4 | 187 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 188 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 189 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 190 | |
mbed_official | 181:a4cbdfbbd2f4 | 191 | #endif /* STM32L051xx && STM32L061xx*/ |
mbed_official | 181:a4cbdfbbd2f4 | 192 | #endif /* HAL_DAC_MODULE_ENABLED */ |
mbed_official | 181:a4cbdfbbd2f4 | 193 | |
mbed_official | 181:a4cbdfbbd2f4 | 194 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 195 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 196 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 197 | |
mbed_official | 181:a4cbdfbbd2f4 | 198 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 199 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 200 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 201 | |
mbed_official | 181:a4cbdfbbd2f4 | 202 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |