Skip to content

Commit 9263662

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 36d4d1d + b81573d commit 9263662

File tree

52 files changed

+2604
-24
lines changed

Some content is hidden

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

52 files changed

+2604
-24
lines changed

locale/circuitpython.pot

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,22 @@ msgstr ""
8383
msgid "%q indices must be integers, not %s"
8484
msgstr ""
8585

86+
#: py/argcheck.c
87+
msgid "%q length must be %q"
88+
msgstr ""
89+
8690
#: shared-bindings/vectorio/Polygon.c
8791
msgid "%q list must be a list"
8892
msgstr ""
8993

94+
#: py/argcheck.c
95+
msgid "%q must <= %d"
96+
msgstr ""
97+
98+
#: py/argcheck.c
99+
msgid "%q must be %d-%d"
100+
msgstr ""
101+
90102
#: shared-bindings/usb_hid/Device.c
91103
msgid "%q must be 0-255"
92104
msgstr ""
@@ -95,7 +107,11 @@ msgstr ""
95107
msgid "%q must be 1-255"
96108
msgstr ""
97109

98-
#: shared-bindings/memorymonitor/AllocationAlarm.c
110+
#: py/argcheck.c
111+
msgid "%q must be >= %d"
112+
msgstr ""
113+
114+
#: py/argcheck.c shared-bindings/memorymonitor/AllocationAlarm.c
99115
msgid "%q must be >= 0"
100116
msgstr ""
101117

@@ -111,6 +127,10 @@ msgstr ""
111127
msgid "%q must be None or between 1 and len(report_descriptor)-1"
112128
msgstr ""
113129

130+
#: py/argcheck.c
131+
msgid "%q must be a string"
132+
msgstr ""
133+
114134
#: shared-module/vectorio/Polygon.c
115135
msgid "%q must be a tuple of length 2"
116136
msgstr ""
@@ -119,6 +139,15 @@ msgstr ""
119139
msgid "%q must be between %d and %d"
120140
msgstr ""
121141

142+
#: py/argcheck.c
143+
msgid "%q must of type %q"
144+
msgstr ""
145+
146+
#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c
147+
#: shared-bindings/keypad/ShiftRegisterKeys.c
148+
msgid "%q must store bytes"
149+
msgstr ""
150+
122151
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
123152
#: shared-bindings/canio/Match.c
124153
msgid "%q out of range"

main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
#include "shared-module/displayio/__init__.h"
8787
#endif
8888

89+
#if CIRCUITPY_KEYPAD
90+
#include "shared-module/keypad/__init__.h"
91+
#endif
92+
8993
#if CIRCUITPY_MEMORYMONITOR
9094
#include "shared-module/memorymonitor/__init__.h"
9195
#endif
@@ -230,9 +234,11 @@ STATIC void cleanup_after_vm(supervisor_allocation* heap) {
230234
#if CIRCUITPY_DISPLAYIO
231235
reset_displays();
232236
#endif
237+
233238
#if CIRCUITPY_MEMORYMONITOR
234239
memorymonitor_reset();
235240
#endif
241+
236242
filesystem_flush();
237243
stop_mp();
238244
free_memory(heap);
@@ -242,6 +248,10 @@ STATIC void cleanup_after_vm(supervisor_allocation* heap) {
242248
common_hal_canio_reset();
243249
#endif
244250

251+
#if CIRCUITPY_KEYPAD
252+
keypad_reset();
253+
#endif
254+
245255
// reset_board_busses() first because it may release pins from the never_reset state, so that
246256
// reset_port() can reset them.
247257
#if CIRCUITPY_BOARD

ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LONGINT_IMPL = NONE
1414

1515
CIRCUITPY_BUSDEVICE = 1
1616
CIRCUITPY_DISPLAYIO = 0
17+
CIRCUITPY_KEYPAD = 0
1718

1819
# Include these Python libraries in firmware.
1920
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground

ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
1111

1212
# Turn off features and optimizations for displayio build to make room for additional frozen libs.
1313
LONGINT_IMPL = NONE
14+
CIRCUITPY_KEYPAD = 0
1415
CIRCUITPY_PIXELBUF = 0
1516
CIRCUITPY_ROTARYIO = 0
1617
CIRCUITPY_RTC = 0

ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ LONGINT_IMPL = NONE
1212

1313
# To keep the build small
1414
CIRCUITPY_AUDIOBUSIO = 0
15-
CIRCUITPY_GAMEPAD = 0
1615

1716
# Include these Python libraries in firmware.
1817
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH

ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CIRCUITPY_AUDIOMP3 = 0
1515
CIRCUITPY_BLEIO_HCI = 0
1616
CIRCUITPY_DISPLAYIO = 0
1717
CIRCUITPY_FRAMEBUFFERIO = 0
18+
CIRCUITPY_KEYPAD = 0
1819
CIRCUITPY_MSGPACK = 0
1920
CIRCUITPY_PS2IO = 0
2021
CIRCUITPY_RGBMATRIX = 0

ports/atmel-samd/boards/pycubed/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ CIRCUITPY_DRIVE_LABEL = "PYCUBED"
1616
CIRCUITPY_AUDIOBUSIO = 0
1717
CIRCUITPY_BITMAPTOOLS = 0
1818
CIRCUITPY_DISPLAYIO = 0
19+
CIRCUITPY_KEYPAD = 0
1920
CIRCUITPY_FRAMEBUFFERIO = 0
20-
CIRCUITPY_GAMEPAD = 0
2121
CIRCUITPY_RGBMATRIX = 0
2222
CIRCUITPY_PS2IO = 0
2323

ports/atmel-samd/boards/pycubed_mram/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CIRCUITPY_AUDIOBUSIO = 0
1717
CIRCUITPY_BITMAPTOOLS = 0
1818
CIRCUITPY_DISPLAYIO = 0
1919
CIRCUITPY_FRAMEBUFFERIO = 0
20-
CIRCUITPY_GAMEPAD = 0
20+
CIRCUITPY_KEYPAD = 0
2121
CIRCUITPY_RGBMATRIX = 0
2222
CIRCUITPY_PS2IO = 0
2323

ports/atmel-samd/boards/stringcar_m0_express/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ SPI_FLASH_FILESYSTEM = 1
1111
EXTERNAL_FLASH_DEVICES = AT25SF161
1212
LONGINT_IMPL = MPZ
1313

14+
CIRCUITPY_KEYPAD = 0
15+
1416
CIRCUITPY_BITBANG_APA102 = 1

ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ CIRCUITPY_FREQUENCYIO = 0
2222
CIRCUITPY_AUDIOBUSIO = 0
2323
CIRCUITPY_BLEIO = 0
2424
CIRCUITPY_DISPLAYIO = 0
25-
CIRCUITPY_GAMEPAD = 0
2625
CIRCUITPY_I2CPERIPHERAL = 0
2726
CIRCUITPY_TOUCHIO = 0
2827
CIRCUITPY_RGBMATRIX = 0

ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ CIRCUITPY_BITMAPTOOLS = 0
2121
CIRCUITPY_BLEIO_HCI = 0
2222
CIRCUITPY_DISPLAYIO = 0
2323
CIRCUITPY_FRAMEBUFFERIO = 0
24-
CIRCUITPY_GAMEPAD = 0
2524
CIRCUITPY_I2CPERIPHERAL = 0
2625
CIRCUITPY_TOUCHIO = 0
2726
CIRCUITPY_RGBMATRIX = 0

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 0
5050
CIRCUITPY_FREQUENCYIO ?= 0
5151
CIRCUITPY_I2CPERIPHERAL ?= 0
5252
CIRCUITPY_JSON ?= 0
53+
CIRCUITPY_KEYPAD ?= 0
5354
CIRCUITPY_MSGPACK ?= 0
5455
CIRCUITPY_RE ?= 0
5556
CIRCUITPY_SDCARDIO ?= 0

ports/nrf/boards/pca10100/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CIRCUITPY_FRAMEBUFFERIO = 0
1818
CIRCUITPY_FREQUENCYIO = 0
1919
CIRCUITPY_I2CPERIPHERAL = 0
2020
CIRCUITPY_JSON = 0
21+
CIRCUITPY_KEYPAD = 0
2122
CIRCUITPY_MSGPACK = 0
2223
CIRCUITPY_NEOPIXEL_WRITE = 0
2324
CIRCUITPY_NVM = 0

ports/nrf/boards/simmel/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CIRCUITPY_COUNTIO = 0
2020
CIRCUITPY_DISPLAYIO = 0
2121
CIRCUITPY_ERRNO = 0
2222
CIRCUITPY_FRAMEBUFFERIO = 0
23-
CIRCUITPY_GAMEPAD = 0
23+
CIRCUITPY_KEYPAD = 0
2424
CIRCUITPY_MSGPACK = 0
2525
CIRCUITPY_NEOPIXEL_WRITE = 0
2626
CIRCUITPY_NVM = 0

ports/stm/boards/espruino_pico/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CIRCUITPY_AUDIOPWMIO = 0
2222
CIRCUITPY_BUSDEVICE = 0
2323
CIRCUITPY_BITMAPTOOLS = 0
2424
CIRCUITPY_FRAMEBUFFERIO = 0
25+
CIRCUITPY_KEYPAD = 0
2526
CIRCUITPY_MIDI = 0
2627
CIRCUITPY_MSGPACK = 0
2728
CIRCUITPY_ULAB = 0

ports/stm/boards/meowbit_v121/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ LD_FILE = boards/STM32F401xe_boot.ld
2020
# For debugging - also comment BOOTLOADER_OFFSET and BOARD_VTOR_DEFER
2121
# LD_FILE = boards/STM32F401xe_fs.ld
2222

23+
CIRCUITPY_BLEIO_HCI = 0
2324
CIRCUITPY_ULAB = 0

ports/stm/boards/pyb_nano_v2/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ LD_FILE = boards/STM32F411_fs.ld
1616
# Too big for the flash
1717
CIRCUITPY_AUDIOCORE = 0
1818
CIRCUITPY_AUDIOPWMIO = 0
19+
CIRCUITPY_KEYPAD = 0
1920
CIRCUITPY_MIDI = 0
2021
CIRCUITPY_MSGPACK = 0

ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ LD_FILE = boards/STM32F411_fs.ld
1515
# Too big for the flash
1616
CIRCUITPY_AUDIOCORE = 0
1717
CIRCUITPY_AUDIOPWMIO = 0
18+
CIRCUITPY_KEYPAD = 0
1819
CIRCUITPY_MIDI = 0
1920
CIRCUITPY_MSGPACK = 0

py/argcheck.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,56 @@ NORETURN void mp_arg_error_unimpl_kw(void) {
162162
mp_raise_NotImplementedError(MP_ERROR_TEXT("keyword argument(s) not yet implemented - use normal args instead"));
163163
}
164164
#endif
165+
166+
167+
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
168+
if (i < min) {
169+
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, min);
170+
}
171+
return i;
172+
}
173+
174+
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t max, qstr arg_name) {
175+
if (i > max) {
176+
mp_raise_ValueError_varg(translate("%q must <= %d"), arg_name, max);
177+
}
178+
return i;
179+
}
180+
181+
mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name) {
182+
if (i < min || i > max) {
183+
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
184+
}
185+
return i;
186+
}
187+
188+
mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name) {
189+
const mp_float_t f = (float_in == MP_OBJ_NULL)
190+
? default_for_null
191+
: mp_obj_get_float(float_in);
192+
if (f <= (mp_float_t)0.0) {
193+
mp_raise_ValueError_varg(translate("%q must be >= 0"), arg_name);
194+
}
195+
return f;
196+
}
197+
198+
size_t mp_arg_validate_length_with_name(mp_int_t i, size_t length, qstr arg_name, qstr length_name) {
199+
if (i != (mp_int_t)length) {
200+
mp_raise_ValueError_varg(translate("%q length must be %q"), MP_QSTR_pressed, MP_QSTR_num_keys);
201+
}
202+
return (size_t)i;
203+
}
204+
205+
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
206+
if (!mp_obj_is_type(obj, type)) {
207+
mp_raise_TypeError_varg(translate("%q must of type %q"), arg_name, type->name);
208+
}
209+
return obj;
210+
}
211+
212+
mp_obj_t mp_arg_validate_string(mp_obj_t obj, qstr arg_name) {
213+
if (!mp_obj_is_str(obj)) {
214+
mp_raise_TypeError_varg(translate("%q must be a string"), arg_name);
215+
}
216+
return obj;
217+
}

py/circuitpy_defns.mk

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ endif
178178
ifeq ($(CIRCUITPY_FRAMEBUFFERIO),1)
179179
SRC_PATTERNS += framebufferio/%
180180
endif
181+
ifeq ($(CIRCUITPY__EVE),1)
182+
SRC_PATTERNS += _eve/%
183+
endif
181184
ifeq ($(CIRCUITPY_FREQUENCYIO),1)
182185
SRC_PATTERNS += frequencyio/%
183186
endif
@@ -196,12 +199,12 @@ endif
196199
ifeq ($(CIRCUITPY_IPADDRESS),1)
197200
SRC_PATTERNS += ipaddress/%
198201
endif
202+
ifeq ($(CIRCUITPY_KEYPAD),1)
203+
SRC_PATTERNS += keypad/%
204+
endif
199205
ifeq ($(CIRCUITPY_MATH),1)
200206
SRC_PATTERNS += math/%
201207
endif
202-
ifeq ($(CIRCUITPY__EVE),1)
203-
SRC_PATTERNS += _eve/%
204-
endif
205208
ifeq ($(CIRCUITPY_MEMORYMONITOR),1)
206209
SRC_PATTERNS += memorymonitor/%
207210
endif
@@ -512,6 +515,12 @@ SRC_SHARED_MODULE_ALL = \
512515
framebufferio/__init__.c \
513516
ipaddress/IPv4Address.c \
514517
ipaddress/__init__.c \
518+
keypad/__init__.c \
519+
keypad/Event.c \
520+
keypad/EventQueue.c \
521+
keypad/KeyMatrix.c \
522+
keypad/ShiftRegisterKeys.c \
523+
keypad/Keys.c \
515524
sdcardio/SDCard.c \
516525
sdcardio/__init__.c \
517526
gamepad/GamePad.c \

py/circuitpy_mpconfig.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,13 @@ extern const struct _mp_obj_module_t espidf_module;
440440
#define ESPIDF_MODULE
441441
#endif
442442

443+
#if CIRCUITPY__EVE
444+
extern const struct _mp_obj_module_t _eve_module;
445+
#define _EVE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__eve), (mp_obj_t)&_eve_module },
446+
#else
447+
#define _EVE_MODULE
448+
#endif
449+
443450
#if CIRCUITPY_FRAMEBUFFERIO
444451
extern const struct _mp_obj_module_t framebufferio_module;
445452
#define FRAMEBUFFERIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_framebufferio), (mp_obj_t)&framebufferio_module },
@@ -523,20 +530,30 @@ extern const struct _mp_obj_module_t ipaddress_module;
523530
#define JSON_MODULE
524531
#endif
525532

533+
#if CIRCUITPY_KEYPAD
534+
extern const struct _mp_obj_module_t keypad_module;
535+
#define KEYPAD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_keypad), (mp_obj_t)&keypad_module },
536+
#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list;
537+
#else
538+
#define KEYPAD_MODULE
539+
#define KEYPAD_ROOT_POINTERS
540+
#endif
541+
542+
#if CIRCUITPY_GAMEPAD || CIRCUITPY_GAMEPADSHIFT
543+
// Scan gamepad every 32ms
544+
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
545+
#define GAMEPAD_ROOT_POINTERS mp_obj_t gamepad_singleton;
546+
#else
547+
#define GAMEPAD_ROOT_POINTERS
548+
#endif
549+
526550
#if CIRCUITPY_MATH
527551
extern const struct _mp_obj_module_t math_module;
528552
#define MATH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module },
529553
#else
530554
#define MATH_MODULE
531555
#endif
532556

533-
#if CIRCUITPY__EVE
534-
extern const struct _mp_obj_module_t _eve_module;
535-
#define _EVE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__eve), (mp_obj_t)&_eve_module },
536-
#else
537-
#define _EVE_MODULE
538-
#endif
539-
540557
#if CIRCUITPY_MEMORYMONITOR
541558
extern const struct _mp_obj_module_t memorymonitor_module;
542559
#define MEMORYMONITOR_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_memorymonitor), (mp_obj_t)&memorymonitor_module },
@@ -877,6 +894,7 @@ extern const struct _mp_obj_module_t msgpack_module;
877894
VECTORIO_MODULE \
878895
ERRNO_MODULE \
879896
ESPIDF_MODULE \
897+
_EVE_MODULE \
880898
FRAMEBUFFERIO_MODULE \
881899
FREQUENCYIO_MODULE \
882900
GAMEPAD_MODULE \
@@ -886,8 +904,8 @@ extern const struct _mp_obj_module_t msgpack_module;
886904
IPADDRESS_MODULE \
887905
IMAGECAPTURE_MODULE \
888906
JSON_MODULE \
907+
KEYPAD_MODULE \
889908
MATH_MODULE \
890-
_EVE_MODULE \
891909
MEMORYMONITOR_MODULE \
892910
MICROCONTROLLER_MODULE \
893911
MSGPACK_MODULE \
@@ -954,6 +972,7 @@ struct _supervisor_allocation_node;
954972
vstr_t *repl_line; \
955973
mp_obj_t rtc_time_source; \
956974
GAMEPAD_ROOT_POINTERS \
975+
KEYPAD_ROOT_POINTERS \
957976
mp_obj_t pew_singleton; \
958977
BOARD_UART_ROOT_POINTER \
959978
FLASH_ROOT_POINTERS \

0 commit comments

Comments
 (0)