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.
sqmbed/src/digitalout.cpp@0:6f55c7651ccc, 2014-12-16 (annotated)
- 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?
User | Revision | Line number | New 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/digitalout.h> |
jhnwkmn | 0:6f55c7651ccc | 6 | |
jhnwkmn | 0:6f55c7651ccc | 7 | template<> |
jhnwkmn | 0:6f55c7651ccc | 8 | struct SqBindAllocator<SqMbed::DigitalOut> { |
jhnwkmn | 0:6f55c7651ccc | 9 | static SQBIND_INLINE SqMbed::DigitalOut *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::DigitalOut *copy_construct(const SqMbed::DigitalOut* 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::DigitalOut* p_val, const SqMbed::DigitalOut* 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::DigitalOut* 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::DigitalOut& 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::DigitalOut *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 | DigitalOut::DigitalOut(PinName pin) |
jhnwkmn | 0:6f55c7651ccc | 37 | : m_digOut(pin) |
jhnwkmn | 0:6f55c7651ccc | 38 | { |
jhnwkmn | 0:6f55c7651ccc | 39 | } |
jhnwkmn | 0:6f55c7651ccc | 40 | |
jhnwkmn | 0:6f55c7651ccc | 41 | DigitalOut::~DigitalOut() |
jhnwkmn | 0:6f55c7651ccc | 42 | { |
jhnwkmn | 0:6f55c7651ccc | 43 | } |
jhnwkmn | 0:6f55c7651ccc | 44 | |
jhnwkmn | 0:6f55c7651ccc | 45 | void DigitalOut::write(int value) |
jhnwkmn | 0:6f55c7651ccc | 46 | { |
jhnwkmn | 0:6f55c7651ccc | 47 | m_digOut.write(value); |
jhnwkmn | 0:6f55c7651ccc | 48 | } |
jhnwkmn | 0:6f55c7651ccc | 49 | |
jhnwkmn | 0:6f55c7651ccc | 50 | int DigitalOut::read() const |
jhnwkmn | 0:6f55c7651ccc | 51 | { |
jhnwkmn | 0:6f55c7651ccc | 52 | return m_digOut.read(); |
jhnwkmn | 0:6f55c7651ccc | 53 | } |
jhnwkmn | 0:6f55c7651ccc | 54 | |
jhnwkmn | 0:6f55c7651ccc | 55 | // static |
jhnwkmn | 0:6f55c7651ccc | 56 | void DigitalOut::bind(HSQUIRRELVM vm) |
jhnwkmn | 0:6f55c7651ccc | 57 | { |
jhnwkmn | 0:6f55c7651ccc | 58 | SqBind<DigitalOut>::init(vm, _SC("DigitalOut")); |
jhnwkmn | 0:6f55c7651ccc | 59 | SqBind<DigitalOut>::set_custom_constructor(&DigitalOut::constructor); |
jhnwkmn | 0:6f55c7651ccc | 60 | sqbind_method(vm, "write", &DigitalOut::write); |
jhnwkmn | 0:6f55c7651ccc | 61 | sqbind_method(vm, "read", &DigitalOut::read); |
jhnwkmn | 0:6f55c7651ccc | 62 | } |
jhnwkmn | 0:6f55c7651ccc | 63 | |
jhnwkmn | 0:6f55c7651ccc | 64 | // static |
jhnwkmn | 0:6f55c7651ccc | 65 | DigitalOut* DigitalOut::constructor(HSQUIRRELVM vm) |
jhnwkmn | 0:6f55c7651ccc | 66 | { |
jhnwkmn | 0:6f55c7651ccc | 67 | DigitalOut* pThis = 0; |
jhnwkmn | 0:6f55c7651ccc | 68 | |
jhnwkmn | 0:6f55c7651ccc | 69 | int nParams = sq_gettop(vm); |
jhnwkmn | 0:6f55c7651ccc | 70 | |
jhnwkmn | 0:6f55c7651ccc | 71 | if (nParams == 2) { // Need 1 (sic) params. |
jhnwkmn | 0:6f55c7651ccc | 72 | SQInteger i; |
jhnwkmn | 0:6f55c7651ccc | 73 | |
jhnwkmn | 0:6f55c7651ccc | 74 | if (!SQ_FAILED(sq_getinteger(vm, 2, &i))) { |
jhnwkmn | 0:6f55c7651ccc | 75 | pThis = new DigitalOut(static_cast<PinName>(i)); |
jhnwkmn | 0:6f55c7651ccc | 76 | } else { |
jhnwkmn | 0:6f55c7651ccc | 77 | printf("Could not get integer."); |
jhnwkmn | 0:6f55c7651ccc | 78 | } |
jhnwkmn | 0:6f55c7651ccc | 79 | } else { |
jhnwkmn | 0:6f55c7651ccc | 80 | printf("nParams != 2\n"); |
jhnwkmn | 0:6f55c7651ccc | 81 | } |
jhnwkmn | 0:6f55c7651ccc | 82 | |
jhnwkmn | 0:6f55c7651ccc | 83 | return pThis; |
jhnwkmn | 0:6f55c7651ccc | 84 | } |
jhnwkmn | 0:6f55c7651ccc | 85 | |
jhnwkmn | 0:6f55c7651ccc | 86 | } |