From 0153e57f0c3b696ddf88582d9545773e4e56caf6 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 28 Dec 2014 12:59:45 +0100 Subject: I2S test. --- firmware/test/i2s/i2stest.c | 107 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 11 deletions(-) (limited to 'firmware/test/i2s/i2stest.c') diff --git a/firmware/test/i2s/i2stest.c b/firmware/test/i2s/i2stest.c index 31f5c20..8a2c598 100644 --- a/firmware/test/i2s/i2stest.c +++ b/firmware/test/i2s/i2stest.c @@ -26,35 +26,120 @@ */ #include #include +#include + +#include #include "../test.h" +#include "../../src/sample.h" +unsigned int size = sizeof(samples) / sizeof(short); + +static uint32_t cnt = 0; +static int num = 0; + +#if 1 +void I2S_IRQHandler (void) +{ + num = 8 - i2s_get_state_tx_level(); + + for(int i = 0; i < num; i++) { + i2s_write_pcm_16_stereo(samples[cnt % size] * 10, + samples[cnt % size] * 10); + //if((cnt % 24000) == 0) led_toggle(); + //i2s_write_pcm_16_stereo(cnt, cnt); + // if(cnt > (1<<16)) cnt = 0; + 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(); + /* // From: tools/clkcalc 48000 16 2 - int pclkdiv = 1; - int bitrate = 24; - int x = 96; - int y = 125; + 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); + */ + int res = i2s_clkcalc_init(48000, 16, 2); if(res) error(); + // BUG? 4pin mode = 0 works for some reason...? + i2s_set_tx_mode_control(CLK_TX_SRC, 0, 1); + + // i2s_tx_reset_fifo(); + /* + // Set up IRQ + uint32_t *i2sirq = (uint32_t*)0x400A801C; + // *i2sirq &= ~(0b1111 << 16); // Reset tx irq depth + int depth = 4; + *i2sirq |= ((depth & 0b1111) << 16); // Set tx irq depth + *i2sirq |= 0b1 << 1; // Enable IRQ, pg. 479 table 412 + + NVIC_EnableIRQ(I2S_IRQn); // I2S_IRQn = 27; + */ i2s_tx_start(); - // success(); + cli_printf("loop...\n"); - int16_t s = 0; + // int32_t *fifo = (int32_t*)0x400A8008; while(1) { - //while(i2s_get_state_tx_level() < 3) {} - i2s_write_pcm_16_stereo(s, s); - if((s % 2) == 0) led_toggle(); - s++; + 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 * 10) cnt = 0; + + // if(cnt > 64000) cnt = 0; + cnt++; } + } -- cgit v1.2.3