Skip to main content

Crate pico_de_gallo_ffi

Crate pico_de_gallo_ffi 

Source
Expand description

C-compatible FFI bindings for the Pico de Gallo USB bridge.

This crate wraps pico-de-gallo-lib in a C-compatible API using opaque pointers and integer status codes. It is compiled as a cdylib (shared library) and generates a C header via cbindgen.

§Usage from C

#include "pico_de_gallo.h"

const PicoDeGallo *gallo = gallo_init();
uint32_t id = 42;
Status status = gallo_ping(gallo, &id);
// id now contains the round-tripped value
gallo_free(gallo);

§Lifecycle

  1. Call gallo_init (or gallo_init_with_serial_number) to create a context.
  2. Use gallo_* functions, passing the context pointer.
  3. Call gallo_free to release resources.

§Thread Safety

The context pointer is safe to share across threads — the inner type is Send + Sync (enforced by a compile-time assertion). Each function call creates its own async executor via futures::executor::block_on, so concurrent calls from multiple threads are safe.

§Status Codes

All functions return a Status code. Status::Ok (0) indicates success; negative values indicate errors. See Status for the full list.

Structs§

GalloDeviceInfo
C-compatible device information struct.
PicoDeGallo
Opaque handle to a Pico de Gallo device context.

Enums§

Status
Status codes returned by all FFI functions.

Constants§

GALLO_CAP_ADC
ADC input support (bit 5).
GALLO_CAP_GPIO
GPIO support (bit 3).
GALLO_CAP_I2C
I2C bus support (bit 0).
GALLO_CAP_ONEWIRE
1-Wire bus support (bit 6).
GALLO_CAP_PWM
PWM output support (bit 4).
GALLO_CAP_SPI
SPI bus support (bit 1).
GALLO_CAP_UART
UART support (bit 2).

Functions§

gallo_adc_get_config
gallo_adc_get_config - Query the ADC configuration.
gallo_adc_read
gallo_adc_read - Perform a single-shot ADC read.
gallo_free
gallo_free - Releases and destroys the library context created by gallo_init.
gallo_get_device_info
gallo_get_device_info - Gets extended device information.
gallo_gpio_get
gallo_gpio_get - Get the state of a given GPIO pin.
gallo_gpio_put
gallo_gpio_put - Set the state of a given GPIO pin.
gallo_gpio_set_config
gallo_gpio_set_config - Configure a GPIO pin’s direction and pull resistor.
gallo_gpio_subscribe
gallo_gpio_subscribe - Subscribe to GPIO edge events on a pin.
gallo_gpio_unsubscribe
gallo_gpio_unsubscribe - Unsubscribe from GPIO edge events on a pin.
gallo_gpio_wait_for_any_edge
gallo_gpio_wait_for_any_edge - Waits for a any edge on a given GPIO pin.
gallo_gpio_wait_for_falling_edge
gallo_gpio_wait_for_falling_edge - Waits for a falling edge on a given GPIO pin.
gallo_gpio_wait_for_high
gallo_gpio_wait_for_high - Waits for a high level on a given GPIO pin.
gallo_gpio_wait_for_low
gallo_gpio_wait_for_low - Waits for a low level on a given GPIO pin.
gallo_gpio_wait_for_rising_edge
gallo_gpio_wait_for_rising_edge - Waits for a rising edge on a given GPIO pin.
gallo_i2c_get_config
gallo_i2c_get_config - Queries the current I2C bus configuration.
gallo_i2c_read
gallo_i2c_read - Read len bytes from the device at address into buf.
gallo_i2c_scan
gallo_i2c_scan - Scan the I2C bus for responding devices.
gallo_i2c_set_config
gallo_i2c_set_config - Sets the I2C bus configuration parameters.
gallo_i2c_write
gallo_i2c_write - Write len bytes from buf to the device at address.
gallo_i2c_write_read
gallo_i2c_write_read - Perform a write followed by a read.
gallo_init
gallo_init - Initialize the library context.
gallo_init_with_serial_number
gallo_init_with_serial_number - Initialize the library context for a device with the given serial number.
gallo_onewire_read
gallo_onewire_read - Read bytes from the 1-Wire bus.
gallo_onewire_reset
gallo_onewire_reset - Perform a 1-Wire bus reset.
gallo_onewire_search
gallo_onewire_search - Search for all devices on the 1-Wire bus.
gallo_onewire_write
gallo_onewire_write - Write raw bytes to the 1-Wire bus.
gallo_onewire_write_pullup
gallo_onewire_write_pullup - Write bytes then apply a strong pullup.
gallo_ping
gallo_ping - Ping the firmware and wait for a response
gallo_pwm_disable
gallo_pwm_disable - Disable the PWM slice that owns the given channel.
gallo_pwm_enable
gallo_pwm_enable - Enable the PWM slice that owns the given channel.
gallo_pwm_get_config
gallo_pwm_get_config - Query the current PWM configuration.
gallo_pwm_get_duty_cycle
gallo_pwm_get_duty_cycle - Query the current duty cycle of a PWM channel.
gallo_pwm_set_config
gallo_pwm_set_config - Configure the PWM slice behind a channel.
gallo_pwm_set_duty_cycle
gallo_pwm_set_duty_cycle - Set the raw duty cycle of a PWM channel.
gallo_spi_flush
gallo_spi_flush - Flush the SPI interface.
gallo_spi_get_config
gallo_spi_get_config - Queries the current SPI bus configuration.
gallo_spi_read
gallo_spi_read - Read len bytes.
gallo_spi_set_config
gallo_spi_set_config - Sets the SPI bus configuration parameters.
gallo_spi_write
gallo_spi_write - Write len bytes from buf.
gallo_uart_flush
gallo_uart_flush - Flush the UART transmit buffer.
gallo_uart_get_config
gallo_uart_get_config - Query the current UART configuration.
gallo_uart_read
gallo_uart_read - Read bytes from the UART bus.
gallo_uart_set_config
gallo_uart_set_config - Set the UART baud rate.
gallo_uart_write
gallo_uart_write - Write bytes to the UART bus.
gallo_version
gallo_version - Gets the firmware version.