Pages: [1]   Go Down
Author Topic: Making the Arduino functions as interfaces.  (Read 370 times)
0 Members and 1 Guest are viewing this topic.
Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been thinking about making the arduino functions into an interface. Then one could add to the arduino hierarchy different classes for implementing different processors.

The arduino enviroment would import a interface declaration by default. (for instance:)
Code:
#include "arduino_interface.h"

One could determine the processor type / interface implemenentation in an include.

Code:
#include "ATmega168.h"

This would use the ATmega168 implementation of the arduino functions when compiling.



Thoughts? Is this even possible?  I am yet to acquire enough microcontroller knowledge, but this kind of system developement works great in software.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had a similar idea to yours except when creating the new sketch a menu would let you select which AVR device you were using. The biggest problem I see with this is that not all AVRs have the same functionality. There would have to be some sort of code reference box built into the Arduino software that would let you know which functions you could call.  I really like this idea and wish  I could be of more help, I'm new to the AVR scene and barely got hello world functioning on a attiny2313, even with the hundreds of tutorials out their.  If you could get this working it would be awesome for the arduino users out their who want to create embedded devices when the atmega168 is overkill. I hope this project goes somewhere as it is a great idea.
Logged

Forum Administrator
Offline Offline
Newbie
*****
Karma: 3
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

check the source code for arduino
it's already like this in part...


the wiring.h  declares the functions that are part of the standard arduino library then the implementation has a series of ifdef depending on the actual processor used

we support 3 processors already and more are coming...

Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've done some thinking on what do when something is impossible to implement. (do not know of anything yet) But if, for instance a chip does not support PWM, I think the best way to solve that would be not to prevent the user to use analogWrite, but rather set the pin HIGH / LOW if argument >128 or not. And maybe print a warning in the IDE.
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
check the source code for arduino
it's already like this in part...

Agreed.

Quote
the wiring.h  declares the functions that are part of the standard arduino library then the implementation has a series of ifdef depending on the actual processor used

I've seen that, but I do think that it is a lot of work if one wants to add a processor. Maybe if the implementation themselves is written in separate .h files, that would help a bit I think.

Code:
#if defined(__AVR_ATmega168__)

#include "ATmega168.h"

#endif


I think the use of interface / implementation can lead to cleaner code, easier maintenance, easier expanding / adding new processors. (even non Atmel).
[not critizising, just thinking out loud]
 If a interface was used, all microprocessors with a c++ compiler could be used as an 'arduino'. [kind of anyway]

@Massimo:
Do you think this is a waste of time and energy, pursuing a hierarchial arduino system/structure?


I imagine the arduino functionset could be beneficial to both the beginner and the expert.

I myself would love to be able to utilize some of the ATtiny processors at one side of the Atmel AVRs and the XMega at the other.

The 168 was an excellent choise for an allrounder, but there is often situations where you need moremoremore, and oftentimes you only need 5 I/O and a little programspace for a short code.
« Last Edit: January 20, 2009, 07:10:13 pm by AlphaBeta » Logged

Pages: [1]   Go Up
Jump to: