AP_HAL_LINUX:toggle gpio port

This commit is contained in:
MHefny 2021-06-12 09:01:23 +02:00 committed by Lucas De Marchi
parent d95f6c8c2f
commit 280788bfdf
2 changed files with 9 additions and 1 deletions

View File

@ -228,7 +228,12 @@ void GPIO_RPI::write(uint8_t pin, uint8_t value)
void GPIO_RPI::toggle(uint8_t pin)
{
write(pin, !read(pin));
if (pin >= GPIO_RPI_MAX_NUMBER_PINS) {
return ;
}
uint32_t flag = (1 << pin);
_gpio_output_port_status ^= flag;
write(pin, (_gpio_output_port_status & flag) >> pin);
}
/* Alternative interface: */

View File

@ -192,6 +192,9 @@ private:
// File descriptor for the memory device file
// If it's negative, then there was an error opening the file.
int _system_memory_device;
// store GPIO output status.
uint32_t _gpio_output_port_status = 0x00;
};
}