summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/bitbangio/I2C.c2
-rw-r--r--shared-bindings/bitbangio/SPI.c13
-rw-r--r--shared-bindings/nativeio/AnalogOut.c3
-rw-r--r--shared-bindings/nativeio/DigitalInOut.c15
-rw-r--r--shared-bindings/nativeio/I2C.c2
-rw-r--r--shared-bindings/nativeio/PWMOut.c8
-rw-r--r--shared-bindings/nativeio/SPI.c15
-rw-r--r--shared-bindings/nativeio/UART.c6
-rw-r--r--shared-bindings/time/__init__.c6
9 files changed, 31 insertions, 39 deletions
diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c
index 5b772c9bf..e5c9831b5 100644
--- a/shared-bindings/bitbangio/I2C.c
+++ b/shared-bindings/bitbangio/I2C.c
@@ -100,7 +100,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_i2c_obj___exit___obj, 4, 4,
static void check_lock(bitbangio_i2c_obj_t *self) {
if (!shared_module_bitbangio_i2c_has_lock(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Function requires I2C lock."));
+ mp_raise_RuntimeError("Function requires lock");
}
}
diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c
index a5d3f358f..83eb1b204 100644
--- a/shared-bindings/bitbangio/SPI.c
+++ b/shared-bindings/bitbangio/SPI.c
@@ -33,6 +33,7 @@
#include "shared-bindings/microcontroller/Pin.h"
#include "lib/utils/context_manager_helpers.h"
+#include "py/mperrno.h"
#include "py/runtime.h"
//| .. currentmodule:: bitbangio
@@ -113,7 +114,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_obj___exit___obj, 4, 4,
static void check_lock(bitbangio_spi_obj_t *self) {
if (!shared_module_bitbangio_spi_has_lock(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Function requires SPI lock."));
+ mp_raise_RuntimeError("Function requires lock");
}
}
@@ -136,15 +137,15 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args,
uint8_t polarity = args[ARG_polarity].u_int;
if (polarity != 0 && polarity != 1) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid polarity."));
+ mp_raise_ValueError("Invalid polarity");
}
uint8_t phase = args[ARG_phase].u_int;
if (phase != 0 && phase != 1) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid phase."));
+ mp_raise_ValueError("Invalid phase");
}
uint8_t bits = args[ARG_bits].u_int;
if (bits != 8 && bits != 9) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid number of bits."));
+ mp_raise_ValueError("Invalid number of bits");
}
shared_module_bitbangio_spi_configure(self, args[ARG_baudrate].u_int, polarity, phase, bits);
@@ -183,7 +184,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
check_lock(self);
bool ok = shared_module_bitbangio_spi_write(self, src.buf, src.len);
if (!ok) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI bus error"));
+ mp_raise_OSError(MP_EIO);
}
return mp_const_none;
}
@@ -200,7 +201,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) {
check_lock(args[0]);
bool ok = shared_module_bitbangio_spi_read(args[0], bufinfo.buf, bufinfo.len);
if (!ok) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI bus error"));
+ mp_raise_OSError(MP_EIO);
}
return mp_const_none;
}
diff --git a/shared-bindings/nativeio/AnalogOut.c b/shared-bindings/nativeio/AnalogOut.c
index 950faabb5..a6996ba18 100644
--- a/shared-bindings/nativeio/AnalogOut.c
+++ b/shared-bindings/nativeio/AnalogOut.c
@@ -113,8 +113,7 @@ STATIC mp_obj_t nativeio_analogout_obj_set_value(mp_obj_t self_in, mp_obj_t valu
nativeio_analogout_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint32_t v = mp_obj_get_int(value);
if (v >= (1 << 16)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "AnalogOut is only 16 bits. Value must be less than 65536."));
+ mp_raise_ValueError("AnalogOut is only 16 bits. Value must be less than 65536.");
}
common_hal_nativeio_analogout_set_value(self, v);
return mp_const_none;
diff --git a/shared-bindings/nativeio/DigitalInOut.c b/shared-bindings/nativeio/DigitalInOut.c
index b45086be1..aa62f6a5f 100644
--- a/shared-bindings/nativeio/DigitalInOut.c
+++ b/shared-bindings/nativeio/DigitalInOut.c
@@ -220,8 +220,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(nativeio_digitalinout_get_value_obj, nativeio_digitali
STATIC mp_obj_t nativeio_digitalinout_obj_set_value(mp_obj_t self_in, mp_obj_t value) {
nativeio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_nativeio_digitalinout_get_direction(self) == DIRECTION_IN) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
- "Cannot set value when direction is input."));
+ mp_raise_AttributeError("Cannot set value when direction is input.");
return mp_const_none;
}
common_hal_nativeio_digitalinout_set_value(self, mp_obj_is_true(value));
@@ -243,8 +242,7 @@ mp_obj_property_t nativeio_digitalinout_value_obj = {
STATIC mp_obj_t nativeio_digitalinout_obj_get_drive_mode(mp_obj_t self_in) {
nativeio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_nativeio_digitalinout_get_direction(self) == DIRECTION_IN) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
- "Drive mode not used when direction is input."));
+ mp_raise_AttributeError("Drive mode not used when direction is input.");
return mp_const_none;
}
enum digitalinout_drive_mode_t drive_mode = common_hal_nativeio_digitalinout_get_drive_mode(self);
@@ -258,8 +256,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(nativeio_digitalinout_get_drive_mode_obj, nativeio_dig
STATIC mp_obj_t nativeio_digitalinout_obj_set_drive_mode(mp_obj_t self_in, mp_obj_t drive_mode) {
nativeio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_nativeio_digitalinout_get_direction(self) == DIRECTION_IN) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
- "Drive mode not used when direction is input."));
+ mp_raise_AttributeError("Drive mode not used when direction is input.");
return mp_const_none;
}
enum digitalinout_drive_mode_t c_drive_mode = DRIVE_MODE_PUSH_PULL;
@@ -287,8 +284,7 @@ mp_obj_property_t nativeio_digitalinout_drive_mode_obj = {
STATIC mp_obj_t nativeio_digitalinout_obj_get_pull(mp_obj_t self_in) {
nativeio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_nativeio_digitalinout_get_direction(self) == DIRECTION_OUT) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
- "Pull not used when direction is output."));
+ mp_raise_AttributeError("Pull not used when direction is output.");
return mp_const_none;
}
enum digitalinout_pull_t pull = common_hal_nativeio_digitalinout_get_pull(self);
@@ -304,8 +300,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(nativeio_digitalinout_get_pull_obj, nativeio_digitalin
STATIC mp_obj_t nativeio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t pull_obj) {
nativeio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_nativeio_digitalinout_get_direction(self) == DIRECTION_OUT) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
- "Pull not used when direction is output."));
+ mp_raise_AttributeError("Pull not used when direction is output.");
return mp_const_none;
}
enum digitalinout_pull_t pull = PULL_NONE;
diff --git a/shared-bindings/nativeio/I2C.c b/shared-bindings/nativeio/I2C.c
index 43cf7b63d..4b0f9a640 100644
--- a/shared-bindings/nativeio/I2C.c
+++ b/shared-bindings/nativeio/I2C.c
@@ -109,7 +109,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nativeio_i2c___exit___obj, 4, 4, nati
static void check_lock(nativeio_i2c_obj_t *self) {
if (!common_hal_nativeio_i2c_has_lock(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Function requires I2C lock."));
+ mp_raise_RuntimeError("Function requires lock.");
}
}
diff --git a/shared-bindings/nativeio/PWMOut.c b/shared-bindings/nativeio/PWMOut.c
index 330ffb187..bbb4e5a87 100644
--- a/shared-bindings/nativeio/PWMOut.c
+++ b/shared-bindings/nativeio/PWMOut.c
@@ -155,9 +155,7 @@ STATIC mp_obj_t nativeio_pwmout_obj_set_duty_cycle(mp_obj_t self_in, mp_obj_t du
nativeio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t duty = mp_obj_get_int(duty_cycle);
if (duty < 0 || duty > 0xffff) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "PWM duty must be between 0 and 65536 (16 bit resolution), not %d",
- duty));
+ mp_raise_ValueError("PWM duty must be between 0 and 65536 (16 bit resolution)");
}
common_hal_nativeio_pwmout_set_duty_cycle(self, duty);
return mp_const_none;
@@ -185,9 +183,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(nativeio_pwmout_get_frequency_obj, nativeio_pwmout_obj
STATIC mp_obj_t nativeio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t frequency) {
nativeio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!common_hal_nativeio_pwmout_get_variable_frequency(self)) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
+ mp_raise_AttributeError(
"PWM frequency not writeable when variable_frequency is False on "
- "construction."));
+ "construction.");
}
common_hal_nativeio_pwmout_set_frequency(self, mp_obj_get_int(frequency));
return mp_const_none;
diff --git a/shared-bindings/nativeio/SPI.c b/shared-bindings/nativeio/SPI.c
index 465334353..eb2f86e22 100644
--- a/shared-bindings/nativeio/SPI.c
+++ b/shared-bindings/nativeio/SPI.c
@@ -33,6 +33,7 @@
#include "shared-bindings/nativeio/SPI.h"
#include "lib/utils/context_manager_helpers.h"
+#include "py/mperrno.h"
#include "py/nlr.h"
#include "py/runtime.h"
@@ -124,7 +125,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nativeio_spi_obj___exit___obj, 4, 4,
static void check_lock(nativeio_spi_obj_t *self) {
if (!common_hal_nativeio_spi_has_lock(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Function requires SPI lock."));
+ mp_raise_RuntimeError("Function requires lock");
}
}
@@ -147,20 +148,20 @@ STATIC mp_obj_t nativeio_spi_configure(size_t n_args, const mp_obj_t *pos_args,
uint8_t polarity = args[ARG_polarity].u_int;
if (polarity != 0 && polarity != 1) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid polarity."));
+ mp_raise_ValueError("Invalid polarity");
}
uint8_t phase = args[ARG_phase].u_int;
if (phase != 0 && phase != 1) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid phase."));
+ mp_raise_ValueError("Invalid phase");
}
uint8_t bits = args[ARG_bits].u_int;
if (bits != 8 && bits != 9) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid number of bits."));
+ mp_raise_ValueError("Invalid number of bits");
}
if (!common_hal_nativeio_spi_configure(self, args[ARG_baudrate].u_int,
polarity, phase, bits)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI configure failed."));
+ mp_raise_OSError(MP_EIO);
}
return mp_const_none;
}
@@ -222,7 +223,7 @@ STATIC mp_obj_t nativeio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_m
bool ok = common_hal_nativeio_spi_write(self, ((uint8_t*)bufinfo.buf) + start, len);
if (!ok) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI bus error"));
+ mp_raise_OSError(MP_EIO);
}
return mp_const_none;
}
@@ -267,7 +268,7 @@ STATIC mp_obj_t nativeio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, m
bool ok = common_hal_nativeio_spi_read(self, ((uint8_t*)bufinfo.buf) + start, len, args[ARG_write_value].u_int);
if (!ok) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI bus error"));
+ mp_raise_OSError(MP_EIO);
}
return mp_const_none;
}
diff --git a/shared-bindings/nativeio/UART.c b/shared-bindings/nativeio/UART.c
index f4921814b..b4942b72f 100644
--- a/shared-bindings/nativeio/UART.c
+++ b/shared-bindings/nativeio/UART.c
@@ -92,8 +92,7 @@ STATIC mp_obj_t nativeio_uart_make_new(const mp_obj_type_t *type, size_t n_args,
uint8_t bits = args[ARG_bits].u_int;
if (bits < 7 || bits > 9) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "bits must be 7, 8 or 9"));
+ mp_raise_ValueError("bits must be 7, 8 or 9");
}
uart_parity_t parity = PARITY_NONE;
@@ -105,8 +104,7 @@ STATIC mp_obj_t nativeio_uart_make_new(const mp_obj_type_t *type, size_t n_args,
uint8_t stop = args[ARG_stop].u_int;
if (stop != 1 && stop != 2) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "stop must be 1 or 2"));
+ mp_raise_ValueError("stop must be 1 or 2");
}
common_hal_nativeio_uart_construct(self, tx, rx,
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index 36e63d36f..9c4cee8e0 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -69,7 +69,7 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
int seconds = mp_obj_get_int(seconds_o);
#endif
if (seconds < 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "sleep length must be non-negative"));
+ mp_raise_ValueError("sleep length must be non-negative");
}
common_hal_time_delay_ms(1000 * seconds);
return mp_const_none;
@@ -79,10 +79,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
#if MICROPY_PY_COLLECTIONS
mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
if (n_args != 1) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "time.struct_time() takes exactly 1 argument"));
+ mp_raise_TypeError("time.struct_time() takes exactly 1 argument");
}
if (!MP_OBJ_IS_TYPE(args[0], &mp_type_tuple) || ((mp_obj_tuple_t*) MP_OBJ_TO_PTR(args[0]))->len != 9) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "time.struct_time() takes a 9-sequence"));
+ mp_raise_TypeError("time.struct_time() takes a 9-sequence");
}
mp_obj_tuple_t* tuple = MP_OBJ_TO_PTR(args[0]);