/// <summary> /// Reads in a specified number of bytes starting at the specified address /// </summary> /// <param name="address">Address to read from</param> /// <param name="registersToRead">Number of registers to read</param> /// <returns></returns> private byte[] ReadRegister(byte address, int registersToRead = 1) { if (registersToRead < 1) { throw new Exception("At least one byte must be specified to read in"); } var readBuffer = new byte[1 + registersToRead]; // registersToRead bytes for reading in, one byte of padding var regAddressBuffer = new byte[1 + registersToRead]; // One byte for address, registersToRead bytes of padding regAddressBuffer[0] = address; // Set the address to the first byte CHIP_SELECT.Write(GpioPinValue.Low); spiDisplay.TransferFullDuplex(regAddressBuffer, readBuffer); CHIP_SELECT.Write(GpioPinValue.High); return(readBuffer.Skip(1).ToArray()); // The first has a dead bit that was transferred while reading in the address to read from, so chop that off }
/// <summary> /// Writes one byte to the specified register's address /// </summary> /// <param name="address">Address to write to</param> /// <param name="value">Value to write to the register</param> private void WriteRegister(byte address, byte value) { CHIP_SELECT.Write(GpioPinValue.Low); spiDisplay.Write(new byte[] { address, value }); CHIP_SELECT.Write(GpioPinValue.High); }