Skip to content

Commit

Permalink
update bitmask in bar_graph.c
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperChamp234 committed Jan 31, 2024
1 parent b83e2ca commit 071bb53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/bar_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "esp_log.h"
#include "esp_err.h"
#include "pin_defs.h"
#include "motor_driver.h"

/**
* It will check for state of motor driver A, and accordingly init the free gpios.
Expand Down
16 changes: 5 additions & 11 deletions src/bar_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,25 @@ static int enabled_bar_graph_flag = 0;
// pins IN1 - IN4 are usable in the bar graph, as pins IN5 - IN8 are connected to pins of motor driver B and these cannot be used.
// So, bit mask sets bits of IN5 - IN8 as 0 and that of IN1 - IN4 as 1, because if we set pins used by mcpwm, esp32 will crash or behave oddly.
// IN1 is the leftmost bit and IN8 is the rightmost bit
static const uint8_t bitmask[3] = {0xFF, 0xCF, 0x0F};
// state 0 1 2
static const uint8_t bitmask[3] = {0xFF, 0x0F};
// state 0 1
// Just an array of pins used by bar graph led
static const int pin_out[8] = {BG_LED_1, BG_LED_2, BG_LED_3, BG_LED_4, BG_LED_5, BG_LED_6, BG_LED_7, BG_LED_8};

esp_err_t enable_bar_graph()
{
uint64_t bit_mask = 0;
// motor driver a is off so we can use IN1 - IN8 pins
if (read_motor_driver_mode(a) == 0)
if (get_motor_driver_status() == 0)
{
bit_mask = (1ULL << BG_LED_1) | (1ULL << BG_LED_2) | (1ULL << BG_LED_3) | (1ULL << BG_LED_4) | (1ULL << BG_LED_5) | (1ULL << BG_LED_6) | (1ULL << BG_LED_7) | (1ULL << BG_LED_8);
enabled_bar_graph_flag = 0;
}
// motor driver a is in parallel mode, so we can use IN1, IN2, IN5 - IN8 pins
else if (read_motor_driver_mode(a) == 1)
{
bit_mask = (1ULL << BG_LED_1) | (1ULL << BG_LED_2) | (1ULL << BG_LED_5) | (1ULL << BG_LED_6) | (1ULL << BG_LED_7) | (1ULL << BG_LED_8);
enabled_bar_graph_flag = 1;
}
// motor driver a is in normal mode, so we can use IN5, IN6, IN7, IN8 pins
else if (read_motor_driver_mode(a) == 2)
else if (get_motor_driver_status() == 1)
{
bit_mask = (1ULL << BG_LED_5) | (1ULL << BG_LED_6) | (1ULL << BG_LED_7) | (1ULL << BG_LED_8);
enabled_bar_graph_flag = 2;
enabled_bar_graph_flag = 1;
}

gpio_config_t io_conf;
Expand Down

0 comments on commit 071bb53

Please sign in to comment.