Ejemplo n.º 1
0
        protected override ushort Read(Stm32Command command, ushort data, bool dataAvailable)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(Strings.Message_3);
            }

            Span <byte> writeBuffer;

            Span <byte> readBuffer = new byte[2];

            if (dataAvailable)
            {
                writeBuffer = new byte[3];

                Unsafe.As <byte, Stm32Command>(ref writeBuffer[0]) = command;
                Unsafe.As <byte, ushort>(ref writeBuffer[1])       = data;
            }
            else
            {
                writeBuffer = new byte[1];

                Unsafe.As <byte, Stm32Command>(ref writeBuffer[0]) = command;
            }

            _gpioExpander.WriteRead(writeBuffer, readBuffer);

            return(MemoryMarshal.Read <ushort>(readBuffer));
        }