|
25 | 25 | #include "PeripheralPins.h"
|
26 | 26 | #include "gpio_api.h"
|
27 | 27 | #include "nu_modutil.h"
|
| 28 | +#include "hal/PinNameAliases.h" |
28 | 29 |
|
29 | 30 | static uint32_t eadc_modinit_mask = 0;
|
30 | 31 |
|
@@ -84,6 +85,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
|
84 | 85 | {ADC_2_15, EADC2_MODULE, CLK_CLKSEL0_EADC2SEL_HCLK, CLK_CLKDIV5_EADC2(8), EADC2_RST, EADC20_IRQn, NULL},
|
85 | 86 | };
|
86 | 87 |
|
| 88 | +#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST) |
| 89 | +/* Structure for extending sampling time on per-pin basis */ |
| 90 | +struct nu_eadc_extsmpt { |
| 91 | + PinName pin; |
| 92 | + uint32_t value; |
| 93 | +}; |
| 94 | + |
| 95 | +static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = { |
| 96 | + MBED_CONF_TARGET_EADC_EXTSMPT_LIST |
| 97 | +}; |
| 98 | +#endif |
| 99 | + |
87 | 100 | void analogin_init(analogin_t *obj, PinName pin)
|
88 | 101 | {
|
89 | 102 | obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
|
@@ -126,6 +139,18 @@ void analogin_init(analogin_t *obj, PinName pin)
|
126 | 139 | // Configure the sample module Nmod for analog input channel Nch and software trigger source
|
127 | 140 | EADC_ConfigSampleModule(eadc_base, chn, EADC_SOFTWARE_TRIGGER, chn);
|
128 | 141 |
|
| 142 | +#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST) |
| 143 | + // Extend sampling time in EADC clocks on per-pin basis |
| 144 | + struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr; |
| 145 | + struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]); |
| 146 | + for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) { |
| 147 | + if (eadc_extsmpt_pos->pin == pin) { |
| 148 | + EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value); |
| 149 | + break; |
| 150 | + } |
| 151 | + } |
| 152 | +#endif |
| 153 | + |
129 | 154 | eadc_modinit_mask |= 1 << chn;
|
130 | 155 | }
|
131 | 156 |
|
|
0 commit comments