Skip to content

Commit

Permalink
fixed: squash more warnings, implement __eq__, from_bits
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Sep 23, 2024
1 parent 2bfb5fc commit 87507d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 28 additions & 2 deletions gateware/src/amaranth_future/fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def const(self, value):
value = 0
return Const(value, self)._target

def from_bits(self, raw):
c = Const(0, self)
c._value = raw
return c

def max(self):
c = Const(0, self)
c._value = c._max_value()
Expand Down Expand Up @@ -233,11 +238,28 @@ def __rshift__(self, other):
return Value.cast(self.round(f_width).raw() >> other, f_width)

def __lt__(self, other):
return self.__sub__(other).raw() < 0
if isinstance(other, hdl.Value):
other = Value.cast(other)
elif isinstance(other, int):
other = Const(other)
elif not isinstance(other, Value):
raise TypeError(f"Object {other!r} cannot be converted to a fixed.Value")
f_width = max(self.f_width, other.f_width)
return self.round(f_width).raw() < other.round(f_width).raw()

def __ge__(self, other):
return ~self.__lt__(other)

def __eq__(self, other):
if isinstance(other, hdl.Value):
other = Value.cast(other)
elif isinstance(other, int):
other = Const(other)
elif not isinstance(other, Value):
raise TypeError(f"Object {other!r} cannot be converted to a fixed.Value")
f_width = max(self.f_width, other.f_width)
return self.round(f_width).raw() == other.round(f_width).raw()

def __repr__(self):
return f"(fixedpoint {'SQ' if self.signed else 'UQ'}{self.i_width}.{self.f_width} {self._target!r})"

Expand All @@ -247,7 +269,11 @@ def __init__(self, value, shape=None):

if isinstance(value, float) or isinstance(value, int):
num, den = value.as_integer_ratio()

elif isinstance(value, Const):
# FIXME: Memory inits seem to construct a fixed.Const with fixed.Const
self._shape = value._shape
self._value = value._value
return
else:
raise TypeError(f"Object {value!r} cannot be converted to a fixed.Const")

Expand Down
2 changes: 1 addition & 1 deletion gateware/src/tiliqua/eurorack_pmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class EurorackPmod(wiring.Component):
eeprom_serial: Out(32)

# Bitwise manual LED overrides. 1 == audio passthrough, 0 == manual set.
led_mode: In(8, reset=0xff)
led_mode: In(8, init=0xff)
# If an LED is in manual, this is signed i8 from -green to +red
led: In(8).array(8)

Expand Down

0 comments on commit 87507d7

Please sign in to comment.