Adapted to work with the LPC4088 Experiment Base Board

Dependents:   lpc4088_ebb_ptp Algorithm-testing

Fork of I2S by Giles Barton-Owen

Files at this revision

API Documentation at this revision

Comitter:
embeddedartists
Date:
Mon Sep 08 11:33:30 2014 +0000
Parent:
0:455d5826751b
Commit message:
Changed sample rate and pinning to work on the LPC4088 Experiment Base Board.

Changed in this revision

I2S.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 455d5826751b -r af579d286498 I2S.cpp
--- a/I2S.cpp	Wed Sep 19 10:53:33 2012 +0000
+++ b/I2S.cpp	Mon Sep 08 11:33:30 2014 +0000
@@ -1,7 +1,7 @@
 #include "I2S.h"
 
 #define I2S_DF_WORDWIDTH                16
-#define I2S_DF_SAMPLERATE               32000
+#define I2S_DF_SAMPLERATE               48000
 #define I2S_DF_MASTERSLAVE              I2S_SLAVE
 #define I2S_DF_STEREOMONO               I2S_STEREO
 #define I2S_DF_MUTED                    I2S_UNMUTED
@@ -11,7 +11,8 @@
 #define I2S_MAX_NUMERATOR               256
 #define I2S_MAX_BITRATE_DIV             64
 
-#define I2S_PCLK_RATE                   24000000
+//#define I2S_PCLK_RATE                   24000000
+#define I2S_PCLK_RATE                   120000000
 
 FunctionPointer I2S::I2STXISR;
 FunctionPointer I2S::I2SRXISR;
@@ -183,7 +184,7 @@
             for (int j = 0; j < 4; j++) {
                 temp |= int(buf[i + j]) << (j * 8);
             }
-            LPC_I2S->I2STXFIFO = temp;
+            LPC_I2S->TXFIFO = temp;
         }
     }
 
@@ -236,7 +237,7 @@
             //if(((temp >> 16) & 0xFFFF) == 0xFFFF) printf("Hmmm %x %x %x\n\r",temp, increment,i); //|| temp &0xFFFF == 0xFFFF
             //if((buf[i]-buf[i+1])>5000 || (buf[i]-buf[i+1])<-5000) printf("J:%i,%i\n\r",buf[i],buf[i+1]);
             //printf("%x\n",temp);
-            LPC_I2S->I2STXFIFO = temp;
+            LPC_I2S->TXFIFO = temp;
         }
     }
 }
@@ -248,7 +249,7 @@
 
 int I2S::read()
 {
-    return LPC_I2S->I2SRXFIFO;
+    return LPC_I2S->RXFIFO;
 }
 
 void I2S::read(char buf[], int len)
@@ -263,7 +264,7 @@
     int increment = 4;            //32/wordwidth;
     int fifo_levl = fifo_level();
     while (counter < fifo_levl && len_valid) {
-        temp[counter] = LPC_I2S->I2SRXFIFO;
+        temp[counter] = LPC_I2S->RXFIFO;
         for (int j = 0; j < increment; j++) {
             if ((counter * 4) + j > len) {
                 len_valid = false;
@@ -288,7 +289,7 @@
     int increment = 32 / wordwidth;
     int fifo_levl = fifo_level();
     while (counter < fifo_levl && len_valid) {
-        temp[counter] = LPC_I2S->I2SRXFIFO;
+        temp[counter] = LPC_I2S->RXFIFO;
         for (int j = 0; j < increment; j++) {
             if ((counter * increment) + j > len) {
                 len_valid = false;
@@ -376,11 +377,11 @@
 {
     int level = 0;
     if (_rxtx == I2S_TRANSMIT) {
-        level = LPC_I2S->I2SSTATE;
+        level = LPC_I2S->STATE;
         level >>= 16;
         level &= 0xF;
     } else {
-        level = LPC_I2S->I2SSTATE;
+        level = LPC_I2S->STATE;
         level >>= 8;
         level &= 0xF;
     }
@@ -440,20 +441,20 @@
     pin_setup_err = 0;
 
     if (_rxtx == I2S_TRANSMIT) {
-        printf("\n\rSetting up pins....\n\r");
-        if (_sd != p5)
+        //printf("\n\rSetting up pins....\n\r");
+        if (_sd != p11)
             pin_setup_err++;
-        if (_ws != p6 && ws_d == true)
+        if (_ws != p12 && ws_d == true)
             pin_setup_err++;
-        if (_clk != p7 && clk_d == true)
+        if (_clk != p13 && clk_d == true)
             pin_setup_err++;
-        printf("Hmm....%i\n\r", pin_setup_err);
+        //printf("Hmm....%i\n\r", pin_setup_err);
     } else {
-        if (_sd != p17 && _sd != p8)
+        if (_sd != p14)
             pin_setup_err++;
-        if (_ws != p16 && _ws != p29 && ws_d == true)
+        if (_ws != p33 && ws_d == true)
             pin_setup_err++;
-        if (_clk != p15 && _clk != p30 && clk_d == true)
+        if (_clk != p34 && clk_d == true)
             pin_setup_err++;
     }
 
@@ -463,11 +464,14 @@
             if (deallocating) {
                 val1 = 0;
             }
-            LPC_PINCON->PINSEL0 |= (val1 << 18); //set p5 as transmit serial data line
+            LPC_IOCON->P0_9 |= ((1<<7) | (1<<0));
+//            LPC_PINCON->PINSEL0 |= (val1 << 18); //set p5 as transmit serial data line
             if (ws_d == true)
-                LPC_PINCON->PINSEL0 |= (val1 << 14); //set p7 as transmit clock line
+                LPC_IOCON->P0_8 |= ((1<<7) | (1<<0));
+//                LPC_PINCON->PINSEL0 |= (val1 << 14); //set p7 as transmit clock line
             if (clk_d == true)
-                LPC_PINCON->PINSEL0 |= (val1 << 16); //set p6 as word select line
+                LPC_IOCON->P0_7 |= ((1<<7) | (1<<0));
+//                LPC_PINCON->PINSEL0 |= (val1 << 16); //set p6 as word select line
 
         } else {
             int val1 = 1;
@@ -477,23 +481,26 @@
                 val2 = 0;
             }
 
-            if (_sd == p8)
-                LPC_PINCON->PINSEL0 |= (val1 << 12);
-            else
-                LPC_PINCON->PINSEL1 |= (val2 << 18);
+//            if (_sd == p8)
+            LPC_IOCON->P0_6 |= (1<<0);
+//                LPC_PINCON->PINSEL0 |= (val1 << 12);
+//            else
+//                LPC_PINCON->PINSEL1 |= (val2 << 18);
 
             if (ws_d == true) {
-                if (_ws == p29)
-                    LPC_PINCON->PINSEL0 |= (val1 << 10);
-                else
-                    LPC_PINCON->PINSEL1 |= (val2 << 16);
+                LPC_IOCON->P0_5 |= (1<<0);
+//                if (_ws == p29)
+//                    LPC_PINCON->PINSEL0 |= (val1 << 10);
+//                else
+//                    LPC_PINCON->PINSEL1 |= (val2 << 16);
             }
 
             if (clk_d == true) {
-                if (_clk == p15)
-                    LPC_PINCON->PINSEL0 |= (val1 << 8);
-                else
-                    LPC_PINCON->PINSEL1 |= (val2 << 14);
+                LPC_IOCON->P0_4 |= (1<<0);
+//                if (_clk == p15)
+//                    LPC_PINCON->PINSEL0 |= (val1 << 8);
+//                else
+//                    LPC_PINCON->PINSEL1 |= (val2 << 14);
             }
         }
     }
@@ -540,31 +547,31 @@
         old_pre_den = pre_den;
         old_bitrate_div = bitrate_div;
     } else {
-        pre_num = old_pre_num;
-        pre_den = old_pre_den;
-        bitrate_div = old_bitrate_div;
+        pre_num = 0; //old_pre_num;
+        pre_den = 0; //old_pre_den;
+        bitrate_div = 1; //old_bitrate_div;
     }
 
     //Clock Multiplier, MCLK setup
     if (_rxtx == I2S_TRANSMIT) {
         int regvals = ((pre_num << 8) & 0xFF00) | (pre_den & 0xFF);
-        LPC_I2S->I2STXRATE = regvals;                // Setting the X/Y fraction
-        LPC_I2S->I2STXBITRATE = (bitrate_div - 1) & 0x3F;// Setting up the bitrate divider, the periferal adds one to this
+        LPC_I2S->TXRATE = regvals;                // Setting the X/Y fraction
+        LPC_I2S->TXBITRATE = (bitrate_div - 1) & 0x3F;// Setting up the bitrate divider, the periferal adds one to this
 
-        LPC_I2S->I2STXMODE = fourwire << 2;
+        LPC_I2S->TXMODE = fourwire << 2;
 
         if (mclk_d == true) {
-            LPC_I2S->I2STXMODE |= (1 << 3);
+            LPC_I2S->TXMODE |= (1 << 3);
         }
     } else {
         int regvals = ((pre_num << 8) & 0xFF00) | (pre_den & 0xFF);
-        LPC_I2S->I2SRXRATE = regvals;                // Setting the X/Y fraction
-        LPC_I2S->I2SRXBITRATE = (bitrate_div - 1) & 0x3F;// Setting up the bitrate divider, the periferal adds one to this
+        LPC_I2S->RXRATE = regvals;                // Setting the X/Y fraction
+        LPC_I2S->RXBITRATE = (bitrate_div - 1) & 0x3F;// Setting up the bitrate divider, the periferal adds one to this
 
-        LPC_I2S->I2SRXMODE = fourwire << 2;
+        LPC_I2S->RXMODE = fourwire << 2;
 
         if (mclk_d == true) {
-            LPC_I2S->I2SRXMODE |= (1 << 3);
+            LPC_I2S->RXMODE |= (1 << 3);
         }
     }
 
@@ -591,28 +598,28 @@
     I2SDA_reg |= ((muted << 15) & 0x8000);
 
     if (_rxtx == I2S_TRANSMIT) {
-        LPC_I2S->I2SDAO = I2SDA_reg;
+        LPC_I2S->DAO = I2SDA_reg;
     } else {
-        LPC_I2S->I2SDAI = I2SDA_reg;
+        LPC_I2S->DAI = I2SDA_reg;
     }
 
     if (_rxtx == I2S_TRANSMIT) {
         if (txisr) {
-            LPC_I2S->I2SIRQ = (LPC_I2S->I2SIRQ & 0xFF0FFFFF)
+            LPC_I2S->IRQ = (LPC_I2S->IRQ & 0xFF0FFFFF)
                               | ((interrupt_fifo_level & 0xF) << 16);
-            LPC_I2S->I2SIRQ |= 0x2;
+            LPC_I2S->IRQ |= 0x2;
         } else {
-            LPC_I2S->I2SIRQ &= 0xFFFFFFFD;
+            LPC_I2S->IRQ &= 0xFFFFFFFD;
         }
     } else {
         if (rxisr) {
-            LPC_I2S->I2SIRQ = (LPC_I2S->I2SIRQ & 0xFFFFF0FF)
+            LPC_I2S->IRQ = (LPC_I2S->IRQ & 0xFFFFF0FF)
                               | ((interrupt_fifo_level & 0xF) << 8);
-            LPC_I2S->I2SIRQ |= 0x1;
+            LPC_I2S->IRQ |= 0x1;
         }
 
         else {
-            LPC_I2S->I2SIRQ &= 0xFFFFFFFE;
+            LPC_I2S->IRQ &= 0xFFFFFFFE;
         }
     }
 }