Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions cores/arduino/stm32/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ static uint32_t get_adc_channel(PinName pin)
return channel;
}

static uint32_t get_pwm_channel(PinName pin)
{
uint32_t function = pinmap_function(pin, PinMap_PWM);
uint32_t channel = 0;
switch(STM_PIN_CHANNEL(function)) {
case 1:
channel = TIM_CHANNEL_1;
break;
case 2:
channel = TIM_CHANNEL_2;
break;
case 3:
channel = TIM_CHANNEL_3;
break;
case 4:
channel = TIM_CHANNEL_4;
break;
default:
channel = 0;
break;
}
return channel;
}

#ifdef HAL_DAC_MODULE_ENABLED
static uint32_t get_dac_channel(PinName pin)
{
uint32_t function = pinmap_function(pin, PinMap_DAC);
Expand All @@ -216,29 +241,6 @@ static uint32_t get_dac_channel(PinName pin)
return channel;
}

static uint32_t get_pwm_channel(PinName pin)
{
uint32_t function = pinmap_function(pin, PinMap_PWM);
uint32_t channel = 0;
switch(STM_PIN_CHANNEL(function)) {
case 1:
channel = TIM_CHANNEL_1;
break;
case 2:
channel = TIM_CHANNEL_2;
break;
case 3:
channel = TIM_CHANNEL_3;
break;
case 4:
channel = TIM_CHANNEL_4;
break;
default:
channel = 0;
break;
}
return channel;
}
////////////////////////// DAC INTERFACE FUNCTIONS /////////////////////////////

/**
Expand Down Expand Up @@ -369,6 +371,7 @@ void dac_stop(PinName pin)
return;
}
}
#endif //HAL_DAC_MODULE_ENABLED


////////////////////////// ADC INTERFACE FUNCTIONS /////////////////////////////
Expand Down
19 changes: 11 additions & 8 deletions cores/arduino/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
uint8_t do_init = 0;
PinName p = analogToPinName(ulPin);
if(p != NC) {
#ifdef HAL_DAC_MODULE_ENABLED
if(pin_in_pinmap(p, PinMap_DAC)) {
if(is_pin_configured(p, g_anOutputPinConfigured) == false) {
do_init = 1;
set_pin_configured(p, g_anOutputPinConfigured);
}
ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
dac_write_value(p, ulValue, do_init);
} else if(pin_in_pinmap(p, PinMap_PWM)) {
if(is_pin_configured(p, g_anOutputPinConfigured) == false) {
do_init = 1;
set_pin_configured(p, g_anOutputPinConfigured);
}
ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
pwm_start(p, PWM_FREQUENCY*PWM_MAX_DUTY_CYCLE,
} else
#endif //HAL_DAC_MODULE_ENABLED
if(pin_in_pinmap(p, PinMap_PWM)) {
if(is_pin_configured(p, g_anOutputPinConfigured) == false) {
do_init = 1;
set_pin_configured(p, g_anOutputPinConfigured);
}
ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
pwm_start(p, PWM_FREQUENCY*PWM_MAX_DUTY_CYCLE,
PWM_MAX_DUTY_CYCLE,
ulValue, do_init);
} else { //DIGITAL PIN ONLY
Expand All @@ -98,7 +101,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
}
else {
digitalWrite(ulPin, HIGH);
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion cores/arduino/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
if(p != NC) {
// If the pin that support PWM or DAC output, we need to turn it off
if(is_pin_configured(p, g_anOutputPinConfigured)) {
#ifdef HAL_DAC_MODULE_ENABLED
if(pin_in_pinmap(p, PinMap_DAC)) {
dac_stop(p);
} else if(pin_in_pinmap(p, PinMap_PWM)) {
} else
#endif //HAL_DAC_MODULE_ENABLED
if(pin_in_pinmap(p, PinMap_PWM)) {
pwm_stop(p);
}
reset_pin_configured(p, g_anOutputPinConfigured);
Expand Down