コード例 #1
0
ファイル: RPIPL1167.cs プロジェクト: bzuidgeest/SmartLights
        public override byte[] ReadRXFIFO()
        {
            lastRSSIRead = (byte)(ReadRegister16(0x06, 7) >> 10);

            SpiTransferBuffer addressBuffer = new SpiTransferBuffer(1, SpiTransferMode.Write) { ChipSelectChange = true };
            addressBuffer.Tx[0] = (0x32 | C_REG_RD); // Start reading of FIFO Data Register
            spiConnection.Transfer(addressBuffer);

            SpiTransferBuffer dataLengthBuffer = new SpiTransferBuffer(1, SpiTransferMode.Read) { ChipSelectChange = true };
            spiConnection.Transfer(dataLengthBuffer);

            int receiveBufferLength = dataLengthBuffer.Rx[0]; // First byte of FIFO Data Register is the length of message to receive
            receiveBufferLength = (receiveBufferLength <= PL1167_BUFFER_LENGTH) ? receiveBufferLength : PL1167_BUFFER_LENGTH;  // First byte of FIFO Data Register is the length of message to receive

            SpiTransferBuffer dataBuffer = new SpiTransferBuffer(receiveBufferLength, SpiTransferMode.Read) { ChipSelectChange = true };
            spiConnection.Transfer(dataLengthBuffer);

            byte[] receiveBuffer = new byte[receiveBufferLength];
            for (int i = 0; i < receiveBufferLength; i++)
                receiveBuffer[i] = dataBuffer.Rx[i];

            ReadStatusReg();

            return receiveBuffer;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpiTransferBufferCollection"/> class.
        /// </summary>
        /// <param name="numberOfMessages">Number of tranfer messages</param>
        /// <param name="messageLengthInBytes">Message size in bytes</param>
        /// <param name="transferMode">Transfer mode</param>
        public SpiTransferBufferCollection(int numberOfMessages, int messageLengthInBytes, SpiTransferMode transferMode) {
            if (numberOfMessages <= 0) {
                throw new ArgumentOutOfRangeException("numberOfMessages", numberOfMessages, string.Format(CultureInfo.InvariantCulture, "{0} is not a valid number of messages", numberOfMessages));
            }

            transferBuffers = new ISpiTransferBuffer[numberOfMessages];
            for (var i = 0; i < numberOfMessages; i++) {
                transferBuffers[i] = new SpiTransferBuffer(messageLengthInBytes, transferMode);
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpiTransferBufferCollection"/> class.
        /// </summary>
        /// <param name="numberOfMessages">Number of tranfer messages</param>
        /// <param name="messageLengthInBytes">Message size in bytes</param>
        /// <param name="transferMode">Transfer mode</param>
        public SpiTransferBufferCollection(int numberOfMessages, int messageLengthInBytes, SpiTransferMode transferMode)
        {
            if (numberOfMessages <= 0)
            {
                throw new ArgumentOutOfRangeException("numberOfMessages", numberOfMessages, string.Format(CultureInfo.InvariantCulture, "{0} is not a valid number of messages", numberOfMessages));
            }

            transferBuffers = new ISpiTransferBuffer[numberOfMessages];
            for (var i = 0; i < numberOfMessages; i++)
            {
                transferBuffers[i] = new SpiTransferBuffer(messageLengthInBytes, transferMode);
            }
        }
コード例 #4
0
 protected override void Cleanup() {
     if (!ReferenceEquals(buffer, null)) {
         buffer.Dispose();
         buffer = null;
     }
 }
コード例 #5
0
 protected override void EstablishContext() {
     buffer = new SpiTransferBuffer(REQUESTED_SIZE, SpiTransferMode.Write);
 }
コード例 #6
0
ファイル: RPIPL1167.cs プロジェクト: bzuidgeest/SmartLights
        // Read and write RX/TX FIFO
        public override void WriteTXFIFO(byte[] transmitBuffer)
        {
            if (transmitBuffer.Length < 256)
                throw new Exception("Max buffer length is 256");

            if (mode != PL1167Mode.Disabled)
                StopRXTXMode();

            ResetFIFOPointerReg(C_TXFIFOPOINTER);

            SpiTransferBuffer addressBuffer = new SpiTransferBuffer(1, SpiTransferMode.Write) { ChipSelectChange = true };
            addressBuffer.Tx[0] = 0x32;
            spiConnection.Transfer(addressBuffer);

            //First byte contains FIFO length
            SpiTransferBuffer dataBuffer = new SpiTransferBuffer(transmitBuffer.Length + 1, SpiTransferMode.Write) { ChipSelectChange = true };
            addressBuffer.Tx[0] = (byte)transmitBuffer.Length;
            for (int i = 1; i < transmitBuffer.Length + 1; i++)
                addressBuffer.Tx[i] = transmitBuffer[i];
            spiConnection.Transfer(addressBuffer);

            //delayMicroseconds(10);
            SetTXMode();

            ReadStatusReg();
            //while (digitalRead(PL1167_PKT_PIN) == 0) ;
            //	delayMicroseconds(400);
        }
コード例 #7
0
ファイル: RPIPL1167.cs プロジェクト: bzuidgeest/SmartLights
        /// <summary>
        /// Write a register of PL1167
        /// </summary>
        /// <param name="ADDR">Register address to write int16 to</param>
        /// <param name="MSByte">Most significant byte of value\</param>
        /// <param name="LSByte">Least significant byte of value</param>
        /// <param name="WAIT">Delay after write</param>
        protected override void WriteRegister16(byte ADDR, byte MSByte, byte LSByte, byte WAIT)
        {
            // Create new buffer of one byte.
            SpiTransferBuffer addressBuffer = new SpiTransferBuffer(1, SpiTransferMode.Write) { ChipSelectChange = true };
            addressBuffer.Tx[0] = ADDR;
            spiConnection.Transfer(addressBuffer);

            // Create new buffer of two bytes. Read them. Not setting Tx data shifts out zero
            SpiTransferBuffer readBuffer = new SpiTransferBuffer(2, SpiTransferMode.Write) { ChipSelectChange = true };
            addressBuffer.Tx[0] = MSByte;
            addressBuffer.Tx[1] = LSByte;
            spiConnection.Transfer(readBuffer);

            //delayMicroseconds(WAIT);
        }
コード例 #8
0
ファイル: RPIPL1167.cs プロジェクト: bzuidgeest/SmartLights
        /// <summary>
        /// Read a register of PL1167
        /// </summary>
        /// <param name="ADDR">Address of register</param>
        /// <param name="WAIT">Delay time after read</param>
        /// <returns></returns>
        protected override int ReadRegister16(byte ADDR, byte WAIT)
        {
            // Create new buffer of one byte.
            SpiTransferBuffer addressBuffer = new SpiTransferBuffer(1, SpiTransferMode.Write) { ChipSelectChange = true };
            addressBuffer.Tx[0] = (byte)(ADDR | C_REG_RD);
            spiConnection.Transfer(addressBuffer);

            // Create new buffer of two bytes. Read them. Not setting Tx data shifts out zero
            SpiTransferBuffer readBuffer = new SpiTransferBuffer(2, SpiTransferMode.Read) { ChipSelectChange = true };
            spiConnection.Transfer(readBuffer);

            return readBuffer.Rx[0] << 8 + readBuffer.Rx[1];

            //delayMicroseconds(WAIT);
        }