Skip to content

Feature: I2S callback on DMA read #4205

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 23 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
33a3112
Fix I2S base frequency
Crypter Dec 27, 2017
d1496a4
Merge pull request #1 from Crypter/hotfix/i2s_frequency
Crypter Dec 27, 2017
f335b28
Update frequency dividers for I2S
Crypter Dec 27, 2017
b07cc34
Merge branch 'master' into master
earlephilhower Jan 15, 2018
a380742
Merge branch 'master' into master
Crypter Jan 17, 2018
941e68e
fixed i2s_set_rate, added i2s_get_real_rate() and i2s_set_dividers
Jan 17, 2018
b56bc49
Minimise float calculations
Crypter Jan 18, 2018
6df60c4
Merge branch 'master' into master
Crypter Jan 18, 2018
f5d676a
Merge branch 'master' into master
earlephilhower Jan 20, 2018
f67cff8
Merge branch 'master' into master
earlephilhower Jan 20, 2018
f2c9841
added optional callback after every DMA interrupt for better timing c…
Jan 21, 2018
bdc2d40
Merge branch 'master' into i2s-isr
Jan 21, 2018
a469864
Merge branch 'master' into i2s-isr
Jan 21, 2018
30bae68
Merge branch 'master' into i2s-isr
Crypter Jan 21, 2018
d964f8e
Merge branch 'master' into i2s-isr
Crypter Feb 2, 2018
da855ed
Merge branch 'master' into i2s-isr
Crypter Feb 5, 2018
6c4b75f
Merge branch 'master' into i2s-isr
Crypter Feb 8, 2018
8428695
Merge branch 'master' into i2s-isr
Crypter Feb 20, 2018
126a79f
Merge branch 'master' into i2s-isr
Crypter Feb 25, 2018
88778cf
Merge branch 'master' into i2s-isr
earlephilhower Mar 9, 2018
aad4453
Removed function from IRAM, added comment for better clarity
Mar 18, 2018
751b5db
Merge branch 'master' into i2s-isr
Crypter Mar 18, 2018
db9b12e
Merge branch 'master' into i2s-isr
earlephilhower Mar 19, 2018
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
7 changes: 6 additions & 1 deletion cores/esp8266/core_esp8266_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static uint32_t *i2s_slc_buf_pntr[SLC_BUF_CNT]; //Pointer to the I2S DMA buffer
static struct slc_queue_item i2s_slc_items[SLC_BUF_CNT]; //I2S DMA buffer descriptors
static uint32_t *i2s_curr_slc_buf=NULL;//current buffer for writing
static int i2s_curr_slc_buf_pos=0; //position in the current buffer
static void (*i2s_callback) (void)=0; //Callback function should be defined as 'void ICACHE_FLASH_ATTR function_name()', placing the function in IRAM for faster execution. Avoid long computational tasks in this function, use it to set flags and process later.

bool ICACHE_FLASH_ATTR i2s_is_full(){
return (i2s_curr_slc_buf_pos==SLC_BUF_LEN || i2s_curr_slc_buf==NULL) && (i2s_slc_queue_len == 0);
Expand Down Expand Up @@ -92,10 +93,15 @@ void ICACHE_FLASH_ATTR i2s_slc_isr(void) {
i2s_slc_queue_next_item(); //free space for finished_item
}
i2s_slc_queue[i2s_slc_queue_len++] = finished_item->buf_ptr;
if (i2s_callback) i2s_callback();
ETS_SLC_INTR_ENABLE();
}
}

void i2s_set_callback(void (*callback) (void)){
i2s_callback = callback;
}

void ICACHE_FLASH_ATTR i2s_slc_begin(){
i2s_slc_queue_len = 0;
int x, y;
Expand Down Expand Up @@ -248,7 +254,6 @@ float ICACHE_FLASH_ATTR i2s_get_real_rate(){
return (float)I2SBASEFREQ/32/((I2SC>>I2SBD) & I2SBDM)/((I2SC >> I2SCD) & I2SCDM);
}


void ICACHE_FLASH_ATTR i2s_begin(){
_i2s_sample_rate = 0;
i2s_slc_begin();
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool i2s_write_lr(int16_t left, int16_t right);//combines both channels and call
bool i2s_is_full();//returns true if DMA is full and can not take more bytes (overflow)
bool i2s_is_empty();//returns true if DMA is empty (underflow)
int16_t i2s_available();// returns the number of samples than can be written before blocking
void i2s_set_callback(void (*callback) (void));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(continuing prior thought)
The actual callback function passed in, though, needs to be in IRAM. A comment in the code to that effect would be appreciated here, so it's obvious to people coming into it that it's an ISR and needs to be very special...


#ifdef __cplusplus
}
Expand Down