forked from Seeed-Studio/Lua_for_LinkIt_One
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
333bd1a
commit deb0a32
Showing
9 changed files
with
1,092 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
Arduino.h - Main include file for the Arduino SDK | ||
Copyright (c) 2005-2013 Arduino Team. All right reserved. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
Modified 20 Aug 2014 by MediaTek Inc. | ||
*/ | ||
|
||
#ifndef Arduino_h | ||
#define Arduino_h | ||
|
||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
// some libraries and sketches depend on this | ||
// AVR stuff, assuming Arduino.h or WProgram.h | ||
// automatically includes it... | ||
//#include <avr/pgmspace.h> | ||
|
||
|
||
#include "vmdcl.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C"{ | ||
#endif // __cplusplus | ||
|
||
#include "wiring_constants.h" | ||
|
||
void yield(void); | ||
|
||
/* sketch */ | ||
extern void setup( void ) ; | ||
extern void loop( void ) ; | ||
|
||
|
||
extern boolean changePinType(uint32_t ulPin, uint32_t ulPinType, VM_DCL_HANDLE* handle); | ||
extern void spiPinsRest(void); | ||
extern void setPinHandle(uint32_t ulPin, VM_DCL_HANDLE handle); | ||
|
||
typedef enum _EExt_Interrupts | ||
{ | ||
EXTERNAL_INT_0=0, | ||
EXTERNAL_INT_1=1, | ||
EXTERNAL_NUM_INTERRUPTS | ||
} EExt_Interrupts ; | ||
|
||
|
||
typedef void (*voidFuncPtr)( void ) ; | ||
|
||
#define PIO_MAX_NUM 19 | ||
|
||
typedef enum _EPioType | ||
{ | ||
PIO_DIGITAL, | ||
PIO_ANALOG, | ||
PIO_EINT, | ||
PIO_PWM, | ||
PIO_SPI, | ||
PIO_UART, | ||
PIO_I2C, | ||
PIO_SD, | ||
PIO_END | ||
} EPioType ; | ||
|
||
/* Types used for the tables below */ | ||
typedef struct _PinDescription | ||
{ | ||
VM_DCL_HANDLE ulHandle; | ||
uint32_t ulGpioId ; | ||
EPioType ulPinType ; | ||
uint32_t ulPupd; | ||
} PinDescription ; | ||
|
||
/* Pins table to be instanciated into variant.cpp */ | ||
extern PinDescription g_APinDescription[] ; | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
|
||
|
||
#endif // __cplusplus | ||
|
||
// Include board variant | ||
#include "variant.h" | ||
|
||
|
||
|
||
#define USB_PID_LEONARDO 0x0034 | ||
#define USB_PID_MICRO 0x0035 | ||
#define USB_PID_DUE 0x003E | ||
|
||
boolean noStopInterrupts(void); | ||
extern void spiPinsRest(void); | ||
extern void setPinHandle(uint32_t ulPin, VM_DCL_HANDLE handle); | ||
|
||
#endif // Arduino_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
#include "Arduino.h" | ||
#include "wiring_digital.h" | ||
|
||
#include "lua.h" | ||
#include "lauxlib.h" | ||
|
||
|
||
int gpio_mode(lua_State *L) | ||
{ | ||
int pin = luaL_checkinteger(L, 1); | ||
int mode = luaL_checkinteger(L, 2); | ||
|
||
pinMode(pin, mode); | ||
|
||
return 0; | ||
} | ||
|
||
int gpio_read(lua_State *L) | ||
{ | ||
int pin = luaL_checkinteger(L, 1); | ||
|
||
lua_pushnumber(L, digitalRead(pin)); | ||
|
||
return 1; | ||
} | ||
|
||
int gpio_write(lua_State *L) | ||
{ | ||
int pin = luaL_checkinteger(L, 1); | ||
int value = luaL_checkinteger(L, 2); | ||
|
||
digitalWrite(pin, value); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
#undef MIN_OPT_LEVEL | ||
#define MIN_OPT_LEVEL 0 | ||
#include "lrodefs.h" | ||
|
||
#define MOD_REG_NUMBER(L, name, value) lua_pushnumber(L, value); \ | ||
lua_setfield(L, -2, name); | ||
|
||
const LUA_REG_TYPE gpio_map[] = | ||
{ | ||
{LSTRKEY("mode"), LFUNCVAL(gpio_mode)}, | ||
{LSTRKEY("read"), LFUNCVAL(gpio_read)}, | ||
{LSTRKEY("write"), LFUNCVAL(gpio_write)}, | ||
#if LUA_OPTIMIZE_MEMORY > 0 | ||
{ LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, | ||
{ LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) }, | ||
{ LSTRKEY( "HIGH" ), LNUMVAL( HIGH ) }, | ||
{ LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, | ||
{ LSTRKEY( "INPUT_PULLUP" ), LNUMVAL( INPUT_PULLUP ) }, | ||
#endif | ||
{LNILKEY, LNILVAL} | ||
}; | ||
|
||
LUALIB_API int luaopen_gpio(lua_State *L) | ||
{ | ||
lua_register(L, "pinMode", gpio_mode); | ||
lua_register(L, "digitalRead", gpio_read); | ||
lua_register(L, "digitalWrite", gpio_write); | ||
|
||
#if LUA_OPTIMIZE_MEMORY > 0 | ||
return 0; | ||
#else // #if LUA_OPTIMIZE_MEMORY > 0 | ||
|
||
luaL_register(L, "gpio", gpio_map); | ||
// Add constants | ||
MOD_REG_NUMBER( L, "OUTPUT", OUTPUT ); | ||
MOD_REG_NUMBER( L, "INPUT", INPUT ); | ||
MOD_REG_NUMBER( L, "HIGH", HIGH ); | ||
MOD_REG_NUMBER( L, "LOW", LOW ); | ||
MOD_REG_NUMBER( L, "INPUT_PULLUP", INPUT_PULLUP ); | ||
return 1; | ||
#endif // #if LUA_OPTIMIZE_MEMORY > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.