all: Use MP_ERROR_TEXT for all error messages.

This commit is contained in:
Jim Mussared 2020-03-02 22:35:22 +11:00 committed by Damien George
parent 85858e72df
commit def76fe4d9
192 changed files with 823 additions and 919 deletions

View File

@ -45,7 +45,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) {
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE);
if (bufinfo.len < 5) {
mp_raise_ValueError("buffer too small");
mp_raise_ValueError(MP_ERROR_TEXT("buffer too small"));
}
// issue start command

View File

@ -45,7 +45,7 @@ STATIC mp_int_t fibonacci_helper(mp_int_t x) {
STATIC mp_obj_t fibonacci(mp_obj_t x_in) {
mp_int_t x = mp_obj_get_int(x_in);
if (x < 0) {
mp_raise_ValueError("can't compute negative Fibonacci number");
mp_raise_ValueError(MP_ERROR_TEXT("can't compute negative Fibonacci number"));
}
return mp_obj_new_int(fibonacci_helper(x));
}

View File

@ -52,7 +52,7 @@ STATIC mp_obj_t productf(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_o
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_RW);
if (bufinfo.typecode != 'f') {
mp_raise_ValueError("expecting float array");
mp_raise_ValueError(MP_ERROR_TEXT("expecting float array"));
}
// Compute product, store result back in first element of array

View File

@ -15,7 +15,7 @@ void mp_stack_check(void) {
// Assumes descending stack on target
volatile char dummy;
if (stack_top - &dummy >= STACK_LIMIT) {
mp_raise_msg(&mp_type_RuntimeError, "maximum recursion depth exceeded");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("maximum recursion depth exceeded"));
}
}

View File

@ -327,7 +327,7 @@ STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, s
extern mp_obj_t MICROPY_PY_MACHINE_I2C_MAKE_NEW(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
return MICROPY_PY_MACHINE_I2C_MAKE_NEW(type, n_args, n_kw, args);
#else
mp_raise_ValueError("invalid I2C peripheral");
mp_raise_ValueError(MP_ERROR_TEXT("invalid I2C peripheral"));
#endif
}
--n_args;
@ -367,7 +367,7 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->start == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}
int ret = i2c_p->start(self);
if (ret != 0) {
@ -381,7 +381,7 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->stop == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}
int ret = i2c_p->stop(self);
if (ret != 0) {
@ -395,7 +395,7 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->read == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}
// get the buffer to read into
@ -419,7 +419,7 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->write == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}
// get the buffer to write from

View File

@ -42,7 +42,7 @@
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
if ((addr & (align - 1)) != 0) {
mp_raise_msg_varg(&mp_type_ValueError, "address %08x is not aligned to %d bytes", addr, align);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("address %08x is not aligned to %d bytes"), addr, align);
}
return addr;
}

View File

@ -52,7 +52,7 @@ mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
extern mp_obj_t MICROPY_PY_MACHINE_SPI_MAKE_NEW(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
return MICROPY_PY_MACHINE_SPI_MAKE_NEW(type, n_args, n_kw, args);
#else
mp_raise_ValueError("invalid SPI peripheral");
mp_raise_ValueError(MP_ERROR_TEXT("invalid SPI peripheral"));
#endif
}
--n_args;
@ -119,7 +119,7 @@ STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp
mp_buffer_info_t dest;
mp_get_buffer_raise(rd_buf, &dest, MP_BUFFER_WRITE);
if (src.len != dest.len) {
mp_raise_ValueError("buffers must be the same length");
mp_raise_ValueError(MP_ERROR_TEXT("buffers must be the same length"));
}
mp_machine_spi_transfer(self, src.len, src.buf, dest.buf);
return mp_const_none;
@ -202,15 +202,15 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n
self->spi.polarity = args[ARG_polarity].u_int;
self->spi.phase = args[ARG_phase].u_int;
if (args[ARG_bits].u_int != 8) {
mp_raise_ValueError("bits must be 8");
mp_raise_ValueError(MP_ERROR_TEXT("bits must be 8"));
}
if (args[ARG_firstbit].u_int != MICROPY_PY_MACHINE_SPI_MSB) {
mp_raise_ValueError("firstbit must be MSB");
mp_raise_ValueError(MP_ERROR_TEXT("firstbit must be MSB"));
}
if (args[ARG_sck].u_obj == MP_OBJ_NULL
|| args[ARG_mosi].u_obj == MP_OBJ_NULL
|| args[ARG_miso].u_obj == MP_OBJ_NULL) {
mp_raise_ValueError("must specify all of sck/mosi/miso");
mp_raise_ValueError(MP_ERROR_TEXT("must specify all of sck/mosi/miso"));
}
self->spi.sck = mp_hal_get_pin_obj(args[ARG_sck].u_obj);
self->spi.mosi = mp_hal_get_pin_obj(args[ARG_mosi].u_obj);

View File

@ -91,7 +91,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
self->type = MP_BLUETOOTH_UUID_TYPE_16;
mp_int_t value = mp_obj_get_int(all_args[0]);
if (value > 65535) {
mp_raise_ValueError("invalid UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid UUID"));
}
self->data[0] = value & 0xff;
self->data[1] = (value >> 8) & 0xff;
@ -112,12 +112,12 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
continue;
}
if (!unichar_isxdigit(c)) {
mp_raise_ValueError("invalid char in UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid char in UUID"));
}
c = unichar_xdigit_value(c);
uuid_i--;
if (uuid_i < 0) {
mp_raise_ValueError("UUID too long");
mp_raise_ValueError(MP_ERROR_TEXT("UUID too long"));
}
if (uuid_i % 2 == 0) {
// lower nibble
@ -128,7 +128,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
}
}
if (uuid_i > 0) {
mp_raise_ValueError("UUID too short");
mp_raise_ValueError(MP_ERROR_TEXT("UUID too short"));
}
}
}
@ -283,7 +283,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
if (kwargs->used == 0) {
// Get config value
if (n_args != 2) {
mp_raise_TypeError("must query one param");
mp_raise_TypeError(MP_ERROR_TEXT("must query one param"));
}
switch (mp_obj_str_get_qstr(args[1])) {
@ -295,12 +295,12 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
case MP_QSTR_rxbuf:
return mp_obj_new_int(self->ringbuf.size);
default:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
} else {
// Set config value(s)
if (n_args != 1) {
mp_raise_TypeError("can't specify pos and kw args");
mp_raise_TypeError(MP_ERROR_TEXT("can't specify pos and kw args"));
}
for (size_t i = 0; i < kwargs->alloc; ++i) {
@ -341,7 +341,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
break;
}
default:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
}
}
@ -361,7 +361,7 @@ STATIC mp_obj_t bluetooth_ble_irq(size_t n_args, const mp_obj_t *pos_args, mp_ma
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_obj_t callback = args[ARG_handler].u_obj;
if (callback != mp_const_none && !mp_obj_is_callable(callback)) {
mp_raise_ValueError("invalid callback");
mp_raise_ValueError(MP_ERROR_TEXT("invalid callback"));
}
// Update the callback.
@ -414,7 +414,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_gap_advertise_obj, 1, bluetooth_
STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t characteristics_in, uint16_t **handles, size_t *num_handles) {
if (!mp_obj_is_type(uuid_in, &bluetooth_uuid_type)) {
mp_raise_ValueError("invalid service UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid service UUID"));
}
mp_obj_bluetooth_uuid_t *service_uuid = MP_OBJ_TO_PTR(uuid_in);
@ -451,11 +451,11 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
mp_obj_get_array(characteristic_obj, &characteristic_len, &characteristic_items);
if (characteristic_len < 2 || characteristic_len > 3) {
mp_raise_ValueError("invalid characteristic tuple");
mp_raise_ValueError(MP_ERROR_TEXT("invalid characteristic tuple"));
}
mp_obj_t uuid_obj = characteristic_items[0];
if (!mp_obj_is_type(uuid_obj, &bluetooth_uuid_type)) {
mp_raise_ValueError("invalid characteristic UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid characteristic UUID"));
}
(*handles)[handle_index++] = 0xffff;
@ -487,7 +487,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
mp_obj_get_array_fixed_n(descriptor_obj, 2, &descriptor_items);
mp_obj_t desc_uuid_obj = descriptor_items[0];
if (!mp_obj_is_type(desc_uuid_obj, &bluetooth_uuid_type)) {
mp_raise_ValueError("invalid descriptor UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid descriptor UUID"));
}
descriptor_uuids[descriptor_index] = MP_OBJ_TO_PTR(desc_uuid_obj);
@ -567,7 +567,7 @@ STATIC mp_obj_t bluetooth_ble_gap_connect(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo = {0};
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
mp_raise_ValueError("invalid addr");
mp_raise_ValueError(MP_ERROR_TEXT("invalid addr"));
}
mp_int_t scan_duration_ms = MP_BLUETOOTH_CONNECT_DEFAULT_SCAN_DURATION_MS;
if (n_args == 4) {

View File

@ -300,7 +300,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
case FRAMEBUF_GS8:
break;
default:
mp_raise_ValueError("invalid format");
mp_raise_ValueError(MP_ERROR_TEXT("invalid format"));
}
return MP_OBJ_FROM_PTR(o);

View File

@ -144,15 +144,15 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
ip_addr_t iplocal, ipremote;
if (!ipaddr_aton(mp_obj_str_get_str(args[1]), &iplocal)) {
mp_raise_ValueError("not a valid local IP");
mp_raise_ValueError(MP_ERROR_TEXT("not a valid local IP"));
}
if (!ipaddr_aton(mp_obj_str_get_str(args[2]), &ipremote)) {
mp_raise_ValueError("not a valid remote IP");
mp_raise_ValueError(MP_ERROR_TEXT("not a valid remote IP"));
}
struct netif *n = &lwip_slip_obj.lwip_netif;
if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) {
mp_raise_ValueError("out of memory");
mp_raise_ValueError(MP_ERROR_TEXT("out of memory"));
}
netif_set_up(n);
netif_set_default(n);

View File

@ -112,7 +112,7 @@ STATIC mp_obj_t task_queue_pop_head(mp_obj_t self_in) {
mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_task_t *head = (mp_obj_task_t *)mp_pairheap_peek(task_lt, &self->heap->pairheap);
if (head == NULL) {
mp_raise_msg(&mp_type_IndexError, "empty heap");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
}
self->heap = (mp_obj_task_t *)mp_pairheap_pop(task_lt, &self->heap->pairheap);
return MP_OBJ_FROM_PTR(head);
@ -173,7 +173,7 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) {
// Can't cancel self (not supported yet).
mp_obj_t cur_task = mp_obj_dict_get(uasyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
if (self_in == cur_task) {
mp_raise_msg(&mp_type_RuntimeError, "cannot cancel self");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("cannot cancel self"));
}
// If Task waits on another task then forward the cancel to the one it's waiting on.
while (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(mp_obj_get_type(self->data)), MP_OBJ_FROM_PTR(&task_type))) {

View File

@ -79,7 +79,7 @@ STATIC mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
if ((bufinfo.len & 1) != 0) {
mp_raise_ValueError("odd-length string");
mp_raise_ValueError(MP_ERROR_TEXT("odd-length string"));
}
vstr_t vstr;
vstr_init_len(&vstr, bufinfo.len / 2);
@ -90,7 +90,7 @@ STATIC mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
if (unichar_isxdigit(hex_ch)) {
hex_byte += unichar_xdigit_value(hex_ch);
} else {
mp_raise_ValueError("non-hex digit found");
mp_raise_ValueError(MP_ERROR_TEXT("non-hex digit found"));
}
if (i & 1) {
hex_byte <<= 4;
@ -158,7 +158,7 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
}
if (nbits) {
mp_raise_ValueError("incorrect padding");
mp_raise_ValueError(MP_ERROR_TEXT("incorrect padding"));
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);

View File

@ -225,7 +225,7 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
break;
default:
mp_raise_ValueError("mode");
mp_raise_ValueError(MP_ERROR_TEXT("mode"));
}
mp_obj_aes_t *o = m_new_obj_var(mp_obj_aes_t, struct ctr_params, !!is_ctr_mode(block_mode));
@ -237,7 +237,7 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
mp_buffer_info_t keyinfo;
mp_get_buffer_raise(args[0], &keyinfo, MP_BUFFER_READ);
if (32 != keyinfo.len && 16 != keyinfo.len) {
mp_raise_ValueError("key");
mp_raise_ValueError(MP_ERROR_TEXT("key"));
}
mp_buffer_info_t ivinfo;
@ -246,10 +246,10 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
mp_get_buffer_raise(args[2], &ivinfo, MP_BUFFER_READ);
if (16 != ivinfo.len) {
mp_raise_ValueError("IV");
mp_raise_ValueError(MP_ERROR_TEXT("IV"));
}
} else if (o->block_mode == UCRYPTOLIB_MODE_CBC || is_ctr_mode(o->block_mode)) {
mp_raise_ValueError("IV");
mp_raise_ValueError(MP_ERROR_TEXT("IV"));
}
if (is_ctr_mode(block_mode)) {
@ -274,7 +274,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
mp_get_buffer_raise(in_buf, &in_bufinfo, MP_BUFFER_READ);
if (!is_ctr_mode(self->block_mode) && in_bufinfo.len % 16 != 0) {
mp_raise_ValueError("blksize % 16");
mp_raise_ValueError(MP_ERROR_TEXT("blksize % 16"));
}
vstr_t vstr;
@ -284,7 +284,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
if (out_buf != MP_OBJ_NULL) {
mp_get_buffer_raise(out_buf, &out_bufinfo, MP_BUFFER_WRITE);
if (out_bufinfo.len < in_bufinfo.len) {
mp_raise_ValueError("output too small");
mp_raise_ValueError(MP_ERROR_TEXT("output too small"));
}
out_buf_ptr = out_bufinfo.buf;
} else {
@ -301,7 +301,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
if ((encrypt && self->key_type == AES_KEYTYPE_DEC) ||
(!encrypt && self->key_type == AES_KEYTYPE_ENC)) {
mp_raise_ValueError("can't encrypt & decrypt");
mp_raise_ValueError(MP_ERROR_TEXT("can't encrypt & decrypt"));
}
}

View File

@ -117,7 +117,7 @@ typedef struct _mp_obj_uctypes_struct_t {
} mp_obj_uctypes_struct_t;
STATIC NORETURN void syntax_error(void) {
mp_raise_TypeError("syntax error in uctypes descriptor");
mp_raise_TypeError(MP_ERROR_TEXT("syntax error in uctypes descriptor"));
}
STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@ -226,7 +226,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
// but scalar structure field is lowered into native Python int, so all
// type info is lost. So, we cannot say if it's scalar type description,
// or such lowered scalar.
mp_raise_TypeError("Cannot unambiguously get sizeof scalar");
mp_raise_TypeError(MP_ERROR_TEXT("Cannot unambiguously get sizeof scalar"));
}
syntax_error();
}
@ -424,7 +424,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
&& !mp_obj_is_type(self->desc, &mp_type_ordereddict)
#endif
) {
mp_raise_TypeError("struct: no fields");
mp_raise_TypeError(MP_ERROR_TEXT("struct: no fields"));
}
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
@ -557,7 +557,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
} else {
// load / store
if (!mp_obj_is_type(self->desc, &mp_type_tuple)) {
mp_raise_TypeError("struct: cannot index");
mp_raise_TypeError(MP_ERROR_TEXT("struct: cannot index"));
}
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
@ -571,7 +571,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
arr_sz &= VALUE_MASK(VAL_TYPE_BITS);
if (index >= arr_sz) {
mp_raise_msg(&mp_type_IndexError, "struct: index out of range");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("struct: index out of range"));
}
if (t->len == 2) {

View File

@ -33,7 +33,7 @@
STATIC mp_obj_list_t *uheapq_get_heap(mp_obj_t heap_in) {
if (!mp_obj_is_type(heap_in, &mp_type_list)) {
mp_raise_TypeError("heap must be a list");
mp_raise_TypeError(MP_ERROR_TEXT("heap must be a list"));
}
return MP_OBJ_TO_PTR(heap_in);
}
@ -81,7 +81,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
mp_obj_list_t *heap = uheapq_get_heap(heap_in);
if (heap->len == 0) {
mp_raise_msg(&mp_type_IndexError, "empty heap");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
}
mp_obj_t item = heap->items[0];
heap->len -= 1;

View File

@ -295,7 +295,7 @@ success:
return stack_top;
fail:
mp_raise_ValueError("syntax error in JSON");
mp_raise_ValueError(MP_ERROR_TEXT("syntax error in JSON"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);

View File

@ -235,7 +235,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte *)subj.begin, caps[0] - subj.begin);
mp_obj_list_append(retval, s);
if (self->re.sub > 0) {
mp_raise_NotImplementedError("Splitting with sub-captures");
mp_raise_NotImplementedError(MP_ERROR_TEXT("Splitting with sub-captures"));
}
subj.begin = caps[1];
if (maxsplit > 0 && --maxsplit == 0) {
@ -403,7 +403,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
int error = re1_5_compilecode(&o->re, re_str);
if (error != 0) {
error:
mp_raise_ValueError("Error in regex");
mp_raise_ValueError(MP_ERROR_TEXT("Error in regex"));
}
#if MICROPY_PY_URE_DEBUG
if (flags & FLAG_DEBUG) {

View File

@ -82,13 +82,13 @@ STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args
const byte *data = (const byte *)mp_obj_str_get_data(args->key.u_obj, &len);
int res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_RSA_KEY, data, len, NULL);
if (res != SSL_OK) {
mp_raise_ValueError("invalid key");
mp_raise_ValueError(MP_ERROR_TEXT("invalid key"));
}
data = (const byte *)mp_obj_str_get_data(args->cert.u_obj, &len);
res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_X509_CERT, data, len, NULL);
if (res != SSL_OK) {
mp_raise_ValueError("invalid cert");
mp_raise_ValueError(MP_ERROR_TEXT("invalid cert"));
}
}

View File

@ -217,9 +217,9 @@ cleanup:
if (ret == MBEDTLS_ERR_SSL_ALLOC_FAILED) {
mp_raise_OSError(MP_ENOMEM);
} else if (ret == MBEDTLS_ERR_PK_BAD_INPUT_DATA) {
mp_raise_ValueError("invalid key");
mp_raise_ValueError(MP_ERROR_TEXT("invalid key"));
} else if (ret == MBEDTLS_ERR_X509_BAD_INPUT_DATA) {
mp_raise_ValueError("invalid cert");
mp_raise_ValueError(MP_ERROR_TEXT("invalid cert"));
} else {
mp_raise_OSError(MP_EIO);
}

View File

@ -126,7 +126,7 @@ STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
mp_obj_t heap_in = args[0];
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
if (heap->len == heap->alloc) {
mp_raise_msg(&mp_type_IndexError, "queue overflow");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("queue overflow"));
}
mp_uint_t l = heap->len;
heap->items[l].time = MP_OBJ_SMALL_INT_VALUE(args[1]);
@ -142,7 +142,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_utimeq_heappush_obj, 4, 4, mod_ut
STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
if (heap->len == 0) {
mp_raise_msg(&mp_type_IndexError, "empty heap");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
}
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
if (!mp_obj_is_type(list_ref, &mp_type_list) || ret->len < 3) {
@ -167,7 +167,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_utimeq_heappop_obj, mod_utimeq_heappop);
STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
if (heap->len == 0) {
mp_raise_msg(&mp_type_IndexError, "empty heap");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
}
struct qentry *item = &heap->items[0];

View File

@ -92,7 +92,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size
dict_opt = uzlib_zlib_parse_header(&o->decomp);
if (dict_opt < 0) {
header_error:
mp_raise_ValueError("compression header");
mp_raise_ValueError(MP_ERROR_TEXT("compression header"));
}
dict_sz = 1 << dict_opt;
} else {

View File

@ -196,7 +196,7 @@ STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
int scan_res = cyw43_wifi_scan(self->cyw, &opts, MP_OBJ_TO_PTR(res), network_cyw43_scan_cb);
if (scan_res < 0) {
mp_raise_msg(&mp_type_OSError, "STA must be active");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("STA must be active"));
}
// Wait for scan to finish, with a 10s timeout
@ -279,7 +279,7 @@ STATIC mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) {
case MP_QSTR_stations: {
// return list of connected stations
if (self->itf != CYW43_ITF_AP) {
mp_raise_ValueError("AP required");
mp_raise_ValueError(MP_ERROR_TEXT("AP required"));
}
int num_stas;
uint8_t macs[32 * 6];
@ -295,7 +295,7 @@ STATIC mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) {
}
}
mp_raise_ValueError("unknown status param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown status param"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_status_obj, 1, 2, network_cyw43_status);
@ -316,7 +316,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
if (kwargs->used == 0) {
// Get config value
if (n_args != 2) {
mp_raise_TypeError("must query one param");
mp_raise_TypeError(MP_ERROR_TEXT("must query one param"));
}
switch (mp_obj_str_get_qstr(args[1])) {
@ -354,12 +354,12 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
return MP_OBJ_NEW_SMALL_INT(nw_get_le32(buf) / 4);
}
default:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
} else {
// Set config value(s)
if (n_args != 1) {
mp_raise_TypeError("can't specify pos and kw args");
mp_raise_TypeError(MP_ERROR_TEXT("can't specify pos and kw args"));
}
for (size_t i = 0; i < kwargs->alloc; ++i) {
@ -420,7 +420,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
break;
}
default:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
}
}

View File

@ -179,7 +179,7 @@ STATIC mp_obj_t mp_uos_dupterm(size_t n_args, const mp_obj_t *args) {
}
if (idx < 0 || idx >= MICROPY_PY_OS_DUPTERM) {
mp_raise_ValueError("invalid dupterm index");
mp_raise_ValueError(MP_ERROR_TEXT("invalid dupterm index"));
}
mp_obj_t previous_obj = MP_STATE_VM(dupterm_objs[idx]);

View File

@ -47,7 +47,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
#ifdef MICROPY_CPYTHON_COMPAT
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
if (o->fd < 0) {
mp_raise_ValueError("I/O operation on closed file");
mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file"));
}
}
#else

View File

@ -3,5 +3,5 @@
NORETURN void abort_(void);
NORETURN void abort_(void) {
mp_raise_msg(&mp_type_RuntimeError, "abort() called");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("abort() called"));
}

View File

@ -79,7 +79,7 @@ void netutils_parse_ipv4_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian
} else if (i > 0 && s < s_top && *s == '.') {
s++;
} else {
mp_raise_ValueError("invalid arguments");
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
}
}
}

View File

@ -73,7 +73,6 @@ APP_MISC_SRC_C = $(addprefix misc/,\
help.c \
mpirq.c \
mperror.c \
mpexception.c \
)
APP_MODS_SRC_C = $(addprefix mods/,\
@ -112,12 +111,12 @@ APP_CC3100_SRC_C = $(addprefix drivers/cc3100/src/,\
APP_SL_SRC_C = $(addprefix simplelink/,\
oslib/osi_freertos.c \
cc_pal.c \
)
)
APP_TELNET_SRC_C = $(addprefix telnet/,\
telnet.c \
)
APP_UTIL_SRC_C = $(addprefix util/,\
cryptohash.c \
fifo.c \
@ -125,18 +124,18 @@ APP_UTIL_SRC_C = $(addprefix util/,\
random.c \
socketfifo.c \
)
APP_UTIL_SRC_S = $(addprefix util/,\
sleeprestore.s \
)
APP_MAIN_SRC_C = \
main.c \
mptask.c \
mpthreadport.c \
serverstask.c \
fatfs_port.c \
APP_LIB_SRC_C = $(addprefix lib/,\
oofatfs/ff.c \
oofatfs/ffunicode.c \
@ -148,7 +147,7 @@ APP_LIB_SRC_C = $(addprefix lib/,\
utils/interrupt_char.c \
utils/sys_stdio_mphal.c \
)
APP_STM_SRC_C = $(addprefix ports/stm32/,\
bufhelper.c \
irq.c \

View File

@ -45,7 +45,6 @@
#include "systick.h"
#include "prcm.h"
#include "pin.h"
#include "mpexception.h"
#include "telnet.h"
#include "pybuart.h"
#include "utils.h"

View File

@ -1,39 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Daniel Campora
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdint.h>
#include <string.h>
#include "mpexception.h"
/******************************************************************************
DECLARE EXPORTED DATA
******************************************************************************/
const char mpexception_value_invalid_arguments[] = "invalid argument(s) value";
const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type";
const char mpexception_uncaught[] = "uncaught exception";

View File

@ -1,34 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Daniel Campora
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H
#define MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H
extern const char mpexception_value_invalid_arguments[];
extern const char mpexception_num_type_invalid_arguments[];
extern const char mpexception_uncaught[];
#endif // MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H

View File

@ -33,7 +33,6 @@
#include "inc/hw_types.h"
#include "interrupt.h"
#include "pybsleep.h"
#include "mpexception.h"
#include "mperror.h"
#include "mpirq.h"
@ -112,7 +111,7 @@ void mp_irq_remove (const mp_obj_t parent) {
uint mp_irq_translate_priority (uint priority) {
if (priority < 1 || priority > MP_ARRAY_SIZE(mp_irq_priorities)) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
return mp_irq_priorities[priority - 1];
}

View File

@ -47,7 +47,6 @@
#include "FreeRTOS.h"
#include "portable.h"
#include "task.h"
#include "mpexception.h"
#include "random.h"
#include "pybadc.h"
#include "pybi2c.h"
@ -125,7 +124,7 @@ STATIC mp_obj_t machine_main(mp_obj_t main) {
if (mp_obj_is_str(main)) {
MP_STATE_PORT(machine_config_main) = main;
} else {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
return mp_const_none;
}

View File

@ -29,7 +29,6 @@
#include "py/mperrno.h"
#include "py/mphal.h"
#include "modnetwork.h"
#include "mpexception.h"
#include "serverstask.h"
#include "simplelink.h"

View File

@ -41,7 +41,6 @@
#include "prcm.h"
#include "shamd5.h"
#include "cryptohash.h"
#include "mpexception.h"
/******************************************************************************

View File

@ -40,7 +40,6 @@
#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
#include "random.h"
#include "mpexception.h"
#include "version.h"
#include "pybsd.h"
#include "pybuart.h"

View File

@ -38,7 +38,6 @@
#include "lib/netutils/netutils.h"
#include "modnetwork.h"
#include "modusocket.h"
#include "mpexception.h"
/******************************************************************************/
// The following set of macros and functions provide a glue between the CC3100

View File

@ -33,7 +33,6 @@
#include "py/runtime.h"
#include "modnetwork.h"
#include "modusocket.h"
#include "mpexception.h"
/******************************************************************************
DEFINE CONSTANTS
@ -133,7 +132,7 @@ socket_error:
mp_raise_OSError(_errno);
arg_error:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket);

View File

@ -42,7 +42,6 @@
#include "prcm.h"
#include "systick.h"
#include "pybrtc.h"
#include "mpexception.h"
#include "utils.h"
/// \module time - time related functions
@ -109,7 +108,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) {
// localtime generates a tuple of len 8. CPython uses 9, so we accept both.
if (len < 8 || len > 9) {
mp_raise_TypeError(mpexception_num_type_invalid_arguments);
mp_raise_TypeError(MP_ERROR_TEXT("invalid argument(s) num/type"));
}
return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]),

View File

@ -45,7 +45,6 @@
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
#include "serverstask.h"
#endif
#include "mpexception.h"
#include "mpirq.h"
#include "pybsleep.h"
#include "antenna.h"
@ -589,7 +588,7 @@ STATIC void wlan_reset (void) {
STATIC void wlan_validate_mode (uint mode) {
if (mode != ROLE_STA && mode != ROLE_AP) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
@ -600,7 +599,7 @@ STATIC void wlan_set_mode (uint mode) {
STATIC void wlan_validate_ssid_len (uint32_t len) {
if (len > MODWLAN_SSID_LEN_MAX) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
@ -633,7 +632,7 @@ STATIC void wlan_validate_security (uint8_t auth, const char *key, uint8_t len)
return;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len) {
@ -656,7 +655,7 @@ STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len) {
STATIC void wlan_validate_channel (uint8_t channel) {
if (channel < 1 || channel > 11) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
@ -668,7 +667,7 @@ STATIC void wlan_set_channel (uint8_t channel) {
#if MICROPY_HW_ANTENNA_DIVERSITY
STATIC void wlan_validate_antenna (uint8_t antenna) {
if (antenna != ANTENNA_TYPE_INTERNAL && antenna != ANTENNA_TYPE_EXTERNAL) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
@ -964,7 +963,7 @@ STATIC mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
if (status == MODWLAN_ERROR_TIMEOUT) {
mp_raise_OSError(MP_ETIMEDOUT);
} else if (status == MODWLAN_ERROR_INVALID_PARAMS) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
return mp_const_none;
}
@ -1040,7 +1039,7 @@ STATIC mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t
// check for the correct string
const char *mode = mp_obj_str_get_str(args[1].u_obj);
if (strcmp("dhcp", mode)) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
// only if we are not in AP mode
@ -1154,7 +1153,7 @@ STATIC mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
memcpy(self->mac, bufinfo.buf, SL_MAC_ADDR_LEN);
sl_NetCfgSet(SL_MAC_ADDRESS_SET, 1, SL_MAC_ADDR_LEN, (_u8 *)self->mac);
@ -1190,7 +1189,7 @@ STATIC mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
return _irq;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
@ -1219,7 +1218,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
//
// // the call to sl_NetAppSet corrupts the input string URN=args[1], so we copy into a local buffer
// if (len > MAX_DEVICE_URN_LEN) {
// mp_raise_ValueError(mpexception_value_invalid_arguments);
// mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
// }
// strcpy(urn, p);
//

View File

@ -47,7 +47,6 @@
#include "pybpin.h"
#include "pybsleep.h"
#include "pins.h"
#include "mpexception.h"
/******************************************************************************
@ -153,7 +152,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
// check the number of bits
if (args[1].u_int != 12) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
// setup the object
@ -172,7 +171,7 @@ STATIC mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_adc_init_args[1], args);
// check the number of bits
if (args[0].u_int != 12) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
pyb_adc_init(pos_args[0]);
return mp_const_none;
@ -205,11 +204,11 @@ STATIC mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
if (args[0].u_obj != MP_OBJ_NULL) {
ch_id = mp_obj_get_int(args[0].u_obj);
if (ch_id >= PYB_ADC_NUM_CHANNELS) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
} else if (args[1].u_obj != mp_const_none) {
uint pin_ch_id = pin_find_peripheral_type (args[1].u_obj, PIN_FN_ADC, 0);
if (ch_id != pin_ch_id) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
} else {

View File

@ -41,7 +41,6 @@
#include "prcm.h"
#include "i2c.h"
#include "pybi2c.h"
#include "mpexception.h"
#include "pybsleep.h"
#include "utils.h"
#include "pybpin.h"

View File

@ -44,7 +44,6 @@
#include "mpirq.h"
#include "pins.h"
#include "pybsleep.h"
#include "mpexception.h"
#include "mperror.h"
@ -142,7 +141,7 @@ pin_obj_t *pin_find(mp_obj_t user_obj) {
return pin_obj;
}
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
void pin_config (pin_obj_t *self, int af, uint mode, uint pull, int value, uint strength) {
@ -182,7 +181,7 @@ uint8_t pin_find_peripheral_unit (const mp_obj_t pin, uint8_t fn, uint8_t type)
return pin_o->af_list[i].unit;
}
}
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
uint8_t pin_find_peripheral_type (const mp_obj_t pin, uint8_t fn, uint8_t unit) {
@ -192,13 +191,13 @@ uint8_t pin_find_peripheral_type (const mp_obj_t pin, uint8_t fn, uint8_t unit)
return pin_o->af_list[i].type;
}
}
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
int8_t pin_find_af_index (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type) {
int8_t af = pin_obj_find_af(pin, fn, unit, type);
if (af < 0) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
return af;
}
@ -423,18 +422,18 @@ STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t prio
STATIC void pin_validate_mode (uint mode) {
if (mode != GPIO_DIR_MODE_IN && mode != GPIO_DIR_MODE_OUT && mode != PIN_TYPE_OD &&
mode != GPIO_DIR_MODE_ALT && mode != GPIO_DIR_MODE_ALT_OD) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
STATIC void pin_validate_pull (uint pull) {
if (pull != PIN_TYPE_STD && pull != PIN_TYPE_STD_PU && pull != PIN_TYPE_STD_PD) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
STATIC void pin_validate_drive(uint strength) {
if (strength != PIN_STRENGTH_2MA && strength != PIN_STRENGTH_4MA && strength != PIN_STRENGTH_6MA) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
@ -447,7 +446,7 @@ STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8
return;
}
}
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC uint8_t pin_get_value (const pin_obj_t* self) {
@ -588,7 +587,7 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj
return mp_const_none;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@ -895,7 +894,7 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
return _irq;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);

View File

@ -41,7 +41,6 @@
#include "simplelink.h"
#include "modnetwork.h"
#include "modwlan.h"
#include "mpexception.h"
/// \moduleref pyb
/// \class RTC - real time clock
@ -201,7 +200,7 @@ STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) {
// verify the tuple
if (len < 3 || len > 8) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
tm.tm_year = mp_obj_get_int(items[0]);
@ -370,7 +369,7 @@ STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t
if (mp_obj_is_type(args[1].u_obj, &mp_type_tuple)) { // datetime tuple given
// repeat cannot be used with a datetime tuple
if (repeat) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
f_mseconds = pyb_rtc_datetime_s_us (args[1].u_obj, &f_seconds) / 1000;
} else { // then it must be an integer
@ -452,7 +451,7 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
return _irq;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);

View File

@ -42,7 +42,6 @@
#include "sdhost.h"
#include "sd_diskio.h"
#include "pybsd.h"
#include "mpexception.h"
#include "pybsleep.h"
#include "pybpin.h"
#include "pins.h"

View File

@ -49,7 +49,6 @@
#include "modwlan.h"
#include "osi.h"
#include "debug.h"
#include "mpexception.h"
#include "mperror.h"
#include "sleeprestore.h"
#include "serverstask.h"

View File

@ -40,7 +40,6 @@
#include "prcm.h"
#include "spi.h"
#include "pybspi.h"
#include "mpexception.h"
#include "pybsleep.h"
#include "pybpin.h"
#include "pins.h"
@ -213,7 +212,7 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *arg
return mp_const_none;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
static const mp_arg_t pyb_spi_init_args[] = {
@ -351,7 +350,7 @@ STATIC mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj
// get the read buffer
mp_get_buffer_raise(readbuf, &bufinfo_read, MP_BUFFER_WRITE);
if (bufinfo_read.len != bufinfo_write.len) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}

View File

@ -47,7 +47,6 @@
#include "pins.h"
#include "mpirq.h"
#include "pybsleep.h"
#include "mpexception.h"
/// \moduleref pyb
@ -221,7 +220,7 @@ STATIC uint32_t compute_prescaler_period_and_match_value(pyb_timer_channel_obj_t
return prescaler;
error:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC void timer_init (pyb_timer_obj_t *tim) {
@ -317,7 +316,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const
return mp_const_none;
error:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@ -438,7 +437,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
return ch;
error:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
@ -558,7 +557,7 @@ STATIC mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) {
// set
int32_t _frequency = mp_obj_get_int(args[1]);
if (_frequency <= 0) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
ch->frequency = _frequency;
ch->period = 1000000 / _frequency;
@ -577,7 +576,7 @@ STATIC mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) {
// set
int32_t _period = mp_obj_get_int(args[1]);
if (_period <= 0) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
ch->period = _period;
ch->frequency = 1000000 / _period;
@ -710,7 +709,7 @@ STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, m
return _irq;
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_irq_obj, 1, pyb_timer_channel_irq);

View File

@ -45,7 +45,6 @@
#include "pybuart.h"
#include "mpirq.h"
#include "pybsleep.h"
#include "mpexception.h"
#include "osi.h"
#include "utils.h"
#include "pin.h"
@ -431,7 +430,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a
return mp_const_none;
error:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC const mp_arg_t pyb_uart_init_args[] = {
@ -555,7 +554,7 @@ STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
return uart_irq_new (self, trigger, priority, args[2].u_obj);
invalid_args:
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq);

View File

@ -40,7 +40,6 @@
#include "prcm.h"
#include "utils.h"
#include "pybwdt.h"
#include "mpexception.h"
#include "mperror.h"
@ -105,7 +104,7 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_
}
uint timeout_ms = args[1].u_int;
if (timeout_ms < PYBWDT_MIN_TIMEOUT_MS) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
if (pyb_wdt_obj.running) {
mp_raise_OSError(MP_EPERM);

View File

@ -132,7 +132,7 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
TaskHandle_t id = xTaskCreateStatic(freertos_entry, "Thread", *stack_size / sizeof(void *), arg, 2, stack, tcb);
if (id == NULL) {
mp_thread_mutex_unlock(&thread_mutex);
mp_raise_msg(&mp_type_OSError, "can't create thread");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't create thread"));
}
// add thread to linked list of all threads

View File

@ -38,7 +38,6 @@
#include "ftp.h"
#include "pybwdt.h"
#include "modusocket.h"
#include "mpexception.h"
#include "modnetwork.h"
#include "modwlan.h"
@ -184,7 +183,7 @@ void servers_close_socket (int16_t *sd) {
void servers_set_login (char *user, char *pass) {
if (strlen(user) > SERVERS_USER_PASS_LEN_MAX || strlen(pass) > SERVERS_USER_PASS_LEN_MAX) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
memcpy(servers_user, user, SERVERS_USER_PASS_LEN_MAX);
memcpy(servers_pass, pass, SERVERS_USER_PASS_LEN_MAX);
@ -193,7 +192,7 @@ void servers_set_login (char *user, char *pass) {
void servers_set_timeout (uint32_t timeout) {
if (timeout < SERVERS_MIN_TIMEOUT_MS) {
// timeout is too low
mp_raise_ValueError(mpexception_value_invalid_arguments);
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
servers_data.timeout = timeout;
}

View File

@ -35,7 +35,6 @@
#include "modwlan.h"
#include "modusocket.h"
#include "debug.h"
#include "mpexception.h"
#include "serverstask.h"
#include "genhdr/mpversion.h"
#include "irq.h"

View File

@ -61,7 +61,7 @@ typedef struct _esp32_rmt_obj_t {
// At least update the method in machine_time.c.
STATIC esp_err_t check_esp_err(esp_err_t code) {
if (code) {
mp_raise_msg(&mp_type_OSError, esp_err_to_name(code));
mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t)esp_err_to_name(code));
}
return code;
@ -80,7 +80,7 @@ STATIC mp_obj_t esp32_rmt_make_new(const mp_obj_type_t *type, size_t n_args, siz
mp_uint_t clock_div = args[2].u_int;
if (clock_div < 1 || clock_div > 255) {
mp_raise_ValueError("clock_div must be between 1 and 255");
mp_raise_ValueError(MP_ERROR_TEXT("clock_div must be between 1 and 255"));
}
esp32_rmt_obj_t *self = m_new_obj_with_finaliser(esp32_rmt_obj_t);
@ -189,7 +189,7 @@ STATIC mp_obj_t esp32_rmt_write_pulses(size_t n_args, const mp_obj_t *pos_args,
mp_uint_t start = args[2].u_int;
if (start < 0 || start > 1) {
mp_raise_ValueError("start must be 0 or 1");
mp_raise_ValueError(MP_ERROR_TEXT("start must be 0 or 1"));
}
size_t pulses_length = 0;

View File

@ -75,13 +75,13 @@ STATIC mp_obj_t madc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
}
}
if (!self) {
mp_raise_ValueError("invalid Pin for ADC");
mp_raise_ValueError(MP_ERROR_TEXT("invalid Pin for ADC"));
}
esp_err_t err = adc1_config_channel_atten(self->adc1_id, ADC_ATTEN_0db);
if (err == ESP_OK) {
return MP_OBJ_FROM_PTR(self);
}
mp_raise_ValueError("Parameter Error");
mp_raise_ValueError(MP_ERROR_TEXT("Parameter Error"));
}
STATIC void madc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@ -104,7 +104,7 @@ STATIC mp_obj_t madc_read(mp_obj_t self_in) {
madc_obj_t *self = self_in;
int val = adc1_get_raw(self->adc1_id);
if (val == -1) {
mp_raise_ValueError("Parameter Error");
mp_raise_ValueError(MP_ERROR_TEXT("Parameter Error"));
}
return MP_OBJ_NEW_SMALL_INT(val);
}
@ -117,7 +117,7 @@ STATIC mp_obj_t madc_atten(mp_obj_t self_in, mp_obj_t atten_in) {
if (err == ESP_OK) {
return mp_const_none;
}
mp_raise_ValueError("Parameter Error");
mp_raise_ValueError(MP_ERROR_TEXT("Parameter Error"));
}
MP_DEFINE_CONST_FUN_OBJ_2(madc_atten_obj, madc_atten);
@ -125,7 +125,7 @@ STATIC mp_obj_t madc_width(mp_obj_t cls_in, mp_obj_t width_in) {
adc_bits_width_t width = mp_obj_get_int(width_in);
esp_err_t err = adc1_config_width(width);
if (err != ESP_OK) {
mp_raise_ValueError("Parameter Error");
mp_raise_ValueError(MP_ERROR_TEXT("Parameter Error"));
}
switch (width) {
case ADC_WIDTH_9Bit:

View File

@ -60,7 +60,7 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
}
}
if (!self) {
mp_raise_ValueError("invalid Pin for DAC");
mp_raise_ValueError(MP_ERROR_TEXT("invalid Pin for DAC"));
}
esp_err_t err = dac_output_enable(self->dac_id);
@ -70,7 +70,7 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
if (err == ESP_OK) {
return MP_OBJ_FROM_PTR(self);
}
mp_raise_ValueError("Parameter Error");
mp_raise_ValueError(MP_ERROR_TEXT("Parameter Error"));
}
STATIC void mdac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@ -82,14 +82,14 @@ STATIC mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) {
mdac_obj_t *self = self_in;
int value = mp_obj_get_int(value_in);
if (value < 0 || value > 255) {
mp_raise_ValueError("Value out of range");
mp_raise_ValueError(MP_ERROR_TEXT("Value out of range"));
}
esp_err_t err = dac_output_voltage(self->dac_id, value);
if (err == ESP_OK) {
return mp_const_none;
}
mp_raise_ValueError("Parameter Error");
mp_raise_ValueError(MP_ERROR_TEXT("Parameter Error"));
}
MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write);

View File

@ -64,21 +64,21 @@ STATIC machine_hw_spi_obj_t machine_hw_spi_obj[2];
STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) {
switch (spi_bus_remove_device(self->spi)) {
case ESP_ERR_INVALID_ARG:
mp_raise_msg(&mp_type_OSError, "invalid configuration");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration"));
return;
case ESP_ERR_INVALID_STATE:
mp_raise_msg(&mp_type_OSError, "SPI device already freed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SPI device already freed"));
return;
}
switch (spi_bus_free(self->host)) {
case ESP_ERR_INVALID_ARG:
mp_raise_msg(&mp_type_OSError, "invalid configuration");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration"));
return;
case ESP_ERR_INVALID_STATE:
mp_raise_msg(&mp_type_OSError, "SPI bus already freed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SPI bus already freed"));
return;
}
@ -159,7 +159,7 @@ STATIC void machine_hw_spi_init_internal(
}
if (self->host != HSPI_HOST && self->host != VSPI_HOST) {
mp_raise_ValueError("SPI ID must be either HSPI(1) or VSPI(2)");
mp_raise_ValueError(MP_ERROR_TEXT("SPI ID must be either HSPI(1) or VSPI(2)"));
}
if (changed) {
@ -201,28 +201,28 @@ STATIC void machine_hw_spi_init_internal(
ret = spi_bus_initialize(self->host, &buscfg, dma_chan);
switch (ret) {
case ESP_ERR_INVALID_ARG:
mp_raise_msg(&mp_type_OSError, "invalid configuration");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration"));
return;
case ESP_ERR_INVALID_STATE:
mp_raise_msg(&mp_type_OSError, "SPI host already in use");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SPI host already in use"));
return;
}
ret = spi_bus_add_device(self->host, &devcfg, &self->spi);
switch (ret) {
case ESP_ERR_INVALID_ARG:
mp_raise_msg(&mp_type_OSError, "invalid configuration");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration"));
spi_bus_free(self->host);
return;
case ESP_ERR_NO_MEM:
mp_raise_msg(&mp_type_OSError, "out of memory");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("out of memory"));
spi_bus_free(self->host);
return;
case ESP_ERR_NOT_FOUND:
mp_raise_msg(&mp_type_OSError, "no free slots");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("no free slots"));
spi_bus_free(self->host);
return;
}
@ -241,7 +241,7 @@ STATIC void machine_hw_spi_transfer(mp_obj_base_t *self_in, size_t len, const ui
machine_hw_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->state == MACHINE_HW_SPI_STATE_DEINIT) {
mp_raise_msg(&mp_type_OSError, "transfer on deinitialized SPI");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("transfer on deinitialized SPI"));
return;
}

View File

@ -130,7 +130,7 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
// Get I2C bus
mp_int_t i2c_id = mp_obj_get_int(args[ARG_id].u_obj);
if (!(I2C_NUM_0 <= i2c_id && i2c_id < I2C_NUM_MAX)) {
mp_raise_msg_varg(&mp_type_ValueError, "I2C(%d) doesn't exist", i2c_id);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
}
// Get static peripheral object

View File

@ -126,7 +126,7 @@ STATIC void machine_pin_isr_handler(void *arg) {
gpio_num_t machine_pin_get_id(mp_obj_t pin_in) {
if (mp_obj_get_type(pin_in) != &machine_pin_type) {
mp_raise_ValueError("expecting a pin");
mp_raise_ValueError(MP_ERROR_TEXT("expecting a pin"));
}
machine_pin_obj_t *self = pin_in;
return self->id;
@ -162,7 +162,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
if (args[ARG_mode].u_obj != mp_const_none) {
mp_int_t pin_io_mode = mp_obj_get_int(args[ARG_mode].u_obj);
if (self->id >= 34 && (pin_io_mode & GPIO_MODE_DEF_OUTPUT)) {
mp_raise_ValueError("pin can only be input");
mp_raise_ValueError(MP_ERROR_TEXT("pin can only be input"));
} else {
gpio_set_direction(self->id, pin_io_mode);
}
@ -205,7 +205,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
self = (machine_pin_obj_t *)&machine_pin_obj[wanted_pin];
}
if (self == NULL || self->base.type == NULL) {
mp_raise_ValueError("invalid pin");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin"));
}
if (n_args > 1 || n_kw > 0) {
@ -282,24 +282,24 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
mp_int_t wake;
if (mp_obj_get_int_maybe(wake_obj, &wake)) {
if (wake < 2 || wake > 7) {
mp_raise_ValueError("bad wake value");
mp_raise_ValueError(MP_ERROR_TEXT("bad wake value"));
}
} else {
mp_raise_ValueError("bad wake value");
mp_raise_ValueError(MP_ERROR_TEXT("bad wake value"));
}
if (machine_rtc_config.wake_on_touch) { // not compatible
mp_raise_ValueError("no resources");
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
}
if (!RTC_IS_VALID_EXT_PIN(self->id)) {
mp_raise_ValueError("invalid pin for wake");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin for wake"));
}
if (machine_rtc_config.ext0_pin == -1) {
machine_rtc_config.ext0_pin = self->id;
} else if (machine_rtc_config.ext0_pin != self->id) {
mp_raise_ValueError("no resources");
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
}
machine_rtc_config.ext0_level = trigger == GPIO_PIN_INTR_LOLEVEL ? 0 : 1;

View File

@ -145,7 +145,7 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
}
if (channel >= LEDC_CHANNEL_MAX) {
if (avail == -1) {
mp_raise_ValueError("out of PWM channels");
mp_raise_ValueError(MP_ERROR_TEXT("out of PWM channels"));
}
channel = avail;
}
@ -163,7 +163,7 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
.timer_sel = PWTIMER,
};
if (ledc_channel_config(&cfg) != ESP_OK) {
mp_raise_msg_varg(&mp_type_ValueError, "PWM not supported on pin %d", self->pin);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("PWM not supported on pin %d"), self->pin);
}
chan_gpio[channel] = self->pin;
}
@ -173,7 +173,7 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
if (tval != -1) {
if (tval != timer_cfg.freq_hz) {
if (!set_freq(tval)) {
mp_raise_msg_varg(&mp_type_ValueError, "Bad frequency %d", tval);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Bad frequency %d"), tval);
}
}
}
@ -247,7 +247,7 @@ STATIC mp_obj_t esp32_pwm_freq(size_t n_args, const mp_obj_t *args) {
// set
int tval = mp_obj_get_int(args[1]);
if (!set_freq(tval)) {
mp_raise_msg_varg(&mp_type_ValueError, "Bad frequency %d", tval);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Bad frequency %d"), tval);
}
return mp_const_none;
}

View File

@ -154,7 +154,7 @@ STATIC mp_obj_t machine_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len > MICROPY_HW_RTC_USER_MEM_MAX) {
mp_raise_ValueError("buffer too long");
mp_raise_ValueError(MP_ERROR_TEXT("buffer too long"));
}
memcpy((char *)rtc_user_mem_data, (char *)bufinfo.buf, bufinfo.len);
rtc_user_mem_len = bufinfo.len;

View File

@ -177,7 +177,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
int slot_num = arg_vals[ARG_slot].u_int;
if (slot_num < 0 || slot_num > 3) {
mp_raise_ValueError("Slot number must be between 0 and 3 inclusive");
mp_raise_ValueError(MP_ERROR_TEXT("Slot number must be between 0 and 3 inclusive"));
}
// Slots 0 and 1 are native SD/MMC, slots 2 and 3 are SPI
@ -253,7 +253,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
if (width == 1 || width == 4 || (width == 8 && slot_num == 0)) {
slot_config.width = width;
} else {
mp_raise_ValueError("Width must be 1 or 4 (or 8 on slot 0)");
mp_raise_ValueError(MP_ERROR_TEXT("Width must be 1 or 4 (or 8 on slot 0)"));
}
DEBUG_printf(" Calling init_slot()");

View File

@ -68,7 +68,7 @@ STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
}
}
if (!self) {
mp_raise_ValueError("invalid pin for touchpad");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin for touchpad"));
}
static int initialized = 0;
@ -81,7 +81,7 @@ STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
if (err == ESP_OK) {
return MP_OBJ_FROM_PTR(self);
}
mp_raise_ValueError("Touch pad error");
mp_raise_ValueError(MP_ERROR_TEXT("Touch pad error"));
}
STATIC mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) {
@ -91,7 +91,7 @@ STATIC mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) {
if (err == ESP_OK) {
return mp_const_none;
}
mp_raise_ValueError("Touch pad error");
mp_raise_ValueError(MP_ERROR_TEXT("Touch pad error"));
}
MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config);
@ -102,7 +102,7 @@ STATIC mp_obj_t mtp_read(mp_obj_t self_in) {
if (err == ESP_OK) {
return MP_OBJ_NEW_SMALL_INT(value);
}
mp_raise_ValueError("Touch pad error");
mp_raise_ValueError(MP_ERROR_TEXT("Touch pad error"));
}
MP_DEFINE_CONST_FUN_OBJ_1(mtp_read_obj, mtp_read);

View File

@ -187,7 +187,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
self->bits = 8;
break;
default:
mp_raise_ValueError("invalid data bits");
mp_raise_ValueError(MP_ERROR_TEXT("invalid data bits"));
break;
}
@ -222,7 +222,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
self->stop = 2;
break;
default:
mp_raise_ValueError("invalid stop bits");
mp_raise_ValueError(MP_ERROR_TEXT("invalid stop bits"));
break;
}
@ -239,7 +239,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
// set line inversion
if (args[ARG_invert].u_int & ~UART_LINE_INV_MASK) {
mp_raise_ValueError("invalid inversion mask");
mp_raise_ValueError(MP_ERROR_TEXT("invalid inversion mask"));
}
self->invert = args[ARG_invert].u_int;
uart_set_line_inverse(self->uart_num, self->invert);
@ -251,13 +251,13 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
// get uart id
mp_int_t uart_num = mp_obj_get_int(args[0]);
if (uart_num < 0 || uart_num >= UART_NUM_MAX) {
mp_raise_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", uart_num);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("UART(%d) does not exist"), uart_num);
}
// Attempts to use UART0 from Python has resulted in all sorts of fun errors.
// FIXME: UART0 is disabled for now.
if (uart_num == UART_NUM_0) {
mp_raise_msg_varg(&mp_type_ValueError, "UART(%d) is disabled (dedicated to REPL)", uart_num);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("UART(%d) is disabled (dedicated to REPL)"), uart_num);
}
// Defaults

View File

@ -58,7 +58,7 @@ STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, size_t n_args
args[ARG_timeout].u_int /= 1000;
if (args[ARG_timeout].u_int <= 0) {
mp_raise_ValueError("WDT timeout too short");
mp_raise_ValueError(MP_ERROR_TEXT("WDT timeout too short"));
}
mp_int_t rs_code = esp_task_wdt_init(args[ARG_timeout].u_int, true);

View File

@ -46,9 +46,9 @@
STATIC mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) {
if (machine_rtc_config.ext0_pin != -1) {
mp_raise_ValueError("no resources");
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
}
//mp_raise_msg(&mp_type_RuntimeError, "touchpad wakeup not available for this version of ESP-IDF");
//mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("touchpad wakeup not available for this version of ESP-IDF"));
machine_rtc_config.wake_on_touch = mp_obj_is_true(wake);
return mp_const_none;
@ -58,7 +58,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_touch_obj, esp32_wake_on_touch);
STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
if (machine_rtc_config.wake_on_touch) {
mp_raise_ValueError("no resources");
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
}
enum {ARG_pin, ARG_level};
const mp_arg_t allowed_args[] = {
@ -74,7 +74,7 @@ STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m
gpio_num_t pin_id = machine_pin_get_id(args[ARG_pin].u_obj);
if (pin_id != machine_rtc_config.ext0_pin) {
if (!RTC_IS_VALID_EXT_PIN(pin_id)) {
mp_raise_ValueError("invalid pin");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin"));
}
machine_rtc_config.ext0_pin = pin_id;
}
@ -109,7 +109,7 @@ STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_m
gpio_num_t pin_id = machine_pin_get_id(elem[i]);
if (!RTC_IS_VALID_EXT_PIN(pin_id)) {
mp_raise_ValueError("invalid pin");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin"));
break;
}
ext1_pins |= (1ll << pin_id);

View File

@ -73,7 +73,7 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
// set
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
if (freq != 20 && freq != 40 && freq != 80 && freq != 160 && freq != 240) {
mp_raise_ValueError("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz");
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz"));
}
esp_pm_config_esp32_t pm;
pm.max_freq_mhz = freq;
@ -120,7 +120,7 @@ STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const
if (machine_rtc_config.wake_on_touch) {
if (esp_sleep_enable_touchpad_wakeup() != ESP_OK) {
mp_raise_msg(&mp_type_RuntimeError, "esp_sleep_enable_touchpad_wakeup() failed");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("esp_sleep_enable_touchpad_wakeup() failed"));
}
}

View File

@ -60,45 +60,45 @@
NORETURN void _esp_exceptions(esp_err_t e) {
switch (e) {
case ESP_ERR_WIFI_NOT_INIT:
mp_raise_msg(&mp_type_OSError, "Wifi Not Initialized");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Not Initialized"));
case ESP_ERR_WIFI_NOT_STARTED:
mp_raise_msg(&mp_type_OSError, "Wifi Not Started");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Not Started"));
case ESP_ERR_WIFI_NOT_STOPPED:
mp_raise_msg(&mp_type_OSError, "Wifi Not Stopped");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Not Stopped"));
case ESP_ERR_WIFI_IF:
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Interface");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Invalid Interface"));
case ESP_ERR_WIFI_MODE:
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Mode");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Invalid Mode"));
case ESP_ERR_WIFI_STATE:
mp_raise_msg(&mp_type_OSError, "Wifi Internal State Error");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Internal State Error"));
case ESP_ERR_WIFI_CONN:
mp_raise_msg(&mp_type_OSError, "Wifi Internal Error");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Internal Error"));
case ESP_ERR_WIFI_NVS:
mp_raise_msg(&mp_type_OSError, "Wifi Internal NVS Error");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Internal NVS Error"));
case ESP_ERR_WIFI_MAC:
mp_raise_msg(&mp_type_OSError, "Wifi Invalid MAC Address");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Invalid MAC Address"));
case ESP_ERR_WIFI_SSID:
mp_raise_msg(&mp_type_OSError, "Wifi SSID Invalid");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi SSID Invalid"));
case ESP_ERR_WIFI_PASSWORD:
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Password");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Invalid Password"));
case ESP_ERR_WIFI_TIMEOUT:
mp_raise_OSError(MP_ETIMEDOUT);
case ESP_ERR_WIFI_WAKE_FAIL:
mp_raise_msg(&mp_type_OSError, "Wifi Wakeup Failure");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Wakeup Failure"));
case ESP_ERR_WIFI_WOULD_BLOCK:
mp_raise_msg(&mp_type_OSError, "Wifi Would Block");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Would Block"));
case ESP_ERR_WIFI_NOT_CONNECT:
mp_raise_msg(&mp_type_OSError, "Wifi Not Connected");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Wifi Not Connected"));
case ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS:
mp_raise_msg(&mp_type_OSError, "TCP/IP Invalid Parameters");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("TCP/IP Invalid Parameters"));
case ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:
mp_raise_msg(&mp_type_OSError, "TCP/IP IF Not Ready");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("TCP/IP IF Not Ready"));
case ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED:
mp_raise_msg(&mp_type_OSError, "TCP/IP DHCP Client Start Failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("TCP/IP DHCP Client Start Failed"));
case ESP_ERR_TCPIP_ADAPTER_NO_MEM:
mp_raise_OSError(MP_ENOMEM);
default:
mp_raise_msg_varg(&mp_type_RuntimeError, "Wifi Unknown Error 0x%04x", e);
mp_raise_msg_varg(&mp_type_RuntimeError, MP_ERROR_TEXT("Wifi Unknown Error 0x%04x"), e);
}
}
@ -241,7 +241,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
STATIC void require_if(mp_obj_t wlan_if, int if_no) {
wlan_if_obj_t *self = MP_OBJ_TO_PTR(wlan_if);
if (self->if_id != if_no) {
mp_raise_msg(&mp_type_OSError, if_no == WIFI_IF_STA ? "STA required" : "AP required");
mp_raise_msg(&mp_type_OSError, if_no == WIFI_IF_STA ? MP_ERROR_TEXT("STA required") : MP_ERROR_TEXT("AP required"));
}
}
@ -262,7 +262,7 @@ STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) {
} else if (idx == WIFI_IF_AP) {
return MP_OBJ_FROM_PTR(&wlan_ap_obj);
} else {
mp_raise_ValueError("invalid WLAN interface identifier");
mp_raise_ValueError(MP_ERROR_TEXT("invalid WLAN interface identifier"));
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(get_wlan_obj, 0, 1, get_wlan);
@ -429,7 +429,7 @@ STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(info.rssi);
}
default:
mp_raise_ValueError("unknown status param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown status param"));
}
return mp_const_none;
@ -441,7 +441,7 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
wifi_mode_t mode;
ESP_EXCEPTIONS(esp_wifi_get_mode(&mode));
if ((mode & WIFI_MODE_STA) == 0) {
mp_raise_msg(&mp_type_OSError, "STA must be active");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("STA must be active"));
}
mp_obj_t list = mp_obj_new_list(0, NULL);
@ -540,7 +540,7 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
// check for the correct string
const char *mode = mp_obj_str_get_str(args[1]);
if ((self->if_id != WIFI_IF_STA && self->if_id != ESP_IF_ETH) || strcmp("dhcp", mode)) {
mp_raise_ValueError("invalid arguments");
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
}
ESP_EXCEPTIONS(tcpip_adapter_dhcpc_start(self->if_id));
}
@ -552,7 +552,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig);
STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args != 1 && kwargs->used != 0) {
mp_raise_TypeError("either pos or kw args are allowed");
mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed"));
}
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
@ -580,7 +580,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(kwargs->table[i].value, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
mp_raise_ValueError("invalid buffer length");
mp_raise_ValueError(MP_ERROR_TEXT("invalid buffer length"));
}
ESP_EXCEPTIONS(esp_wifi_set_mac(self->if_id, bufinfo.buf));
break;
@ -647,7 +647,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
// Get config
if (n_args != 2) {
mp_raise_TypeError("can query only one param");
mp_raise_TypeError(MP_ERROR_TEXT("can query only one param"));
}
int req_if = -1;
@ -720,7 +720,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
return val;
unknown:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);

View File

@ -66,7 +66,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) {
// localtime generates a tuple of len 8. CPython uses 9, so we accept both.
if (len < 8 || len > 9) {
mp_raise_msg_varg(&mp_type_TypeError, "mktime needs a tuple of length 8 or 9 (%d given)", len);
mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len);
}
return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]),

View File

@ -137,7 +137,7 @@ void mp_thread_create_ex(void *(*entry)(void *), void *arg, size_t *stack_size,
BaseType_t result = xTaskCreatePinnedToCore(freertos_entry, name, *stack_size / sizeof(StackType_t), arg, priority, &th->id, MP_TASK_COREID);
if (result != pdPASS) {
mp_thread_mutex_unlock(&thread_mutex);
mp_raise_msg(&mp_type_OSError, "can't create thread");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't create thread"));
}
// adjust the stack_size to provide room to recover from hitting the limit

View File

@ -111,7 +111,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
if (args[ARG_id].u_obj != mp_const_none) {
if (mp_obj_get_int(args[ARG_id].u_obj) != 0) {
mp_raise_ValueError("invalid LAN interface identifier");
mp_raise_ValueError(MP_ERROR_TEXT("invalid LAN interface identifier"));
}
}
@ -120,11 +120,11 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
self->phy_power_pin = args[ARG_power].u_obj == mp_const_none ? -1 : machine_pin_get_id(args[ARG_power].u_obj);
if (args[ARG_phy_addr].u_int < 0x00 || args[ARG_phy_addr].u_int > 0x1f) {
mp_raise_ValueError("invalid phy address");
mp_raise_ValueError(MP_ERROR_TEXT("invalid phy address"));
}
if (args[ARG_phy_type].u_int != PHY_LAN8720 && args[ARG_phy_type].u_int != PHY_TLK110) {
mp_raise_ValueError("invalid phy type");
mp_raise_ValueError(MP_ERROR_TEXT("invalid phy type"));
}
if (args[ARG_clock_mode].u_int != -1 &&
@ -133,7 +133,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
//args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO0_OUT &&
args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO16_OUT &&
args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO17_OUT) {
mp_raise_ValueError("invalid clock mode");
mp_raise_ValueError(MP_ERROR_TEXT("invalid clock mode"));
}
eth_config_t config;
@ -165,7 +165,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
self->active = false;
self->initialized = true;
} else {
mp_raise_msg(&mp_type_OSError, "esp_eth_init() failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("esp_eth_init() failed"));
}
return MP_OBJ_FROM_PTR(&lan_obj);
}
@ -178,12 +178,12 @@ STATIC mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) {
if (mp_obj_is_true(args[1])) {
self->active = (esp_eth_enable() == ESP_OK);
if (!self->active) {
mp_raise_msg(&mp_type_OSError, "ethernet enable failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ethernet enable failed"));
}
} else {
self->active = !(esp_eth_disable() == ESP_OK);
if (self->active) {
mp_raise_msg(&mp_type_OSError, "ethernet disable failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ethernet disable failed"));
}
}
}

View File

@ -128,7 +128,7 @@ STATIC mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) {
self->pcb = pppapi_pppos_create(&self->pppif, ppp_output_callback, ppp_status_cb, self);
if (self->pcb == NULL) {
mp_raise_msg(&mp_type_RuntimeError, "init failed");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("init failed"));
}
self->active = true;
} else {
@ -178,7 +178,7 @@ STATIC mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw
ppp_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (!self->active) {
mp_raise_msg(&mp_type_OSError, "must be active");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("must be active"));
}
if (self->client_task_handle != NULL) {
@ -191,7 +191,7 @@ STATIC mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw
case PPPAUTHTYPE_CHAP:
break;
default:
mp_raise_ValueError("invalid auth");
mp_raise_ValueError(MP_ERROR_TEXT("invalid auth"));
}
if (parsed_args[ARG_authmode].u_int != PPPAUTHTYPE_NONE) {
@ -200,17 +200,17 @@ STATIC mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw
pppapi_set_auth(self->pcb, parsed_args[ARG_authmode].u_int, username_str, password_str);
}
if (pppapi_set_default(self->pcb) != ESP_OK) {
mp_raise_msg(&mp_type_OSError, "set default failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("set default failed"));
}
ppp_set_usepeerdns(self->pcb, true);
if (pppapi_connect(self->pcb, 0) != ESP_OK) {
mp_raise_msg(&mp_type_OSError, "connect failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("connect failed"));
}
if (xTaskCreatePinnedToCore(pppos_client_task, "ppp", 2048, self, 1, (TaskHandle_t *)&self->client_task_handle, MP_TASK_COREID) != pdPASS) {
mp_raise_msg(&mp_type_RuntimeError, "failed to create worker task");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("failed to create worker task"));
}
return mp_const_none;

View File

@ -149,7 +149,7 @@ void ets_event_poll(void) {
void __assert_func(const char *file, int line, const char *func, const char *expr) {
printf("assert:%s:%d:%s: %s\n", file, line, func, expr);
mp_raise_msg(&mp_type_AssertionError, "C-level assert");
mp_raise_msg(&mp_type_AssertionError, MP_ERROR_TEXT("C-level assert"));
}
void mp_hal_signal_input(void) {

View File

@ -64,7 +64,7 @@ mp_obj_t machine_adc_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
case 1:
return &machine_adc_vdd3;
default:
mp_raise_msg_varg(&mp_type_ValueError, "ADC(%d) doesn't exist", chn);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("ADC(%d) doesn't exist"), chn);
}
}

View File

@ -127,13 +127,13 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
spi_init_gpio(HSPI, SPI_CLK_80MHZ_NODIV);
spi_clock(HSPI, 0, 0);
} else if (self->baudrate > 40000000L) {
mp_raise_ValueError("impossible baudrate");
mp_raise_ValueError(MP_ERROR_TEXT("impossible baudrate"));
} else {
uint32_t divider = 40000000L / self->baudrate;
uint16_t prediv = MIN(divider, SPI_CLKDIV_PRE + 1);
uint16_t cntdiv = (divider / prediv) * 2; // cntdiv has to be even
if (cntdiv > SPI_CLKCNT_N + 1 || cntdiv == 0 || prediv == 0) {
mp_raise_ValueError("impossible baudrate");
mp_raise_ValueError(MP_ERROR_TEXT("impossible baudrate"));
}
self->baudrate = 80000000L / (prediv * cntdiv);
spi_init_gpio(HSPI, SPI_CLK_USE_DIV);

View File

@ -128,7 +128,7 @@ void pin_intr_handler(uint32_t status) {
pyb_pin_obj_t *mp_obj_get_pin_obj(mp_obj_t pin_in) {
if (mp_obj_get_type(pin_in) != &pyb_pin_type) {
mp_raise_ValueError("expecting a pin");
mp_raise_ValueError(MP_ERROR_TEXT("expecting a pin"));
}
pyb_pin_obj_t *self = pin_in;
return self;
@ -283,7 +283,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, size_t n_args, cons
// only pull-down seems to be supported by the hardware, and
// we only expose pull-up behaviour in software
if (pull != GPIO_PULL_NONE) {
mp_raise_ValueError("Pin(16) doesn't support pull");
mp_raise_ValueError(MP_ERROR_TEXT("Pin(16) doesn't support pull"));
}
} else {
PIN_FUNC_SELECT(self->periph, self->func);
@ -322,7 +322,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
pin = (pyb_pin_obj_t *)&pyb_pin_obj[wanted_pin];
}
if (pin == NULL || pin->base.type == NULL) {
mp_raise_ValueError("invalid pin");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin"));
}
if (n_args > 1 || n_kw > 0) {
@ -388,7 +388,7 @@ STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
if (self->phys_port >= 16) {
mp_raise_msg(&mp_type_OSError, "pin does not have IRQ capabilities");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("pin does not have IRQ capabilities"));
}
if (n_args > 1 || kw_args->used != 0) {

View File

@ -65,7 +65,7 @@ STATIC void pyb_pwm_init_helper(pyb_pwm_obj_t *self, size_t n_args, const mp_obj
int channel = pwm_add(self->pin->phys_port, self->pin->periph, self->pin->func);
if (channel == -1) {
mp_raise_msg_varg(&mp_type_ValueError, "PWM not supported on pin %d", self->pin->phys_port);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("PWM not supported on pin %d"), self->pin->phys_port);
}
self->channel = channel;

View File

@ -181,7 +181,7 @@ STATIC mp_obj_t pyb_rtc_memory(size_t n_args, const mp_obj_t *args) {
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len > MEM_USER_MAXLEN) {
mp_raise_ValueError("buffer too long");
mp_raise_ValueError(MP_ERROR_TEXT("buffer too long"));
}
len = bufinfo.len;
@ -205,7 +205,7 @@ STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time
// check we want alarm0
if (mp_obj_get_int(alarm_id) != 0) {
mp_raise_ValueError("invalid alarm");
mp_raise_ValueError(MP_ERROR_TEXT("invalid alarm"));
}
// set expiry time (in microseconds)
@ -219,7 +219,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_rtc_alarm_obj, pyb_rtc_alarm);
STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) {
// check we want alarm0
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
mp_raise_ValueError("invalid alarm");
mp_raise_ValueError(MP_ERROR_TEXT("invalid alarm"));
}
uint64_t now = pyb_rtc_get_us_since_2000();
@ -242,7 +242,7 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
// check we want alarm0
if (args[ARG_trigger].u_int != 0) {
mp_raise_ValueError("invalid alarm");
mp_raise_ValueError(MP_ERROR_TEXT("invalid alarm"));
}
// set the wake value

View File

@ -107,7 +107,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
self->bits = 8;
break;
default:
mp_raise_ValueError("invalid data bits");
mp_raise_ValueError(MP_ERROR_TEXT("invalid data bits"));
break;
}
@ -143,7 +143,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
} else if (tx == 15 && rx == 13) {
system_uart_swap();
} else {
mp_raise_ValueError("invalid tx/rx");
mp_raise_ValueError(MP_ERROR_TEXT("invalid tx/rx"));
}
// set stop bits
@ -159,7 +159,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
self->stop = 2;
break;
default:
mp_raise_ValueError("invalid stop bits");
mp_raise_ValueError(MP_ERROR_TEXT("invalid stop bits"));
break;
}
@ -198,7 +198,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
// get uart id
mp_int_t uart_id = mp_obj_get_int(args[0]);
if (uart_id != 0 && uart_id != 1) {
mp_raise_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", uart_id);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("UART(%d) does not exist"), uart_id);
}
// create instance
@ -248,7 +248,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->uart_id == 1) {
mp_raise_msg(&mp_type_OSError, "UART(1) can't read");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("UART(1) can't read"));
}
// make sure we want at least 1 char

View File

@ -42,7 +42,7 @@
#define MODESP_INCLUDE_CONSTANTS (1)
void error_check(bool status, const char *msg) {
void error_check(bool status, mp_rom_error_text_t msg) {
if (!status) {
mp_raise_msg(&mp_type_OSError, msg);
}
@ -120,7 +120,7 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len & 0x3) {
mp_raise_ValueError("len must be multiple of 4");
mp_raise_ValueError(MP_ERROR_TEXT("len must be multiple of 4"));
}
ets_loop_iter(); // flash access takes time so run any pending tasks
SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len);
@ -289,7 +289,7 @@ void *esp_native_code_commit(void *buf, size_t len, void *reloc) {
len = (len + 3) & ~3;
if (esp_native_code_cur + len > esp_native_code_end) {
mp_raise_msg_varg(&mp_type_MemoryError,
"memory allocation failed, allocating %u bytes for native code", (uint)len);
MP_ERROR_TEXT("memory allocation failed, allocating %u bytes for native code"), (uint)len);
}
void *dest;
@ -342,7 +342,7 @@ STATIC mp_obj_t esp_set_native_code_location(mp_obj_t start_in, mp_obj_t len_in)
esp_native_code_erased = esp_native_code_start;
// memory-mapped flash is limited in extents to 1MByte
if (esp_native_code_end > FLASH_END - FLASH_START) {
mp_raise_ValueError("flash location must be below 1MByte");
mp_raise_ValueError(MP_ERROR_TEXT("flash location must be below 1MByte"));
}
}
return mp_const_none;

View File

@ -64,7 +64,7 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
// set
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
if (freq != 80 && freq != 160) {
mp_raise_ValueError("frequency can only be either 80Mhz or 160MHz");
mp_raise_ValueError(MP_ERROR_TEXT("frequency can only be either 80Mhz or 160MHz"));
}
system_update_cpu_freq(freq);
return mp_const_none;

View File

@ -181,7 +181,7 @@ STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(wifi_station_get_rssi());
}
}
mp_raise_ValueError("unknown status param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown status param"));
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_status_obj, 1, 2, esp_status);
@ -229,7 +229,7 @@ STATIC void esp_scan_cb(void *result, STATUS status) {
STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
require_if(self_in, STATION_IF);
if ((wifi_get_opmode() & STATION_MODE) == 0) {
mp_raise_msg(&mp_type_OSError, "STA must be active");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("STA must be active"));
}
mp_obj_t list = mp_obj_new_list(0, NULL);
esp_scan_list = &list;
@ -246,7 +246,7 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
ets_loop_iter();
}
if (list == MP_OBJ_NULL) {
mp_raise_msg(&mp_type_OSError, "scan failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("scan failed"));
}
return list;
}
@ -317,7 +317,7 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
wifi_softap_dhcps_stop();
}
if (!wifi_set_ip_info(self->if_id, &info)) {
mp_raise_msg(&mp_type_OSError, "wifi_set_ip_info() failed");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("wifi_set_ip_info() failed"));
}
dns_setserver(0, &dns_addr);
if (restart_dhcp_server) {
@ -330,7 +330,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig)
STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args != 1 && kwargs->used != 0) {
mp_raise_TypeError("either pos or kw args are allowed");
mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed"));
}
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
@ -357,7 +357,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(kwargs->table[i].value, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
mp_raise_ValueError("invalid buffer length");
mp_raise_ValueError(MP_ERROR_TEXT("invalid buffer length"));
}
wifi_set_macaddr(self->if_id, bufinfo.buf);
break;
@ -427,7 +427,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
// Get config
if (n_args != 2) {
mp_raise_TypeError("can query only one param");
mp_raise_TypeError(MP_ERROR_TEXT("can query only one param"));
}
mp_obj_t val;
@ -480,7 +480,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
return val;
unknown:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);

View File

@ -88,7 +88,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) {
// localtime generates a tuple of len 8. CPython uses 9, so we accept both.
if (len < 8 || len > 9) {
mp_raise_msg_varg(&mp_type_TypeError, "mktime needs a tuple of length 8 or 9 (%d given)", len);
mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len);
}
return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]),

View File

@ -305,7 +305,7 @@ static void draw_object(mp_obj_t obj) {
async_stop();
}
} else {
MP_STATE_VM(mp_pending_exception) = mp_obj_new_exception_msg(&mp_type_TypeError, "not an image.");
MP_STATE_VM(mp_pending_exception) = mp_obj_new_exception_msg(&mp_type_TypeError, MP_ERROR_TEXT("not an image."));
async_stop();
}
}
@ -499,10 +499,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(microbit_display_clear_obj, microbit_display_clear_fun
void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y, mp_int_t bright) {
if (x < 0 || y < 0 || x > 4 || y > 4) {
mp_raise_ValueError("index out of bounds.");
mp_raise_ValueError(MP_ERROR_TEXT("index out of bounds."));
}
if (bright < 0 || bright > MAX_BRIGHTNESS) {
mp_raise_ValueError("brightness out of bounds.");
mp_raise_ValueError(MP_ERROR_TEXT("brightness out of bounds."));
}
display->image_buffer[x][y] = bright;
display->brightnesses |= (1 << bright);
@ -518,7 +518,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_display_set_pixel_obj, 4, 4, microb
mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y) {
if (x < 0 || y < 0 || x > 4 || y > 4) {
mp_raise_ValueError("index out of bounds.");
mp_raise_ValueError(MP_ERROR_TEXT("index out of bounds."));
}
return display->image_buffer[x][y];
}

View File

@ -162,7 +162,7 @@ STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len)
} else if ('c' >= '0' && c <= '9') {
++line_len;
} else {
mp_raise_ValueError("Unexpected character in Image definition.");
mp_raise_ValueError(MP_ERROR_TEXT("Unexpected character in Image definition."));
}
}
if (line_len) {
@ -227,7 +227,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
return image_from_parsed_str(str, len);
}
} else {
mp_raise_TypeError("Image(s) takes a string.");
mp_raise_TypeError(MP_ERROR_TEXT("Image(s) takes a string."));
}
}
@ -243,7 +243,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
if (w < 0 || h < 0 || (size_t)(w * h) != bufinfo.len) {
mp_raise_ValueError("image data is incorrect size");
mp_raise_ValueError(MP_ERROR_TEXT("image data is incorrect size"));
}
mp_int_t i = 0;
for (mp_int_t y = 0; y < h; y++) {
@ -258,7 +258,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
}
default: {
mp_raise_TypeError("Image() takes 0 to 3 arguments");
mp_raise_TypeError(MP_ERROR_TEXT("Image() takes 0 to 3 arguments"));
}
}
}
@ -351,19 +351,19 @@ mp_obj_t microbit_image_get_pixel(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in
mp_int_t x = mp_obj_get_int(x_in);
mp_int_t y = mp_obj_get_int(y_in);
if (x < 0 || y < 0) {
mp_raise_ValueError("index cannot be negative");
mp_raise_ValueError(MP_ERROR_TEXT("index cannot be negative"));
}
if (x < imageWidth(self) && y < imageHeight(self)) {
return MP_OBJ_NEW_SMALL_INT(imageGetPixelValue(self, x, y));
}
mp_raise_ValueError("index too large");
mp_raise_ValueError(MP_ERROR_TEXT("index too large"));
}
MP_DEFINE_CONST_FUN_OBJ_3(microbit_image_get_pixel_obj, microbit_image_get_pixel);
/* Raise an exception if not mutable */
static void check_mutability(microbit_image_obj_t *self) {
if (self->base.five) {
mp_raise_TypeError("image cannot be modified (try copying first)");
mp_raise_TypeError(MP_ERROR_TEXT("image cannot be modified (try copying first)"));
}
}
@ -375,16 +375,16 @@ mp_obj_t microbit_image_set_pixel(mp_uint_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
if (x < 0 || y < 0) {
mp_raise_ValueError("index cannot be negative");
mp_raise_ValueError(MP_ERROR_TEXT("index cannot be negative"));
}
mp_int_t bright = mp_obj_get_int(args[3]);
if (bright < 0 || bright > MAX_BRIGHTNESS)
mp_raise_ValueError("brightness out of bounds.");
mp_raise_ValueError(MP_ERROR_TEXT("brightness out of bounds."));
if (x < imageWidth(self) && y < imageHeight(self)) {
greyscaleSetPixelValue(&(self->greyscale), x, y, bright);
return mp_const_none;
}
mp_raise_ValueError("index too large");
mp_raise_ValueError(MP_ERROR_TEXT("index too large"));
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_image_set_pixel_obj, 4, 4, microbit_image_set_pixel);
@ -393,7 +393,7 @@ mp_obj_t microbit_image_fill(mp_obj_t self_in, mp_obj_t n_in) {
check_mutability(self);
mp_int_t n = mp_obj_get_int(n_in);
if (n < 0 || n > MAX_BRIGHTNESS) {
mp_raise_ValueError("brightness out of bounds.");
mp_raise_ValueError(MP_ERROR_TEXT("brightness out of bounds."));
}
greyscaleFill(&self->greyscale, n);
return mp_const_none;
@ -406,17 +406,17 @@ mp_obj_t microbit_image_blit(mp_uint_t n_args, const mp_obj_t *args) {
mp_obj_t src = args[1];
if (mp_obj_get_type(src) != &microbit_image_type) {
mp_raise_TypeError("expecting an image");
mp_raise_TypeError(MP_ERROR_TEXT("expecting an image"));
}
if (n_args == 7) {
mp_raise_TypeError("must specify both offsets");
mp_raise_TypeError(MP_ERROR_TEXT("must specify both offsets"));
}
mp_int_t x = mp_obj_get_int(args[2]);
mp_int_t y = mp_obj_get_int(args[3]);
mp_int_t w = mp_obj_get_int(args[4]);
mp_int_t h = mp_obj_get_int(args[5]);
if (w < 0 || h < 0) {
mp_raise_ValueError("size cannot be negative");
mp_raise_ValueError(MP_ERROR_TEXT("size cannot be negative"));
}
mp_int_t xdest;
mp_int_t ydest;
@ -608,7 +608,7 @@ microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t f
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t fval) {
#endif
if (fval < 0)
mp_raise_ValueError("Brightness multiplier must not be negative.");
mp_raise_ValueError(MP_ERROR_TEXT("Brightness multiplier must not be negative."));
greyscale_t *result = greyscale_new(imageWidth(lhs), imageHeight(lhs));
for (int x = 0; x < imageWidth(lhs); ++x) {
for (int y = 0; y < imageWidth(lhs); ++y) {
@ -628,7 +628,7 @@ microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_ima
mp_int_t w = imageWidth(lhs);
if (imageHeight(rhs) != h || imageWidth(lhs) != w) {
// TODO: verify that image width in test above should really test (lhs != w)
mp_raise_ValueError("Images must be the same size.");
mp_raise_ValueError(MP_ERROR_TEXT("Images must be the same size."));
}
greyscale_t *result = greyscale_new(w, h);
for (int x = 0; x < w; ++x) {

View File

@ -223,7 +223,7 @@ uint32_t ble_drv_stack_enable(void) {
if ((err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)device_name,
strlen(device_name))) != 0) {
mp_raise_msg(&mp_type_OSError, "can't apply GAP parameters");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't apply GAP parameters"));
}
// set connection parameters
@ -235,7 +235,7 @@ uint32_t ble_drv_stack_enable(void) {
gap_conn_params.conn_sup_timeout = BLE_CONN_SUP_TIMEOUT;
if (sd_ble_gap_ppcp_set(&gap_conn_params) != 0) {
mp_raise_msg(&mp_type_OSError, "can't set PPCP parameters");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't set PPCP parameters"));
}
return err_code;
@ -266,7 +266,7 @@ void ble_drv_address_get(ble_drv_addr_t * p_addr) {
#endif
if (err_code != 0) {
mp_raise_msg(&mp_type_OSError, "can't query for the device address");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't query for the device address"));
}
BLE_DRIVER_LOG("ble address, type: " HEX2_FMT ", " \
@ -284,7 +284,7 @@ bool ble_drv_uuid_add_vs(uint8_t * p_uuid, uint8_t * idx) {
SD_TEST_OR_ENABLE();
if (sd_ble_uuid_vs_add((ble_uuid128_t const *)p_uuid, idx) != 0) {
mp_raise_msg(&mp_type_OSError, "can't add Vendor Specific 128-bit UUID");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Vendor Specific 128-bit UUID"));
}
return true;
@ -303,7 +303,7 @@ bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj) {
if (sd_ble_gatts_service_add(p_service_obj->type,
&uuid,
&p_service_obj->handle) != 0) {
mp_raise_msg(&mp_type_OSError, "can't add Service");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Service"));
}
} else if (p_service_obj->p_uuid->type == BLE_UUID_TYPE_BLE) {
BLE_DRIVER_LOG("adding service\n");
@ -316,7 +316,7 @@ bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj) {
if (sd_ble_gatts_service_add(p_service_obj->type,
&uuid,
&p_service_obj->handle) != 0) {
mp_raise_msg(&mp_type_OSError, "can't add Service");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Service"));
}
}
return true;
@ -386,7 +386,7 @@ bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj) {
&char_md,
&attr_char_value,
&handles) != 0) {
mp_raise_msg(&mp_type_OSError, "can't add Characteristic");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Characteristic"));
}
// apply handles to object instance
@ -413,7 +413,7 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
if (sd_ble_gap_device_name_set(&sec_mode,
p_adv_params->p_device_name,
p_adv_params->device_name_len) != 0) {
mp_raise_msg(&mp_type_OSError, "can't apply device name in the stack");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't apply device name in the stack"));
}
BLE_DRIVER_LOG("Device name applied\n");
@ -476,12 +476,12 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
uuid.uuid += p_service->p_uuid->value[1] << 8;
// calculate total size of uuids
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
mp_raise_msg(&mp_type_OSError, "can't encode UUID, to check length");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID, to check length"));
}
// do encoding into the adv buffer
if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) {
mp_raise_msg(&mp_type_OSError, "can't encode UUID into advertisment packet");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisment packet"));
}
BLE_DRIVER_LOG("encoded uuid for service %u: ", 0);
@ -524,12 +524,12 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
// calculate total size of uuids
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
mp_raise_msg(&mp_type_OSError, "can't encode UUID, to check length");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID, to check length"));
}
// do encoding into the adv buffer
if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) {
mp_raise_msg(&mp_type_OSError, "can't encode UUID into advertisment packet");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisment packet"));
}
BLE_DRIVER_LOG("encoded uuid for service %u: ", 0);
@ -553,7 +553,7 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
if ((p_adv_params->data_len > 0) && (p_adv_params->p_data != NULL)) {
if (p_adv_params->data_len + byte_pos > BLE_GAP_ADV_MAX_SIZE) {
mp_raise_msg(&mp_type_OSError, "can't fit data into advertisment packet");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't fit data into advertisment packet"));
}
memcpy(adv_data, p_adv_params->p_data, p_adv_params->data_len);

View File

@ -151,7 +151,7 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
// check led number
if (!(1 <= led_id && led_id <= NUM_LEDS)) {
mp_raise_ValueError("LED doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("LED doesn't exist"));
}
// return static led object

View File

@ -101,7 +101,7 @@ STATIC int adc_find(mp_obj_t id) {
if (pin->adc_num & PIN_ADC1) {
adc_idx = pin->adc_channel;
} else {
mp_raise_ValueError("invalid Pin for ADC");
mp_raise_ValueError(MP_ERROR_TEXT("invalid Pin for ADC"));
}
}
@ -109,7 +109,7 @@ STATIC int adc_find(mp_obj_t id) {
&& machine_adc_obj[adc_idx].id != (uint8_t)-1) {
return adc_idx;
}
mp_raise_ValueError("ADC doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("ADC doesn't exist"));
}
/// \method __str__()

View File

@ -80,7 +80,7 @@ STATIC int i2c_find(mp_obj_t id) {
if (i2c_id >= 0 && i2c_id < MP_ARRAY_SIZE(machine_hard_i2c_obj)) {
return i2c_id;
}
mp_raise_ValueError("I2C doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("I2C doesn't exist"));
}
STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

View File

@ -150,7 +150,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
pin_obj = mp_call_function_1(MP_STATE_PORT(pin_class_mapper), user_obj);
if (pin_obj != mp_const_none) {
if (!mp_obj_is_type(pin_obj, &pin_type)) {
mp_raise_ValueError("Pin.mapper didn't return a Pin object");
mp_raise_ValueError(MP_ERROR_TEXT("Pin.mapper didn't return a Pin object"));
}
if (pin_class_debug) {
printf("Pin.mapper maps ");
@ -207,7 +207,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
return pin_obj;
}
mp_raise_ValueError("not a valid pin identifier");
mp_raise_ValueError(MP_ERROR_TEXT("not a valid pin identifier"));
}
/// \method __str__()
@ -375,7 +375,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
NRF_GPIO_PIN_S0S1,
NRF_GPIO_PIN_NOSENSE);
} else {
mp_raise_msg_varg(&mp_type_ValueError, "invalid pin mode: %d", mode);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("invalid pin mode: %d"), mode);
}
return mp_const_none;

View File

@ -97,7 +97,7 @@ STATIC int hard_pwm_find(mp_obj_t id) {
if (pwm_id >= 0 && pwm_id < MP_ARRAY_SIZE(machine_hard_pwm_obj)) {
return pwm_id;
}
mp_raise_ValueError("PWM doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("PWM doesn't exist"));
}
return -1;
}
@ -249,7 +249,7 @@ STATIC mp_obj_t machine_hard_pwm_make_new(mp_arg_val_t *args) {
if (args[ARG_period].u_obj != MP_OBJ_NULL) {
self->p_config->period = mp_obj_get_int(args[ARG_period].u_obj);
} else {
mp_raise_ValueError("PWM period must be within 16000 cycles");
mp_raise_ValueError(MP_ERROR_TEXT("PWM period must be within 16000 cycles"));
}
if (args[ARG_duty].u_obj != MP_OBJ_NULL) {

View File

@ -116,7 +116,7 @@ STATIC int rtc_find(mp_obj_t id) {
if (rtc_id >= 0 && rtc_id < MP_ARRAY_SIZE(machine_rtc_obj)) {
return rtc_id;
}
mp_raise_ValueError("RTCounter doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("RTCounter doesn't exist"));
}
STATIC void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@ -162,7 +162,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
} else if (mp_obj_is_fun(args[ARG_callback].u_obj)) {
config->callback = args[ARG_callback].u_obj;
} else {
mp_raise_ValueError("callback must be a function");
mp_raise_ValueError(MP_ERROR_TEXT("callback must be a function"));
}
// Periodic or one-shot

View File

@ -140,14 +140,14 @@ STATIC int spi_find(mp_obj_t id) {
return 1;
#endif
}
mp_raise_ValueError("SPI doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("SPI doesn't exist"));
} else {
// given an integer id
int spi_id = mp_obj_get_int(id);
if (spi_id >= 0 && spi_id < MP_ARRAY_SIZE(machine_hard_spi_obj)) {
return spi_id;
}
mp_raise_ValueError("SPI doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("SPI doesn't exist"));
}
}
@ -415,7 +415,7 @@ STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp
mp_buffer_info_t dest;
mp_get_buffer_raise(rd_buf, &dest, MP_BUFFER_WRITE);
if (src.len != dest.len) {
mp_raise_ValueError("buffers must be the same length");
mp_raise_ValueError(MP_ERROR_TEXT("buffers must be the same length"));
}
spi_transfer(self, src.len, src.buf, dest.buf);
return mp_const_none;

View File

@ -77,7 +77,7 @@ STATIC int timer_find(mp_obj_t id) {
if (timer_id >= 0 && timer_id < MP_ARRAY_SIZE(machine_timer_obj)) {
return timer_id;
}
mp_raise_ValueError("Timer doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("Timer doesn't exist"));
}
STATIC void timer_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
@ -114,13 +114,13 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
#if BLUETOOTH_SD
if (timer_id == 0) {
mp_raise_ValueError("Timer reserved by Bluetooth LE stack");
mp_raise_ValueError(MP_ERROR_TEXT("Timer reserved by Bluetooth LE stack"));
}
#endif
#if MICROPY_PY_MACHINE_SOFT_PWM
if (timer_id == 1) {
mp_raise_ValueError("Timer reserved by ticker driver");
mp_raise_ValueError(MP_ERROR_TEXT("Timer reserved by ticker driver"));
}
#endif
@ -131,7 +131,7 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
} else if (args[ARG_callback].u_obj == mp_const_none) {
machine_timer_callbacks[timer_id] = NULL;
} else {
mp_raise_ValueError("callback must be a function");
mp_raise_ValueError(MP_ERROR_TEXT("callback must be a function"));
}
// Timer peripheral usage:

View File

@ -118,7 +118,7 @@ STATIC int uart_find(mp_obj_t id) {
if (uart_id >= 0 && uart_id < MP_ARRAY_SIZE(machine_hard_uart_obj)) {
return uart_id;
}
mp_raise_ValueError("UART doesn't exist");
mp_raise_ValueError(MP_ERROR_TEXT("UART doesn't exist"));
}
STATIC void uart_event_handler(nrfx_uart_event_t const *p_event, void *p_context) {
@ -215,7 +215,7 @@ STATIC mp_obj_t machine_hard_uart_make_new(const mp_obj_type_t *type, size_t n_a
// These baudrates are not supported, it seems.
if (args[ARG_baudrate].u_int < 1200 || args[ARG_baudrate].u_int > 1000000) {
mp_raise_ValueError("UART baudrate not supported");
mp_raise_ValueError(MP_ERROR_TEXT("UART baudrate not supported"));
}
// Magic: calculate 'baudrate' register from the input number.

View File

@ -284,7 +284,7 @@ STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) {
#ifdef MICROPY_HW_MUSIC_PIN
pin = mp_hal_get_pin_obj(MP_OBJ_NEW_SMALL_INT(MICROPY_HW_MUSIC_PIN));
#else
mp_raise_ValueError("pin parameter not given");
mp_raise_ValueError(MP_ERROR_TEXT("pin parameter not given"));
#endif
} else {
pin = (pin_obj_t *)args[0];
@ -337,7 +337,7 @@ STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args,
#ifdef MICROPY_HW_MUSIC_PIN
pin = mp_hal_get_pin_obj(MP_OBJ_NEW_SMALL_INT(MICROPY_HW_MUSIC_PIN));
#else
mp_raise_ValueError("pin parameter not given");
mp_raise_ValueError(MP_ERROR_TEXT("pin parameter not given"));
#endif
} else {
pin = (pin_obj_t *)args[1].u_obj;
@ -392,7 +392,7 @@ STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args,
#ifdef MICROPY_HW_MUSIC_PIN
pin = mp_hal_get_pin_obj(MP_OBJ_NEW_SMALL_INT(MICROPY_HW_MUSIC_PIN));
#else
mp_raise_ValueError("pin parameter not given");
mp_raise_ValueError(MP_ERROR_TEXT("pin parameter not given"));
#endif
} else {
pin = (pin_obj_t *)args[2].u_obj;
@ -408,7 +408,7 @@ STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args,
//TODO: pwm_release(pin->name);
} else if (pwm_set_period_us(1000000/frequency)) {
pwm_release(pin->pin); // TODO: remove pin setting.
mp_raise_ValueError("invalid pitch");
mp_raise_ValueError(MP_ERROR_TEXT("invalid pitch"));
}
if (duration >= 0) {
// use async machinery to stop the pitch after the duration

View File

@ -63,7 +63,7 @@ STATIC mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_
s->p_uuid = MP_OBJ_TO_PTR(uuid_obj);
// (void)sd_characterstic_add(s);
} else {
mp_raise_ValueError("Invalid UUID parameter");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid UUID parameter"));
}
if (args[1].u_int > 0) {

View File

@ -68,13 +68,13 @@ STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_arg
if (type > 0 && type <= UBLUEPY_SERVICE_PRIMARY) {
s->type = type;
} else {
mp_raise_ValueError("Invalid Service type");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid Service type"));
}
(void)ble_drv_service_add(s);
} else {
mp_raise_ValueError("Invalid UUID parameter");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid UUID parameter"));
}
// clear reference to peripheral
@ -125,7 +125,7 @@ STATIC mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) {
// validate that there is an UUID object passed in as parameter
if (!(mp_obj_is_type(uuid, &ubluepy_uuid_type))) {
mp_raise_ValueError("Invalid UUID parameter");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid UUID parameter"));
}
mp_obj_t * chars = NULL;

View File

@ -122,7 +122,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
ble_drv_uuid_add_vs(buffer, &s->uuid_vs_idx);
} else {
mp_raise_ValueError("Invalid UUID string length");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid UUID string length"));
}
} else if (mp_obj_is_type(uuid_obj, &ubluepy_uuid_type)) {
// deep copy instance
@ -131,7 +131,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
s->value[0] = p_old->value[0];
s->value[1] = p_old->value[1];
} else {
mp_raise_ValueError("Invalid UUID parameter");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid UUID parameter"));
}
return MP_OBJ_FROM_PTR(s);

View File

@ -389,7 +389,7 @@ STATIC mp_obj_t microbit_remove(mp_obj_t filename) {
STATIC void check_file_open(file_descriptor_obj *self) {
if (!self->open) {
mp_raise_ValueError("I/O operation on closed file");
mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file"));
}
}
@ -685,7 +685,7 @@ mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) {
}
return res;
mode_error:
mp_raise_ValueError("illegal mode");
mp_raise_ValueError(MP_ERROR_TEXT("illegal mode"));
}
STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) {

View File

@ -128,7 +128,7 @@ STATIC mp_obj_t os_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
} else if (mp_obj_get_type(args[0]) == &machine_hard_uart_type) {
MP_STATE_PORT(board_stdio_uart) = args[0];
} else {
mp_raise_ValueError("need a UART object");
mp_raise_ValueError(MP_ERROR_TEXT("need a UART object"));
}
return mp_const_none;
}

Some files were not shown because too many files have changed in this diff Show More