Skip to content

Commit 3419958

Browse files
add analogReadPeriod()
1 parent 0e7a574 commit 3419958

File tree

13 files changed

+64
-39
lines changed

13 files changed

+64
-39
lines changed

cores/stm32l4/STM32.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ float STM32Class::getVBAT()
6767
stm32l4_adc_enable(&stm32l4_adc, 0, NULL, NULL, 0);
6868
}
6969

70-
vref_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VREFINT);
71-
vbat_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VBAT);
70+
vref_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VREFINT, ADC_VREFINT_PERIOD);
71+
vbat_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VBAT, ADC_VBAT_PERIOD);
7272

7373
stm32l4_adc_disable(&stm32l4_adc);
7474

@@ -93,7 +93,7 @@ float STM32Class::getVREF()
9393
stm32l4_adc_enable(&stm32l4_adc, 0, NULL, NULL, 0);
9494
}
9595

96-
vref_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VREFINT);
96+
vref_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VREFINT, ADC_VREFINT_PERIOD);
9797

9898
stm32l4_adc_disable(&stm32l4_adc);
9999

@@ -118,8 +118,8 @@ float STM32Class::getTemperature()
118118
stm32l4_adc_enable(&stm32l4_adc, 0, NULL, NULL, 0);
119119
}
120120

121-
vref_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VREFINT);
122-
ts_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_TS);
121+
vref_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_VREFINT, ADC_VREFINT_PERIOD);
122+
ts_data = stm32l4_adc_convert(&stm32l4_adc, ADC_CHANNEL_ADC1_TS, ADC_TSENSE_PERIOD);
123123

124124
stm32l4_adc_disable(&stm32l4_adc);
125125

cores/stm32l4/stm32l4_wiring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef enum _eAnalogReference {
8484

8585
extern void analogReference(eAnalogReference reference);
8686
extern void analogReadResolution(int resolution);
87+
extern void analogReadPeriod(int period);
8788
extern uint32_t analogRead(uint32_t pin);
8889
extern void analogWriteResolution(int resolution);
8990
extern void analogWriteFrequency(uint32_t pin, uint32_t frequency);

cores/stm32l4/stm32l4_wiring_analog.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ static stm32l4_dac_t stm32l4_dac;
3939
static stm32l4_timer_t stm32l4_pwm[PWM_INSTANCE_COUNT];
4040

4141
static uint8_t _channels[PWM_INSTANCE_COUNT];
42+
4243
static int _readResolution = 10;
44+
static int _readPeriod = 2;
4345
static int _writeResolution = 8;
4446

4547
static uint32_t _writeFrequency[PWM_INSTANCE_COUNT];
@@ -57,6 +59,11 @@ void analogReadResolution(int resolution)
5759
_readResolution = resolution;
5860
}
5961

62+
void analogReadPeriod(int period)
63+
{
64+
_readPeriod = period;
65+
}
66+
6067
static inline uint32_t mapResolution(uint32_t value, uint32_t from, uint32_t to)
6168
{
6269
if (from == to)
@@ -115,7 +122,7 @@ uint32_t analogRead(uint32_t pin)
115122

116123
stm32l4_gpio_pin_configure(g_APinDescription[pin].pin, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG | GPIO_ANALOG_SWITCH));
117124

118-
input = stm32l4_adc_convert(&stm32l4_adc, g_APinDescription[pin].adc_input);
125+
input = stm32l4_adc_convert(&stm32l4_adc, g_APinDescription[pin].adc_input, _readPeriod);
119126

120127
stm32l4_adc_disable(&stm32l4_adc);
121128

system/STM32L4xx/Include/stm32l4_adc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ enum {
7171

7272
typedef void (*stm32l4_adc_callback_t)(void *context, uint32_t events);
7373

74+
#define ADC_VREFINT_PERIOD 4
75+
#define ADC_VBAT_PERIOD 12
76+
#define ADC_TSENSE_PERIOD 5
77+
7478
#define ADC_STATE_NONE 0
7579
#define ADC_STATE_INIT 1
7680
#define ADC_STATE_BUSY 2
@@ -93,7 +97,7 @@ extern bool stm32l4_adc_disable(stm32l4_adc_t *adc);
9397
extern bool stm32l4_adc_configure(stm32l4_adc_t *adc, uint32_t option);
9498
extern bool stm32l4_adc_calibrate(stm32l4_adc_t *adc);
9599
extern bool stm32l4_adc_notify(stm32l4_adc_t *adc, stm32l4_adc_callback_t callback, void *context, uint32_t events);
96-
extern uint32_t stm32l4_adc_convert(stm32l4_adc_t *adc, unsigned int channel);
100+
extern uint32_t stm32l4_adc_convert(stm32l4_adc_t *adc, unsigned int channel, unsigned int period);
97101

98102
#ifdef __cplusplus
99103
}
-48 Bytes
Binary file not shown.
-48 Bytes
Binary file not shown.
-48 Bytes
Binary file not shown.
-48 Bytes
Binary file not shown.
1.18 KB
Binary file not shown.
1.18 KB
Binary file not shown.

0 commit comments

Comments
 (0)