Skip to content

samd21/adc: initial implementation #6929

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

Merged
merged 1 commit into from
Apr 28, 2017
Merged

samd21/adc: initial implementation #6929

merged 1 commit into from
Apr 28, 2017

Conversation

travisgriggs
Copy link
Contributor

This is an implementation of the simple RIOT ADC driver for the samd21 chip. The samd21-xpro board definition is modified to include this peripheral.

I have a simple "examples" app I wrote to test it, but was uncertain whether that should be included or not for just this. Seemed like it should be a different PR if there was interest at all.

@thomaseichinger
Copy link
Member

Attempts to provide an ADC implementation for the samd21 can be found in #2063 and #4162. Bottom line, it's complicated. 😉 But AFAIK it was mostly due to configuration issues on the samr21-xpro board.

/* ADC 0 device configuration */
#define ADC_0_DEV ADC
#define ADC_0_IRQ ADC_IRQn
#define ADC_0_CHANNELS (3U)
Copy link
Member

Choose a reason for hiding this comment

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

Indention is off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. tabs. old habits die hard.

#define ADC_0_PRESCALER ADC_CTRLB_PRESCALER_DIV512
static const adc_channel_t adc_channels[] = {
/* port, pin, muxpos */
{GPIO_PIN(PA, 10), ADC_INPUTCTRL_MUXPOS_PIN18}, // EXT2, pin 3
Copy link
Member

Choose a reason for hiding this comment

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

Here and all following, please use /* C style comments */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also fixed. old habits, again.


static mutex_t lock = MUTEX_INIT;

static inline void prep(void)
Copy link
Member

Choose a reason for hiding this comment

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

For your consideration, usually static function names are prefixed by a underscore RIOT e.g. _function_name. This is not a coding convention but might improve consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

static variables as well? Or just the functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed lock to _lock as well. I can back out if that's going to far.

@travisgriggs
Copy link
Contributor Author

Yes, we had seen #4162, and wanted to avoid the demise of that attempt. So we just stuck with the simple/straightforward approach that satisfied the basic riot driver. Said API is good enough for our current project anyway.

@thomaseichinger thomaseichinger added CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable Area: drivers Area: Device drivers labels Apr 19, 2017
@thomaseichinger
Copy link
Member

@travisgriggs Thanks for your changes. Can't test but code looks good to me. @PeterKietzmann do you agree?

@aabadie
Copy link
Contributor

aabadie commented Apr 19, 2017

looking at the jenkins CI, other samd21 based boards should be adapted as well (arduino-zero, sodaq-autonomo and samr21-xpro)

@travisgriggs
Copy link
Contributor Author

squashed

#include "periph/adc.h"
#include "periph_conf.h"
#include "mutex.h"

Copy link
Member

Choose a reason for hiding this comment

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

Please guard the implementation by #if ADC_NUMOF. This way we work around adding the configurations for other boards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed (I think I did what you wanted, found something similar in nrf51 variant). resquashed as well

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

@thomaseichinger thomaseichinger 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 labels Apr 19, 2017
@thomaseichinger
Copy link
Member

@aabadie Is the ADC configuration in arduino-zero's periph_conf.h supposed to serve any purpose? Without an ADC implementation this seemed to be only a placeholder. Would you mind either updating or removing it as an intermediate step?

@aabadie
Copy link
Contributor

aabadie commented Apr 20, 2017

Is the ADC configuration in arduino-zero's periph_conf.h supposed to serve any purpose? Without an ADC implementation this seemed to be only a placeholder.

Indeed, I don't remember why I added this configuration. Normally, it should match the actual ADC configuration of the board.

Would you mind either updating or removing it as an intermediate step?

Sure

@aabadie
Copy link
Contributor

aabadie commented Apr 20, 2017

@thomaseichinger, I opened #6943 regarding the issue with arduino-zero board.

typedef struct {
gpio_t pin;
uint32_t muxpos;
} adc_channel_t;
Copy link
Member

Choose a reason for hiding this comment

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

Please add doxygen documentation here. Something like

/**
 * @brief ADC Channel Configuration
 */
typedef struct {
    gpio_t pin;         /**< ADC channel pin */
    uint32_t muxpos;    /**< ADC channel pin multiplexer value */
} adc_channel_t;

@thomaseichinger
Copy link
Member

Also, please rebase since #6943 got merged.

@travisgriggs
Copy link
Contributor Author

I'm out for the rest of the week at a wedding; I'll make the change first thing Monday morning. Thanks for the continuing guidance.

@travisgriggs
Copy link
Contributor Author

doxygen updates and squashed

@travisgriggs
Copy link
Contributor Author

rebased again to keep it on top of master

@thomaseichinger thomaseichinger added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 28, 2017
@thomaseichinger
Copy link
Member

@travisgriggs All set, ACK & Go

@thomaseichinger thomaseichinger merged commit d186de2 into RIOT-OS:master Apr 28, 2017
@travisgriggs travisgriggs deleted the samd21_adc branch April 28, 2017 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants