Class Bus

extends Object
Bus for communicating using SPI.
An SPI bus is constructed with 3 main wires for data transmission and a clock.
Each device on the bus is enabled with its own chip-select pin. See Bus.device.

Class summary


constructor --mosi/any= --miso/any= --clock/any
Constructs a new SPI bus using the given mosi, miso, and clock pins.

Constructors

constructor --mosi/any=null --miso/any=null --clock/any
Constructs a new SPI bus using the given mosi, miso, and clock pins.
The mosi, miso, and clock are GPIO numbers. The bus reserves the pins and releases them again when the bus is closed.
Passing a gpio.Pin is deprecated; provide the integer GPIO number instead. The gpio.Pin form will be removed in a future release.

Methods

close -> none
Closes this SPI bus and frees the associated resources.

device --cs/any=null --dc/any=null --frequency/int --mode/int=0 --command-bits/int=0 --address-bits/int=0 -> Device
Configures a device on this SPI bus.
The device's clock speed is configured to the given frequency. The given frequency is only aspirational, and the actual frequency might be different. For example, the ESP32S3 seems to have a minimum frequency of 100kHz.
An optional cs (chip select) and dc (data/command) pin can be assigned for this device. They are GPIO numbers. The device reserves the pins and releases them again when the device is closed. If no cs pin is provided, then the chip must be enabled in software (or hardware, tied to ground, if it's the only chip on the bus).
The SPI mode can further be configured in the range [0..3], defaulting to 0.
Some SPI devices have an explicit command and/or address section that can be configured using command-bits and address-bits.
Parameters
The mode parameter configures the clock polarity and phase (CPOL and CPHA) for this bus.
The possible configurations are:
  • 0 (0b00): CPOL=0, CPHA=0
  • 1 (0b01): CPOL=0, CPHA=1
  • 2 (0b10): CPOL=1, CPHA=0
  • 3 (0b11): CPOL=1, CPHA=1
Passing a gpio.Pin as cs or dc is deprecated; provide the integer GPIO number instead. The gpio.Pin form will be removed in a future release.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.