2 Replies Latest reply on Apr 28, 2013 10:11 PM by userc_43267

    Porting C++ files

      When I heard about PSoC 4 and the board being compatible with Arduino shields, I was wondering how I can port al the C++ files of arduino library to be ported to PSoC Creator. Can I write any code in C++. Is it possible?


      If at all if I were to compile C++ files in PSoC Creator, how do I change the physical layer of that library.

        • 1. Re: Porting C++ files
                  Hi, This article introduce the way to use c++ in PSoC, Might help for you. http://www.psocdeveloper.com/forums/viewtopic.php?f=43&t=8086 Anyway, Even in this way has some problems, because PSoC is using user module's code wrote by C. Someone want to use c++ who have to add wrapping software for the user modules. Do you do that?   
          • 2. Re: Porting C++ files

            I write PSoC code with C++, and have written a small tutorial about how to do it here...http://cladlab.com/programming/microcontrollers/psoc/using-cplusplus-with-psoc-creator.


            Getting PSoC Creator to compile C++ is the first step, you will still have to do things like convert non-standard data types and port any code the accesses hardware peripherals, system features (the PSoC and ATmega are different).


            If you want to go to C, then Google porting Arduino code to C, there are many resources on this, and it doesn't matter if they were not doing it to go to a PSoC, most of it will be same, thanks to the portability to C (and C++) code. However, if you do this, you will loose all the nice stuff you could do with the Arduino, like for example,


            LiquidCrystal lcd(12, 13, ..)




            You can of course create structures in C which emulate the classes in C++, but you will have to pass in the structure to the member functions, and associating functions with the structures (to emulate member functions in C++), will mean having to use function pointers and consequentially functions pointers to call them. In other words, not nice, and I reckon it's better to try the C++ way first, and then fall back to C if you have to.