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.

Committer:
jhnwkmn
Date:
Tue Dec 16 12:54:53 2014 +0000
Revision:
0:6f55c7651ccc
Child:
1:540008bb92a2
Added README.txt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:6f55c7651ccc 1 /*
jhnwkmn 0:6f55c7651ccc 2 @License@
jhnwkmn 0:6f55c7651ccc 3 */
jhnwkmn 0:6f55c7651ccc 4
jhnwkmn 0:6f55c7651ccc 5 #include <sqmbed/ticker.h>
jhnwkmn 0:6f55c7651ccc 6
jhnwkmn 0:6f55c7651ccc 7 template<>
jhnwkmn 0:6f55c7651ccc 8 struct SqBindAllocator<SqMbed::Ticker> {
jhnwkmn 0:6f55c7651ccc 9 static SQBIND_INLINE SqMbed::Ticker *construct(HSQUIRRELVM vm) {
jhnwkmn 0:6f55c7651ccc 10 SqMbed::Ticker* pThis = 0;
jhnwkmn 0:6f55c7651ccc 11
jhnwkmn 0:6f55c7651ccc 12 if (SqMbed::Trigger::reserve()) {
jhnwkmn 0:6f55c7651ccc 13 pThis = new SqMbed::Ticker(vm);
jhnwkmn 0:6f55c7651ccc 14 } else {
jhnwkmn 0:6f55c7651ccc 15 printf("Out of memory\n");
jhnwkmn 0:6f55c7651ccc 16 }
jhnwkmn 0:6f55c7651ccc 17
jhnwkmn 0:6f55c7651ccc 18 return pThis;
jhnwkmn 0:6f55c7651ccc 19 }
jhnwkmn 0:6f55c7651ccc 20
jhnwkmn 0:6f55c7651ccc 21 static SQBIND_INLINE SqMbed::Ticker *copy_construct(const SqMbed::Ticker* p_from) {
jhnwkmn 0:6f55c7651ccc 22 return NULL; // make it not able to copy-construct
jhnwkmn 0:6f55c7651ccc 23 }
jhnwkmn 0:6f55c7651ccc 24
jhnwkmn 0:6f55c7651ccc 25 static SQBIND_INLINE bool assign(SqMbed::Ticker* p_val, const SqMbed::Ticker* p_from) {
jhnwkmn 0:6f55c7651ccc 26 return false; // make it not able to assign
jhnwkmn 0:6f55c7651ccc 27 }
jhnwkmn 0:6f55c7651ccc 28
jhnwkmn 0:6f55c7651ccc 29 static SQBIND_INLINE void destruct(SqMbed::Ticker* p_instance) {
jhnwkmn 0:6f55c7651ccc 30 delete p_instance;
jhnwkmn 0:6f55c7651ccc 31 }
jhnwkmn 0:6f55c7651ccc 32
jhnwkmn 0:6f55c7651ccc 33 static SQBIND_INLINE SqMbed::Ticker& get_empty() {
jhnwkmn 0:6f55c7651ccc 34 // if someone tries to assign, this will crash.
jhnwkmn 0:6f55c7651ccc 35 // however, this will likely never be called anyway.
jhnwkmn 0:6f55c7651ccc 36 static SqMbed::Ticker *crashplease=NULL;
jhnwkmn 0:6f55c7651ccc 37 return *crashplease;
jhnwkmn 0:6f55c7651ccc 38 }
jhnwkmn 0:6f55c7651ccc 39 };
jhnwkmn 0:6f55c7651ccc 40
jhnwkmn 0:6f55c7651ccc 41 namespace SqMbed
jhnwkmn 0:6f55c7651ccc 42 {
jhnwkmn 0:6f55c7651ccc 43
jhnwkmn 0:6f55c7651ccc 44 Ticker::Ticker(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 45 : Trigger(vm)
jhnwkmn 0:6f55c7651ccc 46 {
jhnwkmn 0:6f55c7651ccc 47 }
jhnwkmn 0:6f55c7651ccc 48
jhnwkmn 0:6f55c7651ccc 49 Ticker::~Ticker()
jhnwkmn 0:6f55c7651ccc 50 {
jhnwkmn 0:6f55c7651ccc 51 }
jhnwkmn 0:6f55c7651ccc 52
jhnwkmn 0:6f55c7651ccc 53 void Ticker::attach(HSQOBJECT o, float t)
jhnwkmn 0:6f55c7651ccc 54 {
jhnwkmn 0:6f55c7651ccc 55 Trigger::attach(o);
jhnwkmn 0:6f55c7651ccc 56
jhnwkmn 0:6f55c7651ccc 57 void (Ticker::*pTrigger)() = &Ticker::triggered;
jhnwkmn 0:6f55c7651ccc 58
jhnwkmn 0:6f55c7651ccc 59 m_ticker.attach(this, pTrigger, t);
jhnwkmn 0:6f55c7651ccc 60 }
jhnwkmn 0:6f55c7651ccc 61
jhnwkmn 0:6f55c7651ccc 62 void Ticker::detach()
jhnwkmn 0:6f55c7651ccc 63 {
jhnwkmn 0:6f55c7651ccc 64 m_ticker.detach();
jhnwkmn 0:6f55c7651ccc 65 }
jhnwkmn 0:6f55c7651ccc 66
jhnwkmn 0:6f55c7651ccc 67 // static
jhnwkmn 0:6f55c7651ccc 68 void Ticker::bind(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 69 {
jhnwkmn 0:6f55c7651ccc 70 SqBind<Ticker>::init(vm, _SC("Ticker"));
jhnwkmn 0:6f55c7651ccc 71
jhnwkmn 0:6f55c7651ccc 72 sqbind_method(vm, "attach", &Ticker::attach);
jhnwkmn 0:6f55c7651ccc 73 sqbind_method(vm, "detach", &Ticker::detach);
jhnwkmn 0:6f55c7651ccc 74 }
jhnwkmn 0:6f55c7651ccc 75
jhnwkmn 0:6f55c7651ccc 76 }