Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Gpio.Toggle for ESP32 #1744

Merged
merged 1 commit into from
Oct 23, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct gpio_input_state : public HAL_DblLinkedNode<gpio_input_state>
static HAL_DblLinkedList<gpio_input_state> gpioInputList; // Doulble LInkedlist for GPIO input status
static uint16_t pinReserved[TOTAL_GPIO_PORTS]; // reserved - 1 bit per pin

// memory for pin state
static uint16_t pinStateStore[TOTAL_GPIO_PORTS];

// Get pointer to gpio_input_state for Gpio pin
// return NULL if not found
gpio_input_state *GetInputState(GPIO_PIN pinNumber)
Expand Down Expand Up @@ -218,8 +221,24 @@ void CPU_GPIO_TogglePinState(GPIO_PIN pinNumber)
{
// platform DOES NOT support toggle
// need to do it "the hard way"
GpioPinValue newState = (GpioPinValue)(gpio_get_level((gpio_num_t)pinNumber) ^ GpioPinValue_High);
gpio_set_level((gpio_num_t)pinNumber, (uint32_t)newState);

uint32_t newValue;

// need to store pin state
int port = pinNumber >> 4, bit = 1 << (pinNumber & 0x0F);

if (pinStateStore[port] & bit)
{
pinStateStore[port] &= ~bit;
newValue = 0;
}
else
{
pinStateStore[port] |= bit;
newValue = 1;
}

gpio_set_level((gpio_num_t)pinNumber, newValue);
}

// ISR called by IDF
Expand Down