summaryrefslogtreecommitdiff
path: root/firmware/test/i2s/i2stest.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/i2s/i2stest.c')
-rw-r--r--firmware/test/i2s/i2stest.c107
1 files changed, 96 insertions, 11 deletions
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 <i2s.h>
#include <led.h>
+#include <LPC17xx.h>
+
+#include <cli.h>
#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++;
}
+
}