2015-02-18 23:57:34 +01:00
|
|
|
|
|
|
|
-- setup I2c and connect display
|
|
|
|
function init_i2c_display()
|
2015-03-11 21:53:45 +01:00
|
|
|
-- SDA and SCL can be assigned freely to available GPIOs
|
2015-04-21 21:48:12 +02:00
|
|
|
local sda = 5 -- GPIO14
|
|
|
|
local scl = 6 -- GPIO12
|
|
|
|
local sla = 0x3c
|
2015-02-18 23:57:34 +01:00
|
|
|
i2c.setup(0, sda, scl, i2c.SLOW)
|
|
|
|
disp = u8g.ssd1306_128x64_i2c(sla)
|
|
|
|
end
|
|
|
|
|
2015-03-11 21:53:45 +01:00
|
|
|
-- setup SPI and connect display
|
|
|
|
function init_spi_display()
|
|
|
|
-- Hardware SPI CLK = GPIO14
|
|
|
|
-- Hardware SPI MOSI = GPIO13
|
|
|
|
-- Hardware SPI MISO = GPIO12 (not used)
|
2015-03-17 21:03:15 +01:00
|
|
|
-- CS, D/C, and RES can be assigned freely to available GPIOs
|
2015-04-21 21:48:12 +02:00
|
|
|
local cs = 8 -- GPIO15, pull-down 10k to GND
|
|
|
|
local dc = 4 -- GPIO2
|
|
|
|
local res = 0 -- GPIO16
|
2015-03-11 21:53:45 +01:00
|
|
|
|
|
|
|
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
|
2015-07-16 23:23:43 +02:00
|
|
|
disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
|
2015-03-11 21:53:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-02-18 23:57:34 +01:00
|
|
|
function xbm_picture()
|
|
|
|
disp:setFont(u8g.font_6x10)
|
|
|
|
disp:drawStr( 0, 10, "XBM picture")
|
|
|
|
|
|
|
|
disp:drawXBM( 0, 20, 38, 24, xbm_data )
|
|
|
|
end
|
|
|
|
|
2015-02-19 12:12:14 +01:00
|
|
|
function bitmap_picture(state)
|
2015-02-18 23:57:34 +01:00
|
|
|
disp:setFont(u8g.font_6x10)
|
|
|
|
disp:drawStr( 0, 10, "Bitmap picture")
|
|
|
|
|
2015-02-19 12:12:14 +01:00
|
|
|
disp:drawBitmap( 0 + (state * 10), 20 + (state * 4), 1, 8, bm_data )
|
2015-02-18 23:57:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- the draw() routine
|
|
|
|
function draw(draw_state)
|
|
|
|
local component = bit.rshift(draw_state, 3)
|
|
|
|
|
|
|
|
if (component == 0) then
|
|
|
|
xbm_picture(bit.band(draw_state, 7))
|
|
|
|
elseif (component == 1) then
|
|
|
|
bitmap_picture(bit.band(draw_state, 7))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-03-11 21:53:45 +01:00
|
|
|
function bitmap_test(delay)
|
2015-02-18 23:57:34 +01:00
|
|
|
-- read XBM picture
|
|
|
|
file.open("u8glib_logo.xbm", "r")
|
|
|
|
xbm_data = file.read()
|
|
|
|
file.close()
|
|
|
|
|
2015-02-19 12:12:14 +01:00
|
|
|
-- read Bitmap picture
|
|
|
|
file.open("u8g_rook.bm", "r")
|
|
|
|
bm_data = file.read()
|
|
|
|
file.close()
|
|
|
|
|
2015-02-18 23:57:34 +01:00
|
|
|
print("--- Starting Bitmap Test ---")
|
|
|
|
dir = 0
|
|
|
|
next_rotation = 0
|
|
|
|
|
|
|
|
local draw_state
|
2015-02-19 12:12:14 +01:00
|
|
|
for draw_state = 1, 7 + 1*8, 1 do
|
2015-02-18 23:57:34 +01:00
|
|
|
disp:firstPage()
|
|
|
|
repeat
|
|
|
|
draw(draw_state)
|
|
|
|
until disp:nextPage() == false
|
|
|
|
|
2015-03-11 21:53:45 +01:00
|
|
|
tmr.delay(delay)
|
2015-02-18 23:57:34 +01:00
|
|
|
tmr.wdclr()
|
|
|
|
end
|
|
|
|
|
|
|
|
print("--- Bitmap Test done ---")
|
|
|
|
end
|
|
|
|
|
2015-03-11 21:53:45 +01:00
|
|
|
--init_i2c_display()
|
|
|
|
init_spi_display()
|
|
|
|
bitmap_test(50000)
|