1 unstable release
0.1.0 | Jun 28, 2019 |
---|
#12 in #configuring
26KB
417 lines
Bus Pirate client library
This library implements the Bus Pirate binary protocol, allowing Rust programs to interact with a Bus Pirate and in turn to interact with SPI, I2C, UART, etc devices. The implemented protocol is that of the Bus Pirate v3.6.
The library API uses types to ensure safe switching between different Bus Pirate modes and to provide functions relating only to the current mode. At initialization, the bus pirate is assumed to be in its normal terminal mode, and so the first step implemented by this library is to switch into binary mode. After that, the caller may transition into other binary modes as desired.
The entry point is BusPirate::new
, which takes (and consumes) a serial
writer and a serial reader as defined by
embedded_hal::serial
.
If you are running on a general computing platform then you can use
serial_embedded_hal
to connect with a serial port provided by your operating system:
let port = Serial::new(
"/dev/ttyUSB0",
&PortSettings {
baud_rate: serial_embedded_hal::BaudRate::Baud115200,
char_size: serial_embedded_hal::CharSize::Bits8,
parity: serial_embedded_hal::Parity::ParityNone,
stop_bits: serial_embedded_hal::StopBits::Stop1,
flow_control: serial_embedded_hal::FlowControl::FlowNone,
},
)?;
let (tx, rx) = port.split();
let bp = BusPirate::new(tx, rx);
A BusPirate
object represents a Bus Pirate in normal terminal mode, not
yet configured to speak a binary protocol. Method init
can then transition
into "binary bit-bang" mode, yielding a bitbang::BitBang
object:
let bb = bp.init()?;
As well as offering direct control over the Bus Pirate's pins, bit-bang mode is also a gateway into the other more specialized protocol modes. For example, SPI mode:
let spi = bp.to_spi()?;
Dependencies
~71KB