Easiest way might be to start a timer running and use a pin change interrupt.
On the interrupt, read the time from the timer.
If the pin is high, it's a rising edge, save the time in a volatile variable.
If the pin is low, it's a falling edge, subtract the time you saved from the current time and there you have it.
If you don't know my whole story, keep your mouth shut.
If you know my whole story, you're an accomplice. Keep your mouth shut.
© 2020 Microchip Technology Inc.