/// <summary> /// Construct the driver using the specific SPI port. /// </summary> /// <param name="busSelector">Which SPI bus to use</param> /// <param name="width">Width of display in pixels</param> /// <param name="height">Height of display in pixels</param> /// <param name="dcPin">The Gpio pin to use for D/C (Data or Command) signal</param> /// <param name="rstPin">The Gpio pin to use for hardware reset of the display</param> /// <param name="csPin">The Cpio pin to use for Chip Select signal for SPI communication</param> /// <param name="bufSize">The size of the internal display buffer</param> public ILI9341_SPI(string busSelector, uint width, uint height, GpioPin dcPin, GpioPin rstPin, GpioPin csPin, uint bufSize = 256) { if (dcPin == null || rstPin == null || csPin == null) { throw new ArgumentNullException(); } _dcPin = dcPin; _rstPin = rstPin; _csPin = csPin; _dcPin.SetDriveMode(GpioPinDriveMode.Output); _rstPin.SetDriveMode(GpioPinDriveMode.Output); _csPin.SetDriveMode(GpioPinDriveMode.Output); SpiBusInfo busInfo = SpiDevice.GetBusInfo(busSelector); var spiConnSettings = new SpiConnectionSettings(csPin.PinNumber) { ClockFrequency = 10000000, //10 MHz SPI clock,max period for read is 150ns, write is 100ns DataBitLength = 8, //8-bit data length Mode = SpiMode.Mode3 //mode 3, data read on the rising edge - idle high }; _coreWidth = Width = width; _coreHeight = Height = height; _buffer = new byte[bufSize]; _font = new PixelFont7X9();//default font _spiDevice = SpiDevice.FromId(busSelector, spiConnSettings); }
/// <summary> /// Constructor /// </summary> /// <param name="busSelector">The I2C bus selector</param> /// <param name="addr">The I2C device address</param> /// <param name="width">Width of OLED display (in pixel)</param> /// <param name="height">Height of OLED display (in pixel)</param> public OLEDSSD1306_I2C(string busSelector = "I2C1", int addr = 0x3C, int width = 128, int height = 32) { this._i2cDevice = I2cDevice.FromId(busSelector, new I2cConnectionSettings(addr) { BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared });; this._width = width; this._height = height; this._pages = _height / 8; _buffer = new byte[width * _pages]; _font = new PixelFont7X9();//default font }
/// <summary> /// Set the font object to use to render text elements. /// </summary> /// <param name="font">ILCDFont instance.</param> public void SetFont(IPixelFont font) { this.Font = font ?? throw new ArgumentNullException("font"); }