Skip to content

Commit

Permalink
deprecated input_byte and co. ability to read back what we've written…
Browse files Browse the repository at this point in the history
… to bidirs
  • Loading branch information
psychogenic committed Nov 23, 2024
1 parent cce767b commit 95edf39
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 121 deletions.
2 changes: 1 addition & 1 deletion src/ttboard/boot/firstboot_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def say_hello(delay_interval_ms:int=200, times:int=1):
tt.clock_project_PWM(1e3) # clock it real good

log.info('First boot: saying hello')
tt.uio_oe[:] = [Pins.OUT] * 8 # set as outputs
tt.uio_oe_pico[:] = [Pins.OUT] * 8 # set as outputs

short_delay_ms = int(delay_interval_ms/10)
if short_delay_ms < 10:
Expand Down
115 changes: 1 addition & 114 deletions src/ttboard/pins/pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _init_ioports(self):
port_defs = [
('uo_out', platform.read_output_byte, platform.write_output_byte),
('ui_in', platform.read_input_byte, platform.write_input_byte),
('uio_in', None, platform.write_bidir_byte),
('uio_in', platform.read_bidir_byte, platform.write_bidir_byte),
('uio_out', platform.read_bidir_byte, None)
]
self._ports = dict()
Expand Down Expand Up @@ -197,119 +197,6 @@ def mode(self, setTo:int):
beginFunc = startupMap[setTo]
beginFunc()

def _setmode_on_pins(self, pinslist:list, modelist:list):
max_idx = len(pinslist)
if len(modelist) < max_idx:
max_idx = len(modelist)

for i in range(max_idx):
p = pinslist[i]
p.mode = modelist[i]

def _getmode_for_pins(self, pinslist:list):
return list(map(lambda x: x.mode, pinslist))

@property
def outputs(self):
return self.list_port('out')

@property
def output_pins(self):
return self.list_port('pin_out')

@property
def output_byte(self):

if platform.IsRP2040:
return platform.read_output_byte()
return self._read_byte(self.outputs)

@output_byte.setter
def output_byte(self, val:int):

if platform.IsRP2040:
platform.write_output_byte(val)
else:
self._write_byte(self.outputs, val)

@property
def output_mode(self):
return self._getmode_for_pins(self.outputs)

@output_mode.setter
def output_mode(self, pinmodes:list):
self._setmode_on_pins(self.outputs, pinmodes)


@property
def inputs(self):
return self.list_port('in')

@property
def input_pins(self):
return self.list_port('pin_in')

@property
def input_byte(self):

if platform.IsRP2040:
return platform.read_input_byte()

return self._read_byte(self.inputs)


@input_byte.setter
def input_byte(self, val:int):

if platform.IsRP2040:
platform.write_input_byte(val)
else:
self._write_byte(self.inputs, val)



@property
def input_mode(self):
return self._getmode_for_pins(self.inputs)

@input_mode.setter
def input_mode(self, pinmodes:list):
self._setmode_on_pins(self.inputs, pinmodes)


@property
def bidirs(self):
return self.list_port('uio')

@property
def bidir_pins(self):
return self.list_port('pin_uio')

@property
def bidir_byte(self):


if platform.IsRP2040:
return platform.read_bidir_byte()

return self._read_byte(self.bidirs)

@bidir_byte.setter
def bidir_byte(self, val:int):
if platform.IsRP2040:
platform.write_bidir_byte(val)
else:
self._write_byte(self.bidirs, val)


@property
def bidir_mode(self):
return self._getmode_for_pins(self.bidirs)

@bidir_mode.setter
def bidir_mode(self, pinmodes:list):
self._setmode_on_pins(self.bidirs, pinmodes)

def begin_inputs_all(self):

log.debug(f'Begin inputs all with {gp.GPIOMap}')
Expand Down
12 changes: 12 additions & 0 deletions src/ttboard/types/logic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ def __eq__(
return self == other
else:
return NotImplemented

def __gt__(self, other):
return int(self) > int(other)

def __ge__(self, other):
return int(self) >= int(other)

def __lt__(self, other):
return int(self) < int(other)
def __le__(self, other):
return int(self) <= int(other)


@property
def is_resolvable(self) -> bool:
Expand Down
9 changes: 3 additions & 6 deletions src/ttboard/util/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ def write_bidir_byte(val):
# for bidir, all uio bits are in a line starting
# at GPIO 21
val = (val << 21)
# xor with current GPIO values, and mask to keep only input bits
val = (machine.mem32[0xd0000010] ^ val) & 0x1FE00000
# val is now be all the bits that have CHANGED:
# writing to 0xd000001c will flip any GPIO where a 1 is found,
# only applies immediately to pins set as output
machine.mem32[0xd000001c] = val


@micropython.native
def read_bidir_byte():
return (machine.mem32[0xd0000004] & (0xff << 21)) >> 21

@micropython.native
def read_bidir_outputenable():
Expand All @@ -156,11 +158,6 @@ def write_bidir_outputenable(val):
val = (val << 21)
machine.mem32[0xd0000020] = (machine.mem32[0xd0000020] & ((1 << 21) - 1)) | val

@micropython.native
def read_bidir_byte():
# just read the high and low nibbles from GPIO and combine into a byte
return (machine.mem32[0xd0000004] & (0xff << 21)) >> 21

@micropython.native
def write_output_byte(val):
# low level machine stuff
Expand Down

0 comments on commit 95edf39

Please sign in to comment.