NAME
Device::BusPirate::Mode::BB - use Device::BusPirate in bit-banging mode
SYNOPSIS
use Device::BusPirate;
my $pirate = Device::BusPirate->new;
my $bb = $pirate->enter_mode( "BB" )->get;
my $count = 0;
while(1) {
$bb->write(
miso => $count == 0,
cs => $count == 1,
mosi => $count == 2,
clk => $count == 3,
aux => $count == 4,
)->then( sub { $pirate->sleep( 0.5 ) })
->get;
$count++;
$count = 0 if $count >= 5;
}
DESCRIPTION
This object is returned by a Device::BusPirate instance when switching it into BB mode. It provides methods to configure the hardware, and interact with the five basic IO lines in bit-banging mode.
METHODS
configure
$bb->configure( %args )->get
Change configuration options. The following options exist; all of which are simple true/false booleans.
- open_drain
-
If enabled, a "high" output pin will be set as an input; i.e. hi-Z. When disabled (default), a "high" output pin will be driven by 3.3V. A "low" output will be driven to GND in either case.
cs
miso
clk
mosi
aux
$bb->cs( $state )->get
$bb->miso( $state )->get
$bb->clk( $state )->get
$bb->mosi( $state )->get
$bb->aux( $state )->get
Set an output pin to the given logical state. Uses the open_drain configuration setting to determine whether high should be hi-Z or 3.3V.
write
$bb->write( %pins )->get
Sets the state of multiple output pins at the same time.
read_cs
read_miso
read_clk
read_mosi
read_aux
$state = $bb->read_cs->get
$state = $bb->read_miso->get
$state = $bb->read_clk->get
$state = $bb->read_mosi->get
$state = $bb->read_aux->get
Set a pin to input direction and read its current state.
read
$pins = $bbio->read( @pins )->get
Sets given list of pins (which may be empty) to be inputs, and returns a HASH containing the current state of all the pins currently configured as inputs. More efficient than calling multiple read_* methods when more than one pin is being read at the same time.
writeread
$in_pins = $bbio->writeread( %out_pins )->get
Combines the effects of write and read in a single operation; sets the output state of any pins in %out_pins then returns the input state of the pins currently set as inputs.
power
$bb->power( $power )->get
Enable or disable the VREG 5V and 3.3V power outputs.
pullup
$bb->pullup( $pullup )->get
Enable or disable the IO pin pullup resistors from Vpu. These are connected to the MISO, CLK, MOSI and CS pins.
TODO
Some method of setting multiple pins into read mode at once, so that a single
readmethod hits them all.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>