Skip to content

Commit dbf50f7

Browse files
authored
Merge pull request #28 from stm32duino/issue_26
Fix when HAL_DAC_MODULE_ENABLED is not defined
2 parents a721430 + 1003930 commit dbf50f7

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

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

+26-23
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@ static uint32_t get_adc_channel(PinName pin)
191191
return channel;
192192
}
193193

194+
static uint32_t get_pwm_channel(PinName pin)
195+
{
196+
uint32_t function = pinmap_function(pin, PinMap_PWM);
197+
uint32_t channel = 0;
198+
switch(STM_PIN_CHANNEL(function)) {
199+
case 1:
200+
channel = TIM_CHANNEL_1;
201+
break;
202+
case 2:
203+
channel = TIM_CHANNEL_2;
204+
break;
205+
case 3:
206+
channel = TIM_CHANNEL_3;
207+
break;
208+
case 4:
209+
channel = TIM_CHANNEL_4;
210+
break;
211+
default:
212+
channel = 0;
213+
break;
214+
}
215+
return channel;
216+
}
217+
218+
#ifdef HAL_DAC_MODULE_ENABLED
194219
static uint32_t get_dac_channel(PinName pin)
195220
{
196221
uint32_t function = pinmap_function(pin, PinMap_DAC);
@@ -216,29 +241,6 @@ static uint32_t get_dac_channel(PinName pin)
216241
return channel;
217242
}
218243

219-
static uint32_t get_pwm_channel(PinName pin)
220-
{
221-
uint32_t function = pinmap_function(pin, PinMap_PWM);
222-
uint32_t channel = 0;
223-
switch(STM_PIN_CHANNEL(function)) {
224-
case 1:
225-
channel = TIM_CHANNEL_1;
226-
break;
227-
case 2:
228-
channel = TIM_CHANNEL_2;
229-
break;
230-
case 3:
231-
channel = TIM_CHANNEL_3;
232-
break;
233-
case 4:
234-
channel = TIM_CHANNEL_4;
235-
break;
236-
default:
237-
channel = 0;
238-
break;
239-
}
240-
return channel;
241-
}
242244
////////////////////////// DAC INTERFACE FUNCTIONS /////////////////////////////
243245

244246
/**
@@ -369,6 +371,7 @@ void dac_stop(PinName pin)
369371
return;
370372
}
371373
}
374+
#endif //HAL_DAC_MODULE_ENABLED
372375

373376

374377
////////////////////////// ADC INTERFACE FUNCTIONS /////////////////////////////

Diff for: cores/arduino/wiring_analog.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,23 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
7373
uint8_t do_init = 0;
7474
PinName p = analogToPinName(ulPin);
7575
if(p != NC) {
76+
#ifdef HAL_DAC_MODULE_ENABLED
7677
if(pin_in_pinmap(p, PinMap_DAC)) {
7778
if(is_pin_configured(p, g_anOutputPinConfigured) == false) {
7879
do_init = 1;
7980
set_pin_configured(p, g_anOutputPinConfigured);
8081
}
8182
ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
8283
dac_write_value(p, ulValue, do_init);
83-
} else if(pin_in_pinmap(p, PinMap_PWM)) {
84-
if(is_pin_configured(p, g_anOutputPinConfigured) == false) {
85-
do_init = 1;
86-
set_pin_configured(p, g_anOutputPinConfigured);
87-
}
88-
ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
89-
pwm_start(p, PWM_FREQUENCY*PWM_MAX_DUTY_CYCLE,
84+
} else
85+
#endif //HAL_DAC_MODULE_ENABLED
86+
if(pin_in_pinmap(p, PinMap_PWM)) {
87+
if(is_pin_configured(p, g_anOutputPinConfigured) == false) {
88+
do_init = 1;
89+
set_pin_configured(p, g_anOutputPinConfigured);
90+
}
91+
ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
92+
pwm_start(p, PWM_FREQUENCY*PWM_MAX_DUTY_CYCLE,
9093
PWM_MAX_DUTY_CYCLE,
9194
ulValue, do_init);
9295
} else { //DIGITAL PIN ONLY
@@ -98,7 +101,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
98101
}
99102
else {
100103
digitalWrite(ulPin, HIGH);
101-
}
104+
}
102105
}
103106
}
104107
}

Diff for: cores/arduino/wiring_digital.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
3535
if(p != NC) {
3636
// If the pin that support PWM or DAC output, we need to turn it off
3737
if(is_pin_configured(p, g_anOutputPinConfigured)) {
38+
#ifdef HAL_DAC_MODULE_ENABLED
3839
if(pin_in_pinmap(p, PinMap_DAC)) {
3940
dac_stop(p);
40-
} else if(pin_in_pinmap(p, PinMap_PWM)) {
41+
} else
42+
#endif //HAL_DAC_MODULE_ENABLED
43+
if(pin_in_pinmap(p, PinMap_PWM)) {
4144
pwm_stop(p);
4245
}
4346
reset_pin_configured(p, g_anOutputPinConfigured);

0 commit comments

Comments
 (0)