1 #include "py/obj.h" 2 #include "pin.h" 3 4 // Returns the pin mode. This value returned by this macro should be one of: 5 // GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD, 6 // GPIO_MODE_AF_PP, GPIO_MODE_AF_OD, or GPIO_MODE_ANALOG. 7 pin_get_mode(const pin_obj_t * pin)8uint32_t pin_get_mode(const pin_obj_t *pin) { 9 GPIO_TypeDef *gpio = pin->gpio; 10 uint32_t mode = (gpio->MODER >> (pin->pin * 2)) & 3; 11 if (mode == GPIO_MODE_OUTPUT_PP || mode == GPIO_MODE_AF_PP) { 12 if (gpio->OTYPER & pin->pin_mask) { 13 mode |= 1 << 4; // Converts from xxx_PP to xxx_OD 14 } 15 } 16 return mode; 17 } 18 19 // Returns the pin pullup/pulldown. The value returned by this macro should 20 // be one of GPIO_NOPULL, GPIO_PULLUP, or GPIO_PULLDOWN. 21 pin_get_pull(const pin_obj_t * pin)22uint32_t pin_get_pull(const pin_obj_t *pin) { 23 return (pin->gpio->PUPDR >> (pin->pin * 2)) & 3; 24 } 25 26 // Returns the af (alternate function) index currently set for a pin. 27 pin_get_af(const pin_obj_t * pin)28uint32_t pin_get_af(const pin_obj_t *pin) { 29 return (pin->gpio->AFR[pin->pin >> 3] >> ((pin->pin & 7) * 4)) & 0xf; 30 } 31