Skip to content

Commit

Permalink
Merge pull request ARMmbed#15422 from OpenNuvoton/nuvoton_eadc_extend…
Browse files Browse the repository at this point in the history
…_sample_time

Nuvoton: Enable configurability for extending sampling time for ADC/EADC
  • Loading branch information
0xc0170 authored May 16, 2023
2 parents cc39261 + 91a1b59 commit 8779918
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 1 deletion.
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M2354/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "PeripheralPins.h"
#include "gpio_api.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand All @@ -47,6 +48,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_0_15, EADC_MODULE, 0, CLK_CLKDIV0_EADC(8), EADC_RST, EADC0_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -92,6 +105,18 @@ void analogin_init(analogin_t *obj, PinName pin)
// Configure the sample module Nmod for analog input channel Nch and software trigger source
EADC_ConfigSampleModule(eadc_base, chn, EADC_SOFTWARE_TRIGGER, chn);

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << chn;
}

Expand Down
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M251/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "pinmap.h"
#include "PeripheralPins.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand All @@ -46,6 +47,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_0_15, EADC_MODULE, 0, CLK_CLKDIV0_EADC(8), EADC_RST, EADC_INT0_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -90,6 +103,18 @@ void analogin_init(analogin_t *obj, PinName pin)
*/
EADC_SetExtendSampleTime(eadc_base, chn, 10);

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << chn;
}

Expand Down
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M261/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "pinmap.h"
#include "PeripheralPins.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand All @@ -45,6 +46,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_0_15, EADC_MODULE, 0, CLK_CLKDIV0_EADC(8), EADC_RST, EADC0_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -81,6 +94,18 @@ void analogin_init(analogin_t *obj, PinName pin)
// Configure the sample module Nmod for analog input channel Nch and software trigger source
EADC_ConfigSampleModule(eadc_base, chn, EADC_SOFTWARE_TRIGGER, chn);

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << chn;
}

Expand Down
27 changes: 26 additions & 1 deletion targets/TARGET_NUVOTON/TARGET_M451/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "pinmap.h"
#include "PeripheralPins.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand All @@ -44,6 +45,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_0_15, EADC_MODULE, 0, CLK_CLKDIV0_EADC(8), EADC_RST, ADC00_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -80,7 +93,19 @@ void analogin_init(analogin_t *obj, PinName pin)

// Configure the sample module Nmod for analog input channel Nch and software trigger source
EADC_ConfigSampleModule(eadc_base, chn, EADC_SOFTWARE_TRIGGER, chn);


#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << chn;
}

Expand Down
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M460/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "PeripheralPins.h"
#include "gpio_api.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand Down Expand Up @@ -84,6 +85,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_2_15, EADC2_MODULE, CLK_CLKSEL0_EADC2SEL_HCLK, CLK_CLKDIV5_EADC2(8), EADC2_RST, EADC20_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -126,6 +139,18 @@ void analogin_init(analogin_t *obj, PinName pin)
// Configure the sample module Nmod for analog input channel Nch and software trigger source
EADC_ConfigSampleModule(eadc_base, chn, EADC_SOFTWARE_TRIGGER, chn);

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << chn;
}

Expand Down
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M480/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "PeripheralPins.h"
#include "gpio_api.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand Down Expand Up @@ -66,6 +67,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_1_15, EADC1_MODULE, 0, CLK_CLKDIV2_EADC1(8), EADC1_RST, EADC10_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -102,6 +115,18 @@ void analogin_init(analogin_t *obj, PinName pin)
// Configure the sample module Nmod for analog input channel Nch and software trigger source
EADC_ConfigSampleModule(eadc_base, chn, EADC_SOFTWARE_TRIGGER, chn);

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << chn;
}

Expand Down
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_NANO100/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "pinmap.h"
#include "PeripheralPins.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t adc_modinit_mask = 0;

Expand All @@ -41,6 +42,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_0_11, ADC_MODULE, CLK_CLKSEL1_ADC_S_HIRC, CLK_ADC_CLK_DIVIDER(1), ADC_RST, ADC_IRQn, NULL},
};

#if defined(MBED_CONF_TARGET_ADC_SMPLCNT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_smplcnt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_smplcnt eadc_smplcnt_arr[] = {
MBED_CONF_TARGET_ADC_SMPLCNT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -82,6 +95,18 @@ void analogin_init(analogin_t *obj, PinName pin)
adc_base->CHEN |= 1 << chn;
}

#if defined(MBED_CONF_TARGET_ADC_SMPLCNT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_smplcnt *eadc_extsmpt_pos = eadc_smplcnt_arr;
struct nu_eadc_smplcnt *eadc_extsmpt_end = eadc_smplcnt_arr + sizeof (eadc_smplcnt_arr) / sizeof (eadc_smplcnt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
ADC_SetExtraSampleTime(adc_base, chn, eadc_extsmpt_pos->value);
break;
}
}
#endif

adc_modinit_mask |= 1 << chn;
}

Expand Down
25 changes: 25 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_NUC472/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "pinmap.h"
#include "PeripheralPins.h"
#include "nu_modutil.h"
#include "hal/PinNameAliases.h"

static uint32_t eadc_modinit_mask = 0;

Expand All @@ -45,6 +46,18 @@ static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_1_7, EADC_MODULE, CLK_CLKSEL1_ADCSEL_PLL, CLK_CLKDIV0_ADC(5), ADC_RST, EADC0_IRQn, NULL}
};

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
/* Structure for extending sampling time on per-pin basis */
struct nu_eadc_extsmpt {
PinName pin;
uint32_t value;
};

static struct nu_eadc_extsmpt eadc_extsmpt_arr[] = {
MBED_CONF_TARGET_EADC_EXTSMPT_LIST
};
#endif

void analogin_init(analogin_t *obj, PinName pin)
{
obj->adc = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
Expand Down Expand Up @@ -82,6 +95,18 @@ void analogin_init(analogin_t *obj, PinName pin)
// Configure the sample module Nmod for analog input channel Nch and software trigger source
EADC_ConfigSampleModule(eadc_base, smp_mod, EADC_SOFTWARE_TRIGGER, smp_chn);

#if defined(MBED_CONF_TARGET_EADC_EXTSMPT_LIST)
// Extend sampling time in EADC clocks on per-pin basis
struct nu_eadc_extsmpt *eadc_extsmpt_pos = eadc_extsmpt_arr;
struct nu_eadc_extsmpt *eadc_extsmpt_end = eadc_extsmpt_arr + sizeof (eadc_extsmpt_arr) / sizeof (eadc_extsmpt_arr[0]);
for (; eadc_extsmpt_pos != eadc_extsmpt_end; eadc_extsmpt_pos ++) {
if (eadc_extsmpt_pos->pin == pin) {
EADC_SetExtendSampleTime(eadc_base, smp_mod, eadc_extsmpt_pos->value);
break;
}
}
#endif

eadc_modinit_mask |= 1 << smp_mod;
}

Expand Down
Loading

0 comments on commit 8779918

Please sign in to comment.