/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Starting and configuring the I2S driver 2. */ i2sStart(&I2SD2, &i2scfg); palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(5)); palSetPadMode(GPIOC, 3, PAL_MODE_ALTERNATE(5)); /* * Starting continuous I2S transfer. */ i2sStartExchange(&I2SD2); /* * Normal main() thread activity, if the button is pressed then the I2S * transfer is stopped. */ while (true) { if (palReadPad(GPIOA, GPIOA_BUTTON)) i2sStopExchange(&I2SD2); chThdSleepMilliseconds(500); } return 0; }
void mp45dt02Init(mp45dt02Config *config) { #if 0 PRINT("Initialising mp45dt02.\n\r" "mp45dt02I2sData.buffer size: %u words %u bytes\n\r" "mp45dt02ExpandedBuffer size: %u words %u bytes\n\r" "MP45DT02_DECIMATED_BUFFER_SIZE: %u", MP45DT02_I2S_BUFFER_SIZE_2B, sizeof(mp45dt02I2sData.buffer), MP45DT02_EXPANDED_BUFFER_SIZE, sizeof(mp45dt02ExpandedBuffer), MP45DT02_DECIMATED_BUFFER_SIZE); #endif initConfig = *config; chSemObjectInit(&mp45dt02ProcessingSem, 0); pMp45dt02ProcessingThd = chThdCreateStatic(mp45dt02ProcessingThdWA, sizeof(mp45dt02ProcessingThdWA), NORMALPRIO, mp45dt02ProcessingThd, NULL); dspInit(); memset(&mp45dt02I2sData, 0, sizeof(mp45dt02I2sData)); mp45dt02I2sData.guard = MEMORY_GUARD; memset(&mp45dt02I2SConfig, 0, sizeof(mp45dt02I2SConfig)); mp45dt02I2SConfig.tx_buffer = NULL; mp45dt02I2SConfig.rx_buffer = mp45dt02I2sData.buffer; mp45dt02I2SConfig.size = MP45DT02_I2S_BUFFER_SIZE_2B; mp45dt02I2SConfig.end_cb = mp45dt02Cb; mp45dt02I2SConfig.i2scfgr = I2SCFG_MODE_MASTER_RECEIVE | I2SCFG_STD_MSB_JUSTIFIED | I2SCFG_CKPOL_STEADY_HIGH; mp45dt02I2SConfig.i2spr = (SPI_I2SPR_I2SDIV & MP45DT02_I2SDIV) | (SPI_I2SPR_ODD & (MP45DT02_I2SODD << I2SPR_I2SODD_SHIFT)); i2sStart(&MP45DT02_I2S_DRIVER, &mp45dt02I2SConfig); i2sStartExchange(&MP45DT02_I2S_DRIVER); }