/** * \brief Configuration function for the right button. * * Parameters are passed onto config_buttons, which does the actual * configuration * Parameters are ignored. They have been included because the prototype is * dictated by the core sensor api. The return value is also required by * the API but otherwise ignored. * * \param type passed to config_buttons as-is * \param value passed to config_buttons as-is * * \return ignored */ static int config_right(int type, int value) { config_buttons(type, value, BOARD_IOID_KEY_RIGHT); return 1; }
/** * \brief Configuration function for the left button. * * Parameters are passed onto config_buttons, which does the actual * configuration * Parameters are ignored. They have been included because the prototype is * dictated by the core sensor API. The return value is also required by * the API but otherwise ignored. * * \param type passed to config_buttons as-is * \param value passed to config_buttons as-is * * \return ignored */ static int config_left(int type, int value) { config_buttons(type, value, BOARD_IOID_KEY_LEFT); return 1; }
/** * \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; } } }
/*! * \brief main function : do init and loop (poll if configured so) */ int main(void) { uint8_t key; struct picouart_dev_inst dev_inst; struct picouart_config config; struct ast_config ast_conf; /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n"); printf("-- PICOUART Example 1 --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); printf("-- IMPORTANT: This example requires a board " "monitor firmware version V1.3 or greater.\r\n"); /* Enable osc32 oscillator*/ if (!osc_is_ready(OSC_ID_OSC32)) { osc_enable(OSC_ID_OSC32); osc_wait_ready(OSC_ID_OSC32); } /* Disable all AST wake enable bits for safety since the AST is reset only by a POR. */ ast_enable(AST); ast_conf.mode = AST_COUNTER_MODE; ast_conf.osc_type = AST_OSC_32KHZ; ast_conf.psel = AST_PSEL_32KHZ_1HZ; ast_conf.counter = 0; ast_set_config(AST, &ast_conf); ast_disable_wakeup(AST, AST_WAKEUP_ALARM); ast_disable_wakeup(AST, AST_WAKEUP_PER); ast_disable_wakeup(AST, AST_WAKEUP_OVF); ast_disable(AST); /* Config the push button */ config_buttons(); /* Configurate the USART to board monitor */ bm_init(); sysclk_enable_hsb_module(SYSCLK_PBA_BRIDGE); sysclk_enable_peripheral_clock(BM_USART_USART); /* Init the PICOUART */ picouart_get_config_defaults(&config); picouart_init(&dev_inst, PICOUART, &config); /* Enable the PICOUART */ picouart_enable(&dev_inst); /* PICOUART and EIC can wakeup the device */ config_wakeup(); /* Display menu */ display_menu(); while (1) { scanf("%c", (char *)&key); switch (key) { case 'h': display_menu(); break; case 's': if (bm_flag) { printf("Switch off the board monitor to wake up..\r\n"); bm_flag = false; } else { printf("Switch on the board monitor to wake up..\r\n"); bm_flag = true; } break; case '0': printf("Enter Sleep mode with start bit wakeup.\r\n"); config.action = PICOUART_ACTION_WAKEUP_ON_STARTBIT; picouart_set_config(&dev_inst, &config); if (bm_flag) { printf("Board monitor will send frame after 3 seconds.\r\n"); bm_send_picouart_frame('A', 3000); } /* Wait for the printf operation to finish before setting the device in a power save mode. */ delay_ms(30); bpm_sleep(BPM, BPM_SM_SLEEP_2); printf("--Exit Sleep mode.\r\n\r\n"); break; case '1': printf("Enter Retention mode with full frame wakeup.\r\n"); config.action = PICOUART_ACTION_WAKEUP_ON_FULLFRAME; picouart_set_config(&dev_inst, &config); if (bm_flag) { printf("Board monitor will send frame after 3 seconds.\r\n"); bm_send_picouart_frame('T', 3000); } /* Wait for the printf operation to finish before setting the device in a power save mode. */ delay_ms(30); bpm_sleep(BPM, BPM_SM_RET); printf("--Exit Retention mode.\r\n\r\n"); break; case '2': printf("Enter backup mode with character match wakeup.\r\n"); config.action = PICOUART_ACTION_WAKEUP_ON_MATCH; config.match = 'L'; picouart_set_config(&dev_inst, &config); if (bm_flag) { printf("Board monitor will send frame after 3 seconds.\r\n"); bm_send_picouart_frame('L', 3000); } /* Wait for the printf operation to finish before setting the device in a power save mode. */ delay_ms(30); bpm_sleep(BPM, BPM_SM_BACKUP); break; default: break; } } }