2014-12-22 12:35:05 +01:00
|
|
|
// Module for interfacing with adc
|
|
|
|
|
|
|
|
//#include "lua.h"
|
|
|
|
#include "lualib.h"
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "auxmods.h"
|
|
|
|
#include "lrotable.h"
|
|
|
|
|
|
|
|
#include "c_types.h"
|
2015-03-26 17:52:55 +01:00
|
|
|
#include "user_interface.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
// Lua: read(id) , return system adc
|
2015-01-05 03:09:51 +01:00
|
|
|
static int adc_sample( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
{
|
|
|
|
unsigned id = luaL_checkinteger( L, 1 );
|
|
|
|
MOD_CHECK_ID( adc, id );
|
|
|
|
unsigned val = 0xFFFF & system_adc_read();
|
|
|
|
lua_pushinteger( L, val );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:52:55 +01:00
|
|
|
// Lua: readvdd33()
|
|
|
|
static int adc_readvdd33( lua_State* L )
|
|
|
|
{
|
2015-11-10 05:30:59 +01:00
|
|
|
lua_pushinteger(L, system_get_vdd33 ());
|
2015-03-26 17:52:55 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
// Module function map
|
|
|
|
#define MIN_OPT_LEVEL 2
|
|
|
|
#include "lrodefs.h"
|
|
|
|
const LUA_REG_TYPE adc_map[] =
|
|
|
|
{
|
|
|
|
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
|
2015-03-26 17:52:55 +01:00
|
|
|
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
|
2014-12-22 12:35:05 +01:00
|
|
|
#if LUA_OPTIMIZE_MEMORY > 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
{ LNILKEY, LNILVAL }
|
|
|
|
};
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
LUALIB_API int luaopen_adc( lua_State *L )
|
2014-12-22 12:35:05 +01:00
|
|
|
{
|
|
|
|
#if LUA_OPTIMIZE_MEMORY > 0
|
|
|
|
return 0;
|
|
|
|
#else // #if LUA_OPTIMIZE_MEMORY > 0
|
|
|
|
luaL_register( L, AUXLIB_ADC, adc_map );
|
|
|
|
// Add constants
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
#endif // #if LUA_OPTIMIZE_MEMORY > 0
|
|
|
|
}
|