Skip to content

Commit 063e394

Browse files
authored
Merge pull request #5094 from jepler/quirc
Add qrio: Decode QR codes with quirc lib
2 parents be2342f + 67551c1 commit 063e394

File tree

30 files changed

+721
-23
lines changed

30 files changed

+721
-23
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,6 @@
188188
[submodule "frozen/Adafruit_CircuitPython_SimpleIO"]
189189
path = frozen/Adafruit_CircuitPython_SimpleIO
190190
url = https://github.com/adafruit/adafruit_circuitpython_simpleio
191+
[submodule "lib/quirc"]
192+
path = lib/quirc
193+
url = https://github.com/adafruit/quirc.git

docs/common_hal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ These instructions also apply to `analogio`, `busio`, `pulseio` and `touchio`. M
77
Common HAL related files are found in these locations:
88

99
* `shared-bindings` Shared home for the Python <-> C bindings which includes inline RST documentation for the created interfaces. The common hal functions are defined in the .h files of the corresponding C files.
10-
* `shared-modules` Shared home for C code built on the Common HAL and used by all ports. This code only uses `common_hal` methods defined in `shared-bindings`.
10+
* `shared-module` Shared home for C code built on the Common HAL and used by all ports. This code only uses `common_hal` methods defined in `shared-bindings`.
1111
* `<port>/common-hal` Port-specific implementation of the Common HAL.
1212

1313
Each folder has the substructure of <python module name>/<class name> and they should match 1:1. `__init__.c` is used for module globals that are not classes (similar to `__init__.py`).

lib/quirc

Submodule quirc added at 8c6ffa2

locale/circuitpython.pot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,6 @@ msgid "Size not supported"
20632063
msgstr ""
20642064

20652065
#: ports/raspberrypi/common-hal/alarm/SleepMemory.c
2066-
#: ports/stm/common-hal/alarm/SleepMemory.c
20672066
msgid "Sleep Memory not available"
20682067
msgstr ""
20692068

ports/atmel-samd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE))
340340
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
341341

342342
# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
343-
# because a few modules have files both in common-hal/ and shared-modules/.
343+
# because a few modules have files both in common-hal/ and shared-module/.
344344
# Doing a $(sort ...) removes duplicates as part of sorting.
345345
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
346346

ports/esp32s2/boards/espressif_kaluga_1.3/mpconfigboard.mk

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ CIRCUITPY_ESP_FLASH_MODE=dio
1414
CIRCUITPY_ESP_FLASH_FREQ=80m
1515
CIRCUITPY_ESP_FLASH_SIZE=4MB
1616

17-
# We only have enough endpoints available in hardware to
18-
# enable ONE of these at a time.
19-
CIRCUITPY_USB_MIDI = 1
20-
CIRCUITPY_USB_HID = 0
21-
CIRCUITPY_USB_VENDOR = 0
22-
2317
CIRCUITPY_MODULE=wrover

ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ CIRCUITPY_ESP_FLASH_MODE=dio
1414
CIRCUITPY_ESP_FLASH_FREQ=80m
1515
CIRCUITPY_ESP_FLASH_SIZE=4MB
1616

17-
# We only have enough endpoints available in hardware to
18-
# enable ONE of these at a time.
19-
CIRCUITPY_USB_MIDI = 1
20-
CIRCUITPY_USB_HID = 0
21-
CIRCUITPY_USB_VENDOR = 0
22-
2317
CIRCUITPY_MODULE=wrover

ports/esp32s2/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CIRCUITPY_ROTARYIO = 1
3131
CIRCUITPY_NVM = 1
3232
CIRCUITPY_PS2IO ?= 1
3333
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1
34-
CIRCUITPY_WIFI = 1
34+
CIRCUITPY_WIFI ?= 1
3535
CIRCUITPY_WATCHDOG ?= 1
3636

3737
CIRCUITPY_ESPIDF = 1

ports/nrf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE))
191191
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
192192

193193
# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
194-
# because a few modules have files both in common-hal/ and shared-modules/.
194+
# because a few modules have files both in common-hal/ and shared-module/.
195195
# Doing a $(sort ...) removes duplicates as part of sorting.
196196
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
197197

ports/raspberrypi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE))
213213
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
214214

215215
# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
216-
# because a few modules have files both in common-hal/ and shared-modules/.
216+
# because a few modules have files both in common-hal/ and shared-module/.
217217
# Doing a $(sort ...) removes duplicates as part of sorting.
218218
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
219219

ports/unix/variants/coverage/mpconfigvariant.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@ MICROPY_VFS_LFS2 = 1
2121
FROZEN_DIR=variants/coverage/frzstr
2222
FROZEN_MPY_DIR=variants/coverage/frzmpy
2323

24+
SRC_QRIO := $(patsubst ../../%,%,$(wildcard ../../shared-bindings/qrio/*.c ../../shared-module/qrio/*.c ../../lib/quirc/lib/*.c))
25+
$(info SRC_QRIO = $(SRC_QRIO))
26+
SRC_C += $(SRC_QRIO)
27+
28+
CFLAGS += -DCIRCUITPY_QRIO=1
29+
$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h
30+
2431
SRC_C += coverage.c
2532
SRC_CXX += coveragecpp.cpp

py/circuitpy_defns.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ endif
224224
ifeq ($(CIRCUITPY_PIXELBUF),1)
225225
SRC_PATTERNS += adafruit_pixelbuf/%
226226
endif
227+
ifeq ($(CIRCUITPY_QRIO),1)
228+
SRC_PATTERNS += qrio/%
229+
endif
227230
ifeq ($(CIRCUITPY_RAINBOWIO),1)
228231
SRC_PATTERNS += rainbowio/%
229232
endif
@@ -445,6 +448,8 @@ $(filter $(SRC_PATTERNS), \
445448
_eve/__init__.c \
446449
camera/ImageFormat.c \
447450
canio/Match.c \
451+
qrio/PixelPolicy.c \
452+
qrio/QRInfo.c \
448453
digitalio/Direction.c \
449454
digitalio/DriveMode.c \
450455
digitalio/Pull.c \
@@ -532,6 +537,8 @@ SRC_SHARED_MODULE_ALL = \
532537
network/__init__.c \
533538
msgpack/__init__.c \
534539
os/__init__.c \
540+
qrio/__init__.c \
541+
qrio/QRDecoder.c \
535542
rainbowio/__init__.c \
536543
random/__init__.c \
537544
rgbmatrix/RGBMatrix.c \
@@ -668,6 +675,11 @@ SRC_CIRCUITPY_COMMON = \
668675
lib/utils/stdout_helpers.c \
669676
lib/utils/sys_stdio_mphal.c
670677

678+
ifeq ($(CIRCUITPY_QRIO),1)
679+
SRC_CIRCUITPY_COMMON += lib/quirc/lib/decode.c lib/quirc/lib/identify.c lib/quirc/lib/quirc.c lib/quirc/lib/version_db.c
680+
$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h
681+
endif
682+
671683
ifdef LD_TEMPLATE_FILE
672684
# Generate a linker script (.ld file) from a template, for those builds that use it.
673685
GENERATED_LD_FILE = $(BUILD)/$(notdir $(patsubst %.template.ld,%.ld,$(LD_TEMPLATE_FILE)))

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,13 @@ extern const struct _mp_obj_module_t pwmio_module;
621621
#define PWMIO_MODULE
622622
#endif
623623

624+
#if CIRCUITPY_QRIO
625+
extern const struct _mp_obj_module_t qrio_module;
626+
#define QRIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_qrio), (mp_obj_t)&qrio_module },
627+
#else
628+
#define QRIO_MODULE
629+
#endif
630+
624631
#if CIRCUITPY_RAINBOWIO
625632
extern const struct _mp_obj_module_t rainbowio_module;
626633
#define RAINBOWIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_rainbowio), (mp_obj_t)&rainbowio_module },
@@ -905,6 +912,7 @@ extern const struct _mp_obj_module_t msgpack_module;
905912
PS2IO_MODULE \
906913
PULSEIO_MODULE \
907914
PWMIO_MODULE \
915+
QRIO_MODULE \
908916
RAINBOWIO_MODULE \
909917
RANDOM_MODULE \
910918
RE_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO)
239239
CIRCUITPY_PWMIO ?= 1
240240
CFLAGS += -DCIRCUITPY_PWMIO=$(CIRCUITPY_PWMIO)
241241

242+
CIRCUITPY_QRIO ?= $(CIRCUITPY_IMAGECAPTURE)
243+
CFLAGS += -DCIRCUITPY_QRIO=$(CIRCUITPY_QRIO)
244+
242245
CIRCUITPY_RAINBOWIO ?= 1
243246
CFLAGS += -DCIRCUITPY_RAINBOWIO=$(CIRCUITPY_RAINBOWIO)
244247

shared-bindings/qrio/PixelPolicy.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of the CircuitPython project, https://github.com/adafruit/circuitpython
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Jeff Epler
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/qrio/__init__.h"
28+
#include "shared-bindings/qrio/PixelPolicy.h"
29+
#include "py/obj.h"
30+
#include "py/enum.h"
31+
32+
//| class PixelPolicy:
33+
//| EVERY_BYTE: PixelPolicy
34+
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
35+
//|
36+
//| EVEN_BYTES: PixelPolicy
37+
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data."""
38+
//|
39+
//| ODD_BYTES: PixelPolicy
40+
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data"""
41+
//|
42+
43+
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
44+
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
45+
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
46+
47+
MAKE_ENUM_MAP(qrio_pixel_policy) {
48+
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
49+
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
50+
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
51+
};
52+
STATIC MP_DEFINE_CONST_DICT(qrio_pixel_policy_locals_dict, qrio_pixel_policy_locals_table);
53+
54+
MAKE_PRINTER(qrio, qrio_pixel_policy);
55+
56+
MAKE_ENUM_TYPE(qrio, PixelPolicy, qrio_pixel_policy);

shared-bindings/qrio/PixelPolicy.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Jeff Epler for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#pragma once
28+
29+
#include "py/enum.h"
30+
#include "py/obj.h"
31+
#include "py/objnamedtuple.h"
32+
33+
extern const mp_obj_type_t qrio_pixel_policy_type;
34+
35+
typedef enum {
36+
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES
37+
} qrio_pixel_policy_t;
38+
39+
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;

0 commit comments

Comments
 (0)