|
1 |
| -/* |
2 |
| - i2s.h - Software I2S library for esp8266 |
3 |
| -
|
4 |
| - Copyright (c) 2015 Hristo Gochkov. All rights reserved. |
5 |
| - This file is part of the esp8266 core for Arduino environment. |
6 |
| - |
7 |
| - This library is free software; you can redistribute it and/or |
8 |
| - modify it under the terms of the GNU Lesser General Public |
9 |
| - License as published by the Free Software Foundation; either |
10 |
| - version 2.1 of the License, or (at your option) any later version. |
11 |
| -
|
12 |
| - This library is distributed in the hope that it will be useful, |
13 |
| - but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
| - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
| - Lesser General Public License for more details. |
16 |
| -
|
17 |
| - You should have received a copy of the GNU Lesser General Public |
18 |
| - License along with this library; if not, write to the Free Software |
19 |
| - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 |
| -*/ |
21 |
| -#ifndef I2S_h |
22 |
| -#define I2S_h |
23 |
| - |
24 |
| -#define I2S_HAS_BEGIN_RXTX_DRIVE_CLOCKS 1 |
25 |
| - |
26 |
| -/* |
27 |
| -How does this work? Basically, to get sound, you need to: |
28 |
| -- Connect an I2S codec to the I2S pins on the ESP. |
29 |
| -- Start up a thread that's going to do the sound output |
30 |
| -- Call i2s_set_bits() if you want to enable 24-bit mode |
31 |
| -- Call i2s_begin() |
32 |
| -- Call i2s_set_rate() with the sample rate you want. |
33 |
| -- Generate sound and call i2s_write_sample() with 32-bit samples. |
34 |
| -The 32bit samples basically are 2 16-bit signed values (the analog values for |
35 |
| -the left and right channel) concatenated as (Rout<<16)+Lout |
36 |
| -
|
37 |
| -i2s_write_sample will block when you're sending data too quickly, so you can just |
38 |
| -generate and push data as fast as you can and i2s_write_sample will regulate the |
39 |
| -speed. |
40 |
| -*/ |
41 |
| - |
42 |
| -#ifdef __cplusplus |
43 |
| -extern "C" { |
44 |
| -#endif |
45 |
| - |
46 |
| -bool i2s_set_bits(int bits); // Set bits per sample, only 16 or 24 supported. Call before begin. |
47 |
| -// Note that in 24 bit mode each sample must be left-aligned (i.e. 0x00000000 .. 0xffffff00) as the |
48 |
| -// hardware shifts starting at bit 31, not bit 23. |
49 |
| - |
50 |
| -void i2s_begin(); // Enable TX only, for compatibility |
51 |
| -bool i2s_rxtx_begin(bool enableRx, bool enableTx); // Allow TX and/or RX, returns false on OOM error |
52 |
| -bool i2s_rxtxdrive_begin(bool enableRx, bool enableTx, bool driveRxClocks, bool driveTxClocks); |
53 |
| -void i2s_end(); |
54 |
| -void i2s_set_rate(uint32_t rate);//Sample Rate in Hz (ex 44100, 48000) |
55 |
| -void i2s_set_dividers(uint8_t div1, uint8_t div2);//Direct control over output rate |
56 |
| -float i2s_get_real_rate();//The actual Sample Rate on output |
57 |
| -bool i2s_write_sample(uint32_t sample);//32bit sample with channels being upper and lower 16 bits (blocking when DMA is full) |
58 |
| -bool i2s_write_sample_nb(uint32_t sample);//same as above but does not block when DMA is full and returns false instead |
59 |
| -bool i2s_write_lr(int16_t left, int16_t right);//combines both channels and calls i2s_write_sample with the result |
60 |
| -bool i2s_read_sample(int16_t *left, int16_t *right, bool blocking); // RX data returned in both 16-bit outputs. |
61 |
| -bool i2s_is_full();//returns true if DMA is full and can not take more bytes (overflow) |
62 |
| -bool i2s_is_empty();//returns true if DMA is empty (underflow) |
63 |
| -bool i2s_rx_is_full(); |
64 |
| -bool i2s_rx_is_empty(); |
65 |
| -uint16_t i2s_available();// returns the number of samples than can be written before blocking |
66 |
| -uint16_t i2s_rx_available();// returns the number of samples than can be written before blocking |
67 |
| -void i2s_set_callback(void (*callback) (void)); |
68 |
| -void i2s_rx_set_callback(void (*callback) (void)); |
69 |
| - |
70 |
| -// writes a buffer of frames into the DMA memory, returns the amount of frames written |
71 |
| -// A frame is just a int16_t for mono, for stereo a frame is two int16_t, one for each channel. |
72 |
| -uint16_t i2s_write_buffer_mono(int16_t *frames, uint16_t frame_count); |
73 |
| -uint16_t i2s_write_buffer_mono_nb(int16_t *frames, uint16_t frame_count); |
74 |
| -uint16_t i2s_write_buffer(int16_t *frames, uint16_t frame_count); |
75 |
| -uint16_t i2s_write_buffer_nb(int16_t *frames, uint16_t frame_count); |
76 |
| - |
77 |
| -#ifdef __cplusplus |
78 |
| -} |
79 |
| -#endif |
80 |
| - |
81 |
| -#endif |
| 1 | +// This include file is a hack to ensure backward compatibility with |
| 2 | +// pre 3.0.0 versions of the core. There was a *lowercase* "i2s.h" |
| 3 | +// header which was in this directory, now renamed to "core_esp82i66s.h" |
| 4 | +// But, the I2S class has a header, "I2S.h" in uppercase. On Linux |
| 5 | +// the two names are different, but on Windows it's case-insensitive |
| 6 | +// so the names conflict. |
| 7 | +// |
| 8 | +// Avoid the issue by preserving the old i2s.h file and have it redirect |
| 9 | +// to I2S.h which will give the ESP8266-specific functions as well as |
| 10 | +// the generic I2S class. |
| 11 | + |
| 12 | +#include "../../libraries/I2S/src/I2S.h" |
0 commit comments