From Spin1 to Spin2
I've had the opportunity to convert a lot of Spin1 to Spin2 and find myself running a bit of a routine. With more people trying the P2, I thought I'd move comments I left in another thread to make them available to a wider audience. Opinions expressed here are my own, and as ever, I appreciate your thoughtful feedback.
In most cases, moving from the P1 to the P2 doesn't involve a lot of drama. This is what I do:
- Use SaveAs to make a copy of the file with the .spin2 extension
- Add blank parenthesis to method names/calls that don't have parameters.
- Declare return value by name (after colon) for methods that return a value
P1: pub get_temp P2: pub get_temp() : tempC
- Replace/remove P1 objects/calls (e.g., I no longer need my jm_time_80.spin object)
- Use F9 to compile P2 file and work through required changes
I'm taking an online Python programming course, so I though I'd write a little utility that will hunt through a Spin1 file and look for operators and keywords that need to change -- a few P1 operators will not flag a P2 compiler error, but won't work properly, either. The Spin2 compiler will tell where a problem exists, but not how to fix it. The idea behind this little program is to provide hints. This is the output from a test.
Processing d:/programming/p1_spin/jm_max7219_demo.spin 0139 t := cnt * (p1) cnt @Col 6 --> (p2) getct 0142 waitcnt(t += constant(100 * MS_001)) ' hold 1/10th second * (p1) waitcnt @Col 1 --> (p2) waitct * (p1) constant @Col 14 --> (p2) N/A 0207 prng.seed(-cnt, -cnt ~> 2, $CAFE_BABE, cnt <- 2, cnt) ' seed randomizer * (p1) ~> @Col 22 --> (p2) sar * (p1) <- @Col 44 --> (p2) rol Done. 5 suggestions in 3 lines.
This is version 1, so if you're a Python programmer, please feel free to jump in and improve it -- again, I'm a newish Python programmer so it would be nice to see ideas from others.
Not everything is going to be an easy fix. The P2 doesn't have counters like the P1, so we'll have to use code or smart pins in P2 updates. There are no waitxxx instructions, so those situations will have to be dealt with differently. This doesn't look at any PASM instructions -- that's a detailed process, anyway.
Note: Remove ".txt" from end of filename before attempting to run.