arduino-audio-tools
I2SSAMD.h
1 #pragma once
2 
3 #if defined(ARDUINO_ARCH_SAMD)
4 #include <I2S.h>
5 
6 #include "AudioI2S/I2SConfig.h"
7 
8 namespace audio_tools {
9 
17  friend class I2SStream;
18 
19  public:
22  I2SConfigStd c(mode);
23  return c;
24  }
25 
27  bool setAudioInfo(AudioInfo) { return false; }
28 
30  bool begin(RxTxMode mode) { return begin(defaultConfig(mode)); }
31 
33  bool begin(I2SConfigStd cfg) {
34  this->cfg = cfg;
35  return I2S.begin(cfg.i2s_format, cfg.sample_rate, cfg.bits_per_sample);
36  }
37 
38  bool begin() { return begin(cfg); }
39 
41  void end() { I2S.end(); }
42 
44  I2SConfigStd config() { return cfg; }
45 
46  size_t writeBytes(const void *src, size_t size_bytes) {
47  return I2S.write((const uint8_t *)src, size_bytes);
48  }
49 
50  size_t readBytes(void *src, size_t size_bytes) {
51  return I2S.read(src, size_bytes);
52  }
53 
54  int available() { return I2S.available(); }
55 
56  int availableForWrite() { return I2S.availableForWrite(); }
57 
58  protected:
59  I2SConfigStd cfg;
60 };
61 
62 using I2SDriver = I2SDriverSAMD;
63 
64 } // namespace audio_tools
65 
66 #endif
Configuration for i2s.
Definition: I2SConfigStd.h:17
Basic I2S API - for the SAMD.
Definition: I2SSAMD.h:16
bool setAudioInfo(AudioInfo)
Potentially updates the sample rate (if supported)
Definition: I2SSAMD.h:27
I2SConfigStd config()
provides the actual configuration
Definition: I2SSAMD.h:44
I2SConfigStd defaultConfig(RxTxMode mode)
Provides the default configuration.
Definition: I2SSAMD.h:21
bool begin(I2SConfigStd cfg)
starts the DAC
Definition: I2SSAMD.h:33
void end()
stops the I2C and unistalls the driver
Definition: I2SSAMD.h:41
bool begin(RxTxMode mode)
starts the DAC with the default config
Definition: I2SSAMD.h:30
We support the Stream interface for the I2S access. In addition we allow a separate mute pin which mi...
Definition: I2SStream.h:31
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:26
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:50
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition: AudioTypes.h:53
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition: AudioTypes.h:57