def upload(self, args, device=-1): ret = self.process_arguments(args) if isinstance(ret, int): return ret if isinstance(ret, tuple): variables, board = ret detected_boards = System().detect_boards() if isinstance(detected_boards, int): return detected_boards if device: # Check device argument if board: desc = self.resources.boards[board]['ftdi-desc'] check = False for b in detected_boards: # Selected board if device == b['index']: # Check the device ftdi description if desc in b['description']: check = True break if not check: device = -1 else: # Check device id if int(device) >= len(detected_boards): device = -1 else: # Detect device device = -1 if board: desc = self.resources.boards[board]['ftdi-desc'] for b in detected_boards: if desc in b['description']: # Select the first board that validates # the ftdi description device = b['index'] break else: # Insufficient arguments click.secho('Error: insufficient arguments: device or board', fg='red') click.secho('You have two options:\n' + ' 1) Execute your command with\n' + ' `--device <deviceid>`\n' + ' 2) Execute your command with\n' + ' `--board <boardname>`', fg='yellow') return 1 if device == -1: # Board not detected click.secho('Error: board not detected', fg='red') return 1 return self.run('upload', variables + ['device={0}'.format(device)], board)
def cli(ctx, lsftdi, lsusb, info): """System tools.\n Install with `apio install system`""" exit_code = 0 if lsftdi: exit_code = System().lsftdi() elif lsusb: exit_code = System().lsusb() elif info: click.secho('Platform: ', nl=False) click.secho(get_systype(), fg='yellow') else: click.secho(ctx.get_help()) ctx.exit(exit_code)
def check_usb(self, board_data): if 'usb' not in board_data: raise Exception('Missing board configuration: usb') usb_data = board_data.get('usb') hwid = '{0}:{1}'.format(usb_data.get('vid'), usb_data.get('pid')) found = False for usb_device in System().get_usb_devices(): if usb_device.get('hwid') == hwid: found = True break if not found: # Board not connected raise Exception('board not connected')
def check_usb(self, board, board_data): if 'usb' not in board_data: raise Exception('Missing board configuration: usb') usb_data = board_data.get('usb') hwid = '{0}:{1}'.format(usb_data.get('vid'), usb_data.get('pid')) found = False for usb_device in System().get_usb_devices(): if usb_device.get('hwid') == hwid: found = True break if not found: # Board not connected if 'tinyprog' in board_data: click.secho('Activate bootloader by pressing the reset button', fg='yellow') raise Exception('board ' + board + ' not connected')
def _check_ftdi(self, board_data, ext_ftdi_id): if 'ftdi' not in board_data: raise Exception('Missing board configuration: ftdi') ftdi_data = board_data.get('ftdi') desc_pattern = '^' + ftdi_data.get('desc') + '$' # Match the discovered FTDI chips for ftdi_device in System().get_ftdi_devices(): index = ftdi_device.get('index') if ext_ftdi_id and ext_ftdi_id != index: # If the --device options is set but it doesn't match # with the detected index, skip the port. continue if re.match(desc_pattern, ftdi_device.get('description')): # If matches the description pattern # return the index for the FTDI device. return index
def upload(self, args, device=-1): ret = self.process_arguments(args) if isinstance(ret, int): return ret if isinstance(ret, tuple): variables, board = ret # Get programmer value programmer = '' if board: p = self.resources.boards[board]['programmer'] type = p['type'] content = self.resources.programmers[type] extra_args = p['extra_args'] if 'extra_args' in p else '' command = content['command'] if 'command' in content else '' args = content['args'] if 'args' in content else '' programmer = '{0} {1} {2}'.format(command, args, extra_args) # -- Check check = self.resources.boards[board]['check'] # Check FTDI description if 'ftdi-desc' in check: detected_boards = System().detect_boards() if isinstance(detected_boards, int): return detected_boards if device: # Check device argument if board: desc = check['ftdi-desc'] found = False for b in detected_boards: # Selected board if device == b['index']: # Check the device ftdi description if desc in b['description']: found = True break if not found: device = -1 else: # Check device id if int(device) >= len(detected_boards): device = -1 else: # Detect device device = -1 if board: desc = check['ftdi-desc'] for b in detected_boards: if desc in b['description']: # Select the first board that validates # the ftdi description device = b['index'] break else: # Insufficient arguments click.secho( 'Error: insufficient arguments: device or board', fg='red') click.secho('You have two options:\n' + ' 1) Execute your command with\n' + ' `--device <deviceid>`\n' + ' 2) Execute your command with\n' + ' `--board <boardname>`', fg='yellow') return 1 if device == -1: # Board not detected click.secho('Error: board not detected', fg='red') return 1 # Check platforms if 'platform' in check: # Device argument is ignored if device and device != -1: click.secho('Info: ignore device argument {0}'.format(device), fg='yellow') platform = check['platform'] current_platform = util.get_systype() if platform != current_platform: # Incorrect platform if platform == 'linux_armv7l': click.secho( 'Error: incorrect platform: RPI2 or RPI3 required', fg='red') else: click.secho( 'Error: incorrect platform {0}'.format(platform), fg='red') return 1 return self.run('upload', variables + ['prog={0}'.format(programmer.replace('%D%', device))], board, deps=['scons', 'icestorm'])