Esempio n. 1
0
int main(void)
{
	system_init();

//! [setup_init]
	configure_dac();
	configure_dac_channel();
//! [setup_init]

//! [main]
//! [main_output_var]
	uint16_t i = 0;
//! [main_output_var]

//! [main_loop]
	while (1) {
//! [main_loop]
//! [main_write]
		dac_chan_write(&dac_instance, DAC_CHANNEL_0, i);
//! [main_write]

//! [main_inc_val]
		if (++i == 0x3FF) {
			i = 0;
		}
//! [main_inc_val]
	}
//! [main]
}
Esempio n. 2
0
//! [setup_dac]
void configure_dac(void)
{
//! [setup_dac_config]
	struct dac_config config_dac;
//! [setup_dac_config]

//! [setup_dac_config_default]
	dac_get_config_defaults(&config_dac);
//! [setup_dac_config_default]

//! [setup_dac_start_on_event]
#if (SAML21)
	dac_instance.start_on_event[DAC_CHANNEL_0] = true;
#else
	dac_instance.start_on_event = true;
#endif
//! [setup_dac_start_on_event]

//! [setup_dac_instance]
	dac_init(&dac_instance, DAC, &config_dac);
//! [setup_dac_instance]

//! [setup_dac_on_event_start_conversion]
	struct dac_events events =
#if (SAML21)
		{ .on_event_chan0_start_conversion = true };
#else
		{ .on_event_start_conversion = true };
#endif
//! [setup_dac_on_event_start_conversion]

//! [enable_dac_event]
	dac_enable_events(&dac_instance, &events);
//! [enable_dac_event]
}
//! [setup_dac]

//! [setup_dac_channel]
void configure_dac_channel(void)
{
//! [setup_dac_chan_config]
	struct dac_chan_config config_dac_chan;
//! [setup_dac_chan_config]

//! [setup_dac_chan_config_default]
	dac_chan_get_config_defaults(&config_dac_chan);
//! [setup_dac_chan_config_default]

//! [set_dac_chan_config]
	dac_chan_set_config(&dac_instance, DAC_CHANNEL_0,
			&config_dac_chan);
//! [set_dac_chan_config]

//! [enable_dac_channel]
	dac_chan_enable(&dac_instance, DAC_CHANNEL_0);
//! [enable_dac_channel]
}
//! [setup_dac_channel]

int main(void)
{
//! [data_length_var]
	uint32_t i;
//! [data_length_var]
	system_init();

//! [setup_init]
//! [init_rtc]
	configure_rtc_count();
//! [init_rtc]

//! [set_rtc_period]
	rtc_count_set_period(&rtc_instance, 1);
//! [set_rtc_period]

//! [init_dac]
	configure_dac();
//! [init_dac]

//! [init_dac_chan]
	configure_dac_channel();
//! [init_dac_chan]

//! [enable_dac]
	dac_enable(&dac_instance);
//! [enable_dac]

//! [init_event_resource]
	configure_event_resource();
//! [init_event_resource]

//! [register_dac_callback]
	dac_register_callback(&dac_instance, DAC_CHANNEL_0,
			dac_callback,DAC_CALLBACK_TRANSFER_COMPLETE);
//! [register_dac_callback]

//! [enable_dac_callback]
	dac_chan_enable_callback(&dac_instance, DAC_CHANNEL_0,
			DAC_CALLBACK_TRANSFER_COMPLETE);
//! [enable_dac_callback]

//! [setup_dac_data]
	for (i = 0;i < DATA_LENGTH;i++) {
		dac_data[i] = 0xfff * i;
	}
//! [setup_dac_data]
//! [setup_init]

//! [main_start]
//! [main_write]
	dac_chan_write_buffer_job(&dac_instance, DAC_CHANNEL_0,
			dac_data, DATA_LENGTH);
//! [main_write]

//! [main_check_transfer_done]
	while (!transfer_is_done) {
		/* Wait for transfer done */
	}
//! [main_check_transfer_done]

//! [main_loop]
	while (1) {
	}
//! [main_loop]
//! [main_start]
}