def adapter_connect(self): LOGGER.debug('<') (num, ports, unique_ids) = aa.aa_find_devices_ext(16, 16) del unique_ids if num == 0: raise EvaluationKitException( 'Aardvark i2c/spi host adapter not connected.') elif num == -2: raise EvaluationKitException( 'Aardvark i2c/spi host adapter never connected.') else: self._ports = ports[0] if num > 1: LOGGER.warning( 'More that 1 Aardvark ports found. Selecting 1st one.') # with "port_index" it is possible to support multiple simultanously connected Aardvarks self._handle = aa.aa_open(self.bus1config['port_index']) if self._handle < 0: if self._handle == -7: raise EvaluationKitException( 'bus_aadvark_i2c.open failed with error code %d (Aardvark disconnected)' % self._handle) else: raise EvaluationKitException( 'bus_aadvark_i2c.open failed with error code %d' % self._handle)
def _define_request_message_v1(self, sensor=None, fmt=None, hdr=None, reg=None, pin_index=None, timer=None): assert not None in [fmt, hdr, reg], 'All values must be defined' if timer is not None: raise EvaluationKitException( 'Timer not supported in this firmware version') # NOTE : =None needed due API change and to prevent API break if sensor is not None: assert pin_index in sensor.int_pins, 'Sensor does not have interrput pin %d.' % pin_index message = RequestMessageDefinition(sensor, fmt, hdr, reg, pin_index) else: assert pin_index in self.sensor.int_pins, 'Sensor does not have interrput pin %d.' % pin_index message = RequestMessageDefinition(self.sensor, fmt, hdr, reg, pin_index) self.macro_id_list.append(message) self._prepare_request_message_v1(message)
def get_com_port(self): """Autodetect a connected serial device and return the device's name. Raises: EvaluationKitException: Autodetection found no devices. Returns: str: The name of the detected serial device (e.g. 'COM2'). """ matching_ports = [] LOGGER.debug('Listing serial ports.') for port in list_ports.comports(): LOGGER.debug(port.name) LOGGER.debug(port.description) LOGGER.debug(port.vid) LOGGER.debug(port.pid) # matcing port found based in vid and pid? if (port.vid, port.pid) in self._valid_vid_pid_pairs: matching_ports.append(port.device) if not matching_ports: raise EvaluationKitException('Automatic search found no devices') return matching_ports
def get_com_port(self): """Autodetect a connected serial device and return the device's name. Raises: EvaluationKitException: Autodetection found no devices. Returns: str: The name of the detected serial device (e.g. 'COM2'). """ # TODO 3 check also pid and vid matching_ports = [] LOGGER.debug('Listing serial ports.') for port in list_ports.comports(): LOGGER.debug(port.name) LOGGER.debug(port.description) LOGGER.debug(port.vid) LOGGER.debug(port.pid) # matcing port found based in vid and pid? if self.bus2_configuration[ 'vid'] == port.vid and self.bus2_configuration[ 'pid'] == port.pid: matching_ports.append(port.device) continue if not matching_ports: raise EvaluationKitException('Automatic search found no devices') return matching_ports
def adapter_write_sensor_register_spi(self, _, chip_select, register, values): # TODO 3 how to handle chip select # TODO 3 "target" is not in use LOGGER.debug('<') if register is None: # Pure SPI command write without address # TODO 3 test this data_out = array('B', [values]) length = 1 ## TODO 3 support for multi byte write? elif isinstance(values, int): length = 2 data_out = array('B', [register, values]) elif isinstance(values, (list, tuple)): values = list(values) length = 1 + len(values) data_out = array('B', [register] + values) else: raise ProtocolBus1Exception("unsupported value") res, dummy_data = aa.aa_spi_write(self._handle, data_out, 0) # write the reg.address and data if res != length: raise EvaluationKitException('Unable write to SPI slave') LOGGER.debug('>')
def read_drdy(self, channel=CH_ACC): # separately followed """ Read data ready register. """ ins1 = self.read_register(r.KMX62_INS1)[0] if channel & CH_ACC > 0: return ins1 & b.KMX62_INS1_DRDY_A_AVAILABLE != 0 if channel & CH_MAG > 0: return ins1 & b.KMX62_INS1_DRDY_M_AVAILABLE != 0 raise EvaluationKitException('Invalid channel number %d' % channel)
def __init__(self, bus2_configuration=None): KxPySerial.__init__(self, bus2_configuration) self.baudrate = self.bus2_configuration['baud_rate'] hw_ids = self.bus2_configuration.get('hw_id') if hw_ids is not None: self._valid_vid_pid_pairs = [(d['vid'], d['pid']) for d in hw_ids] else: raise EvaluationKitException( 'No hardware IDs found in board config')
def __init__(self, sensor=None): # FIXME: Add support for protocol 1 when using stream_config_utils.py for generating streams # if sensor not defined here then must be defined on define_request_message() # TODO 2 does not work if sensor not defined here, make test for this use case self.sensor = sensor self.macro_id_list = [ ] # list of all data streams requested. Integer list. self.msg_ind_dict = {} # {macro_id_list:RequestMessageDefinition} self.adapter = self.sensor.connection_manager.kx_adapter if self.adapter.stream_support is False: raise EvaluationKitException( "Adapter %s does not support data streaming." % self.adapter) # map methods based on protocol version if self.adapter.engine.version == 2: self._start_streaming = self._start_streaming_v2 self._stop_streaming = self._stop_streaming_v2 self.define_request_message = self._define_request_message_v2 elif self.adapter.engine.version == 1: self._start_streaming = self._start_streaming_v1 self._stop_streaming = self._stop_streaming_v1 self.define_request_message = self._define_request_message_v1 else: raise EvaluationKitException( 'Unsupported protocol engine version.') protocol = self.adapter.protocol # kx_protocol or kx_protocol_2 module # TODO 2 move to protocol self.sense_dict = { EVKIT_GPIO_PIN_SENSE_HIGH: protocol.EVKIT_GPIO_PIN_SENSE_HIGH, EVKIT_GPIO_PIN_SENSE_LOW: protocol.EVKIT_GPIO_PIN_SENSE_LOW } # TODO 2 move to protocol self.pullup_dict = { EVKIT_GPIO_PIN_NOPULL: protocol.EVKIT_GPIO_PIN_NOPULL, EVKIT_GPIO_PIN_PULLDOWN: protocol.EVKIT_GPIO_PIN_PULLDOWN, EVKIT_GPIO_PIN_PULLUP: protocol.EVKIT_GPIO_PIN_PULLUP }
def __init__(self, sensor=None, stream_type='continuous'): self.stream_type = stream_type # if sensor not defined here then must be defined on define_request_message() self.sensor = sensor self.macro_id_list = [ ] # list of all data streams requested. Integer list. self.msg_ind_dict = {} # {macro_id_list:RequestMessageDefinition} self.adapter = self.sensor.connection_manager.kx_adapter if self.adapter.stream_support is False: raise EvaluationKitException( "\nSelected board does not support streaming." + "\nPlease edit rokix_settings.cfg and select another board or set 'stream_mode = FALSE'" ) # map methods based on protocol version if self.adapter.engine.version == 2: self._start_streaming = self._start_streaming_v2 self._stop_streaming = self._stop_streaming_v2 self.define_request_message = self._define_request_message_v2 elif self.adapter.engine.version == 1: self._start_streaming = self._start_streaming_v1 self._stop_streaming = self._stop_streaming_v1 self.define_request_message = self._define_request_message_v1 else: raise EvaluationKitException( 'Unsupported protocol engine version.') protocol = self.adapter.protocol # kx_protocol or kx_protocol_2 module self.sense_dict = { EVKIT_GPIO_PIN_SENSE_HIGH: protocol.EVKIT_GPIO_PIN_SENSE_HIGH, EVKIT_GPIO_PIN_SENSE_LOW: protocol.EVKIT_GPIO_PIN_SENSE_LOW } self.pullup_dict = { EVKIT_GPIO_PIN_NOPULL: protocol.EVKIT_GPIO_PIN_NOPULL, EVKIT_GPIO_PIN_PULLDOWN: protocol.EVKIT_GPIO_PIN_PULLDOWN, EVKIT_GPIO_PIN_PULLUP: protocol.EVKIT_GPIO_PIN_PULLUP }
def __init__(self, sensor, fmt, hdr, reg=None, pin_index=None, timer=None): """Container for data needed for creating macro request message and parsing indication messages Args: sensor(SensorDriver) fmt(string): formatter for struct.unpack how to interpret binary data hdr(string): Header row for log, dimensions separated with ! mark. reg(int): register number where reading starts. pin_index(int): Sensor's interrupt line number. timer(float): delay in seconds when using timer based data stream Allowed parameter combinations: reg+pin_index: read register when interrupt triggers reg+timer: read register when timer triggers timer+gpio_pin: read ADC when timer triggers """ # TODO 3 is it needed to have "read ADC when interrupt triggers"? if pin_index is not None: self.gpio_pin = sensor.connection_manager.get_physical_pin_for_sensor( sensor, pin_index) if isinstance(pin_index, int): pin_index = [pin_index] # change to list for value checking for _pin in pin_index: if _pin not in sensor.int_pins: raise EvaluationKitException( 'Request logical interrupt pin {} not supported in selected sensor. Supported pins are {}' .format(pin_index, sensor.int_pins)) if timer is not None and reg is not None: raise EvaluationKitException( 'timer cannot ber used together with gpio interrupt') self.msg_fmt = fmt self.msg_hdr = hdr self.sensor = sensor self.reg = reg self.msg_size = struct.calcsize(self.msg_fmt) self.msg_req = [] # protocol v1 messages generated by this request self.timer = timer self.axis_mapper = AxisMapper(channel_header=hdr, axis_map=sensor.resource[CFG_AXIS_MAP])
def get_pin_index(): "Returns 1 if drdy_operation == 'ADAPTER_GPIO1_INT' and 2 if it is ADAPTER_GPIO2_INT " drdy = evkit_config.get('generic', 'drdy_operation') if drdy == 'ADAPTER_GPIO1_INT': pin_index = 1 elif drdy == 'ADAPTER_GPIO2_INT': pin_index = 2 else: raise EvaluationKitException( 'drdy_operation is configured to %s. Please select "ADAPTER_GPIO1_INT" or "ADAPTER_GPIO2_INT" instead'\ % drdy) return pin_index
def adapter_write_sensor_register_i2c(self, _, sad, register, values): LOGGER.debug('<') if isinstance(values, int): length = 2 data_out = array('B', [register, values]) elif isinstance(values, (list, tuple)): values = list(values) length = 1 + len(values) data_out = array('B', [register] + values) # TODO 3 test below option elif register is None: # special case : write without dedicated register address length = len(values) data_out = array('B', [values]) else: raise EvaluationKitException('Datatype "%s" not supported.' % type(values)) res = aa.aa_i2c_write(self._handle, sad, aa.AA_I2C_NO_FLAGS, data_out) if res != length: # TODO 3 add sensor name to error message raise EvaluationKitException('Unable write to I2C slave at address 0x%x' % sad)
def get_other_pin_index(): "Returns 1 if other_function_mode == 'ADAPTER_GPIO1_INT' and 2 if it is ADAPTER_GPIO2_INT " other_f = evkit_config.other_function_mode if other_f == ADAPTER_GPIO1_INT: pin_index = 1 elif other_f == ADAPTER_GPIO2_INT: pin_index = 2 elif other_f == TIMER_POLL: pin_index = None else: raise EvaluationKitException( 'other_function_mode is configured to %s. Please select "ADAPTER_GPIO1_INT" or "ADAPTER_GPIO2_INT" instead' % other_f) return pin_index
def __init__(self, bus1config): LOGGER.debug('>init') if not AARDVARK_FOUND: raise EvaluationKitException( 'Aardvark libraries not found/installed.') KxAdapterBase.__init__(self) self.fw_protocol_version = "2.0" self.bus1config = bus1config self._adapter_configured = None # None / BUS1_I2C / BUS1_SPI self.bus_gpio_list = [1, 2] self._has_gpio = True self._handle = None self._bitrate = None # I2C related settings self._aa_target_power = { 'AA_TARGET_POWER_BOTH': aa.AA_TARGET_POWER_BOTH, 'AA_TARGET_POWER_NONE': aa.AA_TARGET_POWER_NONE } self._aa_i2c_pullup = { 'AA_I2C_PULLUP_BOTH': aa.AA_I2C_PULLUP_BOTH, 'AA_I2C_PULLUP_NONE': aa.AA_I2C_PULLUP_NONE, } # SPI related settings self._polarity = { 'RISING_FALLING': aa.AA_SPI_POL_RISING_FALLING, 'FALLING_RISING': aa.AA_SPI_POL_FALLING_RISING } self._phase = { 'SETUP_SAMPLE': aa.AA_SPI_PHASE_SETUP_SAMPLE, 'SAMPLE_SETUP': aa.AA_SPI_PHASE_SAMPLE_SETUP } self._ss_polarity = { 'ACTIVE_HIGH': aa.AA_SPI_SS_ACTIVE_HIGH, 'ACTIVE_LOW': aa.AA_SPI_SS_ACTIVE_LOW } self._bitorder = { 'MSB': aa.AA_SPI_BITORDER_MSB, 'LSB': aa.AA_SPI_BITORDER_LSB } self.adapter_connect() LOGGER.debug('<init')
def adapter_read_sensor_register_spi(self, _, chip_select, register, length=1): if self._adapter_configured is None: self.configure_spi() assert self._adapter_configured == BUS1_SPI # TODO 3 how to handle chip select # TODO 3 "target" can be used for selecting between i2c and spi but currently no needs for it. data_in = aa.array_u08(1 + length) data_out = array('B', [register] + [0] * length) try: (count, data_in) = aa.aa_spi_write(self._handle, data_out, data_in) # write address except TypeError: raise EvaluationKitException('Cannot read sensor from SPI bus.') #LOGGER.debug( 'count,length %d %d ' %(count,length)) assert count == length + 1 return data_in[1:]
def stream_config_check(sensor_driver): # sensor is not yet assigned to board so not possible to check does the board support streaming # if sensor_driver.connection_manager.kx_adapter.engine is None: # raise EvaluationKitException('Selected board does not support data streaming.') # TODO 2 consider improving logic of stream_config_check "Verify that needed settings are in place when streaming mode is used" if sensor_driver.sensor_type in [ SENSOR_TYPE_DIGITAL_1D, SENSOR_TYPE_DIGITAL_2D, SENSOR_TYPE_DIGITAL_3D ]: if (evkit_config.get('generic', 'drdy_operation') not in ['ADAPTER_GPIO1_INT', 'ADAPTER_GPIO2_INT']): raise EvaluationKitException( 'Stream mode requires GPIO drdy_operation in settings.cfg') return True
def adapter_read_sensor_register_spi(self, _, chip_select, register, length=1): if self._adapter_configured is None: self.configure_spi() assert self._adapter_configured == BUS1_SPI data_in = aa.array_u08(1 + length) data_out = array('B', [register] + [0] * length) try: (count, data_in) = aa.aa_spi_write(self._handle, data_out, data_in) # write address except TypeError: raise EvaluationKitException('Cannot read sensor from SPI bus.') #LOGGER.debug( 'count,length %d %d ' %(count,length)) assert count == length + 1 return data_in[1:]
def app_main(odr=25): args = get_datalogger_args() if args.odr: odr = args.odr sensor = KMX62Driver() connection_manager = ConnectionManager() connection_manager.add_sensor(sensor) enable_data_logging(sensor, odr=odr) if args.stream_mode: read_with_stream(sensor, args.loop) elif args.timer_stream_mode: raise EvaluationKitException('Timer polling not yet implemented') else: read_with_polling(sensor, args.loop) sensor.set_power_off() connection_manager.disconnect()
def __init__(self): # TODO 2 find a way to check this which works on both py2 and py3 #assert self.read_data.__func__ == SensorDriver.read_data.__func__,\ #'read_data() must not be overriden. Implement sensor spesific data reading to __read_data().' self.connected = False self.connection_manager = None self.resource = None self.supported_connectivity = None self.name = 'undefined' self.channel_header = 'ax!ay!az' self._registers = {} self._dump_range = [0, 2] self.WHOAMI = None self.poll_delay_s = evkit_config.getint('generic', 'drdy_poll_interval') / 1000. self.sensor_type = SENSOR_TYPE_DIGITAL_3D self.axis_mapper = None self.selected_connectivity = None self._drdy_LUT = { 'INTERVAL_READ': self._poll_delay, 'DRDY_REG_POLL': self._poll_drdy_register, 'ADAPTER_GPIO1_INT': self._poll_gpio_line1, 'ADAPTER_GPIO2_INT': self._poll_gpio_line2 } try: drdy_operation = evkit_config.get('generic', 'drdy_operation') LOGGER.debug('Using "{}" for data ready.'.format(drdy_operation)) self.drdy_function = self._drdy_LUT[evkit_config.get( 'generic', 'drdy_operation')] except KeyError: raise EvaluationKitException( 'Missing or invalid "drdy_operation" definition in settings.cfg' )
def selftest(self, ttype): raise EvaluationKitException('Not implemented for this adapter.')
def reset(self): raise EvaluationKitException('Not implemented for this adapter.')
def configure_pin(self, gpio_pin, direction, drivemode, connect_input=False): raise EvaluationKitException('Not implemented for this adapter.')
def configure_pin_as_input(self, gpio_pin, drivemode): raise EvaluationKitException('Not implemented for this adapter.')
def _define_request_message_v2(self, sensor=None, fmt=None, hdr=None, reg=None, pin_index=None, timer=None): """Construct stream request message Args: sensor_driver(SensorDriver): sensor driver instance in case of multiple sensors in use. Defaults to None. NOTE : In one sensor case the sensor driver instance is given in constructor. fmt(string): format definition how received binary data is interpreted as struct module format string. hdr(string): sensor data log file header, channel names separated with ! mark. Example :ch!ax!ay!az reg(int): register number from reading starts. NOTE: fmt defines how many bytes are read. pin_index(int): sensor's logical interrupt pin which triggers register reading. pin_index(list): list of sensor's logical gpio pins from read ADC values timer(float): interval value if using timer based polling. When timer is set then pin_index must be unset and vice versa. """ LOGGER.debug('>') assert not None in [fmt, hdr], 'Mandatory values not defined' if sensor is None: sensor = self.sensor if timer is None: assert pin_index in sensor.int_pins, 'Sensor does not have interrput pin %d.' % pin_index LOGGER.debug('Stream request for {}'.format(self.sensor.name)) message = RequestMessageDefinition(sensor, fmt, hdr, reg, pin_index, timer) # (u'spi', {u'cs': 0, u'gpio1': 0, u'target': 1, u'name': u'KX122'}) # (u'i2c', {u'gpio1': 0, u'SAD': 31, u'target': 4, u'name': u'KX122'}) bus1_name = sensor.selected_connectivity protocol = self.adapter.protocol # # Create macro request # if message.reg is None: # FOR ADC reading? LOGGER.debug('EVKIT_MACRO_TYPE_POLL {}'.format(message.gpio_pin)) # TODO 2 determine timer scale dynamically req = protocol.create_macro_req( trigger_type=protocol.EVKIT_MACRO_TYPE_POLL, timer_scale=protocol.EVKIT_TIME_SCALE_MS, timer_value=int(message.timer * 1000)) elif message.timer is not None: # FOR timer polling digital bus # TODO 2 combine these two? LOGGER.debug('EVKIT_MACRO_TYPE_POLL {}seconds'.format( message.timer)) # TODO 2 determine timer scale dynamically req = protocol.create_macro_req( trigger_type=protocol.EVKIT_MACRO_TYPE_POLL, timer_scale=protocol.EVKIT_TIME_SCALE_MS, timer_value=int(message.timer * 1000)) elif message.gpio_pin is not None: LOGGER.debug('EVKIT_MACRO_TYPE_INTR %s' % message.gpio_pin) req = protocol.create_macro_req( trigger_type=protocol.EVKIT_MACRO_TYPE_INTR, gpio_pin=message.gpio_pin, gpio_sense=self.sense_dict[sensor.resource[CFG_POLARITY]], gpio_pullup=self.pullup_dict[sensor.resource[CFG_PULLUP]]) # TODO 2 update _pin_mode_cache. else: raise EvaluationKitException('No rule to make request.') # # send macro request and store macro # self.adapter.send_message(req) _, macro_id = self.adapter.receive_message( waif_for_message=protocol.EVKIT_MSG_CREATE_MACRO_RESP ) # message_type, macro_id self.macro_id_list.append(macro_id) self.msg_ind_dict[macro_id] = message message.msg_req.append(req) LOGGER.debug('Macro created with id %d', macro_id) # # Defene what action is done when macro triggers # if bus1_name == BUS1_I2C: LOGGER.debug("EVKIT_MACRO_ACTION_READ over i2c") req = protocol.add_macro_action_req( macro_id, action=protocol.EVKIT_MACRO_ACTION_READ, target=sensor.resource[CFG_TARGET], identifier=sensor.resource[CFG_SAD], append=True, start_register=message.reg, bytes_to_read=message.msg_size - 1) LOGGER.debug(req) self.adapter.send_message(req) self.adapter.receive_message( waif_for_message=protocol.EVKIT_MSG_ADD_MACRO_ACTION_RESP) message.msg_req.append(req) elif bus1_name == BUS1_SPI: LOGGER.debug("EVKIT_MACRO_ACTION_READ over spi") assert sensor.resource[CFG_SPI_PROTOCOL] in [0, 1] if sensor.resource[CFG_SPI_PROTOCOL] == 1: # With Kionix components, MSB must be set 1 to indicate reading message.reg = message.reg | 1 << 7 req = protocol.add_macro_action_req( macro_id, action=protocol.EVKIT_MACRO_ACTION_READ, target=sensor.resource[CFG_TARGET], identifier=sensor.resource[CFG_CS], append=True, start_register=message.reg, bytes_to_read=message.msg_size - 1) LOGGER.debug(req) self.adapter.send_message(req) message.msg_req.append(req) self.adapter.receive_message( waif_for_message=protocol.EVKIT_MSG_ADD_MACRO_ACTION_RESP) elif bus1_name == BUS1_ADC: LOGGER.debug("EVKIT_MACRO_ACTION_ADC_READ") if isinstance(message.gpio_pin, int): message.gpio_pin = [message.gpio_pin] self.sensor.connection_manager.gpio_config_for_adc(self.sensor) for pin in message.gpio_pin: req2 = protocol.add_macro_action_req( macro_id=macro_id, action=protocol.EVKIT_MACRO_ACTION_ADC_READ, target=sensor.resource[CFG_TARGET], identifier=pin, append=True, adc_oversample=sensor. resource['adc_msg_oversampling_enum'], adc_gain=sensor.resource['adc_msg_gain_enum'], adc_resolution=sensor.resource[CFG_ADC_RESOLUTION], adc_acq_time_us=sensor. resource['adc_msg_conversion_time_us']) LOGGER.debug(req2) self.adapter.send_message(req2) message.msg_req.append(req2) self.adapter.receive_message( waif_for_message=protocol.EVKIT_MSG_ADD_MACRO_ACTION_RESP) elif bus1_name == BUS1_GPIO: # TODO 3 BUS1_GPIO data stream raise EvaluationKitException( 'Unsupported bus1 {}'.format(bus1_name)) else: raise EvaluationKitException( 'Unsupported bus1 {}'.format(bus1_name)) LOGGER.debug('<')
def enable_data_logging(sensor, odr=25, max_range_acc='2G', lp_mode=False, power_off_on=True, int_number=None): LOGGER.info('enable_data_logging start') # # parameter validation # assert convert_to_enumkey(odr) in e.KMX62_ODCNTL_OSA.keys( ), 'Invalid odr_OSA value "{}". Support values are {}'.format( odr, e.KMX62_ODCNTL_OSA.keys()) assert max_range_acc in e.KMX62_CNTL2_GSEL, 'Invalid range value "{}". Support values are {}'.format( max_range_acc, e.KMX62_CNTL2_GSEL.keys()) assert ( lp_mode in list(e.KMX62_CNTL2_RES.keys()) + [False] ), 'Invalid lp_mode value "{}". Support values are {} and False'.format( lp_mode, e.KMX62_CNTL2_RES.keys()) # Set sensor to stand-by to enable setup change if power_off_on: sensor.set_power_off() # # Configure sensor # # Select acc ODRs sensor.set_odr(e.KMX62_ODCNTL_OSA[convert_to_enumkey(odr)], CH_ACC) # Select mag ODRs sensor.set_odr(e.KMX62_ODCNTL_OSM[convert_to_enumkey(odr)], CH_MAG) # select g-range (for acc) sensor.set_range(e.KMX62_CNTL2_GSEL[max_range_acc]) # resolution / power mode selection if lp_mode not in ['MAX1', 'MAX2', False]: # Low power mode sensor.set_average(e.KMX62_CNTL2_RES[lp_mode], None, CH_ACC) else: # Full power mode sensor.set_average(b.KMX62_CNTL2_RES_MAX2, None, CH_ACC) # # interrupt pin routings and settings # if int_number is None: # KMX62: interrupt source selection activates also physical interrupt pin if evkit_config.get('generic', 'drdy_operation') == 'ADAPTER_GPIO1_INT': sensor.enable_drdy(1, CH_ACC) # acc data ready to int1 # sensor.enable_drdy(1, CH_MAG) # mag data ready to int1 elif evkit_config.get('generic', 'drdy_operation') == 'ADAPTER_GPIO2_INT': sensor.enable_drdy(2, CH_ACC) # acc data ready to int2 # sensor.enable_drdy(2, CH_MAG) # mag data ready to int2 elif evkit_config.get('generic', 'drdy_operation') == 'DRDY_REG_POLL': sensor.enable_drdy(1, CH_ACC) # acc data ready to int1 # sensor.enable_drdy(1, CH_MAG) # mag data ready to int1 else: sensor.enable_drdy(int_number, CH_ACC) polarity = POLARITY_DICT[sensor.resource[CFG_POLARITY]] LOGGER.debug('Configuring interrput polarity %s' % format(sensor.resource[CFG_POLARITY])) if polarity == ACTIVE_HIGH: IEA1 = b.KMX62_INC3_IEA1_HIGH IEA2 = b.KMX62_INC3_IEA2_HIGH elif polarity == ACTIVE_LOW: IEA1 = b.KMX62_INC3_IEA1_LOW IEA2 = b.KMX62_INC3_IEA2_LOW else: raise EvaluationKitException('Unsupported interrupt polarity %s' % sensor.resource[CFG_POLARITY]) # interrupt signal parameters sensor.write_register( r.KMX62_INC3, b.KMX62_INC3_IED1_PUSHPULL | IEA1 | b.KMX62_INC3_IEL1_LATCHED | b.KMX62_INC3_IED2_PUSHPULL | IEA2 | b.KMX62_INC3_IEL2_LATCHED) # # Turn on operating mode (disables setup) # if power_off_on: # sensor.set_power_on(CH_MAG ) # mag ON # sensor.set_power_on(CH_ACC | CH_MAG ) # acc + mag ON sensor.set_power_on(CH_ACC | CH_MAG | CH_TEMP) # sensor.register_dump()#;sys.exit() LOGGER.info('enable_data_logging done')
def get_dev_id(self): raise EvaluationKitException('Not implemented for this adapter.')
def adapter_write_sensor_register_i2c(self, target, sad, register, values): raise EvaluationKitException('I2C support not available for this adapter')
def adapter_write_sensor_register_spi(self, target, chip_select, register, values): raise EvaluationKitException('SPI support not available for this adapter')
def adapter_write_gpio(self, gpio_pin, value, connect_input=False): raise EvaluationKitException('Not implemented for this adapter.')
def adapter_read_adc(self, target, channel, resolution, oversample, gain, acq_time_us): raise EvaluationKitException('Not implemented for this adapter.')