-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu, atmega_common: add periph/adc #7954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tested works for Arduino-mega2560 |
Without looking at the code, my findings so far: arduino-mega2560:
arduino-duemilanove:
waspmote:
|
Waspmotes reference says: Waspmote has 7 accessible analog inputs in the sensor connector |
for the Arduino-uno we could explicitly set |
#define ADC_PIN_4 4 | ||
#define ADC_PIN_5 5 | ||
#define ADC_PIN_6 6 | ||
#define ADC_PIN_7 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeterKietzmann I think these names are from [wrong,] according to the waspmote manual they should be
ANALOG1 => 14
ANALOG2 => 15
ANALOG3 => 16
ANALOG4 => 17
ANALOG5 => 18
ANALOG6 => 19
ANALOG7 => 20
right? Though without the values, its just copy-paste from page 46.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeterKietzmann looking at page 45 of the waspmote manual there is a ANALOG
pin top-left on the larger connector, maybe that's the missing ANALOG0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't even know why these 'pins' are defined here. ADC_DEV(x)
returns x
and should be used AFAIK. The ANALOG pin on the top left of the waspmote does not work. I'm against introducing the waspmote semantic to RIOTs periph_conf.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then something like val = analogRead(ANALOG1);
as in the manual is not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when using an Arduino sketch with RIOT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you addressed several arduino mappings in this PR, what is this needed for?
I do not like the fact that we usually use `ADC_NUMOF'' et al as board specific (not MCU specific) indicator for a number of defined devices. As I see it here, it is used to indicate MCU specifics which must not be fully accomplished by a board. The reason for that is most likely the fact of missing configuration capabilities on such controllers. Am I right? However, I don't see this PR responsible to address that issue. Maybe a candidate for #7528? |
still need to address murdock issues for nucleos |
at least when they have ADC |
What you think about removing |
yes they can go, but I still think we should have |
Why? |
because otherwise any sketch for the waspmote will fail when compiled with RIOT. IIRC that's the idea of the Arduino feature in RIOT, that you can take an existing sketch and use it with RIOT, however, if one uses |
Yes it would fail. I'm not too familiar with the Arduino wrapper but (i) I would have assumed the mapping you propose as part of the arduino_pinmap.h file (not periph_conf.h) and (ii) looking at the referenced file it appears that Arduino pins are mapped like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one minor thing from my side...
#endif | ||
|
||
#ifdef CPU_ATMEGA1281 | ||
#define ADC_NUMOF (8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better
#if defined(CPU_ATMEGA328P) || defined(CPU_ATMEGA1281)
above?
@haukepetersen addressed your comment, and fixed issues reported by Murdock. |
if someone could review the ADC mapping for those boards - I'm a bit unsure if they're all correct. |
#define ARDUINO_A14 ADC_LINE(14) | ||
#define ARDUINO_A15 ADC_LINE(15) | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't get this naming scheme, can you send a reference? Above, for instance, analog pins are named like ARDUINO_PIN_AX
. In the Arduino forum it also appears that pins are addresses as AX
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC its partly invented by @haukepetersen, see original PR by @dnahm #7227. This mapping is basically needed to support ADC in sys/arduino/base.cpp
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I didn't know/see was that ARDUINO_PIN_AX
seems to be used for digital I/Os and ARDUINO_AX
for analog inputs. Fine with me...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right (I guess), otherwise there would be a name/macro clash between readAnalog
and readDigitial
and the corresponding pin mappings used in sys/arduino/base.cpp
.
*/ | ||
|
||
/** | ||
* @ingroup boards_nucleo32-common |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discovery boards are not in nucleo common, are they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that I know of, copy-pasta 🍝
#define ADC_PIN_4 4 | ||
#define ADC_PIN_5 5 | ||
#define ADC_PIN_6 6 | ||
#define ADC_PIN_7 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you addressed several arduino mappings in this PR, what is this needed for?
yep, I think the |
mhm, I'm unsure, and would rather clean this up later on, I think this is related to #7528. So leave as is for now, it doesn't hurt and cleanup then. |
36c9a7e
to
e6fbbf2
Compare
@PeterKietzmann IMHO analog pin mapping looks good for nucleos and the rest, I remove the extra (but unused) analog mappings as discussed offline. May I squash? |
Please squash. I will give it a quick test run again then |
e6fbbf2
to
9de00af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
@haukepetersen all good, to get this finally merged? |
Thx! ACK and go |
based on #7227 as discussed with @PeterKietzmann, with missing comments addressed.