scietex.hal.current-amplifier 0.3.0__py3-none-any.whl
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.
- scietex/hal/current_amplifier/__init__.py +10 -0
- scietex/hal/current_amplifier/base/__init__.py +71 -0
- scietex/hal/current_amplifier/base/capabilities.py +541 -0
- scietex/hal/current_amplifier/base/data.py +88 -0
- scietex/hal/current_amplifier/base/errors.py +47 -0
- scietex/hal/current_amplifier/base/protocol.py +411 -0
- scietex/hal/current_amplifier/py.typed +0 -0
- scietex/hal/current_amplifier/registry.py +66 -0
- scietex/hal/current_amplifier/scietex/__init__.py +5 -0
- scietex/hal/current_amplifier/scietex/ebic/__init__.py +5 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/__init__.py +5 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/__init__.py +38 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/client.py +497 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/constants.py +108 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/identity.py +80 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/relaymap.py +347 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/semantic.py +690 -0
- scietex/hal/current_amplifier/version.py +1 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/METADATA +393 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/RECORD +24 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/WHEEL +5 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/entry_points.txt +3 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/licenses/LICENSE +21 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Scietex current amplifier HAL package.
|
|
2
|
+
|
|
3
|
+
A ``CurrentAmplifier`` converts a photodiode or ion-collector current into a
|
|
4
|
+
voltage: the driver layer exposes its capability set, its state snapshot, and
|
|
5
|
+
the transport-agnostic control contract that concrete protocols implement.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .version import __version__
|
|
9
|
+
|
|
10
|
+
__all__ = ["__version__"]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Base current amplifier subpackage.
|
|
3
|
+
|
|
4
|
+
Holds the transport-agnostic pieces every driver shares: the capability model
|
|
5
|
+
that advertises what an amplifier can do, the state snapshot it reports, and the
|
|
6
|
+
driver contract concrete protocols implement.
|
|
7
|
+
|
|
8
|
+
Classes:
|
|
9
|
+
Access: Whether a setting can be read and whether it can be written.
|
|
10
|
+
AmplifierState: A snapshot of the values an amplifier reports.
|
|
11
|
+
BandwidthCapabilities: A bandwidth domain and whether it is selectable.
|
|
12
|
+
BoostCapabilities: Boost stage gain selection.
|
|
13
|
+
CompensationCapabilities: Input-capacitance compensation surface.
|
|
14
|
+
CurrentAmplifierCapabilities: The complete capability set for one amplifier.
|
|
15
|
+
CurrentAmplifierProtocol: The contract every current amplifier driver
|
|
16
|
+
implements.
|
|
17
|
+
DcBiasCapabilities: DC bias injection surface.
|
|
18
|
+
FilterCapabilities: Signal-filter surface.
|
|
19
|
+
FilterSetting: One filter in the amplifier's signal path.
|
|
20
|
+
FilterType: The filter responses an amplifier can apply.
|
|
21
|
+
IndicationCapabilities: A status signal and whether it is readable.
|
|
22
|
+
OutputVoltageCapabilities: Static output voltage swing limits.
|
|
23
|
+
PreampCapabilities: Preamp feedback-resistor selection and clip geometry.
|
|
24
|
+
RegisterMapIncomplete: A register needed by the operation is not mapped.
|
|
25
|
+
SelectableCapabilities: An access plus the values it accepts.
|
|
26
|
+
UnexpectedResponse: A response cannot belong to the register it answers.
|
|
27
|
+
|
|
28
|
+
Modules:
|
|
29
|
+
capabilities: Defines the capability model.
|
|
30
|
+
data: Defines the state snapshot and the filter setting.
|
|
31
|
+
errors: Defines the errors shared by drivers.
|
|
32
|
+
protocol: Defines the `CurrentAmplifierProtocol` driver contract.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from .capabilities import (
|
|
36
|
+
Access,
|
|
37
|
+
BandwidthCapabilities,
|
|
38
|
+
BoostCapabilities,
|
|
39
|
+
CompensationCapabilities,
|
|
40
|
+
CurrentAmplifierCapabilities,
|
|
41
|
+
DcBiasCapabilities,
|
|
42
|
+
FilterCapabilities,
|
|
43
|
+
FilterType,
|
|
44
|
+
IndicationCapabilities,
|
|
45
|
+
OutputVoltageCapabilities,
|
|
46
|
+
PreampCapabilities,
|
|
47
|
+
SelectableCapabilities,
|
|
48
|
+
)
|
|
49
|
+
from .data import AmplifierState, FilterSetting
|
|
50
|
+
from .errors import RegisterMapIncomplete, UnexpectedResponse
|
|
51
|
+
from .protocol import CurrentAmplifierProtocol
|
|
52
|
+
|
|
53
|
+
__all__ = [
|
|
54
|
+
"Access",
|
|
55
|
+
"AmplifierState",
|
|
56
|
+
"BandwidthCapabilities",
|
|
57
|
+
"BoostCapabilities",
|
|
58
|
+
"CompensationCapabilities",
|
|
59
|
+
"CurrentAmplifierCapabilities",
|
|
60
|
+
"CurrentAmplifierProtocol",
|
|
61
|
+
"DcBiasCapabilities",
|
|
62
|
+
"FilterCapabilities",
|
|
63
|
+
"FilterSetting",
|
|
64
|
+
"FilterType",
|
|
65
|
+
"IndicationCapabilities",
|
|
66
|
+
"OutputVoltageCapabilities",
|
|
67
|
+
"PreampCapabilities",
|
|
68
|
+
"RegisterMapIncomplete",
|
|
69
|
+
"SelectableCapabilities",
|
|
70
|
+
"UnexpectedResponse",
|
|
71
|
+
]
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Current amplifier capability model.
|
|
3
|
+
|
|
4
|
+
An amplifier advertises what it can do through a single
|
|
5
|
+
:class:`CurrentAmplifierCapabilities` value, grouped by function rather than by
|
|
6
|
+
method name. The grouping is semantic: a driver maps its own vocabulary onto
|
|
7
|
+
these groups, so a caller can ask "can this amplifier change its feedback
|
|
8
|
+
resistor?" without knowing whether the underlying protocol calls the setting a
|
|
9
|
+
resistor or a code.
|
|
10
|
+
|
|
11
|
+
Two kinds of surface are modelled separately. A switch is an :class:`Access`,
|
|
12
|
+
which distinguishes "readable" from "writeable" because many devices expose a
|
|
13
|
+
setting read-only. A switch that also takes a value is a
|
|
14
|
+
:class:`SelectableCapabilities`, which adds the domain of accepted values.
|
|
15
|
+
|
|
16
|
+
A third kind is static geometry: a limit that never changes while the device
|
|
17
|
+
runs, such as the output voltage swing, is capability data rather than state.
|
|
18
|
+
It is read from the capability set directly instead of through a protocol
|
|
19
|
+
method or a ``supports_*`` property.
|
|
20
|
+
|
|
21
|
+
A bandwidth is either selectable or fixed by the analog design, so it has its
|
|
22
|
+
own :class:`BandwidthCapabilities` rather than reusing
|
|
23
|
+
:class:`SelectableCapabilities`, whose empty option tuple cannot express the
|
|
24
|
+
difference.
|
|
25
|
+
|
|
26
|
+
The groups are frozen dataclasses so a driver declares them once as a class
|
|
27
|
+
attribute and callers cannot mutate them.
|
|
28
|
+
|
|
29
|
+
Classes:
|
|
30
|
+
FilterType: The filter responses an amplifier can apply.
|
|
31
|
+
Access: Whether a setting can be read and whether it can be written.
|
|
32
|
+
SelectableCapabilities: An access plus the values it accepts.
|
|
33
|
+
BandwidthCapabilities: A bandwidth domain and whether it is selectable.
|
|
34
|
+
PreampCapabilities: Preamp feedback-resistor selection and clip geometry.
|
|
35
|
+
BoostCapabilities: Boost stage gain selection.
|
|
36
|
+
OutputVoltageCapabilities: Static output voltage swing limits.
|
|
37
|
+
DcBiasCapabilities: DC bias injection surface.
|
|
38
|
+
FilterCapabilities: Signal-filter surface.
|
|
39
|
+
IndicationCapabilities: A status signal and whether it is readable.
|
|
40
|
+
CompensationCapabilities: Input-capacitance compensation surface.
|
|
41
|
+
CurrentAmplifierCapabilities: The complete capability set for one amplifier.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
from dataclasses import dataclass, field
|
|
45
|
+
from enum import Enum
|
|
46
|
+
from typing import Generic, TypeVar
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class FilterType(str, Enum):
|
|
50
|
+
"""The filter responses an amplifier can apply.
|
|
51
|
+
|
|
52
|
+
The member value is the wire spelling a driver sends; it doubles as the
|
|
53
|
+
serialised form because the class inherits from ``str``.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
LOW_PASS = "low_pass"
|
|
57
|
+
HIGH_PASS = "high_pass"
|
|
58
|
+
BAND_PASS = "band_pass"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True, slots=True)
|
|
62
|
+
class Access:
|
|
63
|
+
"""
|
|
64
|
+
Whether a setting can be read and whether it can be written.
|
|
65
|
+
|
|
66
|
+
Attributes:
|
|
67
|
+
read (bool): Whether the current value can be read back.
|
|
68
|
+
write (bool): Whether the value can be set.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
read: bool = False
|
|
72
|
+
write: bool = False
|
|
73
|
+
|
|
74
|
+
def __bool__(self) -> bool:
|
|
75
|
+
"""Return whether the setting is supported in either direction."""
|
|
76
|
+
return self.read or self.write
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
T = TypeVar("T")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True, slots=True, eq=False)
|
|
83
|
+
class SelectableCapabilities(Generic[T]):
|
|
84
|
+
"""
|
|
85
|
+
An access plus the values it accepts.
|
|
86
|
+
|
|
87
|
+
Attributes:
|
|
88
|
+
access (Access): Whether the setting is readable and writeable.
|
|
89
|
+
options (tuple[T, ...]): The values the device accepts, in the device's
|
|
90
|
+
own order and native units. An empty tuple means the device does
|
|
91
|
+
not enumerate its domain, which is typical of a continuous setting
|
|
92
|
+
such as a boost gain or a cutoff frequency; it does **not** mean the
|
|
93
|
+
device accepts no value. A caller that needs the legal domain of an
|
|
94
|
+
enumerating device reads the options, and against a device with an
|
|
95
|
+
empty tuple it must rely on the state snapshot instead.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
access: Access = field(default_factory=Access)
|
|
99
|
+
options: tuple[T, ...] = ()
|
|
100
|
+
|
|
101
|
+
def __bool__(self) -> bool:
|
|
102
|
+
"""Return whether the setting is supported in either direction."""
|
|
103
|
+
return bool(self.access)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@dataclass(frozen=True, slots=True)
|
|
107
|
+
class BandwidthCapabilities:
|
|
108
|
+
"""
|
|
109
|
+
A bandwidth domain and whether the analog design fixes it.
|
|
110
|
+
|
|
111
|
+
Unlike :class:`SelectableCapabilities`, an empty ``options`` tuple here does
|
|
112
|
+
not silently mean "continuous": the four legitimate states are explicit.
|
|
113
|
+
|
|
114
|
+
Legitimate states:
|
|
115
|
+
- Selectable, enumerated: access is truthy, ``options`` is non-empty and
|
|
116
|
+
``fixed_hz`` is ``None``.
|
|
117
|
+
- Selectable, continuous: access is truthy, ``options`` is empty and
|
|
118
|
+
``fixed_hz`` is ``None``.
|
|
119
|
+
- Fixed, known: ``fixed_hz`` is set, access is falsy and ``options`` is
|
|
120
|
+
empty.
|
|
121
|
+
- Fixed, unknown: access is falsy, ``options`` is empty and ``fixed_hz``
|
|
122
|
+
is ``None``.
|
|
123
|
+
|
|
124
|
+
Invalid combinations, each rejected by ``__post_init__``:
|
|
125
|
+
- ``fixed_hz`` set with write access.
|
|
126
|
+
- ``fixed_hz`` set with a non-empty ``options`` tuple.
|
|
127
|
+
- non-empty ``options`` without access.
|
|
128
|
+
- read-only access with neither a domain nor a fixed value.
|
|
129
|
+
|
|
130
|
+
Individual ``options`` values are not validated, matching
|
|
131
|
+
:class:`SelectableCapabilities`.
|
|
132
|
+
|
|
133
|
+
Attributes:
|
|
134
|
+
access (Access): Whether the bandwidth can be read and written.
|
|
135
|
+
options (tuple[float, ...]): Selectable bandwidths in Hz. Empty when the
|
|
136
|
+
domain is continuous or the bandwidth is fixed.
|
|
137
|
+
fixed_hz (float | None): Bandwidth in Hz when the analog design fixes it,
|
|
138
|
+
or ``None`` when the bandwidth is selectable or unknown.
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
access: Access = field(default_factory=Access)
|
|
142
|
+
options: tuple[float, ...] = ()
|
|
143
|
+
fixed_hz: float | None = None
|
|
144
|
+
|
|
145
|
+
def __post_init__(self) -> None:
|
|
146
|
+
if self.fixed_hz is not None and self.fixed_hz <= 0:
|
|
147
|
+
raise ValueError(
|
|
148
|
+
f"fixed bandwidth must be positive, got {self.fixed_hz!r} Hz"
|
|
149
|
+
)
|
|
150
|
+
if self.fixed_hz is not None and self.access.write:
|
|
151
|
+
raise ValueError("a fixed bandwidth cannot be writeable")
|
|
152
|
+
if self.fixed_hz is not None and self.options:
|
|
153
|
+
raise ValueError("a fixed bandwidth cannot enumerate options")
|
|
154
|
+
if self.options and not self.access:
|
|
155
|
+
raise ValueError("bandwidth options require access")
|
|
156
|
+
if (
|
|
157
|
+
self.access.read
|
|
158
|
+
and not self.access.write
|
|
159
|
+
and self.fixed_hz is None
|
|
160
|
+
and not self.options
|
|
161
|
+
):
|
|
162
|
+
raise ValueError(
|
|
163
|
+
"read-only bandwidth requires a known domain or a fixed value"
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
def __bool__(self) -> bool:
|
|
167
|
+
"""Return whether the bandwidth is selectable in either direction."""
|
|
168
|
+
return bool(self.access)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@dataclass(frozen=True, slots=True)
|
|
172
|
+
class PreampCapabilities:
|
|
173
|
+
"""
|
|
174
|
+
Preamp feedback-resistor selection and static clip geometry.
|
|
175
|
+
|
|
176
|
+
The feedback resistor is the only selectable pre-amp control: it sets the
|
|
177
|
+
transimpedance, and the low- and high-current channels the hardware exposes
|
|
178
|
+
are a grouping of ``feedback_resistor.options`` rather than a value of their
|
|
179
|
+
own. The input-current range is therefore derived from the selected
|
|
180
|
+
resistor together with the boost gain and the static clip limits; it is not
|
|
181
|
+
selected directly.
|
|
182
|
+
|
|
183
|
+
Attributes:
|
|
184
|
+
feedback_resistor (SelectableCapabilities[float]): Selectable
|
|
185
|
+
transimpedance feedback-resistor options, in ohm. An empty tuple
|
|
186
|
+
means the domain is continuous or not enumerated.
|
|
187
|
+
max_output_v (float | None): Magnitude of the largest symmetric pre-amp
|
|
188
|
+
output excursion in V, which is where the Overcurrent comparator
|
|
189
|
+
trips. ``None`` means the geometry is unknown.
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
feedback_resistor: SelectableCapabilities[float] = field(
|
|
193
|
+
default_factory=SelectableCapabilities
|
|
194
|
+
)
|
|
195
|
+
max_output_v: float | None = None
|
|
196
|
+
|
|
197
|
+
def __post_init__(self) -> None:
|
|
198
|
+
if self.max_output_v is not None and self.max_output_v <= 0:
|
|
199
|
+
raise ValueError(
|
|
200
|
+
f"max output voltage must be positive, got {self.max_output_v!r} V"
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def output_ceiling_v(
|
|
204
|
+
self, boost_gain: float, amplifier_swing_v: float | None
|
|
205
|
+
) -> float | None:
|
|
206
|
+
"""
|
|
207
|
+
Compute the pre-amp output ceiling before the boost stage clips it.
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
boost_gain: Dimensionless boost stage gain. A gain of ``0.0`` means
|
|
211
|
+
the booster never reaches its rail, so the pre-amp ceiling
|
|
212
|
+
applies unchanged.
|
|
213
|
+
amplifier_swing_v: Symmetric boost-stage output swing in V, or
|
|
214
|
+
``None`` when the amplifier geometry is unknown.
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
float | None: ``min(max_output_v, amplifier_swing_v / boost_gain)``
|
|
218
|
+
in V, or ``None`` when the pre-amp ceiling or the amplifier swing is
|
|
219
|
+
unknown.
|
|
220
|
+
|
|
221
|
+
Raises:
|
|
222
|
+
ValueError: If ``boost_gain`` is negative or ``amplifier_swing_v``
|
|
223
|
+
is negative.
|
|
224
|
+
"""
|
|
225
|
+
if boost_gain < 0:
|
|
226
|
+
raise ValueError(f"boost gain must be non-negative, got {boost_gain!r}")
|
|
227
|
+
if amplifier_swing_v is not None and amplifier_swing_v < 0:
|
|
228
|
+
raise ValueError(
|
|
229
|
+
f"amplifier swing must be non-negative, got {amplifier_swing_v!r} V"
|
|
230
|
+
)
|
|
231
|
+
if self.max_output_v is None or amplifier_swing_v is None:
|
|
232
|
+
return None
|
|
233
|
+
if boost_gain == 0.0:
|
|
234
|
+
return self.max_output_v
|
|
235
|
+
return min(self.max_output_v, amplifier_swing_v / boost_gain)
|
|
236
|
+
|
|
237
|
+
def preamp_limited_current_a(self, feedback_resistor_ohm: float) -> float | None:
|
|
238
|
+
"""
|
|
239
|
+
Compute the input current the pre-amp alone can accept.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
feedback_resistor_ohm: Transimpedance feedback resistance in ohm.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
float | None: ``max_output_v / feedback_resistor_ohm`` in A, ignoring
|
|
246
|
+
the boost stage, or ``None`` when ``max_output_v`` is unknown.
|
|
247
|
+
|
|
248
|
+
Raises:
|
|
249
|
+
ValueError: If ``feedback_resistor_ohm`` is zero or negative.
|
|
250
|
+
"""
|
|
251
|
+
if feedback_resistor_ohm <= 0:
|
|
252
|
+
raise ValueError(
|
|
253
|
+
f"feedback resistor must be positive, got {feedback_resistor_ohm!r} ohm"
|
|
254
|
+
)
|
|
255
|
+
if self.max_output_v is None:
|
|
256
|
+
return None
|
|
257
|
+
return self.max_output_v / feedback_resistor_ohm
|
|
258
|
+
|
|
259
|
+
def input_current_range_a(
|
|
260
|
+
self,
|
|
261
|
+
feedback_resistor_ohm: float,
|
|
262
|
+
boost_gain: float,
|
|
263
|
+
amplifier_swing_v: float | None,
|
|
264
|
+
) -> float | None:
|
|
265
|
+
"""
|
|
266
|
+
Compute the input-current range for a selected feedback resistor.
|
|
267
|
+
|
|
268
|
+
The range is derived, never selected: the limiting output voltage is the
|
|
269
|
+
smaller of the pre-amp ceiling and the boost-stage swing divided by the
|
|
270
|
+
gain, and the current follows from the feedback resistor.
|
|
271
|
+
|
|
272
|
+
Args:
|
|
273
|
+
feedback_resistor_ohm: Transimpedance feedback resistance in ohm.
|
|
274
|
+
boost_gain: Dimensionless boost stage gain.
|
|
275
|
+
amplifier_swing_v: Symmetric boost-stage output swing in V, or
|
|
276
|
+
``None`` when the amplifier geometry is unknown.
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
float | None: The input-current ceiling in A, equal to
|
|
280
|
+
:meth:`output_ceiling_v` divided by ``feedback_resistor_ohm``, or
|
|
281
|
+
``None`` when the pre-amp ceiling or the amplifier swing is unknown.
|
|
282
|
+
|
|
283
|
+
Raises:
|
|
284
|
+
ValueError: If ``feedback_resistor_ohm`` is non-positive,
|
|
285
|
+
``boost_gain`` is negative, or ``amplifier_swing_v`` is negative.
|
|
286
|
+
"""
|
|
287
|
+
if feedback_resistor_ohm <= 0:
|
|
288
|
+
raise ValueError(
|
|
289
|
+
f"feedback resistor must be positive, got {feedback_resistor_ohm!r} ohm"
|
|
290
|
+
)
|
|
291
|
+
ceiling_v = self.output_ceiling_v(boost_gain, amplifier_swing_v)
|
|
292
|
+
if ceiling_v is None:
|
|
293
|
+
return None
|
|
294
|
+
return ceiling_v / feedback_resistor_ohm
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
@dataclass(frozen=True, slots=True)
|
|
298
|
+
class BoostCapabilities:
|
|
299
|
+
"""
|
|
300
|
+
Boost stage gain selection.
|
|
301
|
+
|
|
302
|
+
The boost stage is a dimensionless voltage-gain stage after the preamp, so
|
|
303
|
+
it scales the preamp output without changing the transimpedance.
|
|
304
|
+
|
|
305
|
+
Attributes:
|
|
306
|
+
gain (SelectableCapabilities[float]): Selectable boost gains, as
|
|
307
|
+
dimensionless factors. ``options`` may be empty for a continuously
|
|
308
|
+
settable stage; in that case ``default_gain`` still applies.
|
|
309
|
+
default_gain (float): The gain the device applies at power-on or reset,
|
|
310
|
+
which is unity for this device family.
|
|
311
|
+
"""
|
|
312
|
+
|
|
313
|
+
gain: SelectableCapabilities[float]
|
|
314
|
+
default_gain: float = 1.0
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
@dataclass(frozen=True, slots=True)
|
|
318
|
+
class OutputVoltageCapabilities:
|
|
319
|
+
"""
|
|
320
|
+
Static output voltage swing limits.
|
|
321
|
+
|
|
322
|
+
The limits are geometry rather than runtime state, which is why they live in
|
|
323
|
+
the capability set: they do not change while the device runs. The output
|
|
324
|
+
voltage the device currently reports is a field of the state snapshot.
|
|
325
|
+
|
|
326
|
+
Attributes:
|
|
327
|
+
min_v (float | None): Most negative output voltage in V, or ``None`` when
|
|
328
|
+
the driver does not know the limit.
|
|
329
|
+
max_v (float | None): Most positive output voltage in V, or ``None`` when
|
|
330
|
+
the driver does not know the limit.
|
|
331
|
+
"""
|
|
332
|
+
|
|
333
|
+
min_v: float | None = None
|
|
334
|
+
max_v: float | None = None
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
@dataclass(frozen=True, slots=True)
|
|
338
|
+
class DcBiasCapabilities:
|
|
339
|
+
"""
|
|
340
|
+
DC bias injection surface.
|
|
341
|
+
|
|
342
|
+
Attributes:
|
|
343
|
+
enabled (Access): Whether bias injection can be read and switched.
|
|
344
|
+
level (Access): Whether the bias level can be read and set.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
enabled: Access = field(default_factory=Access)
|
|
348
|
+
level: Access = field(default_factory=Access)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
@dataclass(frozen=True, slots=True)
|
|
352
|
+
class FilterCapabilities:
|
|
353
|
+
"""
|
|
354
|
+
Signal-filter surface.
|
|
355
|
+
|
|
356
|
+
Attributes:
|
|
357
|
+
types (tuple[FilterType, ...]): Filter responses the amplifier supports.
|
|
358
|
+
An empty tuple means no filter is available.
|
|
359
|
+
enabled (Access): Whether the filter can be read and switched on or off.
|
|
360
|
+
cutoff (Access): Whether the filter cutoff frequency can be read and set.
|
|
361
|
+
The frequency domain is carried by the state snapshot, so it is not
|
|
362
|
+
enumerated here.
|
|
363
|
+
"""
|
|
364
|
+
|
|
365
|
+
types: tuple[FilterType, ...] = ()
|
|
366
|
+
enabled: Access = field(default_factory=Access)
|
|
367
|
+
cutoff: Access = field(default_factory=Access)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
@dataclass(frozen=True, slots=True)
|
|
371
|
+
class IndicationCapabilities:
|
|
372
|
+
"""
|
|
373
|
+
A status signal that may exist without being readable.
|
|
374
|
+
|
|
375
|
+
Two questions are distinct: whether the signal exists on the device, and
|
|
376
|
+
whether the firmware can read it.
|
|
377
|
+
|
|
378
|
+
Combinations:
|
|
379
|
+
- Absent: ``(present=False, read=False)``.
|
|
380
|
+
- Present but unobservable: ``(present=True, read=False)``.
|
|
381
|
+
- Present and observable: ``(present=True, read=True)``.
|
|
382
|
+
- Invalid: ``(present=False, read=True)``, rejected by
|
|
383
|
+
``__post_init__``.
|
|
384
|
+
|
|
385
|
+
Truthiness answers "does this signal exist", never "can it be read".
|
|
386
|
+
|
|
387
|
+
Attributes:
|
|
388
|
+
present (bool): Whether the signal exists on the device.
|
|
389
|
+
read (bool): Whether the driver can read it.
|
|
390
|
+
"""
|
|
391
|
+
|
|
392
|
+
present: bool = False
|
|
393
|
+
read: bool = False
|
|
394
|
+
|
|
395
|
+
def __post_init__(self) -> None:
|
|
396
|
+
if self.read and not self.present:
|
|
397
|
+
raise ValueError("a readable indication must be present")
|
|
398
|
+
|
|
399
|
+
def __bool__(self) -> bool:
|
|
400
|
+
"""Return whether the signal exists on the device."""
|
|
401
|
+
return self.present
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@dataclass(frozen=True, slots=True)
|
|
405
|
+
class CompensationCapabilities:
|
|
406
|
+
"""
|
|
407
|
+
Input-capacitance compensation surface.
|
|
408
|
+
|
|
409
|
+
Compensation cancels the pole formed by the source capacitance and the
|
|
410
|
+
feedback resistor, so it is a pair of settings rather than one.
|
|
411
|
+
|
|
412
|
+
Attributes:
|
|
413
|
+
enabled (Access): Whether compensation can be read and switched.
|
|
414
|
+
level (Access): Whether the compensation level can be read and set.
|
|
415
|
+
"""
|
|
416
|
+
|
|
417
|
+
enabled: Access = field(default_factory=Access)
|
|
418
|
+
level: Access = field(default_factory=Access)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
@dataclass(frozen=True, slots=True)
|
|
422
|
+
class CurrentAmplifierCapabilities:
|
|
423
|
+
"""
|
|
424
|
+
The complete capability set for one amplifier.
|
|
425
|
+
|
|
426
|
+
Every group defaults to "unsupported", so a driver declares only what it
|
|
427
|
+
actually implements.
|
|
428
|
+
|
|
429
|
+
A capability answers whether a feature is available; it does not answer
|
|
430
|
+
whether the feature is currently on. A present feature that is switched off
|
|
431
|
+
is truthy here (``bool(...) is True``) while the state flag in the snapshot
|
|
432
|
+
is ``False``. Filtering on capabilities and reading the state are therefore
|
|
433
|
+
both required to act correctly.
|
|
434
|
+
|
|
435
|
+
Attributes:
|
|
436
|
+
preamp (PreampCapabilities): Preamp feedback-resistor selection and
|
|
437
|
+
static clip geometry.
|
|
438
|
+
boost (BoostCapabilities): Boost stage gain selection.
|
|
439
|
+
output_voltage (OutputVoltageCapabilities): Static output voltage swing
|
|
440
|
+
limits, in V.
|
|
441
|
+
dc_bias (DcBiasCapabilities): DC bias injection surface.
|
|
442
|
+
bandwidth (BandwidthCapabilities): Bandwidth domain and whether the
|
|
443
|
+
analog design fixes it.
|
|
444
|
+
filters (FilterCapabilities): Signal-filter surface.
|
|
445
|
+
input_overcurrent (IndicationCapabilities): Input-overcurrent signal.
|
|
446
|
+
output_overload (IndicationCapabilities): Output-overload signal.
|
|
447
|
+
input_compensation (CompensationCapabilities): Input-capacitance
|
|
448
|
+
compensation surface.
|
|
449
|
+
invert_output (Access): Whether the output polarity can be read and set.
|
|
450
|
+
"""
|
|
451
|
+
|
|
452
|
+
preamp: PreampCapabilities = field(default_factory=PreampCapabilities)
|
|
453
|
+
boost: BoostCapabilities = field(
|
|
454
|
+
default_factory=lambda: BoostCapabilities(gain=SelectableCapabilities())
|
|
455
|
+
)
|
|
456
|
+
output_voltage: OutputVoltageCapabilities = field(
|
|
457
|
+
default_factory=OutputVoltageCapabilities
|
|
458
|
+
)
|
|
459
|
+
dc_bias: DcBiasCapabilities = field(default_factory=DcBiasCapabilities)
|
|
460
|
+
bandwidth: BandwidthCapabilities = field(default_factory=BandwidthCapabilities)
|
|
461
|
+
filters: FilterCapabilities = field(default_factory=FilterCapabilities)
|
|
462
|
+
input_overcurrent: IndicationCapabilities = field(
|
|
463
|
+
default_factory=IndicationCapabilities
|
|
464
|
+
)
|
|
465
|
+
output_overload: IndicationCapabilities = field(
|
|
466
|
+
default_factory=IndicationCapabilities
|
|
467
|
+
)
|
|
468
|
+
input_compensation: CompensationCapabilities = field(
|
|
469
|
+
default_factory=CompensationCapabilities
|
|
470
|
+
)
|
|
471
|
+
invert_output: Access = field(default_factory=Access)
|
|
472
|
+
|
|
473
|
+
def total_transconductance(
|
|
474
|
+
self, feedback_resistor_ohm: float, boost_gain: float = 1.0
|
|
475
|
+
) -> float:
|
|
476
|
+
"""
|
|
477
|
+
Compute the whole-amplifier transconductance.
|
|
478
|
+
|
|
479
|
+
The preamp converts input current to voltage through the feedback
|
|
480
|
+
resistor and the boost stage multiplies that voltage, so the
|
|
481
|
+
transimpedance and the boost are the only two factors.
|
|
482
|
+
|
|
483
|
+
Args:
|
|
484
|
+
feedback_resistor_ohm: Transimpedance feedback resistance in ohm.
|
|
485
|
+
boost_gain: Dimensionless boost stage gain. The default of ``1.0``
|
|
486
|
+
is the unity gain this device family applies at power-on.
|
|
487
|
+
|
|
488
|
+
Returns:
|
|
489
|
+
float: Transconductance in V/A, equal to ``Rf * boost``.
|
|
490
|
+
|
|
491
|
+
Raises:
|
|
492
|
+
ValueError: If ``feedback_resistor_ohm`` is zero or negative, since
|
|
493
|
+
such a resistor cannot define a transimpedance.
|
|
494
|
+
"""
|
|
495
|
+
if feedback_resistor_ohm <= 0:
|
|
496
|
+
raise ValueError(
|
|
497
|
+
f"feedback resistor must be positive, got {feedback_resistor_ohm!r} ohm"
|
|
498
|
+
)
|
|
499
|
+
return feedback_resistor_ohm * boost_gain
|
|
500
|
+
|
|
501
|
+
def max_output_swing_v(self) -> float | None:
|
|
502
|
+
"""
|
|
503
|
+
Compute the largest symmetric output excursion.
|
|
504
|
+
|
|
505
|
+
Returns:
|
|
506
|
+
float | None: The smaller of ``|min_v|`` and ``|max_v|``, in V, which
|
|
507
|
+
is how far the output can swing in either direction without
|
|
508
|
+
clipping. ``None`` when either limit is unknown, because a symmetric
|
|
509
|
+
excursion then cannot be guaranteed.
|
|
510
|
+
"""
|
|
511
|
+
limits = self.output_voltage
|
|
512
|
+
if limits.min_v is None or limits.max_v is None:
|
|
513
|
+
return None
|
|
514
|
+
return min(abs(limits.min_v), abs(limits.max_v))
|
|
515
|
+
|
|
516
|
+
def max_input_current_a(
|
|
517
|
+
self, feedback_resistor_ohm: float, boost_gain: float = 1.0
|
|
518
|
+
) -> float | None:
|
|
519
|
+
"""
|
|
520
|
+
Compute the input current at which the amplifier clips.
|
|
521
|
+
|
|
522
|
+
The ceiling is derived from the preamp feedback resistor, the boost gain
|
|
523
|
+
and the static clip limits; it is not a selectable control.
|
|
524
|
+
|
|
525
|
+
Args:
|
|
526
|
+
feedback_resistor_ohm: Transimpedance feedback resistance in ohm.
|
|
527
|
+
boost_gain: Dimensionless boost stage gain. The default of ``1.0``
|
|
528
|
+
is the unity gain this device family applies at power-on.
|
|
529
|
+
|
|
530
|
+
Returns:
|
|
531
|
+
float | None: The input-current ceiling in A, delegated to
|
|
532
|
+
:meth:`PreampCapabilities.input_current_range_a`. ``None`` when the
|
|
533
|
+
amplifier swing or the pre-amp ceiling is unknown.
|
|
534
|
+
|
|
535
|
+
Raises:
|
|
536
|
+
ValueError: If ``feedback_resistor_ohm`` is zero or negative, or
|
|
537
|
+
``boost_gain`` is negative.
|
|
538
|
+
"""
|
|
539
|
+
return self.preamp.input_current_range_a(
|
|
540
|
+
feedback_resistor_ohm, boost_gain, self.max_output_swing_v()
|
|
541
|
+
)
|