Skip to content

Commit 2de067b

Browse files
committed
mcp4822 gain argument fix, as per requested
1 parent c2395d9 commit 2de067b

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

shared-bindings/mcp4822/MCP4822.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ static mp_obj_t mcp4822_mcp4822_make_new(const mp_obj_type_t *type, size_t n_arg
8181
const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock);
8282
const mcu_pin_obj_t *mosi = validate_obj_is_free_pin(args[ARG_mosi].u_obj, MP_QSTR_mosi);
8383
const mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj, MP_QSTR_cs);
84-
85-
mp_int_t gain = args[ARG_gain].u_int;
86-
if (gain != 1 && gain != 2) {
87-
mp_raise_ValueError(MP_ERROR_TEXT("gain must be 1 or 2"));
88-
}
84+
const mp_int_t gain = mp_arg_validate_int_range(args[ARG_gain].u_int, 1, 2, MP_QSTR_gain);
8985

9086
mcp4822_mcp4822_obj_t *self = mp_obj_malloc_with_finaliser(mcp4822_mcp4822_obj_t, &mcp4822_mcp4822_type);
9187
common_hal_mcp4822_mcp4822_construct(self, clock, mosi, cs, (uint8_t)gain);

0 commit comments

Comments
 (0)