Skip to content

Commit a6e612e

Browse files
committed
docs: Document API changes and new classes.
Signed-off-by: iabdalkader <[email protected]>
1 parent 7171488 commit a6e612e

File tree

2 files changed

+286
-25
lines changed

2 files changed

+286
-25
lines changed

docs/api.md

+245-16
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ Nothing.
2323
### `begin()`
2424

2525

26-
Initializes the ADC with the specific parameters. The `begin()` method is firstly used to initialize the library.
27-
28-
If reconfigured during program execution, use `stop()` first.
26+
Initializes the ADC with the specified parameters. If reconfiguration is needed during program execution, `stop()` should be called first.
2927

3028
#### Syntax
3129

@@ -35,15 +33,25 @@ adc0.begin(resolution, sample_rate, n_samples, n_buffers)
3533

3634
#### Parameters
3735

38-
- `enum` - analog read resolution (choose from 8, 10, 12, 14, 16 bit).
36+
- `enum` - **resolution** the ADC resolution (can be 8, 10, 12, 14 or 16 bit).
3937
- `AN_RESOLUTION_8`
4038
- `AN_RESOLUTION_10`
4139
- `AN_RESOLUTION_12`
4240
- `AN_RESOLUTION_14`
4341
- `AN_RESOLUTION_16`
4442
- `int` - **sample_rate** - the sample rate / frequency in Hertz, e.g. `16000`.
45-
- `int` - **n_samples** - number of samples we want to acquire, e.g. `32`. When reading the ADC, we store these samples into a specific buffer (see [SampleBuffer](#samplebuffer)), and read them via `buffer[x]`, where `x` is the sample you want to retrieve.
43+
- `int` - **n_samples** - number of samples per buffer, e.g. `32`. When reading the ADC, we store these samples into a specific buffer (see [SampleBuffer](#samplebuffer)), and read them via `buffer[x]`, where `x` is the sample you want to retrieve.
4644
- `int` - **n_buffers** - the number of buffers in the queue.
45+
- `bool` - **start** - if true, the ADC will start sampling immediately (the default is true).
46+
- `enum` - **sample_time** - the ADC sampling time in cycles (the default is 8.5 cycles).
47+
- `AN_ADC_SAMPLETIME_1_5`
48+
- `AN_ADC_SAMPLETIME_2_5`
49+
- `AN_ADC_SAMPLETIME_8_5`
50+
- `AN_ADC_SAMPLETIME_16_5`
51+
- `AN_ADC_SAMPLETIME_32_5`
52+
- `AN_ADC_SAMPLETIME_64_5`
53+
- `AN_ADC_SAMPLETIME_387_5`
54+
- `AN_ADC_SAMPLETIME_810_5`
4755

4856
#### Returns
4957

@@ -73,7 +81,7 @@ Reads the first available byte in the buffer.
7381

7482
### `stop()`
7583

76-
Stops the ADC and buffer transfer, and releases any memory allocated for the buffer array.
84+
Stops the ADC and releases all of its resources.
7785

7886
#### Syntax
7987

@@ -85,6 +93,67 @@ adc.stop()
8593

8694
- `1`
8795

96+
## AdvancedADCDual
97+
98+
### `AdvancedADCDual`
99+
100+
The AdvancedADCDual class enables the configuration of two ADCs in Dual ADC mode. In this mode, the two ADCs are synchronized, with one ADC acting as the master ADC and controlling the other. Note: This mode is only supported on ADC1 and ADC2, and they must be passed in that order.
101+
102+
#### Syntax
103+
104+
```
105+
AdvancedADCDual adc_dual(adc1, adc2);
106+
```
107+
108+
#### Parameters
109+
110+
- `AdvancedADC` - **adc1** - the first ADC. Note this must be ADC1.
111+
- `AdvancedADC` - **adc2** - the second ADC. Note this must be ADC2.
112+
113+
#### Returns
114+
115+
Nothing.
116+
117+
### `begin()`
118+
119+
Initialize and start the two ADCs with the specified parameters.
120+
121+
#### Syntax
122+
123+
```
124+
adc_dual.begin(resolution, sample_rate, n_samples, n_buffers)
125+
```
126+
127+
#### Parameters
128+
129+
- `enum` - **resolution** the ADC resolution (can be 8, 10, 12, 14 or 16 bit).
130+
- `AN_RESOLUTION_8`
131+
- `AN_RESOLUTION_10`
132+
- `AN_RESOLUTION_12`
133+
- `AN_RESOLUTION_14`
134+
- `AN_RESOLUTION_16`
135+
- `int` - **sample_rate** - the sample rate / frequency in Hertz, e.g. `16000`.
136+
- `int` - **n_samples** - number of samples per buffer, e.g. `32`. When reading the ADC, we store these samples into a specific buffer (see [SampleBuffer](#samplebuffer)), and read them via `buffer[x]`, where `x` is the sample you want to retrieve.
137+
- `int` - **n_buffers** - the number of buffers in the queue.
138+
- `bool` - **start** - if true, the ADC will start sampling immediately (the default is true).
139+
- `enum` - **sample_time** - the ADC sampling time in cycles (the default is 8.5 cycles).
140+
- `AN_ADC_SAMPLETIME_1_5`
141+
- `AN_ADC_SAMPLETIME_2_5`
142+
- `AN_ADC_SAMPLETIME_8_5`
143+
- `AN_ADC_SAMPLETIME_16_5`
144+
- `AN_ADC_SAMPLETIME_32_5`
145+
- `AN_ADC_SAMPLETIME_64_5`
146+
- `AN_ADC_SAMPLETIME_387_5`
147+
- `AN_ADC_SAMPLETIME_810_5`
148+
149+
#### Returns
150+
151+
1 on success, 0 on failure.
152+
153+
### `stop()`
154+
155+
Stops the two ADCs and releases all of their resources.
156+
88157
## AdvancedDAC
89158

90159
### `AdvancedDAC`
@@ -109,10 +178,7 @@ Nothing.
109178

110179
### `begin()`
111180

112-
113-
Initializes the DAC with the specific parameters. The `begin()` method is firstly used to initialize the library.
114-
115-
If reconfigured during program execution, use `stop()` first.
181+
Initializes the DAC with the specified parameters. If reconfiguration is needed during program execution, `stop()` should be called first.
116182

117183
#### Syntax
118184

@@ -127,7 +193,7 @@ dac0.begin(resolution, frequency, n_samples, n_buffers)
127193
- `AN_RESOLUTION_10`
128194
- `AN_RESOLUTION_12`
129195
- `int` - **frequency** - the frequency in Hertz, e.g. `8000`.
130-
- `int` - **n_samples** - number of samples we want to write, e.g. `32`. When writing to the DAC, we first write the samples into a buffer (see [SampleBuffer](#samplebuffer)), and write it to the DAC using `dac_out.write(buf)`.
196+
- `int` - **n_samples** - number of samples per buffer, e.g. `32`. When writing to the DAC, we first write the samples into a buffer (see [SampleBuffer](#samplebuffer)), and write it to the DAC using `dac_out.write(buf)`.
131197
- `int` - **n_buffers** - the number of buffers in the queue.
132198

133199

@@ -188,7 +254,7 @@ dac1.write(buf);
188254

189255
### `stop()`
190256

191-
Stops the DAC timer and buffer transfer, and releases any memory allocated for the buffer array.
257+
Stops the DAC and releases all of its resources.
192258

193259
#### Syntax
194260

@@ -216,7 +282,170 @@ dac.frequency(frequency);
216282

217283
- `int` - frequency in Hertz (Hz).
218284

285+
## AdvancedI2S
286+
287+
### `AdvancedI2S`
288+
289+
Creates an I2S object using the provided pins.
290+
291+
#### Syntax
292+
293+
```
294+
AdvancedI2S i2s(WS, CK, SDI, SDO, MCK);
295+
```
296+
297+
#### Parameters
298+
299+
- `WS` I2S word select (LR clock).
300+
- `CK` I2S bit-clock (BRCLK clock).
301+
- `SDI` I2S data input (can be `NC` in half-duplex output mode).
302+
- `SDO` I2S data output (can be `NC` in half-duplex input mode).
303+
- `MCK` Master clock (can be `NC` if no MCLK is required).
304+
305+
#### Returns
306+
307+
Nothing.
308+
309+
### `begin()`
310+
311+
Initialize and start the I2S device.
312+
313+
#### Syntax
314+
315+
```
316+
i2s.begin(mode, resolution, frequency, n_samples, n_buffers)
317+
```
318+
319+
#### Parameters
320+
321+
- `enum` - **mode** - The I2S mode.
322+
- `AN_I2S_MODE_IN`
323+
- `AN_I2S_MODE_OUT`
324+
- `AN_I2S_MODE_INOUT`
325+
- `int` - **sample_rate** - The sample rate / frequency in Hertz, e.g. `16000`.
326+
- `int` - **n_samples** - The number of samples per buffer (i.e, buffer width).
327+
- `int` - **n_buffers** - The number of buffers in the sample queue (i.e, queue depth).
328+
329+
#### Returns
330+
331+
1 on success, 0 on failure.
332+
333+
### `available()`
334+
335+
Checks if the I2S is readable, writable or both (in full-duplex mode).
336+
337+
#### Syntax
338+
339+
```
340+
if(i2s.available()){}
341+
```
342+
343+
#### Parameters
344+
345+
None.
346+
347+
#### Returns
348+
349+
True if I2S is readable, writable or both (in full-duplex mode), false if not.
350+
351+
### `read()`
352+
353+
Returns a sample buffer from the queue for reading. This function can be called in half-duplex input or full-duplex modes. When the code is done with the buffer, it should be returned to I2S by calling `release()` (see [SampleBuffer](#release))
354+
355+
#### Syntax
356+
357+
```
358+
SampleBuffer buf = i2s.read();
359+
360+
for (size_t i=0; i<buf.size(); i++) {
361+
Serial.println(buf[i]);
362+
}
363+
364+
i2s.release(buf);
365+
```
366+
367+
### `dequeue()`
368+
369+
Returns a sample buffer from the queue for writing. This function can be called in half-duplex output or full-duplex modes. When the code is done with the buffer, it should be written out to I2S by calling `write()` (see [I2S](#write))
370+
371+
#### Syntax
372+
373+
```
374+
SampleBuffer buf = dac.dequeue();
375+
376+
for (size_t i=0; i<buf.size(); i++) {
377+
buf[i] = SAMPLES_BUFFER[i];
378+
}
379+
380+
dac1.write(buf);
381+
```
382+
383+
### `write()`
384+
385+
Writes the buffer to I2S.
386+
387+
#### Syntax
388+
389+
```
390+
i2s.write(buf);
391+
```
392+
393+
#### Parameters
394+
395+
- A buffer containing the samples (see [SampleBuffer](#samplebuffer)).
219396

397+
### `stop()`
398+
399+
Stops the I2S and releases all of its resources.
400+
401+
#### Syntax
402+
403+
```
404+
i2s.stop()
405+
```
406+
407+
#### Returns
408+
409+
- `1`
410+
411+
## WavReader
412+
413+
### `WavReader`
414+
415+
Creates a WAV file reader.
416+
417+
### `begin()`
418+
419+
Initializes the WAV reader, opens the file and reads the WAV file header.
420+
421+
#### Syntax
422+
423+
```
424+
wav.begin(path, n_samples, n_buffers, loop)
425+
```
426+
427+
#### Parameters
428+
429+
- `string` - **path** - the path to the WAV file.
430+
- `int` - **n_samples** - the number of samples per buffer.
431+
- `int` - **n_buffers** - the number of buffers in the queue.
432+
- `bool` - **loop* - if true, the WAV reader will loop back to the start of the file, when the end file is reached.
433+
434+
### `stop()`
435+
436+
Stops the WAV file and releases all of its resources (include the WAV file handle).
437+
438+
### `available()`
439+
440+
Returns true if the WAV file has more data to be read.
441+
442+
### `read()`
443+
444+
Returns a sample buffer from the queue for reading.
445+
446+
### `rewind()`
447+
448+
If `loop` is false, this functions restarts the file read position.
220449

221450
## SampleBuffer
222451

@@ -244,7 +473,7 @@ dac1.write(buf);
244473

245474
### `data()`
246475

247-
Returns a pointer to the buffer's memory.
476+
Returns a pointer to the buffer's memory.
248477

249478
```
250479
buf.data()
@@ -325,7 +554,7 @@ buf.release()
325554

326555
### `setflags()`
327556

328-
Sets flag(s) for the buffer.
557+
Sets flag(s) for the buffer.
329558

330559
```
331560
buf.setflags(int arg)
@@ -373,7 +602,7 @@ buf.readable()
373602

374603
### `allocate()`
375604

376-
Used to obtain a buffer from the free queue.
605+
Used to obtain a buffer from the free queue.
377606

378607
```
379608
buf.allocate()
@@ -401,4 +630,4 @@ Return a DMA buffer from the ready queue.
401630

402631
```
403632
buf.dequeue()
404-
```
633+
```

0 commit comments

Comments
 (0)