Shop OBEX P1 Docs P2 Docs Learn Events
Compile SPIN code from Flexprop — Parallax Forums

Compile SPIN code from Flexprop

disha_sudradisha_sudra Posts: 43
edited 2022-08-02 14:10 in PASM/Spin (P1)

Hello,
How can I call SPIN function in CPP file in Flexprop?

How to compile any sample SPIN code in Flexprop?

I'm trying to compile sample code given in below link.
https://github.com/totalspectrum/flexprop/blob/master/samples/blink1.spin2

Comments

  • JonnyMacJonnyMac Posts: 9,104
    edited 2022-08-02 16:58

    That demo you cite is Spin2, and works as-is (I just tested). Here's a similar program for the P1 -- if you have a FLiP or PAB you can run without any other hardware.

    con 
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      CLK_FREQ = (_clkmode >> 6) * _xinfreq  
      DELAY    = CLK_FREQ / 4
    
    
    con
    
      LED2 = 27
      LED1 = 26
    
    
    pub main | t
    
      outa[LED2..LED1] := %01
      dira[LED2..LED1] := true
    
      t := cnt
    
      repeat
        outa[LED2..LED1] ^= true
        waitcnt(t += DELAY)
    
  • @disha_sudra said:
    Hello,
    How can I call SPIN function in CPP file in Flexprop?

    Load the Spin file into a C struct, something like:

    // create C structure from the Spin2 blink demo
    struct __using("blink1.spin2") my_blink;
    
    void main() {
        // call the demo() function from blink1.spin2
        my_blink.demo();
    }
    

    How to compile any sample SPIN code in Flexprop?

    Just use File > Open to open the Spin file in the editor, and then Compile & Run (for P1 or P2 as appropriate). The language used is based on the file extension: .spin for Spin1, .spin2 for Spin2, .bas for BASIC, .c for C, .cpp for C++ (which is only partly supported).

  • Thank you.

  • RaymanRayman Posts: 14,646

    I think flexprop can compile spin2 code for P1, is that right?

  • @Rayman said:
    I think flexprop can compile spin2 code for P1, is that right?

    Yes, as long as no P2 specific hardware features are used.

Sign In or Register to comment.