Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spireg-0.1.3-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2Python 3

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

Hashes for spireg-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3064540da9199abf1684f717d226a1b1c5f2e5bc70787610af9f5d29efda86e4
MD5 17d941c6b33dd649cecc73859ffac4fd
BLAKE2b-256 b8884c3080d939e5c2252a5fad171f0c58bc1fc703816e5edc4e555dc01eb722

See more details on using hashes here.

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

Hashes for spireg-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 72e86ef2a00a8f68d23b196b04f45ddfa0a7247021e3bed7166f3ad17d8a2f2f
MD5 815e3f01d0283c75129646a50f982829
BLAKE2b-256 746af20c9de0c598a353d93e0f802923b7b6fe19af0079e19b189da1f86823ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page