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.2.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.2.tar.gz.
File metadata
- Download URL: spireg-0.1.2.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 |
e83451096c7107182db006850c80f4ad6c901996b1a60d14f14f6c842dd0a94d
|
|
| MD5 |
12940c038060cf397320bbfaaeb5ee99
|
|
| BLAKE2b-256 |
1b32e9ce9c6c9aa7d67f0cdb60d49e134b75478338521632a3ee166afa9e701f
|
File details
Details for the file spireg-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: spireg-0.1.2-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 |
c49750ec511c7a6187ffccdab53a77eda06f6b83ff866f9a200c3b664986cbdf
|
|
| MD5 |
70461271551e1dc1b7eb8612ae6d50b0
|
|
| BLAKE2b-256 |
0c55d9e9d8ef4fdd75e41b2354e5885a09e10fe909d4456a66ebe9634695e69d
|