diff options
Diffstat (limited to 'utils/hwstub/tools/lua/sansaexpress.lua')
-rw-r--r-- | utils/hwstub/tools/lua/sansaexpress.lua | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/sansaexpress.lua b/utils/hwstub/tools/lua/sansaexpress.lua new file mode 100644 index 0000000000..f152192486 --- /dev/null +++ b/utils/hwstub/tools/lua/sansaexpress.lua | |||
@@ -0,0 +1,97 @@ | |||
1 | -- | ||
2 | -- Sansa Express | ||
3 | -- | ||
4 | SANSAEXPRESS = {} | ||
5 | |||
6 | function SANSAEXPRESS.set_backlight(val) | ||
7 | STMP.pinctrl.pin(3, 13).muxsel('GPIO') | ||
8 | STMP.pinctrl.pin(3, 13).enable() | ||
9 | STMP.pinctrl.pin(3, 13).clr() | ||
10 | for i = 0, val - 1 do | ||
11 | STMP.pinctrl.pin(3, 13).clr() | ||
12 | STMP.pinctrl.pin(3, 13).set() | ||
13 | end | ||
14 | end | ||
15 | |||
16 | function SANSAEXPRESS.lcd_init() | ||
17 | STMP.lcdif.setup_clock() | ||
18 | STMP.pinctrl.lcdif.setup_system(8, false) | ||
19 | STMP.lcdif.init() | ||
20 | STMP.lcdif.set_word_length(8) | ||
21 | STMP.lcdif.set_system_timing(4, 4, 1, 1) | ||
22 | STMP.lcdif.set_reset(1) | ||
23 | STMP.lcdif.set_reset(0) | ||
24 | STMP.lcdif.set_reset(1) | ||
25 | STMP.lcdif.send_pio(false, | ||
26 | { | ||
27 | 0x0a, -- set lower column address: 10 | ||
28 | 0xa1, -- set segment ramp: 131 -> 0 | ||
29 | 0xda, -- set COM configuration: | ||
30 | 0x12, -- -> use alternative | ||
31 | 0xc0, -- set COM scan dir: normal | ||
32 | 0xa8, -- set multiplex ratio: | ||
33 | 0x3f, -- -> 63MUX | ||
34 | 0xd5, -- set display clock freq: | ||
35 | 0x50, -- -> divide ratio = 1, osc freq = 5 | ||
36 | 0xdb, -- set vdcom deselect level | ||
37 | 0x08, -- -> 8 | ||
38 | 0x81, -- set contrast register | ||
39 | 0x25, -- -> 0x25 | ||
40 | 0xad, -- set DCDC on/off | ||
41 | 0x8a, -- -> off | ||
42 | 0xc8, -- set com output scan: reverse | ||
43 | }) | ||
44 | for page = 0, 7 do | ||
45 | STMP.lcdif.send_pio(false, | ||
46 | { | ||
47 | 0xb0 + page, -- set page address | ||
48 | 0x02, -- set low column address: 2 | ||
49 | 0x10, -- set higher column address | ||
50 | }) | ||
51 | for col = 0, 15 do | ||
52 | STMP.lcdif.send_pio(true, {0, 0, 0, 0, 0, 0, 0, 0}) | ||
53 | end | ||
54 | STMP.lcdif.send_pio(true, {0, 0, 0, 0}) | ||
55 | end | ||
56 | STMP.lcdif.send_pio(false, {0xaf}) -- turn on panel | ||
57 | -- wait | ||
58 | STMP.lcdif.send_pio(false, | ||
59 | { | ||
60 | 0x40, -- set display start line: 0 | ||
61 | 0xa4, -- set entire display: normal | ||
62 | 0xa6, -- set normal display: normal | ||
63 | 0xd3, -- set vertical scroll: | ||
64 | 0x00, -- -> 0 | ||
65 | 0xd9, -- set precharge period | ||
66 | 0x1f, -- -> 31 | ||
67 | }) | ||
68 | for page = 0, 7 do | ||
69 | STMP.lcdif.send_pio(false, | ||
70 | { | ||
71 | 0xb0 + page, -- set page address | ||
72 | 0x02, -- set low column address: 2 | ||
73 | 0x10, -- set higher column address | ||
74 | }) | ||
75 | for col = 0, 15 do | ||
76 | STMP.lcdif.send_pio(true, {0, 0, 0, 0, 0, 0, 0, 0}) | ||
77 | end | ||
78 | end | ||
79 | end | ||
80 | |||
81 | function SANSAEXPRESS.set_pixel(x, y, val) | ||
82 | page = math.floor(y / 8) | ||
83 | col = 2 + x -- LCD has two column offset | ||
84 | col_low = bit32.band(col, 0xf) | ||
85 | col_high = bit32.rshift(col ,4) | ||
86 | col_off = y % 8 | ||
87 | STMP.lcdif.send_pio(false, {0x00 + col_low, 0x10 + col_high, 0xb0 + page}) | ||
88 | print(col_off) | ||
89 | byte = bit32.lshift(val, col_off) | ||
90 | print(byte) | ||
91 | STMP.lcdif.send_pio(true, {byte}) | ||
92 | end | ||
93 | |||
94 | function SANSAEXPRESS.init() | ||
95 | SANSAEXPRESS.lcd_init() | ||
96 | SANSAEXPRESS.set_backlight(20) | ||
97 | end \ No newline at end of file | ||