samd/machine_pin: Change the printing of Pin and LED objects.
It now prints lines like: Pin("D9", mode=IN, pull=PULL_UP, GPIO=PA07) or LED("LED") showing for consistency the names as given in pins.csv. For pins, the GPIO numer is printed as well for a reference.
This commit is contained in:
parent
972212907d
commit
366c801b35
|
@ -68,7 +68,7 @@ class Pins:
|
|||
if self.board_leds:
|
||||
pins_file.write("\nconst machine_led_obj_t machine_led_obj[] = {\n")
|
||||
for pin in self.board_leds:
|
||||
pins_file.write(" {{&machine_pin_type}, ")
|
||||
pins_file.write(" {{&machine_led_type}, ")
|
||||
pins_file.write(pin[0] + ', "' + pin[1])
|
||||
pins_file.write('"},\n')
|
||||
pins_file.write("};\n")
|
||||
|
|
|
@ -39,7 +39,7 @@ extern mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c
|
|||
|
||||
STATIC void machine_led_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_led_obj_t *self = self_in;
|
||||
mp_printf(print, "LED(%u)", self->id);
|
||||
mp_printf(print, "LED(\"%s\")", self->name);
|
||||
}
|
||||
|
||||
// constructor(id, ...)
|
||||
|
|
|
@ -64,7 +64,19 @@ uint32_t machine_pin_open_drain_mask[4];
|
|||
|
||||
STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_pin_obj_t *self = self_in;
|
||||
mp_printf(print, "GPIO P%c%02u", "ABCD"[self->id / 32], self->id % 32);
|
||||
char *mode_str;
|
||||
char *pull_str[] = {"PULL_OFF", "PULL_UP", "PULL_DOWN"};
|
||||
if (GPIO_IS_OPEN_DRAIN(self->id)) {
|
||||
mode_str = "OPEN_DRAIN";
|
||||
} else {
|
||||
mode_str = (mp_hal_get_pin_direction(self->id) == GPIO_DIRECTION_OUT) ? "OUT" : "IN";
|
||||
}
|
||||
|
||||
mp_printf(print, "Pin(\"%s\", mode=%s, pull=%s, GPIO=P%c%02u)",
|
||||
self->name,
|
||||
mode_str,
|
||||
pull_str[mp_hal_get_pull_mode(self->id)],
|
||||
"ABCD"[self->id / 32], self->id % 32);
|
||||
}
|
||||
|
||||
STATIC void pin_validate_drive(bool strength) {
|
||||
|
|
|
@ -126,7 +126,17 @@ static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) {
|
|||
}
|
||||
|
||||
static inline unsigned int mp_hal_get_pin_direction(mp_hal_pin_obj_t pin) {
|
||||
return (PORT->Group[pin / 32].DIR.reg & (1 << (pin % 32))) >> (pin % 32);
|
||||
return (PORT->Group[pin / 32].DIR.reg & (1 << (pin % 32))) ?
|
||||
GPIO_DIRECTION_OUT : GPIO_DIRECTION_IN;
|
||||
}
|
||||
|
||||
static inline unsigned int mp_hal_get_pull_mode(mp_hal_pin_obj_t pin) {
|
||||
bool pull_en = (PORT->Group[pin / 32].PINCFG[pin % 32].reg & PORT_PINCFG_PULLEN) != 0;
|
||||
if (pull_en) {
|
||||
return gpio_get_pin_level(pin) ? GPIO_PULL_UP : GPIO_PULL_DOWN;
|
||||
} else {
|
||||
return GPIO_PULL_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int mp_hal_pin_read(mp_hal_pin_obj_t pin) {
|
||||
|
|
Loading…
Reference in New Issue