add function to revert wheel direction

This commit is contained in:
Richie 2023-11-06 20:45:42 +08:00
parent 4137d4f350
commit 389c4ecd92
2 changed files with 17 additions and 5 deletions

View File

@ -23,6 +23,8 @@
#define DIRECTION_LEFT (DIRECTION_RIGHT_FORWARD | DIRECTION_LEFT_BACKWARD)
#define DIRECTION_RIGHT (DIRECTION_RIGHT_BACKWARD | DIRECTION_LEFT_FORWARD)
#define DIRECTION_MASK (DIRECTION_FORWARD | DIRECTION_BACKWARD)
#define SPEED_PIN_RIGHT 15U
#define SPEED_PIN_LEFT 16U

View File

@ -19,14 +19,24 @@
void
set_wheel_direction(uint32_t direction)
{
static const uint32_t mask
= DIRECTION_LEFT_FORWARD | DIRECTION_LEFT_BACKWARD
| DIRECTION_RIGHT_FORWARD | DIRECTION_RIGHT_BACKWARD;
gpio_put_masked(mask, 0U);
gpio_put_masked(DIRECTION_MASK, 0U);
gpio_set_mask(direction);
}
/*!
* @brief Set the direction of the wheel to opposite direction using bit mask
*/
void
revert_wheel_direction()
{
uint32_t current_direction = gpio_get_all();
uint32_t reverted_direction = current_direction ^ DIRECTION_MASK;
gpio_put_masked(DIRECTION_MASK, 0U);
gpio_set_mask(reverted_direction & DIRECTION_MASK);
}
void
turn_left_90()
{