Skip to content

Commit

Permalink
Fix issue #65 that causes analogWrite() stop working after pinMode()
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosun committed Sep 20, 2017
1 parent db67d5f commit 9ee0709
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C" {
#include "delay.h"
#include <hal_adc.h>
#include <hal_pwm.h>
#include <log_dump.h>

static int _readResolution = 12; // MT7687 ADC: 12 Bit

Expand Down Expand Up @@ -121,12 +122,20 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue)
ulValue = (1<<_writeResolution)-1;

if (HAL_PWM_STATUS_OK != hal_pwm_get_running_status(pwm_channel, &status))
return; /* hal_pwm_get_running_status fail */
{
// If fail to get PWM state,
// we assume PWM is not initialized -> set to IDLE.
// switch to PWM mode
status = HAL_PWM_IDLE;
}

if (HAL_PWM_IDLE == status) {
/* Set Pinmux to pwm mode */
if (!pin_enable_pwm(pin_desc))
{
pr_debug("pin_enable_pwm failed -> analogWrite failed\n");
return;
}

if (HAL_PWM_STATUS_OK != hal_pwm_set_frequency(pwm_channel, PWM_FREQUENCY, &total_count))
return; /* hal_pwm_set_frequency fail */
Expand Down

0 comments on commit 9ee0709

Please sign in to comment.