The Squirrel interpreter for FRDM-K64F, extended with a set of classes that provide access to the mbed functionality (currently DigitalIn, DigitalInOut, DigitalOut, InterruptIn, PwmOut, Ticker, Timeout, Timer).
Dependencies: SQUIRREL3 mbed sqbind-0_99
The Squirrel interpreter for FRDM-K64F.
NOTE: Currently of POC quality.
See http://www.squirrel-lang.org/ for information about the Squirrel language.
Currently the following (a subset of their functionality) mbed classes are available from within Squirrel:
- DigitalIn
- DigitalOut
- DigitalInOut
- PwmOut
- Ticker
- Timeout
- Timer
In addition, InterruptIn is supported, but interrupts are noted when they occur, but only delivered from the main loop of the interpreter.
See also README.txt in the root of the project.
Diff: sqmbed/src/digitalin.cpp
- Revision:
- 0:6f55c7651ccc
- Child:
- 1:540008bb92a2
diff -r 000000000000 -r 6f55c7651ccc sqmbed/src/digitalin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqmbed/src/digitalin.cpp Tue Dec 16 12:54:53 2014 +0000 @@ -0,0 +1,104 @@ +/* + @License@ +*/ + +#include <sqmbed/digitalin.h> + +SQBIND_INTEGER(PinMode); + +template<> +struct SqBindAllocator<SqMbed::DigitalIn> { + static SQBIND_INLINE SqMbed::DigitalIn *construct(HSQUIRRELVM) { + return NULL; // make it not able to construct + } + + static SQBIND_INLINE SqMbed::DigitalIn *copy_construct(const SqMbed::DigitalIn* p_from) { + return NULL; // make it not able to copy-construct + } + + static SQBIND_INLINE bool assign(SqMbed::DigitalIn* p_val, const SqMbed::DigitalIn* p_from) { + return false; // make it not able to assign + } + + static SQBIND_INLINE void destruct(SqMbed::DigitalIn* p_instance) { + delete p_instance; + } + + static SQBIND_INLINE SqMbed::DigitalIn& get_empty() { + // if someone tries to assign, this will crash. + // however, this will likely never be called anyway. + static SqMbed::DigitalIn *crashplease=NULL; + return *crashplease; + } +}; + +namespace SqMbed +{ + +DigitalIn::DigitalIn(PinName pin) + : m_digIn(pin) +{ +} + +DigitalIn::DigitalIn(PinName pin, PinMode mode) + : m_digIn(pin, mode) +{ +} + +DigitalIn::~DigitalIn() +{ +} + +int DigitalIn::read() const +{ + return m_digIn.read(); +} + +void DigitalIn::mode(PinMode m) +{ + m_digIn.mode(m); +} + +// static +void DigitalIn::bind(HSQUIRRELVM vm) +{ + SqBind<DigitalIn>::init(vm, _SC("DigitalIn")); + SqBind<DigitalIn>::set_custom_constructor(&DigitalIn::constructor); + sqbind_method(vm, "mode", &DigitalIn::mode); + sqbind_method(vm, "read", &DigitalIn::read); +} + +// static +DigitalIn* DigitalIn::constructor(HSQUIRRELVM vm) +{ + DigitalIn* pThis = 0; + + int nParams = sq_gettop(vm); + + if ((nParams == 2) || (nParams == 3)) { // Need 1 (sic) params. + SQInteger pin; + + if (!SQ_FAILED(sq_getinteger(vm, 2, &pin))) { + if (nParams == 3) { + SQInteger mode; + + if (!SQ_FAILED(sq_getinteger(vm, 3, &mode))) { + pThis = new DigitalIn(static_cast<PinName>(pin), + static_cast<PinMode>(mode)); + } else { + printf("error: Invalid PinMode.\n"); + } + } else { + pThis = new DigitalIn(static_cast<PinName>(pin)); + } + } else { + printf("error: Invalid PinName.\n"); + } + } else { + printf("error: 2 or 3 params.\n"); + } + + return pThis; +} + +}