예제 #1
0
파일: dac.c 프로젝트: InSoonPark/asf
/**
 * \brief Writes a DAC channel configuration to the hardware module.
 *
 * Writes out a given channel configuration to the hardware module.
 *
 * \note The DAC device instance structure must be initialized before calling
 *       this function.
 *
 * \param[in] module_inst  Pointer to the DAC software instance struct
 * \param[in] channel      Channel to configure
 * \param[in] config       Pointer to the configuration struct
 *
 */
void dac_chan_set_config(
		struct dac_module *const module_inst,
		const enum dac_channel channel,
		struct dac_chan_config *const config)
{
	/* Sanity check arguments */
	Assert(module_inst);
	Assert(module_inst->hw);
	Assert(config);

	/* MUX the DAC VOUT pin */
	struct system_pinmux_config pin_conf;
	system_pinmux_get_config_defaults(&pin_conf);

	pin_conf.direction    = SYSTEM_PINMUX_PIN_DIR_INPUT;
	pin_conf.input_pull   = SYSTEM_PINMUX_PIN_PULL_NONE;

	if(channel == DAC_CHANNEL_0) {
		/* Set up the DAC VOUT0 pin */
		pin_conf.mux_position = MUX_PA02B_DAC_VOUT0;
		system_pinmux_pin_set_config(PIN_PA02B_DAC_VOUT0, &pin_conf);
	}
	else if(channel == DAC_CHANNEL_1) {
		/* Set up the DAC VOUT1 pin */
		pin_conf.mux_position = MUX_PA05B_DAC_VOUT1;
		system_pinmux_pin_set_config(PIN_PA05B_DAC_VOUT1, &pin_conf);
	}

	Dac *const dac_module = module_inst->hw;

	uint32_t new_dacctrl = 0;

	/* Left adjust data if configured */
	if (config->left_adjust) {
		new_dacctrl |= DAC_DACCTRL_LEFTADJ;
	}

	/* Set current control */
	new_dacctrl |= config->current;

	/* Enable DAC in standby sleep mode if configured */
	if (config->run_in_standby) {
		new_dacctrl |= DAC_DACCTRL_RUNSTDBY;
	}

	/* Voltage pump disable if configured */
	if (config->dither_mode) {
		new_dacctrl |= DAC_DACCTRL_DITHER;
	}

	new_dacctrl |= DAC_DACCTRL_REFRESH(config->refresh_period);

	/* Apply the new configuration to the hardware module */
	dac_module->DACCTRL[channel].reg = new_dacctrl;
}
예제 #2
0
/**
 * \brief Writes a DAC channel configuration to the hardware module.
 *
 * Writes out a given channel configuration to the hardware module.
 *
 * \note The DAC device instance structure must be initialized before calling
 *       this function.
 *
 * \param[in] module_inst  Pointer to the DAC software instance struct
 * \param[in] channel      Channel to configure
 * \param[in] config       Pointer to the configuration struct
 *
 */
void dac_chan_set_config(
		struct dac_module *const module_inst,
		const enum dac_channel channel,
		struct dac_chan_config *const config)
{
	/* Sanity check arguments */
	Assert(module_inst);
	Assert(module_inst->hw);
	Assert(config);

	Dac *const dac_module = module_inst->hw;

	uint32_t new_dacctrl = 0;

	/* Left adjust data if configured */
	if (config->left_adjust) {
		new_dacctrl |= DAC_DACCTRL_LEFTADJ;
	}

	/* Set current control */
	new_dacctrl |= config->current;

	/* Enable DAC in standby sleep mode if configured */
	if (config->run_in_standby) {
		new_dacctrl |= DAC_DACCTRL_RUNSTDBY;
	}

	/* Voltage pump disable if configured */
	if (config->dither_mode) {
		new_dacctrl |= DAC_DACCTRL_DITHER;
	}

	new_dacctrl |= DAC_DACCTRL_REFRESH(config->refresh_period);

	/* Apply the new configuration to the hardware module */
	dac_module->DACCTRL[channel].reg = new_dacctrl;
}