/* -*- 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 "../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 = 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(); cli_printf("loop...\n"); // int32_t *fifo = (int32_t*)0x400A8008; 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 * 10) cnt = 0; // if(cnt > 64000) cnt = 0; cnt++; } }