From 1e3d350ebcfdb37aeb6f7b4299cb424e1a43af63 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 17 May 2015 16:49:11 +0200 Subject: [PATCH] Add support for Sda5708 displays. --- .../Displays/Sda5708/Sda5708Brightness.cs | 17 + .../Displays/Sda5708/Sda5708Connection.cs | 120 +++ .../Displays/Sda5708/Sda5708Font.cs | 825 ++++++++++++++++++ .../Raspberry.IO.Components.csproj | 3 + 4 files changed, 965 insertions(+) create mode 100644 Raspberry.IO.Components/Displays/Sda5708/Sda5708Brightness.cs create mode 100644 Raspberry.IO.Components/Displays/Sda5708/Sda5708Connection.cs create mode 100644 Raspberry.IO.Components/Displays/Sda5708/Sda5708Font.cs diff --git a/Raspberry.IO.Components/Displays/Sda5708/Sda5708Brightness.cs b/Raspberry.IO.Components/Displays/Sda5708/Sda5708Brightness.cs new file mode 100644 index 0000000..8dbc18c --- /dev/null +++ b/Raspberry.IO.Components/Displays/Sda5708/Sda5708Brightness.cs @@ -0,0 +1,17 @@ +using System; + +namespace Raspberry.IO.Components.Displays.Sda5708 +{ + public enum Sda5708Brightness + { + Level100 = 0, + Level53 = 1, + Level40 = 2, + Level27 = 3, + Level20 = 4, + Level13 = 5, + Level6_6 = 6, + Level0 = 7 + } +} + diff --git a/Raspberry.IO.Components/Displays/Sda5708/Sda5708Connection.cs b/Raspberry.IO.Components/Displays/Sda5708/Sda5708Connection.cs new file mode 100644 index 0000000..d8cc142 --- /dev/null +++ b/Raspberry.IO.Components/Displays/Sda5708/Sda5708Connection.cs @@ -0,0 +1,120 @@ +/* Sda5708Connection + * Parts of this code are ported from https://github.com/pimium/sda5708 + * which in turn used the information from http://www.sbprojects.com/knowledge/footprints/sda5708.php. + * The font is taken from http://sunge.awardspace.com/glcd-sd/node4.html + * with additional german characters added. */ +using System; +using System.IO; +using System.Text; +using System.Linq; +using System.Threading; +using Raspberry.IO; +using Raspberry.IO.GeneralPurpose; +using System.Collections.Generic; + +namespace Raspberry.IO.Components.Displays.Sda5708 +{ + public sealed class Sda5708Connection : IDisposable + { + private Sda5708Brightness _brightness = Sda5708Brightness.Level100; + + private readonly ProcessorPin _load; + private readonly ProcessorPin _data; + private readonly ProcessorPin _sdclk; + private readonly ProcessorPin _reset; + private readonly GpioConnection _baseConnection; + + public Sda5708Connection () : this( + ProcessorPin.Pin7, + ProcessorPin.Pin8, + ProcessorPin.Pin18, + ProcessorPin.Pin23) + { + } + + public Sda5708Connection (ProcessorPin load, ProcessorPin data, ProcessorPin sdclk, ProcessorPin reset) + { + this._load = load; + this._data = data; + this._sdclk = sdclk; + this._reset = reset; + + this._baseConnection = new GpioConnection ( + load.Output (), + data.Output (), + sdclk.Output (), + reset.Output ()); + + this._baseConnection [reset] = false; + this._baseConnection [reset] = false; + Thread.Sleep (50); + this._baseConnection [reset] = true; + + this.Clear(); + } + + public void SetBrightness(Sda5708Brightness brightness) + { + this._brightness = brightness; + this.Write(0xe0 | (int)brightness); + } + + public void Clear() + { + this.Write(0xc0 | (int)this._brightness); + } + + public void WriteString(string str) + { + var chars = str + .PadRight (8, ' ') + .Substring (0, 8); + + for(var i = 0; i < chars.Length; i++) + { + this.WriteChar (i, chars [i]); + } + } + + private void WriteChar(int position, char value) + { + this.Write(0xa0 + position); + + string[] pattern; + if (!Sda5708Font.Patterns.TryGetValue(value, out pattern)) + pattern = Sda5708Font.Patterns['?']; + + for(var i = 0; i < 7; i++) + { + this.Write (Convert.ToInt32 (pattern[i].Replace (' ', '0'), 2)); + } + } + + private void Write(int value) + { + this._baseConnection [this._sdclk] = false; + this._baseConnection [this._load] = false; + + for(var i = 8; i > 0; i--) + { + this._baseConnection[this._data] = (value & 0x1) == 0x1; + + this._baseConnection [this._sdclk] = true; + this._baseConnection [this._sdclk] = false; + + value = value >> 1; + } + + this._baseConnection [this._sdclk] = false; + this._baseConnection [this._load] = true; + } + + #region IDisposable implementation + public void Dispose () + { + this._baseConnection [this._reset] = false; + ((IDisposable)this._baseConnection).Dispose (); + } + #endregion + } +} diff --git a/Raspberry.IO.Components/Displays/Sda5708/Sda5708Font.cs b/Raspberry.IO.Components/Displays/Sda5708/Sda5708Font.cs new file mode 100644 index 0000000..67444c5 --- /dev/null +++ b/Raspberry.IO.Components/Displays/Sda5708/Sda5708Font.cs @@ -0,0 +1,825 @@ +using System; +using System.IO; +using System.Text; +using System.Linq; +using System.Threading; +using Raspberry.IO; +using Raspberry.IO.GeneralPurpose; +using System.Collections.Generic; + +namespace Raspberry.IO.Components.Displays.Sda5708 +{ + public sealed class Sda5708Font + { + public static readonly Dictionary Patterns = new Dictionary + { + { ' ', new[]{ " ", + " ", + " ", + " ", + " ", + " ", + " " }}, + + { '!', new[]{ " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " ", + " 1 " }}, + + { '"', new[]{ " 1 1 ", + " 1 1 ", + " 1 1 ", + " ", + " ", + " ", + " " }}, + + { '#', new[]{ " 1 1 ", + " 1 1 ", + "11111", + " 1 1 ", + "11111", + " 1 1 ", + " 1 1 " }}, + + { '$', new[]{ " 1 ", + " 1111", + "1 1 ", + " 111 ", + " 1 1", + "1111 ", + " 1 " }}, + + { '%', new[]{ "11 ", + "11 1", + " 1 ", + " 1 ", + " 1 ", + "1 11", + " 11" }}, + + { '&', new[]{ " 11 ", + "1 1 ", + "1 1 ", + " 1 ", + "1 1 1", + "1 1 ", + " 11 1" }}, + + { '\'', new[]{ " 11 ", + " 1 ", + " 1 ", + " ", + " ", + " ", + " " }}, + + { '(', new[]{ " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { ')', new[]{ " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { '*', new[]{ " ", + " 1 1 ", + " 1 ", + "11111", + " 1 ", + " 1 1 ", + " " }}, + + { '+', new[]{ " ", + " 1 ", + " 1 ", + "11111", + " 1 ", + " 1 ", + " " }}, + + { ',', new[]{ " ", + " ", + " ", + " ", + " 11 ", + " 1 ", + " 1 " }}, + + { '-', new[]{ " ", + " ", + " ", + "11111", + " ", + " ", + " " }}, + + { '.', new[]{ " ", + " ", + " ", + " ", + " ", + " 11 ", + " 11 " }}, + + { '/', new[]{ " ", + " 1", + " 1 ", + " 1 ", + " 1 ", + "1 ", + " " }}, + + { '0', new[]{ " 111 ", + "1 1", + "1 11", + "1 1 1", + "11 1", + "1 1", + " 111 " }}, + + { '1', new[]{ " 1 ", + " 11 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 111 " }}, + + { '2', new[]{ " 111 ", + "1 1", + " 1", + " 1 ", + " 1 ", + " 1 ", + "11111" }}, + + { '3', new[]{ "11111", + " 1 ", + " 1 ", + " 1 ", + " 1", + "1 1", + " 111 " }}, + + { '4', new[]{ " 1 ", + " 11 ", + " 1 1 ", + "1 1 ", + "11111", + " 1 ", + " 1 " }}, + + { '5', new[]{ "11111", + "1 ", + "1111 ", + " 1", + " 1", + "1 1", + " 111 " }}, + + { '6', new[]{ " 11 ", + " 1 ", + "1 ", + "1111 ", + "1 1", + "1 1", + " 111 " }}, + + { '7', new[]{ "11111", + " 1", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { '8', new[]{ " 111 ", + "1 1", + "1 1", + " 111 ", + "1 1", + "1 1", + " 111 " }}, + + { '9', new[]{ " 111 ", + "1 1", + "1 1", + " 1111", + " 1", + " 1 ", + " 11 " }}, + + { ':', new[]{ " ", + " 11 ", + " 11 ", + " ", + " 11 ", + " 11 ", + " " }}, + + { ';', new[]{ " ", + " 11 ", + " 11 ", + " ", + " 11 ", + " 1 ", + " 1 " }}, + + { '<', new[]{ " 1", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1" }}, + + { '=', new[]{ " ", + " ", + "11111", + " ", + "11111", + " ", + " " }}, + + { '>', new[]{ "1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + "1 " }}, + + { '?', new[]{ " 111 ", + "1 1", + " 1", + " 1 ", + " 1 ", + " ", + " 1 " }}, + + { '@', new[]{ " 111 ", + "1 1", + " 1", + " 11 1", + "1 1 1", + "1 1 1", + " 111 " }}, + + { 'A', new[]{ " 111 ", + "1 1", + "1 1", + "1 1", + "11111", + "1 1", + "1 1" }}, + + { 'Ä', new[]{ "1 1", + " ", + " 111 ", + "1 1", + "11111", + "1 1", + "1 1" }}, + + { 'B', new[]{ "1111 ", + "1 1", + "1 1", + "1111 ", + "1 1", + "1 1", + "1111 " }}, + + { 'C', new[]{ " 111 ", + "1 1", + "1 ", + "1 ", + "1 ", + "1 1", + " 111 " }}, + + { 'D', new[]{ "111 ", + "1 1 ", + "1 1", + "1 1", + "1 1", + "1 1 ", + "111 " }}, + + { 'E', new[]{ "11111", + "1 ", + "1 ", + "1111 ", + "1 ", + "1 ", + "11111" }}, + + { 'F', new[]{ "11111", + "1 ", + "1 ", + "111 ", + "1 ", + "1 ", + "1 " }}, + + { 'G', new[]{ " 111 ", + "1 1", + "1 ", + "1 ", + "1 11", + "1 1", + " 111 " }}, + + { 'H', new[]{ "1 1", + "1 1", + "1 1", + "11111", + "1 1", + "1 1", + "1 1" }}, + + { 'I', new[]{ " 111 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 111 " }}, + + { 'J', new[]{ " 111", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + "1 1 ", + " 11 " }}, + + { 'K', new[]{ "1 1", + "1 1 ", + "1 1 ", + "11 ", + "1 1 ", + "1 1 ", + "1 1" }}, + + { 'L', new[]{ "1 ", + "1 ", + "1 ", + "1 ", + "1 ", + "1 ", + "11111" }}, + + { 'M', new[]{ "1 1", + "11 11", + "1 1 1", + "1 1", + "1 1", + "1 1", + "1 1" }}, + + { 'N', new[]{ "1 1", + "1 1", + "11 1", + "1 1 1", + "1 11", + "1 1", + "1 1" }}, + + { 'O', new[]{ " 111 ", + "1 1", + "1 1", + "1 1", + "1 1", + "1 1", + " 111 " }}, + + { 'Ö', new[]{ "1 1", + " ", + " 111 ", + "1 1", + "1 1", + "1 1", + " 111 " }}, + + { 'P', new[]{ "1111 ", + "1 1", + "1 1", + "1111 ", + "1 ", + "1 ", + "1 " }}, + + { 'Q', new[]{ " 111 ", + "1 1", + "1 1", + "1 1", + "1 1 1", + "1 1 ", + " 11 1" }}, + + { 'R', new[]{ "1111 ", + "1 1", + "1 1", + "1111 ", + "1 1 ", + "1 1 ", + "1 1" }}, + + { 'S', new[]{ " 1111", + "1 ", + "1 ", + " 111 ", + " 1", + " 1", + "1111 " }}, + + { 'T', new[]{ "11111", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { 'U', new[]{ "1 1", + "1 1", + "1 1", + "1 1", + "1 1", + "1 1", + " 111 " }}, + + { 'Ü', new[]{ "1 1", + " ", + "1 1", + "1 1", + "1 1", + "1 1", + " 111 " }}, + + { 'V', new[]{ "1 1", + "1 1", + "1 1", + "1 1", + "1 1", + " 1 1 ", + " 1 " }}, + + { 'W', new[]{ "1 1", + "1 1", + "1 1", + "1 1 1", + "1 1 1", + "11 11", + "1 1" }}, + + { 'X', new[]{ "1 1", + "1 1", + " 1 1 ", + " 1 ", + " 1 1 ", + "1 1", + "1 1" }}, + + { 'Y', new[]{ "1 1", + "1 1", + " 1 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { 'Z', new[]{ "11111", + " 1", + " 1 ", + " 1 ", + " 1 ", + "1 ", + "11111" }}, + + { '[', new[]{ " 111", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 111" }}, + + { '\\', new[]{ " ", + "1 ", + " 1 ", + " 1 ", + " 1 ", + " 1", + " " }}, + + { ']', new[]{ "111 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + "111 " }}, + + { '^', new[]{ " 1 ", + " 1 1 ", + "1 1", + " ", + " ", + " ", + " " }}, + + { '_', new[]{ " ", + " ", + " ", + " ", + " ", + " ", + "11111" }}, + + { '`', new[]{ " 1 ", + " 1 ", + " 1 ", + " ", + " ", + " ", + " " }}, + + { 'a', new[]{ " ", + " ", + " 111 ", + " 1", + " 1111", + "1 1", + " 1111" }}, + + { 'ä', new[]{ " 1 1 ", + " ", + " 111 ", + " 1", + " 1111", + "1 1", + " 1111" }}, + + { 'b', new[]{ "1 ", + "1 ", + "1 11 ", + "11 1", + "1 1", + "1 1", + "1111 " }}, + + { 'c', new[]{ " ", + " ", + " 111 ", + "1 ", + "1 ", + "1 1", + " 111 " }}, + + { 'd', new[]{ " 1", + " 1", + " 11 1", + "1 11", + "1 1", + "1 1", + " 1111" }}, + + { 'e', new[]{ " ", + " ", + " 111 ", + "1 1", + "11111", + "1 ", + " 111 " }}, + + { 'f', new[]{ " 11 ", + " 1 1", + " 1 ", + "111 ", + " 1 ", + " 1 ", + " 1 " }}, + + { 'g', new[]{ " ", + " ", + " 1111", + "1 1", + " 1111", + " 1", + " 11 " }}, + + { 'h', new[]{ "1 ", + "1 ", + "1 11 ", + "11 1", + "1 1", + "1 1", + "1 1" }}, + + { 'i', new[]{ " 1 ", + " ", + " 11 ", + " 1 ", + " 1 ", + " 1 ", + " 111 " }}, + + { 'j', new[]{ " 1 ", + " ", + " 11 ", + " 1 ", + " 1 ", + "1 1 ", + " 11 " }}, + + { 'k', new[]{ " 1 ", + " 1 ", + " 1 1", + " 1 1 ", + " 11 ", + " 1 1 ", + " 1 1" }}, + + { 'l', new[]{ " 11 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 111 " }}, + + { 'm', new[]{ " ", + " ", + "11 1 ", + "1 1 1", + "1 1 1", + "1 1", + "1 1" }}, + + { 'n', new[]{ " ", + " ", + "1 11 ", + "11 1", + "1 1", + "1 1", + "1 1" }}, + + { 'o', new[]{ " ", + " ", + " 111 ", + "1 1", + "1 1", + "1 1", + " 111 " }}, + + { 'ö', new[]{ " 1 1 ", + " ", + " 111 ", + "1 1", + "1 1", + "1 1", + " 111 " }}, + + { 'p', new[]{ " ", + " ", + "1111 ", + "1 1", + "1111 ", + "1 ", + "1 " }}, + + { 'q', new[]{ " ", + " ", + " 11 1", + "1 11", + " 1111", + " 1", + " 1" }}, + + { 'r', new[]{ " ", + " ", + "1 11 ", + "11 1", + "1 ", + "1 ", + "1 " }}, + + { 's', new[]{ " ", + " ", + " 111 ", + "1 ", + " 111 ", + " 1", + "1111 " }}, + + { 't', new[]{ " 1 ", + " 1 ", + "111 ", + " 1 ", + " 1 ", + " 1 1", + " 11 " }}, + + { 'u', new[]{ " ", + " ", + "1 1", + "1 1", + "1 1", + "1 11", + " 11 1" }}, + + { 'ü', new[]{ " 1 1 ", + " ", + "1 1", + "1 1", + "1 1", + "1 11", + " 11 1" }}, + + { 'v', new[]{ " ", + " ", + "1 1", + "1 1", + "1 1", + " 1 1 ", + " 1 " }}, + + { 'w', new[]{ " ", + " ", + "1 1", + "1 1", + "1 1 1", + "1 1 1", + " 1 1 " }}, + + { 'x', new[]{ " ", + " ", + "1 1", + " 1 1 ", + " 1 ", + " 1 1 ", + "1 1" }}, + + { 'y', new[]{ " ", + " ", + "1 1", + "1 1", + " 1111", + " 1", + " 111 " }}, + + { 'z', new[]{ " ", + " ", + "11111", + " 1 ", + " 1 ", + " 1 ", + "11111" }}, + + { 'ß', new[]{ " 11 ", + "1 1 ", + "111 ", + "1 1 ", + "1 1 ", + "111 ", + "1 " }}, + + { '{', new[]{ " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { '|', new[]{ " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + + { '}', new[]{ " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 ", + " 1 " }}, + }; + } +} \ No newline at end of file diff --git a/Raspberry.IO.Components/Raspberry.IO.Components.csproj b/Raspberry.IO.Components/Raspberry.IO.Components.csproj index 7ca78e4..b831c74 100644 --- a/Raspberry.IO.Components/Raspberry.IO.Components.csproj +++ b/Raspberry.IO.Components/Raspberry.IO.Components.csproj @@ -150,6 +150,9 @@ + + +