ported quadrature encoder from mbed impl