Example #1
0
/**
 * \brief Test ABDAC initialization APIs.
 *
 * \param test Current test case.
 */
static void run_abdac_init_test(const struct test_case *test)
{
	status_code_t status;

	/* Config the ABDAC. */
	abdac_get_config_defaults(&g_abdac_cfg);
	status = abdac_init(&g_abdac_inst, ABDACB, &g_abdac_cfg);
	abdac_enable(&g_abdac_inst);
	abdac_clear_interrupt_flag(&g_abdac_inst, ABDAC_INTERRUPT_TXRDY);
	abdac_clear_interrupt_flag(&g_abdac_inst, ABDAC_INTERRUPT_TXUR);

	test_assert_true(test, status == STATUS_OK,
			"Initialization fails!");
}
Example #2
0
/**
 * \brief Application entry point for ABDAC example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t key;
	uint32_t i, count;
	status_code_t status;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Initialize the UART console. */
	configure_console();

	/* Output example information */
	printf("-- ABDAC Example --\r\n");
	printf("-- %s\r\n", BOARD_NAME);
	printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__);

	/* Config the push button. */
	config_buttons();

	/* Config the ABDAC. */
	abdac_get_config_defaults(&g_abdac_cfg);
	g_abdac_cfg.sample_rate_hz = ABDAC_SAMPLE_RATE_11025;
	g_abdac_cfg.data_word_format = ABDAC_DATE_16BIT;
	g_abdac_cfg.mono = false;
	g_abdac_cfg.cmoc = false;
	status = abdac_init(&g_abdac_inst, ABDACB, &g_abdac_cfg);
	if (status != STATUS_OK) {
		printf("-- Initialization fails! --\r\n");
		while (1) {
		}
	}
	abdac_enable(&g_abdac_inst);
	abdac_clear_interrupt_flag(&g_abdac_inst, ABDAC_INTERRUPT_TXRDY);
	abdac_clear_interrupt_flag(&g_abdac_inst, ABDAC_INTERRUPT_TXUR);

	/* Config PDCA module */
	pdca_enable(PDCA);
	pdca_channel_set_config(PDCA_ABDAC_CHANNEL0, &pdca_abdac_config0);
	pdca_channel_enable(PDCA_ABDAC_CHANNEL0);
	pdca_channel_set_config(PDCA_ABDAC_CHANNEL1, &pdca_abdac_config1);
	pdca_channel_enable(PDCA_ABDAC_CHANNEL1);

	/* Display menu. */
	display_menu();

	while (1) {
		scanf("%c", (char *)&key);

		switch (key) {
		case 'h':
			display_menu();
			break;

		case 's':
			printf("--Looped output audio, use push button to exit--\r\n");
			abdac_set_volume0(&g_abdac_inst, false, 0x7FFF);
			abdac_set_volume1(&g_abdac_inst, false, 0x7FFF);
			i = 0;
			/* output sample from the sound_table array */
			while(!exit_flag) {
				count = 0;
				// Store sample from the sound_table array
				while(count < (SOUND_SAMPLES)){
					samples_left[count] = ((uint8_t)sound_table[i]) << 8;
					samples_right[count] = ((uint8_t)sound_table[i]) << 8;
					i++;
					count++;
					if (i >= sizeof(sound_table)) i = 0;
				}

				pdca_channel_write_reload(PDCA_ABDAC_CHANNEL0,
						(void *)samples_left, SOUND_SAMPLES);
				pdca_channel_write_reload(PDCA_ABDAC_CHANNEL1,
						(void *)samples_right, SOUND_SAMPLES);
				/**
				 * Wait until the reload register is empty. This means that
				 * one transmission is still ongoing but we are already able
				 * to set up the next transmission.
				 */
				while(!(pdca_get_channel_status(PDCA_ABDAC_CHANNEL1)
					== PDCA_CH_COUNTER_RELOAD_IS_ZERO));
			}
			exit_flag = false;
			printf("--Exit the audio output--\r\n\r\n");
			/* Mute the volume */
			abdac_set_volume0(&g_abdac_inst, true, 0x7FFF);
			abdac_set_volume1(&g_abdac_inst, true, 0x7FFF);
			break;

		default:
			break;
		}
	}
}