Skip to content

Commit ae81c36

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

File tree

2 files changed

+289
-25
lines changed

2 files changed

+289
-25
lines changed

docs/api.md

+248-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,173 @@ dac.frequency(frequency);
216282

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

285+
## AdvancedI2S
286+
287+
### `AdvancedI2S`
288+
289+
290+
Creates an I2S object using the provided pins.
291+
292+
#### Syntax
293+
294+
```
295+
AdvancedI2S i2s(WS, CK, SDI, SDO, MCK);
296+
```
297+
298+
#### Parameters
299+
300+
- `WS` I2S word select (LR clock).
301+
- `CK` I2S bit-clock (BRCLK clock).
302+
- `SDI` I2S data input (can be `NC` in half-duplex output mode).
303+
- `SDO` I2S data output (can be `NC` in half-duplex input mode).
304+
- `MCK` Master clock (can be `NC` if no MCLK is required).
305+
306+
#### Returns
307+
308+
Nothing.
309+
310+
### `begin()`
311+
312+
Initialize and start the I2S device.
313+
314+
#### Syntax
315+
316+
```
317+
i2s.begin(mode, resolution, frequency, n_samples, n_buffers)
318+
```
319+
320+
#### Parameters
321+
322+
- `enum` - **mode** - The I2S mode.
323+
- `AN_I2S_MODE_IN`
324+
- `AN_I2S_MODE_OUT`
325+
- `AN_I2S_MODE_INOUT`
326+
- `int` - **sample_rate** - The sample rate / frequency in Hertz, e.g. `16000`.
327+
- `int` - **n_samples** - The number of samples per buffer (i.e, buffer width).
328+
- `int` - **n_buffers** - The number of buffers in the sample queue (i.e, queue depth).
219329

330+
#### Returns
331+
332+
1 on success, 0 on failure.
333+
334+
### `available()`
335+
336+
Checks if the I2S is readable, writable or both (in full-duplex mode).
337+
338+
#### Syntax
339+
340+
```
341+
if(i2s.available()){}
342+
```
343+
344+
#### Parameters
345+
346+
None.
347+
348+
#### Returns
349+
350+
True if I2S is readable, writable or both (in full-duplex mode), false if not.
351+
352+
353+
### `read()`
354+
355+
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))
356+
357+
#### Syntax
358+
359+
```
360+
SampleBuffer buf = i2s.read();
361+
362+
for (size_t i=0; i<buf.size(); i++) {
363+
Serial.println(buf[i]);
364+
}
365+
366+
i2s.release(buf);
367+
```
368+
369+
### `dequeue()`
370+
371+
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))
372+
373+
#### Syntax
374+
375+
```
376+
SampleBuffer buf = dac.dequeue();
377+
378+
for (size_t i=0; i<buf.size(); i++) {
379+
buf[i] = SAMPLES_BUFFER[i];
380+
}
381+
382+
dac1.write(buf);
383+
```
384+
385+
### `write()`
386+
387+
388+
Writes the buffer to I2S.
389+
390+
#### Syntax
391+
392+
```
393+
i2s.write(buf);
394+
```
395+
396+
#### Parameters
397+
398+
- A buffer containing the samples (see [SampleBuffer](#samplebuffer)).
399+
400+
### `stop()`
401+
402+
Stops the I2S and releases all of its resources.
403+
404+
#### Syntax
405+
406+
```
407+
i2s.stop()
408+
```
409+
410+
#### Returns
411+
412+
- `1`
413+
414+
## WavReader
415+
416+
### `WavReader`
417+
418+
Creates a WAV file reader.
419+
420+
### `begin()`
421+
422+
Initializes the WAV reader, opens the file and reads the WAV file header.
423+
424+
#### Syntax
425+
426+
```
427+
wav.begin(path, n_samples, n_buffers, loop)
428+
```
429+
430+
#### Parameters
431+
432+
- `string` - **path** - the path to the WAV file.
433+
- `int` - **n_samples** - the number of samples per buffer.
434+
- `int` - **n_buffers** - the number of buffers in the queue.
435+
- `bool` - **loop* - if true, the WAV reader will loop back to the start of the file, when the end file is reached.
436+
437+
### `stop()`
438+
439+
Stops the WAV file and releases all of its resources (include the WAV file handle).
440+
441+
### `available()`
442+
443+
Returns true if the WAV file has more data to be read.
444+
445+
### `read()`
446+
447+
Returns a sample buffer from the queue for reading.
448+
449+
### `rewind()`
450+
451+
If `loop` is false, this functions restarts the file read position.
220452

221453
## SampleBuffer
222454

@@ -244,7 +476,7 @@ dac1.write(buf);
244476

245477
### `data()`
246478

247-
Returns a pointer to the buffer's memory.
479+
Returns a pointer to the buffer's memory.
248480

249481
```
250482
buf.data()
@@ -325,7 +557,7 @@ buf.release()
325557

326558
### `setflags()`
327559

328-
Sets flag(s) for the buffer.
560+
Sets flag(s) for the buffer.
329561

330562
```
331563
buf.setflags(int arg)
@@ -373,7 +605,7 @@ buf.readable()
373605

374606
### `allocate()`
375607

376-
Used to obtain a buffer from the free queue.
608+
Used to obtain a buffer from the free queue.
377609

378610
```
379611
buf.allocate()
@@ -401,4 +633,4 @@ Return a DMA buffer from the ready queue.
401633

402634
```
403635
buf.dequeue()
404-
```
636+
```

0 commit comments

Comments
 (0)