Skip to content

Commit b3f2f07

Browse files
committed
fix gndlink in .connecteds and make things compile
1 parent 457c5a1 commit b3f2f07

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

edg/abstract_parts/AbstractDevices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def __init__(self, voltage: RangeLike,
1717
self.capacity = self.ArgParameter(capacity)
1818
self.actual_capacity = self.Parameter(RangeExpr())
1919

20-
self.require(self.pwr.voltage_out.within(voltage))
20+
self.require(self.pwr.voltage_out.within(voltage + self.gnd.link().voltage))
2121
self.require(self.pwr.current_limits.contains(current))
2222
self.require(self.actual_capacity.upper() >= capacity)

edg/abstract_parts/AbstractResistor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(self, resistance: RangeLike) -> None:
157157
DigitalSource.pulldown_from_supply(self.gnd)
158158
), [InOut])
159159

160-
def connected(self, gnd: Optional[Port[VoltageLink]] = None, io: Optional[Port[DigitalLink]] = None) -> \
160+
def connected(self, gnd: Optional[Port[GroundLink]] = None, io: Optional[Port[DigitalLink]] = None) -> \
161161
'PulldownResistor':
162162
"""Convenience function to connect both ports, returning this object so it can still be given a name."""
163163
if gnd is not None:

edg/abstract_parts/PassiveFilters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, impedance: RangeLike, time_constant: RangeLike):
5151
self.io = self.Export(self.rc.output.adapt_to(DigitalSource.pullup_from_supply(self.pwr)), [Output])
5252
self.gnd = self.Export(self.rc.gnd.adapt_to(Ground()), [Common])
5353

54-
def connected(self, *, gnd: Optional[Port[VoltageLink]] = None, pwr: Optional[Port[VoltageLink]] = None,
54+
def connected(self, *, gnd: Optional[Port[GroundLink]] = None, pwr: Optional[Port[VoltageLink]] = None,
5555
io: Optional[Port[DigitalLink]] = None) -> 'PullupDelayRc':
5656
"""Convenience function to connect both ports, returning this object so it can still be given a name."""
5757
if gnd is not None:

edg/electronics_model/CircuitBlock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .KiCadImportableBlock import KiCadImportableBlock
1010

1111

12-
CircuitLinkType = TypeVar('CircuitLinkType', bound=Link)
12+
CircuitLinkType = TypeVar('CircuitLinkType', bound=Link, covariant=True)
1313
class CircuitPort(Port[CircuitLinkType], Generic[CircuitLinkType]):
1414
"""Electrical connection that represents a single port into a single copper net"""
1515
pass

edg/electronics_model/DigitalPorts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def __init__(self, *, voltage_limits: RangeLike = RangeExpr.ALL,
471471
class DigitalSingleSourceFake:
472472
@staticmethod
473473
@deprecated("use DigitalSource.sink_from_supply")
474-
def low_from_supply(neg: Port[VoltageLink], is_pulldown: bool = False) -> DigitalSource:
474+
def low_from_supply(neg: Port[GroundLink], is_pulldown: bool = False) -> DigitalSource:
475475
if not is_pulldown:
476476
return DigitalSource.low_from_supply(neg)
477477
else:

edg/parts/Batteries.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, Union
22

33
from ..abstract_parts import *
44

@@ -57,8 +57,8 @@ def contents(self):
5757
class AaBattery(Battery, FootprintBlock):
5858
"""AA battery holder supporting alkaline and rechargeable chemistries."""
5959
@init_in_parent
60-
def __init__(self, voltage: RangeLike = (0.9, 1.6)*Volt, *args,
61-
actual_voltage: RangeLike = (0.9, 1.6)*Volt, **kwargs):
60+
def __init__(self, voltage: RangeLike = (1.0, 1.6)*Volt, *args,
61+
actual_voltage: RangeLike = (1.0, 1.6)*Volt, **kwargs):
6262
super().__init__(voltage, *args, **kwargs)
6363
self.gnd.init_from(Ground())
6464
self.pwr.init_from(VoltageSource(
@@ -84,22 +84,28 @@ def contents(self):
8484
class AaBatteryStack(Battery, GeneratorBlock):
8585
"""AA Alkaline battery stack that generates batteries in series"""
8686
@init_in_parent
87-
def __init__(self, count: IntLike = 1, *, cell_actual_voltage: RangeLike = (0.9, 1.6)*Volt):
88-
super().__init__()
87+
def __init__(self, count: IntLike = 1, *, cell_actual_voltage: RangeLike = (1.0, 1.6)*Volt):
88+
super().__init__(voltage=Range.all()) # no voltage spec passed in
8989
self.count = self.ArgParameter(count)
9090
self.cell_actual_voltage = self.ArgParameter(cell_actual_voltage)
9191
self.generator_param(self.count)
9292

9393
def generate(self):
9494
super().generate()
9595
prev_cell: Optional[AaBattery] = None
96+
prev_capacity_min: Union[FloatExpr, float] = float('inf')
97+
prev_capacity_max: Union[FloatExpr, float] = float('inf')
9698
self.cell = ElementDict[AaBattery]()
9799
for i in range(self.get(self.count)):
98100
self.cell[i] = cell = self.Block(AaBattery(actual_voltage=self.cell_actual_voltage))
99-
if prev_cell is None: # direct connect to gnd
101+
if prev_cell is None: # first cell, direct connect to gnd
100102
self.connect(self.gnd, cell.gnd)
101103
else:
102-
self.connect(prev_cell.pwr.as_ground(), cell.gnd)
104+
self.connect(prev_cell.pwr.as_ground(self.pwr.link().current_drawn), cell.gnd)
105+
prev_capacity_min = cell.actual_capacity.lower().min(prev_capacity_min)
106+
prev_capacity_max= cell.actual_capacity.upper().min(prev_capacity_max)
107+
prev_cell = cell
103108

104109
assert prev_cell is not None, "must generate >=1 cell"
105110
self.connect(self.pwr, prev_cell.pwr)
111+
self.assign(self.actual_capacity, (prev_capacity_min, prev_capacity_max))

edg/parts/Microcontroller_Rp2040.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def contents(self) -> None:
432432

433433
self.pwr_vin.init_from(VoltageSink( # based on RS3236-3.3
434434
voltage_limits=(3.3*1.025 + 0.55, 7.5)*Volt, # output * tolerance + dropout @ 300mA
435+
current_draw=RangeExpr()
435436
))
436437
self.vusb_out.init_from(VoltageSource(
437438
voltage_out=UsbConnector.USB2_VOLTAGE_RANGE,
@@ -447,7 +448,7 @@ def contents(self) -> None:
447448
))
448449
self.require(~self.pwr_out.is_connected() | ~self.pwr.is_connected(), "cannot use both 3.3v out and 3.3v in")
449450
self.assign(self.pwr_vin.current_draw, self.pwr_out.is_connected().then_else( # prop output current draw
450-
self.pwr_out.link().current_drawn, (0, 0)
451+
self.pwr_out.link().current_drawn, (0, 0)*Amp
451452
))
452453

453454
self.generator_param(self.pwr.is_connected())

edg/parts/PowerConditioning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def contents(self):
254254
'gnd': Ground(),
255255
})
256256

257-
def connected_from(self, gnd: Optional[Port[VoltageLink]] = None, pwr_hi: Optional[Port[VoltageLink]] = None,
257+
def connected_from(self, gnd: Optional[Port[GroundLink]] = None, pwr_hi: Optional[Port[VoltageLink]] = None,
258258
pwr_lo: Optional[Port[VoltageLink]] = None) -> 'PriorityPowerOr':
259259
"""Convenience function to connect ports, returning this object so it can still be given a name."""
260260
if gnd is not None:

examples/test_blinky.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestBlinkyEmpty(SimpleBoardTop):
2020
class TestBlinkyBasicBattery(SimpleBoardTop):
2121
"""The simplest cirucit, a microcontroller dev board with a LED, powered from a battery"""
2222
def contents(self) -> None:
23-
self.bat = self.Block(AaBatteryStack(3))
23+
self.bat = self.Block(AaBatteryStack(4))
2424
self.mcu = self.Block(Xiao_Rp2040())
2525
self.led = self.Block(IndicatorLed())
2626

0 commit comments

Comments
 (0)