From a287020096393dea6f88b4e2c90b3eeb243a3aad Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 18 Feb 2015 23:57:34 +0100 Subject: [PATCH 01/18] implement drawXBM --- app/modules/u8g.c | 21 ++++++++++++ lua_examples/u8g_bitmaps.lua | 62 +++++++++++++++++++++++++++++++++++ lua_examples/u8glib_logo.xbm | Bin 0 -> 120 bytes 3 files changed, 83 insertions(+) create mode 100644 lua_examples/u8g_bitmaps.lua create mode 100644 lua_examples/u8glib_logo.xbm diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 9876616f..e91b4f5b 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -576,6 +576,26 @@ static int lu8g_drawVLine( lua_State *L ) return 0; } +// Lua: u8g.drawXBM( self, x, y, width, height, data ) +static int lu8g_drawXBM( lua_State *L ) +{ + lu8g_userdata_t *lud; + + if ((lud = get_lud( L )) == NULL) + return 0; + + u8g_uint_t args[4]; + lu8g_get_int_args( L, 2, 4, args ); + + const char *xbm_data = luaL_checkstring( L, (1+4) + 1 ); + if (xbm_data == NULL) + return 0; + + u8g_DrawXBM( lud, args[0], args[1], args[2], args[3], (const uint8_t *)xbm_data ); + + return 0; +} + // Lua: u8g.setScale2x2( self ) static int lu8g_setScale2x2( lua_State *L ) { @@ -931,6 +951,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g_drawPixel ) }, { LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g_drawHLine ) }, { LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g_drawVLine ) }, + { LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g_drawXBM ) }, { LSTRKEY( "setScale2x2" ), LFUNCVAL( lu8g_setScale2x2 ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) }, { LSTRKEY( "firstPage" ), LFUNCVAL( lu8g_firstPage ) }, diff --git a/lua_examples/u8g_bitmaps.lua b/lua_examples/u8g_bitmaps.lua new file mode 100644 index 00000000..43f49d8c --- /dev/null +++ b/lua_examples/u8g_bitmaps.lua @@ -0,0 +1,62 @@ + +-- setup I2c and connect display +function init_i2c_display() + sda = 5 + scl = 6 + sla = 0x3c + i2c.setup(0, sda, scl, i2c.SLOW) + disp = u8g.ssd1306_128x64_i2c(sla) +end + +function xbm_picture() + disp:setFont(u8g.font_6x10) + disp:drawStr( 0, 10, "XBM picture") + + disp:drawXBM( 0, 20, 38, 24, xbm_data ) +end + +function bitmap_picture() + disp:setFont(u8g.font_6x10) + disp:drawStr( 0, 10, "Bitmap picture") + + --disp:drawXBM( 0, 20, 38, 24, bitmap_data ) +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 + + +function bitmap_test() + init_i2c_display() + + -- read XBM picture + file.open("u8glib_logo.xbm", "r") + xbm_data = file.read() + file.close() + + print("--- Starting Bitmap Test ---") + dir = 0 + next_rotation = 0 + + local draw_state + for draw_state = 1, 7 + 0*8, 1 do + disp:firstPage() + repeat + draw(draw_state) + until disp:nextPage() == false + + tmr.wdclr() + end + + print("--- Bitmap Test done ---") +end + +bitmap_test() diff --git a/lua_examples/u8glib_logo.xbm b/lua_examples/u8glib_logo.xbm new file mode 100644 index 0000000000000000000000000000000000000000..876c4b7ca11b4f3da9e39271fc9facbf40c5491d GIT binary patch literal 120 zcmezW|Nnn`ApURv-~o_${18Zd{s<=i?Kl4{C?jw1nUSMM;WHz{0n5*g#}8V5K6w13 z#pi>EC2byeGS09+F2TTI$8S?0V_^UPPrKp&|ND Date: Thu, 19 Feb 2015 12:12:14 +0100 Subject: [PATCH 02/18] implement drawBitmap --- README.md | 6 +++--- app/modules/u8g.c | 21 +++++++++++++++++++++ lua_examples/u8g_bitmaps.lua | 11 ++++++++--- lua_examples/u8g_rook.bm | Bin 0 -> 8 bytes 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 lua_examples/u8g_rook.bm diff --git a/README.md b/README.md index f4cf9c85..42712dc1 100644 --- a/README.md +++ b/README.md @@ -368,9 +368,9 @@ They'll be available as `u8g.` in Lua. - [ ] setCursorFont() - [ ] setCursorPos() - [ ] setCursorStyle() -- [ ] Bitmaps - - [ ] drawBitmap() - - [ ] drawXBM() +- [x] Bitmaps + - [x] drawBitmap() + - [x] drawXBM() - [ ] General functions - [x] begin() - [ ] print() diff --git a/app/modules/u8g.c b/app/modules/u8g.c index e91b4f5b..316ccddd 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -596,6 +596,26 @@ static int lu8g_drawXBM( lua_State *L ) return 0; } +// Lua: u8g.drawBitmap( self, x, y, count, height, data ) +static int lu8g_drawBitmap( lua_State *L ) +{ + lu8g_userdata_t *lud; + + if ((lud = get_lud( L )) == NULL) + return 0; + + u8g_uint_t args[4]; + lu8g_get_int_args( L, 2, 4, args ); + + const char *bm_data = luaL_checkstring( L, (1+4) + 1 ); + if (bm_data == NULL) + return 0; + + u8g_DrawBitmap( lud, args[0], args[1], args[2], args[3], (const uint8_t *)bm_data ); + + return 0; +} + // Lua: u8g.setScale2x2( self ) static int lu8g_setScale2x2( lua_State *L ) { @@ -951,6 +971,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g_drawPixel ) }, { LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g_drawHLine ) }, { LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g_drawVLine ) }, + { LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) }, { LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g_drawXBM ) }, { LSTRKEY( "setScale2x2" ), LFUNCVAL( lu8g_setScale2x2 ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) }, diff --git a/lua_examples/u8g_bitmaps.lua b/lua_examples/u8g_bitmaps.lua index 43f49d8c..0a8ac8e7 100644 --- a/lua_examples/u8g_bitmaps.lua +++ b/lua_examples/u8g_bitmaps.lua @@ -15,11 +15,11 @@ function xbm_picture() disp:drawXBM( 0, 20, 38, 24, xbm_data ) end -function bitmap_picture() +function bitmap_picture(state) disp:setFont(u8g.font_6x10) disp:drawStr( 0, 10, "Bitmap picture") - --disp:drawXBM( 0, 20, 38, 24, bitmap_data ) + disp:drawBitmap( 0 + (state * 10), 20 + (state * 4), 1, 8, bm_data ) end -- the draw() routine @@ -42,12 +42,17 @@ function bitmap_test() xbm_data = file.read() file.close() + -- read Bitmap picture + file.open("u8g_rook.bm", "r") + bm_data = file.read() + file.close() + print("--- Starting Bitmap Test ---") dir = 0 next_rotation = 0 local draw_state - for draw_state = 1, 7 + 0*8, 1 do + for draw_state = 1, 7 + 1*8, 1 do disp:firstPage() repeat draw(draw_state) diff --git a/lua_examples/u8g_rook.bm b/lua_examples/u8g_rook.bm new file mode 100644 index 0000000000000000000000000000000000000000..9dd93966f264609e124d1438e97c63b29a56c805 GIT binary patch literal 8 NcmZPwt+xY$dH@MH0!#n^ literal 0 HcmV?d00001 From 81be529d68dad4cf576b4307e4e2ced74537e81d Mon Sep 17 00:00:00 2001 From: devsaurus Date: Thu, 19 Feb 2015 16:47:41 +0100 Subject: [PATCH 03/18] preparation for adding more display devices: allocate and construct page buffer dynamically to save heap for unused device types --- app/modules/u8g.c | 157 ++++++++++++++++++++++++++++++---------------- 1 file changed, 104 insertions(+), 53 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 316ccddd..caf487bc 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -8,11 +8,21 @@ #include "lrotable.h" //#include "c_string.h" -//#include "c_stdlib.h" +#include "c_stdlib.h" #include "u8g.h" -typedef u8g_t lu8g_userdata_t; +struct _lu8g_userdata_t +{ + u8g_t u8g; + u8g_pb_t pb; + u8g_dev_t dev; +}; + +typedef struct _lu8g_userdata_t lu8g_userdata_t; + +// shorthand macro for the u8g structure inside the userdata +#define LU8G (&(lud->u8g)) // Font look-up array @@ -79,7 +89,7 @@ static int lu8g_begin( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_Begin( lud ); + u8g_Begin( LU8G ); return 0; } @@ -94,7 +104,7 @@ static int lu8g_setFont( lua_State *L ) lua_Integer fontnr = luaL_checkinteger( L, 2 ); if ((fontnr >= 0) && (fontnr < (sizeof( font_array ) / sizeof( u8g_fntpgm_uint8_t )))) - u8g_SetFont( lud, font_array[fontnr] ); + u8g_SetFont( LU8G, font_array[fontnr] ); return 0; } @@ -107,7 +117,7 @@ static int lu8g_setFontRefHeightAll( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontRefHeightAll( lud ); + u8g_SetFontRefHeightAll( LU8G ); return 0; } @@ -120,7 +130,7 @@ static int lu8g_setFontRefHeightExtendedText( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontRefHeightExtendedText( lud ); + u8g_SetFontRefHeightExtendedText( LU8G ); return 0; } @@ -133,7 +143,7 @@ static int lu8g_setFontRefHeightText( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontRefHeightText( lud ); + u8g_SetFontRefHeightText( LU8G ); return 0; } @@ -146,7 +156,7 @@ static int lu8g_setDefaultBackgroundColor( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetDefaultBackgroundColor( lud ); + u8g_SetDefaultBackgroundColor( LU8G ); return 0; } @@ -159,7 +169,7 @@ static int lu8g_setDefaultForegroundColor( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetDefaultForegroundColor( lud ); + u8g_SetDefaultForegroundColor( LU8G ); return 0; } @@ -172,7 +182,7 @@ static int lu8g_setFontPosBaseline( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontPosBaseline( lud ); + u8g_SetFontPosBaseline( LU8G ); return 0; } @@ -185,7 +195,7 @@ static int lu8g_setFontPosBottom( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontPosBottom( lud ); + u8g_SetFontPosBottom( LU8G ); return 0; } @@ -198,7 +208,7 @@ static int lu8g_setFontPosCenter( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontPosCenter( lud ); + u8g_SetFontPosCenter( LU8G ); return 0; } @@ -211,7 +221,7 @@ static int lu8g_setFontPosTop( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetFontPosTop( lud ); + u8g_SetFontPosTop( LU8G ); return 0; } @@ -224,7 +234,7 @@ static int lu8g_getFontAscent( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetFontAscent( lud ) ); + lua_pushinteger( L, u8g_GetFontAscent( LU8G ) ); return 1; } @@ -237,7 +247,7 @@ static int lu8g_getFontDescent( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetFontDescent( lud ) ); + lua_pushinteger( L, u8g_GetFontDescent( LU8G ) ); return 1; } @@ -250,7 +260,7 @@ static int lu8g_getFontLineSpacing( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetFontLineSpacing( lud ) ); + lua_pushinteger( L, u8g_GetFontLineSpacing( LU8G ) ); return 1; } @@ -263,7 +273,7 @@ static int lu8g_getMode( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetMode( lud ) ); + lua_pushinteger( L, u8g_GetMode( LU8G ) ); return 1; } @@ -276,7 +286,7 @@ static int lu8g_setColorIndex( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetColorIndex( lud, luaL_checkinteger( L, 2 ) ); + u8g_SetColorIndex( LU8G, luaL_checkinteger( L, 2 ) ); return 0; } @@ -289,7 +299,7 @@ static int lu8g_getColorIndex( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetColorIndex( lud ) ); + lua_pushinteger( L, u8g_GetColorIndex( LU8G ) ); return 1; } @@ -311,16 +321,16 @@ static int lu8g_generic_drawStr( lua_State *L, uint8_t rot ) switch (rot) { case 1: - lua_pushinteger( L, u8g_DrawStr90( lud, args[0], args[1], s ) ); + lua_pushinteger( L, u8g_DrawStr90( LU8G, args[0], args[1], s ) ); break; case 2: - lua_pushinteger( L, u8g_DrawStr180( lud, args[0], args[1], s ) ); + lua_pushinteger( L, u8g_DrawStr180( LU8G, args[0], args[1], s ) ); break; case 3: - lua_pushinteger( L, u8g_DrawStr270( lud, args[0], args[1], s ) ); + lua_pushinteger( L, u8g_DrawStr270( LU8G, args[0], args[1], s ) ); break; default: - lua_pushinteger( L, u8g_DrawStr( lud, args[0], args[1], s ) ); + lua_pushinteger( L, u8g_DrawStr( LU8G, args[0], args[1], s ) ); break; } @@ -371,7 +381,7 @@ static int lu8g_drawLine( lua_State *L ) u8g_uint_t args[4]; lu8g_get_int_args( L, 2, 4, args ); - u8g_DrawLine( lud, args[0], args[1], args[2], args[3] ); + u8g_DrawLine( LU8G, args[0], args[1], args[2], args[3] ); return 0; } @@ -387,7 +397,7 @@ static int lu8g_drawTriangle( lua_State *L ) u8g_uint_t args[6]; lu8g_get_int_args( L, 2, 6, args ); - u8g_DrawTriangle( lud, args[0], args[1], args[2], args[3], args[4], args[5] ); + u8g_DrawTriangle( LU8G, args[0], args[1], args[2], args[3], args[4], args[5] ); return 0; } @@ -403,7 +413,7 @@ static int lu8g_drawBox( lua_State *L ) u8g_uint_t args[4]; lu8g_get_int_args( L, 2, 4, args ); - u8g_DrawBox( lud, args[0], args[1], args[2], args[3] ); + u8g_DrawBox( LU8G, args[0], args[1], args[2], args[3] ); return 0; } @@ -419,7 +429,7 @@ static int lu8g_drawRBox( lua_State *L ) u8g_uint_t args[5]; lu8g_get_int_args( L, 2, 5, args ); - u8g_DrawRBox( lud, args[0], args[1], args[2], args[3], args[4] ); + u8g_DrawRBox( LU8G, args[0], args[1], args[2], args[3], args[4] ); return 0; } @@ -435,7 +445,7 @@ static int lu8g_drawFrame( lua_State *L ) u8g_uint_t args[4]; lu8g_get_int_args( L, 2, 4, args ); - u8g_DrawFrame( lud, args[0], args[1], args[2], args[3] ); + u8g_DrawFrame( LU8G, args[0], args[1], args[2], args[3] ); return 0; } @@ -451,7 +461,7 @@ static int lu8g_drawRFrame( lua_State *L ) u8g_uint_t args[5]; lu8g_get_int_args( L, 2, 5, args ); - u8g_DrawRFrame( lud, args[0], args[1], args[2], args[3], args[4] ); + u8g_DrawRFrame( LU8G, args[0], args[1], args[2], args[3], args[4] ); return 0; } @@ -469,7 +479,7 @@ static int lu8g_drawDisc( lua_State *L ) u8g_uint_t opt = luaL_optinteger( L, (1+3) + 1, U8G_DRAW_ALL ); - u8g_DrawDisc( lud, args[0], args[1], args[2], opt ); + u8g_DrawDisc( LU8G, args[0], args[1], args[2], opt ); return 0; } @@ -487,7 +497,7 @@ static int lu8g_drawCircle( lua_State *L ) u8g_uint_t opt = luaL_optinteger( L, (1+3) + 1, U8G_DRAW_ALL ); - u8g_DrawCircle( lud, args[0], args[1], args[2], opt ); + u8g_DrawCircle( LU8G, args[0], args[1], args[2], opt ); return 0; } @@ -505,7 +515,7 @@ static int lu8g_drawEllipse( lua_State *L ) u8g_uint_t opt = luaL_optinteger( L, (1+4) + 1, U8G_DRAW_ALL ); - u8g_DrawEllipse( lud, args[0], args[1], args[2], args[3], opt ); + u8g_DrawEllipse( LU8G, args[0], args[1], args[2], args[3], opt ); return 0; } @@ -523,7 +533,7 @@ static int lu8g_drawFilledEllipse( lua_State *L ) u8g_uint_t opt = luaL_optinteger( L, (1+4) + 1, U8G_DRAW_ALL ); - u8g_DrawFilledEllipse( lud, args[0], args[1], args[2], args[3], opt ); + u8g_DrawFilledEllipse( LU8G, args[0], args[1], args[2], args[3], opt ); return 0; } @@ -539,7 +549,7 @@ static int lu8g_drawPixel( lua_State *L ) u8g_uint_t args[2]; lu8g_get_int_args( L, 2, 2, args ); - u8g_DrawPixel( lud, args[0], args[1] ); + u8g_DrawPixel( LU8G, args[0], args[1] ); return 0; } @@ -555,7 +565,7 @@ static int lu8g_drawHLine( lua_State *L ) u8g_uint_t args[3]; lu8g_get_int_args( L, 2, 3, args ); - u8g_DrawHLine( lud, args[0], args[1], args[2] ); + u8g_DrawHLine( LU8G, args[0], args[1], args[2] ); return 0; } @@ -571,7 +581,7 @@ static int lu8g_drawVLine( lua_State *L ) u8g_uint_t args[3]; lu8g_get_int_args( L, 2, 3, args ); - u8g_DrawVLine( lud, args[0], args[1], args[2] ); + u8g_DrawVLine( LU8G, args[0], args[1], args[2] ); return 0; } @@ -591,7 +601,7 @@ static int lu8g_drawXBM( lua_State *L ) if (xbm_data == NULL) return 0; - u8g_DrawXBM( lud, args[0], args[1], args[2], args[3], (const uint8_t *)xbm_data ); + u8g_DrawXBM( LU8G, args[0], args[1], args[2], args[3], (const uint8_t *)xbm_data ); return 0; } @@ -611,7 +621,7 @@ static int lu8g_drawBitmap( lua_State *L ) if (bm_data == NULL) return 0; - u8g_DrawBitmap( lud, args[0], args[1], args[2], args[3], (const uint8_t *)bm_data ); + u8g_DrawBitmap( LU8G, args[0], args[1], args[2], args[3], (const uint8_t *)bm_data ); return 0; } @@ -624,7 +634,7 @@ static int lu8g_setScale2x2( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetScale2x2( lud ); + u8g_SetScale2x2( LU8G ); return 0; } @@ -637,7 +647,7 @@ static int lu8g_undoScale( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_UndoScale( lud ); + u8g_UndoScale( LU8G ); return 0; } @@ -650,7 +660,7 @@ static int lu8g_firstPage( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_FirstPage( lud ); + u8g_FirstPage( LU8G ); return 0; } @@ -663,7 +673,7 @@ static int lu8g_nextPage( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushboolean( L, u8g_NextPage( lud ) ); + lua_pushboolean( L, u8g_NextPage( LU8G ) ); return 1; } @@ -676,7 +686,7 @@ static int lu8g_sleepOn( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SleepOn( lud ); + u8g_SleepOn( LU8G ); return 0; } @@ -689,7 +699,7 @@ static int lu8g_sleepOff( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SleepOff( lud ); + u8g_SleepOff( LU8G ); return 0; } @@ -702,7 +712,7 @@ static int lu8g_setRot90( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetRot90( lud ); + u8g_SetRot90( LU8G ); return 0; } @@ -715,7 +725,7 @@ static int lu8g_setRot180( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetRot180( lud ); + u8g_SetRot180( LU8G ); return 0; } @@ -728,7 +738,7 @@ static int lu8g_setRot270( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_SetRot270( lud ); + u8g_SetRot270( LU8G ); return 0; } @@ -741,7 +751,7 @@ static int lu8g_undoRotation( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - u8g_UndoRotation( lud ); + u8g_UndoRotation( LU8G ); return 0; } @@ -754,7 +764,7 @@ static int lu8g_getWidth( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetWidth( lud ) ); + lua_pushinteger( L, u8g_GetWidth( LU8G ) ); return 1; } @@ -767,7 +777,7 @@ static int lu8g_getHeight( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_pushinteger( L, u8g_GetHeight( lud ) ); + lua_pushinteger( L, u8g_GetHeight( LU8G ) ); return 1; } @@ -906,9 +916,26 @@ uint8_t u8g_com_esp8266_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi +// device destructor +static int lu8g_close_display( lua_State *L ) +{ + lu8g_userdata_t *lud; + + if ((lud = get_lud( L )) == NULL) + return 0; + + // free up allocated page buffer + if (lud->pb.buf != NULL) + c_free( lud->pb.buf ); + + return 0; +} + + // device constructors -// Lua: speed = u8g.ssd1306_128x64_i2c( i2c_addr ) +uint8_t u8g_dev_ssd1306_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); +// Lua: object = u8g.ssd1306_128x64_i2c( i2c_addr ) static int lu8g_ssd1306_128x64_i2c( lua_State *L ) { unsigned addr = luaL_checkinteger( L, 1 ); @@ -918,9 +945,32 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) lu8g_userdata_t *lud = (lu8g_userdata_t *) lua_newuserdata( L, sizeof( lu8g_userdata_t ) ); - lud->i2c_addr = (uint8_t)addr; + lud->u8g.i2c_addr = (uint8_t)addr; - u8g_InitI2C( lud, &u8g_dev_ssd1306_128x64_i2c, U8G_I2C_OPT_NONE); + // We don't use the pre-defined device structure for u8g_dev_ssd1306_128x64_i2c here + // Reason: linking the pre-defined structures allocates RAM for the device/comm structure + // *before* the display is constructed (especially the page buffers) + // this consumes heap even when the device is not used at all +#if 1 + // build device entry + lud->dev.dev_fn = u8g_dev_ssd1306_128x64_fn; + lud->dev.dev_mem = &(lud->pb); + lud->dev.com_fn = u8g_com_esp8266_ssd_i2c_fn; + // then allocate and populate page buffer + lud->pb.width = 128; // WIDTH in u8g_dev_ssd1306_128x64.c + if ((lud->pb.buf = (void *)c_zalloc(lud->pb.width)) == NULL) + return luaL_error( L, "out of memory" ); + + lud->pb.p.page_height = 8; // PAGE_HEIGHT in u8g_dev_ssd1306_128x64.c + lud->pb.p.total_height = 64; // HEIGHT in u8g_dev_ssd1306_128x64.c + lud->pb.p.page_y0 = 0; + lud->pb.p.page_y1 = 0; + lud->pb.p.page = 0; + + u8g_InitI2C( LU8G, &(lud->dev), U8G_I2C_OPT_NONE); +#else + u8g_InitI2C( LU8G, u8g_dev_ssd1306_128x64_i2c, U8G_I2C_OPT_NONE); +#endif // set its metatable @@ -985,6 +1035,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) }, { LSTRKEY( "getWidth" ), LFUNCVAL( lu8g_getWidth ) }, { LSTRKEY( "getHeight" ), LFUNCVAL( lu8g_getHeight ) }, + { LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( lu8g_display_map ) }, #endif From 6c0adbf980a14cd3c6002c92b86f8a2107100bf4 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Fri, 20 Feb 2015 11:07:52 +0100 Subject: [PATCH 04/18] SPI comm function, untested --- app/modules/u8g.c | 80 +++++++++++++++++++++++++++++++++++++++++++++-- app/u8glib/u8g.h | 5 +++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index caf487bc..b1e3f0a8 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -826,6 +826,83 @@ static uint8_t u8g_com_esp8266_ssd_start_sequence(u8g_t *u8g) } +static void lu8g_digital_write( u8g_t *u8g, uint8_t pin_index, uint8_t value ) +{ + uint8_t pin; + + pin = u8g->pin_list[pin_index]; + if ( pin != U8G_PIN_NONE ) + platform_gpio_write( pin, value ); +} + +uint8_t u8g_com_esp8266_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) +{ + switch(msg) + { + case U8G_COM_MSG_STOP: + break; + + case U8G_COM_MSG_INIT: + // we assume that the SPI interface was already initialized + // just care for the /CS and D/C pins + lu8g_digital_write( u8g, U8G_PI_CS, PLATFORM_GPIO_HIGH ); + platform_gpio_mode( u8g->pin_list[U8G_PI_CS], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); + platform_gpio_mode( u8g->pin_list[U8G_PI_A0], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); + break; + + case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ + lu8g_digital_write( u8g, U8G_PI_A0, arg_val == 0 ? PLATFORM_GPIO_LOW : PLATFORM_GPIO_HIGH ); + break; + + case U8G_COM_MSG_CHIP_SELECT: + if (arg_val == 0) + { + /* disable */ + lu8g_digital_write( u8g, U8G_PI_CS, PLATFORM_GPIO_HIGH ); + } + else + { + /* enable */ + //u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); + lu8g_digital_write( u8g, U8G_PI_CS, PLATFORM_GPIO_LOW ); + } + break; + + case U8G_COM_MSG_RESET: + if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) + lu8g_digital_write( u8g, U8G_PI_RESET, arg_val == 0 ? PLATFORM_GPIO_LOW : PLATFORM_GPIO_HIGH ); + break; + + case U8G_COM_MSG_WRITE_BYTE: + platform_spi_send_recv( 1, arg_val ); + break; + + case U8G_COM_MSG_WRITE_SEQ: + { + register uint8_t *ptr = arg_ptr; + while( arg_val > 0 ) + { + platform_spi_send_recv( 1, *ptr++ ); + arg_val--; + } + } + break; + case U8G_COM_MSG_WRITE_SEQ_P: + { + register uint8_t *ptr = arg_ptr; + while( arg_val > 0 ) + { + platform_spi_send_recv( 1, u8g_pgm_read(ptr) ); + ptr++; + arg_val--; + } + } + break; + } + return 1; +} + + uint8_t u8g_com_esp8266_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { switch(msg) @@ -915,7 +992,6 @@ uint8_t u8g_com_esp8266_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi - // device destructor static int lu8g_close_display( lua_State *L ) { @@ -955,7 +1031,7 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) // build device entry lud->dev.dev_fn = u8g_dev_ssd1306_128x64_fn; lud->dev.dev_mem = &(lud->pb); - lud->dev.com_fn = u8g_com_esp8266_ssd_i2c_fn; + lud->dev.com_fn = U8G_COM_SSD_I2C; // then allocate and populate page buffer lud->pb.width = 128; // WIDTH in u8g_dev_ssd1306_128x64.c if ((lud->pb.buf = (void *)c_zalloc(lud->pb.width)) == NULL) diff --git a/app/u8glib/u8g.h b/app/u8glib/u8g.h index 3c590df3..7aa2845a 100644 --- a/app/u8glib/u8g.h +++ b/app/u8glib/u8g.h @@ -654,6 +654,7 @@ uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, v uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_no_en_parallel.c */ uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_ssd_i2c.c */ uint8_t u8g_com_esp8266_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g.c */ +uint8_t u8g_com_esp8266_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g.c */ uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); uint8_t u8g_com_arduino_t6963_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_t6963.c */ @@ -723,6 +724,10 @@ defined(__18CXX) || defined(__PIC32MX) #define U8G_COM_HW_SPI u8g_com_atmega_hw_spi_fn #define U8G_COM_ST7920_HW_SPI u8g_com_atmega_st7920_hw_spi_fn #endif +#if defined(__XTENSA__) +#define U8G_COM_HW_SPI u8g_com_esp8266_hw_spi_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#endif #endif #ifndef U8G_COM_HW_SPI #define U8G_COM_HW_SPI u8g_com_null_fn From e3ed4fc0da6b0da74476575b4576750309326370 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Fri, 20 Feb 2015 18:24:53 +0100 Subject: [PATCH 05/18] fix typo --- app/modules/u8g.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index b1e3f0a8..44fb2232 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1045,7 +1045,7 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) u8g_InitI2C( LU8G, &(lud->dev), U8G_I2C_OPT_NONE); #else - u8g_InitI2C( LU8G, u8g_dev_ssd1306_128x64_i2c, U8G_I2C_OPT_NONE); + u8g_InitI2C( LU8G, &u8g_dev_ssd1306_128x64_i2c, U8G_I2C_OPT_NONE); #endif From 2cfb86b5b53e68526c557309a31674312391b51c Mon Sep 17 00:00:00 2001 From: devsaurus Date: Fri, 20 Feb 2015 21:15:38 +0100 Subject: [PATCH 06/18] improve device and page buffer initialization --- app/modules/u8g.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 44fb2232..c5dfccd6 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1029,20 +1029,20 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) // this consumes heap even when the device is not used at all #if 1 // build device entry - lud->dev.dev_fn = u8g_dev_ssd1306_128x64_fn; - lud->dev.dev_mem = &(lud->pb); - lud->dev.com_fn = U8G_COM_SSD_I2C; - // then allocate and populate page buffer - lud->pb.width = 128; // WIDTH in u8g_dev_ssd1306_128x64.c + lud->dev = (u8g_dev_t){ u8g_dev_ssd1306_128x64_fn, &(lud->pb), U8G_COM_SSD_I2C }; + + // populate and allocate page buffer + // constants taken from u8g_dev_ssd1306_128x64.c: + // PAGE_HEIGHT + // | Height + // | | WIDTH + // | | | + lud->pb = (u8g_pb_t){ { 8, 64, 0, 0, 0 }, 128, NULL }; + // if ((lud->pb.buf = (void *)c_zalloc(lud->pb.width)) == NULL) return luaL_error( L, "out of memory" ); - lud->pb.p.page_height = 8; // PAGE_HEIGHT in u8g_dev_ssd1306_128x64.c - lud->pb.p.total_height = 64; // HEIGHT in u8g_dev_ssd1306_128x64.c - lud->pb.p.page_y0 = 0; - lud->pb.p.page_y1 = 0; - lud->pb.p.page = 0; - + // and finally init device using specific interface init function u8g_InitI2C( LU8G, &(lud->dev), U8G_I2C_OPT_NONE); #else u8g_InitI2C( LU8G, &u8g_dev_ssd1306_128x64_i2c, U8G_I2C_OPT_NONE); From 7ae293d5664dfef4cfdaaa641beec38dda9bd547 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 25 Feb 2015 23:17:08 +0100 Subject: [PATCH 07/18] set free'd pointer to NULL --- app/modules/u8g.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index c5dfccd6..0fb26fd3 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1002,7 +1002,10 @@ static int lu8g_close_display( lua_State *L ) // free up allocated page buffer if (lud->pb.buf != NULL) + { c_free( lud->pb.buf ); + lud->pb.buf = NULL; + } return 0; } @@ -1033,10 +1036,10 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) // populate and allocate page buffer // constants taken from u8g_dev_ssd1306_128x64.c: - // PAGE_HEIGHT - // | Height - // | | WIDTH - // | | | + // PAGE_HEIGHT + // | Height + // | | WIDTH + // | | | lud->pb = (u8g_pb_t){ { 8, 64, 0, 0, 0 }, 128, NULL }; // if ((lud->pb.buf = (void *)c_zalloc(lud->pb.width)) == NULL) From 32774d428cabdbd54ae47dea551b1eb5080a1c57 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Sun, 1 Mar 2015 23:11:24 +0100 Subject: [PATCH 08/18] handle font data as light userdata --- app/lua/lrodefs.h | 1 + app/lua/lrotable.h | 3 +++ app/modules/auxmods.h | 4 ++++ app/modules/u8g.c | 24 ++++++++++++------------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/lua/lrodefs.h b/app/lua/lrodefs.h index fb6fabfb..384be3ee 100644 --- a/app/lua/lrodefs.h +++ b/app/lua/lrodefs.h @@ -21,6 +21,7 @@ #define LNUMKEY LRO_NUMKEY #define LNILKEY LRO_NILKEY #define LFUNCVAL LRO_FUNCVAL +#define LUDATA LRO_LUDATA #define LNUMVAL LRO_NUMVAL #define LROVAL LRO_ROVAL #define LNILVAL LRO_NILVAL diff --git a/app/lua/lrotable.h b/app/lua/lrotable.h index 27de84a0..e8963e3b 100644 --- a/app/lua/lrotable.h +++ b/app/lua/lrotable.h @@ -11,6 +11,7 @@ /* Macros one can use to define rotable entries */ #ifndef LUA_PACK_VALUE #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION} +#define LRO_LUDATA(v) {{.p = v}, LUA_TLIGHTUSERDATA} #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER} #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE} #define LRO_NILVAL {{.p = NULL}, LUA_TNIL} @@ -18,10 +19,12 @@ #define LRO_NUMVAL(v) {.value.n = v} #ifdef ELUA_ENDIAN_LITTLE #define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}} +#define LRO_LUDATA(v) {{(int)v, add_sig(LUA_TLIGHTUSERDATA)}} #define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}} #define LRO_NILVAL {{0, add_sig(LUA_TNIL)}} #else // #ifdef ELUA_ENDIAN_LITTLE #define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}} +#define LRO_LUDATA(v) {{add_sig(LUA_TLIGHTUSERDATA), (int)v}} #define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}} #define LRO_NILVAL {{add_sig(LUA_TNIL), 0}} #endif // #ifdef ELUA_ENDIAN_LITTLE diff --git a/app/modules/auxmods.h b/app/modules/auxmods.h index 1823d300..175a1f2b 100644 --- a/app/modules/auxmods.h +++ b/app/modules/auxmods.h @@ -95,5 +95,9 @@ LUALIB_API int ( luaopen_ow )( lua_State *L ); lua_pushnumber( L, val );\ lua_setfield( L, -2, name ) +#define MOD_REG_LUDATA( L, name, val )\ + lua_pushlightuserdata( L, val );\ + lua_setfield( L, -2, name ) + #endif diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 0fb26fd3..3595bf18 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -26,13 +26,13 @@ typedef struct _lu8g_userdata_t lu8g_userdata_t; // Font look-up array -static const u8g_fntpgm_uint8_t *font_array[] = -{ -#undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) u8g_ ## font , - U8G_FONT_TABLE - NULL -}; +//static const u8g_fntpgm_uint8_t *font_array[] = +//{ +//#undef U8G_FONT_TABLE_ENTRY +//#define U8G_FONT_TABLE_ENTRY(font) u8g_ ## font , +// U8G_FONT_TABLE +// NULL +//}; static uint32_t *u8g_pgm_cached_iadr = NULL; @@ -102,9 +102,9 @@ static int lu8g_setFont( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_Integer fontnr = luaL_checkinteger( L, 2 ); - if ((fontnr >= 0) && (fontnr < (sizeof( font_array ) / sizeof( u8g_fntpgm_uint8_t )))) - u8g_SetFont( LU8G, font_array[fontnr] ); + u8g_fntpgm_uint8_t *font = (u8g_fntpgm_uint8_t *)lua_touserdata( L, 2 ); + if (font != NULL) + u8g_SetFont( LU8G, font ); return 0; } @@ -1128,7 +1128,7 @@ const LUA_REG_TYPE lu8g_map[] = // Register fonts #undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LNUMVAL( __COUNTER__ ) }, +#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) }, U8G_FONT_TABLE // Options for circle/ ellipse drwing @@ -1164,7 +1164,7 @@ LUALIB_API int luaopen_u8g( lua_State *L ) // Register fonts #undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_NUMBER( L, #font, __COUNTER__ ); +#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) ); U8G_FONT_TABLE // Options for circle/ ellipse drawing From 5f1d32405985f58f26f36b871c16551682d080f8 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Sun, 1 Mar 2015 23:45:25 +0100 Subject: [PATCH 09/18] remove caching --- app/modules/u8g.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 3595bf18..e882ae4e 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -35,28 +35,15 @@ typedef struct _lu8g_userdata_t lu8g_userdata_t; //}; -static uint32_t *u8g_pgm_cached_iadr = NULL; -static uint32_t u8g_pgm_cached_data; - // function to read 4-byte aligned from program memory AKA irom0 u8g_pgm_uint8_t ICACHE_FLASH_ATTR u8g_pgm_read(const u8g_pgm_uint8_t *adr) { uint32_t iadr = (uint32_t)adr; // set up pointer to 4-byte aligned memory location uint32_t *ptr = (uint32_t *)(iadr & ~0x3); - uint32_t pgm_data; - if (ptr == u8g_pgm_cached_iadr) - { - pgm_data = u8g_pgm_cached_data; - } - else - { - // read 4-byte aligned - pgm_data = *ptr; - u8g_pgm_cached_iadr = ptr; - u8g_pgm_cached_data = pgm_data; - } + // read 4-byte aligned + uint32_t pgm_data = *ptr; // return the correct byte within the retrieved 32bit word return pgm_data >> ((iadr % 4) * 8); From 4f55ee4e34e32dc77e06202006b07cd45fa5a645 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 11 Mar 2015 21:53:45 +0100 Subject: [PATCH 10/18] validate SPI comm interface with ssd1306_128x64_spi --- app/modules/u8g.c | 46 ++++++++++++++++++++++++++++++ lua_examples/u8g_bitmaps.lua | 28 ++++++++++++++---- lua_examples/u8g_graphics_test.lua | 27 ++++++++++++++---- lua_examples/u8g_rotation.lua | 25 +++++++++++++--- 4 files changed, 110 insertions(+), 16 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index e882ae4e..66e75dfe 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1046,6 +1046,51 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) return 1; } +// Lua: object = u8g.ssd1306_128x64_spi( cs, dc ) +static int lu8g_ssd1306_128x64_spi( lua_State *L ) +{ + unsigned cs = luaL_checkinteger( L, 1 ); + if (cs == 0) + return luaL_error( L, "CS pin required" ); + unsigned dc = luaL_checkinteger( L, 2 ); + if (dc == 0) + return luaL_error( L, "D/C pin required" ); + + lu8g_userdata_t *lud = (lu8g_userdata_t *) lua_newuserdata( L, sizeof( lu8g_userdata_t ) ); + + // We don't use the pre-defined device structure for u8g_dev_ssd1306_128x64_i2c here + // Reason: linking the pre-defined structures allocates RAM for the device/comm structure + // *before* the display is constructed (especially the page buffers) + // this consumes heap even when the device is not used at all +#if 1 + // build device entry + lud->dev = (u8g_dev_t){ u8g_dev_ssd1306_128x64_fn, &(lud->pb), U8G_COM_HW_SPI }; + + // populate and allocate page buffer + // constants taken from u8g_dev_ssd1306_128x64.c: + // PAGE_HEIGHT + // | Height + // | | WIDTH + // | | | + lud->pb = (u8g_pb_t){ { 8, 64, 0, 0, 0 }, 128, NULL }; + // + if ((lud->pb.buf = (void *)c_zalloc(lud->pb.width)) == NULL) + return luaL_error( L, "out of memory" ); + + // and finally init device using specific interface init function + u8g_InitHWSPI( LU8G, &(lud->dev), cs, dc, U8G_PIN_NONE ); +#else + u8g_InitHWSPI( LU8G, &u8g_dev_ssd1306_128x64_spi, cs, dc, U8G_PIN_NONE ); +#endif + + + // set its metatable + luaL_getmetatable(L, "u8g.display"); + lua_setmetatable(L, -2); + + return 1; +} + // Module function map #define MIN_OPT_LEVEL 2 @@ -1111,6 +1156,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = const LUA_REG_TYPE lu8g_map[] = { { LSTRKEY( "ssd1306_128x64_i2c" ), LFUNCVAL ( lu8g_ssd1306_128x64_i2c ) }, + { LSTRKEY( "ssd1306_128x64_spi" ), LFUNCVAL ( lu8g_ssd1306_128x64_spi ) }, #if LUA_OPTIMIZE_MEMORY > 0 // Register fonts diff --git a/lua_examples/u8g_bitmaps.lua b/lua_examples/u8g_bitmaps.lua index 0a8ac8e7..92b5f7a0 100644 --- a/lua_examples/u8g_bitmaps.lua +++ b/lua_examples/u8g_bitmaps.lua @@ -1,13 +1,28 @@ -- setup I2c and connect display function init_i2c_display() - sda = 5 - scl = 6 + -- SDA and SCL can be assigned freely to available GPIOs + sda = 5 -- GPIO14 + scl = 6 -- GPIO12 sla = 0x3c i2c.setup(0, sda, scl, i2c.SLOW) disp = u8g.ssd1306_128x64_i2c(sla) end +-- setup SPI and connect display +function init_spi_display() + -- Hardware SPI CLK = GPIO14 + -- Hardware SPI MOSI = GPIO13 + -- Hardware SPI MISO = GPIO12 (not used) + -- CS and D/C can be assigned freely to available GPIOs + cs = 8 -- GPIO15, pull-down 10k to GND + dc = 4 -- GPIO2 + + spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) + disp = u8g.ssd1306_128x64_spi(cs, dc) +end + + function xbm_picture() disp:setFont(u8g.font_6x10) disp:drawStr( 0, 10, "XBM picture") @@ -34,9 +49,7 @@ function draw(draw_state) end -function bitmap_test() - init_i2c_display() - +function bitmap_test(delay) -- read XBM picture file.open("u8glib_logo.xbm", "r") xbm_data = file.read() @@ -58,10 +71,13 @@ function bitmap_test() draw(draw_state) until disp:nextPage() == false + tmr.delay(delay) tmr.wdclr() end print("--- Bitmap Test done ---") end -bitmap_test() +--init_i2c_display() +init_spi_display() +bitmap_test(50000) diff --git a/lua_examples/u8g_graphics_test.lua b/lua_examples/u8g_graphics_test.lua index edadf872..8a721e99 100644 --- a/lua_examples/u8g_graphics_test.lua +++ b/lua_examples/u8g_graphics_test.lua @@ -1,13 +1,27 @@ -- setup I2c and connect display function init_i2c_display() - sda = 5 - scl = 6 + -- SDA and SCL can be assigned freely to available GPIOs + sda = 5 -- GPIO14 + scl = 6 -- GPIO12 sla = 0x3c i2c.setup(0, sda, scl, i2c.SLOW) disp = u8g.ssd1306_128x64_i2c(sla) end +-- setup SPI and connect display +function init_spi_display() + -- Hardware SPI CLK = GPIO14 + -- Hardware SPI MOSI = GPIO13 + -- Hardware SPI MISO = GPIO12 (not used) + -- CS and D/C can be assigned freely to available GPIOs + cs = 8 -- GPIO15, pull-down 10k to GND + dc = 4 -- GPIO2 + + spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) + disp = u8g.ssd1306_128x64_spi(cs, dc) +end + -- graphic test components function prepare() @@ -122,9 +136,7 @@ function draw(draw_state) end end -function graphics_test() - init_i2c_display() - +function graphics_test(delay) print("--- Starting Graphics Test ---") -- cycle through all components @@ -135,6 +147,7 @@ function graphics_test() draw(draw_state) until disp:nextPage() == false --print(node.heap()) + tmr.delay(delay) -- re-trigger Watchdog! tmr.wdclr() end @@ -142,4 +155,6 @@ function graphics_test() print("--- Graphics Test done ---") end -graphics_test() +--init_i2c_display() +init_spi_display() +graphics_test(50000) diff --git a/lua_examples/u8g_rotation.lua b/lua_examples/u8g_rotation.lua index 0d900831..5b20fca8 100644 --- a/lua_examples/u8g_rotation.lua +++ b/lua_examples/u8g_rotation.lua @@ -1,13 +1,28 @@ -- setup I2c and connect display function init_i2c_display() - sda = 5 - scl = 6 + -- SDA and SCL can be assigned freely to available GPIOs + sda = 5 -- GPIO14 + scl = 6 -- GPIO12 sla = 0x3c i2c.setup(0, sda, scl, i2c.SLOW) disp = u8g.ssd1306_128x64_i2c(sla) end +-- setup SPI and connect display +function init_spi_display() + -- Hardware SPI CLK = GPIO14 + -- Hardware SPI MOSI = GPIO13 + -- Hardware SPI MISO = GPIO12 (not used) + -- CS and D/C can be assigned freely to available GPIOs + cs = 8 -- GPIO15, pull-down 10k to GND + dc = 4 -- GPIO2 + + spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) + disp = u8g.ssd1306_128x64_spi(cs, dc) +end + + -- the draw() routine function draw() disp:setFont(u8g.font_6x10) @@ -35,13 +50,12 @@ function rotate() dir = dir + 1 dir = bit.band(dir, 3) + -- schedule next rotation step in 1000ms next_rotation = tmr.now() / 1000 + 1000 end end function rotation_test() - init_i2c_display() - print("--- Starting Rotation Test ---") dir = 0 next_rotation = 0 @@ -55,10 +69,13 @@ function rotation_test() draw(draw_state) until disp:nextPage() == false + tmr.delay(100000) tmr.wdclr() end print("--- Rotation Test done ---") end +--init_i2c_display() +init_spi_display() rotation_test() From 88815012d4dbd036226854faaf772a41facc0f47 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 11 Mar 2015 21:56:20 +0100 Subject: [PATCH 11/18] move u8glib examples to subfolder --- lua_examples/{ => u8glib}/u8g_bitmaps.lua | 0 lua_examples/{ => u8glib}/u8g_graphics_test.lua | 0 lua_examples/{ => u8glib}/u8g_rook.bm | Bin lua_examples/{ => u8glib}/u8g_rotation.lua | 0 lua_examples/{ => u8glib}/u8glib_logo.xbm | Bin 5 files changed, 0 insertions(+), 0 deletions(-) rename lua_examples/{ => u8glib}/u8g_bitmaps.lua (100%) rename lua_examples/{ => u8glib}/u8g_graphics_test.lua (100%) rename lua_examples/{ => u8glib}/u8g_rook.bm (100%) rename lua_examples/{ => u8glib}/u8g_rotation.lua (100%) rename lua_examples/{ => u8glib}/u8glib_logo.xbm (100%) diff --git a/lua_examples/u8g_bitmaps.lua b/lua_examples/u8glib/u8g_bitmaps.lua similarity index 100% rename from lua_examples/u8g_bitmaps.lua rename to lua_examples/u8glib/u8g_bitmaps.lua diff --git a/lua_examples/u8g_graphics_test.lua b/lua_examples/u8glib/u8g_graphics_test.lua similarity index 100% rename from lua_examples/u8g_graphics_test.lua rename to lua_examples/u8glib/u8g_graphics_test.lua diff --git a/lua_examples/u8g_rook.bm b/lua_examples/u8glib/u8g_rook.bm similarity index 100% rename from lua_examples/u8g_rook.bm rename to lua_examples/u8glib/u8g_rook.bm diff --git a/lua_examples/u8g_rotation.lua b/lua_examples/u8glib/u8g_rotation.lua similarity index 100% rename from lua_examples/u8g_rotation.lua rename to lua_examples/u8glib/u8g_rotation.lua diff --git a/lua_examples/u8glib_logo.xbm b/lua_examples/u8glib/u8glib_logo.xbm similarity index 100% rename from lua_examples/u8glib_logo.xbm rename to lua_examples/u8glib/u8glib_logo.xbm From b172f628b5c621b3d790c0c22f3f32159daf36ea Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 11 Mar 2015 22:20:28 +0100 Subject: [PATCH 12/18] document SPI and bitmap --- README.md | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fb55a684..9ffec70a 100644 --- a/README.md +++ b/README.md @@ -346,24 +346,50 @@ The integration in nodemcu is developed for SSD1306 based display attached via t U8glib v1.17 #####I2C connection -Hook up SDA and SCL to any free GPIOs. Eg. [lua_examples/graphics_test.lua](https://github.com/devsaurus/nodemcu-firmware/blob/dev/lua_examples/graphics_test.lua) expects SDA=5 (GPIO14) and SCL=6 (GPIO12). They are used to set up nodemcu's I2C driver before accessing the display: +Hook up SDA and SCL to any free GPIOs. Eg. `lua_examples/u8glib/graphics_test.lua` expects SDA=5 (GPIO14) and SCL=6 (GPIO12). They are used to set up nodemcu's I2C driver before accessing the display: ```lua sda = 5 scl = 6 i2c.setup(0, sda, scl, i2c.SLOW) ``` +#####SPI connection +The HSPI module is used, so certain pins are fixed: +* HSPI CLK = GPIO14 +* HSPI MOSI = GPIO13 +* HPSI MISO = GPIO12 (not used) + +All other pins can be assigned to any available GPIO: +* CS +* D/C +* RES (optional) + +Also refer to the initialization sequence eg in `lua_examples/u8glib/graphics_test.lua`: +```lua +spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) +``` + + #####Library usage -The Lua bindings for this library closely follow u8glib's object oriented C++ API. Based on the u8g class, you create an object for your display type: +The Lua bindings for this library closely follow u8glib's object oriented C++ API. Based on the u8g class, you create an object for your display type. + +SSD1306 via I2C: ```lua sla = 0x3c disp = u8g.ssd1306_128x64_i2c(sla) ``` +SSD1306 via SPI: +```lua +cs = 8 -- GPIO15, pull-down 10k to GND +dc = 4 -- GPIO2 +disp = u8g.ssd1306_128x64_spi(cs, dc) +``` + This object provides all of u8glib's methods to control the display. -Again, refer to [lua_examples/graphics_test.lua](https://github.com/devsaurus/nodemcu-firmware/blob/dev/lua_examples/u8g_graphics_test.lua) to get an impression how this is achieved with Lua code. Visit the [u8glib homepage](https://code.google.com/p/u8glib/) for technical details. +Again, refer to `lua_examples/u8glib/graphics_test.lua` to get an impression how this is achieved with Lua code. Visit the [u8glib homepage](https://code.google.com/p/u8glib/) for technical details. #####Fonts -u8glib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in [app/include/user_config.h](https://github.com/devsaurus/nodemcu-firmware/blob/dev/app/include/user_config.h) and recompile. Simply add the desired fonts to the font table: +u8glib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in `app/include/user_config.h` and recompile. Simply add the desired fonts to the font table: ```c #define U8G_FONT_TABLE \ U8G_FONT_TABLE_ENTRY(font_6x10) \ @@ -371,6 +397,9 @@ u8glib comes with a wide range of fonts for small displays. Since they need to b ``` They'll be available as `u8g.` in Lua. +#####Bitmaps +Bitmaps and XBMs are supplied as strings to `drawBitmap()` and `drawXBM()`. This off-loads all data handling from the u8g module to generic methods for binary files. See `lua_examples/u8glib/u8g_bitmaps.lua`. Binary files can be uploaded with [nodemcu-uploader.py](https://github.com/kmpm/nodemcu-uploader). + #####Unimplemented functions - [ ] Cursor handling - [ ] disableCursor() @@ -379,12 +408,7 @@ They'll be available as `u8g.` in Lua. - [ ] setCursorFont() - [ ] setCursorPos() - [ ] setCursorStyle() -- [x] Bitmaps - - [x] drawBitmap() - - [x] drawXBM() - [ ] General functions - - [x] begin() - - [ ] print() - [ ] setContrast() - [ ] setPrintPos() - [ ] setHardwareBackup() From b387ba93ecf6061fb62fed2c6b568f425d489f18 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Thu, 12 Mar 2015 21:50:57 +0100 Subject: [PATCH 13/18] introduce u8g_config.h --- app/include/u8g_config.h | 14 ++++++++++++++ app/include/user_config.h | 8 -------- app/modules/u8g.c | 13 ++----------- 3 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 app/include/u8g_config.h diff --git a/app/include/u8g_config.h b/app/include/u8g_config.h new file mode 100644 index 00000000..d0055167 --- /dev/null +++ b/app/include/u8g_config.h @@ -0,0 +1,14 @@ +#ifndef __U8G_CONFIG_H__ +#define __U8G_CONFIG_H__ + + + +// Configure U8glib fonts +// add a U8G_FONT_TABLE_ENTRY for each font you want to compile into the image +#define U8G_FONT_TABLE_ENTRY(font) +#define U8G_FONT_TABLE \ + U8G_FONT_TABLE_ENTRY(font_6x10) \ + U8G_FONT_TABLE_ENTRY(font_chikita) +#undef U8G_FONT_TABLE_ENTRY + +#endif /* __U8G_CONFIG_H__ */ diff --git a/app/include/user_config.h b/app/include/user_config.h index c1a9805c..26af62cc 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -65,12 +65,4 @@ #define LED_LOW_COUNT_DEFAULT 0 #endif -// Configure U8glib fonts -// add a U8G_FONT_TABLE_ENTRY for each font you want to compile into the image -#define U8G_FONT_TABLE_ENTRY(font) -#define U8G_FONT_TABLE \ - U8G_FONT_TABLE_ENTRY(font_6x10) \ - U8G_FONT_TABLE_ENTRY(font_chikita) -#undef U8G_FONT_TABLE_ENTRY - #endif /* __USER_CONFIG_H__ */ diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 66e75dfe..79366c3c 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1,6 +1,5 @@ // Module for U8glib -//#include "lua.h" #include "lualib.h" #include "lauxlib.h" #include "platform.h" @@ -12,6 +11,8 @@ #include "u8g.h" +#include "u8g_config.h" + struct _lu8g_userdata_t { u8g_t u8g; @@ -25,16 +26,6 @@ typedef struct _lu8g_userdata_t lu8g_userdata_t; #define LU8G (&(lud->u8g)) -// Font look-up array -//static const u8g_fntpgm_uint8_t *font_array[] = -//{ -//#undef U8G_FONT_TABLE_ENTRY -//#define U8G_FONT_TABLE_ENTRY(font) u8g_ ## font , -// U8G_FONT_TABLE -// NULL -//}; - - // function to read 4-byte aligned from program memory AKA irom0 u8g_pgm_uint8_t ICACHE_FLASH_ATTR u8g_pgm_read(const u8g_pgm_uint8_t *adr) { From 429bf57d67ce1a281c31e80fd506225a4ea49c81 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Thu, 12 Mar 2015 23:09:41 +0100 Subject: [PATCH 14/18] add pcd8544 --- app/include/u8g_config.h | 8 +++++- app/modules/u8g.c | 61 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/app/include/u8g_config.h b/app/include/u8g_config.h index d0055167..08885fef 100644 --- a/app/include/u8g_config.h +++ b/app/include/u8g_config.h @@ -2,7 +2,6 @@ #define __U8G_CONFIG_H__ - // Configure U8glib fonts // add a U8G_FONT_TABLE_ENTRY for each font you want to compile into the image #define U8G_FONT_TABLE_ENTRY(font) @@ -11,4 +10,11 @@ U8G_FONT_TABLE_ENTRY(font_chikita) #undef U8G_FONT_TABLE_ENTRY + +// Enable display drivers +#define U8G_SSD1306_128x64_I2C +#define U8G_SSD1306_128x64_SPI +#define U8G_PCD8544_84x48 + + #endif /* __U8G_CONFIG_H__ */ diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 79366c3c..e2aff544 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1004,7 +1004,7 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) lud->u8g.i2c_addr = (uint8_t)addr; - // We don't use the pre-defined device structure for u8g_dev_ssd1306_128x64_i2c here + // Don't use the pre-defined device structure for u8g_dev_ssd1306_128x64_i2c here // Reason: linking the pre-defined structures allocates RAM for the device/comm structure // *before* the display is constructed (especially the page buffers) // this consumes heap even when the device is not used at all @@ -1049,7 +1049,7 @@ static int lu8g_ssd1306_128x64_spi( lua_State *L ) lu8g_userdata_t *lud = (lu8g_userdata_t *) lua_newuserdata( L, sizeof( lu8g_userdata_t ) ); - // We don't use the pre-defined device structure for u8g_dev_ssd1306_128x64_i2c here + // Don't use the pre-defined device structure for u8g_dev_ssd1306_128x64_spi here // Reason: linking the pre-defined structures allocates RAM for the device/comm structure // *before* the display is constructed (especially the page buffers) // this consumes heap even when the device is not used at all @@ -1082,6 +1082,55 @@ static int lu8g_ssd1306_128x64_spi( lua_State *L ) return 1; } +uint8_t u8g_dev_pcd8544_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); +// Lua: object = u8g.pcd8544_84x48( sce, dc, res ) +static int lu8g_pcd8544_84x48( lua_State *L ) +{ + unsigned sce = luaL_checkinteger( L, 1 ); + if (sce == 0) + return luaL_error( L, "SCE pin required" ); + unsigned dc = luaL_checkinteger( L, 2 ); + if (dc == 0) + return luaL_error( L, "D/C pin required" ); + unsigned res = luaL_checkinteger( L, 3 ); + if (res == 0) + return luaL_error( L, "RES pin required" ); + + lu8g_userdata_t *lud = (lu8g_userdata_t *) lua_newuserdata( L, sizeof( lu8g_userdata_t ) ); + + // Don't use the pre-defined device structure for u8g_dev_pcd8544_84x48_hw_spi here + // Reason: linking the pre-defined structures allocates RAM for the device/comm structure + // *before* the display is constructed (especially the page buffers) + // this consumes heap even when the device is not used at all +#if 1 + // build device entry + lud->dev = (u8g_dev_t){ u8g_dev_pcd8544_fn, &(lud->pb), U8G_COM_HW_SPI }; + + // populate and allocate page buffer + // constants taken from u8g_dev_pcd8544_84x48.c: + // PAGE_HEIGHT + // | Height + // | | WIDTH + // | | | + lud->pb = (u8g_pb_t){ { 8, 48, 0, 0, 0 }, 84, NULL }; + // + if ((lud->pb.buf = (void *)c_zalloc(lud->pb.width)) == NULL) + return luaL_error( L, "out of memory" ); + + // and finally init device using specific interface init function + u8g_InitHWSPI( LU8G, &(lud->dev), sce, dc, res ); +#else + u8g_InitHWSPI( LU8G, &u8g_dev_pcd8544_84x48_hw_spi, sce, dc, res ); +#endif + + + // set its metatable + luaL_getmetatable(L, "u8g.display"); + lua_setmetatable(L, -2); + + return 1; +} + // Module function map #define MIN_OPT_LEVEL 2 @@ -1146,8 +1195,16 @@ static const LUA_REG_TYPE lu8g_display_map[] = const LUA_REG_TYPE lu8g_map[] = { +#ifdef U8G_SSD1306_128x64_I2C { LSTRKEY( "ssd1306_128x64_i2c" ), LFUNCVAL ( lu8g_ssd1306_128x64_i2c ) }, +#endif +#ifdef U8G_SSD1306_128x64_I2C { LSTRKEY( "ssd1306_128x64_spi" ), LFUNCVAL ( lu8g_ssd1306_128x64_spi ) }, +#endif +#ifdef U8G_PCD8544_84x48 + { LSTRKEY( "pcd8544_84x48" ), LFUNCVAL ( lu8g_pcd8544_84x48 ) }, +#endif + #if LUA_OPTIMIZE_MEMORY > 0 // Register fonts From 3b37f0920cb41e19958dffe7eb6f218644d4709f Mon Sep 17 00:00:00 2001 From: devsaurus Date: Fri, 13 Mar 2015 22:22:57 +0100 Subject: [PATCH 15/18] res optional --- app/modules/u8g.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/modules/u8g.c b/app/modules/u8g.c index e2aff544..59cb20d9 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1037,7 +1037,7 @@ static int lu8g_ssd1306_128x64_i2c( lua_State *L ) return 1; } -// Lua: object = u8g.ssd1306_128x64_spi( cs, dc ) +// Lua: object = u8g.ssd1306_128x64_spi( cs, dc, [res] ) static int lu8g_ssd1306_128x64_spi( lua_State *L ) { unsigned cs = luaL_checkinteger( L, 1 ); @@ -1046,6 +1046,7 @@ static int lu8g_ssd1306_128x64_spi( lua_State *L ) unsigned dc = luaL_checkinteger( L, 2 ); if (dc == 0) return luaL_error( L, "D/C pin required" ); + unsigned res = luaL_optinteger( L, 3, U8G_PIN_NONE ); lu8g_userdata_t *lud = (lu8g_userdata_t *) lua_newuserdata( L, sizeof( lu8g_userdata_t ) ); @@ -1069,9 +1070,9 @@ static int lu8g_ssd1306_128x64_spi( lua_State *L ) return luaL_error( L, "out of memory" ); // and finally init device using specific interface init function - u8g_InitHWSPI( LU8G, &(lud->dev), cs, dc, U8G_PIN_NONE ); + u8g_InitHWSPI( LU8G, &(lud->dev), cs, dc, res ); #else - u8g_InitHWSPI( LU8G, &u8g_dev_ssd1306_128x64_spi, cs, dc, U8G_PIN_NONE ); + u8g_InitHWSPI( LU8G, &u8g_dev_ssd1306_128x64_spi, cs, dc, res ); #endif From 8e7e5310224ea3a00bdfd4654d34bca0c1f8bbb8 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Sun, 15 Mar 2015 22:08:35 +0100 Subject: [PATCH 16/18] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ab78ed81..987c2891 100644 --- a/README.md +++ b/README.md @@ -375,12 +375,12 @@ i2c.setup(0, sda, scl, i2c.SLOW) The HSPI module is used, so certain pins are fixed: * HSPI CLK = GPIO14 * HSPI MOSI = GPIO13 -* HPSI MISO = GPIO12 (not used) +* HSPI MISO = GPIO12 (not used) All other pins can be assigned to any available GPIO: * CS * D/C -* RES (optional) +* RES (optional for some displays) Also refer to the initialization sequence eg in `lua_examples/u8glib/graphics_test.lua`: ```lua @@ -407,7 +407,7 @@ This object provides all of u8glib's methods to control the display. Again, refer to `lua_examples/u8glib/graphics_test.lua` to get an impression how this is achieved with Lua code. Visit the [u8glib homepage](https://code.google.com/p/u8glib/) for technical details. #####Fonts -u8glib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in `app/include/user_config.h` and recompile. Simply add the desired fonts to the font table: +u8glib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in `app/include/u8g_config.h` and recompile. Simply add the desired fonts to the font table: ```c #define U8G_FONT_TABLE \ U8G_FONT_TABLE_ENTRY(font_6x10) \ @@ -463,4 +463,4 @@ cs:func("myfun") -- post coap://192.168.18.103:5683/v1/f/myfun will call myfun cc = coap.Client() cc:get(coap.CON, "coap://192.168.18.100:5683/.well-known/core") cc:post(coap.NON, "coap://192.168.18.100:5683/", "Hello") -``` \ No newline at end of file +``` From 09b650be415c1ed272b031fabec7d6848b492148 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Tue, 17 Mar 2015 20:52:47 +0100 Subject: [PATCH 17/18] disable untested pcd8544 driver for the moment --- app/include/u8g_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/include/u8g_config.h b/app/include/u8g_config.h index 08885fef..007e5450 100644 --- a/app/include/u8g_config.h +++ b/app/include/u8g_config.h @@ -14,7 +14,8 @@ // Enable display drivers #define U8G_SSD1306_128x64_I2C #define U8G_SSD1306_128x64_SPI -#define U8G_PCD8544_84x48 +// untested +#undef U8G_PCD8544_84x48 #endif /* __U8G_CONFIG_H__ */ From b34a8b46fec2b241c837ea35c6a6cf1edc0fb46a Mon Sep 17 00:00:00 2001 From: devsaurus Date: Tue, 17 Mar 2015 21:03:15 +0100 Subject: [PATCH 18/18] use RES pin for examples --- README.md | 7 ++++--- lua_examples/u8glib/u8g_bitmaps.lua | 9 +++++---- lua_examples/u8glib/u8g_graphics_test.lua | 9 +++++---- lua_examples/u8glib/u8g_rotation.lua | 9 +++++---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 987c2891..aeb06675 100644 --- a/README.md +++ b/README.md @@ -398,9 +398,10 @@ disp = u8g.ssd1306_128x64_i2c(sla) ``` SSD1306 via SPI: ```lua -cs = 8 -- GPIO15, pull-down 10k to GND -dc = 4 -- GPIO2 -disp = u8g.ssd1306_128x64_spi(cs, dc) +cs = 8 -- GPIO15, pull-down 10k to GND +dc = 4 -- GPIO2 +res = 0 -- GPIO16, RES is optional YMMV +disp = u8g.ssd1306_128x64_spi(cs, dc, res) ``` This object provides all of u8glib's methods to control the display. diff --git a/lua_examples/u8glib/u8g_bitmaps.lua b/lua_examples/u8glib/u8g_bitmaps.lua index 92b5f7a0..1b388e41 100644 --- a/lua_examples/u8glib/u8g_bitmaps.lua +++ b/lua_examples/u8glib/u8g_bitmaps.lua @@ -14,12 +14,13 @@ function init_spi_display() -- Hardware SPI CLK = GPIO14 -- Hardware SPI MOSI = GPIO13 -- Hardware SPI MISO = GPIO12 (not used) - -- CS and D/C can be assigned freely to available GPIOs - cs = 8 -- GPIO15, pull-down 10k to GND - dc = 4 -- GPIO2 + -- CS, D/C, and RES can be assigned freely to available GPIOs + cs = 8 -- GPIO15, pull-down 10k to GND + dc = 4 -- GPIO2 + res = 0 -- GPIO16 spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) - disp = u8g.ssd1306_128x64_spi(cs, dc) + disp = u8g.ssd1306_128x64_spi(cs, dc, res) end diff --git a/lua_examples/u8glib/u8g_graphics_test.lua b/lua_examples/u8glib/u8g_graphics_test.lua index 8a721e99..27c7a346 100644 --- a/lua_examples/u8glib/u8g_graphics_test.lua +++ b/lua_examples/u8glib/u8g_graphics_test.lua @@ -14,12 +14,13 @@ function init_spi_display() -- Hardware SPI CLK = GPIO14 -- Hardware SPI MOSI = GPIO13 -- Hardware SPI MISO = GPIO12 (not used) - -- CS and D/C can be assigned freely to available GPIOs - cs = 8 -- GPIO15, pull-down 10k to GND - dc = 4 -- GPIO2 + -- CS, D/C, and RES can be assigned freely to available GPIOs + cs = 8 -- GPIO15, pull-down 10k to GND + dc = 4 -- GPIO2 + res = 0 -- GPIO16 spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) - disp = u8g.ssd1306_128x64_spi(cs, dc) + disp = u8g.ssd1306_128x64_spi(cs, dc, res) end diff --git a/lua_examples/u8glib/u8g_rotation.lua b/lua_examples/u8glib/u8g_rotation.lua index 5b20fca8..6d81c779 100644 --- a/lua_examples/u8glib/u8g_rotation.lua +++ b/lua_examples/u8glib/u8g_rotation.lua @@ -14,12 +14,13 @@ function init_spi_display() -- Hardware SPI CLK = GPIO14 -- Hardware SPI MOSI = GPIO13 -- Hardware SPI MISO = GPIO12 (not used) - -- CS and D/C can be assigned freely to available GPIOs - cs = 8 -- GPIO15, pull-down 10k to GND - dc = 4 -- GPIO2 + -- CS, D/C, and RES can be assigned freely to available GPIOs + cs = 8 -- GPIO15, pull-down 10k to GND + dc = 4 -- GPIO2 + res = 0 -- GPIO16 spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) - disp = u8g.ssd1306_128x64_spi(cs, dc) + disp = u8g.ssd1306_128x64_spi(cs, dc, res) end