2015-08-09 01:38:16 +02:00
|
|
|
-- setup SPI and connect display
|
|
|
|
function init_spi_display()
|
|
|
|
-- Hardware SPI CLK = GPIO14
|
|
|
|
-- Hardware SPI MOSI = GPIO13
|
|
|
|
-- Hardware SPI MISO = GPIO12 (not used)
|
2016-06-04 00:18:19 +02:00
|
|
|
-- Hardware SPI /CS = GPIO15 (not used)
|
2015-08-09 01:38:16 +02:00
|
|
|
-- CS, D/C, and RES can be assigned freely to available GPIOs
|
|
|
|
local cs = 8 -- GPIO15, pull-down 10k to GND
|
|
|
|
local dc = 4 -- GPIO2
|
|
|
|
local res = 0 -- GPIO16
|
|
|
|
|
2015-10-11 16:03:58 +02:00
|
|
|
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
|
2016-06-04 00:18:19 +02:00
|
|
|
-- we won't be using the HSPI /CS line, so disable it again
|
|
|
|
gpio.mode(8, gpio.INPUT, gpio.PULLUP)
|
2015-09-17 22:37:31 +02:00
|
|
|
|
|
|
|
-- initialize the matching driver for your display
|
|
|
|
-- see app/include/ucg_config.h
|
|
|
|
--disp = ucg.ili9341_18x240x320_hw_spi(cs, dc, res)
|
|
|
|
disp = ucg.st7735_18x128x160_hw_spi(cs, dc, res)
|
2015-08-09 01:38:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- switch statement http://lua-users.org/wiki/SwitchStatement
|
|
|
|
function switch(c)
|
|
|
|
local swtbl = {
|
|
|
|
casevar = c,
|
|
|
|
caseof = function (self, code)
|
|
|
|
local f
|
|
|
|
if (self.casevar) then
|
|
|
|
f = code[self.casevar] or code.default
|
|
|
|
else
|
|
|
|
f = code.missing or code.default
|
|
|
|
end
|
|
|
|
if f then
|
|
|
|
if type(f)=="function" then
|
|
|
|
return f(self.casevar,self)
|
|
|
|
else
|
|
|
|
error("case "..tostring(self.casevar).." not a function")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return swtbl
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
z = 127 -- start value
|
|
|
|
function lcg_rnd()
|
|
|
|
z = bit.band(65 * z + 17, 255)
|
|
|
|
return z
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function millis()
|
|
|
|
local usec = tmr.now()
|
|
|
|
return usec/1000
|
|
|
|
end
|
|
|
|
|
|
|
|
function set_clip_range()
|
|
|
|
local x, y, w, h
|
|
|
|
w = bit.band(lcg_rnd(), 31)
|
|
|
|
h = bit.band(lcg_rnd(), 31)
|
|
|
|
w = w + 25
|
|
|
|
h = h + 25
|
|
|
|
x = bit.rshift(lcg_rnd() * (disp:getWidth() - w), 8)
|
|
|
|
y = bit.rshift(lcg_rnd() * (disp:getHeight() - h), 8)
|
|
|
|
|
|
|
|
disp:setClipRange(x, y, w, h)
|
|
|
|
end
|
|
|
|
|
|
|
|
function loop()
|
|
|
|
|
|
|
|
if (loop_idx == 0) then
|
|
|
|
switch(bit.band(r, 3)) : caseof {
|
|
|
|
[0] = function() disp:undoRotate() end,
|
|
|
|
[1] = function() disp:setRotate90() end,
|
|
|
|
[2] = function() disp:setRotate180() end,
|
|
|
|
default = function() disp:setRotate270() end
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( r > 3 ) then
|
|
|
|
disp:clearScreen()
|
|
|
|
set_clip_range()
|
2017-01-02 21:45:06 +01:00
|
|
|
else
|
|
|
|
disp:undoClipRange()
|
2015-08-09 01:38:16 +02:00
|
|
|
end
|
|
|
|
|
2017-01-02 21:45:06 +01:00
|
|
|
r = bit.band(r + 1, 7)
|
2015-08-09 01:38:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
switch(loop_idx) : caseof {
|
|
|
|
[0] = function() end,
|
2015-08-09 12:54:35 +02:00
|
|
|
[1] = function() require("GT_graphics_test").run() end,
|
|
|
|
[2] = function() require("GT_cross").run() end,
|
|
|
|
[3] = function() require("GT_pixel_and_lines").run() end,
|
|
|
|
[4] = function() require("GT_color_test").run() end,
|
|
|
|
[5] = function() require("GT_triangle").run() end,
|
|
|
|
[6] = function() require("GT_fonts").run() end,
|
|
|
|
[7] = function() require("GT_text").run() end,
|
|
|
|
[8] = function() if r <= 3 then require("GT_clip").run() end end,
|
|
|
|
[9] = function() require("GT_box").run() end,
|
|
|
|
[10] = function() require("GT_gradient").run() end,
|
|
|
|
[11] = function() disp:setMaxClipRange() end,
|
2015-08-09 01:38:16 +02:00
|
|
|
default = function() loop_idx = -1 end
|
|
|
|
}
|
|
|
|
|
|
|
|
loop_idx = loop_idx + 1
|
2015-08-09 12:54:35 +02:00
|
|
|
|
|
|
|
print("Heap: " .. node.heap())
|
2015-08-09 01:38:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-08-09 12:54:35 +02:00
|
|
|
T = 1000
|
2015-08-09 01:38:16 +02:00
|
|
|
|
|
|
|
r = 0
|
|
|
|
loop_idx = 0
|
|
|
|
|
|
|
|
init_spi_display()
|
|
|
|
|
|
|
|
disp:begin(ucg.FONT_MODE_TRANSPARENT)
|
|
|
|
disp:setFont(ucg.font_ncenR14_hr)
|
|
|
|
disp:clearScreen()
|
|
|
|
|
|
|
|
|
|
|
|
tmr.register(0, 3000, tmr.ALARM_AUTO, function() loop() end)
|
|
|
|
tmr.start(0)
|