Skip to content

Commit 67551c1

Browse files
committed
qrio: Split QRInfo & PixelPolicy to their own .c/.h files
1 parent 8e201d5 commit 67551c1

File tree

9 files changed

+196
-75
lines changed

9 files changed

+196
-75
lines changed

py/circuitpy_defns.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ $(filter $(SRC_PATTERNS), \
445445
_eve/__init__.c \
446446
camera/ImageFormat.c \
447447
canio/Match.c \
448+
qrio/PixelPolicy.c \
449+
qrio/QRInfo.c \
448450
digitalio/Direction.c \
449451
digitalio/DriveMode.c \
450452
digitalio/Pull.c \
@@ -672,7 +674,6 @@ SRC_CIRCUITPY_COMMON = \
672674
ifeq ($(CIRCUITPY_QRIO),1)
673675
SRC_CIRCUITPY_COMMON += lib/quirc/lib/decode.c lib/quirc/lib/identify.c lib/quirc/lib/quirc.c lib/quirc/lib/version_db.c
674676
$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h
675-
676677
endif
677678

678679
ifdef LD_TEMPLATE_FILE

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;

shared-bindings/qrio/QRInfo.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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/QRInfo.h"
29+
#include "py/obj.h"
30+
#include "py/enum.h"
31+
32+
//| class QRInfo:
33+
//| """Information about a decoded QR code"""
34+
//|
35+
//| payload: bytes
36+
//| """The content of the QR code"""
37+
//|
38+
//| data_type: Union[str, int]
39+
//| """The encoding of the payload as a string (if a standard encoding) or int (if not standard)"""
40+
41+
const mp_obj_namedtuple_type_t qrio_qrinfo_type_obj = {
42+
.base = {
43+
.base = {
44+
.type = &mp_type_type
45+
},
46+
.flags = MP_TYPE_FLAG_EXTENDED,
47+
.name = MP_QSTR_QRInfo,
48+
.print = namedtuple_print,
49+
.parent = &mp_type_tuple,
50+
.make_new = namedtuple_make_new,
51+
.attr = namedtuple_attr,
52+
MP_TYPE_EXTENDED_FIELDS(
53+
.unary_op = mp_obj_tuple_unary_op,
54+
.binary_op = mp_obj_tuple_binary_op,
55+
.subscr = mp_obj_tuple_subscr,
56+
.getiter = mp_obj_tuple_getiter,
57+
),
58+
},
59+
.n_fields = 2,
60+
.fields = {
61+
MP_QSTR_payload,
62+
MP_QSTR_data_type,
63+
},
64+
};

shared-bindings/qrio/QRInfo.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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/objnamedtuple.h"
30+
31+
extern const mp_obj_namedtuple_type_t qrio_qrinfo_type_obj;

shared-bindings/qrio/__init__.c

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "shared-bindings/qrio/__init__.h"
2828
#include "shared-bindings/qrio/QRDecoder.h"
29+
#include "shared-bindings/qrio/QRInfo.h"
30+
#include "shared-bindings/qrio/PixelPolicy.h"
2931
#include "py/obj.h"
3032
#include "py/enum.h"
3133

@@ -34,66 +36,6 @@
3436
//| Provides the `QRDecoder` object."""
3537
//|
3638

37-
//| class PixelPolicy:
38-
//| EVERY_BYTE: PixelPolicy
39-
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
40-
//|
41-
//| EVEN_BYTES: PixelPolicy
42-
//| """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."""
43-
//|
44-
//| ODD_BYTES: PixelPolicy
45-
//| """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"""
46-
//|
47-
48-
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
49-
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
50-
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
51-
52-
MAKE_ENUM_MAP(qrio_pixel_policy) {
53-
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
54-
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
55-
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
56-
};
57-
STATIC MP_DEFINE_CONST_DICT(qrio_pixel_policy_locals_dict, qrio_pixel_policy_locals_table);
58-
59-
MAKE_PRINTER(qrio, qrio_pixel_policy);
60-
61-
MAKE_ENUM_TYPE(qrio, PixelPolicy, qrio_pixel_policy);
62-
63-
//| class QRInfo:
64-
//| """Information about a decoded QR code"""
65-
//|
66-
//| payload: bytes
67-
//| """The content of the QR code"""
68-
//|
69-
//| data_type: Union[str, int]
70-
//| """The encoding of the payload as a string (if a standard encoding) or int (if not standard)"""
71-
72-
const mp_obj_namedtuple_type_t qrio_qrinfo_type_obj = {
73-
.base = {
74-
.base = {
75-
.type = &mp_type_type
76-
},
77-
.flags = MP_TYPE_FLAG_EXTENDED,
78-
.name = MP_QSTR_QRInfo,
79-
.print = namedtuple_print,
80-
.parent = &mp_type_tuple,
81-
.make_new = namedtuple_make_new,
82-
.attr = namedtuple_attr,
83-
MP_TYPE_EXTENDED_FIELDS(
84-
.unary_op = mp_obj_tuple_unary_op,
85-
.binary_op = mp_obj_tuple_binary_op,
86-
.subscr = mp_obj_tuple_subscr,
87-
.getiter = mp_obj_tuple_getiter,
88-
),
89-
},
90-
.n_fields = 2,
91-
.fields = {
92-
MP_QSTR_payload,
93-
MP_QSTR_data_type,
94-
},
95-
};
96-
9739
STATIC const mp_rom_map_elem_t qrio_module_globals_table[] = {
9840
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_qrio) },
9941
{ MP_ROM_QSTR(MP_QSTR_QRInfo), MP_ROM_PTR(&qrio_qrinfo_type_obj) },

shared-bindings/qrio/__init__.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,3 @@
2525
*/
2626

2727
#pragma once
28-
29-
#include "py/enum.h"
30-
#include "py/obj.h"
31-
#include "py/objnamedtuple.h"
32-
33-
extern const mp_obj_namedtuple_type_t qrio_qrinfo_type_obj;
34-
35-
extern const mp_obj_type_t qrio_pixel_policy_type;
36-
37-
typedef enum {
38-
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES
39-
} qrio_pixel_policy_t;
40-
41-
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;

shared-module/qrio/QRDecoder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "py/gc.h"
3030
#include "py/objnamedtuple.h"
3131
#include "shared-bindings/qrio/__init__.h"
32+
#include "shared-bindings/qrio/QRInfo.h"
3233
#include "shared-module/qrio/QRDecoder.h"
3334

3435
void shared_module_qrio_qrdecoder_construct(qrdecoder_qrdecoder_obj_t *self, int width, int height) {

shared-module/qrio/QRDecoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "py/obj.h"
3030
#include "lib/quirc/lib/quirc.h"
31+
#include "shared-bindings/qrio/PixelPolicy.h"
3132

3233
typedef struct qrio_qrdecoder_obj {
3334
mp_obj_base_t base;

0 commit comments

Comments
 (0)