41 lines
923 B
C
41 lines
923 B
C
// Module for interfacing with adc
|
|
|
|
#include "lauxlib.h"
|
|
#include "platform.h"
|
|
#include "lrodefs.h"
|
|
|
|
#include "c_types.h"
|
|
#include "user_interface.h"
|
|
|
|
// Lua: read(id) , return system adc
|
|
static int adc_sample( lua_State* L )
|
|
{
|
|
unsigned id = luaL_checkinteger( L, 1 );
|
|
MOD_CHECK_ID( adc, id );
|
|
unsigned val = 0xFFFF & system_adc_read();
|
|
lua_pushinteger( L, val );
|
|
return 1;
|
|
}
|
|
|
|
// Lua: readvdd33()
|
|
static int adc_readvdd33( lua_State* L )
|
|
{
|
|
lua_pushinteger(L, system_get_vdd33 ());
|
|
return 1;
|
|
}
|
|
|
|
// Module function map
|
|
const LUA_REG_TYPE adc_map[] = {
|
|
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
|
|
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
|
|
{ LNILKEY, LNILVAL }
|
|
};
|
|
|
|
LUALIB_API int luaopen_adc( lua_State *L ) {
|
|
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
|
|
return 0;
|
|
#else
|
|
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
|
|
#endif
|
|
}
|