This commit is contained in:
kraus 2021-12-05 22:45:50 +01:00
commit 8b892db11a
9 changed files with 84051 additions and 8 deletions

View File

@ -73,7 +73,7 @@
/* always enable U8G2_16BIT on 32bit environments, see issue https://github.com/olikraus/u8g2/issues/1222 */
#ifndef U8G2_16BIT
#if defined(unix) || defined(__unix__) || defined(__arm__) || defined(__xtensa__) || defined(xtensa) || defined(__arc__) || defined(ESP8266) || defined(ESP_PLATFORM)
#if defined(unix) || defined(__unix__) || defined(__arm__) || defined(__xtensa__) || defined(xtensa) || defined(__arc__) || defined(ESP8266) || defined(ESP_PLATFORM) || defined(__LUATOS__)
#define U8G2_16BIT
#endif
#endif
@ -86,7 +86,6 @@
*/
//#define U8G2_USE_DYNAMIC_ALLOC
/* U8g2 feature selection, see also https://github.com/olikraus/u8g2/wiki/u8g2optimization */
/*
@ -191,7 +190,7 @@
/* the macro U8G2_USE_LARGE_FONTS enables large fonts (>32K) */
/* it can be enabled for those uC supporting larger arrays */
#if defined(unix) || defined(__unix__) || defined(__arm__) || defined(__arc__) || defined(ESP8266) || defined(ESP_PLATFORM)
#if defined(unix) || defined(__unix__) || defined(__arm__) || defined(__arc__) || defined(ESP8266) || defined(ESP_PLATFORM) || defined(__LUATOS__)
#ifndef U8G2_USE_LARGE_FONTS
#define U8G2_USE_LARGE_FONTS
#endif

View File

@ -194,6 +194,10 @@ uint8_t u8x8_pgm_read_esp(const uint8_t * addr); /* u8x8_8x8.c */
#define U8X8_USE_PINS
#endif
#ifdef __LUATOS__
#define U8X8_USE_PINS
#endif
#if defined(__ARM_LINUX__) || defined(unix) || defined(__unix__) || defined(__unix)
/* https://github.com/olikraus/u8g2/pull/1666 */
#define U8X8_USE_PINS

View File

@ -5,7 +5,8 @@
* Overall performance should be better.
* Run as non-root user.
* Thread safe and multiple display capable.
* For Java check out [Java U8g2](https://github.com/sgjava/java-u8g2) which uses arm-linux port.
* For Java check out [Java UIO U8g2](https://github.com/sgjava/javauio/tree/main/u8g2)
which uses arm-linux port.
## Non-root access
If you want to access devices without root do the following (you can try udev

View File

@ -158,7 +158,6 @@ void init_pin(u8x8_t *u8x8, uint8_t pin) {
fprintf(stderr, "gpio_open(): pin %d, %s\n", u8x8->pins[pin],
gpio_errmsg(user_data -> pins[pin]));
gpio_free(user_data->pins[pin]);
exit(error);
}
}
}
@ -173,7 +172,6 @@ void init_pin(u8x8_t *u8x8, uint8_t pin) {
fprintf(stderr, "gpio_open_sysfs(): pin %d, %s\n", u8x8->pins[pin],
gpio_errmsg(user_data->pins[pin]));
gpio_free(user_data->pins[pin]);
exit(error);
}
}
}
@ -205,7 +203,6 @@ void init_i2c(u8x8_t *u8x8) {
i2c_errmsg(i2c_handles[user_data->bus]));
i2c_free(i2c_handles[user_data->bus]);
i2c_handles[user_data->bus] = NULL;
exit(error);
}
}
}
@ -247,7 +244,6 @@ void init_spi(u8x8_t *u8x8) {
spi_errmsg(spi_handles[user_data->bus]));
spi_free(spi_handles[user_data->bus]);
spi_handles[user_data->bus] = NULL;
exit(error);
}
}
}

View File

@ -0,0 +1,124 @@
--- 模块功能u8g2demo
-- @module u8g2
-- @author Dozingfiretruck
-- @release 2021.01.25
--[[ 注意如需使用u8g2的全中文字库需将 luat_base.h中26行#define USE_U8G2_WQY12_T_GB2312 打开]]
-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "u8g2demo"
VERSION = "1.0.1"
log.info("main", PROJECT, VERSION)
-- sys库是标配
_G.sys = require("sys")
--[[
I2C0
I2C0_SCL (PA1)
I2C0_SDA (PA4)
]]
--添加硬狗防止程序卡死
wdt.init(15000)--初始化watchdog设置为15s
sys.timerLoopStart(wdt.feed, 10000)--10s喂一次狗
-- 日志TAG, 非必须
local TAG = "main"
-- 初始化显示屏
log.info(TAG, "init ssd1306")
-- u8g2.begin({ic ="ssd1306",mode="i2c_sw", pin0=1, pin1=4}) -- 通过PA1 SLK/PA4 SDA模拟, 也可以用硬件i2c脚
u8g2.begin({ic ="ssd1306", mode="i2c_hw", i2c_id=0, i2c_speed = i2c.FAST}) -- 硬件i2c
--u8g2.begin({ic ="st7567",mode="spi_hw_4pin",spi_id=1,spi_res=19,spi_dc=17,cs=20})
--u8g2.begin("ssd1306")
u8g2.SetFontMode(1)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm8)
u8g2.DrawUTF8("U8g2+LuatOS", 32, 22)
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("中文测试", 40, 38)
u8g2.SendBuffer()
-- 联网主流程
sys.taskInit(function()
sys.wait(2000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("屏幕宽度", 20, 24)
u8g2.DrawUTF8("屏幕高度", 20, 42)
u8g2.SetFont(u8g2.font_opposansm8)
u8g2.DrawUTF8(":"..u8g2.GetDisplayWidth(), 72, 24)
u8g2.DrawUTF8(":"..u8g2.GetDisplayHeight(), 72, 42)
u8g2.SendBuffer()
sys.wait(2000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("画线测试:", 30, 24)
for i = 0, 128, 8 do
u8g2.DrawLine(0,40,i,40)
u8g2.DrawLine(0,60,i,60)
u8g2.SendBuffer()
end
sys.wait(1000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("画圆测试:", 30, 24)
u8g2.DrawCircle(30,50,10,15)
u8g2.DrawDisc(90,50,10,15)
u8g2.SendBuffer()
sys.wait(1000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("椭圆测试:", 30, 24)
u8g2.DrawEllipse(30,50,6,10,15)
u8g2.DrawFilledEllipse(90,50,6,10,15)
u8g2.SendBuffer()
sys.wait(1000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("方框测试:", 30, 24)
u8g2.DrawBox(30,40,30,24)
u8g2.DrawFrame(90,40,30,24)
u8g2.SendBuffer()
sys.wait(1000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("圆角方框:", 30, 24)
u8g2.DrawRBox(30,40,30,24,8)
u8g2.DrawRFrame(90,40,30,24,8)
u8g2.SendBuffer()
sys.wait(1000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("符号测试:", 30, 24)
u8g2.DrawUTF8("显示雪人", 30, 38)
u8g2.SetFont(u8g2.font_unifont_t_symbols)
u8g2.DrawGlyph( 50, 60, 0x2603 )
u8g2.SendBuffer()
sys.wait(1000)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm12_chinese)
u8g2.DrawUTF8("三角测试:", 30, 24)
u8g2.DrawTriangle(30,60, 60,30, 90,60)
u8g2.SendBuffer()
sys.wait(3000)
u8g2.close()
while true do
sys.wait(1000)
end
end)
-- 主循环, 必须加
sys.run()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
#include "luat_base.h"
typedef struct luat_u8g2_conf
{
size_t pinType; // I2C_SW = 1, I2C_HW = 2, SPI_SW_3PIN = 3, SPI_SW_4PIN = 4, SPI_HW_4PIN=5, P8080 = 6
size_t w;
size_t h;
size_t pin0;
size_t pin1;
size_t pin2;
size_t pin3;
size_t pin4;
size_t pin5;
size_t pin6;
size_t pin7;
char* cname; // 控制器名称, 例如SSD1306
void* ptr;
} luat_u8g2_conf_t;
int luat_u8g2_setup(luat_u8g2_conf_t *conf);
int luat_u8g2_close(luat_u8g2_conf_t *conf);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,47 @@
#ifndef U8G2_LUAT_FONTS_H
#define U8G2_LUAT_FONTS_H
#include "u8x8.h"
/*==========================================*/
/* C++ compatible */
#ifdef __cplusplus
extern "C" {
#endif
/*==========================================*/
/*==========================================*/
/* start font list */
extern const uint8_t u8g2_font_opposansm8[] U8G2_FONT_SECTION("u8g2_font_opposansm8");
extern const uint8_t u8g2_font_opposansm10[] U8G2_FONT_SECTION("u8g2_font_opposansm10");
extern const uint8_t u8g2_font_opposansm12[] U8G2_FONT_SECTION("u8g2_font_opposansm12");
extern const uint8_t u8g2_font_opposansm16[] U8G2_FONT_SECTION("u8g2_font_opposansm16");
extern const uint8_t u8g2_font_opposansm18[] U8G2_FONT_SECTION("u8g2_font_opposansm18");
extern const uint8_t u8g2_font_opposansm20[] U8G2_FONT_SECTION("u8g2_font_opposansm20");
extern const uint8_t u8g2_font_opposansm22[] U8G2_FONT_SECTION("u8g2_font_opposansm22");
extern const uint8_t u8g2_font_opposansm24[] U8G2_FONT_SECTION("u8g2_font_opposansm24");
extern const uint8_t u8g2_font_opposansm32[] U8G2_FONT_SECTION("u8g2_font_opposansm32");
extern const uint8_t u8g2_font_opposansm12_chinese[] U8G2_FONT_SECTION("u8g2_font_opposansm12_chinese");
extern const uint8_t u8g2_font_opposansm16_chinese[] U8G2_FONT_SECTION("u8g2_font_opposansm16_chinese");
extern const uint8_t u8g2_font_opposansm24_chinese[] U8G2_FONT_SECTION("u8g2_font_opposansm24_chinese");
extern const uint8_t u8g2_font_opposansm32_chinese[] U8G2_FONT_SECTION("u8g2_font_opposansm32_chinese");
/* end font list */
/*==========================================*/
/* C++ compatible */
#ifdef __cplusplus
}
#endif
#endif