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.

Revision:
0:6f55c7651ccc
Child:
1:540008bb92a2
diff -r 000000000000 -r 6f55c7651ccc sqmbed/src/pwmout.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sqmbed/src/pwmout.cpp	Tue Dec 16 12:54:53 2014 +0000
@@ -0,0 +1,96 @@
+/*
+  @License@
+*/
+
+#include <sqmbed/pwmout.h>
+
+namespace SqMbed
+{
+
+PwmOut::PwmOut(PinName pin)
+    : m_pwmOut(pin)
+{
+}
+
+PwmOut::~PwmOut()
+{
+}
+
+void PwmOut::write(float value)
+{
+    m_pwmOut.write(value);
+}
+
+float PwmOut::read() const
+{
+    return m_pwmOut.read();
+}
+
+void PwmOut::period(float seconds)
+{
+    m_pwmOut.period(seconds);
+}
+
+void PwmOut::period_ms(int ms)
+{
+    m_pwmOut.period_ms(ms);
+}
+
+void PwmOut::period_us(int us)
+{
+    m_pwmOut.period_us(us);
+}
+
+void PwmOut::pulsewidth(float seconds)
+{
+    m_pwmOut.pulsewidth(seconds);
+}
+
+void PwmOut::pulsewidth_ms(int ms)
+{
+    m_pwmOut.pulsewidth_ms(ms);
+}
+
+void PwmOut::pulsewidth_us(int us)
+{
+    m_pwmOut.pulsewidth_us(us);
+}
+
+// static
+void PwmOut::bind(HSQUIRRELVM vm)
+{
+    SqBind<PwmOut>::init(vm, _SC("PwmOut"));
+    SqBind<PwmOut>::set_custom_constructor(&PwmOut::constructor);
+    sqbind_method(vm, "write", &PwmOut::write);
+    sqbind_method(vm, "read", &PwmOut::read);
+    sqbind_method(vm, "period", &PwmOut::period);
+    sqbind_method(vm, "period_ms", &PwmOut::period_ms);
+    sqbind_method(vm, "period_us", &PwmOut::period_us);
+    sqbind_method(vm, "pulsewidth", &PwmOut::pulsewidth);
+    sqbind_method(vm, "pulsewidth_ms", &PwmOut::pulsewidth_ms);
+    sqbind_method(vm, "pulsewidth_us", &PwmOut::pulsewidth_us);
+}
+
+// static
+PwmOut* PwmOut::constructor(HSQUIRRELVM vm)
+{
+    PwmOut* pThis = 0;
+
+    int nParams = sq_gettop(vm);
+
+    if (nParams == 2) { // Need 1 (sic) params.
+        SQInteger i;
+
+        if (!SQ_FAILED(sq_getinteger(vm, 2, &i))) {
+            pThis = new PwmOut(static_cast<PinName>(i));
+        } else {
+            printf("error: Could not get PinName.");
+        }
+    } else {
+        printf("error: nParams != 2\n");
+    }
+
+    return pThis;
+}
+
+}