Dependents: playback FTSESpeech i2s_audio_echo i2s_audio_sampler ... more
I2SSlave.h
00001 /** 00002 * @author Daniel Worrall 00003 * 00004 * @section LICENSE 00005 * 00006 * Copyright (c) 2011 mbed 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 * @section DESCRIPTION 00027 * I2S port abstraction library h file for NXP LPC1768 00028 * 00029 */ 00030 00031 #include "mbed.h" 00032 #include "math.h" 00033 00034 #ifndef __MBED_I2SSLAVE_H__ 00035 #define __MBED_I2SSLAVE_H__ 00036 00037 extern FunctionPointer akjnh3489v8ncv; 00038 00039 /** I2S class defined on the LPC1768 port 00040 * 00041 */ 00042 class I2SSlave{ 00043 00044 public: 00045 //Constructor 00046 /** Create an I2S object 00047 * 00048 * @param tx_sda Transmitter serial data line 00049 * @param tx_ws Transmitter word select line 00050 * @param clk Shared transmitter/receiver clock line 00051 * @param rx_sda Receiver serial data line 00052 * @param rx_ws Receiver word select line 00053 */ 00054 I2SSlave(PinName tx_sda, PinName tx_ws, PinName clk, PinName rx_sda, PinName rx_ws); 00055 /** Set the data transmission format 00056 * 00057 * @param bit Set the number of bits per write 00058 * @param mode Set STEREO (0) or MONO (1) mode 00059 */ 00060 void format(int bit, bool mode); 00061 /** Write a buffer to the I2S port 00062 * 00063 * @param buffer Address of buffer to pass to I2S port 00064 * @param from Start position in buffer to read from 00065 * @param length Length of buffer (MUST not exceed 8 words, each 32 bits long) 00066 * 00067 * Note: sending 8 words to the TXFIFO will trigger an interrupt! 00068 */ 00069 void write(int* buffer, int from, int length); 00070 /** Activate I2S port for data streaming 00071 * 00072 * @param mode Mode to enable - NONE, TRANSMIT only, RECEIVE only, BOTH 00073 * Enables tx/rx interrupts 00074 */ 00075 void start(int mode); 00076 /** Deactivate I2S port from data streaming 00077 * 00078 * Disable all interrupts 00079 */ 00080 void stop(void); 00081 /** Load receive FIFO data into receiver buffer 00082 * 00083 */ 00084 void read(void); 00085 /** Attach a void/void function or void/void static memeber function to an interrupt generated by the I2SxxFIFOs 00086 * 00087 * @param function Function to attach 00088 * 00089 * <code> myI2sObject.attach(&myfunction); </code> 00090 * OR <code> myI2sObject.attach(&myClass::myStaticMemberFunction); </code> 00091 */ 00092 void attach(void(*fptr)(void)){ 00093 akjnh3489v8ncv.attach(fptr); 00094 } 00095 /** Attach a nonstatic void/void member function to an interrupt generated by the I2SxxFIFOs 00096 * 00097 * @param tptr Object pointer 00098 * @param mptr Member function pointer 00099 * 00100 * e.g. <code>myI2sObject.attach(&myObject, &myClass::myNonstaticMemberFunction); </code>where myObject is an object of myClass 00101 */ 00102 template<typename T> 00103 void attach(T *tptr, void(T::*mptr)(void)){ 00104 akjnh3489v8ncv.attach(tptr, mptr); 00105 } 00106 /** Return contents of I2S status register 00107 * 00108 * @returns Content of I2SSTATE register 00109 * 00110 * bit0: receive/transmit interrupt active 00111 * bit1: receive/transmit DMA request 1 00112 * bit2: receive/transmit DMA request 2 00113 * bit[11:8]: receive FIFO level 00114 * bit[19:16]: transmit FIFO level 00115 */ 00116 int status(void); 00117 00118 //Receiver buffer 00119 int rxBuffer[4]; 00120 //defines 00121 #define STEREO 0 00122 #define MONO 1 00123 00124 #define I2SFIFO_EMPTY 0 00125 #define I2SFIFO_FULL 8 00126 00127 #define RAM_LENGTH 1024 00128 #define RAM_LIMIT (RAM_LENGTH - 1) 00129 #define PTR_MAX ((RAM_LENGTH / 8) - 1) 00130 00131 #define NONE 0 00132 #define TRANSMIT 1 00133 #define RECEIVE 2 00134 #define BOTH 3 00135 00136 private: 00137 /** I2S intitalize function 00138 * 00139 * @param tx_sda Transmitter serial data line 00140 * @param tx_ws Transmitter word select line 00141 * @param clk Shared transmitter/receiver clock line 00142 * @param rx_sda Receiver serial data line 00143 * @param rx_ws Receiver word select line 00144 * @return Returns 0 for successful initialisation, -1 for an error 00145 */ 00146 int initialize_(PinName tx_sda, PinName tx_ws, PinName clk, PinName rx_sda, PinName rx_ws); 00147 /** Set internal clock divide by rate 00148 * 00149 * @param divideBy Divide by 1, 2, 4 or 8 00150 */ 00151 void setClocks_(int divideBy); 00152 /** Set up the pins on the processor itself 00153 * 00154 * @param tx_sda Transmitter serial data line 00155 * @param tx_ws Transmitter word select line 00156 * @param clk Shared transmitter/receiver clock line 00157 * @param rx_sda Receiver serial data line 00158 * @param rx_ws Receiver word select line 00159 */ 00160 void setPins_(PinName tx_sda, PinName tx_ws, PinName clk, PinName rx_sda, PinName rx_ws); 00161 /** Set the data transmission format 00162 * 00163 * @param bit Set the number of bits per write 00164 * @param mode Set STEREO (0) or MONO (1) mode 00165 */ 00166 void format_(int bit, bool mode); 00167 /** Set slave mode 00168 * 00169 */ 00170 void modeConfig_(void); 00171 /** Store PinName values 00172 * 00173 * @param tx_sda Transmitter serial data line 00174 * @param tx_ws Transmitter word select line 00175 * @param clk Shared transmitter/receiver clock line 00176 * @param rx_sda Receiver serial data line 00177 * @param rx_ws Receiver word select line 00178 */ 00179 void storePins_(PinName tx_sda, PinName tx_ws, PinName clk, PinName rx_sda, PinName rx_ws); 00180 //variables 00181 int bit_; 00182 bool mode_; 00183 PinName tx_sda_; 00184 PinName tx_ws_; 00185 PinName clk_; 00186 PinName rx_sda_; 00187 PinName rx_ws_; 00188 }; 00189 00190 #endif /*__MBED_I2S_H__*/
Generated on Tue Jul 12 2022 18:43:37 by 1.7.2