def generate_pin_mapping(self, dev_target): pin_mapping = KeyboardPinMapping() fw_info = dev_target.firmware_info pin_mapping.mode = self.mode pin_mapping.internal_scan_method = fw_info.internal_scan_method using_basic_scan = ( fw_info.internal_scan_method == MATRIX_SCANNER_INTERNAL_BASIC_SCAN) pin_mapping.max_rows = fw_info.max_rows io_mapper = dev_target.get_io_mapper() pin_mapping.io_mapper = io_mapper if self.mode == NO_MATRIX: pass elif self.mode in [ROW_COL, COL_ROW]: row_pin_numbers = self.get_row_pin_numbers(io_mapper) column_pin_numbers = self.get_column_pin_numbers(io_mapper) if (using_basic_scan and self.mode == ROW_COL): # ROW_COL method can't use pull-down resistors, so it needs # treat the columns as rows, and the rows as columns. # So we swap them here. (row_pin_numbers, column_pin_numbers) = (column_pin_numbers, row_pin_numbers) invert_row_col = True # Since the internal scan method used by the device is still # COL_ROW since we are flipping ROWS and COLUMNS here. pin_mapping.mode = COL_ROW else: invert_row_col = False pin_mapping.row_pins = row_pin_numbers pin_mapping.column_pins = column_pin_numbers pin_mapping.key_number_map = self._generate_key_number_map( column_pin_numbers, invert_row_col=invert_row_col) elif self.mode in [PIN_VCC, PIN_GND]: # NOTE: The direct wiring pins are treated the same way as column # pins if (using_basic_scan and self.mode == PIN_VCC): raise KeyplusSettingsError( "The target device can't support the `pin_vcc` scan method. " "Using the BASIC_SCAN method it can only support: " "`pin_gnd`, `col_row` and `row_col`.") direct_pins = io_mapper.get_pin_numbers(self.direct_wiring_pins) pin_mapping.column_pins = direct_pins pin_mapping.row_pins = [0] # dummy value pin_mapping.key_number_map = self._generate_key_number_map( direct_pins, use_pin_map=True) return pin_mapping
def generate_pin_mapping(self, device_target): pin_mapping = KeyboardPinMapping() internal_scan_method = device_target.firmware_info.internal_scan_method pin_mapping.mode = self.mode pin_mapping.internal_scan_method = internal_scan_method io_mapper = device_target.get_io_mapper() pin_mapping.io_mapper = io_mapper if self.mode == NO_MATRIX: pass elif self.mode in [ROW_COL, COL_ROW]: row_pin_numbers = self.get_row_pin_numbers(io_mapper) column_pin_numbers = self.get_column_pin_numbers(io_mapper) pin_mapping.row_pins = row_pin_numbers pin_mapping.column_pins = column_pin_numbers pin_mapping.key_number_map = self._generate_key_number_map( column_pin_numbers) elif self.mode in [PIN_VCC, PIN_GND]: # NOTE: The direct wiring pins are treated the same way as column # pins direct_pins = io_mapper.get_pin_numbers(self.direct_wiring_pins) pin_mapping.column_pins = direct_pins pin_mapping.row_pins = [0] # dummy value pin_mapping.key_number_map = self._generate_key_number_map( direct_pins, pin_map=True) return pin_mapping