/** * @brief Enables or disables DAC Wave Generation according to the specified * parameters. * @param DAC_Channel : the selected DAC channel from @ref DAC_Channel_TypeDef * enumeration. * @param DAC_Wave : the selected waveform from @ref DAC_Wave_TypeDef enumeration. * @retval None */ void DAC_WaveGenerationCmd(DAC_Channel_TypeDef DAC_Channel, DAC_Wave_TypeDef DAC_Wave, FunctionalState NewState) { uint8_t tmpreg = 0; /* Check the DAC parameters */ assert_param(IS_DAC_CHANNEL(DAC_Channel)); assert_param(IS_DAC_WAVE(DAC_Wave)); assert_param(IS_FUNCTIONAL_STATE(NewState)); /* Get the DAC CHxCR1 value & Clear WAVEN bits */ tmpreg = (uint8_t)((*(uint8_t*)(uint16_t)(DAC_BASE + CR1_Offset + (uint8_t)((uint8_t)DAC_Channel << 1))) & (uint8_t)~(DAC_CR1_WAVEN)); if (NewState != DISABLE) { tmpreg |= (uint8_t)(DAC_Wave); } /* Write to DAC CHxCR1 */ (*(uint8_t*) (uint16_t)(DAC_BASE + CR1_Offset + (uint8_t)((uint8_t)DAC_Channel << 1))) = tmpreg; }
/** * @brief Initialize the DAC. * @param DACx: Select the DAC channel. * This parameter can be one of the following values: * TSB_DA0, TSB_DA1 * @param InitStruct: The structure containing basic DAC configuration including clear DAC request, * set post adjustment for VOUTHOLD time, pre adjustment for VOUTHOLD time, * offset setting of output waveform, amplitude setting of output waveform, * output waveform selection, trigger selection and trigger function. * @retval None */ void DAC_Init(TSB_DA_TypeDef * DACx, DAC_InitTypeDef * InitStruct) { uint32_t tmp = 0U; /* Check the parameters */ assert_param(IS_DAC_CHANNEL(DACx)); assert_param(IS_POINTER_NOT_NULL(InitStruct)); assert_param(IS_DAC_CLEAR(InitStruct->DACClear)); assert_param(IS_DAC_ADJTIME(InitStruct->PostTime)); assert_param(IS_DAC_ADJTIME(InitStruct->PreTime)); assert_param(IS_DAC_OFFSET(InitStruct->Offset)); assert_param(IS_DAC_AMPSEL(InitStruct->AmpSel)); assert_param(IS_DAC_TRGSEL(InitStruct->TrgSel)); assert_param(IS_DAC_TRGFUNC(InitStruct->TrgFunc)); assert_param(IS_DAC_DMAFUNC(InitStruct->DMAFunc)); assert_param(IS_DAC_WAVE(InitStruct->Wave)); /*Clear DAC */ tmp = DACx->TCTL; tmp &= DAC_CLEAR_MASK; tmp |= InitStruct->DACClear; DACx->TCTL = tmp; /*Set time to VOUTHOLD adjustment register */ tmp = (uint8_t) (InitStruct->PostTime << 4U); tmp += InitStruct->PreTime; DACx->VCTL = tmp; /*set DACDCTLx(output control register) */ tmp = (uint8_t) (InitStruct->Offset << 18U); tmp += (uint8_t) (InitStruct->AmpSel << 16U); tmp += (uint8_t) (InitStruct->TrgSel << 9U); tmp += (uint8_t) (InitStruct->TrgFunc << 8U); tmp += (uint8_t) (InitStruct->DMAFunc << 7U); tmp += (uint8_t) (InitStruct->Wave); DACx->DCTL = tmp; }