This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

machine.I2S

Classes

I2S

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 line

  • ws is a pin object for the word select line

  • sd is a pin object for the serial data line

  • mck is a pin object for the master clock line; master clock frequency is sampling rate * 256

  • mode specifies receive or transmit

  • bits specifies sample size (bits), 16 or 32

  • format specifies channel format, STEREO or MONO

  • rate specifies audio sampling rate (Hz); this is the frequency of the ws signal

  • ibuf 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 when buf is emptied (write method) or becomes full (readinto method). Setting a callback changes the write and readinto 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