Skip to content

Commit d4f1601

Browse files
authored
Merge pull request #8723 from jepler/jpegdecoder-enhancements
Jpegdecoder enhancements
2 parents 7418398 + 7724ce3 commit d4f1601

File tree

27 files changed

+917
-131
lines changed

27 files changed

+917
-131
lines changed

extmod/modjson.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ STATIC mp_uint_t json_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, i
188188
}
189189

190190
STATIC mp_obj_t _mod_json_load(mp_obj_t stream_obj, bool return_first_json) {
191-
const mp_stream_p_t *stream_p = mp_proto_get(MP_QSTR_protocol_stream, stream_obj);
191+
const mp_stream_p_t *stream_p = mp_proto_get(0, stream_obj);
192192
json_stream_t s;
193193
uint8_t character_buffer[CIRCUITPY_JSON_READ_CHUNK_SIZE];
194194
if (stream_p == NULL) {

locale/circuitpython.pot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ msgstr ""
212212
msgid "%q must be of type %q or %q, not %q"
213213
msgstr ""
214214

215+
#: shared-bindings/jpegio/JpegDecoder.c
216+
msgid "%q must be of type %q, %q, or %q, not %q"
217+
msgstr ""
218+
215219
#: py/argcheck.c shared-module/synthio/__init__.c
216220
msgid "%q must be of type %q, not %q"
217221
msgstr ""
@@ -249,6 +253,10 @@ msgstr ""
249253
msgid "%q() takes %d positional arguments but %d were given"
250254
msgstr ""
251255

256+
#: shared-module/jpegio/JpegDecoder.c
257+
msgid "%q() without %q()"
258+
msgstr ""
259+
252260
#: shared-bindings/usb_hid/Device.c
253261
msgid "%q, %q, and %q must all be the same length"
254262
msgstr ""

ports/espressif/bindings/espnow/ESPNow.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ STATIC mp_uint_t espnow_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt
332332
}
333333

334334
STATIC const mp_stream_p_t espnow_stream_p = {
335-
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
336335
.ioctl = espnow_stream_ioctl,
337336
};
338337

ports/espressif/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,24 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
3535
claim_pin(pin_a);
3636
claim_pin(pin_b);
3737

38+
// This configuration counts on all edges of the quadrature signal: Channel 0
39+
// counts on rising and falling edges of channel A, with the direction set by the
40+
// polarity of channel B. Channel 1 does likewise, counting edges of channel B according
41+
// to the polarity of channel A. A little pencil work suffices to show that this
42+
// counts correctly on all 8 correct quadrature state transitions.
43+
//
44+
// These routines also implicitly configure the weak internal pull-ups, as expected
45+
// in CircuitPython.
46+
3847
// Prepare configuration for the PCNT unit
3948
pcnt_config_t pcnt_config_channel_0 = {
4049
// Set PCNT input signal and control GPIOs
4150
.pulse_gpio_num = pin_a->number,
4251
.ctrl_gpio_num = pin_b->number,
4352
.channel = PCNT_CHANNEL_0,
4453
// What to do on the positive / negative edge of pulse input?
45-
.pos_mode = PCNT_COUNT_DEC, // Count up on the positive edge
46-
.neg_mode = PCNT_COUNT_INC, // Keep the counter value on the negative edge
54+
.pos_mode = PCNT_COUNT_DEC, // Count down on the positive edge
55+
.neg_mode = PCNT_COUNT_INC, // Count up on negative edge
4756
// What to do when control input is low or high?
4857
.lctrl_mode = PCNT_MODE_REVERSE, // Reverse counting direction if low
4958
.hctrl_mode = PCNT_MODE_KEEP, // Keep the primary counter mode if high
@@ -61,8 +70,8 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
6170
.ctrl_gpio_num = pin_a->number,
6271
.channel = PCNT_CHANNEL_1,
6372
// What to do on the positive / negative edge of pulse input?
64-
.pos_mode = PCNT_COUNT_DEC, // Count up on the positive edge
65-
.neg_mode = PCNT_COUNT_INC, // Keep the counter value on the negative edge
73+
.pos_mode = PCNT_COUNT_DEC, // Count down on the positive edge
74+
.neg_mode = PCNT_COUNT_INC, // Count up on negative edge
6675
// What to do when control input is low or high?
6776
.lctrl_mode = PCNT_MODE_KEEP, // Keep the primary counter mode if low
6877
.hctrl_mode = PCNT_MODE_REVERSE, // Reverse counting direction if high
@@ -88,6 +97,7 @@ void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_o
8897
reset_pin_number(self->pin_a);
8998
reset_pin_number(self->pin_b);
9099
peripherals_pcnt_deinit(&self->unit);
100+
self->unit = PCNT_UNIT_MAX;
91101
}
92102

93103
mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementalencoder_obj_t *self) {

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ extern void common_hal_mcu_enable_interrupts(void);
142142
#define MICROPY_PY_GC (1)
143143
// Supplanted by shared-bindings/math
144144
#define MICROPY_PY_IO (CIRCUITPY_IO)
145+
#define MICROPY_PY_IO_IOBASE (CIRCUITPY_IO_IOBASE)
145146
// In extmod
146147
#define MICROPY_PY_JSON (CIRCUITPY_JSON)
147148
#define MICROPY_PY_MATH (0)

py/circuitpy_mpconfig.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ CFLAGS += -DCIRCUITPY_IMAGECAPTURE=$(CIRCUITPY_IMAGECAPTURE)
302302
CIRCUITPY_IO ?= $(CIRCUITPY_JSON)
303303
CFLAGS += -DCIRCUITPY_IO=$(CIRCUITPY_IO)
304304

305+
# io.IOBase - enhances JPEG support
306+
CIRCUITPY_IO_IOBASE ?= $(call enable-if-all,$(CIRCUITPY_IO) $(CIRCUITPY_JPEGIO))
307+
CFLAGS += -DCIRCUITPY_IO_IOBASE=$(CIRCUITPY_IO_IOBASE)
308+
305309
CIRCUITPY_IPADDRESS ?= $(CIRCUITPY_WIFI)
306310
CFLAGS += -DCIRCUITPY_IPADDRESS=$(CIRCUITPY_IPADDRESS)
307311

py/makeqstrdata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@
250250
"zip",
251251
]
252252

253+
# CIRCUITPY-CHANGE
254+
# When taking the next merge from Micropython, prefer upstream's way of ensuring these appear in the "QSTR0" pool.
253255
# These qstrs have to be sorted early (preferably right after static_qstr_list) because they are required to fit in 8-bit values
254256
# however they should never be *forced* to appear
255257
# repeats len, hash, int from the static qstr list, but this doesn't hurt anything.

py/proto.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#ifndef MICROPY_INCLUDED_PY_PROTO_H
2828
#define MICROPY_INCLUDED_PY_PROTO_H
2929

30+
// CIRCUITPY-CHANGE
31+
//
32+
// In CircuitPython, we have multiple different 'protocol' types (rather than multiplexing through ioctl).
33+
// The standard (read/write/ioctl) protocol is indicated by the "0" protocol, while others must MP_PROTO_IMPLEMENT(QSTR_...).
34+
// While not used in CircuitPython or tested, the ability to skip including the protocol field in a protocol object is included at the source level
35+
3036
#ifdef MICROPY_UNSAFE_PROTO
3137
#define MP_PROTOCOL_HEAD /* NOTHING */
3238
#define MP_PROTO_IMPLEMENT(name) /* NOTHING */
@@ -35,7 +41,7 @@ static inline void *mp_proto_get(uint16_t name, mp_const_obj_type_t obj) {
3541
}
3642
#else
3743
#define MP_PROTOCOL_HEAD \
38-
uint16_t name; // The name of this protocol, a qstr
44+
uint16_t name;
3945
#define MP_PROTO_IMPLEMENT(n) .name = n,
4046
const void *mp_proto_get(uint16_t name, mp_const_obj_t obj);
4147
const void *mp_proto_get_or_throw(uint16_t name, mp_const_obj_t obj);

py/stream.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode
8383
}
8484

8585
const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
86-
const mp_obj_type_t *type = mp_obj_get_type(self_in);
87-
if (MP_OBJ_TYPE_HAS_SLOT(type, protocol)) {
88-
const mp_stream_p_t *stream_p = MP_OBJ_TYPE_GET_SLOT(type, protocol);
89-
if (!((flags & MP_STREAM_OP_READ) && stream_p->read == NULL)
90-
&& !((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
91-
&& !((flags & MP_STREAM_OP_IOCTL) && stream_p->ioctl == NULL)) {
92-
return stream_p;
93-
}
86+
// CIRCUITPY-CHANGE: using type-safe protocol accessor
87+
const mp_stream_p_t *stream_p = mp_get_stream(self_in);
88+
if (stream_p
89+
&& !((flags & MP_STREAM_OP_READ) && stream_p->read == NULL)
90+
&& !((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
91+
&& !((flags & MP_STREAM_OP_IOCTL) && stream_p->ioctl == NULL)) {
92+
return stream_p;
9493
}
9594
// CPython: io.UnsupportedOperation, OSError subclass
9695
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("stream operation not supported"));

py/stream.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj);
103103

104104
// Object is assumed to have a non-NULL stream protocol with valid r/w/ioctl methods
105105
static inline const mp_stream_p_t *mp_get_stream(mp_const_obj_t self) {
106-
return (const mp_stream_p_t *)MP_OBJ_TYPE_GET_SLOT(((const mp_obj_base_t *)MP_OBJ_TO_PTR(self))->type, protocol);
106+
// CIRCUITPY-CHANGE: using type-safe protocol accessor
107+
return mp_proto_get(0, (mp_obj_t)self);
107108
}
108109

109110
const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags);

0 commit comments

Comments
 (0)