Skip to content

Add DMA support to I2S #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2016 Intel Corporation. All rights reserved.
* See the bottom of this file for the license terms.
*/

/**
* A simple sketch to test the rx channel of the i2s interface.
* A callback function is used to fill up a buffer whenever data is received
*
* To test this sketch you will need a second Arduino/Genuino 101 board with the I2SDMA_TxCallback sketch uploaded
*
* Connection:
* GND -> GND
* I2S_RSCK(pin 8) -> I2S_TSCK(pin 2)
* I2S_RWS(pin 3) -> I2S_TWS(pin 4)
* I2S_RXD(pin 5) -> I2S_TXD(pin 7)
*
**/
#include <CurieI2SDMA.h>

#define BUFF_SIZE 128
#define OFFSET 2
uint32_t dataBuff[BUFF_SIZE+OFFSET]; // extra 2 buffer is for the padding zero

uint8_t start_flag = 0;
uint8_t done_flag = 0;
uint32_t loop_count = 0;

void setup()
{
Serial.begin(115200);
while(!Serial);
Serial.println("CurieI2SDMA Rx Callback");

CurieI2SDMA.iniRX();
/*
* CurieI2SDMA.beginTX(sample_rate, resolution, master,mode)
* mode 1 : PHILIPS_MODE
* 2 : RIGHT_JST_MODE
* 3 : LEFT_JST_MODE
* 4 : DSP_MODE
*/
CurieI2SDMA.beginRX(44100, 32,0,1);

}

void loop()
{
int status = CurieI2SDMA.transRX(dataBuff,sizeof(dataBuff));
if(status)
return;

if(start_flag)
{
if((dataBuff[OFFSET]>>16) != loop_count+1)
Serial.println("+++ loop_count jump +++");
}
else
{
start_flag = 1;
}
loop_count = (dataBuff[OFFSET] >> 16);

done_flag = 1;
for(uint32_t i = 0 ;i < BUFF_SIZE;++i)
{
//Serial.println(dataBuff[i+OFFSET],HEX);
if ((dataBuff[i+OFFSET] & 0XFFFF0000) == (loop_count <<16)
&& (dataBuff[i+OFFSET] & 0XFFFF) == (i+1))
;
else
{
done_flag = 0;
Serial.println(dataBuff[i+OFFSET],HEX);
Serial.println("ERROR");
break;
}
}

if(done_flag)
Serial.println("RX done");
delay(100);
}

/*
Copyright (c) 2016 Intel Corporation. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-
1301 USA
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2016 Intel Corporation. All rights reserved.
* See the bottom of this file for the license terms.
*/

//I2S_TX -> Pin 7
//I2S_TSK -> Pin 4
//I2S_TSCK -> pin 2

#include <CurieI2SDMA.h>

#define BUFF_SIZE 128
boolean blinkState = true; // state of the LED
uint32_t dataBuff[BUFF_SIZE];
uint32_t loop_count = 0;
void setup()
{
Serial.begin(115200);
while(!Serial);
Serial.println("CurieI2SDMA Tx Callback");

CurieI2SDMA.iniTX();
/*
* CurieI2SDMA.beginTX(sample_rate, resolution, master,mode)
* mode 1 : PHILIPS_MODE
* 2 : RIGHT_JST_MODE
* 3 : LEFT_JST_MODE
* 4 : DSP_MODE
*/
CurieI2SDMA.beginTX(44100, 32,1, 1);
digitalWrite(13, blinkState);
}

void loop()
{
for(uint32_t i = 0; i <BUFF_SIZE; ++i)
{
dataBuff[i] = i + 1 + (loop_count<<16);
}
loop_count++;
int status = CurieI2SDMA.transTX(dataBuff,sizeof(dataBuff));
if(status)
return;

blinkState = !blinkState;
digitalWrite(13, blinkState);

//when the TX set to be slave, the two lines below will introduce delay.
//Please remove them.
Serial.println("done transmitting");
delay(1000);

}

/*
Copyright (c) 2016 Intel Corporation. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-
1301 USA
*/
106 changes: 58 additions & 48 deletions libraries/CurieI2S/keywords.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
#######################################
# Syntax Coloring Map For CurieI2S
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

Curie_I2S KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
start KEYWORD2
stop KEYWORD2
begin KEYWORD2
enableRX KEYWORD2
enableTX KEYWORD2
startRX KEYWORD2
startTX KEYWORD2
stopRX KEYWORD2
stopTX KEYWORD2
setI2SMode KEYWORD2
setResolution KEYWORD2
initRX KEYWORD2
initTX KEYWORD2
end KEYWORD2
pushData KEYWORD2
fastPushData KEYWORD2
write KEYWORD2
pullData KEYWORD2
read KEYWORD2
requestdword KEYWORD2
available KEYWORD2
availableTx KEYWORD2
attachRxInterrupt KEYWORD2
detachRxInterrupt KEYWORD2
attachTxInterrupt KEYWORD2
detachTxInterrupt KEYWORD2
#######################################
# Instances (KEYWORD2)
#######################################
CurieI2S KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
#######################################
# Syntax Coloring Map For CurieI2S CurieI2SDMA
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

Curie_I2S KEYWORD1

Curie_I2SDMA KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
start KEYWORD2
stop KEYWORD2
begin KEYWORD2
enableRX KEYWORD2
enableTX KEYWORD2
startRX KEYWORD2
startTX KEYWORD2
stopRX KEYWORD2
stopTX KEYWORD2
setI2SMode KEYWORD2
setResolution KEYWORD2
initRX KEYWORD2
initTX KEYWORD2
end KEYWORD2
pushData KEYWORD2
fastPushData KEYWORD2
write KEYWORD2
pullData KEYWORD2
read KEYWORD2
requestdword KEYWORD2
available KEYWORD2
availableTx KEYWORD2
attachRxInterrupt KEYWORD2
detachRxInterrupt KEYWORD2
attachTxInterrupt KEYWORD2
detachTxInterrupt KEYWORD2
attachTxEmptyInterrupt KEYWORD2
beginTX KEYWORD2
beginRX KEYWORD2
transTX KEYWORD2
transRX KEYWORD2
mergeData KEYWORD2
separateData KEYWORD2
#######################################
# Instances (KEYWORD2)
#######################################
CurieI2S KEYWORD2
CurieI2SDMA KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
Loading