Shop OBEX P1 Docs P2 Docs Learn Events
P2 FlexProp Arduino to P2 — Parallax Forums

P2 FlexProp Arduino to P2

pic18f2550pic18f2550 Posts: 400
edited 2021-06-30 11:17 in Propeller 2

Hello,

I have a few questions about porting an Arduino program to the P2 with FlexProp.

The last C was over 20 years ago :(

I get an error message at the following point.

typedef struct {
  int16_t Phase[9];
  int16_t Power[9];
} lift_t;

syntax error, unexpected identifier `int16_t'.

const char text[] PROGMEM =
  "Antrieb 1;"
  "Bremse 1;"
;

syntax error, unexpected identifier `PROGMEM', expecting ',' or ';'

Comments

  • I get an error message at the following point.

    typedef struct {
      int16_t Phase[9];
      int16_t Power[9];
    } lift_t;
    
    

    syntax error, unexpected identifier `int16_t'.

    Add an include <stdint.h>

    const char text[] PROGMEM =
      "Antrieb 1;"
      "Bremse 1;"
    ;
    
    

    syntax error, unexpected identifier `PROGMEM', expecting ',' or ';'

    PROGMEM places data in the flash memory of the Arduino's AVR processor. Since that's not applicable to P2, you can either just remove it or #define it to nothing (i.e. just #define PROGMEM with nothing else on the line)

  • pic18f2550pic18f2550 Posts: 400
    edited 2021-06-30 13:07

    So these files I have thrown out for now because they are not suitable for the P2.

    include <avr/io.h>
    include "Arduino.h"
    include <avr/pgmspace.h>

    I hope that the rest is kept within limits.

    bool newFrame(uint8_t c);
    

    unexpected identifier `newFrame', expecting '{'

    Is there no bool?
    If I turn bool into e.g. int_8 there are no problems.

    int8_t newFrame(uint8_t c);
    
  • Arduino code is C++, but FlexProp only really supports C (with a tiny bit of C++). If you name your files with a .cc or .cpp extension that will cause the limited extra support for C++ to be active in FlexProp, but be prepared for many things to be missing.

    (That said, "bool" should be easy to support in C++ mode, but it isn't right now -- you have to manually add #include <stdbool.h> to the file.)

  • RaymanRayman Posts: 14,640
    edited 2021-06-30 16:34

    I've ported several Arduino programs over to FlexProp C.
    Here are my notes for converting a Gameduino program:

    To convert a GD2 Arduino sketch to GD2MO program:
    1. Rename extention from .ino to .c
    2. Replace top of file includes (#include <EEPROM.h>, #include <SPI.h>, #include <GD2.h>) with #include GD2MO.h
    3. Replace all GD. with nothing
    4. "random()" calls with 1 parameter replaced with "random1()". Two parameters --> "random2()"
    5. replace empty "draw()" with "draw(0)"
    6. replace Vertex2ii() calls with four parameters to Vertex2ii4(), three parameters to Vertex2ii3(), two parameters as is
    7. If the assets file has a long filename, may need to write out full filename if using Plan 9 to access host files
    8. Delete Arduino things like "static const PROGMEM"
    9. Some examples need a file from either uSD (USE_SD defined in Platform.h) or system (USE_HOST defined in Platform.h). File name specified in _assets.h
    10. Things like "pgm_read_byte_near(p++);" become "(byte)
    (p++);"
    11. Replace micros with _getus and millis with _getms
    12. Comment out Serial.begin(115200);
    13. Include "math.h" if things like sin or cos used
    14. Define M_PI if needed
    15. Classes need to be converted to typedef struct (see FlexSpin C documentation)

    Note: Some of the above is specific to Gameduino and not general Arduino...

  • RaymanRayman Posts: 14,640

    The above is from a few months ago... These days, I like to include a "Platform.h" file that has most all includes and defines needed. Like the attached.

    h
    h
    747B
Sign In or Register to comment.