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