Skip to content

Commit fc23a0c

Browse files
committed
implement ota module
1 parent 054eafd commit fc23a0c

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed
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 MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 microDev
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/ota/__init__.h"
28+
29+
void common_hal_ota_flash(const void *buf, const size_t len) {
30+
31+
}

ports/esp32s2/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CIRCUITPY_FREQUENCYIO = 1
2323
CIRCUITPY_I2CPERIPHERAL = 0
2424
CIRCUITPY_ROTARYIO = 1
2525
CIRCUITPY_NVM = 1
26+
CIRCUITPY_OTA = 1
2627
# We don't have enough endpoints to include MIDI.
2728
CIRCUITPY_USB_MIDI = 0
2829
CIRCUITPY_WIFI = 1

py/circuitpy_defns.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ endif
205205
ifeq ($(CIRCUITPY_OS),1)
206206
SRC_PATTERNS += os/%
207207
endif
208+
ifeq ($(CIRCUITPY_OTA),1)
209+
SRC_PATTERNS += ota/%
210+
endif
208211
ifeq ($(CIRCUITPY_PIXELBUF),1)
209212
SRC_PATTERNS += _pixelbuf/%
210213
endif
@@ -347,6 +350,7 @@ SRC_COMMON_HAL_ALL = \
347350
nvm/ByteArray.c \
348351
nvm/__init__.c \
349352
os/__init__.c \
353+
ota/__init__.c \
350354
ps2io/Ps2.c \
351355
ps2io/__init__.c \
352356
pulseio/PulseIn.c \

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ extern const struct _mp_obj_module_t os_module;
539539
#define OS_MODULE_ALT_NAME
540540
#endif
541541

542+
#if CIRCUITPY_OTA
543+
extern const struct _mp_obj_module_t ota_module;
544+
#define OTA_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ota), (mp_obj_t)&ota_module },
545+
#else
546+
#define OTA_MODULE
547+
#endif
548+
542549
#if CIRCUITPY_PEW
543550
extern const struct _mp_obj_module_t pew_module;
544551
#define PEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module },
@@ -827,6 +834,7 @@ extern const struct _mp_obj_module_t wifi_module;
827834
NETWORK_MODULE \
828835
SOCKET_MODULE \
829836
WIZNET_MODULE \
837+
OTA_MODULE \
830838
PEW_MODULE \
831839
PIXELBUF_MODULE \
832840
PS2IO_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM)
179179
CIRCUITPY_OS ?= 1
180180
CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS)
181181

182+
CIRCUITPY_OTA ?= 0
183+
CFLAGS += -DCIRCUITPY_OTA=$(CIRCUITPY_OTA)
184+
182185
CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD)
183186
CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF)
184187

shared-bindings/ota/__init__.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 microDev
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/ota/__init__.h"
28+
29+
//| """ota module
30+
//|
31+
//| The `ota` module implements over-the-air update."""
32+
33+
STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) {
34+
mp_buffer_info_t bufinfo;
35+
mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ);
36+
37+
common_hal_ota_flash(bufinfo.buf, bufinfo.len);
38+
return mp_const_none;
39+
}
40+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash);
41+
42+
STATIC const mp_rom_map_elem_t ota_module_globals_table[] = {
43+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) },
44+
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) },
45+
};
46+
STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table);
47+
48+
const mp_obj_module_t ota_module = {
49+
.base = { &mp_type_module },
50+
.globals = (mp_obj_dict_t*)&ota_module_globals,
51+
};

shared-bindings/ota/__init__.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 microDev
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+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H
29+
30+
#include "py/runtime.h"
31+
32+
extern void common_hal_ota_flash(const void *buf, const size_t len);
33+
34+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H

0 commit comments

Comments
 (0)