Skip to content

Commit

Permalink
make Pin hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed May 3, 2022
1 parent bf0e1fa commit 9717fd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ msgstr ""
msgid "Buffer length must be a multiple of 512"
msgstr ""

#: ports/stm/common-hal/sdioio/SDCard.c
#: ports/stm/common-hal/sdioio/SDCard.c shared-bindings/floppyio/__init__.c
msgid "Buffer must be a multiple of 512 bytes"
msgstr ""

Expand Down
20 changes: 19 additions & 1 deletion shared-bindings/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,28 @@ STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
}
}

//| def __hash__(self) -> int:
//| """Returns a hash for the Pin."""
//| ...
//|
STATIC mp_obj_t mcu_pin_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
switch (op) {
case MP_UNARY_OP_HASH: {
return mp_obj_id(self_in);
}
default:
return MP_OBJ_NULL; // op not supported
}
}

const mp_obj_type_t mcu_pin_type = {
{ &mp_type_type },
.flags = MP_TYPE_FLAG_EXTENDED,
.name = MP_QSTR_Pin,
.print = mcu_pin_print
.print = mcu_pin_print,
MP_TYPE_EXTENDED_FIELDS(
.unary_op = mcu_pin_unary_op,
)
};

const mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj) {
Expand Down

0 comments on commit 9717fd2

Please sign in to comment.