summaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorDaniel Tralamazza <daniel@tralamazza.com>2017-08-08 00:45:58 +0200
committerDaniel Tralamazza <daniel@tralamazza.com>2017-08-08 00:45:58 +0200
commitb53b6913147bdee5aef1b54f7728d44580dd0935 (patch)
treecfbfad1ddf3ef386131ec5a39961be70d4b60398 /extmod
parent3e0d3d283d5619e52e04dc8484d7bf413e66d130 (diff)
parent6c55cdafa32e4db9e2aaf08b1ec597b4723721ea (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'extmod')
-rw-r--r--extmod/lwip-include/arch/cc.h6
-rw-r--r--extmod/lwip-include/arch/perf.h6
-rw-r--r--extmod/lwip-include/lwipopts.h7
-rw-r--r--extmod/machine_i2c.h7
-rw-r--r--extmod/machine_mem.c2
-rw-r--r--extmod/machine_mem.h10
-rw-r--r--extmod/machine_pinbase.h8
-rw-r--r--extmod/machine_pulse.h7
-rw-r--r--extmod/machine_signal.c2
-rw-r--r--extmod/machine_signal.h8
-rw-r--r--extmod/machine_spi.h1
-rw-r--r--extmod/misc.h4
-rw-r--r--extmod/modbtree.c2
-rw-r--r--extmod/modframebuf.c56
-rw-r--r--extmod/modlwip.c114
-rw-r--r--extmod/modonewire.c162
-rw-r--r--extmod/modubinascii.c14
-rw-r--r--extmod/modubinascii.h9
-rw-r--r--extmod/moductypes.c6
-rw-r--r--extmod/moduhashlib.c2
-rw-r--r--extmod/moduheapq.c2
-rw-r--r--extmod/modujson.c2
-rw-r--r--extmod/modure.c11
-rw-r--r--extmod/moduselect.c10
-rw-r--r--extmod/modussl_axtls.c63
-rw-r--r--extmod/modussl_mbedtls.c52
-rw-r--r--extmod/moduzlib.c3
-rw-r--r--extmod/modwebrepl.c21
-rw-r--r--extmod/modwebsocket.c5
-rw-r--r--extmod/modwebsocket.h5
-rw-r--r--extmod/uos_dupterm.c1
-rw-r--r--extmod/utime_mphal.c2
-rw-r--r--extmod/utime_mphal.h4
-rw-r--r--extmod/vfs.h1
-rw-r--r--extmod/vfs_fat.h6
-rw-r--r--extmod/vfs_fat_diskio.c2
-rw-r--r--extmod/vfs_fat_file.c3
-rw-r--r--extmod/virtpin.h4
38 files changed, 437 insertions, 193 deletions
diff --git a/extmod/lwip-include/arch/cc.h b/extmod/lwip-include/arch/cc.h
index 0a7907d34..400dc6ec7 100644
--- a/extmod/lwip-include/arch/cc.h
+++ b/extmod/lwip-include/arch/cc.h
@@ -1,5 +1,5 @@
-#ifndef __CC_H__
-#define __CC_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_CC_H
+#define MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_CC_H
#include <stdint.h>
@@ -38,4 +38,4 @@ typedef u32_t mem_ptr_t;
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
-#endif /* __ARCH_CC_H__ */
+#endif // MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_CC_H
diff --git a/extmod/lwip-include/arch/perf.h b/extmod/lwip-include/arch/perf.h
index 51710701a..d310fc339 100644
--- a/extmod/lwip-include/arch/perf.h
+++ b/extmod/lwip-include/arch/perf.h
@@ -1,7 +1,7 @@
-#ifndef __PERF_H__
-#define __PERF_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_PERF_H
+#define MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_PERF_H
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
-#endif /* __PERF_H__ */
+#endif // MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_PERF_H
diff --git a/extmod/lwip-include/lwipopts.h b/extmod/lwip-include/lwipopts.h
index e4a33b238..2122f30f0 100644
--- a/extmod/lwip-include/lwipopts.h
+++ b/extmod/lwip-include/lwipopts.h
@@ -1,5 +1,5 @@
-#ifndef __LWIPOPTS_H__
-#define __LWIPOPTS_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_LWIPOPTS_H
+#define MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_LWIPOPTS_H
#include <py/mpconfig.h>
#include <py/misc.h>
@@ -32,5 +32,4 @@ typedef uint32_t sys_prot_t;
// things like this into a port-provided header file.
#define sys_now mp_hal_ticks_ms
-#endif
-
+#endif // MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_LWIPOPTS_H
diff --git a/extmod/machine_i2c.h b/extmod/machine_i2c.h
index d49ff01e4..f5af6656f 100644
--- a/extmod/machine_i2c.h
+++ b/extmod/machine_i2c.h
@@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__
-#define __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H
+#define MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H
#include "py/obj.h"
@@ -54,4 +53,4 @@ extern const mp_obj_dict_t mp_machine_soft_i2c_locals_dict;
int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t *dest, size_t len, bool stop);
int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uint8_t *src, size_t len, bool stop);
-#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__
+#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H
diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c
index 88c176803..af987cb7f 100644
--- a/extmod/machine_mem.c
+++ b/extmod/machine_mem.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/extmod/machine_mem.h b/extmod/machine_mem.h
index fddd7d46c..a48a52c82 100644
--- a/extmod/machine_mem.h
+++ b/extmod/machine_mem.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -23,10 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-
-#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H__
-#define __MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H
+#define MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H
#include "py/obj.h"
@@ -48,4 +46,4 @@ uintptr_t MICROPY_MACHINE_MEM_GET_READ_ADDR(mp_obj_t addr_o, uint align);
uintptr_t MICROPY_MACHINE_MEM_GET_WRITE_ADDR(mp_obj_t addr_o, uint align);
#endif
-#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H__
+#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H
diff --git a/extmod/machine_pinbase.h b/extmod/machine_pinbase.h
index ece3384cc..c96abbc46 100644
--- a/extmod/machine_pinbase.h
+++ b/extmod/machine_pinbase.h
@@ -23,13 +23,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-
-#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H__
-#define __MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H
+#define MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H
#include "py/obj.h"
extern const mp_obj_type_t machine_pinbase_type;
-#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H__
+#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H
diff --git a/extmod/machine_pulse.h b/extmod/machine_pulse.h
index cc1c4eda5..e303dca02 100644
--- a/extmod/machine_pulse.h
+++ b/extmod/machine_pulse.h
@@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__
-#define __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H
+#define MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H
#include "py/obj.h"
#include "py/mphal.h"
@@ -34,4 +33,4 @@ mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj);
-#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__
+#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H
diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c
index d08931296..78d0c3fee 100644
--- a/extmod/machine_signal.c
+++ b/extmod/machine_signal.c
@@ -96,7 +96,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
if (n_args == 1) {
if (n_kw == 0) {
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
- invert = mp_obj_is_true(args[1]);
+ invert = mp_obj_is_true(args[2]);
} else {
goto error;
}
diff --git a/extmod/machine_signal.h b/extmod/machine_signal.h
index 7f88cbaa8..df1c3e2e9 100644
--- a/extmod/machine_signal.h
+++ b/extmod/machine_signal.h
@@ -23,13 +23,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-
-#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H__
-#define __MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H__
+#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H
+#define MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H
#include "py/obj.h"
extern const mp_obj_type_t machine_signal_type;
-#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H__
+#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H
diff --git a/extmod/machine_spi.h b/extmod/machine_spi.h
index 88a3e19f4..e24e41eb3 100644
--- a/extmod/machine_spi.h
+++ b/extmod/machine_spi.h
@@ -23,7 +23,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H
#define MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H
diff --git a/extmod/misc.h b/extmod/misc.h
index d7ead0654..6c13592c7 100644
--- a/extmod/misc.h
+++ b/extmod/misc.h
@@ -24,6 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_EXTMOD_MISC_H
+#define MICROPY_INCLUDED_EXTMOD_MISC_H
// This file contains cumulative declarations for extmod/ .
@@ -38,3 +40,5 @@ void mp_uos_deactivate(const char *msg, mp_obj_t exc);
#else
#define mp_uos_dupterm_tx_strn(s, l)
#endif
+
+#endif // MICROPY_INCLUDED_EXTMOD_MISC_H
diff --git a/extmod/modbtree.c b/extmod/modbtree.c
index 127dd71a3..229daaf0f 100644
--- a/extmod/modbtree.c
+++ b/extmod/modbtree.c
@@ -26,7 +26,7 @@
#include <stdio.h>
#include <string.h>
-#include <errno.h>
+#include <errno.h> // for declaration of global errno variable
#include <fcntl.h>
#include "py/nlr.h"
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c
index b8e84fe1c..f4e857129 100644
--- a/extmod/modframebuf.c
+++ b/extmod/modframebuf.c
@@ -62,10 +62,10 @@ typedef struct _mp_framebuf_p_t {
// Functions for MHLSB and MHMSB
-STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
+STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
size_t index = (x + y * fb->stride) >> 3;
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
- ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset);
+ ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
}
STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
@@ -90,10 +90,10 @@ STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int
// Functions for MVLSB format
-STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
+STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
size_t index = (y >> 3) * fb->stride + x;
uint8_t offset = y & 0x07;
- ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset);
+ ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
}
STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
@@ -114,19 +114,19 @@ STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, in
// Functions for RGB565 format
-STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
- ((uint16_t*)fb->buf)[x + y * fb->stride] = color;
+STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
+ ((uint16_t*)fb->buf)[x + y * fb->stride] = col;
}
STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
return ((uint16_t*)fb->buf)[x + y * fb->stride];
}
-STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t colour) {
+STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
uint16_t *b = &((uint16_t*)fb->buf)[x + y * fb->stride];
while (h--) {
for (int ww = w; ww; --ww) {
- *b++ = colour;
+ *b++ = col;
}
b += fb->stride - w;
}
@@ -156,7 +156,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
col &= 0x0f;
uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
uint8_t col_shifted_left = col << 4;
- uint8_t colored_pixel_pair = col_shifted_left | col;
+ uint8_t col_pixel_pair = col_shifted_left | col;
int pixel_count_till_next_line = (fb->stride - w) >> 1;
bool odd_x = (x % 2 == 1);
@@ -169,7 +169,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
ww--;
}
- memset(pixel_pair, colored_pixel_pair, ww >> 1);
+ memset(pixel_pair, col_pixel_pair, ww >> 1);
pixel_pair += ww >> 1;
if (ww % 2) {
@@ -191,8 +191,8 @@ STATIC mp_framebuf_p_t formats[] = {
[FRAMEBUF_MHMSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect},
};
-static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
- formats[fb->format].setpixel(fb, x, y, color);
+static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
+ formats[fb->format].setpixel(fb, x, y, col);
}
static inline uint32_t getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
@@ -237,15 +237,16 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
switch (o->format) {
case FRAMEBUF_MVLSB:
case FRAMEBUF_RGB565:
- case FRAMEBUF_GS4_HMSB:
break;
case FRAMEBUF_MHLSB:
case FRAMEBUF_MHMSB:
o->stride = (o->stride + 7) & ~7;
break;
+ case FRAMEBUF_GS4_HMSB:
+ o->stride = (o->stride + 1) & ~1;
+ break;
default:
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "invalid format"));
+ mp_raise_ValueError("invalid format");
}
return MP_OBJ_FROM_PTR(o);
@@ -276,9 +277,9 @@ STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) {
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t width = mp_obj_get_int(args[3]);
mp_int_t height = mp_obj_get_int(args[4]);
- mp_int_t color = mp_obj_get_int(args[5]);
+ mp_int_t col = mp_obj_get_int(args[5]);
- fill_rect(self, x, y, width, height, color);
+ fill_rect(self, x, y, width, height, col);
return mp_const_none;
}
@@ -443,14 +444,13 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
int y1 = MAX(0, -y);
int x0end = MIN(self->width, x + source->width);
int y0end = MIN(self->height, y + source->height);
- uint32_t color;
for (; y0 < y0end; ++y0) {
int cx1 = x1;
for (int cx0 = x0; cx0 < x0end; ++cx0) {
- color = getpixel(source, cx1, y1);
- if (color != key) {
- setpixel(self, cx0, y0, color);
+ uint32_t col = getpixel(source, cx1, y1);
+ if (col != (uint32_t)key) {
+ setpixel(self, cx0, y0, col);
}
++cx1;
}
@@ -549,7 +549,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
.name = MP_QSTR_FrameBuffer,
.make_new = framebuf_make_new,
.buffer_p = { .get_buffer = framebuf_get_buffer },
- .locals_dict = (mp_obj_t)&framebuf_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict,
};
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
@@ -578,12 +578,12 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) },
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) },
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) },
- { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
- { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
- { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) },
- { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) },
- { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) },
- { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) },
+ { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_ROM_INT(FRAMEBUF_MVLSB) },
+ { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_ROM_INT(FRAMEBUF_MVLSB) },
+ { MP_ROM_QSTR(MP_QSTR_RGB565), MP_ROM_INT(FRAMEBUF_RGB565) },
+ { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_ROM_INT(FRAMEBUF_GS4_HMSB) },
+ { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_ROM_INT(FRAMEBUF_MHLSB) },
+ { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_ROM_INT(FRAMEBUF_MHMSB) },
};
STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table);
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index 01190d200..bde251cca 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Galen Hazelwood
- * Copyright (c) 2015-2016 Paul Sokolovsky
+ * Copyright (c) 2015-2017 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -45,6 +45,7 @@
//#include "lwip/raw.h"
#include "lwip/dns.h"
#include "lwip/tcp_impl.h"
+#include "lwip/igmp.h"
#if 0 // print debugging info
#define DEBUG_printf DEBUG_printf
@@ -52,6 +53,10 @@
#define DEBUG_printf(...) (void)0
#endif
+// All socket options should be globally distinct,
+// because we ignore option levels for efficiency.
+#define IP_ADD_MEMBERSHIP 0x400
+
// For compatibilily with older lwIP versions.
#ifndef ip_set_option
#define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
@@ -148,8 +153,8 @@ STATIC mp_obj_t lwip_slip_status(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwip_slip_status_obj, lwip_slip_status);
-STATIC const mp_map_elem_t lwip_slip_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&lwip_slip_status_obj },
+STATIC const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lwip_slip_status_obj) },
};
STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table);
@@ -158,7 +163,7 @@ STATIC const mp_obj_type_t lwip_slip_type = {
{ &mp_type_type },
.name = MP_QSTR_slip,
.make_new = lwip_slip_make_new,
- .locals_dict = (mp_obj_t)&lwip_slip_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&lwip_slip_locals_dict,
};
#endif // MICROPY_PY_LWIP_SLIP
@@ -1079,10 +1084,10 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
- // Integer options
- mp_int_t val = mp_obj_get_int(args[3]);
switch (opt) {
- case SOF_REUSEADDR:
+ // level: SOL_SOCKET
+ case SOF_REUSEADDR: {
+ mp_int_t val = mp_obj_get_int(args[3]);
// Options are common for UDP and TCP pcb's.
if (val) {
ip_set_option(socket->pcb.tcp, SOF_REUSEADDR);
@@ -1090,6 +1095,24 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
ip_reset_option(socket->pcb.tcp, SOF_REUSEADDR);
}
break;
+ }
+
+ // level: IPPROTO_IP
+ case IP_ADD_MEMBERSHIP: {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
+ if (bufinfo.len != sizeof(ip_addr_t) * 2) {
+ mp_raise_ValueError(NULL);
+ }
+
+ // POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
+ err_t err = igmp_joingroup((ip_addr_t*)bufinfo.buf + 1, bufinfo.buf);
+ if (err != ERR_OK) {
+ mp_raise_OSError(error_lookup_table[-err]);
+ }
+ break;
+ }
+
default:
printf("Warning: lwip.setsockopt() not implemented\n");
}
@@ -1160,27 +1183,27 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
return ret;
}
-STATIC const mp_map_elem_t lwip_socket_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&lwip_socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&lwip_socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&lwip_socket_bind_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_listen), (mp_obj_t)&lwip_socket_listen_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_accept), (mp_obj_t)&lwip_socket_accept_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&lwip_socket_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&lwip_socket_send_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&lwip_socket_recv_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendto), (mp_obj_t)&lwip_socket_sendto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recvfrom), (mp_obj_t)&lwip_socket_recvfrom_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendall), (mp_obj_t)&lwip_socket_sendall_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_settimeout), (mp_obj_t)&lwip_socket_settimeout_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setblocking), (mp_obj_t)&lwip_socket_setblocking_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setsockopt), (mp_obj_t)&lwip_socket_setsockopt_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&lwip_socket_makefile_obj },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
+STATIC const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&lwip_socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&lwip_socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&lwip_socket_bind_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&lwip_socket_listen_obj) },
+ { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&lwip_socket_accept_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&lwip_socket_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&lwip_socket_send_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&lwip_socket_recv_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&lwip_socket_sendto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&lwip_socket_recvfrom_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendall), MP_ROM_PTR(&lwip_socket_sendall_obj) },
+ { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&lwip_socket_settimeout_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&lwip_socket_setblocking_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&lwip_socket_setsockopt_obj) },
+ { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&lwip_socket_makefile_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
};
STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table);
@@ -1196,7 +1219,7 @@ STATIC const mp_obj_type_t lwip_socket_type = {
.print = lwip_socket_print,
.make_new = lwip_socket_make_new,
.protocol = &lwip_socket_stream_p,
- .locals_dict = (mp_obj_t)&lwip_socket_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&lwip_socket_locals_dict,
};
/******************************************************************************/
@@ -1321,27 +1344,30 @@ MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs);
#ifdef MICROPY_PY_LWIP
-STATIC const mp_map_elem_t mp_module_lwip_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_lwip) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&mod_lwip_reset_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&mod_lwip_callback_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&lwip_getaddrinfo_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_print_pcbs), (mp_obj_t)&lwip_print_pcbs_obj },
+STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_lwip) },
+ { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mod_lwip_reset_obj) },
+ { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_lwip_callback_obj) },
+ { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&lwip_getaddrinfo_obj) },
+ { MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
// objects
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&lwip_socket_type },
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) },
#ifdef MICROPY_PY_LWIP_SLIP
- { MP_OBJ_NEW_QSTR(MP_QSTR_slip), (mp_obj_t)&lwip_slip_type },
+ { MP_ROM_QSTR(MP_QSTR_slip), MP_ROM_PTR(&lwip_slip_type) },
#endif
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET6), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET6) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) },
+
+ { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(MOD_NETWORK_SOCK_STREAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(MOD_NETWORK_SOCK_DGRAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_RAW), MP_ROM_INT(MOD_NETWORK_SOCK_RAW) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_DGRAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_RAW), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_RAW) },
+ { MP_ROM_QSTR(MP_QSTR_SOL_SOCKET), MP_ROM_INT(1) },
+ { MP_ROM_QSTR(MP_QSTR_SO_REUSEADDR), MP_ROM_INT(SOF_REUSEADDR) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOL_SOCKET), MP_OBJ_NEW_SMALL_INT(1) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SO_REUSEADDR), MP_OBJ_NEW_SMALL_INT(SOF_REUSEADDR) },
+ { MP_ROM_QSTR(MP_QSTR_IPPROTO_IP), MP_ROM_INT(0) },
+ { MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table);
diff --git a/extmod/modonewire.c b/extmod/modonewire.c
new file mode 100644
index 000000000..53c9456c2
--- /dev/null
+++ b/extmod/modonewire.c
@@ -0,0 +1,162 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015-2017 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+#include "py/obj.h"
+#include "py/mphal.h"
+
+/******************************************************************************/
+// Low-level 1-Wire routines
+
+#define TIMING_RESET1 (480)
+#define TIMING_RESET2 (40)
+#define TIMING_RESET3 (420)
+#define TIMING_READ1 (5)
+#define TIMING_READ2 (5)
+#define TIMING_READ3 (40)
+#define TIMING_WRITE1 (10)
+#define TIMING_WRITE2 (50)
+#define TIMING_WRITE3 (10)
+
+STATIC int onewire_bus_reset(mp_hal_pin_obj_t pin) {
+ mp_hal_pin_write(pin, 0);
+ mp_hal_delay_us(TIMING_RESET1);
+ uint32_t i = mp_hal_quiet_timing_enter();
+ mp_hal_pin_write(pin, 1);
+ mp_hal_delay_us_fast(TIMING_RESET2);
+ int status = !mp_hal_pin_read(pin);
+ mp_hal_quiet_timing_exit(i);
+ mp_hal_delay_us(TIMING_RESET3);
+ return status;
+}
+
+STATIC int onewire_bus_readbit(mp_hal_pin_obj_t pin) {
+ mp_hal_pin_write(pin, 1);
+ uint32_t i = mp_hal_quiet_timing_enter();
+ mp_hal_pin_write(pin, 0);
+ mp_hal_delay_us_fast(TIMING_READ1);
+ mp_hal_pin_write(pin, 1);
+ mp_hal_delay_us_fast(TIMING_READ2);
+ int value = mp_hal_pin_read(pin);
+ mp_hal_quiet_timing_exit(i);
+ mp_hal_delay_us_fast(TIMING_READ3);
+ return value;
+}
+
+STATIC void onewire_bus_writebit(mp_hal_pin_obj_t pin, int value) {
+ uint32_t i = mp_hal_quiet_timing_enter();
+ mp_hal_pin_write(pin, 0);
+ mp_hal_delay_us_fast(TIMING_WRITE1);
+ if (value) {
+ mp_hal_pin_write(pin, 1);
+ }
+ mp_hal_delay_us_fast(TIMING_WRITE2);
+ mp_hal_pin_write(pin, 1);
+ mp_hal_delay_us_fast(TIMING_WRITE3);
+ mp_hal_quiet_timing_exit(i);
+}
+
+/******************************************************************************/
+// MicroPython bindings
+
+STATIC mp_obj_t onewire_reset(mp_obj_t pin_in) {
+ return mp_obj_new_bool(onewire_bus_reset(mp_hal_get_pin_obj(pin_in)));
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_reset_obj, onewire_reset);
+
+STATIC mp_obj_t onewire_readbit(mp_obj_t pin_in) {
+ return MP_OBJ_NEW_SMALL_INT(onewire_bus_readbit(mp_hal_get_pin_obj(pin_in)));
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbit_obj, onewire_readbit);
+
+STATIC mp_obj_t onewire_readbyte(mp_obj_t pin_in) {
+ mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(pin_in);
+ uint8_t value = 0;
+ for (int i = 0; i < 8; ++i) {
+ value |= onewire_bus_readbit(pin) << i;
+ }
+ return MP_OBJ_NEW_SMALL_INT(value);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbyte_obj, onewire_readbyte);
+
+STATIC mp_obj_t onewire_writebit(mp_obj_t pin_in, mp_obj_t value_in) {
+ onewire_bus_writebit(mp_hal_get_pin_obj(pin_in), mp_obj_get_int(value_in));
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebit_obj, onewire_writebit);
+
+STATIC mp_obj_t onewire_writebyte(mp_obj_t pin_in, mp_obj_t value_in) {
+ mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(pin_in);
+ int value = mp_obj_get_int(value_in);
+ for (int i = 0; i < 8; ++i) {
+ onewire_bus_writebit(pin, value & 1);
+ value >>= 1;
+ }
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebyte_obj, onewire_writebyte);
+
+STATIC mp_obj_t onewire_crc8(mp_obj_t data) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
+ uint8_t crc = 0;
+ for (size_t i = 0; i < bufinfo.len; ++i) {
+ uint8_t byte = ((uint8_t*)bufinfo.buf)[i];
+ for (int b = 0; b < 8; ++b) {
+ uint8_t fb_bit = (crc ^ byte) & 0x01;
+ if (fb_bit == 0x01) {
+ crc = crc ^ 0x18;
+ }
+ crc = (crc >> 1) & 0x7f;
+ if (fb_bit == 0x01) {
+ crc = crc | 0x80;
+ }
+ byte = byte >> 1;
+ }
+ }
+ return MP_OBJ_NEW_SMALL_INT(crc);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_crc8_obj, onewire_crc8);
+
+STATIC const mp_rom_map_elem_t onewire_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewire) },
+
+ { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&onewire_reset_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readbit), MP_ROM_PTR(&onewire_readbit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readbyte), MP_ROM_PTR(&onewire_readbyte_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writebit), MP_ROM_PTR(&onewire_writebit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writebyte), MP_ROM_PTR(&onewire_writebyte_obj) },
+ { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR(&onewire_crc8_obj) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table);
+
+const mp_obj_module_t mp_module_onewire = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&onewire_module_globals,
+};
diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c
index 2ef1a6f21..d79191b3e 100644
--- a/extmod/modubinascii.c
+++ b/extmod/modubinascii.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -42,6 +42,12 @@ mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
+ // Code below assumes non-zero buffer length when computing size with
+ // separator, so handle the zero-length case here.
+ if (bufinfo.len == 0) {
+ return mp_const_empty_bytes;
+ }
+
vstr_t vstr;
size_t out_len = bufinfo.len * 2;
if (n_args > 1) {
@@ -75,7 +81,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
if ((bufinfo.len & 1) != 0) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "odd-length string"));
+ mp_raise_ValueError("odd-length string");
}
vstr_t vstr;
vstr_init_len(&vstr, bufinfo.len / 2);
@@ -86,7 +92,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
if (unichar_isxdigit(hex_ch)) {
hex_byte += unichar_xdigit_value(hex_ch);
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "non-hex digit found"));
+ mp_raise_ValueError("non-hex digit found");
}
if (i & 1) {
hex_byte <<= 4;
@@ -112,7 +118,7 @@ mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
vstr_init_len(&vstr, 0);
}
else {
- vstr_init_len(&vstr, ((bufinfo.len / 4) * 3) - ((in[bufinfo.len-1] == '=') ? ((in[bufinfo.len-2] == '=') ? 2 : 1 ) : 0));
+ vstr_init_len(&vstr, ((bufinfo.len / 4) * 3) - ((in[bufinfo.len-1] == '=') ? ((in[bufinfo.len-2] == '=') ? 2 : 1 ) : 0));
}
byte *out = (byte*)vstr.buf;
for (mp_uint_t i = bufinfo.len; i; i -= 4) {
diff --git a/extmod/modubinascii.h b/extmod/modubinascii.h
index 33d0f1cbd..fb3169267 100644
--- a/extmod/modubinascii.h
+++ b/extmod/modubinascii.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-#ifndef MICROPY_EXTMOD_MODUBINASCII
-#define MICROPY_EXTMOD_MODUBINASCII
+#ifndef MICROPY_INCLUDED_EXTMOD_MODUBINASCII_H
+#define MICROPY_INCLUDED_EXTMOD_MODUBINASCII_H
extern mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args);
extern mp_obj_t mod_binascii_unhexlify(mp_obj_t data);
@@ -39,4 +38,4 @@ MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj);
MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj);
-#endif /* MICROPY_EXTMOD_MODUBINASCII */
+#endif // MICROPY_INCLUDED_EXTMOD_MODUBINASCII_H
diff --git a/extmod/moductypes.c b/extmod/moductypes.c
index d2d2e85de..c2d226562 100644
--- a/extmod/moductypes.c
+++ b/extmod/moductypes.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -281,13 +281,13 @@ STATIC mp_obj_t uctypes_struct_sizeof(mp_obj_t obj_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_sizeof_obj, uctypes_struct_sizeof);
-STATIC inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) {
+static inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) {
char struct_type = big_endian ? '>' : '<';
static const char type2char[16] = "BbHhIiQq------fd";
return mp_binary_get_val(struct_type, type2char[val_type], &p);
}
-STATIC inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) {
+static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) {
char struct_type = big_endian ? '>' : '<';
static const char type2char[16] = "BbHhIiQq------fd";
mp_binary_set_val(struct_type, type2char[val_type], val, &p);
diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c
index 13525cc3f..f3beb3939 100644
--- a/extmod/moduhashlib.c
+++ b/extmod/moduhashlib.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c
index 567ee83da..e6e417d2b 100644
--- a/extmod/moduheapq.c
+++ b/extmod/moduheapq.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/extmod/modujson.c b/extmod/modujson.c
index bb2d45274..f94ec7db8 100644
--- a/extmod/modujson.c
+++ b/extmod/modujson.c
@@ -277,7 +277,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
size_t len;
const char *buf = mp_obj_str_get_data(obj, &len);
vstr_t vstr = {len, len, (char*)buf, true};
- mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0};
+ mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL};
return mod_ujson_load(MP_OBJ_FROM_PTR(&sio));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads);
diff --git a/extmod/modure.c b/extmod/modure.c
index 7be091cc0..b85ba2673 100644
--- a/extmod/modure.c
+++ b/extmod/modure.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -31,6 +31,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
+#include "py/objstr.h"
#if MICROPY_PY_URE
@@ -69,7 +70,8 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
// no match for this group
return mp_const_none;
}
- return mp_obj_new_str(start, self->caps[no * 2 + 1] - start, false);
+ return mp_obj_new_str_of_type(mp_obj_get_type(self->str),
+ (const byte*)start, self->caps[no * 2 + 1] - start);
}
MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group);
@@ -129,6 +131,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]);
Subject subj;
size_t len;
+ const mp_obj_type_t *str_type = mp_obj_get_type(args[1]);
subj.begin = mp_obj_str_get_data(args[1], &len);
subj.end = subj.begin + len;
int caps_num = (self->re.sub + 1) * 2;
@@ -150,7 +153,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
break;
}
- mp_obj_t s = mp_obj_new_str(subj.begin, caps[0] - subj.begin, false);
+ mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, caps[0] - subj.begin);
mp_obj_list_append(retval, s);
if (self->re.sub > 0) {
mp_not_implemented("Splitting with sub-captures");
@@ -161,7 +164,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
}
}
- mp_obj_t s = mp_obj_new_str(subj.begin, subj.end - subj.begin, false);
+ mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, subj.end - subj.begin);
mp_obj_list_append(retval, s);
return retval;
}
diff --git a/extmod/moduselect.c b/extmod/moduselect.c
index 88dd29a49..a9f25c195 100644
--- a/extmod/moduselect.c
+++ b/extmod/moduselect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -362,10 +362,10 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) },
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) },
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) },
- { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_RD) },
- { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_WR) },
- { MP_ROM_QSTR(MP_QSTR_POLLERR), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_ERR) },
- { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_HUP) },
+ { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(MP_STREAM_POLL_RD) },
+ { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(MP_STREAM_POLL_WR) },
+ { MP_ROM_QSTR(MP_QSTR_POLLERR), MP_ROM_INT(MP_STREAM_POLL_ERR) },
+ { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_ROM_INT(MP_STREAM_POLL_HUP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table);
diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c
index 416915821..86dd8e29c 100644
--- a/extmod/modussl_axtls.c
+++ b/extmod/modussl_axtls.c
@@ -1,9 +1,9 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
- * Copyright (c) 2015 Paul Sokolovsky
+ * Copyright (c) 2015-2017 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include "py/nlr.h"
#include "py/runtime.h"
@@ -45,9 +44,14 @@ typedef struct _mp_obj_ssl_socket_t {
uint32_t bytes_left;
} mp_obj_ssl_socket_t;
+struct ssl_args {
+ mp_arg_val_t server_side;
+ mp_arg_val_t server_hostname;
+};
+
STATIC const mp_obj_type_t ussl_socket_type;
-STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, bool server_side) {
+STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
o->base.type = &ussl_socket_type;
o->buf = NULL;
@@ -59,18 +63,30 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, bool server_side) {
mp_raise_OSError(MP_EINVAL);
}
- if (server_side) {
+ if (args->server_side.u_bool) {
o->ssl_sock = ssl_server_new(o->ssl_ctx, (long)sock);
} else {
- o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0);
+ SSL_EXTENSIONS *ext = ssl_ext_new();
+
+ if (args->server_hostname.u_obj != mp_const_none) {
+ ext->host_name = (char*)mp_obj_str_get_str(args->server_hostname.u_obj);
+ }
+
+ o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
- int res;
- /* check the return status */
- if ((res = ssl_handshake_status(o->ssl_sock)) != SSL_OK) {
+ int res = ssl_handshake_status(o->ssl_sock);
+ // Pointer to SSL_EXTENSIONS as being passed to ssl_client_new()
+ // is saved in ssl_sock->extensions.
+ // As of axTLS 2.1.3, extensions aren't used beyond the initial
+ // handshake, and that's pretty much how it's expected to be. So
+ // we allocate them on stack and reset the pointer after handshake.
+
+ if (res != SSL_OK) {
printf("ssl_handshake_status: %d\n", res);
ssl_display_error(res);
mp_raise_OSError(MP_EIO);
}
+
}
return o;
@@ -85,6 +101,11 @@ STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin
STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
+ if (o->ssl_sock == NULL) {
+ *errcode = EBADF;
+ return MP_STREAM_ERROR;
+ }
+
while (o->bytes_left == 0) {
mp_int_t r = ssl_read(o->ssl_sock, &o->buf);
if (r == SSL_OK) {
@@ -114,6 +135,12 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
+
+ if (o->ssl_sock == NULL) {
+ *errcode = EBADF;
+ return MP_STREAM_ERROR;
+ }
+
mp_int_t r = ssl_write(o->ssl_sock, buf, size);
if (r < 0) {
*errcode = r;
@@ -134,9 +161,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
STATIC mp_obj_t socket_close(mp_obj_t self_in) {
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in);
- ssl_free(self->ssl_sock);
- ssl_ctx_free(self->ssl_ctx);
- return mp_stream_close(self->sock);
+ if (self->ssl_sock != NULL) {
+ ssl_free(self->ssl_sock);
+ ssl_ctx_free(self->ssl_ctx);
+ self->ssl_sock = NULL;
+ return mp_stream_close(self->sock);
+ }
+
+ return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
@@ -171,18 +203,17 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
// TODO: Implement more args
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
+ { MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
};
// TODO: Check that sock implements stream protocol
mp_obj_t sock = pos_args[0];
- struct {
- mp_arg_val_t server_side;
- } args;
+ struct ssl_args args;
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
- return MP_OBJ_FROM_PTR(socket_new(sock, args.server_side.u_bool));
+ return MP_OBJ_FROM_PTR(socket_new(sock, &args));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket);
diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c
index 40dd8c049..597eaee73 100644
--- a/extmod/modussl_mbedtls.c
+++ b/extmod/modussl_mbedtls.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include <string.h>
-#include <errno.h>
+#include <errno.h> // needed because mp_is_nonblocking_error uses system error codes
#include "py/nlr.h"
#include "py/runtime.h"
@@ -84,6 +84,9 @@ int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
int out_sz = sock_stream->write(sock, buf, len, &err);
if (out_sz == MP_STREAM_ERROR) {
+ if (mp_is_nonblocking_error(err)) {
+ return MBEDTLS_ERR_SSL_WANT_WRITE;
+ }
return -err;
} else {
return out_sz;
@@ -98,6 +101,9 @@ int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
int out_sz = sock_stream->read(sock, buf, len, &err);
if (out_sz == MP_STREAM_ERROR) {
+ if (mp_is_nonblocking_error(err)) {
+ return MBEDTLS_ERR_SSL_WANT_READ;
+ }
return -err;
} else {
return out_sz;
@@ -128,7 +134,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
}
ret = mbedtls_ssl_config_defaults(&o->conf,
- MBEDTLS_SSL_IS_CLIENT,
+ args->server_side.u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT);
if (ret != 0) {
@@ -172,15 +178,11 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
assert(ret == 0);
}
- if (args->server_side.u_bool) {
- assert(0);
- } else {
- while ((ret = mbedtls_ssl_handshake(&o->ssl)) != 0) {
- if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
- //assert(0);
- printf("mbedtls_ssl_handshake error: -%x\n", -ret);
- mp_raise_OSError(MP_EIO);
- }
+ while ((ret = mbedtls_ssl_handshake(&o->ssl)) != 0) {
+ if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
+ //assert(0);
+ printf("mbedtls_ssl_handshake error: -%x\n", -ret);
+ mp_raise_OSError(MP_EIO);
}
}
@@ -197,9 +199,16 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
int ret = mbedtls_ssl_read(&o->ssl, buf, size);
+ if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
+ // end of stream
+ return 0;
+ }
if (ret >= 0) {
return ret;
}
+ if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
+ ret = MP_EWOULDBLOCK;
+ }
*errcode = ret;
return MP_STREAM_ERROR;
}
@@ -211,32 +220,35 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
if (ret >= 0) {
return ret;
}
+ if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
+ ret = MP_EWOULDBLOCK;
+ }
*errcode = ret;
return MP_STREAM_ERROR;
}
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
- // Currently supports only blocking mode
- (void)self_in;
- if (!mp_obj_is_true(flag_in)) {
- mp_not_implemented("");
- }
- return mp_const_none;
+ mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in);
+ mp_obj_t sock = o->sock;
+ mp_obj_t dest[3];
+ mp_load_method(sock, MP_QSTR_setblocking, dest);
+ dest[2] = flag_in;
+ return mp_call_method_n_kw(1, 0, dest);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
STATIC mp_obj_t socket_close(mp_obj_t self_in) {
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in);
+ mbedtls_pk_free(&self->pkey);
+ mbedtls_x509_crt_free(&self->cert);
mbedtls_x509_crt_free(&self->cacert);
mbedtls_ssl_free(&self->ssl);
mbedtls_ssl_config_free(&self->conf);
mbedtls_ctr_drbg_free(&self->ctr_drbg);
mbedtls_entropy_free(&self->entropy);
- mp_obj_t dest[2];
- mp_load_method(self->sock, MP_QSTR_close, dest);
- return mp_call_method_n_kw(0, 0, dest);
+ return mp_stream_close(self->sock);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c
index a91405a93..a05d0f2ed 100644
--- a/extmod/moduzlib.c
+++ b/extmod/moduzlib.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -143,7 +143,6 @@ STATIC const mp_obj_type_t decompio_type = {
};
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
- (void)n_args;
mp_obj_t data = args[0];
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c
index ce3c7dcbd..d618f5370 100644
--- a/extmod/modwebrepl.c
+++ b/extmod/modwebrepl.c
@@ -27,7 +27,6 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
-#include <errno.h>
#include "py/nlr.h"
#include "py/obj.h"
@@ -318,11 +317,11 @@ STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password);
-STATIC const mp_map_elem_t webrepl_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&webrepl_close_obj },
+STATIC const mp_rom_map_elem_t webrepl_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&webrepl_close_obj) },
};
STATIC MP_DEFINE_CONST_DICT(webrepl_locals_dict, webrepl_locals_dict_table);
@@ -336,13 +335,13 @@ STATIC const mp_obj_type_t webrepl_type = {
.name = MP_QSTR__webrepl,
.make_new = webrepl_make_new,
.protocol = &webrepl_stream_p,
- .locals_dict = (mp_obj_t)&webrepl_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&webrepl_locals_dict,
};
-STATIC const mp_map_elem_t webrepl_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__webrepl) },
- { MP_OBJ_NEW_QSTR(MP_QSTR__webrepl), (mp_obj_t)&webrepl_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_password), (mp_obj_t)&webrepl_set_password_obj },
+STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__webrepl) },
+ { MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&webrepl_type) },
+ { MP_ROM_QSTR(MP_QSTR_password), MP_ROM_PTR(&webrepl_set_password_obj) },
};
STATIC MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table);
diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c
index 9e17d6a6d..6c6e32c1a 100644
--- a/extmod/modwebsocket.c
+++ b/extmod/modwebsocket.c
@@ -27,7 +27,6 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
-#include <errno.h>
#include "py/nlr.h"
#include "py/obj.h"
@@ -88,7 +87,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
self->buf_pos += out_sz;
self->to_recv -= out_sz;
if (self->to_recv != 0) {
- *errcode = EAGAIN;
+ *errcode = MP_EAGAIN;
return MP_STREAM_ERROR;
}
}
@@ -267,7 +266,7 @@ STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t
return cur;
}
default:
- *errcode = EINVAL;
+ *errcode = MP_EINVAL;
return MP_STREAM_ERROR;
}
}
diff --git a/extmod/modwebsocket.h b/extmod/modwebsocket.h
index 7da147561..2720147df 100644
--- a/extmod/modwebsocket.h
+++ b/extmod/modwebsocket.h
@@ -1,5 +1,10 @@
+#ifndef MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
+#define MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
+
#define FRAME_OPCODE_MASK 0x0f
enum {
FRAME_CONT, FRAME_TXT, FRAME_BIN,
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
};
+
+#endif // MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c
index d888099df..29a62ab89 100644
--- a/extmod/uos_dupterm.c
+++ b/extmod/uos_dupterm.c
@@ -24,7 +24,6 @@
* THE SOFTWARE.
*/
-#include <errno.h>
#include <string.h>
#include "py/mpconfig.h"
diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c
index e99ba46ce..0fe3a3ba1 100644
--- a/extmod/utime_mphal.c
+++ b/extmod/utime_mphal.c
@@ -38,7 +38,7 @@
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
#if MICROPY_PY_BUILTINS_FLOAT
- mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
+ mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o)));
#else
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
#endif
diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h
index 644387b67..88a9ed4d3 100644
--- a/extmod/utime_mphal.h
+++ b/extmod/utime_mphal.h
@@ -24,6 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H
+#define MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H
#include "py/obj.h"
@@ -35,3 +37,5 @@ MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj);
MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj);
MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj);
MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj);
+
+#endif // MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H
diff --git a/extmod/vfs.h b/extmod/vfs.h
index edaeb5349..f2efdbe79 100644
--- a/extmod/vfs.h
+++ b/extmod/vfs.h
@@ -23,7 +23,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
#ifndef MICROPY_INCLUDED_EXTMOD_VFS_H
#define MICROPY_INCLUDED_EXTMOD_VFS_H
diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h
index 6c7c05a9a..443e4eda8 100644
--- a/extmod/vfs_fat.h
+++ b/extmod/vfs_fat.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -23,6 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_EXTMOD_VFS_FAT_H
+#define MICROPY_INCLUDED_EXTMOD_VFS_FAT_H
#include "py/lexer.h"
#include "py/obj.h"
@@ -58,3 +60,5 @@ mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode)
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj);
mp_obj_t fat_vfs_ilistdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type);
+
+#endif // MICROPY_INCLUDED_EXTMOD_VFS_FAT_H
diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c
index 24c00ffba..ff23c6b0c 100644
--- a/extmod/vfs_fat_diskio.c
+++ b/extmod/vfs_fat_diskio.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* Original template for this file comes from:
* Low level disk I/O module skeleton for FatFs, (C)ChaN, 2013
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index edffa37c7..8fb48f01a 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#if MICROPY_VFS && MICROPY_VFS_FAT
#include <stdio.h>
-#include <errno.h>
#include "py/nlr.h"
#include "py/runtime.h"
diff --git a/extmod/virtpin.h b/extmod/virtpin.h
index 041010350..706affc19 100644
--- a/extmod/virtpin.h
+++ b/extmod/virtpin.h
@@ -23,6 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_EXTMOD_VIRTPIN_H
+#define MICROPY_INCLUDED_EXTMOD_VIRTPIN_H
#include "py/obj.h"
@@ -41,3 +43,5 @@ void mp_virtual_pin_write(mp_obj_t pin, int value);
// If a port exposes a Pin object, it's constructor should be like this
mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
+
+#endif // MICROPY_INCLUDED_EXTMOD_VIRTPIN_H