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/pwmout.h>
jhnwkmn 0:6f55c7651ccc 6
jhnwkmn 0:6f55c7651ccc 7 namespace SqMbed
jhnwkmn 0:6f55c7651ccc 8 {
jhnwkmn 0:6f55c7651ccc 9
jhnwkmn 0:6f55c7651ccc 10 PwmOut::PwmOut(PinName pin)
jhnwkmn 0:6f55c7651ccc 11 : m_pwmOut(pin)
jhnwkmn 0:6f55c7651ccc 12 {
jhnwkmn 0:6f55c7651ccc 13 }
jhnwkmn 0:6f55c7651ccc 14
jhnwkmn 0:6f55c7651ccc 15 PwmOut::~PwmOut()
jhnwkmn 0:6f55c7651ccc 16 {
jhnwkmn 0:6f55c7651ccc 17 }
jhnwkmn 0:6f55c7651ccc 18
jhnwkmn 0:6f55c7651ccc 19 void PwmOut::write(float value)
jhnwkmn 0:6f55c7651ccc 20 {
jhnwkmn 0:6f55c7651ccc 21 m_pwmOut.write(value);
jhnwkmn 0:6f55c7651ccc 22 }
jhnwkmn 0:6f55c7651ccc 23
jhnwkmn 0:6f55c7651ccc 24 float PwmOut::read() const
jhnwkmn 0:6f55c7651ccc 25 {
jhnwkmn 0:6f55c7651ccc 26 return m_pwmOut.read();
jhnwkmn 0:6f55c7651ccc 27 }
jhnwkmn 0:6f55c7651ccc 28
jhnwkmn 0:6f55c7651ccc 29 void PwmOut::period(float seconds)
jhnwkmn 0:6f55c7651ccc 30 {
jhnwkmn 0:6f55c7651ccc 31 m_pwmOut.period(seconds);
jhnwkmn 0:6f55c7651ccc 32 }
jhnwkmn 0:6f55c7651ccc 33
jhnwkmn 0:6f55c7651ccc 34 void PwmOut::period_ms(int ms)
jhnwkmn 0:6f55c7651ccc 35 {
jhnwkmn 0:6f55c7651ccc 36 m_pwmOut.period_ms(ms);
jhnwkmn 0:6f55c7651ccc 37 }
jhnwkmn 0:6f55c7651ccc 38
jhnwkmn 0:6f55c7651ccc 39 void PwmOut::period_us(int us)
jhnwkmn 0:6f55c7651ccc 40 {
jhnwkmn 0:6f55c7651ccc 41 m_pwmOut.period_us(us);
jhnwkmn 0:6f55c7651ccc 42 }
jhnwkmn 0:6f55c7651ccc 43
jhnwkmn 0:6f55c7651ccc 44 void PwmOut::pulsewidth(float seconds)
jhnwkmn 0:6f55c7651ccc 45 {
jhnwkmn 0:6f55c7651ccc 46 m_pwmOut.pulsewidth(seconds);
jhnwkmn 0:6f55c7651ccc 47 }
jhnwkmn 0:6f55c7651ccc 48
jhnwkmn 0:6f55c7651ccc 49 void PwmOut::pulsewidth_ms(int ms)
jhnwkmn 0:6f55c7651ccc 50 {
jhnwkmn 0:6f55c7651ccc 51 m_pwmOut.pulsewidth_ms(ms);
jhnwkmn 0:6f55c7651ccc 52 }
jhnwkmn 0:6f55c7651ccc 53
jhnwkmn 0:6f55c7651ccc 54 void PwmOut::pulsewidth_us(int us)
jhnwkmn 0:6f55c7651ccc 55 {
jhnwkmn 0:6f55c7651ccc 56 m_pwmOut.pulsewidth_us(us);
jhnwkmn 0:6f55c7651ccc 57 }
jhnwkmn 0:6f55c7651ccc 58
jhnwkmn 0:6f55c7651ccc 59 // static
jhnwkmn 0:6f55c7651ccc 60 void PwmOut::bind(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 61 {
jhnwkmn 0:6f55c7651ccc 62 SqBind<PwmOut>::init(vm, _SC("PwmOut"));
jhnwkmn 0:6f55c7651ccc 63 SqBind<PwmOut>::set_custom_constructor(&PwmOut::constructor);
jhnwkmn 0:6f55c7651ccc 64 sqbind_method(vm, "write", &PwmOut::write);
jhnwkmn 0:6f55c7651ccc 65 sqbind_method(vm, "read", &PwmOut::read);
jhnwkmn 0:6f55c7651ccc 66 sqbind_method(vm, "period", &PwmOut::period);
jhnwkmn 0:6f55c7651ccc 67 sqbind_method(vm, "period_ms", &PwmOut::period_ms);
jhnwkmn 0:6f55c7651ccc 68 sqbind_method(vm, "period_us", &PwmOut::period_us);
jhnwkmn 0:6f55c7651ccc 69 sqbind_method(vm, "pulsewidth", &PwmOut::pulsewidth);
jhnwkmn 0:6f55c7651ccc 70 sqbind_method(vm, "pulsewidth_ms", &PwmOut::pulsewidth_ms);
jhnwkmn 0:6f55c7651ccc 71 sqbind_method(vm, "pulsewidth_us", &PwmOut::pulsewidth_us);
jhnwkmn 0:6f55c7651ccc 72 }
jhnwkmn 0:6f55c7651ccc 73
jhnwkmn 0:6f55c7651ccc 74 // static
jhnwkmn 0:6f55c7651ccc 75 PwmOut* PwmOut::constructor(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 76 {
jhnwkmn 0:6f55c7651ccc 77 PwmOut* pThis = 0;
jhnwkmn 0:6f55c7651ccc 78
jhnwkmn 0:6f55c7651ccc 79 int nParams = sq_gettop(vm);
jhnwkmn 0:6f55c7651ccc 80
jhnwkmn 0:6f55c7651ccc 81 if (nParams == 2) { // Need 1 (sic) params.
jhnwkmn 0:6f55c7651ccc 82 SQInteger i;
jhnwkmn 0:6f55c7651ccc 83
jhnwkmn 0:6f55c7651ccc 84 if (!SQ_FAILED(sq_getinteger(vm, 2, &i))) {
jhnwkmn 0:6f55c7651ccc 85 pThis = new PwmOut(static_cast<PinName>(i));
jhnwkmn 0:6f55c7651ccc 86 } else {
jhnwkmn 0:6f55c7651ccc 87 printf("error: Could not get PinName.");
jhnwkmn 0:6f55c7651ccc 88 }
jhnwkmn 0:6f55c7651ccc 89 } else {
jhnwkmn 0:6f55c7651ccc 90 printf("error: nParams != 2\n");
jhnwkmn 0:6f55c7651ccc 91 }
jhnwkmn 0:6f55c7651ccc 92
jhnwkmn 0:6f55c7651ccc 93 return pThis;
jhnwkmn 0:6f55c7651ccc 94 }
jhnwkmn 0:6f55c7651ccc 95
jhnwkmn 0:6f55c7651ccc 96 }