Skip to content

Commit e4b1121

Browse files
committed
[ADC] Able to build without HAL module
Note: no size change Signed-off-by: Frederic Pillon <[email protected]>
1 parent 0753358 commit e4b1121

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Diff for: cores/arduino/stm32/analog.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@
4444
extern "C" {
4545
#endif
4646

47+
48+
/* Private_Variables */
49+
static PinName g_current_pin = NC;
50+
4751
/* Private_Defines */
52+
#ifdef HAL_ADC_MODULE_ENABLED
53+
4854
#if defined(ADC_SAMPLETIME_8CYCLES_5)
4955
#define SAMPLINGTIME ADC_SAMPLETIME_8CYCLES_5;
5056
#elif defined(ADC_SAMPLETIME_12CYCLES_5)
@@ -79,9 +85,6 @@ extern "C" {
7985
#define ADC_REGULAR_RANK_1 1
8086
#endif
8187

82-
/* Private_Variables */
83-
static PinName g_current_pin = NC;
84-
8588
/* Private Functions */
8689
static uint32_t get_adc_channel(PinName pin)
8790
{
@@ -155,6 +158,7 @@ static uint32_t get_adc_channel(PinName pin)
155158
}
156159
return channel;
157160
}
161+
#endif /* HAL_ADC_MODULE_ENABLED */
158162

159163
static uint32_t get_pwm_channel(PinName pin)
160164
{
@@ -337,7 +341,7 @@ void dac_stop(PinName pin)
337341
}
338342
#endif //HAL_DAC_MODULE_ENABLED
339343

340-
344+
#ifdef HAL_ADC_MODULE_ENABLED
341345
////////////////////////// ADC INTERFACE FUNCTIONS /////////////////////////////
342346

343347
/**
@@ -641,6 +645,7 @@ uint16_t adc_read_value(PinName pin)
641645

642646
return uhADCxConvertedValue;
643647
}
648+
#endif /* HAL_ADC_MODULE_ENABLED */
644649

645650
////////////////////////// PWM INTERFACE FUNCTIONS /////////////////////////////
646651

Diff for: cores/arduino/stm32/stm32yyxx_hal_conf.h

+4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
/*
2121
* Defined by default
2222
*/
23+
#if !defined(HAL_ADC_MODULE_DISABLED)
2324
#define HAL_ADC_MODULE_ENABLED
25+
#else
26+
#undef HAL_ADC_MODULE_ENABLED
27+
#endif
2428

2529
#if !defined(HAL_I2C_MODULE_DISABLED)
2630
#define HAL_I2C_MODULE_ENABLED

Diff for: cores/arduino/wiring_analog.c

+4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ static inline uint32_t mapResolution(uint32_t value, uint32_t from, uint32_t to)
6464
uint32_t analogRead(uint32_t ulPin)
6565
{
6666
uint32_t value = 0;
67+
#ifdef HAL_ADC_MODULE_ENABLED
6768
PinName p = analogInputToPinName(ulPin);
6869
if (p != NC) {
6970
value = adc_read_value(p);
7071
value = mapResolution(value, ADC_RESOLUTION, _readResolution);
7172
}
73+
#else
74+
UNUSED(ulPin);
75+
#endif
7276
return value;
7377
}
7478

0 commit comments

Comments
 (0)