void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig; // Get the peripheral name from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT(obj->dac != (DACName)NC); // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the pin for future use obj->pin = pin; // Enable DAC clock __DAC1_CLK_ENABLE(); // Configure DAC DacHandle.Instance = (DAC_TypeDef *)(obj->dac); sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig; // Get the peripheral name from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT(obj->dac != (DACName)NC); // Get the pin function and assign the used channel to the object uint32_t function = pinmap_function(pin, PinMap_DAC); MBED_ASSERT(function != (uint32_t)NC); obj->channel = STM_PIN_CHANNEL(function); // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the pin for future use obj->pin = pin; // Enable DAC clock if (obj->dac == DAC_1) { __DAC1_CLK_ENABLE(); } #if defined(DAC2) if (obj->dac == DAC_2) { __DAC2_CLK_ENABLE(); } #endif // Configure DAC DacHandle.Instance = (DAC_TypeDef *)(obj->dac); sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; if (pin == PA_4) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); pa4_used = 1; } #if defined(DAC_CHANNEL_2) if (pin == PA_5) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_2); pa5_used = 1; } #endif if (pin == PA_6) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); } analogout_write_u16(obj, 0); }