dln2 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dln2-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 IPM Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
dln2-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.1
2
+ Name: dln2
3
+ Version: 0.1.0
4
+ Summary: Unified DLN2 driver — SPI, GPIO, I2C, ADC over a single USB connection. Originally developed for the Pico USB I/O Board.
5
+ Home-page: https://github.com/syabyr/dln2_wrapper
6
+ Author: IPM Group
7
+ Author-email: contact@ipmgroup.dev
8
+ License: MIT
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: System :: Hardware
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pyusb>=1.2
24
+
25
+ # dln2 — Unified DLN2 USB I/O Board Wrapper
26
+
27
+ Drop-in replacement for the four independent `dln2_*_wrapper` packages.
28
+ **All modules share a single USB connection** — no echo-counter conflicts, no USB contention.
29
+
30
+ Originally developed for the [Pico USB I/O Board](https://github.com/syabyr/pico-usb-io-board).
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install git+https://github.com/syabyr/dln2_wrapper
36
+ ```
37
+
38
+ Requires: `pyusb`
39
+
40
+ ## Quick Start
41
+
42
+ ```python
43
+ from dln2 import Dln2Connection, SpiDev, GPIO, SMBus, ADC
44
+
45
+ conn = Dln2Connection() # one USB connection
46
+
47
+ # ── SPI ─────────────────────────────────────────────────
48
+ spi = SpiDev(conn)
49
+ spi.mode = 3
50
+ spi.max_speed_hz = 16_000_000
51
+ rx = spi.xfer2([0x9F, 0x00, 0x00, 0x00]) # JEDEC ID
52
+
53
+ # ── GPIO ────────────────────────────────────────────────
54
+ gpio = GPIO(conn)
55
+ gpio.set_direction(20, "out")
56
+ gpio.write(20, 1) # set pin HIGH
57
+ val = gpio.read(20) # read pin level
58
+
59
+ # ── I2C ─────────────────────────────────────────────────
60
+ i2c = SMBus(conn)
61
+ i2c.open()
62
+ devices = []
63
+ for addr in range(1, 128):
64
+ try:
65
+ i2c.write_byte(addr, 0)
66
+ devices.append(addr)
67
+ except: pass
68
+
69
+ # ── ADC ─────────────────────────────────────────────────
70
+ adc = ADC(conn, vref=3.3)
71
+ volts = adc.read_volts(0) # read channel 0 voltage
72
+
73
+ conn.close()
74
+ ```
75
+
76
+ ## Multi-Device Support
77
+
78
+ ```python
79
+ from dln2 import list_devices, Dln2Connection
80
+
81
+ for d in list_devices():
82
+ print(f"[{d.index}] serial={d.serial}")
83
+
84
+ lcd_conn = Dln2Connection(index=0) # first board — ST7789 display
85
+ nfc_conn = Dln2Connection(index=1) # second board — NFC reader
86
+ # or by exact serial:
87
+ # conn = Dln2Connection(serial="4250304B38353817")
88
+ ```
89
+
90
+ ## Module API
91
+
92
+ ### SpiDev
93
+ spidev-compatible API: `xfer()`, `xfer2()`, `writebytes()`, `readbytes()`,
94
+ `mode`, `max_speed_hz`, `bits_per_word`, `cshigh`, `lsbfirst`, `host_hold_cs`
95
+
96
+ ### GPIO
97
+ `set_direction(pin, "in"|"out")`, `write(pin, value)`, `read(pin)`,
98
+ `toggle(pin)`, `get_direction(pin)`, `set_event(pin, type)`, `poll_event()`
99
+
100
+ ### SMBus
101
+ smbus-compatible API: `write_byte()`, `read_byte_data()`,
102
+ `write_word_data()`, `read_word_data()`, `read_block_data()`,
103
+ `write_block_data()`, `write_i2c_block_data()`, `read_i2c_block_data()`
104
+
105
+ ### ADC
106
+ `read_channel(channel)`, `read_all()`, `read_volts(channel)`,
107
+ `set_resolution(bits)`, `enable_channel(ch)`, `disable_channel(ch)`
108
+
109
+ ### BME280
110
+ `read_chip_id()`, `get_temperature()`, `get_humidity()`, `get_pressure()`,
111
+ `get_altitude()`, `get_all()`
112
+
113
+ ## Examples
114
+
115
+ ```bash
116
+ # SPI JEDEC ID read
117
+ python3 examples/spidev_test.py
118
+
119
+ # GPIO pin toggle (default: Pico LED)
120
+ python3 examples/gpio_toggle.py --pin 25
121
+
122
+ # I2C bus scan
123
+ python3 examples/i2c_scan.py
124
+
125
+ # ADC monitor
126
+ python3 examples/adc_info.py
127
+ ```
128
+
129
+ ## Why Unified?
130
+
131
+ | | Old (4 packages) | New (`dln2`) |
132
+ |---|---|---|
133
+ | USB connections | 4 separate (echo conflicts) | 1 shared |
134
+ | Code duplication | ~800 lines (4× Dln2Usb) | 0 lines |
135
+ | GPIO events steal SPI responses | Yes | No (proper event queue) |
136
+ | Multi-device | Manual USB enumeration | `list_devices()` |
137
+ | Cross-module data flow | Impossible (4 echo counters) | Trivial (same counter) |
138
+
139
+ ## Related
140
+
141
+ - [pico-usb-io-board](https://github.com/syabyr/pico-usb-io-board) — RP2040 firmware
142
+ - [st7789 display driver](https://github.com/syabyr/dln2_wrapper) — example ST7789 + BME280 application
143
+
144
+ ## License
145
+
146
+ MIT
dln2-0.1.0/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # dln2 — Unified DLN2 USB I/O Board Wrapper
2
+
3
+ Drop-in replacement for the four independent `dln2_*_wrapper` packages.
4
+ **All modules share a single USB connection** — no echo-counter conflicts, no USB contention.
5
+
6
+ Originally developed for the [Pico USB I/O Board](https://github.com/syabyr/pico-usb-io-board).
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install git+https://github.com/syabyr/dln2_wrapper
12
+ ```
13
+
14
+ Requires: `pyusb`
15
+
16
+ ## Quick Start
17
+
18
+ ```python
19
+ from dln2 import Dln2Connection, SpiDev, GPIO, SMBus, ADC
20
+
21
+ conn = Dln2Connection() # one USB connection
22
+
23
+ # ── SPI ─────────────────────────────────────────────────
24
+ spi = SpiDev(conn)
25
+ spi.mode = 3
26
+ spi.max_speed_hz = 16_000_000
27
+ rx = spi.xfer2([0x9F, 0x00, 0x00, 0x00]) # JEDEC ID
28
+
29
+ # ── GPIO ────────────────────────────────────────────────
30
+ gpio = GPIO(conn)
31
+ gpio.set_direction(20, "out")
32
+ gpio.write(20, 1) # set pin HIGH
33
+ val = gpio.read(20) # read pin level
34
+
35
+ # ── I2C ─────────────────────────────────────────────────
36
+ i2c = SMBus(conn)
37
+ i2c.open()
38
+ devices = []
39
+ for addr in range(1, 128):
40
+ try:
41
+ i2c.write_byte(addr, 0)
42
+ devices.append(addr)
43
+ except: pass
44
+
45
+ # ── ADC ─────────────────────────────────────────────────
46
+ adc = ADC(conn, vref=3.3)
47
+ volts = adc.read_volts(0) # read channel 0 voltage
48
+
49
+ conn.close()
50
+ ```
51
+
52
+ ## Multi-Device Support
53
+
54
+ ```python
55
+ from dln2 import list_devices, Dln2Connection
56
+
57
+ for d in list_devices():
58
+ print(f"[{d.index}] serial={d.serial}")
59
+
60
+ lcd_conn = Dln2Connection(index=0) # first board — ST7789 display
61
+ nfc_conn = Dln2Connection(index=1) # second board — NFC reader
62
+ # or by exact serial:
63
+ # conn = Dln2Connection(serial="4250304B38353817")
64
+ ```
65
+
66
+ ## Module API
67
+
68
+ ### SpiDev
69
+ spidev-compatible API: `xfer()`, `xfer2()`, `writebytes()`, `readbytes()`,
70
+ `mode`, `max_speed_hz`, `bits_per_word`, `cshigh`, `lsbfirst`, `host_hold_cs`
71
+
72
+ ### GPIO
73
+ `set_direction(pin, "in"|"out")`, `write(pin, value)`, `read(pin)`,
74
+ `toggle(pin)`, `get_direction(pin)`, `set_event(pin, type)`, `poll_event()`
75
+
76
+ ### SMBus
77
+ smbus-compatible API: `write_byte()`, `read_byte_data()`,
78
+ `write_word_data()`, `read_word_data()`, `read_block_data()`,
79
+ `write_block_data()`, `write_i2c_block_data()`, `read_i2c_block_data()`
80
+
81
+ ### ADC
82
+ `read_channel(channel)`, `read_all()`, `read_volts(channel)`,
83
+ `set_resolution(bits)`, `enable_channel(ch)`, `disable_channel(ch)`
84
+
85
+ ### BME280
86
+ `read_chip_id()`, `get_temperature()`, `get_humidity()`, `get_pressure()`,
87
+ `get_altitude()`, `get_all()`
88
+
89
+ ## Examples
90
+
91
+ ```bash
92
+ # SPI JEDEC ID read
93
+ python3 examples/spidev_test.py
94
+
95
+ # GPIO pin toggle (default: Pico LED)
96
+ python3 examples/gpio_toggle.py --pin 25
97
+
98
+ # I2C bus scan
99
+ python3 examples/i2c_scan.py
100
+
101
+ # ADC monitor
102
+ python3 examples/adc_info.py
103
+ ```
104
+
105
+ ## Why Unified?
106
+
107
+ | | Old (4 packages) | New (`dln2`) |
108
+ |---|---|---|
109
+ | USB connections | 4 separate (echo conflicts) | 1 shared |
110
+ | Code duplication | ~800 lines (4× Dln2Usb) | 0 lines |
111
+ | GPIO events steal SPI responses | Yes | No (proper event queue) |
112
+ | Multi-device | Manual USB enumeration | `list_devices()` |
113
+ | Cross-module data flow | Impossible (4 echo counters) | Trivial (same counter) |
114
+
115
+ ## Related
116
+
117
+ - [pico-usb-io-board](https://github.com/syabyr/pico-usb-io-board) — RP2040 firmware
118
+ - [st7789 display driver](https://github.com/syabyr/dln2_wrapper) — example ST7789 + BME280 application
119
+
120
+ ## License
121
+
122
+ MIT
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Unified DLN2 wrapper package.
4
+
5
+ Single USB connection shared by SPI, GPIO, I2C and ADC modules.
6
+ Eliminates echo-counter conflicts and USB contention from the
7
+ original four independent packages.
8
+
9
+ Usage:
10
+ from dln2 import Dln2Connection, SpiDev, GPIO, SMBus, ADC, list_devices
11
+
12
+ conn = Dln2Connection() # single USB connection
13
+ spi = SpiDev(conn) # all modules share conn
14
+ gpio = GPIO(conn)
15
+ i2c = SMBus(conn)
16
+
17
+ See also: dln2_wrapper.py (standalone legacy version)
18
+ """
19
+
20
+ from ._core import Dln2Connection, list_devices, Dln2DeviceInfo
21
+ from .spi import SpiDev
22
+ from .gpio import GPIO, \
23
+ GPIO_EVENT_NONE, GPIO_EVENT_CHANGE, \
24
+ GPIO_EVENT_LEVEL_HIGH, GPIO_EVENT_LEVEL_LOW
25
+ from .i2c import SMBus, i2c_msg
26
+ from .adc import ADC
27
+ from .bme280 import BME280