diff --git a/main/config.cpp b/main/config.cpp index 832f984..e0db87e 100644 --- a/main/config.cpp +++ b/main/config.cpp @@ -10,7 +10,8 @@ single100a_config_t configDriverLeft = { .gpio_b = GPIO_NUM_4, .ledc_timer = LEDC_TIMER_0, .ledc_channel = LEDC_CHANNEL_0, - .abInverted = true, + .aEnabledPinState = false, //-> pins inverted (mosfets) + .bEnabledPinState = false, .resolution = LEDC_TIMER_11_BIT, .pwmFreq = 10000 }; @@ -22,7 +23,8 @@ single100a_config_t configDriverRight = { .gpio_b = GPIO_NUM_14, .ledc_timer = LEDC_TIMER_1, .ledc_channel = LEDC_CHANNEL_1, - .abInverted = false, + .aEnabledPinState = true, //-> pins not inverted + .bEnabledPinState = true, .resolution = LEDC_TIMER_11_BIT, .pwmFreq = 10000 }; diff --git a/main/motordrivers.cpp b/main/motordrivers.cpp index fc0f16d..477f861 100644 --- a/main/motordrivers.cpp +++ b/main/motordrivers.cpp @@ -79,14 +79,6 @@ void single100a::init(){ //function to put the h-bridge module in the desired state and duty cycle void single100a::set(motorstate_t state_f, float duty_f){ - //define enabled signal state (gpio high/low) TODO: move this to constructor? - bool enabled; - if (config.abInverted) { - enabled = false; - } else { - enabled = true; - } - //scale provided target duty in percent to available resolution for ledc uint32_t dutyScaled; if (duty_f > 100) { //target duty above 100% @@ -105,29 +97,29 @@ void single100a::set(motorstate_t state_f, float duty_f){ ledc_update_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel); //TODO: to fix bugged state of h-bridge module when idle and start again, maybe try to leave pwm signal on for some time before updating a/b pins? //no brake: (freewheel) - gpio_set_level(config.gpio_a, enabled); - gpio_set_level(config.gpio_b, enabled); + gpio_set_level(config.gpio_a, config.aEnabledPinState); + gpio_set_level(config.gpio_b, config.bEnabledPinState); break; case motorstate_t::BRAKE: ledc_set_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel, 0); ledc_update_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel); //brake: - gpio_set_level(config.gpio_a, !enabled); - gpio_set_level(config.gpio_b, !enabled); + gpio_set_level(config.gpio_a, !config.aEnabledPinState); + gpio_set_level(config.gpio_b, !config.bEnabledPinState); break; case motorstate_t::FWD: ledc_set_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel, dutyScaled); ledc_update_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel); //forward: - gpio_set_level(config.gpio_a, enabled); - gpio_set_level(config.gpio_b, !enabled); + gpio_set_level(config.gpio_a, config.aEnabledPinState); + gpio_set_level(config.gpio_b, !config.bEnabledPinState); break; case motorstate_t::REV: ledc_set_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel, dutyScaled); ledc_update_duty(LEDC_HIGH_SPEED_MODE, config.ledc_channel); //reverse: - gpio_set_level(config.gpio_a, !enabled); - gpio_set_level(config.gpio_b, enabled); + gpio_set_level(config.gpio_a, !config.aEnabledPinState); + gpio_set_level(config.gpio_b, config.bEnabledPinState); break; } ESP_LOGD(TAG, "set module to state=%s, duty=%d/%d, duty_input=%.3f%%", motorstateStr[(int)state_f], dutyScaled, dutyMax, duty_f); diff --git a/main/motordrivers.hpp b/main/motordrivers.hpp index 19da930..71218ea 100644 --- a/main/motordrivers.hpp +++ b/main/motordrivers.hpp @@ -34,7 +34,8 @@ typedef struct single100a_config_t { gpio_num_t gpio_b; ledc_timer_t ledc_timer; ledc_channel_t ledc_channel; - bool abInverted; + bool aEnabledPinState; + bool bEnabledPinState; ledc_timer_bit_t resolution; int pwmFreq; } single100a_config_t;