node.setcpufreq, gpio speed, Os
add node.setcpufreq(80|160) copied from jrahlf faster GPIO read/write change optimization level to Os fix chmod for fullmake.sh
This commit is contained in:
parent
7dc36cea05
commit
f8e8e5a198
2
Makefile
2
Makefile
|
@ -105,7 +105,7 @@ OBINS := $(GEN_BINS:%=$(BINODIR)/%)
|
|||
|
||||
CCFLAGS += \
|
||||
-g \
|
||||
-Ofast \
|
||||
-Os \
|
||||
-Wpointer-arith \
|
||||
-Wundef \
|
||||
-Werror \
|
||||
|
|
|
@ -121,28 +121,14 @@ static int lgpio_mode( lua_State* L )
|
|||
// Lua: read( pin )
|
||||
static int lgpio_read( lua_State* L )
|
||||
{
|
||||
unsigned pin;
|
||||
|
||||
pin = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( gpio, pin );
|
||||
|
||||
unsigned level = platform_gpio_read( pin );
|
||||
lua_pushinteger( L, level );
|
||||
lua_pushinteger( L, platform_gpio_read( luaL_checkinteger( L, 1 ) ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Lua: write( pin, level )
|
||||
static int lgpio_write( lua_State* L )
|
||||
{
|
||||
unsigned level;
|
||||
unsigned pin;
|
||||
|
||||
pin = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( gpio, pin );
|
||||
level = luaL_checkinteger( L, 2 );
|
||||
if ( level!=HIGH && level!=LOW )
|
||||
return luaL_error( L, "wrong arg type" );
|
||||
platform_gpio_write(pin, level);
|
||||
platform_gpio_write(luaL_checkinteger( L, 1 ), luaL_checkinteger( L, 2 ) & 0x1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -387,6 +387,22 @@ static int node_compile( lua_State* L )
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Lua: node.setcpufreq(int) -- change CPU frequency to 80 or 160 MHz, returns current frequency
|
||||
static int node_set_cpu_freq( lua_State* L )
|
||||
{
|
||||
uint32_t new_freq = luaL_checkinteger( L, 1 );
|
||||
if(new_freq == 160){
|
||||
REG_SET_BIT(0x3ff00014, BIT(0));
|
||||
os_update_cpu_frequency(160);
|
||||
}else{
|
||||
REG_CLR_BIT(0x3ff00014, BIT(0));
|
||||
os_update_cpu_frequency(80);
|
||||
}
|
||||
new_freq = ets_get_cpu_frequency();
|
||||
lua_pushinteger(L, new_freq);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Module function map
|
||||
#define MIN_OPT_LEVEL 2
|
||||
#include "lrodefs.h"
|
||||
|
@ -407,8 +423,7 @@ const LUA_REG_TYPE node_map[] =
|
|||
{ LSTRKEY( "output" ), LFUNCVAL( node_output ) },
|
||||
{ LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
|
||||
{ LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
|
||||
// Combined to dsleep(us, option)
|
||||
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
|
||||
{ LSTRKEY( "setcpufreq" ), LFUNCVAL( node_set_cpu_freq ) },
|
||||
#if LUA_OPTIMIZE_MEMORY > 0
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue