forked from Foundation-Devices/passport2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodpassport-mem.h
119 lines (102 loc) · 4.86 KB
/
modpassport-mem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-FileCopyrightText: © 2020 Foundation Devices, Inc. <[email protected]>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <stdint.h>
#include "py/obj.h"
#include "py/objarray.h"
#include "py/binary.h"
#include "../../../../lib/lv_bindings/lvgl/lvgl.h"
#include "framebuffer.h"
/**
* @brief Passport maximum supported QR version that can be rendered.
*
* @note Keep in sync with modfoundation.c QRCode class.
*/
#define PASSPORT_MAX_QR_VERSION (13)
/**
* @brief Attribute used to allocate a static variable in the
* SRAM4 section.
*/
#define MP_SRAM4 __attribute__((section(".sram4")))
/**
* @brief Attribute used to allocate a static variable in the
* SRAM4 section.
*/
#define MP_DTCM __attribute__((section(".dtcm")))
/**
* @brief Create a compile-time bytearray by reference.
*
* Same behaviour as `mp_obj_new_bytearray_by_ref` (bytearray_at in Python side)
* but statically allocated.
*
* @param obj The object name.
* @param ptr The pointer to the data.
* @param len The length of the data.
*/
#define MP_OBJ_BYTEARRAY_BY_REF(obj, ptr, ptr_len) \
mp_obj_array_t obj = { \
.base = {&mp_type_bytearray}, \
.typecode = BYTEARRAY_TYPECODE, \
.free = 0, \
.len = ptr_len, \
.items = ptr, \
}
/// package: passport.mem
/// psbt_output: bytearray
STATIC MP_DTCM uint8_t mod_passport_mem_psbt_output[26 * 1024];
STATIC MP_OBJ_BYTEARRAY_BY_REF(mod_passport_mem_psbt_output_obj,
mod_passport_mem_psbt_output,
sizeof(mod_passport_mem_psbt_output));
/// ext_settings_buf: bytearray
STATIC MP_SRAM4 uint8_t mod_passport_mem_ext_settings_buf[16 * 1024];
STATIC MP_OBJ_BYTEARRAY_BY_REF(mod_passport_mem_ext_settings_buf_obj,
mod_passport_mem_ext_settings_buf,
sizeof(mod_passport_mem_ext_settings_buf));
/// tmp_buf: bytearray
STATIC MP_SRAM4 uint8_t mod_passport_mem_tmp_buf[1024];
STATIC MP_OBJ_BYTEARRAY_BY_REF(mod_passport_mem_tmp_buf_obj,
mod_passport_mem_tmp_buf,
sizeof(mod_passport_mem_tmp_buf));
/// psbt_tmp256: bytearray
STATIC MP_SRAM4 uint8_t mod_passport_mem_psbt_tmp256[256];
STATIC MP_OBJ_BYTEARRAY_BY_REF(mod_passport_mem_psbt_tmp256_obj,
mod_passport_mem_psbt_tmp256,
sizeof(mod_passport_mem_psbt_tmp256));
/// qrcode_buffer: bytearray
STATIC MP_SRAM4 uint8_t mod_passport_mem_qrcode_buffer[LV_QRCODE_IMG_BUF_SIZE(LCD_HOR_RES)];
STATIC MP_OBJ_BYTEARRAY_BY_REF(mod_passport_mem_passport_qrcode_buffer_obj,
mod_passport_mem_qrcode_buffer,
sizeof(mod_passport_mem_qrcode_buffer));
/// qrcode_modules_buffer: bytearray
STATIC MP_SRAM4 uint8_t mod_passport_mem_qrcode_modules_buffer[LV_QRCODE_MODULES_BUF_SIZE(PASSPORT_MAX_QR_VERSION)];
STATIC MP_OBJ_BYTEARRAY_BY_REF(mod_passport_mem_qrcode_modules_buffer_obj,
mod_passport_mem_qrcode_modules_buffer,
sizeof(mod_passport_mem_qrcode_modules_buffer));
/// def qrcode_buffer_clear() -> None:
/// """
/// Clear the QR code buffer
///
/// Sets all bytes to 0, except the color palette which is at the start of the buffer (4 * 2 bytes).
/// """
STATIC mp_obj_t mod_passport_mem_qrcode_buffer_clear(void)
{
memset(mod_passport_mem_qrcode_buffer + (4 * 2), 0, sizeof(mod_passport_mem_qrcode_buffer) - (4 * 2));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_passport_mem_qrcode_buffer_clear_obj,
mod_passport_mem_qrcode_buffer_clear);
STATIC const mp_rom_map_elem_t mod_passport_mem_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR_MAX_QR_VERSION), MP_ROM_INT(PASSPORT_MAX_QR_VERSION)},
{MP_ROM_QSTR(MP_QSTR_psbt_output), MP_ROM_PTR(&mod_passport_mem_psbt_output_obj)},
{MP_ROM_QSTR(MP_QSTR_ext_settings_buf), MP_ROM_PTR(&mod_passport_mem_ext_settings_buf_obj)},
{MP_ROM_QSTR(MP_QSTR_tmp_buf), MP_ROM_PTR(&mod_passport_mem_tmp_buf_obj)},
{MP_ROM_QSTR(MP_QSTR_psbt_tmp256), MP_ROM_PTR(&mod_passport_mem_psbt_tmp256_obj)},
{MP_ROM_QSTR(MP_QSTR_qrcode_buffer), MP_ROM_PTR(&mod_passport_mem_passport_qrcode_buffer_obj)},
{MP_ROM_QSTR(MP_QSTR_qrcode_modules_buffer), MP_ROM_PTR(&mod_passport_mem_qrcode_modules_buffer_obj)},
{MP_ROM_QSTR(MP_QSTR_qrcode_buffer_clear), MP_ROM_PTR(&mod_passport_mem_qrcode_buffer_clear_obj)},
};
STATIC MP_DEFINE_CONST_DICT(mod_passport_mem_globals, mod_passport_mem_globals_table);
STATIC const mp_obj_module_t mod_passport_mem_module = {
.base = {&mp_type_module},
.globals = (mp_obj_dict_t*)&mod_passport_mem_globals,
};