Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
0f1a1685
Commit
0f1a1685
authored
Aug 05, 2015
by
devsaurus
Browse files
add ucg module
parent
6dc0dfc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/modules/modules.h
View file @
0f1a1685
...
@@ -244,6 +244,7 @@
...
@@ -244,6 +244,7 @@
ROM_MODULES_COAP \
ROM_MODULES_COAP \
ROM_MODULES_MQTT \
ROM_MODULES_MQTT \
ROM_MODULES_U8G \
ROM_MODULES_U8G \
ROM_MODULES_UCG \
ROM_MODULES_I2C \
ROM_MODULES_I2C \
ROM_MODULES_SPI \
ROM_MODULES_SPI \
ROM_MODULES_TMR \
ROM_MODULES_TMR \
...
...
app/modules/ucg.c
0 → 100644
View file @
0f1a1685
// Module for Ucglib
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "ucg.h"
//#include "u8g_config.h"
typedef
struct
ucg_t
lucg_userdata_t
;
// helper function: retrieve and check userdata argument
static
lucg_userdata_t
*
get_lud
(
lua_State
*
L
)
{
lucg_userdata_t
*
lud
=
(
lucg_userdata_t
*
)
luaL_checkudata
(
L
,
1
,
"ucg.display"
);
luaL_argcheck
(
L
,
lud
,
1
,
"ucg.display expected"
);
return
lud
;
}
// helper function: retrieve given number of integer arguments
static
void
lucg_get_int_args
(
lua_State
*
L
,
uint8_t
stack
,
uint8_t
num
,
ucg_int_t
*
args
)
{
while
(
num
--
>
0
)
{
*
args
++
=
luaL_checkinteger
(
L
,
stack
++
);
}
}
// device destructor
static
int
lucg_close_display
(
lua_State
*
L
)
{
lucg_userdata_t
*
lud
;
if
((
lud
=
get_lud
(
L
))
==
NULL
)
return
0
;
return
0
;
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static
const
LUA_REG_TYPE
lucg_display_map
[]
=
{
#if 0
{ LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) },
{ LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) },
{ LSTRKEY( "drawBox" ), LFUNCVAL( lu8g_drawBox ) },
{ LSTRKEY( "drawCircle" ), LFUNCVAL( lu8g_drawCircle ) },
{ LSTRKEY( "drawDisc" ), LFUNCVAL( lu8g_drawDisc ) },
{ LSTRKEY( "drawEllipse" ), LFUNCVAL( lu8g_drawEllipse ) },
{ LSTRKEY( "drawFilledEllipse" ), LFUNCVAL( lu8g_drawFilledEllipse ) },
{ LSTRKEY( "drawFrame" ), LFUNCVAL( lu8g_drawFrame ) },
{ LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g_drawHLine ) },
{ LSTRKEY( "drawLine" ), LFUNCVAL( lu8g_drawLine ) },
{ LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g_drawPixel ) },
{ LSTRKEY( "drawRBox" ), LFUNCVAL( lu8g_drawRBox ) },
{ LSTRKEY( "drawRFrame" ), LFUNCVAL( lu8g_drawRFrame ) },
{ LSTRKEY( "drawStr" ), LFUNCVAL( lu8g_drawStr ) },
{ LSTRKEY( "drawStr90" ), LFUNCVAL( lu8g_drawStr90 ) },
{ LSTRKEY( "drawStr180" ), LFUNCVAL( lu8g_drawStr180 ) },
{ LSTRKEY( "drawStr270" ), LFUNCVAL( lu8g_drawStr270 ) },
{ LSTRKEY( "drawTriangle" ), LFUNCVAL( lu8g_drawTriangle ) },
{ LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g_drawVLine ) },
{ LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g_drawXBM ) },
{ LSTRKEY( "firstPage" ), LFUNCVAL( lu8g_firstPage ) },
{ LSTRKEY( "getColorIndex" ), LFUNCVAL( lu8g_getColorIndex ) },
{ LSTRKEY( "getFontAscent" ), LFUNCVAL( lu8g_getFontAscent ) },
{ LSTRKEY( "getFontDescent" ), LFUNCVAL( lu8g_getFontDescent ) },
{ LSTRKEY( "getFontLineSpacing" ), LFUNCVAL( lu8g_getFontLineSpacing ) },
{ LSTRKEY( "getHeight" ), LFUNCVAL( lu8g_getHeight ) },
{ LSTRKEY( "getMode" ), LFUNCVAL( lu8g_getMode ) },
{ LSTRKEY( "getStrWidth" ), LFUNCVAL( lu8g_getStrWidth ) },
{ LSTRKEY( "getWidth" ), LFUNCVAL( lu8g_getWidth ) },
{ LSTRKEY( "nextPage" ), LFUNCVAL( lu8g_nextPage ) },
{ LSTRKEY( "setColorIndex" ), LFUNCVAL( lu8g_setColorIndex ) },
{ LSTRKEY( "setDefaultBackgroundColor" ), LFUNCVAL( lu8g_setDefaultBackgroundColor ) },
{ LSTRKEY( "setDefaultForegroundColor" ), LFUNCVAL( lu8g_setDefaultForegroundColor ) },
{ LSTRKEY( "setFont" ), LFUNCVAL( lu8g_setFont ) },
{ LSTRKEY( "setFontLineSpacingFactor" ), LFUNCVAL( lu8g_setFontLineSpacingFactor ) },
{ LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lu8g_setFontPosBaseline ) },
{ LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lu8g_setFontPosBottom ) },
{ LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lu8g_setFontPosCenter ) },
{ LSTRKEY( "setFontPosTop" ), LFUNCVAL( lu8g_setFontPosTop ) },
{ LSTRKEY( "setFontRefHeightAll" ), LFUNCVAL( lu8g_setFontRefHeightAll ) },
{ LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g_setFontRefHeightExtendedText ) },
{ LSTRKEY( "setFontRefHeightText" ), LFUNCVAL( lu8g_setFontRefHeightText ) },
{ LSTRKEY( "setRot90" ), LFUNCVAL( lu8g_setRot90 ) },
{ LSTRKEY( "setRot180" ), LFUNCVAL( lu8g_setRot180 ) },
{ LSTRKEY( "setRot270" ), LFUNCVAL( lu8g_setRot270 ) },
{ LSTRKEY( "setScale2x2" ), LFUNCVAL( lu8g_setScale2x2 ) },
{ LSTRKEY( "sleepOff" ), LFUNCVAL( lu8g_sleepOff ) },
{ LSTRKEY( "sleepOn" ), LFUNCVAL( lu8g_sleepOn ) },
{ LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) },
{ LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) },
#endif
{
LSTRKEY
(
"__gc"
),
LFUNCVAL
(
lucg_close_display
)
},
#if LUA_OPTIMIZE_MEMORY > 0
{
LSTRKEY
(
"__index"
),
LROVAL
(
lucg_display_map
)
},
#endif
{
LNILKEY
,
LNILVAL
}
};
const
LUA_REG_TYPE
lucg_map
[]
=
{
#if 0
#undef U8G_DISPLAY_TABLE_ENTRY
#define U8G_DISPLAY_TABLE_ENTRY(device) { LSTRKEY( #device ), LFUNCVAL ( lu8g_ ##device ) },
U8G_DISPLAY_TABLE_I2C
U8G_DISPLAY_TABLE_SPI
#endif
#if LUA_OPTIMIZE_MEMORY > 0
// Register fonts
#if 0
#undef U8G_FONT_TABLE_ENTRY
#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
U8G_FONT_TABLE
#endif
#if 0
// Options for circle/ ellipse drawing
{ LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G_DRAW_UPPER_RIGHT ) },
{ LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G_DRAW_UPPER_LEFT ) },
{ LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G_DRAW_LOWER_RIGHT ) },
{ LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G_DRAW_LOWER_LEFT ) },
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G_DRAW_ALL ) },
// Display modes
{ LSTRKEY( "MODE_BW" ), LNUMVAL( U8G_MODE_BW ) },
{ LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) },
#endif
{
LSTRKEY
(
"__metatable"
),
LROVAL
(
lucg_map
)
},
#endif
{
LNILKEY
,
LNILVAL
}
};
LUALIB_API
int
luaopen_ucg
(
lua_State
*
L
)
{
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable
(
L
,
"ucg.display"
,
(
void
*
)
lucg_display_map
);
// create metatable
return
0
;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int
n
;
luaL_register
(
L
,
AUXLIB_UCG
,
lucg_map
);
// Set it as its own metatable
lua_pushvalue
(
L
,
-
1
);
lua_setmetatable
(
L
,
-
2
);
// Module constants
// Register fonts
#if 0
#undef U8G_FONT_TABLE_ENTRY
#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) );
U8G_FONT_TABLE
#endif
#if 0
// Options for circle/ ellipse drawing
MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", U8G_DRAW_UPPER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", U8G_DRAW_UPPER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", U8G_DRAW_UPPER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", U8G_DRAW_UPPER_RIGHT );
// Display modes
MOD_REG_NUMBER( L, "MODE_BW", U8G_MODE_BW );
MOD_REG_NUMBER( L, "MODE_GRAY2BIT", U8G_MODE_BW );
#endif
// create metatable
luaL_newmetatable
(
L
,
"ucg.display"
);
// metatable.__index = metatable
lua_pushliteral
(
L
,
"__index"
);
lua_pushvalue
(
L
,
-
2
);
lua_rawset
(
L
,
-
3
);
// Setup the methods inside metatable
luaL_register
(
L
,
NULL
,
ucg_display_map
);
return
1
;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
app/ucglib/ucg.h
View file @
0f1a1685
...
@@ -81,7 +81,11 @@
...
@@ -81,7 +81,11 @@
#ifndef _UCG_H
#ifndef _UCG_H
#define _UCG_H
#define _UCG_H
#include <stdint.h>
#if defined(__XTENSA__)
# include <c_types.h>
#else
# include <stdint.h>
#endif
#include <stddef.h>
#include <stddef.h>
...
@@ -90,7 +94,7 @@ extern "C"
...
@@ -90,7 +94,7 @@ extern "C"
{
{
#endif
#endif
#if defined(ARDUINO)
#if defined(ARDUINO)
|| defined(__XTENSA__)
#ifndef USE_PIN_LIST
#ifndef USE_PIN_LIST
#define USE_PIN_LIST
#define USE_PIN_LIST
#endif
#endif
...
@@ -104,6 +108,8 @@ extern "C"
...
@@ -104,6 +108,8 @@ extern "C"
# define UCG_FONT_SECTION(name)
# define UCG_FONT_SECTION(name)
# elif defined(__AVR__)
# elif defined(__AVR__)
# define UCG_FONT_SECTION(name) UCG_SECTION(".progmem." name)
# define UCG_FONT_SECTION(name) UCG_SECTION(".progmem." name)
# elif defined(__XTENSA__)
# define UCG_FONT_SECTION(name)
# else
# else
# define UCG_FONT_SECTION(name)
# define UCG_FONT_SECTION(name)
# endif
# endif
...
@@ -121,6 +127,13 @@ typedef uint8_t PROGMEM ucg_pgm_uint8_t;
...
@@ -121,6 +127,13 @@ typedef uint8_t PROGMEM ucg_pgm_uint8_t;
typedef
uint8_t
ucg_fntpgm_uint8_t
;
typedef
uint8_t
ucg_fntpgm_uint8_t
;
#define ucg_pgm_read(adr) pgm_read_byte_near(adr)
#define ucg_pgm_read(adr) pgm_read_byte_near(adr)
#define UCG_PSTR(s) ((ucg_pgm_uint8_t *)PSTR(s))
#define UCG_PSTR(s) ((ucg_pgm_uint8_t *)PSTR(s))
#elif defined(__XTENSA__)
#define UCG_PROGMEM
#define PROGMEM
typedef
uint8_t
ucg_pgm_uint8_t
;
typedef
uint8_t
ucg_fntpgm_uint8_t
;
#define ucg_pgm_read(adr) (*(const ucg_pgm_uint8_t *)(adr))
#define UCG_PSTR(s) ((ucg_pgm_uint8_t *)(s))
#else
#else
#define UCG_PROGMEM
#define UCG_PROGMEM
#define PROGMEM
#define PROGMEM
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment