/* Set DAC Channel Waveform Generation mode for one or both channels. These signals are superimposed on existing output values in the DAC output registers. Waveform can be disabled, noise, triangular, or sawtooth, depending on family.  */
void dac_set_waveform_generation(uint32_t dac, int channel, enum dac_wave wave)
/* Set DAC Channel Waveform Generation mode for one or both channels. These signals are superimposed on existing output values in the DAC output registers. Waveform can be disabled, noise, triangular, or sawtooth, depending on family.  */
void dac_set_waveform_generation(uint32_t dac, int channel, enum dac_wave wave)
{
	uint32_t reg = DAC_CR(dac);
	switch(channel) {
	case DAC_CHANNEL1:
		reg &= ~(DAC_CR_WAVEx_MASK << DAC_CR_WAVE1_SHIFT);
		reg |= wave << DAC_CR_WAVE1_SHIFT;
		break;
	case DAC_CHANNEL2:
		reg &= ~(DAC_CR_WAVEx_MASK << DAC_CR_WAVE2_SHIFT);
		reg |= wave << DAC_CR_WAVE2_SHIFT;
		break;
	case DAC_CHANNEL_BOTH:
		reg &= ~(DAC_CR_WAVEx_MASK << DAC_CR_WAVE1_SHIFT)
			| ~(DAC_CR_WAVEx_MASK << DAC_CR_WAVE2_SHIFT);
		reg |= wave << DAC_CR_WAVE1_SHIFT;
		reg |= wave << DAC_CR_WAVE2_SHIFT;
		break;
	default:
		break;
	}
	DAC_CR(dac) = reg;
}