This is an I2S library to allow people to take advantage of the I2S peripheral on the LPC1768. Ideally it will be included in future releases of the mbed.h file.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers I2S.h Source File

I2S.h

00001 #ifndef MBED_I2S_H
00002 #define MBED_I2S_H
00003 
00004 #include "mbed.h"
00005 
00006 /** An I2S class
00007  * It uses the I2S peripheral of the LPC1768
00008  * @author Pinski1
00009  * More details about the function goes here
00010  * 
00011  * An example:
00012  * @code
00013  * #include "I2S.h"
00014  * #include "mbed.h"
00015  * 
00016  * I2S audioInterface (p7, p6, p5, p30, p29, p8);
00017  *
00018  * void main()
00019  * {
00020  *      audioInterface.setClocks(,,,);
00021  *      audioInterface.setTx(32,9600000,true);
00022  *      audioInterface.setRx(32,9600000,true);
00023  *
00024  *      // now print out registers out to prove it's set up correctly
00025  * 
00026  * 
00027  * 
00028  * 
00029  * 
00030  * 
00031  * 
00032  * 
00033  * 
00034  * }
00035  * @endcode
00036  */
00037 class I2S
00038 {
00039     private:
00040         uint32_t masterClock;
00041         uint32_t peripheralClock;
00042         // fifoRx 0x400A800C
00043         // LPC_I2S->I2SRXFIFO
00044         // fifoTx 0x400A8008
00045         // LPC_I2S->I2STXFIFO
00046         
00047     public:
00048         /** Creates an I2S object to control the I2S peripheral.
00049          *
00050          * @param bitTx The bit clock pin used for transmitting I2S.
00051          * @param wdTx The word clock pin used for transmitting I2S.
00052          * @param daTx The data pin used for transmitting I2S.
00053          * @param bitRx The bit clock pin used for recieving I2S.
00054          * @param wdRx The word clock pin used for recieving I2S.
00055          * @param daRx The data clock pin used for recieving I2S.
00056          */
00057         I2S(PinName, PinName, PinName, PinName, PinName, PinName);
00058         
00059         /** Destructs the I2S object and turns off the I2S peripheral. */
00060         ~I2S();
00061         
00062         /** Sets up the clocks for the I2S peripheral.
00063          * Currents sets up both recieve and transmit channels identically.
00064          *
00065          * @param x The X divider for the perphieral clock which sets the I2S master clock.
00066          * @param y The Y divider for the perphieral clock which sets the I2S master clock.
00067          * @param divider The CPU clock divider that gives the peripheral clock.
00068          */
00069         void setClocks(uint8_t x, uint8_t y, uint8_t divider);
00070         
00071         /** Sets the bit clock and word clocks for the channels.
00072          *
00073          * @param resolution The bits per sample (8, 16 or 32).
00074          * @param rate The samples per second (16kHz to 96kHz).
00075          * @param stereo Whether the stream was stereo or mono.
00076          */
00077         void setTx(uint16_t resolution, uint16_t rate, bool stereo);
00078         void setRx(uint16_t resolution, uint16_t rate, bool stereo);
00079 
00080         /** Mutes or unmutes the transmit I2S channel. */
00081         void muteTx(void);
00082         /** Mutes or unmutes the receive I2S channel. */
00083         void muteRx(void);
00084         
00085         /** Resets the transmit I2S channel. */
00086         void resetTx(void);
00087         /** Resets the receive I2S channel. */
00088         void resetRx(void);
00089         
00090         /** Sets the I2S mode of the transmit channel.
00091          *
00092          * @param mode Sets the typical mode.
00093          */
00094         void setTxMode(uint8_t mode);
00095         /** Sets the I2S mode of the receive channel.
00096          *
00097          * @param mode Sets the typical mode.
00098          */
00099         void setRxMode(uint8_t mode);
00100         
00101         /** Sets up the Interrupt Requests
00102          *
00103          * @param rxInterrupt
00104          * @param txInterrupt
00105          * @param rxDepth
00106          * @param txDepth
00107          */
00108         void setIRQ(bool rxInterrupt, bool txInterrupt, uint8_t rxDepth, uint8_t txDepth);
00109         
00110         /** Sets up the DMA requests
00111          *
00112          * @param rxDMA
00113          * @param txDMA
00114          * @param rxDepth
00115          * @param txDepth
00116          */
00117         void setDMA1(bool rxDMA, bool txDMA, uint8_t rxDepth, uint8_t txDepth);
00118         void setDMA2(bool rxDMA, bool txDMA, uint8_t rxDepth, uint8_t txDepth);
00119 };
00120 #endif