Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
# Set a GPIO pin's state
gpio_set(port, pin, state: bool)

# Get a GPIO pin's state as a bool
gpio_get(port, pin) -> bool

# Get an ADC reading, in mV if raw is False
adc_read(port, pin, raw=False) -> int

# Write tx_bytes over I2C; perform a register write if reg is not None
i2c_write(i2c_port, address, tx_bytes: list[int], reg=None)

# Read rx_len bytes over I2C; perform a register read if reg is not None
# (coming soon)
i2c_read(i2c_port, address, rx_len, reg=None) -> list[int]

# Perform a SPI exchange, first sending tx_bytes, then reading rx_len bytes
# cs is an optional (port, pin) specifying the chip select GPIO pin to use
spi_exchange(tx_bytes, rx_len, spi_port=1, spi_mode=0, baudrate=6000000, cs=None)

# Send a raw CAN message
can_send_raw(msg_id, data: list[int], device_id=BABYDRIVER_DEVICE_ID, channel=None)

# Load a DBC database specifying the format of our CAN messages
load_dbc(dbc_filename)

# Send a CAN message with human-readable names from the loaded DBC database
# Fields can be specified in keyword arguments, e.g. status=1, voltage=3500
can_send(msg_name: str, channel=None, **data)

# Register a GPIO interrupt; callback defaults to printing the port/pin
# (coming soon)
register_gpio_interrupt(port, pin, edge=RISING, callback=None)

# Unregister a GPIO interrupt previously registered
# (coming soon)
unregister_gpio_interrupt(port, pin)

...