6f418fc1b0
Converts generted pins to use qstrs instead of string pointers. This patch also adds the following functions: pyb.Pin.names() pyb.Pin.af_list() pyb.Pin.gpio() dir(pyb.Pin.board) and dir(pyb.Pin.cpu) also produce useful results. pyb.Pin now takes kw args. pyb.Pin.__str__ now prints more useful information about the pin configuration. I found the following functions in my boot.py to be useful: ```python def pins(): for pin_name in dir(pyb.Pin.board): pin = pyb.Pin(pin_name) print('{:10s} {:s}'.format(pin_name, str(pin))) def af(): for pin_name in dir(pyb.Pin.board): pin = pyb.Pin(pin_name) print('{:10s} {:s}'.format(pin_name, str(pin.af_list()))) ```
38 lines
1.0 KiB
C
38 lines
1.0 KiB
C
#include "mpconfig.h"
|
|
#include "nlr.h"
|
|
#include "misc.h"
|
|
#include "qstr.h"
|
|
#include "obj.h"
|
|
#include "runtime.h"
|
|
#include MICROPY_HAL_H
|
|
#include "pin.h"
|
|
|
|
// Returns the pin mode. This value returned by this macro should be one of:
|
|
// GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD,
|
|
// GPIO_MODE_AF_PP, GPIO_MODE_AF_OD, or GPIO_MODE_ANALOG.
|
|
|
|
uint32_t pin_get_mode(const pin_obj_t *pin) {
|
|
GPIO_TypeDef *gpio = pin->gpio;
|
|
uint32_t mode = (gpio->MODER >> (pin->pin * 2)) & 3;
|
|
if (mode != GPIO_MODE_ANALOG) {
|
|
if (gpio->OTYPER & pin->pin_mask) {
|
|
mode |= 1 << 4;
|
|
}
|
|
}
|
|
return mode;
|
|
}
|
|
|
|
// Returns the pin pullup/pulldown. The value returned by this macro should
|
|
// be one of GPIO_NOPULL, GPIO_PULLUP, or GPIO_PULLDOWN.
|
|
|
|
uint32_t pin_get_pull(const pin_obj_t *pin) {
|
|
return (pin->gpio->PUPDR >> (pin->pin * 2)) & 3;
|
|
}
|
|
|
|
// Returns the af (alternate function) index currently set for a pin.
|
|
|
|
uint32_t pin_get_af(const pin_obj_t *pin) {
|
|
return (pin->gpio->AFR[pin->pin >> 3] >> ((pin->pin & 7) * 4)) & 0xf;
|
|
}
|
|
|