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/timeout.cpp
- Revision:
- 0:6f55c7651ccc
- Child:
- 1:540008bb92a2
diff -r 000000000000 -r 6f55c7651ccc sqmbed/src/timeout.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqmbed/src/timeout.cpp Tue Dec 16 12:54:53 2014 +0000 @@ -0,0 +1,76 @@ +/* + @License@ +*/ + +#include <sqmbed/timeout.h> + +template<> +struct SqBindAllocator<SqMbed::Timeout> { + static SQBIND_INLINE SqMbed::Timeout *construct(HSQUIRRELVM vm) { + SqMbed::Timeout* pThis = 0; + + if (SqMbed::Trigger::reserve()) { + pThis = new SqMbed::Timeout(vm); + } else { + printf("Out of memory\n"); + } + + return pThis; + } + + static SQBIND_INLINE SqMbed::Timeout *copy_construct(const SqMbed::Timeout* p_from) { + return NULL; // make it not able to copy-construct + } + + static SQBIND_INLINE bool assign(SqMbed::Timeout* p_val, const SqMbed::Timeout* p_from) { + return false; // make it not able to assign + } + + static SQBIND_INLINE void destruct(SqMbed::Timeout* p_instance) { + delete p_instance; + } + + static SQBIND_INLINE SqMbed::Timeout& get_empty() { + // if someone tries to assign, this will crash. + // however, this will likely never be called anyway. + static SqMbed::Timeout *crashplease=NULL; + return *crashplease; + } +}; + +namespace SqMbed +{ + +Timeout::Timeout(HSQUIRRELVM vm) + : Trigger(vm) +{ +} + +Timeout::~Timeout() +{ +} + +void Timeout::attach(HSQOBJECT o, float t) +{ + Trigger::attach(o); + + void (Timeout::*pTrigger)() = &Timeout::triggered; + + m_timeout.attach(this, pTrigger, t); +} + +void Timeout::detach() +{ + m_timeout.detach(); +} + +// static +void Timeout::bind(HSQUIRRELVM vm) +{ + SqBind<Timeout>::init(vm, _SC("Timeout")); + + sqbind_method(vm, "attach", &Timeout::attach); + sqbind_method(vm, "detach", &Timeout::detach); +} + +}