From d5ab518f3d5fa632660e8377d31fbafd561fe5ca Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 28 Dec 2014 13:01:10 +0100 Subject: WM8523 test. --- firmware/test/wm8523/wm8523test.c | 226 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 firmware/test/wm8523/wm8523test.c (limited to 'firmware/test/wm8523/wm8523test.c') diff --git a/firmware/test/wm8523/wm8523test.c b/firmware/test/wm8523/wm8523test.c new file mode 100644 index 0000000..b67fd32 --- /dev/null +++ b/firmware/test/wm8523/wm8523test.c @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * i2stest.c + * + * Mon Sep 1 20:25:48 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pedal2Metal. + * + * Pedal2Metal is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pedal2Metal is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pedal2Metal; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +#include +#include +//#include +#include + +#include "../../src/sample.h" +unsigned int size = sizeof(samples) / sizeof(short); + +#include "../test.h" + +#if 0 +void I2S_IRQHandler (void) +{ + + static int16_t cnt = 0; + + for(int i = 0; i < 6; i++) { + //if(1 || (cnt % 24000) == 0) led_toggle(); + i2s_write_pcm_16_stereo(cnt, cnt); + cnt++; + } + /* + uint32_t RxCount = 0; + + if ( LPC_I2S->I2SSTATE & 0x01 ) + { + RxCount = (LPC_I2S->I2SSTATE >> 8) & 0xFF; + if ( (RxCount != RXFIFO_EMPTY) && !I2SRXDone ) + { + while ( RxCount > 0 ) + { + if ( I2SReadLength == BUFSIZE ) + { + LPC_I2S->I2SDAI |= ((0x01 << 3) | (0x01 << 4)); + LPC_I2S->I2SIRQ &= ~(0x01 << 0); // Disable RX + I2SRXDone = 1; + break; + } + else + { + I2SRXBuffer[I2SReadLength++] = LPC_I2S->I2SRXFIFO; + } + RxCount--; + } + } + } + return; + */ +} +#endif + +int main (void) +{ + led_init(); + + cli_init(); + + /////////// WM8523 + + uint8_t portnum = 0; + + wm8523_init(portnum, WM8523_FS_48K); + + if(wm8523_get_chip_id(portnum) != WM8532_CHIP_ID) error(); + + wm8523_reset_registers(portnum); + + wm8523_power_mode_t pwr = WM8523_PWR_POWER_UP_TO_UNMUTE; + wm8523_set_power_mode(portnum, pwr); + + wm8523_aif_ctrl1_t ctl1; + ctl1.fmt = WM8523_FMT_I2S; + ctl1.wlen = WM8523_WLEN_16; + ctl1.invctl = WM8523_INVCTL_SLAVE_RISING; + ctl1.lrclkinvctl = WM8523_LRCLKINVCTL_SLAVE_NORMAL; + ctl1.modesel = WM8523_MODESEL_SLAVE; + ctl1.deemp = WM8523_DEEMPH_ENABLED; + wm8523_set_aif_ctrl1(portnum, ctl1); + + wm8523_aif_ctrl2_t ctl2; + ctl2.clkratio = WM8523_CLKRATIO_AUTO; + ctl2.clkdiv = WM8523_CLKDIV_MCLK_4; + ctl2.mix = WM8523_MIX_STEREO; + wm8523_set_aif_ctrl2(portnum, ctl2); + + wm8523_dac_ctrl3_t ctl3; + ctl3.downramp = WM8523_VOL_DOWN_INSTANT; + ctl3.upramp = WM8523_VOL_UP_INSTANT; + ctl3.lmute = WM8523_DACL_UNMUTE; + ctl3.rmute = WM8523_DACR_UNMUTE; + ctl3.dac_zc = WM8523_ZERO_CROSSING_DISABLED; + wm8523_set_dac_ctrl3(portnum, ctl3); + + + int res = i2s_clkcalc_init(48000, 16, 2); + + /* + // From: tools/clkcalc 48000 16 2 + int pclkdiv = 8; + int bitrate = 3; + int x = 57; + int y = 59; + // err = 16.949153 bits/second + + int bitwidth = 16; + int channels = 2; + + int res = i2s_init(pclkdiv, bitrate, x, y, bitwidth, channels); + */ + // if(res) error(); + (void)res; + + i2s_set_tx_mode_control(CLK_TX_SRC, 0, 1); + + /* + + //////// I2S +#if 1 + + // From: tools/clkcalc 48000 16 2 + int pclkdiv = 8; + int bitrate = 1; + int x = 29; + int y = 59; + // err = 16.949153 bits/second + + int bitwidth = 16; + int channels = 2; + + int res = i2s_init(pclkdiv, bitrate, x, y, bitwidth, channels); + if(res) error(); + + // I2SInit(); + + i2s_set_tx_mode_control(CLK_TX_SRC, 0, 1); + + // Set up IRQ + uint32_t *i2sirq = (uint32_t*)0x400A801C; + *i2sirq &= ~(0b1111 << 16); // Reset tx irq depth + int depth = 2; + *i2sirq |= ((depth & 0b1111) << 16); // Set tx irq depth + *i2sirq |= 0b1 << 1; // Enable TX IRQ, pg. 479 table 412 + + i2s_tx_start(); + +#else + // From: tools/clkcalc 48000 16 2 + int pclkdiv = 8; + int bitrate = 1; + int x = 29; + int y = 59; + // err = 16.949153 bits/second + + int bitwidth = 16; + int channels = 2; + + int res = i2s_init(pclkdiv, bitrate, x, y, bitwidth, channels); + if(res) error(); + + // Set up IRQ + uint32_t *i2sirq = (uint32_t*)0x400A801C; + *i2sirq |= 0b1 << 0; // Enable IRQ, pg. 479 table 412 + *i2sirq &= ~(0b1111 << 16); // Reset tx irq depth + int depth = 2; + *i2sirq |= ((depth & 0b1111) << 16); // Set tx irq depth + NVIC_EnableIRQ(I2S_IRQn); // I2S_IRQn = 27; + + + + i2s_tx_reset_fifo(); + i2s_tx_start(); +#endif + */ + + i2s_tx_start(); + + // int32_t *fifo = (int32_t*)0x400A8008; + unsigned int cnt = 0; + while(1) { + while(i2s_get_state_tx_level() > 7) {} + // i2s_write_pcm_16_stereo(cnt, cnt); + // *fifo = cnt; + + // *fifo = (cnt / 40) | (cnt / 40) << 16; + if(cnt < size) { + i2s_write_pcm_16_stereo((samples[cnt] - 485) * 10, + (samples[cnt] - 485) * 10); + } else { + // repeat last sample + i2s_write_pcm_16_stereo(0, 0); + } + + if(cnt > size * 30) cnt = 0; + + // if(cnt > 64000) cnt = 0; + cnt++; + } +} -- cgit v1.2.3