Skip to content

Jira566 I2S DMA improvement: add two extra buffer on TX and RX side #230

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

Closed
wants to merge 1 commit into from
Closed
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
100 changes: 100 additions & 0 deletions libraries/CurieI2SDMA/examples/I2SDMA_RXCallBack/I2SDMA_RXCallBack.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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
uint32_t dataBuff[BUFF_SIZE+2]; // extra 2 buffer is for the padding zero

uint32_t OFFSET = 0;
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;
OFFSET = (dataBuff[0] == 0) ? 2 : 0;
}
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
*/
32 changes: 32 additions & 0 deletions libraries/CurieI2SDMA/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#######################################
# Syntax Coloring Map For CurieI2S
#######################################

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

Curie_I2SDMA KEYWORD1

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

beginTX KEYWORD2
beginRX KEYWORD2
iniTX KEYWORD2
iniRX KEYWORD2
transTX KEYWORD2
transRX KEYWORD2
stopTX KEYWORD2
stopRX KEYWORD2
mergeData KEYWORD2
separateData KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################
CurieI2SDMA KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
11 changes: 11 additions & 0 deletions libraries/CurieI2SDMA/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=CurieI2SDMA
version=1.0
author=Intel
maintainer=Intel
email=dino.tinitigan@intel.com
sentence=Curie I2S DMA Library for Arduino/Genuino 101
paragraph=
category=Communication
url=http://makers.intel.com
architectures=arc32
core-dependencies=arduino (>=1.6.3)
Loading