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/digitalinout.cpp
- Revision:
- 0:6f55c7651ccc
- Child:
- 1:540008bb92a2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqmbed/src/digitalinout.cpp Tue Dec 16 12:54:53 2014 +0000 @@ -0,0 +1,103 @@ +/* + @License@ +*/ + +#include <sqmbed/digitalinout.h> + +template<> +struct SqBindAllocator<SqMbed::DigitalInOut> { + static SQBIND_INLINE SqMbed::DigitalInOut *construct(HSQUIRRELVM) { + return NULL; // make it not able to construct + } + + static SQBIND_INLINE SqMbed::DigitalInOut *copy_construct(const SqMbed::DigitalInOut* p_from) { + return NULL; // make it not able to copy-construct + } + + static SQBIND_INLINE bool assign(SqMbed::DigitalInOut* p_val, const SqMbed::DigitalInOut* p_from) { + return false; // make it not able to assign + } + + static SQBIND_INLINE void destruct(SqMbed::DigitalInOut* p_instance) { + delete p_instance; + } + + static SQBIND_INLINE SqMbed::DigitalInOut& get_empty() { + // if someone tries to assign, this will crash. + // however, this will likely never be called anyway. + static SqMbed::DigitalInOut *crashplease=NULL; + return *crashplease; + } +}; + +namespace SqMbed +{ + +DigitalInOut::DigitalInOut(PinName pin) + : m_digInOut(pin) +{ +} + +DigitalInOut::~DigitalInOut() +{ +} + +void DigitalInOut::write(int value) +{ + m_digInOut.write(value); +} + +int DigitalInOut::read() const +{ + return m_digInOut.read(); +} + +void DigitalInOut::input() +{ + m_digInOut.input(); +} + +void DigitalInOut::output() +{ + m_digInOut.output(); +} + +void DigitalInOut::mode(PinMode m) +{ + m_digInOut.mode(m); +} + +// static +void DigitalInOut::bind(HSQUIRRELVM vm) +{ + SqBind<DigitalInOut>::init(vm, _SC("DigitalInOut")); + SqBind<DigitalInOut>::set_custom_constructor(&DigitalInOut::constructor); + sqbind_method(vm, "read", &DigitalInOut::read); + sqbind_method(vm, "write", &DigitalInOut::write); + sqbind_method(vm, "input", &DigitalInOut::input); + sqbind_method(vm, "output", &DigitalInOut::output); +} + +// static +DigitalInOut* DigitalInOut::constructor(HSQUIRRELVM vm) +{ + DigitalInOut* pThis = 0; + + int nParams = sq_gettop(vm); + + if (nParams == 2) { // Need 1 (sic) params. + SQInteger i; + + if (!SQ_FAILED(sq_getinteger(vm, 2, &i))) { + pThis = new DigitalInOut(static_cast<PinName>(i)); + } else { + printf("Could not get integer."); + } + } else { + printf("nParams != 2\n"); + } + + return pThis; +} + +}