Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5fa0a0bc
Commit
5fa0a0bc
authored
Feb 10, 2015
by
devsaurus
Browse files
cache pgm read data
parent
f2c881db
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/u8g.c
View file @
5fa0a0bc
...
@@ -25,15 +25,28 @@ static const u8g_fntpgm_uint8_t *font_array[] =
...
@@ -25,15 +25,28 @@ static const u8g_fntpgm_uint8_t *font_array[] =
};
};
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
// function to read 4-byte aligned from program memory AKA irom0
u8g_pgm_uint8_t
u8g_pgm_read
(
const
u8g_pgm_uint8_t
*
adr
)
u8g_pgm_uint8_t
ICACHE_FLASH_ATTR
u8g_pgm_read
(
const
u8g_pgm_uint8_t
*
adr
)
{
{
uint32_t
iadr
=
(
uint32_t
)
adr
;
uint32_t
iadr
=
(
uint32_t
)
adr
;
// set up pointer to 4-byte aligned memory location
// set up pointer to 4-byte aligned memory location
uint32_t
*
ptr
=
(
uint32_t
*
)(
iadr
&
~
0x3
);
uint32_t
*
ptr
=
(
uint32_t
*
)(
iadr
&
~
0x3
);
uint32_t
pgm_data
;
// read 4-byte aligned
if
(
ptr
==
u8g_pgm_cached_iadr
)
uint32_t
pgm_data
=
*
ptr
;
{
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
;
}
// return the correct byte within the retrieved 32bit word
// return the correct byte within the retrieved 32bit word
return
pgm_data
>>
((
iadr
%
4
)
*
8
);
return
pgm_data
>>
((
iadr
%
4
)
*
8
);
...
@@ -962,7 +975,7 @@ const LUA_REG_TYPE lu8g_map[] =
...
@@ -962,7 +975,7 @@ const LUA_REG_TYPE lu8g_map[] =
{
LNILKEY
,
LNILVAL
}
{
LNILKEY
,
LNILVAL
}
};
};
LUALIB_API
int
ICACHE_FLASH_ATTR
luaopen_u8g
(
lua_State
*
L
)
LUALIB_API
int
luaopen_u8g
(
lua_State
*
L
)
{
{
#if LUA_OPTIMIZE_MEMORY > 0
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable
(
L
,
"u8g.display"
,
(
void
*
)
lu8g_display_map
);
// create metatable
luaL_rometatable
(
L
,
"u8g.display"
,
(
void
*
)
lu8g_display_map
);
// create metatable
...
...
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