void codec_hw_init(void) { // Fortunately, all pins have already been initialized in board.h // Start the i2c driver i2cStart(&CODEC_I2C, &i2cfg); // Reset the codec codec_hw_reset(); // Write init sequence // Keep codec powered down initially codec_pwrCtl(0); codec_muteCtl(0); // Auto Detect Clock, MCLK/2 codec_writeReg(0x05, 0x81); // Slave Mode, I2S Data Format codec_writeReg(0x06, 0x04); codec_pwrCtl(1); codec_volCtl(200); // Adjust PCM Volume codec_writeReg(0x1A, 0x0A); codec_writeReg(0x1B, 0x0A); // Disable the analog soft ramp codec_writeReg(0x0A, 0x00); // Disable the digital soft ramp codec_writeReg(0x0E, 0x04); // Disable the limiter attack level codec_writeReg(0x27, 0x00); codec_writeReg(0x1C, 0x80); }
void audio_init(void) { int th; DCC_LOG(LOG_TRACE, "..."); audio_drv.enabled = false; /* 50 ms jitter buffer */ jitbuf_init(&audio_drv.jitbuf, SAMPLE_RATE, SAMPLE_RATE, 25); codec_hw_reset(); tracef("%s(): initializing I2S...", __func__); i2s_slave_init(); tracef("%s(): initializing TLV320...", __func__); tlv320_reset(); tlv320_init(); th = thinkos_thread_create((void *)net_rcv_task, (void *)NULL, net_rcv_stack, sizeof(net_rcv_stack), THINKOS_OPT_PRIORITY(1) | THINKOS_OPT_ID(1)); audio_drv.net_thread = th; th = thinkos_thread_create((void *)audio_io_task, (void *)NULL, audio_io_stack, sizeof(audio_io_stack), THINKOS_OPT_PRIORITY(0) | THINKOS_OPT_ID(0)); audio_drv.io_thread = th; }
void audio_reset(void) { bool enable_stream; tracef("%s(): audio system reset ...", __func__); enable_stream = audio_drv.stream_enabled; audio_drv.stream_enabled = false; codec_hw_reset(); tlv320_reset(); if (audio_drv.enabled) i2s_disable(); tlv320_init(); if (audio_drv.enabled) i2s_enable(); audio_drv.stream_enabled = enable_stream; }