Skip to content

Commit 06168c9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into esp32
2 parents 96de4d1 + 6b4d4a2 commit 06168c9

File tree

17 files changed

+71
-49
lines changed

17 files changed

+71
-49
lines changed

cc3200/mods/pybuart.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include <stdint.h>
2929
#include <stdio.h>
30-
#include <errno.h>
3130
#include <string.h>
3231

3332
#include "py/mpconfig.h"

extmod/modbtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <stdio.h>
2828
#include <string.h>
29-
#include <errno.h>
29+
#include <errno.h> // for declaration of global errno variable
3030
#include <fcntl.h>
3131

3232
#include "py/nlr.h"

extmod/modframebuf.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ typedef struct _mp_framebuf_p_t {
6262

6363
// Functions for MHLSB and MHMSB
6464

65-
STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
65+
STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
6666
size_t index = (x + y * fb->stride) >> 3;
6767
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
68-
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset);
68+
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
6969
}
7070

7171
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
9090

9191
// Functions for MVLSB format
9292

93-
STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
93+
STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
9494
size_t index = (y >> 3) * fb->stride + x;
9595
uint8_t offset = y & 0x07;
96-
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset);
96+
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
9797
}
9898

9999
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
114114

115115
// Functions for RGB565 format
116116

117-
STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
118-
((uint16_t*)fb->buf)[x + y * fb->stride] = color;
117+
STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
118+
((uint16_t*)fb->buf)[x + y * fb->stride] = col;
119119
}
120120

121121
STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
122122
return ((uint16_t*)fb->buf)[x + y * fb->stride];
123123
}
124124

125-
STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t colour) {
125+
STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
126126
uint16_t *b = &((uint16_t*)fb->buf)[x + y * fb->stride];
127127
while (h--) {
128128
for (int ww = w; ww; --ww) {
129-
*b++ = colour;
129+
*b++ = col;
130130
}
131131
b += fb->stride - w;
132132
}
@@ -156,7 +156,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
156156
col &= 0x0f;
157157
uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
158158
uint8_t col_shifted_left = col << 4;
159-
uint8_t colored_pixel_pair = col_shifted_left | col;
159+
uint8_t col_pixel_pair = col_shifted_left | col;
160160
int pixel_count_till_next_line = (fb->stride - w) >> 1;
161161
bool odd_x = (x % 2 == 1);
162162

@@ -169,7 +169,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
169169
ww--;
170170
}
171171

172-
memset(pixel_pair, colored_pixel_pair, ww >> 1);
172+
memset(pixel_pair, col_pixel_pair, ww >> 1);
173173
pixel_pair += ww >> 1;
174174

175175
if (ww % 2) {
@@ -191,8 +191,8 @@ STATIC mp_framebuf_p_t formats[] = {
191191
[FRAMEBUF_MHMSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect},
192192
};
193193

194-
static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) {
195-
formats[fb->format].setpixel(fb, x, y, color);
194+
static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
195+
formats[fb->format].setpixel(fb, x, y, col);
196196
}
197197

198198
static inline uint32_t getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
@@ -237,12 +237,14 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
237237
switch (o->format) {
238238
case FRAMEBUF_MVLSB:
239239
case FRAMEBUF_RGB565:
240-
case FRAMEBUF_GS4_HMSB:
241240
break;
242241
case FRAMEBUF_MHLSB:
243242
case FRAMEBUF_MHMSB:
244243
o->stride = (o->stride + 7) & ~7;
245244
break;
245+
case FRAMEBUF_GS4_HMSB:
246+
o->stride = (o->stride + 1) & ~1;
247+
break;
246248
default:
247249
mp_raise_ValueError("invalid format");
248250
}
@@ -275,9 +277,9 @@ STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) {
275277
mp_int_t y = mp_obj_get_int(args[2]);
276278
mp_int_t width = mp_obj_get_int(args[3]);
277279
mp_int_t height = mp_obj_get_int(args[4]);
278-
mp_int_t color = mp_obj_get_int(args[5]);
280+
mp_int_t col = mp_obj_get_int(args[5]);
279281

280-
fill_rect(self, x, y, width, height, color);
282+
fill_rect(self, x, y, width, height, col);
281283

282284
return mp_const_none;
283285
}
@@ -442,14 +444,13 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
442444
int y1 = MAX(0, -y);
443445
int x0end = MIN(self->width, x + source->width);
444446
int y0end = MIN(self->height, y + source->height);
445-
uint32_t color;
446447

447448
for (; y0 < y0end; ++y0) {
448449
int cx1 = x1;
449450
for (int cx0 = x0; cx0 < x0end; ++cx0) {
450-
color = getpixel(source, cx1, y1);
451-
if (color != (uint32_t)key) {
452-
setpixel(self, cx0, y0, color);
451+
uint32_t col = getpixel(source, cx1, y1);
452+
if (col != (uint32_t)key) {
453+
setpixel(self, cx0, y0, col);
453454
}
454455
++cx1;
455456
}

extmod/modussl_axtls.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <stdio.h>
2828
#include <string.h>
29-
#include <errno.h>
3029

3130
#include "py/nlr.h"
3231
#include "py/runtime.h"

extmod/modussl_mbedtls.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include <stdio.h>
3131
#include <string.h>
32-
#include <errno.h>
32+
#include <errno.h> // needed because mp_is_nonblocking_error uses system error codes
3333

3434
#include "py/nlr.h"
3535
#include "py/runtime.h"
@@ -84,6 +84,9 @@ int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
8484

8585
int out_sz = sock_stream->write(sock, buf, len, &err);
8686
if (out_sz == MP_STREAM_ERROR) {
87+
if (mp_is_nonblocking_error(err)) {
88+
return MBEDTLS_ERR_SSL_WANT_WRITE;
89+
}
8790
return -err;
8891
} else {
8992
return out_sz;
@@ -98,6 +101,9 @@ int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
98101

99102
int out_sz = sock_stream->read(sock, buf, len, &err);
100103
if (out_sz == MP_STREAM_ERROR) {
104+
if (mp_is_nonblocking_error(err)) {
105+
return MBEDTLS_ERR_SSL_WANT_READ;
106+
}
101107
return -err;
102108
} else {
103109
return out_sz;
@@ -200,6 +206,9 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
200206
if (ret >= 0) {
201207
return ret;
202208
}
209+
if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
210+
ret = MP_EWOULDBLOCK;
211+
}
203212
*errcode = ret;
204213
return MP_STREAM_ERROR;
205214
}
@@ -211,32 +220,35 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
211220
if (ret >= 0) {
212221
return ret;
213222
}
223+
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
224+
ret = MP_EWOULDBLOCK;
225+
}
214226
*errcode = ret;
215227
return MP_STREAM_ERROR;
216228
}
217229

218230
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
219-
// Currently supports only blocking mode
220-
(void)self_in;
221-
if (!mp_obj_is_true(flag_in)) {
222-
mp_not_implemented("");
223-
}
224-
return mp_const_none;
231+
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in);
232+
mp_obj_t sock = o->sock;
233+
mp_obj_t dest[3];
234+
mp_load_method(sock, MP_QSTR_setblocking, dest);
235+
dest[2] = flag_in;
236+
return mp_call_method_n_kw(1, 0, dest);
225237
}
226238
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
227239

228240
STATIC mp_obj_t socket_close(mp_obj_t self_in) {
229241
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in);
230242

243+
mbedtls_pk_free(&self->pkey);
244+
mbedtls_x509_crt_free(&self->cert);
231245
mbedtls_x509_crt_free(&self->cacert);
232246
mbedtls_ssl_free(&self->ssl);
233247
mbedtls_ssl_config_free(&self->conf);
234248
mbedtls_ctr_drbg_free(&self->ctr_drbg);
235249
mbedtls_entropy_free(&self->entropy);
236250

237-
mp_obj_t dest[2];
238-
mp_load_method(self->sock, MP_QSTR_close, dest);
239-
return mp_call_method_n_kw(0, 0, dest);
251+
return mp_stream_close(self->sock);
240252
}
241253
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
242254

extmod/modwebrepl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <stdio.h>
2828
#include <stdint.h>
2929
#include <string.h>
30-
#include <errno.h>
3130

3231
#include "py/nlr.h"
3332
#include "py/obj.h"

extmod/modwebsocket.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <stdio.h>
2828
#include <stdint.h>
2929
#include <string.h>
30-
#include <errno.h>
3130

3231
#include "py/nlr.h"
3332
#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
8887
self->buf_pos += out_sz;
8988
self->to_recv -= out_sz;
9089
if (self->to_recv != 0) {
91-
*errcode = EAGAIN;
90+
*errcode = MP_EAGAIN;
9291
return MP_STREAM_ERROR;
9392
}
9493
}
@@ -267,7 +266,7 @@ STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t
267266
return cur;
268267
}
269268
default:
270-
*errcode = EINVAL;
269+
*errcode = MP_EINVAL;
271270
return MP_STREAM_ERROR;
272271
}
273272
}

extmod/uos_dupterm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include <errno.h>
2827
#include <string.h>
2928
#include "py/mpconfig.h"
3029

extmod/vfs_fat_file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#if MICROPY_VFS && MICROPY_VFS_FAT
2929

3030
#include <stdio.h>
31-
#include <errno.h>
3231

3332
#include "py/nlr.h"
3433
#include "py/runtime.h"

mpy-cross/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <string.h>
2929
#include <stdlib.h>
3030
#include <unistd.h>
31-
#include <errno.h>
3231

3332
#include "py/mpstate.h"
3433
#include "py/compile.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy