예제 #1
0
 def __init__(self, mcu, pin_desc, cmd_queue=None, value=0):
     self.mcu = mcu
     self.oid = mcu.create_oid()
     ppins = mcu.get_printer().lookup_object('pins')
     pin_params = ppins.lookup_pin(pin_desc)
     if pin_params['chip'] is not mcu:
         raise ppins.error("Pin %s must be on mcu %s" %
                           (pin_desc, mcu.get_name()))
     mcu.add_config_cmd("config_digital_out oid=%d pin=%s value=%d"
                        " default_value=%d max_duration=%d" %
                        (self.oid, pin_params['pin'], value, value, 0))
     mcu.register_config_callback(self.build_config)
     if cmd_queue is None:
         cmd_queue = mcu.alloc_command_queue()
     self.cmd_queue = cmd_queue
     self.update_pin_cmd = None
예제 #2
0
 def __init__(self, mcu, bus, pin, mode, speed, sw_pins=None):
     self.mcu = mcu
     self.bus = bus
     # Config SPI object (set all CS pins high before spi_set_bus commands)
     self.oid = mcu.create_oid()
     if pin is None:
         mcu.add_config_cmd("config_spi_without_cs oid=%d" % (self.oid, ))
     else:
         mcu.add_config_cmd("config_spi oid=%d pin=%s" % (self.oid, pin))
     # Generate SPI bus config message
     if sw_pins is not None:
         self.config_fmt = (
             "spi_set_software_bus oid=%d"
             " miso_pin=%s mosi_pin=%s sclk_pin=%s mode=%d rate=%d" %
             (self.oid, sw_pins[0], sw_pins[1], sw_pins[2], mode, speed))
     else:
         self.config_fmt = (
             "spi_set_bus oid=%d spi_bus=%%s mode=%d rate=%d" %
             (self.oid, mode, speed))
     self.cmd_queue = mcu.alloc_command_queue()
     mcu.register_config_callback(self.build_config)
     self.spi_send_cmd = self.spi_transfer_cmd = None