Metadata-Version: 2.4
Name: dln2-i2c-wrapper
Version: 0.1.0
Summary: A Python library for DLN2 I2C adapters with an SMBus-style API. Originally developed for Pico USB IO Board.
Author-email: IPM Group <contact@ipmgroup.dev>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/syabyr/dln2_i2c_wrapper
Project-URL: Documentation, https://github.com/syabyr/dln2_i2c_wrapper#readme
Project-URL: Repository, https://github.com/syabyr/dln2_i2c_wrapper.git
Project-URL: Bug Tracker, https://github.com/syabyr/dln2_i2c_wrapper/issues
Keywords: dln2,i2c,usb,hardware,driver,smbus
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Hardware :: Hardware Drivers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyusb>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=6.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: build; extra == "dev"
Dynamic: license-file

# DLN2 I2C Wrapper

A Python library for interfacing with DLN2 USB-to-I2C adapters with an `SMBus`-style API.
It targets the Pico USB I/O Board firmware and packages the host-side I2C access layer as a
standalone Python project.

## Features

- SMBus-style API for common byte, word, and I2C block operations
- Low-level DLN2 USB client built on `pyusb`
- BME280 helper for chip ID, calibration, and measurement reads
- I2C scan and BME280 example scripts
- Pure Python, no compiled extension

## Important Limitation

The firmware exposes separate DLN2 read and write commands. It does not expose a single
combined repeated-start transaction through the USB protocol, so register reads are performed as:

1. Write register pointer
2. Start a separate read transaction

That works for many devices, but it is not identical to Linux `i2c-dev` combined transfers.
`i2c_rdwr()` in this wrapper also executes messages sequentially for the same reason.

## Installation

From source:

```bash
git clone https://github.com/syabyr/dln2_i2c_wrapper.git
cd dln2_i2c_wrapper
pip install .
```

For development:

```bash
pip install -e ".[dev]"
```

## Quick Start

```python
from dln2_i2c_wrapper import SMBus

with SMBus(1) as bus:
    device_addr = 0x50
    register = 0x00

    value = bus.read_byte_data(device_addr, register)
    print(hex(value))

    bus.write_byte_data(device_addr, register, 0x12)
```

## BME280 Example

```python
from dln2_i2c_wrapper import BME280

with BME280(bus=1, address=0x76) as sensor:
    print(hex(sensor.check_chip_id()))
    sensor.read_calibration()
    sensor.configure()
    print(sensor.read_measurements())
```

## Command-Line Tools

```bash
dln2-i2c-test --help
dln2-i2c-scan --help
dln2-bme280-test --help
```

Use register-based probing when scanning devices that do not ACK a bare read, for example:

```bash
dln2-i2c-scan --register 0xD0 --read-len 1
```

## Low-Level API

```python
from dln2_i2c_wrapper import Dln2Usb, find_device

device = find_device()
client = Dln2Usb(device, debug=True)

client.i2c_enable()
client.i2c_write(0x50, b"\x00")
data = client.i2c_read(0x50, 4)
print(data.hex())
client.i2c_disable()
client.close()
```

## Development

```bash
make test
make build
```
