Library

Documentation for BaremetalPi.jl.

BaremetalPi.gpio_set_modeMethod
gpio_set_mode(gpio, mode::Symbol)

Set the mode of the GPIO gpio to mode. gpio can be an integer of an AbstractVector with the list of GPIOs that will be set.

mode can be:

  • :out: GPIO direction will be set to out.
  • :in: GPIO direction will be set to in.
  • :alt0: GPIO will be set to alternate function 0.
  • :alt1: GPIO will be set to alternate function 1.
  • :alt2: GPIO will be set to alternate function 2.
  • :alt3: GPIO will be set to alternate function 3.
  • :alt4: GPIO will be set to alternate function 4.
  • :alt5: GPIO will be set to alternate function 5.
source
BaremetalPi.gpio_valueMethod
gpio_value(v::Integer)

Apply the value v to all GPIOs. The bits that are 0 will be cleared, and the bits that are 1 will be set.

gpio_value(v::BitVector)

Convert the bit array v to Int and call gpio_value(::Int).

source
BaremetalPi.i2c_get_funcsMethod
i2c_get_funcs(devid::Int)

Return a vector with the available I2C functions in the device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_slaveMethod
i2c_slave(devid::Integer, address::Integer)

Select the slave device in address address using I2C device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_slave_forceMethod
i2c_slave_force(devid::Integer, address::Integer)

Force selection of slave device in address address using I2C device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_read_byteMethod
i2c_smbus_read_byte(devid::Integer)

Perform a SMBUS read byte using the I2C device devid. This functions returns the read byte.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_read_byte_dataMethod
i2c_smbus_read_byte_data(devid::Integer, command::Integer)

Perform a SMBUS read byte with command command using the I2C device devid. This function return the read byte.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_read_i2c_block_data!Method
i2c_smbus_read_i2c_block_data!(devid::Integer, command::Integer, data::Vector{UInt8})

Perform a SMBUS read block with command command using the I2C device devid. The read data will be written to data. Notice that the first element of the array is always size. Hence, the number of read bytes will be equal to the length of data minus 1.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_read_i2c_block_dataMethod
i2c_smbus_read_i2c_block_data(devid::Integer, command::Integer, size::Integer)

Perform a SMBUS read block with command command and length length using the I2C device devid. The read data will be returned in an array of UInt8 with size size + 1. This array is a view of the buffer that was allocated at the initialization of the I2C device. Notice that the first element of the array is always size.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

Warning

The returned array is a view of the buffer bblock created for each I2C device. This buffer is modified by other functions like i2c_smbus_write_i2c_block_data. Hence, before performing another I2C transfer that will modify this buffer, be sure to copy the returned value to another place.

Allocations

Due to the view returned by this functions, it performs one allocation. If this is not wanted, then use the in-place version i2c_smbus_read_i2c_block_data!.

source
BaremetalPi.i2c_smbus_read_word_dataMethod
i2c_smbus_read_word_data(devid::Integer, command::Integer)

Perform a SMBUS read word with command command using the I2C device devid. This function return the read word.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_write_byteMethod
i2c_smbus_write_byte(devid::Integer, value::Integer)

Perform a SMBUS write byte with value value using the I2C device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_write_byte_dataMethod
i2c_smbus_write_byte_data(devid::Integer, command::Integer, value::Integer)

Perform a SMBUS write byte with command command and value value using the I2C device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_write_i2c_block_dataMethod
i2c_smbus_write_i2c_block_data(devid::Integer, command::Integer, values::Vector{UInt8})

Perform a SMBUS write I2C block data with command command and data in values using the I2C device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.i2c_smbus_write_word_dataMethod
i2c_smbus_write_word_data(devid::Integer, command::Integer, value::Integer)

Perform a SMBUS write word with command command and value value using the I2C device devid.

devid is the ID of the I2C device considering the initialization order when the function init_i2c was called.

source
BaremetalPi.init_i2cMethod
init_i2c(devices)

Initialize the I2C devices. devices can be a string with the path to i2cdev or a vector of strings with a set of I2C devices that will be initialized.

source
BaremetalPi.init_spiMethod
init_spi(devices; mode = 0, max_speed_hz = 4_000_000, bits_per_word = 8)

Initialize the SPI devices. devices can be a string with the path to spidev or a vector of strings with a set of SPI devices that will be initialized.

Keywords

  • mode: Set the mode of the SPI. (Default = 0)
  • max_speed_hz: Maximum allowed speed in SPI communication [Hz]. (Default = 4000000)
  • bits_per_word: Number of bits per word in SPI communication. (Default = 8)

Notice that all keywords can be a Integer, when the configuration will be applied to all SPI devices, or a Vector of Integers, when different configurations can be applied to the initialized devices.

source
BaremetalPi.spi_transfer!Method
spi_transfer!(devid, tx_buf, rx_buf; kwargs...)

Execute a full duplex transfer to SPI device devid. devid is the ID of the SPI device considering the initialization order when the function init_spi was called.

tx_buf can be a vector of Integer, in which only one message will be sent, or a vector of vectors of Integer, in which multiple messages will be sent.

The received data will be stored in rx_buf that must have the same type of tx_buf and enough size.

This function returns the number of bytes received.

Allocations

This function will not allocate only if the number of messages sent is lower than the constant BaremetalPi._SPI_BUFFER_SIZE. Otherwise, it will perform an allocation because it must allocate a vector of struct_spi_ioc_transfer.

Keywords

  • max_speed_hz: If > 0, then override the default maximum transfer speed with this value [Hz]. (Default = 0)
  • delay_usecs: If ≥ 0, then override the default delay with this value. (Default = -1)
  • bits_per_word: If > 0, then override the number of bits per word with this value. (Default = 0)
  • cs_change: If false, the deselect the device at the end of the transfer.
source
BaremetalPi.spi_transferMethod
spi_transfer(devid, tx_buf; kwargs...)

Execute a full duplex transfer to SPI device devid. devid is the ID of the SPI device considering the initialization order when the function init_spi was called.

tx_buf can be a vector of Integer, in which only one message will be sent, or a vector of vectors of Integer, in which multiple messages will be sent.

The result is returned in an object with the same type of tx_buf together with the number of words received.

Allocations

This function will perform allocations because they create the vector that will be returned. If this is not desired, then use the in-place version spi_transfer!.

Keywords

The same keywords of spi_transfer! can be used.

source