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/digitalinout.h>
jhnwkmn 0:6f55c7651ccc 6
jhnwkmn 0:6f55c7651ccc 7 template<>
jhnwkmn 0:6f55c7651ccc 8 struct SqBindAllocator<SqMbed::DigitalInOut> {
jhnwkmn 0:6f55c7651ccc 9 static SQBIND_INLINE SqMbed::DigitalInOut *construct(HSQUIRRELVM) {
jhnwkmn 0:6f55c7651ccc 10 return NULL; // make it not able to construct
jhnwkmn 0:6f55c7651ccc 11 }
jhnwkmn 0:6f55c7651ccc 12
jhnwkmn 0:6f55c7651ccc 13 static SQBIND_INLINE SqMbed::DigitalInOut *copy_construct(const SqMbed::DigitalInOut* p_from) {
jhnwkmn 0:6f55c7651ccc 14 return NULL; // make it not able to copy-construct
jhnwkmn 0:6f55c7651ccc 15 }
jhnwkmn 0:6f55c7651ccc 16
jhnwkmn 0:6f55c7651ccc 17 static SQBIND_INLINE bool assign(SqMbed::DigitalInOut* p_val, const SqMbed::DigitalInOut* p_from) {
jhnwkmn 0:6f55c7651ccc 18 return false; // make it not able to assign
jhnwkmn 0:6f55c7651ccc 19 }
jhnwkmn 0:6f55c7651ccc 20
jhnwkmn 0:6f55c7651ccc 21 static SQBIND_INLINE void destruct(SqMbed::DigitalInOut* p_instance) {
jhnwkmn 0:6f55c7651ccc 22 delete p_instance;
jhnwkmn 0:6f55c7651ccc 23 }
jhnwkmn 0:6f55c7651ccc 24
jhnwkmn 0:6f55c7651ccc 25 static SQBIND_INLINE SqMbed::DigitalInOut& get_empty() {
jhnwkmn 0:6f55c7651ccc 26 // if someone tries to assign, this will crash.
jhnwkmn 0:6f55c7651ccc 27 // however, this will likely never be called anyway.
jhnwkmn 0:6f55c7651ccc 28 static SqMbed::DigitalInOut *crashplease=NULL;
jhnwkmn 0:6f55c7651ccc 29 return *crashplease;
jhnwkmn 0:6f55c7651ccc 30 }
jhnwkmn 0:6f55c7651ccc 31 };
jhnwkmn 0:6f55c7651ccc 32
jhnwkmn 0:6f55c7651ccc 33 namespace SqMbed
jhnwkmn 0:6f55c7651ccc 34 {
jhnwkmn 0:6f55c7651ccc 35
jhnwkmn 0:6f55c7651ccc 36 DigitalInOut::DigitalInOut(PinName pin)
jhnwkmn 0:6f55c7651ccc 37 : m_digInOut(pin)
jhnwkmn 0:6f55c7651ccc 38 {
jhnwkmn 0:6f55c7651ccc 39 }
jhnwkmn 0:6f55c7651ccc 40
jhnwkmn 0:6f55c7651ccc 41 DigitalInOut::~DigitalInOut()
jhnwkmn 0:6f55c7651ccc 42 {
jhnwkmn 0:6f55c7651ccc 43 }
jhnwkmn 0:6f55c7651ccc 44
jhnwkmn 0:6f55c7651ccc 45 void DigitalInOut::write(int value)
jhnwkmn 0:6f55c7651ccc 46 {
jhnwkmn 0:6f55c7651ccc 47 m_digInOut.write(value);
jhnwkmn 0:6f55c7651ccc 48 }
jhnwkmn 0:6f55c7651ccc 49
jhnwkmn 0:6f55c7651ccc 50 int DigitalInOut::read() const
jhnwkmn 0:6f55c7651ccc 51 {
jhnwkmn 0:6f55c7651ccc 52 return m_digInOut.read();
jhnwkmn 0:6f55c7651ccc 53 }
jhnwkmn 0:6f55c7651ccc 54
jhnwkmn 0:6f55c7651ccc 55 void DigitalInOut::input()
jhnwkmn 0:6f55c7651ccc 56 {
jhnwkmn 0:6f55c7651ccc 57 m_digInOut.input();
jhnwkmn 0:6f55c7651ccc 58 }
jhnwkmn 0:6f55c7651ccc 59
jhnwkmn 0:6f55c7651ccc 60 void DigitalInOut::output()
jhnwkmn 0:6f55c7651ccc 61 {
jhnwkmn 0:6f55c7651ccc 62 m_digInOut.output();
jhnwkmn 0:6f55c7651ccc 63 }
jhnwkmn 0:6f55c7651ccc 64
jhnwkmn 0:6f55c7651ccc 65 void DigitalInOut::mode(PinMode m)
jhnwkmn 0:6f55c7651ccc 66 {
jhnwkmn 0:6f55c7651ccc 67 m_digInOut.mode(m);
jhnwkmn 0:6f55c7651ccc 68 }
jhnwkmn 0:6f55c7651ccc 69
jhnwkmn 0:6f55c7651ccc 70 // static
jhnwkmn 0:6f55c7651ccc 71 void DigitalInOut::bind(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 72 {
jhnwkmn 0:6f55c7651ccc 73 SqBind<DigitalInOut>::init(vm, _SC("DigitalInOut"));
jhnwkmn 0:6f55c7651ccc 74 SqBind<DigitalInOut>::set_custom_constructor(&DigitalInOut::constructor);
jhnwkmn 0:6f55c7651ccc 75 sqbind_method(vm, "read", &DigitalInOut::read);
jhnwkmn 0:6f55c7651ccc 76 sqbind_method(vm, "write", &DigitalInOut::write);
jhnwkmn 0:6f55c7651ccc 77 sqbind_method(vm, "input", &DigitalInOut::input);
jhnwkmn 0:6f55c7651ccc 78 sqbind_method(vm, "output", &DigitalInOut::output);
jhnwkmn 0:6f55c7651ccc 79 }
jhnwkmn 0:6f55c7651ccc 80
jhnwkmn 0:6f55c7651ccc 81 // static
jhnwkmn 0:6f55c7651ccc 82 DigitalInOut* DigitalInOut::constructor(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 83 {
jhnwkmn 0:6f55c7651ccc 84 DigitalInOut* pThis = 0;
jhnwkmn 0:6f55c7651ccc 85
jhnwkmn 0:6f55c7651ccc 86 int nParams = sq_gettop(vm);
jhnwkmn 0:6f55c7651ccc 87
jhnwkmn 0:6f55c7651ccc 88 if (nParams == 2) { // Need 1 (sic) params.
jhnwkmn 0:6f55c7651ccc 89 SQInteger i;
jhnwkmn 0:6f55c7651ccc 90
jhnwkmn 0:6f55c7651ccc 91 if (!SQ_FAILED(sq_getinteger(vm, 2, &i))) {
jhnwkmn 0:6f55c7651ccc 92 pThis = new DigitalInOut(static_cast<PinName>(i));
jhnwkmn 0:6f55c7651ccc 93 } else {
jhnwkmn 0:6f55c7651ccc 94 printf("Could not get integer.");
jhnwkmn 0:6f55c7651ccc 95 }
jhnwkmn 0:6f55c7651ccc 96 } else {
jhnwkmn 0:6f55c7651ccc 97 printf("nParams != 2\n");
jhnwkmn 0:6f55c7651ccc 98 }
jhnwkmn 0:6f55c7651ccc 99
jhnwkmn 0:6f55c7651ccc 100 return pThis;
jhnwkmn 0:6f55c7651ccc 101 }
jhnwkmn 0:6f55c7651ccc 102
jhnwkmn 0:6f55c7651ccc 103 }