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 13:32:06 2014 +0000
Revision:
2:0df9688c9a11
Parent:
1:540008bb92a2
Updated libraries.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:6f55c7651ccc 1 /*
jhnwkmn 1:540008bb92a2 2 Copyright 2014 Johan Wikman
jhnwkmn 1:540008bb92a2 3
jhnwkmn 1:540008bb92a2 4 Licensed under the Apache License, Version 2.0 (the "License");
jhnwkmn 1:540008bb92a2 5 you may not use this file except in compliance with the License.
jhnwkmn 1:540008bb92a2 6 You may obtain a copy of the License at
jhnwkmn 1:540008bb92a2 7
jhnwkmn 1:540008bb92a2 8 http://www.apache.org/licenses/LICENSE-2.0
jhnwkmn 1:540008bb92a2 9
jhnwkmn 1:540008bb92a2 10 Unless required by applicable law or agreed to in writing, software
jhnwkmn 1:540008bb92a2 11 distributed under the License is distributed on an "AS IS" BASIS,
jhnwkmn 1:540008bb92a2 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jhnwkmn 1:540008bb92a2 13 See the License for the specific language governing permissions and
jhnwkmn 1:540008bb92a2 14 limitations under the License.
jhnwkmn 0:6f55c7651ccc 15 */
jhnwkmn 0:6f55c7651ccc 16
jhnwkmn 0:6f55c7651ccc 17 #include <sqmbed/digitalin.h>
jhnwkmn 0:6f55c7651ccc 18
jhnwkmn 0:6f55c7651ccc 19 SQBIND_INTEGER(PinMode);
jhnwkmn 0:6f55c7651ccc 20
jhnwkmn 0:6f55c7651ccc 21 template<>
jhnwkmn 0:6f55c7651ccc 22 struct SqBindAllocator<SqMbed::DigitalIn> {
jhnwkmn 0:6f55c7651ccc 23 static SQBIND_INLINE SqMbed::DigitalIn *construct(HSQUIRRELVM) {
jhnwkmn 0:6f55c7651ccc 24 return NULL; // make it not able to construct
jhnwkmn 0:6f55c7651ccc 25 }
jhnwkmn 0:6f55c7651ccc 26
jhnwkmn 0:6f55c7651ccc 27 static SQBIND_INLINE SqMbed::DigitalIn *copy_construct(const SqMbed::DigitalIn* p_from) {
jhnwkmn 0:6f55c7651ccc 28 return NULL; // make it not able to copy-construct
jhnwkmn 0:6f55c7651ccc 29 }
jhnwkmn 0:6f55c7651ccc 30
jhnwkmn 0:6f55c7651ccc 31 static SQBIND_INLINE bool assign(SqMbed::DigitalIn* p_val, const SqMbed::DigitalIn* p_from) {
jhnwkmn 0:6f55c7651ccc 32 return false; // make it not able to assign
jhnwkmn 0:6f55c7651ccc 33 }
jhnwkmn 0:6f55c7651ccc 34
jhnwkmn 0:6f55c7651ccc 35 static SQBIND_INLINE void destruct(SqMbed::DigitalIn* p_instance) {
jhnwkmn 0:6f55c7651ccc 36 delete p_instance;
jhnwkmn 0:6f55c7651ccc 37 }
jhnwkmn 0:6f55c7651ccc 38
jhnwkmn 0:6f55c7651ccc 39 static SQBIND_INLINE SqMbed::DigitalIn& get_empty() {
jhnwkmn 0:6f55c7651ccc 40 // if someone tries to assign, this will crash.
jhnwkmn 0:6f55c7651ccc 41 // however, this will likely never be called anyway.
jhnwkmn 0:6f55c7651ccc 42 static SqMbed::DigitalIn *crashplease=NULL;
jhnwkmn 0:6f55c7651ccc 43 return *crashplease;
jhnwkmn 0:6f55c7651ccc 44 }
jhnwkmn 0:6f55c7651ccc 45 };
jhnwkmn 0:6f55c7651ccc 46
jhnwkmn 0:6f55c7651ccc 47 namespace SqMbed
jhnwkmn 0:6f55c7651ccc 48 {
jhnwkmn 0:6f55c7651ccc 49
jhnwkmn 0:6f55c7651ccc 50 DigitalIn::DigitalIn(PinName pin)
jhnwkmn 0:6f55c7651ccc 51 : m_digIn(pin)
jhnwkmn 0:6f55c7651ccc 52 {
jhnwkmn 0:6f55c7651ccc 53 }
jhnwkmn 0:6f55c7651ccc 54
jhnwkmn 0:6f55c7651ccc 55 DigitalIn::DigitalIn(PinName pin, PinMode mode)
jhnwkmn 0:6f55c7651ccc 56 : m_digIn(pin, mode)
jhnwkmn 0:6f55c7651ccc 57 {
jhnwkmn 0:6f55c7651ccc 58 }
jhnwkmn 0:6f55c7651ccc 59
jhnwkmn 0:6f55c7651ccc 60 DigitalIn::~DigitalIn()
jhnwkmn 0:6f55c7651ccc 61 {
jhnwkmn 0:6f55c7651ccc 62 }
jhnwkmn 0:6f55c7651ccc 63
jhnwkmn 0:6f55c7651ccc 64 int DigitalIn::read() const
jhnwkmn 0:6f55c7651ccc 65 {
jhnwkmn 0:6f55c7651ccc 66 return m_digIn.read();
jhnwkmn 0:6f55c7651ccc 67 }
jhnwkmn 0:6f55c7651ccc 68
jhnwkmn 0:6f55c7651ccc 69 void DigitalIn::mode(PinMode m)
jhnwkmn 0:6f55c7651ccc 70 {
jhnwkmn 0:6f55c7651ccc 71 m_digIn.mode(m);
jhnwkmn 0:6f55c7651ccc 72 }
jhnwkmn 0:6f55c7651ccc 73
jhnwkmn 0:6f55c7651ccc 74 // static
jhnwkmn 0:6f55c7651ccc 75 void DigitalIn::bind(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 76 {
jhnwkmn 0:6f55c7651ccc 77 SqBind<DigitalIn>::init(vm, _SC("DigitalIn"));
jhnwkmn 0:6f55c7651ccc 78 SqBind<DigitalIn>::set_custom_constructor(&DigitalIn::constructor);
jhnwkmn 0:6f55c7651ccc 79 sqbind_method(vm, "mode", &DigitalIn::mode);
jhnwkmn 0:6f55c7651ccc 80 sqbind_method(vm, "read", &DigitalIn::read);
jhnwkmn 0:6f55c7651ccc 81 }
jhnwkmn 0:6f55c7651ccc 82
jhnwkmn 0:6f55c7651ccc 83 // static
jhnwkmn 0:6f55c7651ccc 84 DigitalIn* DigitalIn::constructor(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 85 {
jhnwkmn 0:6f55c7651ccc 86 DigitalIn* pThis = 0;
jhnwkmn 0:6f55c7651ccc 87
jhnwkmn 0:6f55c7651ccc 88 int nParams = sq_gettop(vm);
jhnwkmn 0:6f55c7651ccc 89
jhnwkmn 0:6f55c7651ccc 90 if ((nParams == 2) || (nParams == 3)) { // Need 1 (sic) params.
jhnwkmn 0:6f55c7651ccc 91 SQInteger pin;
jhnwkmn 0:6f55c7651ccc 92
jhnwkmn 0:6f55c7651ccc 93 if (!SQ_FAILED(sq_getinteger(vm, 2, &pin))) {
jhnwkmn 0:6f55c7651ccc 94 if (nParams == 3) {
jhnwkmn 0:6f55c7651ccc 95 SQInteger mode;
jhnwkmn 0:6f55c7651ccc 96
jhnwkmn 0:6f55c7651ccc 97 if (!SQ_FAILED(sq_getinteger(vm, 3, &mode))) {
jhnwkmn 0:6f55c7651ccc 98 pThis = new DigitalIn(static_cast<PinName>(pin),
jhnwkmn 0:6f55c7651ccc 99 static_cast<PinMode>(mode));
jhnwkmn 0:6f55c7651ccc 100 } else {
jhnwkmn 0:6f55c7651ccc 101 printf("error: Invalid PinMode.\n");
jhnwkmn 0:6f55c7651ccc 102 }
jhnwkmn 0:6f55c7651ccc 103 } else {
jhnwkmn 0:6f55c7651ccc 104 pThis = new DigitalIn(static_cast<PinName>(pin));
jhnwkmn 0:6f55c7651ccc 105 }
jhnwkmn 0:6f55c7651ccc 106 } else {
jhnwkmn 0:6f55c7651ccc 107 printf("error: Invalid PinName.\n");
jhnwkmn 0:6f55c7651ccc 108 }
jhnwkmn 0:6f55c7651ccc 109 } else {
jhnwkmn 0:6f55c7651ccc 110 printf("error: 2 or 3 params.\n");
jhnwkmn 0:6f55c7651ccc 111 }
jhnwkmn 0:6f55c7651ccc 112
jhnwkmn 0:6f55c7651ccc 113 return pThis;
jhnwkmn 0:6f55c7651ccc 114 }
jhnwkmn 0:6f55c7651ccc 115
jhnwkmn 0:6f55c7651ccc 116 }