示例#1
0
def resolve_bus_name(mcu, param, bus):
    # Find enumerations for the given bus
    enumerations = mcu.get_enumerations()
    enums = enumerations.get(param, enumerations.get('bus'))
    if enums is None:
        if bus is None:
            return 0
        return bus
    # Verify bus is a valid enumeration
    ppins = mcu.get_printer().lookup_object("pins")
    mcu_name = mcu.get_name()
    if bus is None:
        rev_enums = {v: k for k, v in enums.items()}
        if 0 not in rev_enums:
            raise ppins.error("Must specify %s on mcu '%s'" %
                              (param, mcu_name))
        bus = rev_enums[0]
    if bus not in enums:
        raise ppins.error("Unknown %s '%s'" % (param, bus))
    # Check for reserved bus pins
    constants = mcu.get_constants()
    reserve_pins = constants.get('BUS_PINS_%s' % (bus, ), None)
    pin_resolver = ppins.get_pin_resolver(mcu_name)
    if reserve_pins is not None:
        for pin in reserve_pins.split(','):
            pin_resolver.reserve_pin(pin, bus)
    return bus
示例#2
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