Skip to content

Conversation

smlng
Copy link
Member

@smlng smlng commented Nov 7, 2017

based on #7227 as discussed with @PeterKietzmann, with missing comments addressed.

@smlng smlng added Area: arduino API Area: Arduino wrapper API CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 7, 2017
@smlng
Copy link
Member Author

smlng commented Nov 8, 2017

tested works for Arduino-mega2560

@PeterKietzmann
Copy link
Member

Without looking at the code, my findings so far:

arduino-mega2560:

  • works as expected

arduino-duemilanove:

  • principally works as expected but it seems there are only 6 analog pins on that board though 8 seem to be initialized

waspmote:

  • xtimer does not fire (unrelated to ADC)
  • ADC_LINE(0) does not work or I connected the wrong pin (my pinout reference)
  • rest works as expected

@PeterKietzmann
Copy link
Member

Waspmotes reference says: Waspmote has 7 accessible analog inputs in the sensor connector
-> might be the same problem as on the duemilanove

@smlng
Copy link
Member Author

smlng commented Nov 8, 2017

for the Arduino-uno we could explicitly set ADC_NUMOF (6U) to fix that, but for the waspmote its a bit complicated as line 0 isn't connected so setting ADC_NUMOF (7U) here wouldn't fix that. On the other hand, the corresponding CPUs do have 8 ADC lines but only 6 or 7 are accessible.

#define ADC_PIN_4 4
#define ADC_PIN_5 5
#define ADC_PIN_6 6
#define ADC_PIN_7 7
Copy link
Member Author

@smlng smlng Nov 8, 2017

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.

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

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?

@PeterKietzmann
Copy link
Member

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?

@smlng
Copy link
Member Author

smlng commented Nov 8, 2017

still need to address murdock issues for nucleos

@smlng
Copy link
Member Author

smlng commented Nov 8, 2017

at least when they have ADC

@PeterKietzmann
Copy link
Member

What you think about removing ADC_PIN_X definitions?

@smlng
Copy link
Member Author

smlng commented Nov 8, 2017

What you think about removing ADC_PIN_X definitions?

yes they can go, but I still think we should have ANALOG1-7 defined for waspmote instead.

@PeterKietzmann
Copy link
Member

Why?

@smlng
Copy link
Member Author

smlng commented Nov 8, 2017

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 analogRead(ANALOG1); it would currently fail, or not?

@PeterKietzmann
Copy link
Member

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 ARDUINO_PIN_X. Can you shed some light into the dark?

Copy link
Contributor

@haukepetersen haukepetersen left a 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)
Copy link
Contributor

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?

@smlng
Copy link
Member Author

smlng commented Nov 9, 2017

@haukepetersen addressed your comment, and fixed issues reported by Murdock.

@smlng
Copy link
Member Author

smlng commented Nov 9, 2017

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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...

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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?

@smlng
Copy link
Member Author

smlng commented Nov 10, 2017

yep, I think the ADC_PIN_X mappings are obsolete now.

@smlng
Copy link
Member Author

smlng commented Nov 10, 2017

Now that you addressed several arduino mappings in this PR, what is this needed for

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.

@PeterKietzmann
Copy link
Member

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.

@smlng sure it doesn't hurt but on the other hand I think it makes the thing even worse as it introduces an inconsistency to the other boards

@smlng
Copy link
Member Author

smlng commented Nov 10, 2017

@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?

@PeterKietzmann
Copy link
Member

Please squash. I will give it a quick test run again then

@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 10, 2017
Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@smlng
Copy link
Member Author

smlng commented Nov 10, 2017

@haukepetersen all good, to get this finally merged?

@PeterKietzmann
Copy link
Member

Thx! ACK and go

@PeterKietzmann PeterKietzmann merged commit 8999460 into RIOT-OS:master Nov 13, 2017
@aabadie aabadie added this to the Release 2018.01 milestone Jan 18, 2018
@smlng smlng deleted the cpu/atmega/adc branch February 6, 2018 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: arduino API Area: Arduino wrapper API CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants