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.

Committer:
Pinski1
Date:
Mon Dec 06 00:05:39 2010 +0000
Revision:
0:0408d1e354e7
An initial release, not fully tested.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pinski1 0:0408d1e354e7 1 #ifndef MBED_I2S_H
Pinski1 0:0408d1e354e7 2 #define MBED_I2S_H
Pinski1 0:0408d1e354e7 3
Pinski1 0:0408d1e354e7 4 #include "mbed.h"
Pinski1 0:0408d1e354e7 5
Pinski1 0:0408d1e354e7 6 /** An I2S class
Pinski1 0:0408d1e354e7 7 * It uses the I2S peripheral of the LPC1768
Pinski1 0:0408d1e354e7 8 * @author Pinski1
Pinski1 0:0408d1e354e7 9 * More details about the function goes here
Pinski1 0:0408d1e354e7 10 *
Pinski1 0:0408d1e354e7 11 * An example:
Pinski1 0:0408d1e354e7 12 * @code
Pinski1 0:0408d1e354e7 13 * #include "I2S.h"
Pinski1 0:0408d1e354e7 14 * #include "mbed.h"
Pinski1 0:0408d1e354e7 15 *
Pinski1 0:0408d1e354e7 16 * I2S audioInterface (p7, p6, p5, p30, p29, p8);
Pinski1 0:0408d1e354e7 17 *
Pinski1 0:0408d1e354e7 18 * void main()
Pinski1 0:0408d1e354e7 19 * {
Pinski1 0:0408d1e354e7 20 * audioInterface.setClocks(,,,);
Pinski1 0:0408d1e354e7 21 * audioInterface.setTx(32,9600000,true);
Pinski1 0:0408d1e354e7 22 * audioInterface.setRx(32,9600000,true);
Pinski1 0:0408d1e354e7 23 *
Pinski1 0:0408d1e354e7 24 * // now print out registers out to prove it's set up correctly
Pinski1 0:0408d1e354e7 25 *
Pinski1 0:0408d1e354e7 26 *
Pinski1 0:0408d1e354e7 27 *
Pinski1 0:0408d1e354e7 28 *
Pinski1 0:0408d1e354e7 29 *
Pinski1 0:0408d1e354e7 30 *
Pinski1 0:0408d1e354e7 31 *
Pinski1 0:0408d1e354e7 32 *
Pinski1 0:0408d1e354e7 33 *
Pinski1 0:0408d1e354e7 34 * }
Pinski1 0:0408d1e354e7 35 * @endcode
Pinski1 0:0408d1e354e7 36 */
Pinski1 0:0408d1e354e7 37 class I2S
Pinski1 0:0408d1e354e7 38 {
Pinski1 0:0408d1e354e7 39 private:
Pinski1 0:0408d1e354e7 40 uint32_t masterClock;
Pinski1 0:0408d1e354e7 41 uint32_t peripheralClock;
Pinski1 0:0408d1e354e7 42 // fifoRx 0x400A800C
Pinski1 0:0408d1e354e7 43 // LPC_I2S->I2SRXFIFO
Pinski1 0:0408d1e354e7 44 // fifoTx 0x400A8008
Pinski1 0:0408d1e354e7 45 // LPC_I2S->I2STXFIFO
Pinski1 0:0408d1e354e7 46
Pinski1 0:0408d1e354e7 47 public:
Pinski1 0:0408d1e354e7 48 /** Creates an I2S object to control the I2S peripheral.
Pinski1 0:0408d1e354e7 49 *
Pinski1 0:0408d1e354e7 50 * @param bitTx The bit clock pin used for transmitting I2S.
Pinski1 0:0408d1e354e7 51 * @param wdTx The word clock pin used for transmitting I2S.
Pinski1 0:0408d1e354e7 52 * @param daTx The data pin used for transmitting I2S.
Pinski1 0:0408d1e354e7 53 * @param bitRx The bit clock pin used for recieving I2S.
Pinski1 0:0408d1e354e7 54 * @param wdRx The word clock pin used for recieving I2S.
Pinski1 0:0408d1e354e7 55 * @param daRx The data clock pin used for recieving I2S.
Pinski1 0:0408d1e354e7 56 */
Pinski1 0:0408d1e354e7 57 I2S(PinName, PinName, PinName, PinName, PinName, PinName);
Pinski1 0:0408d1e354e7 58
Pinski1 0:0408d1e354e7 59 /** Destructs the I2S object and turns off the I2S peripheral. */
Pinski1 0:0408d1e354e7 60 ~I2S();
Pinski1 0:0408d1e354e7 61
Pinski1 0:0408d1e354e7 62 /** Sets up the clocks for the I2S peripheral.
Pinski1 0:0408d1e354e7 63 * Currents sets up both recieve and transmit channels identically.
Pinski1 0:0408d1e354e7 64 *
Pinski1 0:0408d1e354e7 65 * @param x The X divider for the perphieral clock which sets the I2S master clock.
Pinski1 0:0408d1e354e7 66 * @param y The Y divider for the perphieral clock which sets the I2S master clock.
Pinski1 0:0408d1e354e7 67 * @param divider The CPU clock divider that gives the peripheral clock.
Pinski1 0:0408d1e354e7 68 */
Pinski1 0:0408d1e354e7 69 void setClocks(uint8_t x, uint8_t y, uint8_t divider);
Pinski1 0:0408d1e354e7 70
Pinski1 0:0408d1e354e7 71 /** Sets the bit clock and word clocks for the channels.
Pinski1 0:0408d1e354e7 72 *
Pinski1 0:0408d1e354e7 73 * @param resolution The bits per sample (8, 16 or 32).
Pinski1 0:0408d1e354e7 74 * @param rate The samples per second (16kHz to 96kHz).
Pinski1 0:0408d1e354e7 75 * @param stereo Whether the stream was stereo or mono.
Pinski1 0:0408d1e354e7 76 */
Pinski1 0:0408d1e354e7 77 void setTx(uint16_t resolution, uint16_t rate, bool stereo);
Pinski1 0:0408d1e354e7 78 void setRx(uint16_t resolution, uint16_t rate, bool stereo);
Pinski1 0:0408d1e354e7 79
Pinski1 0:0408d1e354e7 80 /** Mutes or unmutes the transmit I2S channel. */
Pinski1 0:0408d1e354e7 81 void muteTx(void);
Pinski1 0:0408d1e354e7 82 /** Mutes or unmutes the receive I2S channel. */
Pinski1 0:0408d1e354e7 83 void muteRx(void);
Pinski1 0:0408d1e354e7 84
Pinski1 0:0408d1e354e7 85 /** Resets the transmit I2S channel. */
Pinski1 0:0408d1e354e7 86 void resetTx(void);
Pinski1 0:0408d1e354e7 87 /** Resets the receive I2S channel. */
Pinski1 0:0408d1e354e7 88 void resetRx(void);
Pinski1 0:0408d1e354e7 89
Pinski1 0:0408d1e354e7 90 /** Sets the I2S mode of the transmit channel.
Pinski1 0:0408d1e354e7 91 *
Pinski1 0:0408d1e354e7 92 * @param mode Sets the typical mode.
Pinski1 0:0408d1e354e7 93 */
Pinski1 0:0408d1e354e7 94 void setTxMode(uint8_t mode);
Pinski1 0:0408d1e354e7 95 /** Sets the I2S mode of the receive channel.
Pinski1 0:0408d1e354e7 96 *
Pinski1 0:0408d1e354e7 97 * @param mode Sets the typical mode.
Pinski1 0:0408d1e354e7 98 */
Pinski1 0:0408d1e354e7 99 void setRxMode(uint8_t mode);
Pinski1 0:0408d1e354e7 100
Pinski1 0:0408d1e354e7 101 /** Sets up the Interrupt Requests
Pinski1 0:0408d1e354e7 102 *
Pinski1 0:0408d1e354e7 103 * @param rxInterrupt
Pinski1 0:0408d1e354e7 104 * @param txInterrupt
Pinski1 0:0408d1e354e7 105 * @param rxDepth
Pinski1 0:0408d1e354e7 106 * @param txDepth
Pinski1 0:0408d1e354e7 107 */
Pinski1 0:0408d1e354e7 108 void setIRQ(bool rxInterrupt, bool txInterrupt, uint8_t rxDepth, uint8_t txDepth);
Pinski1 0:0408d1e354e7 109
Pinski1 0:0408d1e354e7 110 /** Sets up the DMA requests
Pinski1 0:0408d1e354e7 111 *
Pinski1 0:0408d1e354e7 112 * @param rxDMA
Pinski1 0:0408d1e354e7 113 * @param txDMA
Pinski1 0:0408d1e354e7 114 * @param rxDepth
Pinski1 0:0408d1e354e7 115 * @param txDepth
Pinski1 0:0408d1e354e7 116 */
Pinski1 0:0408d1e354e7 117 void setDMA1(bool rxDMA, bool txDMA, uint8_t rxDepth, uint8_t txDepth);
Pinski1 0:0408d1e354e7 118 void setDMA2(bool rxDMA, bool txDMA, uint8_t rxDepth, uint8_t txDepth);
Pinski1 0:0408d1e354e7 119 };
Pinski1 0:0408d1e354e7 120 #endif