Skip to content

Commit c1a6637

Browse files
authored
Merge pull request #3 from adafruit/master
Merge updated Circuitpython
2 parents 053277e + 5dd420f commit c1a6637

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2766
-481
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@
8080
path = lib/tinyusb
8181
url = https://github.com/hathach/tinyusb.git
8282
branch = develop
83+
[submodule "tools/huffman"]
84+
path = tools/huffman
85+
url = https://github.com/tannewt/huffman.git

extmod/machine_i2c.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "py/runtime.h"
3434
#include "extmod/machine_i2c.h"
3535

36+
#include "supervisor/shared/translate.h"
37+
3638
#if MICROPY_PY_MACHINE_I2C
3739

3840
typedef mp_machine_soft_i2c_obj_t machine_i2c_obj_t;
@@ -294,7 +296,7 @@ STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, s
294296
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);
295297
return MICROPY_PY_MACHINE_I2C_MAKE_NEW(type, n_args, n_kw, args);
296298
#else
297-
mp_raise_ValueError("invalid I2C peripheral");
299+
mp_raise_ValueError(translate("invalid I2C peripheral"));
298300
#endif
299301
}
300302
--n_args;
@@ -335,7 +337,7 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
335337
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
336338
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
337339
if (i2c_p->start == NULL) {
338-
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
340+
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
339341
}
340342
int ret = i2c_p->start(self);
341343
if (ret != 0) {
@@ -349,7 +351,7 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
349351
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
350352
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
351353
if (i2c_p->stop == NULL) {
352-
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
354+
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
353355
}
354356
int ret = i2c_p->stop(self);
355357
if (ret != 0) {
@@ -363,7 +365,7 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
363365
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
364366
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
365367
if (i2c_p->read == NULL) {
366-
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
368+
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
367369
}
368370

369371
// get the buffer to read into
@@ -387,7 +389,7 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
387389
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
388390
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
389391
if (i2c_p->write == NULL) {
390-
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
392+
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
391393
}
392394

393395
// get the buffer to write from

extmod/machine_mem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
4343
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
4444
if ((addr & (align - 1)) != 0) {
45-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "address %08x is not aligned to %d bytes", addr, align));
45+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, translate("address %08x is not aligned to %d bytes"), addr, align));
4646
}
4747
return addr;
4848
}

extmod/machine_spi.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "py/runtime.h"
3131
#include "extmod/machine_spi.h"
3232

33+
#include "supervisor/shared/translate.h"
34+
3335
#if MICROPY_PY_MACHINE_SPI
3436

3537
// if a port didn't define MSB/LSB constants then provide them
@@ -52,7 +54,7 @@ mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
5254
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);
5355
return MICROPY_PY_MACHINE_SPI_MAKE_NEW(type, n_args, n_kw, args);
5456
#else
55-
mp_raise_ValueError("invalid SPI peripheral");
57+
mp_raise_ValueError(translate("invalid SPI peripheral"));
5658
#endif
5759
}
5860
--n_args;
@@ -119,7 +121,7 @@ STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp
119121
mp_buffer_info_t dest;
120122
mp_get_buffer_raise(rd_buf, &dest, MP_BUFFER_WRITE);
121123
if (src.len != dest.len) {
122-
mp_raise_ValueError("buffers must be the same length");
124+
mp_raise_ValueError(translate("buffers must be the same length"));
123125
}
124126
mp_machine_spi_transfer(self, src.len, src.buf, dest.buf);
125127
return mp_const_none;
@@ -202,15 +204,15 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n
202204
self->spi.polarity = args[ARG_polarity].u_int;
203205
self->spi.phase = args[ARG_phase].u_int;
204206
if (args[ARG_bits].u_int != 8) {
205-
mp_raise_ValueError("bits must be 8");
207+
mp_raise_ValueError(translate("bits must be 8"));
206208
}
207209
if (args[ARG_firstbit].u_int != MICROPY_PY_MACHINE_SPI_MSB) {
208-
mp_raise_ValueError("firstbit must be MSB");
210+
mp_raise_ValueError(translate("firstbit must be MSB"));
209211
}
210212
if (args[ARG_sck].u_obj == MP_OBJ_NULL
211213
|| args[ARG_mosi].u_obj == MP_OBJ_NULL
212214
|| args[ARG_miso].u_obj == MP_OBJ_NULL) {
213-
mp_raise_ValueError("must specify all of sck/mosi/miso");
215+
mp_raise_ValueError(translate("must specify all of sck/mosi/miso"));
214216
}
215217
self->spi.sck = mp_hal_get_pin_obj(args[ARG_sck].u_obj);
216218
self->spi.mosi = mp_hal_get_pin_obj(args[ARG_mosi].u_obj);

extmod/modframebuf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
296296
case FRAMEBUF_GS8:
297297
break;
298298
default:
299-
mp_raise_ValueError("invalid format");
299+
mp_raise_ValueError(translate("invalid format"));
300300
}
301301

302302
return MP_OBJ_FROM_PTR(o);

extmod/modubinascii.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
static void check_not_unicode(const mp_obj_t arg) {
3636
#if MICROPY_CPYTHON_COMPAT
3737
if (MP_OBJ_IS_STR(arg)) {
38-
mp_raise_TypeError("a bytes-like object is required");
38+
mp_raise_TypeError(translate("a bytes-like object is required"));
3939
}
4040
#endif
4141
}
@@ -87,7 +87,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
8787
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
8888

8989
if ((bufinfo.len & 1) != 0) {
90-
mp_raise_ValueError("odd-length string");
90+
mp_raise_ValueError(translate("odd-length string"));
9191
}
9292
vstr_t vstr;
9393
vstr_init_len(&vstr, bufinfo.len / 2);
@@ -98,7 +98,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
9898
if (unichar_isxdigit(hex_ch)) {
9999
hex_byte += unichar_xdigit_value(hex_ch);
100100
} else {
101-
mp_raise_ValueError("non-hex digit found");
101+
mp_raise_ValueError(translate("non-hex digit found"));
102102
}
103103
if (i & 1) {
104104
hex_byte <<= 4;
@@ -166,7 +166,7 @@ mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
166166
}
167167

168168
if (nbits) {
169-
mp_raise_ValueError("incorrect padding");
169+
mp_raise_ValueError(translate("incorrect padding"));
170170
}
171171

172172
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);

extmod/moductypes.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "py/objtuple.h"
3333
#include "py/binary.h"
3434

35+
#include "supervisor/shared/translate.h"
36+
3537
#if MICROPY_PY_UCTYPES
3638

3739
/// \module uctypes - Access data structures in memory
@@ -117,7 +119,7 @@ typedef struct _mp_obj_uctypes_struct_t {
117119
} mp_obj_uctypes_struct_t;
118120

119121
STATIC NORETURN void syntax_error(void) {
120-
mp_raise_TypeError("syntax error in uctypes descriptor");
122+
mp_raise_TypeError(translate("syntax error in uctypes descriptor"));
121123
}
122124

123125
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) {
@@ -214,7 +216,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
214216
// but scalar structure field is lowered into native Python int, so all
215217
// type info is lost. So, we cannot say if it's scalar type description,
216218
// or such lowered scalar.
217-
mp_raise_TypeError("Cannot unambiguously get sizeof scalar");
219+
mp_raise_TypeError(translate("Cannot unambiguously get sizeof scalar"));
218220
}
219221
syntax_error();
220222
}
@@ -392,7 +394,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
392394

393395
// TODO: Support at least OrderedDict in addition
394396
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
395-
mp_raise_TypeError("struct: no fields");
397+
mp_raise_TypeError(translate("struct: no fields"));
396398
}
397399

398400
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
@@ -525,7 +527,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
525527
} else {
526528
// load / store
527529
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
528-
mp_raise_TypeError("struct: cannot index");
530+
mp_raise_TypeError(translate("struct: cannot index"));
529531
}
530532

531533
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
@@ -539,7 +541,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
539541
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
540542
arr_sz &= VALUE_MASK(VAL_TYPE_BITS);
541543
if (index >= arr_sz) {
542-
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "struct: index out of range"));
544+
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, translate("struct: index out of range")));
543545
}
544546

545547
if (t->len == 2) {

extmod/moduhashlib.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#include "py/runtime.h"
3131

32+
#include "supervisor/shared/translate.h"
33+
3234
#if MICROPY_PY_UHASHLIB
3335

3436
#if MICROPY_PY_UHASHLIB_SHA256
@@ -97,7 +99,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
9799
static void check_not_unicode(const mp_obj_t arg) {
98100
#if MICROPY_CPYTHON_COMPAT
99101
if (MP_OBJ_IS_STR(arg)) {
100-
mp_raise_TypeError("a bytes-like object is required");
102+
mp_raise_TypeError(translate("a bytes-like object is required"));
101103
}
102104
#endif
103105
}

extmod/moduheapq.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
#include "py/objlist.h"
2828
#include "py/runtime.h"
2929

30+
#include "supervisor/shared/translate.h"
31+
3032
#if MICROPY_PY_UHEAPQ
3133

3234
// the algorithm here is modelled on CPython's heapq.py
3335

3436
STATIC mp_obj_list_t *get_heap(mp_obj_t heap_in) {
3537
if (!MP_OBJ_IS_TYPE(heap_in, &mp_type_list)) {
36-
mp_raise_TypeError("heap must be a list");
38+
mp_raise_TypeError(translate("heap must be a list"));
3739
}
3840
return MP_OBJ_TO_PTR(heap_in);
3941
}
@@ -81,7 +83,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
8183
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
8284
mp_obj_list_t *heap = get_heap(heap_in);
8385
if (heap->len == 0) {
84-
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
86+
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, translate("empty heap")));
8587
}
8688
mp_obj_t item = heap->items[0];
8789
heap->len -= 1;

extmod/modujson.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "py/runtime.h"
3333
#include "py/stream.h"
3434

35+
#include "supervisor/shared/translate.h"
36+
3537
#if MICROPY_PY_UJSON
3638

3739
STATIC mp_obj_t mod_ujson_dump(mp_obj_t obj, mp_obj_t stream) {
@@ -276,7 +278,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
276278
return stack_top;
277279

278280
fail:
279-
mp_raise_ValueError("syntax error in JSON");
281+
mp_raise_ValueError(translate("syntax error in JSON"));
280282
}
281283
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);
282284

extmod/modure.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
158158
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, caps[0] - subj.begin);
159159
mp_obj_list_append(retval, s);
160160
if (self->re.sub > 0) {
161-
mp_raise_NotImplementedError("Splitting with sub-captures");
161+
mp_raise_NotImplementedError(translate("Splitting with sub-captures"));
162162
}
163163
subj.begin = caps[1];
164164
if (maxsplit > 0 && --maxsplit == 0) {
@@ -204,7 +204,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
204204
int error = re1_5_compilecode(&o->re, re_str);
205205
if (error != 0) {
206206
error:
207-
mp_raise_ValueError("Error in regex");
207+
mp_raise_ValueError(translate("Error in regex"));
208208
}
209209
if (flags & FLAG_DEBUG) {
210210
re1_5_dumpcode(&o->re);

extmod/modussl_axtls.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "py/runtime.h"
3131
#include "py/stream.h"
3232

33+
#include "supervisor/shared/translate.h"
34+
3335
#if MICROPY_PY_USSL && MICROPY_SSL_AXTLS
3436

3537
#include "ssl.h"
@@ -76,13 +78,13 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
7678
const byte *data = (const byte*)mp_obj_str_get_data(args->key.u_obj, &len);
7779
int res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_RSA_KEY, data, len, NULL);
7880
if (res != SSL_OK) {
79-
mp_raise_ValueError("invalid key");
81+
mp_raise_ValueError(translate("invalid key"));
8082
}
8183

8284
data = (const byte*)mp_obj_str_get_data(args->cert.u_obj, &len);
8385
res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_X509_CERT, data, len, NULL);
8486
if (res != SSL_OK) {
85-
mp_raise_ValueError("invalid cert");
87+
mp_raise_ValueError(translate("invalid cert"));
8688
}
8789
}
8890

extmod/modutimeq.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "py/runtime.h"
3232
#include "py/smallint.h"
3333

34+
#include "supervisor/shared/translate.h"
35+
3436
#if MICROPY_PY_UTIMEQ
3537

3638
#define MODULO MICROPY_PY_UTIME_TICKS_PERIOD
@@ -126,7 +128,7 @@ STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
126128
mp_obj_t heap_in = args[0];
127129
mp_obj_utimeq_t *heap = get_heap(heap_in);
128130
if (heap->len == heap->alloc) {
129-
mp_raise_IndexError("queue overflow");
131+
mp_raise_IndexError(translate("queue overflow"));
130132
}
131133
mp_uint_t l = heap->len;
132134
heap->items[l].time = MP_OBJ_SMALL_INT_VALUE(args[1]);
@@ -142,7 +144,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_utimeq_heappush_obj, 4, 4, mod_ut
142144
STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
143145
mp_obj_utimeq_t *heap = get_heap(heap_in);
144146
if (heap->len == 0) {
145-
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
147+
mp_raise_IndexError(translate("empty heap"));
146148
}
147149
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
148150
if (!MP_OBJ_IS_TYPE(list_ref, &mp_type_list) || ret->len < 3) {
@@ -167,7 +169,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_utimeq_heappop_obj, mod_utimeq_heappop);
167169
STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
168170
mp_obj_utimeq_t *heap = get_heap(heap_in);
169171
if (heap->len == 0) {
170-
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
172+
mp_raise_IndexError(translate("empty heap"));
171173
}
172174

173175
struct qentry *item = &heap->items[0];

extmod/moduzlib.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "py/stream.h"
3232
#include "py/mperrno.h"
3333

34+
#include "supervisor/shared/translate.h"
35+
3436
#if MICROPY_PY_UZLIB
3537

3638
#include "../../lib/uzlib/src/tinf.h"
@@ -92,7 +94,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size
9294
dict_opt = uzlib_zlib_parse_header(&o->decomp);
9395
if (dict_opt < 0) {
9496
header_error:
95-
mp_raise_ValueError("compression header");
97+
mp_raise_ValueError(translate("compression header"));
9698
}
9799
dict_sz = 1 << dict_opt;
98100
} else {

extmod/uos_dupterm.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "py/stream.h"
3535
#include "lib/utils/interrupt_char.h"
3636

37+
#include "supervisor/shared/translate.h"
38+
3739
#if MICROPY_PY_OS_DUPTERM
3840

3941
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) {
@@ -115,7 +117,7 @@ STATIC mp_obj_t mp_uos_dupterm(size_t n_args, const mp_obj_t *args) {
115117
}
116118

117119
if (idx < 0 || idx >= MICROPY_PY_OS_DUPTERM) {
118-
mp_raise_ValueError("invalid dupterm index");
120+
mp_raise_ValueError(translate("invalid dupterm index"));
119121
}
120122

121123
mp_obj_t previous_obj = MP_STATE_VM(dupterm_objs[idx]);

extmod/vfs_posix.c

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#if defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX
3333

34+
#include <stdio.h>
3435
#include <string.h>
3536
#include <sys/stat.h>
3637
#include <dirent.h>

0 commit comments

Comments
 (0)