예제 #1
0
        private void OnPinChanged(NRF52840_GPIO.Pin pin, bool value)
        {
            if (pin.Direction != NRF52840_GPIO.PinDirection.Output ||
                !TryGetChannel(pin, out var channel) ||
                channel.Mode != Mode.Event)
            {
                return;
            }

            switch (channel.Polarity)
            {
            case Polarity.None:
                channel.EventPending = false;
                break;

            case Polarity.LoToHi:
                channel.EventPending = !channel.CurrentState && value;
                break;

            case Polarity.HiToLo:
                channel.EventPending = channel.CurrentState && !value;
                break;

            case Polarity.Toggle:
                channel.EventPending = channel.CurrentState != value;
                break;
            }

            channel.CurrentState = value;
            UpdateInterrupt();
        }
예제 #2
0
        private bool TryGetChannel(NRF52840_GPIO.Pin pin, out Channel channel)
        {
            if (pinToChannelMapping.TryGetValue(pin, out channel))
            {
                return(true);
            }

            foreach (var ch in channels)
            {
                if (pin.Id == ch.SelectedPin && pin.Parent == ports[ch.SelectedPort])
                {
                    pinToChannelMapping[pin] = ch;
                    channel = ch;
                    return(true);
                }
            }

            channel = null;
            return(false);
        }
예제 #3
0
            private bool TryGetPin(out NRF52840_GPIO.Pin pin)
            {
                var port = parent.ports[SelectedPort];

                if (port == null)
                {
                    parent.Log(LogLevel.Warning, "Trying to access a not connected port #{0}", SelectedPort);
                    pin = null;
                    return(false);
                }

                if (SelectedPin >= port.Pins.Length)
                {
                    parent.Log(LogLevel.Warning, "Trying to access a not existing pin #{0} in port #{1}", SelectedPin, SelectedPort);
                    pin = null;
                    return(false);
                }

                pin = port.Pins[SelectedPin];
                return(true);
            }