Porting libs from the Atmel Framework

Hello guys,

I'm thinking about porting one or another lib from the Framework from the Due/X or the SAM3X-EK would it be reprehensible if I take the libs and put them in an Arduino user friendly muted just with an lib with an nicer frontend for the users and putting the rest what isn't in the lib itself that comes from other parts in it to make it work? So there are easy therms like .init(); and similar.

B.R.

Markus

I'm sure nobody will object to some nice new libraries :slight_smile:

Most sample code provided by vendors is pretty crap, but it does give you a leg up to do something better.


Rob

With the received absolution from Graynomad, I make my first move with an RTC lib for the Due, there are many stuff for the RTC in the Framework and in the Arduino IDE too.

This is my first version inspired by stimmer, really small on functions but you can Set time and Get time. I make some Wrapper Calls around the functions that i found in the IDE to make it a little bit easier to use it, the other functions like Date and Alarm will follow immediately, this is only for the first view.

B.R.

Markus

Due_RTC.rar (2.16 KB)

Excellent job and nice initiative Markus, porting some ASF libraries for Due from the 1784 ASF samples (almost 50 for Due/X), and that's what we need. Motivated people to motivate others to generate more value inside the Arduino world!

Palliser:
Excellent job and nice initiative Markus, porting some ASF libraries for Due from the 1784 ASF samples (almost 50 for Due/X), and that's what we need. Motivated people to motivate others to generate more value inside the Arduino world!

Thanks,

and now with the date function

Due_RTC.rar (1.79 KB)

Hey Nice to see it
I was thinking of pulling the RTC in from the from the framework.
Code comment review.
There is a potential hiccup. When reading hardware registers and operating on them I always make one good local read/copy of the hardware register and then operate on the same value. So in

int RTC_clock::get_hours()
{
	return (((current_time()  & 0x00300000) >> 20) * 10 + ((current_time()  & 0x000F0000) >> 16));
}

converting from BCD to std number the "current_time()" is called twice and each time reads from the hardware registers. With the two current_time() reads they could return different readings.
Better I would think to do

int RTC_clock::get_hours()
{
uint32_t dwTimeCurrent = current_time(); 
	return (((dwTimeCurrent  & 0x00300000) >> 20) * 10 + (( dwTimeCurrent & 0x000F0000) >> 16));
}

I see the problem, your code is full of "evil" emoticons. Try

return (((current_time() :slight_smile: & 0x00300000) >> 20) * 10 + ((current_time() :slight_smile: & 0x000F0000) >> 16));

or use code tags, edit the post, select the code text, and click on the # button in the toolbar at the top.


Rob

neil12:
Hey Nice to see it
I was thinking of pulling the RTC in from the from the framework.
Code comment review.
There is a potential hiccup. When reading hardware registers and operating on them I always make one good local read/copy of the hardware register and then operate on the same value. So in

int RTC_clock::get_hours()

{
return (((current_time()  & 0x00300000) >> 20) * 10 + ((current_time()  & 0x000F0000) >> 16));
}



converting from BCD to std number the "current_time()" is called twice and each time reads from the hardware registers. With the two current_time() reads they could return different readings.
Better I would think to do 


int RTC_clock::get_hours()
{
uint32_t dwTimeCurrent = current_time();
return (((dwTimeCurrent  & 0x00300000) >> 20) * 10 + (( dwTimeCurrent & 0x000F0000) >> 16));
}

Yes you are right, I will correct it, and after it I will make functions to set parts of the date seperate, but its a little bit tricky the day of the week need to be changed too. Hope I'm back soon with the alarmfunction to.

Btw. it's my first library, the last time I changed one for the Leonardo, so please be patient (I write it between work and studying) updates will follow soon.