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 FuchsiaGpioLib(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 configIn(self, pin, flags): 27 """ Configures a GPIO for input. 28 29 Args: 30 pin: uint32, pin number of GPIO 31 flags: uint32, flags to configure for GPIO 32 33 Returns: 34 None if success, prints error message if error. 35 """ 36 test_cmd = "gpio_facade.ConfigIn" 37 test_args = {"pin": pin, "flags": flags} 38 test_id = self.build_id(self.test_counter) 39 self.test_counter += 1 40 41 return self.send_command(test_id, test_cmd, test_args) 42 43 def configOut(self, pin, value): 44 """ Configures a GPIO for output. 45 46 Args: 47 pin: uint32, pin number of GPIO 48 value: uint8, initial value 49 50 Returns: 51 None if success, prints error message if error. 52 """ 53 test_cmd = "gpio_facade.ConfigOut" 54 test_args = {"pin": pin, "value": value} 55 test_id = self.build_id(self.test_counter) 56 self.test_counter += 1 57 58 return self.send_command(test_id, test_cmd, test_args) 59 60 def read(self, pin): 61 """ Reads the current value of a GPIO (0 or 1). 62 63 Args: 64 pin: uint32, pin number of GPIO 65 66 Returns: 67 uint8. Current value of GPIO. 68 """ 69 test_cmd = "gpio_facade.Read" 70 test_args = {"pin": pin} 71 test_id = self.build_id(self.test_counter) 72 self.test_counter += 1 73 74 return self.send_command(test_id, test_cmd, test_args) 75 76 def write(self, pin, value): 77 """ Sets the current value of the GPIO (any non-zero value maps to 1). 78 79 Args: 80 pin: uint32, pin number of GPIO 81 value: uint8, value of GPIO 82 83 Returns: 84 None if success, prints error message if error. 85 """ 86 test_cmd = "gpio_facade.Write" 87 test_args = {"pin": pin, "value": value} 88 test_id = self.build_id(self.test_counter) 89 self.test_counter += 1 90 91 return self.send_command(test_id, test_cmd, test_args) 92