sam3x8e: Rework adc pin search to be more clear
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
15d5837322
commit
7a7b98cc31
|
@ -1,6 +1,6 @@
|
||||||
// GPIO functions on sam3x8e
|
// GPIO functions on sam3x8e
|
||||||
//
|
//
|
||||||
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
// Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ static Pio * const digital_regs[] = {
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* gpio functions
|
* General Purpose Input Output (GPIO) pins
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -116,6 +116,10 @@ gpio_in_read(struct gpio_in g)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
* Analog to Digital Converter (ADC) pins
|
||||||
|
****************************************************************/
|
||||||
|
|
||||||
static const uint8_t adc_pins[] = {
|
static const uint8_t adc_pins[] = {
|
||||||
GPIO('A', 2), GPIO('A', 3), GPIO('A', 4), GPIO('A', 6),
|
GPIO('A', 2), GPIO('A', 3), GPIO('A', 4), GPIO('A', 6),
|
||||||
GPIO('A', 22), GPIO('A', 23), GPIO('A', 24), GPIO('A', 16),
|
GPIO('A', 22), GPIO('A', 23), GPIO('A', 24), GPIO('A', 16),
|
||||||
|
@ -129,11 +133,15 @@ DECL_CONSTANT(ADC_MAX, 4096);
|
||||||
struct gpio_adc
|
struct gpio_adc
|
||||||
gpio_adc_setup(uint8_t pin)
|
gpio_adc_setup(uint8_t pin)
|
||||||
{
|
{
|
||||||
|
// Find pin in adc_pins table
|
||||||
int chan;
|
int chan;
|
||||||
for (chan=0; chan<ARRAY_SIZE(adc_pins); chan++) {
|
for (chan=0; ; chan++) {
|
||||||
if (adc_pins[chan] != pin)
|
if (chan >= ARRAY_SIZE(adc_pins))
|
||||||
continue;
|
shutdown("Not a valid ADC pin");
|
||||||
// Found PIN
|
if (adc_pins[chan] == pin)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(PMC->PMC_PCSR1 & (1 << (ID_ADC-32)))) {
|
if (!(PMC->PMC_PCSR1 & (1 << (ID_ADC-32)))) {
|
||||||
// Setup ADC
|
// Setup ADC
|
||||||
PMC->PMC_PCER1 = 1 << (ID_ADC-32);
|
PMC->PMC_PCER1 = 1 << (ID_ADC-32);
|
||||||
|
@ -143,8 +151,6 @@ gpio_adc_setup(uint8_t pin)
|
||||||
| ADC_MR_TRANSFER(1));
|
| ADC_MR_TRANSFER(1));
|
||||||
}
|
}
|
||||||
return (struct gpio_adc){ .bit = 1 << chan };
|
return (struct gpio_adc){ .bit = 1 << chan };
|
||||||
}
|
|
||||||
shutdown("Not a valid ADC pin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to sample a value. Returns zero if sample ready, otherwise
|
// Try to sample a value. Returns zero if sample ready, otherwise
|
||||||
|
|
Loading…
Reference in New Issue