supported LPC4088 original: http://mbed.org/users/d_worrall/code/I2SSlave/
Fork of I2SSlave by
Revision 5:9dfdde33be7e, committed 2014-01-08
- Comitter:
- okini3939
- Date:
- Wed Jan 08 05:20:45 2014 +0000
- Parent:
- 4:aa3e863920d2
- Commit message:
- supported LPC4088
Changed in this revision
I2SSlave.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r aa3e863920d2 -r 9dfdde33be7e I2SSlave.cpp --- a/I2SSlave.cpp Fri Aug 05 10:10:07 2011 +0000 +++ b/I2SSlave.cpp Wed Jan 08 05:20:45 2014 +0000 @@ -72,7 +72,11 @@ void I2SSlave::write(int* buffer, int from, int length){ int to = from + length; for(int i = from; i < to; ++i){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) LPC_I2S->I2STXFIFO = buffer[i]; +#elif defined(TARGET_LPC4088) + LPC_I2S->TXFIFO = buffer[i]; +#endif } } /****************************************************** @@ -84,6 +88,7 @@ * Returns: none ******************************************************/ void I2SSlave::start(int mode){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) switch(mode){ case(0): LPC_I2S->I2SIRQ |= (0 << 0); //disable receive interrupt @@ -107,7 +112,32 @@ break; default: break; +#elif defined(TARGET_LPC4088) + switch(mode){ + case(0): + LPC_I2S->IRQ |= (0 << 0); //disable receive interrupt + LPC_I2S->IRQ |= (0 << 1); //disable transmit interrupt + break; + case(1): + LPC_I2S->IRQ |= (0 << 0); //disable receive interrupt + LPC_I2S->IRQ |= (1 << 1); //enable transmit interrupt + LPC_I2S->IRQ |= (0 << 16); //set I2STXFIFO depth to 0 words + break; + case(2): + LPC_I2S->IRQ |= (1 << 0); //enable receive interrupt + LPC_I2S->IRQ |= (0 << 1); //disable transmit interrupt + LPC_I2S->IRQ |= (4 << 8); //set I2SRXFIFO depth to 4 words + break; + case(3): + LPC_I2S->IRQ |= (1 << 0); //enable receive interrupt + LPC_I2S->IRQ |= (4 << 8); //set I2SRXFIFO depth to 4 words + LPC_I2S->IRQ |= (1 << 1); //enable transmit interrupt + LPC_I2S->IRQ |= (0 << 16); //set I2STXFIFO depth to 0 words + break; + default: + break; } +#endif NVIC_SetPriority(I2S_IRQn, 0); NVIC_EnableIRQ(I2S_IRQn); //enable I2S interrupt in the NVIC } @@ -131,10 +161,17 @@ * Returns: none ******************************************************/ void I2SSlave::read(void){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) rxBuffer[0] = LPC_I2S->I2SRXFIFO; rxBuffer[1] = LPC_I2S->I2SRXFIFO; rxBuffer[2] = LPC_I2S->I2SRXFIFO; rxBuffer[3] = LPC_I2S->I2SRXFIFO; +#elif defined(TARGET_LPC4088) + rxBuffer[0] = LPC_I2S->RXFIFO; + rxBuffer[1] = LPC_I2S->RXFIFO; + rxBuffer[2] = LPC_I2S->RXFIFO; + rxBuffer[3] = LPC_I2S->RXFIFO; +#endif } /****************************************************** * Function name: status_() @@ -145,7 +182,11 @@ * Returns: int ******************************************************/ int I2SSlave::status(void){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) return LPC_I2S->I2SSTATE; +#elif defined(TARGET_LPC4088) + return LPC_I2S->STATE; +#endif } //Private functions /****************************************************** @@ -162,6 +203,7 @@ LPC_SC->PCONP |= (1 << 27); //configure input/output register format_(bit_, mode_); +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) //set mbed as SLAVE LPC_I2S->I2SDAO |= (1 << 5); LPC_I2S->I2SDAI |= (1 << 5); @@ -180,6 +222,26 @@ LPC_I2S->I2SDAO |= (0 << 4); LPC_I2S->I2SDAI |= (0 << 4); LPC_I2S->I2SDAO |= (0 << 15); +#elif defined(TARGET_LPC4088) + //set mbed as SLAVE + LPC_I2S->DAO |= (1 << 5); + LPC_I2S->DAI |= (1 << 5); + //clock mode + setClocks_(4); + //set slave mode + modeConfig_(); + //set receiver mode + LPC_I2S->RXMODE |= (1 << 1); + //slave mode + LPC_I2S->TXRATE = 0; + LPC_I2S->RXRATE = 0; + //Start + LPC_I2S->DAO |= (0 << 3); + LPC_I2S->DAI |= (0 << 3); + LPC_I2S->DAO |= (0 << 4); + LPC_I2S->DAI |= (0 << 4); + LPC_I2S->DAO |= (0 << 15); +#endif return 0; } /****************************************************** @@ -191,6 +253,7 @@ * Returns: nothing ******************************************************/ void I2SSlave::setClocks_(int divideBy){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) switch(divideBy){ case 1: LPC_SC->PCLKSEL1 |= (1 << 22); @@ -211,6 +274,28 @@ default: break; } +#elif defined(TARGET_LPC4088) + switch(divideBy){ + case 1: + LPC_SC->PCLKSEL |= (1 << 22); + LPC_SC->PCLKSEL |= (0 << 23); + break; + case 2: + LPC_SC->PCLKSEL |= (0 << 22); + LPC_SC->PCLKSEL |= (1 << 23); + break; + case 4: + LPC_SC->PCLKSEL |= (0 << 22); + LPC_SC->PCLKSEL |= (0 << 23); + break; + case 8: + LPC_SC->PCLKSEL |= (1 << 22); + LPC_SC->PCLKSEL |= (1 << 23); + break; + default: + break; + } +#endif } /****************************************************** * Function name: setPins_() @@ -221,6 +306,7 @@ * Returns: none ******************************************************/ void I2SSlave::setPins_(PinName tx_sda, PinName tx_ws, PinName clk, PinName rx_sda, PinName rx_ws){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) if(rx_ws == p29){ LPC_PINCON->PINSEL0 |= (1 << 10); //set p29 as receive word select line } else { @@ -235,6 +321,23 @@ LPC_PINCON->PINSEL0 |= (1 << 16); //set p6 as word select line (only one of these) LPC_PINCON->PINSEL0 |= (1 << 18); //set p5 as transmit serial data line (only one of these) LPC_PINCON->PINSEL0 |= (0 << 8); //clear rx_clk +#elif defined(TARGET_LPC4088) + if(rx_ws == p33){ + LPC_IOCON->P0_5 = (LPC_IOCON->P0_5 & ~7) | 1; //set p29 as receive word select line + } else { + LPC_IOCON->P0_24 = (LPC_IOCON->P0_24 & ~7) | 2; //set p16 as receive word select line + } + if(rx_sda == p14){ + LPC_IOCON->P0_6 = (LPC_IOCON->P0_6 & ~7) | 1; //set p14 as receive serial data line + } else { + LPC_IOCON->P0_25 = (LPC_IOCON->P0_25 & ~7) | 2; //set p17 as receive serial data line + } + LPC_IOCON->P0_7 = (LPC_IOCON->P0_7 & ~7) | 1; //set p13 as transmit clock line (only one of these) + LPC_IOCON->P0_8 = (LPC_IOCON->P0_8 & ~7) | 1; //set p6 as word select line (only one of these) + LPC_IOCON->P0_9 = (LPC_IOCON->P0_9 & ~7) | 1; //set p5 as transmit serial data line (only one of these) + LPC_IOCON->P0_23 = (LPC_IOCON->P0_4 & ~7); //clear rx_clk + LPC_IOCON->P0_23 = (LPC_IOCON->P0_23 & ~7); //clear rx_clk +#endif } /****************************************************** * Function name: format_() @@ -246,6 +349,7 @@ ******************************************************/ void I2SSlave::format_(int bit, bool mode){ uint32_t bps= ((bit+1)*8)-1; +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) LPC_I2S->I2SDAO &= (0x00 << 6); LPC_I2S->I2SDAO |= (bps << 6); //set bit length @@ -295,6 +399,57 @@ } else { LPC_I2S->I2SDAI |= (1 << 2); } +#elif defined(TARGET_LPC4088) + LPC_I2S->DAO &= (0x00 << 6); + LPC_I2S->DAO |= (bps << 6); + //set bit length + switch(bit){ + case 8: + LPC_I2S->DAO &= 0xfffffffc; + break; + case 16: + LPC_I2S->DAO &= (0 << 1); + LPC_I2S->DAO |= (1 << 0); + break; + case 32: + LPC_I2S->DAO &= (0 << 1); + LPC_I2S->DAO |= (3 << 0); + break; + default: + break; + } + //set audio mode + if(mode == STEREO){ + LPC_I2S->DAO |= (0 << 2); + } else { + LPC_I2S->DAO |= (1 << 2); + } + //set transmitter and receiver setting to be the same + LPC_I2S->DAI &= (0x00 << 6); + LPC_I2S->DAI |= (bps << 6); + //set bit length + switch(bit){ + case 8: + LPC_I2S->DAI &= 0xfffffffc; + break; + case 16: + LPC_I2S->DAI &= (0 << 1); + LPC_I2S->DAI |= (1 << 0); + break; + case 32: + LPC_I2S->DAI &= (0 << 1); + LPC_I2S->DAI |= (3 << 0); + break; + default: + break; + } + //set audio mode + if(mode == STEREO){ + LPC_I2S->DAI |= (0 << 2); + } else { + LPC_I2S->DAI |= (1 << 2); + } +#endif } /****************************************************** * Function name: modeConfig_() @@ -305,8 +460,13 @@ * Returns: none ******************************************************/ void I2SSlave::modeConfig_(void){ +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) LPC_I2S->I2STXMODE |= (0x0 << 0); LPC_I2S->I2SRXMODE |= (0x0 << 0); +#elif defined(TARGET_LPC4088) + LPC_I2S->TXMODE |= (0x0 << 0); + LPC_I2S->RXMODE |= (0x0 << 0); +#endif } /****************************************************** * Function name: storePins_()