NAME
    `Device::BusPirate::Chip::AVR_HVSP' - high-voltage serial programming
    for AVR chips

DESCRIPTION
    This Device::BusPirate::Chip subclass allows interaction with an AVR
    microcontroller of the ATtiny family in high-voltage serial programming
    (HVSP) mode. It is particularly useful for configuring fuses or working
    with a chip with the `RSTDISBL' fuse programmed, because in such cases a
    regular ISP programmer cannot be used.

  CONNECTIONS
    To use this module, make the following connections between the Bus
    Pirate (with colours of common cable types), and the ATtiny chip (with
    example pin numbers for some common devices):

      Bus Pirate | Sparkfun | Seeed    |:| ATtiny | tiny84 | tiny85
      -----------+----------+----------+-+--------+--------+-------
      MISO       | brown    | black    |:|    SDO |      9 |      7
      CS         | red      | white    |:|    SII |      8 |      6
      MOSI       | orange   | grey     |:|    SDI |      7 |      5
      CLK        | yellow   | purple   |:|    SCI |      2 |      2
      AUX        | green    | blue     |:| +12V supply - see below
                 |          |          |:|  RESET |      4 |      1
      +5V        | grey     | orange   |:|    Vcc |      1 |      8
      GND        | black    | brown    |:|    GND |     14 |      4

    The `AUX' line from the Bus Pirate will need to be able to control a
    +12V supply to the `RESET' pin of the ATtiny chip. It should be
    active-high, and can be achieved by a two-stage NPN-then-PNP transistor
    arrangement.

    Additionally, the `SDO' pin and the `PA0' to `PA2' pins of 14-pin
    devices will need a pull-down to ground of around 100Ohm to 1kOhm.

METHODS
    The following methods documented with a trailing call to `->get' return
    Future instances.

  $chip->start->get
    Powers up the device, reads and checks the signature, ensuring it is a
    recognised chip.

    This method leaves the chip powered up with +5V on Vcc and +12V on
    RESET. Use the `power', `hv_power' or `all_power' methods to turn these
    off if it is not required again immediately.

  $chip->stop->get
    Shut down power to the device.

  $chip->power( $on )->get
    Controls +5V to the Vcc pin of the ATtiny chip.

  $chip->hv_power( $on )->get
    Controls +12V to the RESET pin of the ATtiny chip.

  $chip->all_power( $on )->get
    Controls both +5V and +12V supplies at once. The +12V supply is turned
    on last but off first, ensuring the correct HVSP-RESET sequence is
    applied to the chip.

  $name = $chip->partname
    Returns the name of the chip whose signature was detected by the `start'
    method.

  $memory = $avr->memory_info( $name )
    Returns a memory info structure giving details about the named memory
    for the attached part. The following memory names are recognised:

     signature calibration lock lfuse hfuse efuse flash eeprom

    (Note that the ATtiny13 has no `efuse' memory).

    The structure will respond to the following methods:

    * wordsize
        Returns number of bits per word. This will be 8 for the
        byte-oriented memories, but 16 for the main program flash.

    * pagesize
        Returns the number of words per page; the smallest amount that can
        be written in one go.

    * words
        Returns the total number of words that are available.

    * can_write
        Returns true if the memory type can be written (in general; this
        does not take into account the lock bits that might futher restrict
        a particular chip).

  %memories = $avr->memory_infos
    Returns a key/value list of all the known device memories.

  $fuseinfo = $avr->fuseinfo
    Returns a Device::BusPirate::Chip::AVR_HVSP::FuseInfo instance
    containing information on the fuses in the attached device type.

  $avr->chip_erase->get
    Performs an entire chip erase. This will clear the flash and EEPROM
    memories, before resetting the lock bits. It does not affect the fuses.

  $bytes = $avr->read_signature->get
    Reads the three device signature bytes and returns them in as a single
    binary string.

  $byte = $avr->read_calibration->get
    Reads the calibration byte.

  $byte = $avr->read_lock->get
    Reads the lock byte.

  $avr->write_lock( $byte )->get
    Writes the lock byte.

  $int = $avr->read_fuse_byte( $fuse )->get
    Reads one of the fuse bytes `lfuse', `hfuse', `efuse', returning an
    integer.

  $avr->write_fuse_byte( $fuse, $byte )->get
    Writes one of the fuse bytes `lfuse', `hfuse', `efuse' from an integer.

  $byte = $avr->read_lfuse->get
  $byte = $avr->read_hfuse->get
  $byte = $avr->read_efuse->get
    Convenient shortcuts to reading the low, high and extended fuses
    directly, returning a byte.

  $avr->write_lfuse( $byte )->get
  $avr->write_hfuse( $byte )->get
  $avr->write_efuse( $byte )->get
    Convenient shortcuts for writing the low, high and extended fuses
    directly, from a byte.

  $bytes = $avr->read_flash( %args )->get
    Reads a range of the flash memory and returns it as a binary string.

    Takes the following optional arguments:

    start => INT
    stop => INT
        Address range to read. If omitted, reads the entire memory.

    bytes => INT
        Alternative to `stop'; gives the nubmer of bytes (i.e. not words of
        flash) to read.

  $avr->write_flash( $bytes )->get
    Writes the flash memory from the binary string.

  $bytes = $avr->read_eeprom( %args )->get
    Reads a range of the EEPROM memory and returns it as a binary string.

    Takes the following optional arguments:

    start => INT
    stop => INT
        Address range to read. If omitted, reads the entire memory.

    bytes => INT
        Alternative to `stop'; gives the nubmer of bytes to read.

  $avr->write_eeprom( $bytes )->get
    Writes the EEPROM memory from the binary string.

SEE ALSO
    *   http://dangerousprototypes.com/2014/10/27/high-voltage-serial-progra
        mming-for-avr-chips-with-the-bus-pirate/ - High voltage serial
        programming for AVR chips with the Bus Pirate.

AUTHOR
    Paul Evans <leonerd@leonerd.org.uk>

