This is the open source Pawn interpreter ported to mbed. See here: http://www.compuphase.com/pawn/pawn.htm and here: http://code.google.com/p/pawnscript/

Dependents:   Pawn4Test

Some instructions:

  • Put the attached include folder next to your source, so when you compile you get all the proper definitions
  • Use the attached main.p as a starting point if you wish
  • Compile your main.p into main.amx - Put your main.amx on the mbed 'drive'
  • Reset and be amazed.

Important Compile Notes:

  • You should use the -S# option to define a smaller default stack size. Start with -S64 and go up from there if needed.
  • To use on the Cortex-M0 version of the mbed (LPC11U24), you MUST include the TARGET=3 command-line option as well, so the pin names are properly defined. In the future this may be handled on the native code side.

Known Issues:

  • At the moment it appears the kbhit() function is not working right - at least on my mac. Will continue testing on Windows. Working fine.

Todo:

  • Add more wrappers for the mbed peripherals
  • Add Pawn overlay support, to allow much larger scripts to run (even on the LPC11U24)

Files at this revision

API Documentation at this revision

Comitter:
Lobo
Date:
Fri May 24 17:49:26 2013 +0000
Parent:
2:01588bd27169
Commit message:
Now includes AnalogIn and AnalogOut functions

Changed in this revision

amxmbed.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 01588bd27169 -r 185fdbb7ccf0 amxmbed.cpp
--- a/amxmbed.cpp	Wed May 22 16:30:01 2013 +0000
+++ b/amxmbed.cpp	Fri May 24 17:49:26 2013 +0000
@@ -120,7 +120,7 @@
 static cell AMX_NATIVE_CALL n_digitalClose(AMX *amx, const cell *params)
 {
 //    port->printf("digitalClose\n\r");
-    (void)amx;
+    //(void)amx;
     DigitalOut* obj = (DigitalOut*)params[1];
     if (obj)
     {
@@ -130,6 +130,94 @@
     return 0;
 }
 
+static cell AMX_NATIVE_CALL n_analogInOpen(AMX * amx, const cell *params)
+{
+    (void)amx;
+    AnalogIn* self = new AnalogIn((PinName)params[1]);
+    
+    return (cell)self;
+}
+
+static cell AMX_NATIVE_CALL n_analogInClose(AMX *amx, const cell params[])
+{
+    (void)amx;
+    AnalogIn* obj = (AnalogIn*)params[1];
+    
+    if(obj)
+    {
+        return(obj->read());
+    }
+    
+    return 0;
+}
+
+static cell AMX_NATIVE_CALL n_analogInRead(AMX *amx, const cell params[])
+{
+    (void)amx;
+    AnalogIn* obj = (AnalogIn*)params[1];
+    
+    if(obj)
+    {
+        float voltage = obj->read();
+    
+        port->printf("%f read from analog in pin \n\r",voltage);
+        return(amx_ftoc(voltage));
+    }
+    
+    return 0;
+}
+
+static cell AMX_NATIVE_CALL n_analogOutOpen(AMX *amx, const cell params[])
+{
+    (void)amx;
+    AnalogOut* self = new AnalogOut((PinName)params[1]);
+    
+    return (cell)self;
+}
+
+static cell AMX_NATIVE_CALL n_analogOutRead(AMX *amx, const cell params[])
+{
+    (void)amx;
+    AnalogOut* obj = (AnalogOut*)params[1];
+    
+    if(obj)
+    {
+        float voltage = obj->read();
+        port->printf("reading voltage of %f in analog out pin\n\r",voltage);
+    
+        return(amx_ftoc(voltage));
+    }
+    
+    return 0;
+}
+
+static cell AMX_NATIVE_CALL n_analogOutWrite(AMX *amx, const cell params[])
+{
+    (void)amx;
+    AnalogOut* obj = (AnalogOut*)params[1];
+    
+    if(obj)
+    {
+        float voltage = amx_ctof(params[2]);
+        port->printf("writing voltage of %f to analog out pin\n\r",voltage);
+        obj->write(voltage);
+    }
+    
+    return(0);
+}
+
+static cell AMX_NATIVE_CALL n_analogOutClose(AMX* amx, const cell params[])
+{
+    (void)amx;
+    AnalogOut* obj = (AnalogOut*)params[1];
+    
+    if(obj)
+    {
+        delete obj;
+    }
+    return 0;
+}
+
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
 static cell AMX_NATIVE_CALL n_wait(AMX *amx, const cell *params)
 {
@@ -168,6 +256,13 @@
   { "digitalRead",   n_digitalRead },
   { "digitalWrite",  n_digitalWrite },
   { "digitalClose",  n_digitalClose },
+  { "analogInOpen",  n_analogInOpen },
+  { "analogInClose", n_analogInClose },
+  { "analogInRead",  n_analogInRead },
+  { "analogOutOpen", n_analogOutOpen },
+  { "analogOutRead", n_analogOutRead },
+  { "analogOutWrite", n_analogOutWrite },
+  { "analogOutClose", n_analogOutClose },
   
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
   { "wait",   n_wait },   // uses a float, which we do not support on LPC11U24 version