SPIReg provides a method to define and access SPI registers
Project description
SPIReg
SPIReg provides a method to define and access SPI registers and their individual fields.
Features
- Define SPI registers with custom fields.
- Access and modify individual register fields dynamically.
- Ensures values fit within specified field sizes.
- Supports conversion between bit representations and integer values.
Installation
Install SPIReg using:
pip install spireg
Usage
from spireg import Register, Entry
from ctypes import c_uint8
from typing import cast
class ExampleRegisterTypes(Register):
FIELD_A: int
FIELD_B: int
FIELD_C: int
EXAMPLE_REG = cast(ExampleRegisterTypes, Register("EXAMPLE_REG", 0x12, "Example register description.", [
Entry("FIELD_A", 1), # Bit 7: Not used
Entry("FIELD_B", 1), # Bit 6: Example binary flag
Entry("FIELD_C", 6, 0x15), # Bits 5-0: Default value of 0x15
]))
# Print default values
print(EXAMPLE_REG.FIELD_A) # Output: 0
print(EXAMPLE_REG.FIELD_B) # Output: 0
print(EXAMPLE_REG.FIELD_C) # Output: 21
# Set field values
EXAMPLE_REG.FIELD_B = 1
EXAMPLE_REG.FIELD_C = 0x1F
# Get modified field values
print(EXAMPLE_REG.FIELD_B) # Output: 1
print(EXAMPLE_REG.FIELD_C) # Output: 31
print(int(EXAMPLE_REG)) # Get full register value
print(EXAMPLE_REG) # Outputs bit representation and field values
License
This project is licensed under GPL-3.0-or-later.
For commercial licensing, please contact:
Daniël van den Berg
daniel@dmvandenberg.nl
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
spireg-0.1.3.tar.gz
(15.6 kB
view details)
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 spireg-0.1.3.tar.gz.
File metadata
- Download URL: spireg-0.1.3.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3064540da9199abf1684f717d226a1b1c5f2e5bc70787610af9f5d29efda86e4
|
|
| MD5 |
17d941c6b33dd649cecc73859ffac4fd
|
|
| BLAKE2b-256 |
b8884c3080d939e5c2252a5fad171f0c58bc1fc703816e5edc4e555dc01eb722
|
File details
Details for the file spireg-0.1.3-py2.py3-none-any.whl.
File metadata
- Download URL: spireg-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e86ef2a00a8f68d23b196b04f45ddfa0a7247021e3bed7166f3ad17d8a2f2f
|
|
| MD5 |
815e3f01d0283c75129646a50f982829
|
|
| BLAKE2b-256 |
746af20c9de0c598a353d93e0f802923b7b6fe19af0079e19b189da1f86823ab
|