1 // 2 // Copyright (c) 2010-2021 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using System.Linq; 9 using System.Collections.Generic; 10 using Antmicro.Renode.Core; 11 using Antmicro.Renode.Logging; 12 using Antmicro.Migrant; 13 14 namespace Antmicro.Renode.Peripherals.Miscellaneous 15 { 16 public class CombinedInput : IGPIOReceiver 17 { CombinedInput(int numberOfInputs)18 public CombinedInput(int numberOfInputs) 19 { 20 inputStates = new bool[numberOfInputs]; 21 OutputLine = new GPIO(); 22 23 Reset(); 24 } 25 Reset()26 public void Reset() 27 { 28 Array.Clear(inputStates, 0, inputStates.Length); 29 OutputLine.Unset(); 30 } 31 OnGPIO(int number, bool value)32 public void OnGPIO(int number, bool value) 33 { 34 if(number < 0 || number >= inputStates.Length) 35 { 36 this.Log(LogLevel.Error, "Received GPIO signal on an unsupported port #{0} (supported ports are 0 - {1}). Please check the platform configuration", number, inputStates.Length - 1); 37 return; 38 } 39 40 inputStates[number] = value; 41 OutputLine.Set(inputStates.Any(x => x)); 42 } 43 44 public GPIO OutputLine { get; } 45 46 private readonly bool[] inputStates; 47 } 48 } 49 50