Skip to content

Commit e22dc0a

Browse files
committed
improve argument validation logic and error messages
1 parent cf41db1 commit e22dc0a

4 files changed

Lines changed: 8 additions & 13 deletions

File tree

locale/circuitpython.pot

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ msgstr ""
186186
msgid "%q must be 1 when %q is True"
187187
msgstr ""
188188

189+
#: ports/raspberrypi/common-hal/audioi2sin/I2SIn.c
190+
msgid "%q must be 16, 24, or 32"
191+
msgstr ""
192+
189193
#: shared-bindings/audioi2sin/I2SIn.c
190194
msgid "%q must be 8, 16, 24, or 32"
191195
msgstr ""
@@ -223,7 +227,7 @@ msgstr ""
223227
msgid "%q must be array of type 'h'"
224228
msgstr ""
225229

226-
#: shared-bindings/audiobusio/PDMIn.c shared-bindings/audioi2sin/I2SIn.c
230+
#: shared-bindings/audiobusio/PDMIn.c
227231
msgid "%q must be multiple of 8."
228232
msgstr ""
229233

@@ -2702,12 +2706,7 @@ msgstr ""
27022706
msgid "binary op %q not implemented"
27032707
msgstr ""
27042708

2705-
#: ports/raspberrypi/common-hal/audioi2sin/I2SIn.c
2706-
msgid "bit_depth must be 16, 24, or 32"
2707-
msgstr ""
2708-
27092709
#: ports/espressif/common-hal/audiobusio/PDMIn.c
2710-
#: ports/espressif/common-hal/audioi2sin/I2SIn.c
27112710
msgid "bit_depth must be 8, 16, 24, or 32."
27122711
msgstr ""
27132712

ports/espressif/common-hal/audioi2sin/I2SIn.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ void common_hal_audioi2sin_i2sin_construct(audioi2sin_i2sin_obj_t *self,
2323
uint32_t sample_rate, uint8_t bit_depth, uint8_t output_bit_depth,
2424
bool mono, bool left_justified, bool samples_signed) {
2525

26-
if (bit_depth != 8 && bit_depth != 16 && bit_depth != 24 && bit_depth != 32) {
27-
mp_raise_ValueError(MP_ERROR_TEXT("bit_depth must be 8, 16, 24, or 32."));
28-
}
29-
3026
i2s_data_bit_width_t bit_width = (i2s_data_bit_width_t)bit_depth;
3127

3228
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);

ports/raspberrypi/common-hal/audioi2sin/I2SIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void common_hal_audioi2sin_i2sin_construct(audioi2sin_i2sin_obj_t *self,
158158
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_main_clock);
159159
}
160160
if (bit_depth != 16 && bit_depth != 24 && bit_depth != 32) {
161-
mp_raise_ValueError(MP_ERROR_TEXT("bit_depth must be 16, 24, or 32"));
161+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be 16, 24, or 32"), MP_QSTR_bit_depth);
162162
}
163163

164164
// 24- and 32-bit recordings both clock 32 bits per channel; 24-bit MEMS

shared-bindings/audioi2sin/I2SIn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ static mp_obj_t audioi2sin_i2sin_make_new(const mp_obj_type_t *type, size_t n_ar
123123

124124
uint32_t sample_rate = args[ARG_sample_rate].u_int;
125125
uint8_t bit_depth = args[ARG_bit_depth].u_int;
126-
if (bit_depth % 8 != 0) {
127-
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be multiple of 8."), MP_QSTR_bit_depth);
126+
if (bit_depth != 8 && bit_depth != 16 && bit_depth != 24 && bit_depth != 32) {
127+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be 8, 16, 24, or 32"), MP_QSTR_bit_depth);
128128
}
129129
uint8_t output_bit_depth;
130130
mp_obj_t output_bit_depth_obj = args[ARG_output_bit_depth].u_obj;

0 commit comments

Comments
 (0)