esp32: Use always machine_pin_get_id for getting a Pin id.

This applies to all machine modules which have pins as arguments.  Since
machine_pin_get_id() calls pin_find(), these pin arguments may be at the
moment either integer objects or Pin objects.  That allows for instance to
write

    uart = UART(1, tx=Pin(4), rx=Pin(5))

instead of

    uart = UART(1, tx=4, rx=5)

which is consistent with other ports.  Since this handling is done at a
single place in the code, extending that scheme to accept strings for named
pins is easy.

Signed-off-by: robert-hh <robert@hammelrath.com>
This commit is contained in:
robert-hh
2023-06-07 15:10:11 +02:00
committed by Damien George
parent 3819ee4a6f
commit 29e9573de7
5 changed files with 24 additions and 33 deletions

View File

@@ -392,9 +392,9 @@ STATIC void machine_i2s_init_helper(machine_i2s_obj_t *self, size_t n_pos_args,
//
// are Pins valid?
int8_t sck = args[ARG_sck].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_sck].u_obj);
int8_t ws = args[ARG_ws].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_ws].u_obj);
int8_t sd = args[ARG_sd].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_sd].u_obj);
int8_t sck = args[ARG_sck].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_sck].u_obj);
int8_t ws = args[ARG_ws].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_ws].u_obj);
int8_t sd = args[ARG_sd].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_sd].u_obj);
// is Mode valid?
i2s_mode_t mode = args[ARG_mode].u_int;