Skip to content

Commit 288a016

Browse files
committed
Merge pull request #45 from danielcweber/AddSda5708Support
Add support for Sda5708 displays.
2 parents 13a75c6 + 1e3d350 commit 288a016

File tree

4 files changed

+965
-0
lines changed

4 files changed

+965
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Raspberry.IO.Components.Displays.Sda5708
4+
{
5+
public enum Sda5708Brightness
6+
{
7+
Level100 = 0,
8+
Level53 = 1,
9+
Level40 = 2,
10+
Level27 = 3,
11+
Level20 = 4,
12+
Level13 = 5,
13+
Level6_6 = 6,
14+
Level0 = 7
15+
}
16+
}
17+
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* Sda5708Connection
2+
* Parts of this code are ported from https://github.com/pimium/sda5708
3+
* which in turn used the information from http://www.sbprojects.com/knowledge/footprints/sda5708.php.
4+
* The font is taken from http://sunge.awardspace.com/glcd-sd/node4.html
5+
* with additional german characters added. */
6+
using System;
7+
using System.IO;
8+
using System.Text;
9+
using System.Linq;
10+
using System.Threading;
11+
using Raspberry.IO;
12+
using Raspberry.IO.GeneralPurpose;
13+
using System.Collections.Generic;
14+
15+
namespace Raspberry.IO.Components.Displays.Sda5708
16+
{
17+
public sealed class Sda5708Connection : IDisposable
18+
{
19+
private Sda5708Brightness _brightness = Sda5708Brightness.Level100;
20+
21+
private readonly ProcessorPin _load;
22+
private readonly ProcessorPin _data;
23+
private readonly ProcessorPin _sdclk;
24+
private readonly ProcessorPin _reset;
25+
private readonly GpioConnection _baseConnection;
26+
27+
public Sda5708Connection () : this(
28+
ProcessorPin.Pin7,
29+
ProcessorPin.Pin8,
30+
ProcessorPin.Pin18,
31+
ProcessorPin.Pin23)
32+
{
33+
}
34+
35+
public Sda5708Connection (ProcessorPin load, ProcessorPin data, ProcessorPin sdclk, ProcessorPin reset)
36+
{
37+
this._load = load;
38+
this._data = data;
39+
this._sdclk = sdclk;
40+
this._reset = reset;
41+
42+
this._baseConnection = new GpioConnection (
43+
load.Output (),
44+
data.Output (),
45+
sdclk.Output (),
46+
reset.Output ());
47+
48+
this._baseConnection [reset] = false;
49+
this._baseConnection [reset] = false;
50+
Thread.Sleep (50);
51+
this._baseConnection [reset] = true;
52+
53+
this.Clear();
54+
}
55+
56+
public void SetBrightness(Sda5708Brightness brightness)
57+
{
58+
this._brightness = brightness;
59+
this.Write(0xe0 | (int)brightness);
60+
}
61+
62+
public void Clear()
63+
{
64+
this.Write(0xc0 | (int)this._brightness);
65+
}
66+
67+
public void WriteString(string str)
68+
{
69+
var chars = str
70+
.PadRight (8, ' ')
71+
.Substring (0, 8);
72+
73+
for(var i = 0; i < chars.Length; i++)
74+
{
75+
this.WriteChar (i, chars [i]);
76+
}
77+
}
78+
79+
private void WriteChar(int position, char value)
80+
{
81+
this.Write(0xa0 + position);
82+
83+
string[] pattern;
84+
if (!Sda5708Font.Patterns.TryGetValue(value, out pattern))
85+
pattern = Sda5708Font.Patterns['?'];
86+
87+
for(var i = 0; i < 7; i++)
88+
{
89+
this.Write (Convert.ToInt32 (pattern[i].Replace (' ', '0'), 2));
90+
}
91+
}
92+
93+
private void Write(int value)
94+
{
95+
this._baseConnection [this._sdclk] = false;
96+
this._baseConnection [this._load] = false;
97+
98+
for(var i = 8; i > 0; i--)
99+
{
100+
this._baseConnection[this._data] = (value & 0x1) == 0x1;
101+
102+
this._baseConnection [this._sdclk] = true;
103+
this._baseConnection [this._sdclk] = false;
104+
105+
value = value >> 1;
106+
}
107+
108+
this._baseConnection [this._sdclk] = false;
109+
this._baseConnection [this._load] = true;
110+
}
111+
112+
#region IDisposable implementation
113+
public void Dispose ()
114+
{
115+
this._baseConnection [this._reset] = false;
116+
((IDisposable)this._baseConnection).Dispose ();
117+
}
118+
#endregion
119+
}
120+
}

0 commit comments

Comments
 (0)