Modifying Librarys

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

How difficult is it to modify a library from one compiler to the next, i have an Arduino project which uses the Nordic NRf24l01 radios and would like to move it to possibly Cvar as i like the intuitive  nature of this software and also to learn a little more about the C language and its use in general.

 

I see there is a Nrf/C Library by member "kerihbar" but a quick first glance shows there is visual differences between that and the Cvar libraries, so presumably one could,nt just bolt this on.

 

As always any info is good info so Thanks in advance.

 

Essef cool

Just like the Thunderbirds, Printf needs "Strings" yes

Last Edited: Fri. Dec 12, 2014 - 07:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Codevision is only a C compiler.

Arduino is C++ with benefits.    e.g. it adds forward declarations and finds headers and libraries automatically

 

So you can't expect to use the C++ features with the Codevision C compiler.   e.g. overloading and inheritance.

You will have to do forward declarations like any regular C or C++.    You can add the <library.h> and <library.lib> to the system directories or add the locations to your project paths.

 

But the good news is that many Arduino libraries are written in C anyway,   with a C++ object to wrap up the methods.

 

It is pretty straightforward to port C code from GCC to CV.    The NRF chips are just a sequence of SPI transfers.

 

If you provide a link to the original kerihbar source,   I could offer an opinion.

 

David.

Last Edited: Fri. Dec 12, 2014 - 07:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Plural of "library" is "libraries"

 

Essef wrote:
How difficult is it to modify a library from one compiler to the next

That will almost certainly mean rebuilding from the source.

 

So, from that point of view, it's no different to any other porting exercise.

 

Things which can make porting hard are:

  • Dependencies on specific features of the toolchain;
  • Dependencies on specific features of the target hardware.

 

Obviously, the 2nd one only applies when you are porting to different target hardware.

 

'C' code can be written in ways that make it easy to port (ie, make it "portable") - but that does take more care & effort than writing non-portable code!

 

So the short answer to your question is, "it depends on how well the library has been written for portability".

 

Quote:
would like to move it to possibly Cvar

To what?

 

Quote:
learn a little more about the C language

Hmm... generally, porting requires a very good understanding of the 'C' language - because you need to understand the fine implementation details - so not necessarily the best place for learning.

 

And it's not just about the 'C' language - you will also probably have to delve deep into all the options & settings of the toolchains involved...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Dec 12, 2014 - 08:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here,s the link Mr Prentice, https://github.com/kehribar/nrf2...

 

Thanks to both yourself and Awneil for your comments, as a beginner i assumed it would be a difficult task so lots of food for thought here.

 

Essef cool

Just like the Thunderbirds, Printf needs "Strings" yes

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All the files appear to be regular C.    They look 100% portable too.

 

You will need to edit the "radioPinFunction.c" to suit your wiring.

And obviously use <io.h> rather than <avr/io.h>

 

Just create the two projects:  RX and TX.

add the relevant files.

 

You can scrap the crap soft UART functions in "main.c".    After all,  the Arduino hardware has got a perfectly good USART.    And quite honestly,  you have got a perfectly good SPI.

 

For some reason,   people choose completely unsuitable chips.   e.g. Mr kerihbar is using a Tiny84.

 

So you can either do SPI and UART in software by just using PORTD rather than Mr kerihbar's PORTA.

Or you use the proper hardware of your mega328P.

 

Whichever route you choose,   it looks quite simple but not really for a beginner.     You will gain some useful experience.

 

Oh,   and it is really nice how you can Build and Upload to the Arduino in one-click.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

 

For some reason,   people choose completely unsuitable chips.   e.g. Mr kerihbar is using a Tiny84.

 

 

Other than the lack of true hardware "SPI" on the Tiny84 hence the crap software attempt,what else makes this unsuitable ?. 

 

 

david.prentice wrote:

 

Oh,   and it is really nice how you can Build and Upload to the Arduino in one-click.

 

 

It is very convenient, but  to much of the internal engine is hidden which i believe is knowledge needed in order to progress further .

 

 

 

 

Again Thanks for your valuable input, ill look at this over the weekend.

 

Essef cool 

Just like the Thunderbirds, Printf needs "Strings" yes

Last Edited: Fri. Dec 12, 2014 - 11:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Arduino does a good job of hiding the magic on the surface, but you don't have to dig too far to find its libraries, so there's very few secrets.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually,   I think that the Tiny84 has got USI.   So you can do the SPI fairly well.   Implementing a soft UART is always a pain.

 

My 'one-click' comment was about the Codevision ability to "Build and upload" a regular C program to the Arduino hardware.

 

@Kartman,

 

This particular Tiny84 project on GitHub seems to have nothing to do with Arduino 'language' or even C++.

Of course there are several Arduino 'libraries' on the internet.

 

I think that the OP just wants to build a regular C project on the Arduino hardware.

Which is exactly what I try to do whenever possible.    e.g. port a mega32 project to the mega328P and run it on UNO hardware.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

My 'one-click' comment was about the Codevision ability to "Build and upload" a regular C program to the Arduino hardware.

 

Yes and the more i examine this software the more i like its ease of use, additionally being able to view all relevant associated files is a real advantage.

 

david.prentice wrote:

I think that the OP just wants to build a regular C project on the Arduino hardware.

 

Yes the idea being to more openly understand the inner workings along the way.

 

Essef cool

Just like the Thunderbirds, Printf needs "Strings" yes

Last Edited: Tue. Dec 16, 2014 - 09:46 AM