1#!/usr/bin/env python3 2# 3# Copyright 2020 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from acts.controllers.fuchsia_lib.base_lib import BaseLib 18 19 20class FuchsiaI2cLib(BaseLib): 21 def __init__(self, addr, tc, client_id): 22 self.address = addr 23 self.test_counter = tc 24 self.client_id = client_id 25 26 def transfer(self, device_idx, segments_is_write, write_segments_data, 27 read_segments_length): 28 """Gets the fuchsia.input.report.DeviceDescriptor for a given device. 29 30 Args: 31 device_idx: the integer device index to use, e.g. 6 for /dev/class/i2c/006. 32 segments_is_write: a list of bools specifying whether each segment is a read or a write. 33 write_segments_data: a list of write segments, where each segment is a list of bytes to write. 34 read_segments_length: a list of integers specifying the number of bytes in each read segment. 35 36 Returns: 37 The list of read segments received, or an error message if an error was encountered. 38 """ 39 test_cmd = "i2c_facade.Transfer" 40 test_args = { 41 "device_idx": device_idx, 42 "segments_is_write": segments_is_write, 43 "write_segments_data": write_segments_data, 44 "read_segments_length": read_segments_length 45 } 46 test_id = self.build_id(self.test_counter) 47 self.test_counter += 1 48 49 return self.send_command(test_id, test_cmd, test_args) 50