Skip to content

Commit c16b42e

Browse files
committed
Tweak arg checking and comments
1 parent 0498b1d commit c16b42e

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

ports/espressif/bindings/espulp/ULP.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ STATIC espulp_ulp_obj_t *get_ulp_obj(mp_obj_t self_in) {
5656
}
5757

5858
//| def deinit(self) -> None:
59-
//| """Deinitialises the camera and releases all memory resources for reuse."""
59+
//| """Deinitialises the ULP and releases it for another program."""
6060
//| ...
6161
STATIC mp_obj_t espulp_ulp_deinit(mp_obj_t self_in) {
6262
espulp_ulp_obj_t *self = get_ulp_obj(self_in);
@@ -104,12 +104,19 @@ STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t
104104

105105
mp_obj_t pins_in = args[ARG_pins].u_obj;
106106
const size_t num_pins = (size_t)MP_OBJ_SMALL_INT_VALUE(mp_obj_len(pins_in));
107+
108+
// The ULP only supports 21 pins on the ESP32-S2 and S3. So we can store it
109+
// as a bitmask in a 32 bit number. The common-hal code does further checks.
107110
uint32_t pin_mask = 0;
108111

109112
for (mp_uint_t i = 0; i < num_pins; i++) {
110113
mp_obj_t pin_obj = mp_obj_subscr(pins_in, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL);
111114
validate_obj_is_free_pin(pin_obj);
112-
pin_mask |= 1 << ((const mcu_pin_obj_t *)pin_obj)->number;
115+
const mcu_pin_obj_t *pin = ((const mcu_pin_obj_t *)pin_obj);
116+
if (pin->number >= 32) {
117+
raise_ValueError_invalid_pin();
118+
}
119+
pin_mask |= 1 << pin->number;
113120
}
114121

115122
common_hal_espulp_ulp_run(self, bufinfo.buf, bufinfo.len, pin_mask);

ports/espressif/common-hal/espulp/ULP.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void common_hal_espulp_ulp_run(espulp_ulp_obj_t *self, uint32_t *program, size_t
6161
}
6262

6363
if (pin_mask >= (1 << 22)) {
64-
mp_raise_ValueError(translate("Pins 21+ not supported from ULP"));
64+
raise_ValueError_invalid_pin();
6565
}
6666

6767
for (uint8_t i = 0; i < 32; i++) {
@@ -89,7 +89,7 @@ void common_hal_espulp_ulp_halt(espulp_ulp_obj_t *self) {
8989
// ulp_riscv_timer_stop();
9090
// ulp_riscv_halt();
9191

92-
// stop the ulp timer so that is doesn't restart the cpu
92+
// stop the ulp timer so that it doesn't restart the cpu
9393
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
9494

9595
// suspends the ulp operation
@@ -107,6 +107,9 @@ void common_hal_espulp_ulp_halt(espulp_ulp_obj_t *self) {
107107
}
108108

109109
void common_hal_espulp_ulp_construct(espulp_ulp_obj_t *self) {
110+
// Use a static variable to track ULP in use so that subsequent code runs can
111+
// use a running ULP. This is only to prevent multiple portions of user code
112+
// from using the ULP concurrently.
110113
if (ulp_used) {
111114
mp_raise_ValueError_varg(translate("%q in use"), MP_QSTR_ULP);
112115
}

shared-bindings/memorymap/AddressRange.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ STATIC MP_DEFINE_CONST_DICT(memorymap_addressrange_locals_dict, memorymap_addres
105105
//| def __getitem__(self, index: int) -> int:
106106
//| """Returns the value(s) at the given index.
107107
//|
108-
//| 1, 2, 4 and 8 byte reads will be done in one assignment. All others
109-
//| will use memcpy."""
108+
//| 1, 2, 4 and 8 byte aligned reads will be done in one transaction.
109+
//| All others may use multiple transactions."""
110110
//| ...
111111
//| @overload
112112
//| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ...
113113
//| @overload
114114
//| def __setitem__(self, index: int, value: int) -> None:
115115
//| """Set the value(s) at the given index.
116116
//|
117-
//| 1, 2, 4 and 8 byte writes will be done in one assignment. All others
118-
//| will use memcpy."""
117+
//| 1, 2, 4 and 8 byte aligned writes will be done in one transaction.
118+
//| All others may use multiple transactions."""
119119
//| ...
120120
//|
121121
STATIC mp_obj_t memorymap_addressrange_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {

0 commit comments

Comments
 (0)