pyHydrabus package¶
Submodules¶
pyHydrabus.hydrabus module¶
-
class
pyHydrabus.hydrabus.
Hydrabus
(port='')¶ Bases:
object
Base class for all modes.
Manages all serial communication
-
close
()¶ Close the serial port
-
connected
¶ Check if serial port is opened
Returns: Bool
-
enter_bbio
()¶ Enter BBIO mode.
This should be done prior all further operations
Returns: Bool
-
exit_bbio
()¶ Reset Hydrabus to CLI mode
Returns: Bool
-
flush_input
()¶ Flush input buffer (data from Hydrabus)
-
identify
()¶ Identify the current mode
Returns: Current mode Return type: str
-
in_waiting
¶ Return the number of bytes in the receive buffer.
Returns: Number of bytes Return type: int
-
read
(length=1)¶ Base read primitive
Parameters: length (int) – Number of bytes to read Returns: Read data Return type: bytes
-
reset
()¶ Force reset to BBIO main mode
Returns: Bool
-
timeout
¶ Serial port read timeout
Returns: timeout Return type: int
-
write
(data=b'')¶ Base write primitive
Parameters: data (bytes) – Bytes to write
-
pyHydrabus.i2c module¶
-
class
pyHydrabus.i2c.
I2C
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
I2C protocol handler
Example: >>> #Read data from an EEPROM >>> import pyHydrabus >>> i=pyHydrabus.I2C('/dev/hydrabus') >>> i.set_speed(pyHydrabus.I2C.I2C_SPEED_100K) >>> i.pullup=1 >>> i.start();i.bulk_write(b' ');print(i.write_read(b'¡',64))
-
I2C_SPEED_100K
= 1¶
-
I2C_SPEED_1M
= 3¶
-
I2C_SPEED_400K
= 2¶
-
I2C_SPEED_50K
= 0¶
-
bulk_write
(data=b'')¶ Bulk write on I2C bus https://github.com/hydrabus/hydrafw/wiki/HydraFW-Binary-I2C-mode-guide#bulk-i2c-write-0b0001xxxx
Parameters: data (bytes) – Data to be sent Returns: ACK status of the written bytes (b’’=ACK, b’’=NACK) Return type: list
-
clock_stretch
(clock_stretch_val)¶ Set I2C clock stretching timeout in number of clocks
Parameters: clock_stretch_val – clock stretching timeout number of clocks (0 disable up to 2^32)
-
pullup
¶ Pullup status (0=off, 1=on)
-
read
(length=0)¶ Read on I2C bus
Parameters: length (int) – Number of bytes to read Returns: Read data Return type: bytes
-
read_byte
()¶ Read a byte from the I2C bus
-
scan
()¶ Scan I2C bus and returns all available device addresses in a list
Returns: List of available device addresses Return type: list
-
send_ack
()¶ Send an ACK Used with the read_byte() function
-
send_nack
()¶ Send a NACK Used with the read_byte() function
-
set_speed
(speed)¶ Set I2C bus speed
Parameters: speed – Select any of the defined speeds (I2C_SPEED_*)
-
start
()¶ Send a I2C start condition
-
stop
()¶ Send a I2C stop condition
-
write
(data=b'')¶ Write on I2C bus
Parameters: data (bytes) – data to be sent
-
write_read
(data=b'', read_len=0)¶ Write-then-read operation https://github.com/hydrabus/hydrafw/wiki/HydraFW-Binary-I2C-mode-guide#i2c-write-then-read-0b00001000
This method sends a start condition before writing and a stop condition after reading.
Parameters: - data (bytes) – Data to be sent
- read_len (int) – Number of bytes to read
Returns: Read data
Return type: bytes
-
pyHydrabus.onewire module¶
-
class
pyHydrabus.onewire.
OneWire
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
One wire protocol handler
Example: TODO
-
bulk_write
(data=b'')¶ Bulk write on 1-Wire bus https://github.com/hydrabus/hydrafw/wiki/HydraFW-binary-1-Wire-mode-guide#bulk-1-wire-transfer-0b0001xxxx
Parameters: data (bytes) – Data to be sent
-
pullup
¶ Pullup status (0=off, 1=on)
-
read
(read_len=0)¶ Read on 1-Wire bus
Parameters: read_len – Number of bytes to be read Return read_len: int Returns: Read data Return type: bytes
-
read_byte
()¶ Read a byte from the 1-Wire bus
-
reset
()¶ Send a 1-Wire reset
-
write
(data=b'')¶ Write on 1-Wire bus
Parameters: data (bytes) – data to be sent
-
pyHydrabus.protocol module¶
-
class
pyHydrabus.protocol.
Protocol
(name='', fname='', mode_byte=b'x00', port='')¶ Bases:
object
Base class for all supported protocols
Parameters: - name (str) – Name of the protocol (returned by Hydrabus) eg. SPI1
- fname (str) – Full name of the protocol
- mode_byte (bytes) – Byte used to enter the mode (eg. for SPI)
- port (str) – The port name
-
close
()¶ Close the communication channel and resets Hydrabus
-
hydrabus
¶ Return _hydrabus instance to access Hydrabus class functions and serial methods from any protocol classes instances
Returns: _hydrabus class instance
-
identify
()¶ Identify the current mode
Returns: The current mode identifier (4 bytes) Return type: str
-
timeout
¶
pyHydrabus.rawwire module¶
-
class
pyHydrabus.rawwire.
RawWire
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
Raw wire protocol handler
Example: >>> import pyHydrabus >>> r=pyHydrabus.RawWire('/dev/hydrabus') >>> # Set SDA to high >>> r.sda = 1 >>> # Send two clock ticks >>> r.clocks(2) >>> # Read two bytes >>> data = r.read(2)
-
bulk_ticks
(num)¶ Sends a bulk of clock ticks (1 to 16) https://github.com/hydrabus/hydrafw/wiki/HydraFW-binary-raw-wire-mode-guide#bulk-clock-ticks-0b0010xxxx
Parameters: num (int) – Number of clock ticks to send
-
bulk_write
(data=b'')¶ Bulk write on Raw-Wire https://github.com/hydrabus/hydrafw/wiki/HydraFW-binary-raw-wire-mode-guide#bulk-raw-wire-transfer-0b0001xxxx
Parameters: data (bytes) – Data to be sent
-
clk
¶ CLK pin status
-
clock
()¶ Send a clock tick
-
clocks
(num)¶ Sends a number of clock ticks
Parameters: num (int) – Number of clock ticks to send
-
gpio_mode
¶ Raw-Wire GPIO mode (0=Push-Pull, 1=Open Drain)
-
polarity
¶ Clock polarity (0=idle low, 1=idle high)
-
read
(length=0)¶ Read on Raw-Wire bus
Parameters: length (int) – Number of bytes to read Returns: Read data Return type: bytes
-
read_bit
()¶ Sends a clock tick, and return the read bit value
-
read_byte
()¶ Read a byte from the raw wire
Returns: The read byte Return type: bytes
-
sda
¶ SDA pin status
-
set_speed
(speed)¶ Sets the clock max speed.
Parameters: speed – speed in Hz. Possible values : TODO
-
wires
¶ Raw-Wire mode (2=2-Wire, 3=3-Wire)
-
write
(data=b'')¶ Write on Raw-Wire bus
Parameters: data (bytes) – data to be sent Returns: Read bytes Return type: bytes
-
write_bits
(data=b'', num_bits=0)¶ Write bits on Raw-Wire bus Bits are sent MSB first.
Parameters: - data (int) – data to be sent
- num_bits – number of bits to send
Returns: Read bytes
Return type: bytes
-
pyHydrabus.smartcard module¶
-
class
pyHydrabus.smartcard.
Smartcard
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
Smartcard protocol handler
Example: >>> #Read ATR from a smartcard >>> import pyHydrabus >>> sm=pyHydrabus.Smartcard('/dev/hydrabus') >>> sm.prescaler=12 >>> sm.baud=9600 >>> sm.rst=1;sm.rst=0;sm.read(1)
-
baud
¶ Baud rate
-
get_atr
()¶ Get smartcard ATR
-
guardtime
¶ Guard time value
-
prescaler
¶ Prescaler value
-
pullup
¶
-
read
(read_len=0)¶ Read on smartard
Parameters: read_len (int) – number of bytes to be read
-
rst
¶ RST pin status
-
write
(data=b'')¶ Write on smartard
Parameters: data – data to be sent
-
write_read
(data=b'', read_len=0)¶ Write-then-read operation https://github.com/hydrabus/hydrafw/wiki/HydraFW-binary-SMARTCARD-mode-guide#write-then-read-operation-0b00000100
Parameters: - data – Data to be sent
- read_len (int) – number of bytes to read
-
pyHydrabus.spi module¶
-
class
pyHydrabus.spi.
SPI
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
SPI protocol handler
Example: >>> import pyHydrabus >>> s = pyHydrabus.SPI() >>> s.set_speed(s.SPI1_SPEED_10M) >>> s.cs = 0 >>> s.bulk_write(b'') >>> s.read(4)
-
SPI1_SPEED_10M
= 5¶
-
SPI1_SPEED_1M
= 2¶
-
SPI1_SPEED_21M
= 6¶
-
SPI1_SPEED_2M
= 3¶
-
SPI1_SPEED_320K
= 0¶
-
SPI1_SPEED_42M
= 7¶
-
SPI1_SPEED_5M
= 4¶
-
SPI1_SPEED_650K
= 1¶
-
SPI2_SPEED_10M
= 6¶
-
SPI2_SPEED_160K
= 0¶
-
SPI2_SPEED_1M
= 3¶
-
SPI2_SPEED_21M
= 7¶
-
SPI2_SPEED_2M
= 4¶
-
SPI2_SPEED_320K
= 1¶
-
SPI2_SPEED_5M
= 5¶
-
SPI2_SPEED_650K
= 2¶
-
bulk_write
(data=b'')¶ Bulk write on SPI bus https://github.com/hydrabus/hydrafw/wiki/HydraFW-Binary-SPI-mode-guide#bulk-spi-transfer-0b0001xxxx
Parameters: data (bytes) – Data to be sent Returns: Bytes read during the transfer Return type: bytes
-
cs
¶ Chip-Select (CS) status getter
-
device
¶ SPI device to use (1=spi1, 0=spi2)
-
phase
¶ SPI clock phase
-
polarity
¶ SPI polarity
-
read
(read_len=0, drive_cs=0)¶ Read on SPI bus
Parameters: - read_len (int) – Number of bytes to be read
- drive_cs (int) – Whether to enable chip select before writing/reading (0=yes, 1=no)
Returns: Read data
Return type: bytes
-
set_speed
(speed)¶ Set SPI bus speed
Parameters: speed – Select any of the defined speeds (SPI_SPEED_*)
-
write
(data=b'', drive_cs=0)¶ Write on SPI bus
Parameters: - data (bytes) – data to be sent
- drive_cs (int) – Whether to enable chip select before writing/reading (0=yes, 1=no)
-
write_read
(data=b'', read_len=0, drive_cs=0)¶ Write-then-read operation https://github.com/hydrabus/hydrafw/wiki/HydraFW-Binary-SPI-mode-guide#write-then-read-operation-0b00000100—0b00000101
Parameters: - data (bytes) – Data to be sent
- read_len (int) – Number of bytes to read
- drive_cs (int) – Whether to enable chip select before writing/reading (0=yes, 1=no)
Returns: Read data
Return type: bytes
-
pyHydrabus.Utils module¶
Utilities available in hydrafw
param port: | The port name |
---|---|
type port: | str |
-
pyHydrabus.Utils.
adc
¶ Read ADC value
Returns: ADC value (10 bits) Return type: int
pyHydrabus.uart module¶
UART protocol handler
example: | TODO |
---|
>>> #Read data from an EEPROM
>>> import pyHydrabus
>>> u=pyHydrabus.UART('/dev/hydrabus')
>>> u.baud=115200
>>> u.echo=1
-
pyHydrabus.UART.
baud
¶ Baud rate
-
pyHydrabus.UART.
echo
¶ Local echo (0=No, 1=Yes)
-
pyHydrabus.UART.
hydrabus
¶ Return _hydrabus instance to access Hydrabus class functions and serial methods from any protocol classes instances
Returns: _hydrabus class instance
-
pyHydrabus.UART.
parity
¶ Parity
-
pyHydrabus.UART.
timeout
¶
pyHydrabus.swd module¶
SWD protocol handler
example: |
---|
>>> import pyHydrabus
>>> swd = pyHydrabus.SWD('/dev/ttyACM0')
>>> swd.bus_init()
>>> swd.read_dp(0)
>>> swd.write_dp(4, 0x50000000)
>>> swd.scan_bus()
-
pyHydrabus.SWD.
clk
¶ CLK pin status
-
pyHydrabus.SWD.
gpio_mode
¶ Raw-Wire GPIO mode (0=Push-Pull, 1=Open Drain)
-
pyHydrabus.SWD.
hydrabus
¶ Return _hydrabus instance to access Hydrabus class functions and serial methods from any protocol classes instances
Returns: _hydrabus class instance
-
pyHydrabus.SWD.
polarity
¶ Clock polarity (0=idle low, 1=idle high)
-
pyHydrabus.SWD.
sda
¶ SDA pin status
-
pyHydrabus.SWD.
timeout
¶
-
pyHydrabus.SWD.
wires
¶ Raw-Wire mode (2=2-Wire, 3=3-Wire)
pyHydrabus.aux module¶
-
class
pyHydrabus.auxpin.
AUXPin
(number, hydrabus)¶ Bases:
object
Auxilary pin base class
This class is meant to be used in any mode and is instanciated in the Protocol class
Example: >>> import pyHydrabus >>> i=pyHydrabus.RawWire('/dev/hydrabus') >>> # Set AUX pin 0 (PC4) to output >>> i.AUX[0].direction = pyHydrabus.OUTPUT >>> # Set AUX pin to logical 1 >>> i.AUX[0].value = 1 >>> # Read Auxiliary pin 2 (PC5) value >>> i.AUX[1].value
-
INPUT
= 1¶
-
OUTPUT
= 0¶
-
direction
¶ Auxiliary pin direction getter
Returns: The pin direction (0=output, 1=input) Return type: int
-
pullup
¶ Auxiliary pin pullup getter
Returns: Auxiliary pin pullup status (1=enabled, 0=disabled”) Return type: int
-
toggle
()¶ Toggle pin state
-
value
¶ Auxiliary pin getter
-
pyHydrabus.nfc module¶
-
class
pyHydrabus.nfc.
NFC
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
NFC protocol handler
Example: >>> import pyHydrabus >>> n=pyHydrabus.NFC('/dev/hydrabus') >>> # Set mode to ISO 14443A >>> n.mode = pyHydrabus.NFC.MODE_ISO_14443A >>> # Set radio ON >>> n.rf = 1 >>> # Send REQA, get ATQA >>> n.write_bits(b'&', 7) >>> # Send anticol, read ID >>> n.write(b' ', 0).hex()
-
MODE_ISO_14443A
= 0¶
-
MODE_ISO_15693
= 1¶
-
mode
¶
-
rf
¶
-
write
(data=b'', crc=0)¶ Write bytes on NFC https://github.com/hydrabus/hydrafw/wiki/HydraFW-binary-NFC-Reader-mode-guide#send-bytes-0b00000101
Parameters: data (bytes) – Data to be sent
-
write_bits
(data=b'', num_bits=0)¶ Write bits on NFC https://github.com/hydrabus/hydrafw/wiki/HydraFW-binary-NFC-Reader-mode-guide#send-bits-0b00000100
Parameters: - data (byte) – Data to be sent
- num_bits (int) – number of bits to send
-
pyHydrabus.mmc module¶
-
class
pyHydrabus.mmc.
MMC
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
MMC protocol handler
Example: >>> import pyHydrabus >>> m=pyHydrabus.MMC('/dev/hydrabus') >>> # Get CID >>> m.cid >>> # Get CSD >>> m.csd >>> # Read block 0 >>> m.read(0)
-
bus_width
¶ Data bus width (1 or 4)
-
cid
¶
-
csd
¶
-
ext_csd
¶
-
read
(block_num=0)¶ Read MMC block
Parameters: block_num (int) – Block number Returns: Bytes read Return type: bytes
-
write
(data=b'', block_num=0)¶ Write MMC block
Parameters: - data (bytes) – Data to be written (512 bytes)
- block_num (int) – Block number
- data – Data to be written
-
pyHydrabus.sdio module¶
-
class
pyHydrabus.sdio.
SDIO
(port='')¶ Bases:
pyHydrabus.protocol.Protocol
SDIO protocol handler
Example: >>> import pyHydrabus >>> m=pyHydrabus.SDIO('/dev/hydrabus') >>> # CMD0 - IDLE >>> s.send_no(0,0)
>>> #CMD8 - OP_COND >>> s.send_short(8, 0x000001aa)
>>> #ACMD41 *2 >>> s.send_short(55,0) >>> s.send_short(41, 0x50ff8000) >>> s.send_short(55,0) >>> s.send_short(41, 0x50ff8000)
>>> #CMD2 - GET CID >>> cid = s.send_long(2, 0) >>> print(f"CID: {cid.hex()}")
>>> #CMD9 - RADDR >>> raddr = int.from_bytes(s.send_short(3, 0), byteorder='little') >>> print(f"RADDR: {raddr:08x}")
>>> #CSD >>> csd = s.send_long(9, raddr) >>> print(f"CSD: {csd.hex()}")
>>> #Select card >>> print(s.send_short(7, raddr).hex())
>>> #Get status >>> print(s.send_short(13, raddr).hex())
-
bus_width
¶ Data bus width (1 or 4)
-
read
(cmd_id, cmd_arg)¶ Read SDIO block
Parameters: - cmd_id (int) – Command ID (1 byte)
- cmd_arg – Command argument (4 bytes)
Returns: Read data
Return type: bytes
-
send_long
(cmd_id, cmd_arg)¶ Send SDIO command with long reply from card
Parameters: - cmd_id (int) – Command ID (1 byte)
- cmd_arg – Command argument (4 bytes)
Returns: Reply status, None in case of error
Return type: bytes
-
send_no
(cmd_id, cmd_arg)¶ Send SDIO command with no reply from card
Parameters: - cmd_id (int) – Command ID (1 byte)
- cmd_arg – Command argument (4 bytes)
-
send_short
(cmd_id, cmd_arg)¶ Send SDIO command with short reply from card
Parameters: - cmd_id (int) – Command ID (1 byte)
- cmd_arg – Command argument (4 bytes)
Returns: Reply status, None in case of error
Return type: bytes
-
write
(cmd_id, cmd_arg, data)¶ Write SDIO block
Parameters: - cmd_id (int) – Command ID (1 byte)
- cmd_arg – Command argument (4 bytes)
- data (bytes) – Data to be written (512 bytes)
Returns: Transaction status
Return type: Boolean
-