Jump to content
Rooster

Converting a Library

Recommended Posts

I am currently trying to move a project I originally started on Arduino onto the Stellaris LaunchPad. It used the Wave Shield from Adafruit and I am designing a BoosterPack to go with this library. I would like to just convert the library files available for Arduino for the Wave Shield, but my experience with C programing is very basic (and it's been years since I've touched Java either). I would like to re-write things as little as possible so that I can simply get code working so I can start sending PCBs for the BoosterPack off to fab and get this working before the end of the month. Any help/ideas as to where to start? I assume all I will really need to do is change pin references but this is proving more complicated than I had anticipated. Any help and other considerations I may have missed would be excellent and much appreciated!

 

The Arduino library is available here: http://code.google.com/p/wavehc/

Share this post


Link to post
Share on other sites

Unfortunately, a first look at the libraries show intensive use of AVR-specific code:

#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>

That means the code has been optimised for the AVR-MCUs used by the Arduinos. It also means the code is going to be hard to adapt or hardly adaptable to the LM4F.

 

Moreover, the project counts 14 files, with many interdependencies. You'll need to understand what does what.

 

Now, you have two options:

  • you know the LM4F functions corresponding the the AVR ones: you dig into the project and make the translation
  • you know how the shield works and you have the specification sheets at hand: you write a LM4F-compatible library from scratch.

IMHO, I always go for the later option, as it gives me the opportunity to learn how the shield truly works.

Share this post


Link to post
Share on other sites

 

Now, you have two options:

  • you know the LM4F functions corresponding the the AVR ones: you dig into the project and make the translation
  • you know how the shield works and you have the specification sheets at hand: you write a LM4F-compatible library from scratch.

IMHO, I always go for the later option, as it gives me the opportunity to learn how the shield truly works.

 

I haven't looked at the library beyond the description of what it does.

 

One other option - look around and see if you can find other libraries that do what you want, and adapt/adopt them.

 

The description of the libraries you are interested in list 3 main function areas.

 

1) Read SD and SDHC cards

2) Read FAT16 and FAT32 volumes (file information, file content)

3) Play WAV files

 

There are various libraries for reading FAT,

e.g. Petit FATFS, which has been ported to Energia

http://forum.43oh.com/topic/3209-energia-library-petit-fatfs-sd-card-library/

 

If you need more function there is also the FatFS

http://elm-chan.org/fsw/ff/00index_e.html

 

For reading SD cards, there is example code for some of the Stellaris controllers

(e.g. the LM3s8962 has an SD card slot on the evaluation board).  

Some of the FAT ports may also have example code for doing this.

 

For playing wave files - there are various projects out there where people have used Stellaris controllers to play wav files.  

I didn't see much code, except for a sample from TI for the evalbot, but I didn't look very far.

 

If I am going to roll my own library I like to grab several examples of what is out there already.

If I find one that does what I want, it saves me writing my own.  

If I don't, then I have a better basis of comparison for making my own library, so I can be sure it is better than what is out there.  

(If you are going to reinvent the wheel, should make sure yours is rounder than anybody else's.)

 

 

standards.png

http://xkcd.com/927/

(The cartoon is about standards, but works just as well for libraries.)

Share this post


Link to post
Share on other sites

@@igor, nice cartoon! Perfect illustration for the not invented here syndrome...

 

Every library is a mix of

  • something old, something new,
  • something borrowed, something genuine

@@Rooster, what is your goal? Have that shield working on the Stellaris as soon as possible or learn how the MCP4921 works?

Share this post


Link to post
Share on other sites

The goal is to get this up and running on the Stellaris as soon as possible. But now that I have a better idea of what to look for and perhaps how to translate the library, I think it might not be a big deal.

I'll have to go find TI's wav example, did not realize there was one. That's the only library I hadn't found already done for the Stellaris (something to play .wav files) so that should make this a little easier to translate.

 

Thank you for the tips.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×