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