@@ -281,6 +281,50 @@ class SpiConfig(namedtuple("SpiConfig", ["freq", "mode", "cspol", "sck", "mosi",
281
281
"""
282
282
283
283
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
+
284
328
class RaspberryScpiPico (MicroScpiDevice ):
285
329
kw_machine = ScpiKeyword ("MACHINE" , "MACHINE" , None )
286
330
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):
572
616
else :
573
617
self .error_push (E_SYNTAX )
574
618
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
-
615
619
def cb_pin_val (self , param = "" , opt = None ):
616
620
"""
617
621
- 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):
633
637
elif param is not None :
634
638
# print("cb_pin_val", pin_number, param)
635
639
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 )
637
641
self .pin_conf [pin_number ] = PinConfig (machine .Pin .OUT , IO_ON , conf .pull )
638
642
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 )
640
644
self .pin_conf [pin_number ] = PinConfig (machine .Pin .OUT , IO_OFF , conf .pull )
641
645
else :
642
646
self .error_push (E_INVALID_PARAMETER )
@@ -666,8 +670,10 @@ def cb_pin_mode(self, param="", opt=None):
666
670
# print("cb_pin_mode", pin_number, param)
667
671
if self .kw_in .match (param ).match :
668
672
mode = machine .Pin .IN
673
+ vp_set_pin_mode_in (pin_number )
669
674
elif self .kw_out .match (param ).match :
670
675
mode = machine .Pin .OUT
676
+ vp_set_pin_mode_out (pin_number )
671
677
elif self .kw_od .match (param ).match :
672
678
mode = machine .Pin .OPEN_DRAIN
673
679
elif self .kw_pwm .match (param ).match :
0 commit comments