diff --git a/Makefile b/Makefile index b31f49ec..23a6c04a 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ OBINS := $(GEN_BINS:%=$(BINODIR)/%) CCFLAGS += \ -g \ - -Ofast \ + -Os \ -Wpointer-arith \ -Wundef \ -Werror \ diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 551dca8a..74e72756 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -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; } diff --git a/app/modules/node.c b/app/modules/node.c index 90dd0d96..dc635e3c 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -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