-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
127 lines (114 loc) · 4.67 KB
/
main.lua
File metadata and controls
127 lines (114 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
--- 模块功能:lcddemo
-- @module lcd
-- @author Dozingfiretruck
-- @release 2021.01.25
-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "lcddemo"
VERSION = "1.0.0"
log.info("main", PROJECT, VERSION)
-- sys库是标配
_G.sys = require("sys")
--添加硬狗防止程序卡死
if wdt then
wdt.init(9000)--初始化watchdog设置为9s
sys.timerLoopStart(wdt.feed, 3000)--3s喂一次狗
end
--[[
===============================================
===============================================
===============================================
这个demo必须修改才能运行, 把注释看完
===============================================
===============================================
===============================================
]]
-- 按实际情况修改, spi的id, cs脚, 波特率, 都要按实际情况改
spi_lcd = spi.deviceSetup(5,pin.PC14,0,0,8,48*1000*1000,spi.MSB,1,1)
--[[ 下面为custom方式示例,自己传入lcd指令来实现驱动,示例以st7735s做展示 ]]
-- [[ 注意修改下面的pin_xx对应的gpio信息, 数值与pin.XXX 均可]]
-- initcmd的含义, 分3种指令, 每个指令都是int32, 前2个字节是命令, 后2个字节是值
-- 0001 delay 延时, 例如 00010002 , 延时2ms
-- 0002 cmd 发命令, 例如 0002004, dc设置为CMD模式, SPI发送 0x04
-- 0003 data 发数据, 例如 0003004, dc设置为DATA模式, SPI发送 0x04
-- lcd.init("custom",{
-- port = "device",
-- pin_dc = pin.PB01,
-- pin_pwr = pin.PB00,
-- pin_rst = pin.PB03,
-- direction = 0,
-- w = 128,
-- h = 160,
-- xoffset = 2,
-- yoffset = 1,
-- sleepcmd = 0x10,
-- wakecmd = 0x11,
-- initcmd = {
-- 0x00020011,0x00010078,0x00020021, -- 反显
-- 0x000200B1,0x00030002,0x00030035,
-- 0x00030036,0x000200B2,0x00030002,
-- 0x00030035,0x00030036,0x000200B3,
-- 0x00030002,0x00030035,0x00030036,
-- 0x00030002,0x00030035,0x00030036,
-- 0x000200B4,0x00030007,0x000200C0,
-- 0x000300A2,0x00030002,0x00030084,
-- 0x000200C1,0x000300C5,0x000200C2,
-- 0x0003000A,0x00030000,0x000200C3,
-- 0x0003008A,0x0003002A,0x000200C4,
-- 0x0003008A,0x000300EE,0x000200C5,
-- 0x0003000E,0x00020036,0x000300C0,
-- 0x000200E0,0x00030012,0x0003001C,
-- 0x00030010,0x00030018,0x00030033,
-- 0x0003002C,0x00030025,0x00030028,
-- 0x00030028,0x00030027,0x0003002F,
-- 0x0003003C,0x00030000,0x00030003,
-- 0x00030003,0x00030010,0x000200E1,
-- 0x00030012,0x0003001C,0x00030010,
-- 0x00030018,0x0003002D,0x00030028,
-- 0x00030023,0x00030028,0x00030028,
-- 0x00030026,0x0003002F,0x0003003B,
-- 0x00030000,0x00030003,0x00030003,
-- 0x00030010,0x0002003A,0x00030005,
-- 0x00020029,
-- },
-- },
-- spi_lcd)
--[[ 下面为custom方式示例,自己传入lcd指令来实现驱动,示例以st7789做展示 ]]
-- lcd.init("custom",{
-- port = "device",
-- pin_dc = pin.PB01,
-- pin_pwr = pin.PB00,
-- pin_rst = pin.PB03,
-- direction = 0,
-- w = 240,
-- h = 320,
-- xoffset = 0,
-- yoffset = 0,
-- sleepcmd = 0x10,
-- wakecmd = 0x11,
-- initcmd = {--0001 delay 0002 cmd 0003 data
-- 0x00020036, 0x00030000, 0x0002003A, 0x00030005, 0x000200B2,
-- 0x0003000C, 0x0003000C, 0x00030000, 0x00030033, 0x00030033,
-- 0x000200B7, 0x00030035, 0x000200BB, 0x00030032,
-- 0x000200C2, 0x00030001, 0x000200C3, 0x00030015,
-- 0x000200C4, 0x00030020, 0x000200C6, 0x0003000F, 0x000200D0,
-- 0x000300A4, 0x000300A1, 0x000200E0, 0x000300D0, 0x00030008,
-- 0x0003000E, 0x00030009, 0x00030009, 0x00030005, 0x00030031,
-- 0x00030033, 0x00030048, 0x00030017, 0x00030014, 0x00030015,
-- 0x00030031, 0x00030034, 0x000200E1, 0x000300D0, 0x00030008,
-- 0x0003000E, 0x00030009, 0x00030009, 0x00030015, 0x00030031,
-- 0x00030033, 0x00030048, 0x00030017, 0x00030014, 0x00030015,
-- 0x00030031, 0x00030034,
-- 0x00020021, -- 如果发现屏幕反色,注释掉此行
-- },
-- },
-- spi_lcd)
sys.taskInit(function()
sys.wait(500)
log.info("lcd.drawLine", lcd.drawLine(20, 20, 150, 20, 0x001F))
log.info("lcd.drawRectangle", lcd.drawRectangle(20, 40, 120, 70, 0xF800))
log.info("lcd.drawCircle", lcd.drawCircle(50, 50, 20, 0x0CE0))
end)
-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!