Skip to content

Commit 5cb2fec

Browse files
committed
move viper functions out of class
1 parent ad6f57b commit 5cb2fec

File tree

1 file changed

+48
-42
lines changed

1 file changed

+48
-42
lines changed

micropython/RaspberryScpiPico.py

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,50 @@ class SpiConfig(namedtuple("SpiConfig", ["freq", "mode", "cspol", "sck", "mosi",
281281
"""
282282

283283

284+
@viper
285+
def vp_set_pin_hi(pin: int) -> None:
286+
""" Viper code to set pin high
287+
:param int pin: IO pin 0-29
288+
"""
289+
gpio_oe_set_p = ptr32(_REG_GPIO_OE_SET)
290+
gpio_out_set_p = ptr32(_REG_GPIO_OUT_SET)
291+
292+
gpio_oe_set_p[0] = 1 << pin
293+
gpio_out_set_p[0] = 1 << pin
294+
295+
296+
@viper
297+
def vp_set_pin_lo(pin: int) -> None:
298+
""" Viper code to set pin low
299+
:param int pin: IO pin 0-29
300+
"""
301+
gpio_oe_set_p = ptr32(_REG_GPIO_OE_SET)
302+
gpio_out_clr_p = ptr32(_REG_GPIO_OUT_CLR)
303+
304+
gpio_oe_set_p[0] = 1 << pin
305+
gpio_out_clr_p[0] = 1 << pin
306+
307+
308+
@viper
309+
def vp_set_pin_mode_in(pin: int) -> None:
310+
""" Viper code to set a pin input mode
311+
:param int pin: IO pin 0-29
312+
"""
313+
gpio_oe_clr_p = ptr32(_REG_GPIO_OE_CLR)
314+
315+
gpio_oe_clr_p[0] = 1 << pin
316+
317+
318+
@viper
319+
def vp_set_pin_mode_out(pin: int) -> None:
320+
""" Viper code to set a pin output mode
321+
:param int pin: IO pin 0-29
322+
"""
323+
gpio_oe_set_p = ptr32(_REG_GPIO_OE_SET)
324+
325+
gpio_oe_set_p[0] = 1 << pin
326+
327+
284328
class RaspberryScpiPico(MicroScpiDevice):
285329
kw_machine = ScpiKeyword("MACHINE", "MACHINE", None)
286330
kw_pin = ScpiKeyword("PIN", "PIN", ["14", "15", "16", "17", "18", "19", "20", "21", "22", "25", "?"])
@@ -572,46 +616,6 @@ def cb_pin_status(self, param="", opt=None):
572616
else:
573617
self.error_push(E_SYNTAX)
574618

575-
@viper
576-
def set_pin_hi(self, pin: int) -> None:
577-
""" Viper code to set pin high
578-
:param int pin: IO pin 0-29
579-
"""
580-
gpio_oe_set_p = ptr32(_REG_GPIO_OE_SET)
581-
gpio_out_set_p = ptr32(_REG_GPIO_OUT_SET)
582-
583-
gpio_oe_set_p[0] = 1 << pin
584-
gpio_out_set_p[0] = 1 << pin
585-
586-
@viper
587-
def set_pin_lo(self, pin: int) -> None:
588-
""" Viper code to set pin low
589-
:param int pin: IO pin 0-29
590-
"""
591-
gpio_oe_set_p = ptr32(_REG_GPIO_OE_SET)
592-
gpio_out_clr_p = ptr32(_REG_GPIO_OUT_CLR)
593-
594-
gpio_oe_set_p[0] = 1 << pin
595-
gpio_out_clr_p[0] = 1 << pin
596-
597-
@viper
598-
def set_pin_mode_in(self, pin: int) -> None:
599-
""" Viper code to set a pin input mode
600-
:param int pin: IO pin 0-29
601-
"""
602-
gpio_oe_clr_p = ptr32(_REG_GPIO_OE_CLR)
603-
604-
gpio_oe_clr_p[0] = 1 << pin
605-
606-
@viper
607-
def set_pin_mode_out(self, pin: int) -> None:
608-
""" Viper code to set a pin output mode
609-
:param int pin: IO pin 0-29
610-
"""
611-
gpio_oe_set_p = ptr32(_REG_GPIO_OE_SET)
612-
613-
gpio_oe_set_p[0] = 1 << pin
614-
615619
def cb_pin_val(self, param="", opt=None):
616620
"""
617621
- PIN[14|15|16|17|18|19|20|21|22|25]:VALue[?] 0|1|OFF|ON
@@ -633,10 +637,10 @@ def cb_pin_val(self, param="", opt=None):
633637
elif param is not None:
634638
# print("cb_pin_val", pin_number, param)
635639
if param == str(IO_ON) or self.kw_on.match(param).match:
636-
self.set_pin_hi(pin_number)
640+
vp_set_pin_hi(pin_number)
637641
self.pin_conf[pin_number] = PinConfig(machine.Pin.OUT, IO_ON, conf.pull)
638642
elif param == str(IO_OFF) or self.kw_off.match(param).match:
639-
self.set_pin_lo(pin_number)
643+
vp_set_pin_lo(pin_number)
640644
self.pin_conf[pin_number] = PinConfig(machine.Pin.OUT, IO_OFF, conf.pull)
641645
else:
642646
self.error_push(E_INVALID_PARAMETER)
@@ -666,8 +670,10 @@ def cb_pin_mode(self, param="", opt=None):
666670
# print("cb_pin_mode", pin_number, param)
667671
if self.kw_in.match(param).match:
668672
mode = machine.Pin.IN
673+
vp_set_pin_mode_in(pin_number)
669674
elif self.kw_out.match(param).match:
670675
mode = machine.Pin.OUT
676+
vp_set_pin_mode_out(pin_number)
671677
elif self.kw_od.match(param).match:
672678
mode = machine.Pin.OPEN_DRAIN
673679
elif self.kw_pwm.match(param).match:

0 commit comments

Comments
 (0)