summaryrefslogtreecommitdiff
path: root/cc3200/mods/pybi2c.c
diff options
context:
space:
mode:
authorDaniel Campora <daniel@wipy.io>2015-05-26 12:27:13 +0200
committerDaniel Campora <daniel@wipy.io>2015-05-26 12:29:20 +0200
commitfabe79f7afe6f4ee0bdc8ad41c83acb2a0e9eac8 (patch)
treea0ab8228f8adee06b7b19cb6b5c0b3896f74c267 /cc3200/mods/pybi2c.c
parent124aa000af47fea0e75ee53e7fff955c9b05386d (diff)
cc3200: Clean up exception handling.
Diffstat (limited to 'cc3200/mods/pybi2c.c')
-rw-r--r--cc3200/mods/pybi2c.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c
index 7d4f70e86..1b9c6ca16 100644
--- a/cc3200/mods/pybi2c.c
+++ b/cc3200/mods/pybi2c.c
@@ -280,6 +280,11 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, mp_uint_t n_args, const
mp_arg_val_t vals[PYB_I2C_INIT_NUM_ARGS];
mp_arg_parse_all(n_args, args, kw_args, PYB_I2C_INIT_NUM_ARGS, pyb_i2c_init_args, vals);
+ // verify that mode is master
+ if (vals[0].u_int != PYBI2C_MASTER) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
+ }
+
// make sure the baudrate is between the valid range
self->baudrate = MIN(MAX(vals[1].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ);
@@ -303,11 +308,6 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
// check arguments
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
- // work out the i2c bus id
- if (mp_obj_get_int(args[0]) != 1) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable));
- }
-
// setup the object
pyb_i2c_obj_t *self = &pyb_i2c_obj;
self->base.type = &pyb_i2c_type;