A lightweight library to manage direct register field manipulation.
Project description
regmap
regmap is a lightweight library to manage direct register field manipulation.
Many times been in the situation where for development I have wanted to interact with an embedded system, where for testing I just want read and write raw register values. Most of these devices contain registers with multiple fields of varying bit lengths. This library abstracts away the awkward bit manipulation into a simple register definition.
Installation
You can install regmap from PyPi with the following command:
pip install regmap
Usage
Define an interface
The interface is the code that interacts with the system containing the registers. A read and a write method need to be defined.
from regmap import Interface
class DeviceInterface(Interface):
def read(self, address: int) -> int:
# Function to go read a register from the device
value = read_val_from_register(address)
return value
def write(self, address: int, value: int) -> None:
# Function to go write a value to a register on the device
write_val_to_register(address, value)
Define our registers
from regmap import BitField, Register
class config_reg_a_def(Register):
_name = "config_reg_a"
_address = 0x2000
output = BitField(7, 1)
enable = BitField(0)
class config_reg_b_def(Register):
_name = "config_reg_b"
_address = 0x2004
setting2 = BitField(7, 5)
setting1 = BitField(4, 2)
setting0 = BitField(1, 0)
class Registers:
def __init__(self, interface):
self.config_reg_a = config_reg_a_def(interface)
self.config_reg_b = config_reg_b_def(interface)
Set some values
The context manager will deal with reading and writing to the register. By default the context manager will do read, modify, write. This can be changed to perform read-only or write-only operations.
from regmap import Mode
interface = DeviceInterface()
registers = Registers(interface)
# Perform read, modify, write
with registers.config_reg_a:
registers.config_reg_a.output = 20
registers.config_reg_a.enable = 1
# Perform read only, will warn if modifications were attempted
with registers.config_reg_a(mode=Mode.RO):
print(registers.config_reg_a.output)
# Perform write only, zeros will be written in any unset fields
with registers.config_reg_b(mode=Mode.WO):
registers.config_reg_b.setting1 = 2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file regmap-0.2.0.tar.gz.
File metadata
- Download URL: regmap-0.2.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
827cafb312df60b3ebeee612554204d1dfab8bd5cb89e08f2aaa8593995848ee
|
|
| MD5 |
b9b911402e4ae09728a0dfc5ad9acab7
|
|
| BLAKE2b-256 |
e61339a32dd3b25ded01ebd628d2ce14ca94ac8311c8886431273a7d45df69e9
|
Provenance
The following attestation bundles were made for regmap-0.2.0.tar.gz:
Publisher:
build.yml on 8BitJosh/regmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
regmap-0.2.0.tar.gz -
Subject digest:
827cafb312df60b3ebeee612554204d1dfab8bd5cb89e08f2aaa8593995848ee - Sigstore transparency entry: 170751594
- Sigstore integration time:
-
Permalink:
8BitJosh/regmap@6fbf6f83daa32661d57614d4dfd1e9b1c433bddc -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/8BitJosh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@6fbf6f83daa32661d57614d4dfd1e9b1c433bddc -
Trigger Event:
push
-
Statement type:
File details
Details for the file regmap-0.2.0-py3-none-any.whl.
File metadata
- Download URL: regmap-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e28e2c5168d22cd906aeba4a79e3dfba952e9d5ddb0d8a849b235d1b6be36e5f
|
|
| MD5 |
f706ffdc495ec104f32429f55f9428be
|
|
| BLAKE2b-256 |
b9448a8979902b5f00813e4c7d6c7fe966e741dd8117a37dd7f190422d407fbe
|
Provenance
The following attestation bundles were made for regmap-0.2.0-py3-none-any.whl:
Publisher:
build.yml on 8BitJosh/regmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
regmap-0.2.0-py3-none-any.whl -
Subject digest:
e28e2c5168d22cd906aeba4a79e3dfba952e9d5ddb0d8a849b235d1b6be36e5f - Sigstore transparency entry: 170751599
- Sigstore integration time:
-
Permalink:
8BitJosh/regmap@6fbf6f83daa32661d57614d4dfd1e9b1c433bddc -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/8BitJosh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@6fbf6f83daa32661d57614d4dfd1e9b1c433bddc -
Trigger Event:
push
-
Statement type: