machine.I2S
Classes
Construct an I2S object of the given id: |
Module Contents
- class machine.I2S.I2S(id, *, sck, ws, sd, mck=None, mode, bits, format, rate, ibuf)
Construct an I2S object of the given id:
id
identifies a particular I2S bus; it is board and port specific
Keyword-only parameters that are supported on all ports:
sck
is a pin object for the serial clock linews
is a pin object for the word select linesd
is a pin object for the serial data linemck
is a pin object for the master clock line; master clock frequency is sampling rate * 256mode
specifies receive or transmitbits
specifies sample size (bits), 16 or 32format
specifies channel format, STEREO or MONOrate
specifies audio sampling rate (Hz); this is the frequency of thews
signalibuf
specifies internal buffer length (bytes)
For all ports, DMA runs continuously in the background and allows user applications to perform other operations while sample data is transferred between the internal buffer and the I2S peripheral unit. Increasing the size of the internal buffer has the potential to increase the time that user applications can perform non-I2S operations before underflow (e.g.
write
method) or overflow (e.g.readinto
method).- deinit() Incomplete
Deinitialize the I2S bus
- init(sck, *args, **kwargs) Incomplete
see Constructor for argument descriptions
- irq(handler) Incomplete
Set a callback.
handler
is called whenbuf
is emptied (write
method) or becomes full (readinto
method). Setting a callback changes thewrite
andreadinto
methods to non-blocking operation.handler
is called in the context of the MicroPython scheduler.
- readinto(buf) int
Read audio samples into the buffer specified by
buf
.buf
must support the buffer protocol, such as bytearray or array. “buf” byte ordering is little-endian. For Stereo format, left channel sample precedes right channel sample. For Mono format, the left channel sample data is used. Returns number of bytes read
- static shift(*, buf, bits, shift) Incomplete
bitwise shift of all samples contained in
buf
.bits
specifies sample size in bits.shift
specifies the number of bits to shift each sample. Positive for left shift, negative for right shift. Typically used for volume control. Each bit shift changes sample volume by 6dB.
- write(buf) int
Write audio samples contained in
buf
.buf
must support the buffer protocol, such as bytearray or array. “buf” byte ordering is little-endian. For Stereo format, left channel sample precedes right channel sample. For Mono format, the sample data is written to both the right and left channels. Returns number of bytes written
- MONO: Incomplete
for initialising the I2S bus
format
to mono
- RX: Incomplete
for initialising the I2S bus
mode
to receive
- STEREO: Incomplete
for initialising the I2S bus
format
to stereo
- TX: Incomplete
for initialising the I2S bus
mode
to transmit