4 Replies Latest reply on Oct 8, 2020 12:35 PM by MiMi_1891471

    Arduino library compatibility layer with PDL / HAL ?


      Has anyone found an easy way to use Arduino libraries for I2C or SPI devices, or some with GPIO with Cypress code?


      We all have the same problem, implement some mix of peripherals into our product. Like it or not, the most common drivers out there are written for the Arduino framework, so we should be able to just use them. Having to reinvent the wheel, by writing yet another driver (YAD), when there are tested ones available seems like such a waste of time. I don't want to YADa, YADa, YADa..., I want to build product. ;-)

        • 1. Re: Arduino library compatibility layer with PDL / HAL ?

          Hi MiMi_1891471,


          Unfortunately, there is no official support for Arduino libraries to be directly used with PSoC devices. As far as I know, most Arduino libraries have a lower-level function that directly interacts with the device like I2C write or read functions. Porting these functions to PDL/HAL drivers in the case of PSoC 6 devices or component-specific APIs in the case of the other PSoC devices should allow you to reuse most of the code in the library.


          That being said, I agree with you. It is a lot easier if a library is readily available. We are working on interfacing some of the common sensors with PSoC 6 devices and we will be releasing them as example projects here - GitHub - cypresssemiconductorco/Community-Code-Examples: Community Code Examples. So, if you have a recommendation then we would consider working on porting the driver file and interfacing it with PSoC 6 devices.


          Thank you for your feedback!


          Best regards,

          Rakshith M B

          • 2. Re: Arduino library compatibility layer with PDL / HAL ?

            I assume you want to use existing device libraries that call Arduino I2C and SPI functions? Rather than having some strange desire to use the Wire library to write I2C on PSoC? Most well written libraries abstract the communications section so you really only ever need to rewrite a handful of functions, since you only need wrappers that emulate the Arduino library API calls


            I wrote a bunch of such libraries/wrappers to be able to compile for PSoC hardware under the Arduino platform (and IDE). It was important to allow others who only had exposure to 'development' in an Arduino environment to be able to use the hardware but honestly you lose a lot by not using PSoC Creator along with the native PDL especially when it comes to assigning specific hardware peripherals to specific instances (Clocks, Timers etc.). I don't think anyone on the development team would have any reason to use the Arduino stuff, it's more for other people not willing or able to learn the native IDE.


            I haven't used ModusToolbox yet although this is a PSoC6 based hardware. Also embedded system shouldn't be using C++ (AFAIK PSoC Creator doesn't support C++).

            • 3. Re: Arduino library compatibility layer with PDL / HAL ?

              The wire library is generally not very difficult to deal with.  Depending on the driver I just implement those functions with the HAL or PDL.


              The more painful part to deal with is those libraries are typically written in C++ ... and unless you whole application is C++ is difficult to deal with.


              I typically just do a manual port to C... but as you observed that is a bunch of re-writing... so yes its painful.


              PSoC 6 and MTB support C++ so you can also that.


              PaSw_2579927 suggests that you should not write C++ on embedded... I suppose that I am not as dogmatic about that as there are many places where people do that... including Arduino.  But for sure he is right that care should be taken.

              • 4. Re: Arduino library compatibility layer with PDL / HAL ?

                Thanks, so we all seem to agree it would be a nice feature to have an abstraction layer that is Arduino compatible. It may not even be that difficult, which is really why I'm suggesting Cypress do it and make it part of the distribution. Or perhaps one of the other responders could release their abstraction layer as open source.


                Just getting the high level interface to any I2C parts a designer might use would be a boon. There is no need to make it part specific, that's what the Arduino libraries already do.