The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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

The following methods documented with await expressions Future instances.

configure

   await $bb->configure( %args );

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.

write

   await $bb->write( %pins );

Sets the state of multiple output pins at the same time.

read

   $pins = await $bbio->read( @pins );

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 = await $bbio->writeread( %out_pins );

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

   await $bb->power( $power );

Enable or disable the VREG 5V and 3.3V power outputs.

pullup

   await $bb->pullup( $pullup );

Enable or disable the IO pin pullup resistors from Vpu. These are connected to the MISO, CLK, MOSI and CS pins.

PER-PIN METHODS

For each named pin, the following methods are defined. The pin names are

   cs miso sck mosi aux

PIN

   await $bbio->PIN( $state );

Sets the output state of the given pin.

read_PIN

   $state = await $bbio->read_PIN;

Sets the pin to input direction and reads its current state.

TODO

  • Some method of setting multiple pins into read mode at once, so that a single read method hits them all.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>