• AVR Freaks

Hot!Are there any C++ libraries available?

Author
RodoPIC
Senior Member
  • Total Posts : 178
  • Reward points : 0
  • Status: offline
2019/05/16 10:17:39 (permalink)
0

Are there any C++ libraries available?

Hi all,
 
A quick google search didn't show anything useful. It looks like Microchip has the compiler for C++ but nothing else. Are there any libraries available for C++? free or for sale ok. I'm looking for PIC32MX and PIC43MZ stuff. Mostly curious because I wanted to "play" with C++ and see how it goes but I don't want to write every driver.  I'm not that good at C++. I mostly use the objects in visual studio c# but the classes are already done.
 
Thanks
#1

7 Replies Related Threads

    Bryan M. W. Samosir
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/05/14 09:04:04
    • Location: 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/05/16 10:51:12 (permalink)
    0
    You can use XC32++ including g++ compiler to your designated PIC32MX or PIC32MZ module from https://www.microchip.com/mplab/compilers . C++ supports string and boolean data type. Some examples of C++ library I often use are conio.h and iostream . I've not tried mingling XC32++ and generic C++ yet.
    #2
    RodoPIC
    Senior Member
    • Total Posts : 178
    • Reward points : 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/05/16 13:50:47 (permalink)
    0
    I should have been more specific when I said libraries. I mean peripheral libraries so I don't have to write SPI or I2C or ADC, etc. I suppose I could generate the code with the configurator (MCC) and put it in a class but .... I'm trying to get a feel of how much extra work is C++. Thanks. 
    #3
    cvm
    Super Member
    • Total Posts : 292
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/05/16 14:37:56 (permalink)
    0
    You can write your own 'drivers'. Its a bit of work, though-
     
    https://github.com/cv007/PIC32MM_Curiosity_CPP
     
    I did this as an experiment for a pic32mm(gpm). I went through every chapter of the datasheet and created a 'driver' class for each. It ends up being quite nice to use in practice, and you end up with readable/reliable code. I also added some handy features- a sprintf class with simple 'markup' language (colors) that output classes like uart/usb can inherit and create their own printf functions, a delay class which uses cp0 count, a reg class which handles setting/clearing bits using the set/clr registers as needed and also setting values according to the type passed in (byte/halfword/word access). Eventually I also figure out usb and created a class for that.
     
    I wish these manufacturers would embrace c++ - if done right they could end up with 'drivers' that could make things much easier to use.
     
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 17596
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/05/16 14:55:35 (permalink)
    0
    MCC does Not work with Most PIC32MX or any PIC32MZ.  That is Under Harmony.
    and Opens a Bigger can of Worms.  It has a PLIB like Library that you could use. But it is a Framework, that maybe more than you want.
    #5
    Larry.Standage
    Moderator
    • Total Posts : 904
    • Reward points : 0
    • Joined: 2011/12/30 09:50:47
    • Location: 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/05/16 16:15:00 (permalink)
    0
    I would like that as well. I've been tinkering with constexpr, as it is supported (C++11 with some C++14 extension) in the compiler. It would be nice to use templates and constexpr to generate really fast, small code for handling the peripherals.
    #6
    cvm
    Super Member
    • Total Posts : 292
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/05/16 16:46:06 (permalink)
    0
    >It would be nice to use templates and constexpr to generate really fast, small code for handling the peripherals.
     
    With only c++11 support, constexpr seems to end up limited (for constexpr functions anyway), unless you are a recursive coding guru.
     
    I am also using c++ for a tiny416-
    https://github.com/cv007/ATTiny416XplainedNano
    where I use templates and it is mostly just a collection of headers.
     
    The big advantage of the templates is you can end up with-
    PA0_OUTL_t led; //sets pin mode. output/low is on (4 instructions- pin mode and pin set to 'off')
    led.on(); //a single 'sbi 1, 0' (set bit since pin is in invert mode)
     
    The disadvantage when you get into templates, is it 'infects' everything and you end up having to use templates quite often. The advantage, and really the only good option on a limited flash micro like the tiny416 is you end up with small code and you don't get the compiler trying to use pointers all the time, which look sort of ugly on these 8bitters.
     
    With the pic32mm (256K/32K), I started to use templates but then switched to 'normal' coding to keep things simple. It ends up being just fine on a pic32 which can handle pointers/objects with ease. The code is easier to read/change/understand, and any cost is speed is worth it. I do have a reg class template which handles all bit manipulation and register access, but that is the only templates in use for my pic32mm.
     
    #7
    Memen
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2017/04/08 12:17:32
    • Location: 0
    • Status: offline
    Re: Are there any C++ libraries available? 2019/07/19 04:12:32 (permalink)
    0
    This may be a little late, but possibly useful anyways. I actually forked cvm's git repository (thanks for the great work!) and started working on implementation for the PIC32MX (795F512L, but the family is quite similar). You can find it on https://github.com/memen45/PIC32MX_CPP , although not all peripherals are implemented and tested yet, many are - including the standard spi, i2c, uart... The table in the readme shows the support for every peripheral.
     
    Hope this helps!
     
    Best regards,
    post edited by Memen - 2019/07/19 04:24:33
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5