static void DACConfig(void) { DMA_CfgDescr_TypeDef descrCfg; DMA_CfgChannel_TypeDef chnlCfg; DAC_Init_TypeDef dacInit = DAC_INIT_DEFAULT; DAC_InitChannel_TypeDef dacChInit = DAC_INITCHANNEL_DEFAULT; /* Notice: Audio out buffers are by default filled with 0, since */ /* uninitialized data; no need to clear explicitly. */ /* Configure DAC */ /* Init common DAC issues */ dacInit.reference = dacRefVDD; DAC_Init(DAC0, &dacInit); /* Start with "no" signal out */ DAC0->COMBDATA = 0x0; /* Init channels, equal config for both channels. */ dacChInit.enable = true; dacChInit.prsSel = dacPRSSELCh0; dacChInit.prsEnable = true; DAC_InitChannel(DAC0, &dacChInit, 0); /* Right channel */ DAC_InitChannel(DAC0, &dacChInit, 1); /* Left channel */ /* Configure DMA usage by DAC */ cbOutData.cbFunc = dacCb; cbOutData.userPtr = NULL; chnlCfg.highPri = true; chnlCfg.enableInt = true; chnlCfg.select = DMAREQ_DAC0_CH0; chnlCfg.cb = &cbOutData; DMA_CfgChannel(DMA_CHANNEL_DAC, &chnlCfg); descrCfg.dstInc = dmaDataIncNone; descrCfg.srcInc = dmaDataInc4; descrCfg.size = dmaDataSize4; descrCfg.arbRate = dmaArbitrate1; descrCfg.hprot = 0; DMA_CfgDescr(DMA_CHANNEL_DAC, true, &descrCfg); DMA_CfgDescr(DMA_CHANNEL_DAC, false, &descrCfg); DMA_ActivatePingPong(DMA_CHANNEL_DAC, false, (void *)((uint32_t) &(DAC0->COMBDATA)), sourceP, N - 1, (void *)((uint32_t) &(DAC0->COMBDATA)), sourceS, N - 1); }
void setupDAC( void ) { DAC_Init_TypeDef dacInit = DAC_INIT_DEFAULT; dacInit.reference = dacRefVDD; DAC_Init(DAC0, &dacInit); DAC0->COMBDATA = 0x0; DAC_InitChannel_TypeDef dacChInit = DAC_INITCHANNEL_DEFAULT; dacChInit.enable = true; dacChInit.prsSel = dacPRSSELCh0; dacChInit.prsEnable = true; DAC_InitChannel(DAC0, &dacChInit, 0); DAC_InitChannel(DAC0, &dacChInit, 1); }
/**************************************************************************//** * @brief DAC_setup * Configures the DAC *****************************************************************************/ void DAC_setup(void) { /* Enable necessary clocks */ CMU_ClockEnable(cmuClock_DAC0, true); /* Use default settings */ DAC_Init_TypeDef init = DAC_INIT_DEFAULT; DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the * function will check what the current value actually is. */ init.prescale = DAC_PrescaleCalc(500000, 0); /* Set reference voltage to Vdd */ init.reference = dacRefVDD; /* Enable PRS triggered conversion (channel 5) */ initChannel.prsEnable = true; initChannel.prsSel = dacPRSSELCh5; /* Initialize DAC and DAC channel 0 */ DAC_Init(DAC0, &init); DAC_InitChannel(DAC0, &initChannel, 0); /* Enable DAC channel 0, located on pin PB11 */ DAC_Enable(DAC0, 0, true); }
void analogout_init(dac_t *obj, PinName pin) { /* init in-memory structure */ obj->dac = (DAC_TypeDef *) pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT((int) obj->dac != NC); obj->channel = pin_location(pin, PinMap_DAC); MBED_ASSERT((int) obj->channel != NC); pin_mode(pin, Disabled); if (!dac_initialized) { /* Initialize the DAC. Will disable both DAC channels, so should only be done once */ /* Use default settings */ CMU_ClockEnable(cmuClock_DAC0, true); DAC_Init_TypeDef init = DAC_INIT_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK * frequency instead of setting a new one. */ init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY); /* Set reference voltage to VDD */ init.reference = dacRefVDD; DAC_Init(obj->dac, &init); dac_initialized = 1; } /* Use default channel settings */ DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; initChannel.enable = true; DAC_InitChannel(obj->dac, &initChannel, obj->channel); }
void DAC_setup(void) { /* Define DAC settings */ DAC_Init_TypeDef init = { dacRefresh8, /* Refresh every 8 prescaled cycles. */ \ dacRef1V25, /* 1.25V internal reference. */ \ dacOutputPinADC, /* Output to pin and ADC. */ \ dacConvModeContinuous, /* Continuous mode. */ \ 0, /* No prescaling. */ \ false, /* Do not enable low pass filter. */ \ false, /* Do not reset prescaler on ch0 start. */ \ false, /* DAC output enable always on. */ \ false, /* Disable sine mode. */ \ false /* Single ended mode. */ \ }; DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the * function will check what the current value actually is. */ init.prescale = DAC_PrescaleCalc(500000, 0); /* Set reference voltage to vdd.*/ init.reference = dacRefVDD; /* Initialize the DAC and DAC channel. */ DAC_Init(DAC0, &init); /*Initialize DAC channel 0.*/ DAC_InitChannel(DAC0, &initChannel, 0); }
void analogout_init(dac_t *obj, PinName pin) { static uint8_t dac_initialized = 0; /* init in-memory structure */ analogout_preinit(obj, pin); if (!dac_initialized) { /* Initialize the DAC. Will disable both DAC channels, so should only be done once */ /* Use default settings */ CMU_ClockEnable(cmuClock_DAC0, true); DAC_Init_TypeDef init = DAC_INIT_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK * frequency instead of setting a new one. */ init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY); /* Set reference voltage to VDD */ init.reference = dacRefVDD; DAC_Init(obj->dac, &init); dac_initialized = 1; } /* Use default channel settings */ DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; DAC_InitChannel(obj->dac, &initChannel, obj->channel); }
/**************************************************************************//** * @brief Setup DAC * Configures and starts the DAC *****************************************************************************/ void DAC_setup(void) { /* Use default settings */ DAC_Init_TypeDef init = DAC_INIT_DEFAULT; DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; /* Enable the DAC clock */ CMU_ClockEnable(cmuClock_DAC0, true); /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the * function will check what the current value actually is. */ init.prescale = DAC_PrescaleCalc(500000, 0); /* Set reference voltage to 1.25V */ init.reference = dacRef1V25; /* Set output mode for DAC such that the DAC can produce output to both * pin and ADC. */ init.outMode = dacOutputPinADC; /* Initialize the DAC and DAC channel. */ DAC_Init(DAC0, &init); DAC_InitChannel(DAC0, &initChannel, 0); }
void analogout_free(dac_t *obj) { //Reset channel by re-initializing DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; initChannel.enable = false; DAC_InitChannel(obj->dac, &initChannel, obj->channel); //Check all channels to see if we can disable the DAC completely if((DAC0->CH0CTRL & DAC_CH0CTRL_EN) == 0 && (DAC0->CH1CTRL & DAC_CH1CTRL_EN) == 0) { CMU_ClockEnable(cmuClock_DAC0, false); dac_initialized = 0; } }