codeformat
This commit is contained in:
parent
3e25d611ef
commit
b057fb8a4b
@ -71,9 +71,15 @@ STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
|
||||
uintptr_t addr = MICROPY_MACHINE_MEM_GET_READ_ADDR(index, self->elem_size);
|
||||
uint32_t val;
|
||||
switch (self->elem_size) {
|
||||
case 1: val = (*(uint8_t*)addr); break;
|
||||
case 2: val = (*(uint16_t*)addr); break;
|
||||
default: val = (*(uint32_t*)addr); break;
|
||||
case 1:
|
||||
val = (*(uint8_t *)addr);
|
||||
break;
|
||||
case 2:
|
||||
val = (*(uint16_t *)addr);
|
||||
break;
|
||||
default:
|
||||
val = (*(uint32_t *)addr);
|
||||
break;
|
||||
}
|
||||
return mp_obj_new_int(val);
|
||||
} else {
|
||||
@ -81,9 +87,15 @@ STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
|
||||
uintptr_t addr = MICROPY_MACHINE_MEM_GET_WRITE_ADDR(index, self->elem_size);
|
||||
uint32_t val = mp_obj_get_int_truncated(value);
|
||||
switch (self->elem_size) {
|
||||
case 1: (*(uint8_t*)addr) = val; break;
|
||||
case 2: (*(uint16_t*)addr) = val; break;
|
||||
default: (*(uint32_t*)addr) = val; break;
|
||||
case 1:
|
||||
(*(uint8_t *)addr) = val;
|
||||
break;
|
||||
case 2:
|
||||
(*(uint16_t *)addr) = val;
|
||||
break;
|
||||
default:
|
||||
(*(uint32_t *)addr) = val;
|
||||
break;
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -90,8 +90,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||
pin = MICROPY_PY_MACHINE_PIN_MAKE_NEW(NULL, n_args, n_kw, pin_args);
|
||||
|
||||
mp_local_free(pin_args);
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
// Otherwise there should be 1 or 2 args
|
||||
{
|
||||
|
@ -432,9 +432,15 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
|
||||
bool steep;
|
||||
if (dy > dx) {
|
||||
mp_int_t temp;
|
||||
temp = x1; x1 = y1; y1 = temp;
|
||||
temp = dx; dx = dy; dy = temp;
|
||||
temp = sx; sx = sy; sy = temp;
|
||||
temp = x1;
|
||||
x1 = y1;
|
||||
y1 = temp;
|
||||
temp = dx;
|
||||
dx = dy;
|
||||
dy = temp;
|
||||
temp = sx;
|
||||
sx = sy;
|
||||
sy = temp;
|
||||
steep = true;
|
||||
} else {
|
||||
steep = false;
|
||||
|
@ -367,8 +367,7 @@ STATIC err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pb
|
||||
// "Poll" (idle) callback to be called ASAP after accept callback
|
||||
// to execute Python callback function, as it can't be executed
|
||||
// from accept callback itself.
|
||||
STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
||||
{
|
||||
STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb) {
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||
tcp_poll(pcb, NULL, 0);
|
||||
exec_user_callback(socket);
|
||||
@ -482,7 +481,9 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
||||
if (socket->timeout != -1) {
|
||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||
mp_hal_delay_ms(100);
|
||||
if (socket->incoming.pbuf != NULL) break;
|
||||
if (socket->incoming.pbuf != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (socket->incoming.pbuf == NULL) {
|
||||
*_errno = MP_ETIMEDOUT;
|
||||
@ -671,7 +672,8 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
socket->incoming.pbuf = NULL;
|
||||
break;
|
||||
// case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
|
||||
default: mp_raise_OSError(MP_EINVAL);
|
||||
default:
|
||||
mp_raise_OSError(MP_EINVAL);
|
||||
}
|
||||
|
||||
if (socket->pcb.tcp == NULL) {
|
||||
@ -794,7 +796,9 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
||||
} else if (socket->timeout != -1) {
|
||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||
mp_hal_delay_ms(100);
|
||||
if (*incoming_connection != NULL) break;
|
||||
if (*incoming_connection != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*incoming_connection == NULL) {
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
@ -881,7 +885,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
if (socket->timeout != -1) {
|
||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||
mp_hal_delay_ms(100);
|
||||
if (socket->state != STATE_CONNECTING) break;
|
||||
if (socket->state != STATE_CONNECTING) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (socket->state == STATE_CONNECTING) {
|
||||
mp_raise_OSError(MP_EINPROGRESS);
|
||||
@ -1274,7 +1280,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MOD_NETWORK_SOCK_DGRAM: udp_remove(socket->pcb.udp); break;
|
||||
case MOD_NETWORK_SOCK_DGRAM:
|
||||
udp_remove(socket->pcb.udp);
|
||||
break;
|
||||
// case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
|
||||
}
|
||||
socket->pcb.tcp = NULL;
|
||||
|
@ -186,8 +186,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
||||
if (i == 2) {
|
||||
*out++ = (in[0] & 0x03) << 4 | (in[1] & 0xF0) >> 4;
|
||||
*out++ = (in[1] & 0x0F) << 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*out++ = (in[0] & 0x03) << 4;
|
||||
*out++ = 64;
|
||||
}
|
||||
|
@ -148,8 +148,12 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
switch (agg_type) {
|
||||
case PTR: typen = "PTR"; break;
|
||||
case ARRAY: typen = "ARRAY"; break;
|
||||
case PTR:
|
||||
typen = "PTR";
|
||||
break;
|
||||
case ARRAY:
|
||||
typen = "ARRAY";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
typen = "ERROR";
|
||||
@ -324,11 +328,14 @@ static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
|
||||
static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
|
||||
switch (val_type) {
|
||||
case UINT8:
|
||||
*(uint8_t*)p = (uint8_t)v; return;
|
||||
*(uint8_t *)p = (uint8_t)v;
|
||||
return;
|
||||
case UINT16:
|
||||
*(uint16_t*)p = (uint16_t)v; return;
|
||||
*(uint16_t *)p = (uint16_t)v;
|
||||
return;
|
||||
case UINT32:
|
||||
*(uint32_t*)p = (uint32_t)v; return;
|
||||
*(uint32_t *)p = (uint32_t)v;
|
||||
return;
|
||||
}
|
||||
assert(0);
|
||||
}
|
||||
@ -378,17 +385,23 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
|
||||
mp_int_t v = mp_obj_get_int_truncated(val);
|
||||
switch (val_type) {
|
||||
case UINT8:
|
||||
((uint8_t*)p)[index] = (uint8_t)v; return;
|
||||
((uint8_t *)p)[index] = (uint8_t)v;
|
||||
return;
|
||||
case INT8:
|
||||
((int8_t*)p)[index] = (int8_t)v; return;
|
||||
((int8_t *)p)[index] = (int8_t)v;
|
||||
return;
|
||||
case UINT16:
|
||||
((uint16_t*)p)[index] = (uint16_t)v; return;
|
||||
((uint16_t *)p)[index] = (uint16_t)v;
|
||||
return;
|
||||
case INT16:
|
||||
((int16_t*)p)[index] = (int16_t)v; return;
|
||||
((int16_t *)p)[index] = (int16_t)v;
|
||||
return;
|
||||
case UINT32:
|
||||
((uint32_t*)p)[index] = (uint32_t)v; return;
|
||||
((uint32_t *)p)[index] = (uint32_t)v;
|
||||
return;
|
||||
case INT32:
|
||||
((int32_t*)p)[index] = (int32_t)v; return;
|
||||
((int32_t *)p)[index] = (int32_t)v;
|
||||
return;
|
||||
case INT64:
|
||||
case UINT64:
|
||||
if (sizeof(mp_int_t) == 8) {
|
||||
@ -629,7 +642,8 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
}
|
||||
/* fallthru */
|
||||
|
||||
default: return MP_OBJ_NULL; // op not supported
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,11 +147,21 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
||||
if (c == '\\') {
|
||||
c = S_NEXT(s);
|
||||
switch (c) {
|
||||
case 'b': c = 0x08; break;
|
||||
case 'f': c = 0x0c; break;
|
||||
case 'n': c = 0x0a; break;
|
||||
case 'r': c = 0x0d; break;
|
||||
case 't': c = 0x09; break;
|
||||
case 'b':
|
||||
c = 0x08;
|
||||
break;
|
||||
case 'f':
|
||||
c = 0x0c;
|
||||
break;
|
||||
case 'n':
|
||||
c = 0x0a;
|
||||
break;
|
||||
case 'r':
|
||||
c = 0x0d;
|
||||
break;
|
||||
case 't':
|
||||
c = 0x09;
|
||||
break;
|
||||
case 'u': {
|
||||
mp_uint_t num = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -177,7 +187,16 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
||||
next = mp_obj_new_str(vstr.buf, vstr.len);
|
||||
break;
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9': {
|
||||
bool flt = false;
|
||||
vstr_reset(&vstr);
|
||||
for (;;) {
|
||||
|
@ -39,15 +39,14 @@
|
||||
STATIC uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233;
|
||||
STATIC uint8_t yasmarang_dat = 0;
|
||||
|
||||
STATIC uint32_t yasmarang(void)
|
||||
{
|
||||
STATIC uint32_t yasmarang(void) {
|
||||
yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n;
|
||||
yasmarang_pad = (yasmarang_pad << 3) + (yasmarang_pad >> 29);
|
||||
yasmarang_n = yasmarang_pad | 2;
|
||||
yasmarang_d ^= (yasmarang_pad << 31) + (yasmarang_pad >> 1);
|
||||
yasmarang_dat ^= (char)yasmarang_pad ^ (yasmarang_d >> 8) ^ 1;
|
||||
|
||||
return (yasmarang_pad^(yasmarang_d<<5)^(yasmarang_pad>>18)^(yasmarang_dat<<1));
|
||||
return yasmarang_pad ^ (yasmarang_d << 5) ^ (yasmarang_pad >> 18) ^ (yasmarang_dat << 1);
|
||||
} /* yasmarang */
|
||||
|
||||
// End of Yasmarang
|
||||
@ -169,9 +168,11 @@ STATIC mp_float_t yasmarang_float(void) {
|
||||
union {
|
||||
mp_float_t f;
|
||||
#if MP_ENDIANNESS_LITTLE
|
||||
struct { mp_float_int_t frc:MP_FLOAT_FRAC_BITS, exp:MP_FLOAT_EXP_BITS, sgn:1; } p;
|
||||
struct { mp_float_int_t frc : MP_FLOAT_FRAC_BITS, exp : MP_FLOAT_EXP_BITS, sgn : 1;
|
||||
} p;
|
||||
#else
|
||||
struct { mp_float_int_t sgn:1, exp:MP_FLOAT_EXP_BITS, frc:MP_FLOAT_FRAC_BITS; } p;
|
||||
struct { mp_float_int_t sgn : 1, exp : MP_FLOAT_EXP_BITS, frc : MP_FLOAT_FRAC_BITS;
|
||||
} p;
|
||||
#endif
|
||||
} u;
|
||||
u.p.sgn = 0;
|
||||
|
@ -190,9 +190,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump);
|
||||
STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
|
||||
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
|
||||
default: return MP_OBJ_NULL; // op not supported
|
||||
case MP_UNARY_OP_BOOL:
|
||||
return mp_obj_new_bool(self->len != 0);
|
||||
case MP_UNARY_OP_LEN:
|
||||
return MP_OBJ_NEW_SMALL_INT(self->len);
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,7 @@ DRESULT disk_read (
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
UINT count /* Number of sectors to read (1..128) */
|
||||
)
|
||||
{
|
||||
) {
|
||||
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
||||
if (vfs == NULL) {
|
||||
return RES_PARERR;
|
||||
@ -94,8 +93,7 @@ DRESULT disk_write (
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
UINT count /* Number of sectors to write (1..128) */
|
||||
)
|
||||
{
|
||||
) {
|
||||
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
||||
if (vfs == NULL) {
|
||||
return RES_PARERR;
|
||||
@ -131,8 +129,7 @@ DRESULT disk_ioctl (
|
||||
bdev_t pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
) {
|
||||
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
||||
if (vfs == NULL) {
|
||||
return RES_PARERR;
|
||||
|
@ -44,11 +44,15 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
void nlr_jump_fail(void *val) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
@ -71,26 +75,63 @@ int _fstat() {return 0;}
|
||||
int _isatty() {return 0;}
|
||||
*/
|
||||
|
||||
void *malloc(size_t n) {return NULL;}
|
||||
void *calloc(size_t nmemb, size_t size) {return NULL;}
|
||||
void *realloc(void *ptr, size_t size) {return NULL;}
|
||||
void free(void *p) {}
|
||||
int printf(const char *m, ...) {return 0;}
|
||||
void *memcpy(void *dest, const void *src, size_t n) {return NULL;}
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {return 0;}
|
||||
void *memmove(void *dest, const void *src, size_t n) {return NULL;}
|
||||
void *memset(void *s, int c, size_t n) {return NULL;}
|
||||
int strcmp(const char *s1, const char* s2) {return 0;}
|
||||
int strncmp(const char *s1, const char* s2, size_t n) {return 0;}
|
||||
size_t strlen(const char *s) {return 0;}
|
||||
char *strcat(char *dest, const char *src) {return NULL;}
|
||||
char *strchr(const char *dest, int c) {return NULL;}
|
||||
void *malloc(size_t n) {
|
||||
return NULL;
|
||||
}
|
||||
void *calloc(size_t nmemb, size_t size) {
|
||||
return NULL;
|
||||
}
|
||||
void *realloc(void *ptr, size_t size) {
|
||||
return NULL;
|
||||
}
|
||||
void free(void *p) {
|
||||
}
|
||||
int printf(const char *m, ...) {
|
||||
return 0;
|
||||
}
|
||||
void *memcpy(void *dest, const void *src, size_t n) {
|
||||
return NULL;
|
||||
}
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||
return 0;
|
||||
}
|
||||
void *memmove(void *dest, const void *src, size_t n) {
|
||||
return NULL;
|
||||
}
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
return NULL;
|
||||
}
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
return 0;
|
||||
}
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
return 0;
|
||||
}
|
||||
size_t strlen(const char *s) {
|
||||
return 0;
|
||||
}
|
||||
char *strcat(char *dest, const char *src) {
|
||||
return NULL;
|
||||
}
|
||||
char *strchr(const char *dest, int c) {
|
||||
return NULL;
|
||||
}
|
||||
#include <stdarg.h>
|
||||
int vprintf(const char *format, va_list ap) {return 0;}
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap) {return 0;}
|
||||
int vprintf(const char *format, va_list ap) {
|
||||
return 0;
|
||||
}
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef putchar
|
||||
int putchar(int c) {return 0;}
|
||||
int puts(const char *s) {return 0;}
|
||||
int putchar(int c) {
|
||||
return 0;
|
||||
}
|
||||
int puts(const char *s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _start(void) {main(0, NULL);}
|
||||
void _start(void) {
|
||||
main(0, NULL);
|
||||
}
|
||||
|
@ -95,7 +95,8 @@ int main (void) {
|
||||
|
||||
osi_start();
|
||||
|
||||
for ( ; ; );
|
||||
for ( ; ;) {;
|
||||
}
|
||||
}
|
||||
|
||||
// We need this when configSUPPORT_STATIC_ALLOCATION is enabled
|
||||
|
@ -158,8 +158,7 @@ soft_reset:
|
||||
// when waking up from hibernate we just want
|
||||
// to enable simplelink and leave it as is
|
||||
wlan_first_start();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// only if not comming out of hibernate or a soft reset
|
||||
mptask_enter_ap_mode();
|
||||
}
|
||||
|
@ -97,16 +97,14 @@ void TASK_Servers (void *pvParameters) {
|
||||
// now set/clear the flags
|
||||
servers_data.enabled = true;
|
||||
servers_data.do_enable = false;
|
||||
}
|
||||
else if (servers_data.do_disable) {
|
||||
} else if (servers_data.do_disable) {
|
||||
// disable network services
|
||||
telnet_disable();
|
||||
ftp_disable();
|
||||
// now clear the flags
|
||||
servers_data.do_disable = false;
|
||||
servers_data.enabled = false;
|
||||
}
|
||||
else if (servers_data.do_reset) {
|
||||
} else if (servers_data.do_reset) {
|
||||
// resetting the servers is needed to prevent half-open sockets
|
||||
servers_data.do_reset = false;
|
||||
if (servers_data.enabled) {
|
||||
@ -120,8 +118,7 @@ void TASK_Servers (void *pvParameters) {
|
||||
|
||||
if (cycle) {
|
||||
telnet_run();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ftp_run();
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,15 @@ python3 run-tests --target wipy --device 192.168.1.1 ../cc3200/tools/smoke.py
|
||||
pin_map = [23, 24, 11, 12, 13, 14, 15, 16, 17, 22, 28, 10, 9, 8, 7, 6, 30, 31, 3, 0, 4, 5]
|
||||
test_bytes = os.urandom(1024)
|
||||
|
||||
|
||||
def test_pin_read(pull):
|
||||
# enable the pull resistor on all pins, then read the value
|
||||
for p in pin_map:
|
||||
pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull)
|
||||
pin = Pin("GP" + str(p), mode=Pin.IN, pull=pull)
|
||||
# read the pin value
|
||||
print(pin())
|
||||
|
||||
|
||||
def test_pin_shorts(pull):
|
||||
if pull == Pin.PULL_UP:
|
||||
pull_inverted = Pin.PULL_DOWN
|
||||
@ -26,41 +28,42 @@ def test_pin_shorts (pull):
|
||||
pull_inverted = Pin.PULL_UP
|
||||
# enable all pulls of the specified type
|
||||
for p in pin_map:
|
||||
pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull_inverted)
|
||||
pin = Pin("GP" + str(p), mode=Pin.IN, pull=pull_inverted)
|
||||
# then change the pull one pin at a time and read its value
|
||||
i = 0
|
||||
while i < len(pin_map):
|
||||
pin = Pin('GP' + str(pin_map[i]), mode=Pin.IN, pull=pull)
|
||||
Pin('GP' + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
|
||||
pin = Pin("GP" + str(pin_map[i]), mode=Pin.IN, pull=pull)
|
||||
Pin("GP" + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
|
||||
i += 1
|
||||
# read the pin value
|
||||
print(pin())
|
||||
|
||||
|
||||
test_pin_read(Pin.PULL_UP)
|
||||
test_pin_read(Pin.PULL_DOWN)
|
||||
test_pin_shorts(Pin.PULL_UP)
|
||||
test_pin_shorts(Pin.PULL_DOWN)
|
||||
|
||||
# create a test directory
|
||||
os.mkdir('/flash/test')
|
||||
os.chdir('/flash/test')
|
||||
os.mkdir("/flash/test")
|
||||
os.chdir("/flash/test")
|
||||
print(os.getcwd())
|
||||
# create a new file
|
||||
f = open('test.txt', 'w')
|
||||
f = open("test.txt", "w")
|
||||
n_w = f.write(test_bytes)
|
||||
print(n_w == len(test_bytes))
|
||||
f.close()
|
||||
f = open('test.txt', 'r')
|
||||
r = bytes(f.read(), 'ascii')
|
||||
f = open("test.txt", "r")
|
||||
r = bytes(f.read(), "ascii")
|
||||
# check that we can write and read it correctly
|
||||
print(r == test_bytes)
|
||||
f.close()
|
||||
os.remove('test.txt')
|
||||
os.chdir('..')
|
||||
os.rmdir('test')
|
||||
os.remove("test.txt")
|
||||
os.chdir("..")
|
||||
os.rmdir("test")
|
||||
|
||||
ls = os.listdir()
|
||||
print('test' not in ls)
|
||||
print("test" not in ls)
|
||||
print(ls)
|
||||
|
||||
# test the real time clock
|
||||
@ -73,4 +76,3 @@ time.sleep_ms(1000)
|
||||
time2 = rtc.now()
|
||||
print(time2[5] - time1[5] == 1)
|
||||
print(time2[6] - time1[6] < 5000) # microseconds
|
||||
|
||||
|
@ -19,7 +19,7 @@ import subprocess
|
||||
|
||||
|
||||
def print_exception(e):
|
||||
print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
|
||||
print("Exception: {}, on line {}".format(e, sys.exc_info()[-1].tb_lineno))
|
||||
|
||||
|
||||
def execute(command):
|
||||
@ -29,7 +29,7 @@ def execute(command):
|
||||
# Poll process for new output until finished
|
||||
while True:
|
||||
nextline = process.stdout.readline()
|
||||
if nextline == '' and process.poll() != None:
|
||||
if nextline == "" and process.poll() != None:
|
||||
break
|
||||
sys.stdout.write(nextline)
|
||||
sys.stdout.flush()
|
||||
@ -43,25 +43,58 @@ def execute(command):
|
||||
else:
|
||||
raise ProcessException(command, exitCode, output)
|
||||
|
||||
|
||||
def main():
|
||||
cmd_parser = argparse.ArgumentParser(description='Flash the WiPy and optionally run a small test on it.')
|
||||
cmd_parser.add_argument('-u', '--uniflash', default=None, help='the path to the uniflash cli executable')
|
||||
cmd_parser.add_argument('-c', '--config', default=None, help='the path to the uniflash config file')
|
||||
cmd_parser.add_argument('-p', '--port', default=8, help='the com serial port')
|
||||
cmd_parser.add_argument('-s', '--servicepack', default=None, help='the path to the servicepack file')
|
||||
cmd_parser = argparse.ArgumentParser(
|
||||
description="Flash the WiPy and optionally run a small test on it."
|
||||
)
|
||||
cmd_parser.add_argument(
|
||||
"-u", "--uniflash", default=None, help="the path to the uniflash cli executable"
|
||||
)
|
||||
cmd_parser.add_argument(
|
||||
"-c", "--config", default=None, help="the path to the uniflash config file"
|
||||
)
|
||||
cmd_parser.add_argument("-p", "--port", default=8, help="the com serial port")
|
||||
cmd_parser.add_argument(
|
||||
"-s", "--servicepack", default=None, help="the path to the servicepack file"
|
||||
)
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
output = ""
|
||||
com_port = 'com=' + str(args.port)
|
||||
servicepack_path = 'spPath=' + args.servicepack
|
||||
com_port = "com=" + str(args.port)
|
||||
servicepack_path = "spPath=" + args.servicepack
|
||||
|
||||
try:
|
||||
if args.uniflash == None or args.config == None:
|
||||
raise ValueError('uniflash path and config path are mandatory')
|
||||
raise ValueError("uniflash path and config path are mandatory")
|
||||
if args.servicepack == None:
|
||||
output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, '-operations', 'format', 'program'])
|
||||
output += execute(
|
||||
[
|
||||
args.uniflash,
|
||||
"-config",
|
||||
args.config,
|
||||
"-setOptions",
|
||||
com_port,
|
||||
"-operations",
|
||||
"format",
|
||||
"program",
|
||||
]
|
||||
)
|
||||
else:
|
||||
output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, servicepack_path, '-operations', 'format', 'servicePackUpdate', 'program'])
|
||||
output += execute(
|
||||
[
|
||||
args.uniflash,
|
||||
"-config",
|
||||
args.config,
|
||||
"-setOptions",
|
||||
com_port,
|
||||
servicepack_path,
|
||||
"-operations",
|
||||
"format",
|
||||
"servicePackUpdate",
|
||||
"program",
|
||||
]
|
||||
)
|
||||
except Exception as e:
|
||||
print_exception(e)
|
||||
output = ""
|
||||
@ -77,5 +110,6 @@ def main():
|
||||
print("======================================")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -23,12 +23,12 @@ from telnetlib import Telnet
|
||||
|
||||
|
||||
def print_exception(e):
|
||||
print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
|
||||
print("Exception: {}, on line {}".format(e, sys.exc_info()[-1].tb_lineno))
|
||||
|
||||
|
||||
def ftp_directory_exists(ftpobj, directory_name):
|
||||
filelist = []
|
||||
ftpobj.retrlines('LIST',filelist.append)
|
||||
ftpobj.retrlines("LIST", filelist.append)
|
||||
for f in filelist:
|
||||
if f.split()[-1] == directory_name:
|
||||
return True
|
||||
@ -37,34 +37,34 @@ def ftp_directory_exists(ftpobj, directory_name):
|
||||
|
||||
def transfer_file(args):
|
||||
with FTP(args.ip, timeout=20) as ftp:
|
||||
print ('FTP connection established')
|
||||
print("FTP connection established")
|
||||
|
||||
if '230' in ftp.login(args.user, args.password):
|
||||
print ('Login successful')
|
||||
if "230" in ftp.login(args.user, args.password):
|
||||
print("Login successful")
|
||||
|
||||
if '250' in ftp.cwd('/flash'):
|
||||
if not ftp_directory_exists(ftp, 'sys'):
|
||||
print ('/flash/sys directory does not exist')
|
||||
if not '550' in ftp.mkd('sys'):
|
||||
print ('/flash/sys directory created')
|
||||
if "250" in ftp.cwd("/flash"):
|
||||
if not ftp_directory_exists(ftp, "sys"):
|
||||
print("/flash/sys directory does not exist")
|
||||
if not "550" in ftp.mkd("sys"):
|
||||
print("/flash/sys directory created")
|
||||
else:
|
||||
print ('Error: cannot create /flash/sys directory')
|
||||
print("Error: cannot create /flash/sys directory")
|
||||
return False
|
||||
if '250' in ftp.cwd('sys'):
|
||||
if "250" in ftp.cwd("sys"):
|
||||
print("Entered '/flash/sys' directory")
|
||||
with open(args.file, "rb") as fwfile:
|
||||
print ('Firmware image found, initiating transfer...')
|
||||
if '226' in ftp.storbinary("STOR " + 'mcuimg.bin', fwfile, 512):
|
||||
print ('File transfer complete')
|
||||
print("Firmware image found, initiating transfer...")
|
||||
if "226" in ftp.storbinary("STOR " + "mcuimg.bin", fwfile, 512):
|
||||
print("File transfer complete")
|
||||
return True
|
||||
else:
|
||||
print ('Error: file transfer failed')
|
||||
print("Error: file transfer failed")
|
||||
else:
|
||||
print ('Error: cannot enter /flash/sys directory')
|
||||
print("Error: cannot enter /flash/sys directory")
|
||||
else:
|
||||
print ('Error: cannot enter /flash directory')
|
||||
print("Error: cannot enter /flash directory")
|
||||
else:
|
||||
print ('Error: ftp login failed')
|
||||
print("Error: ftp login failed")
|
||||
|
||||
return False
|
||||
|
||||
@ -76,20 +76,24 @@ def reset_board(args):
|
||||
tn = Telnet(args.ip, timeout=5)
|
||||
print("Connected via Telnet, trying to login now")
|
||||
|
||||
if b'Login as:' in tn.read_until(b"Login as:", timeout=5):
|
||||
tn.write(bytes(args.user, 'ascii') + b"\r\n")
|
||||
if b"Login as:" in tn.read_until(b"Login as:", timeout=5):
|
||||
tn.write(bytes(args.user, "ascii") + b"\r\n")
|
||||
|
||||
if b'Password:' in tn.read_until(b"Password:", timeout=5):
|
||||
if b"Password:" in tn.read_until(b"Password:", timeout=5):
|
||||
# needed because of internal implementation details of the WiPy's telnet server
|
||||
time.sleep(0.2)
|
||||
tn.write(bytes(args.password, 'ascii') + b"\r\n")
|
||||
tn.write(bytes(args.password, "ascii") + b"\r\n")
|
||||
|
||||
if b'Type "help()" for more information.' in tn.read_until(b'Type "help()" for more information.', timeout=5):
|
||||
if b'Type "help()" for more information.' in tn.read_until(
|
||||
b'Type "help()" for more information.', timeout=5
|
||||
):
|
||||
print("Telnet login succeeded")
|
||||
tn.write(b'\r\x03\x03') # ctrl-C twice: interrupt any running program
|
||||
tn.write(b"\r\x03\x03") # ctrl-C twice: interrupt any running program
|
||||
time.sleep(1)
|
||||
tn.write(b'\r\x02') # ctrl-B: enter friendly REPL
|
||||
if b'Type "help()" for more information.' in tn.read_until(b'Type "help()" for more information.', timeout=5):
|
||||
tn.write(b"\r\x02") # ctrl-B: enter friendly REPL
|
||||
if b'Type "help()" for more information.' in tn.read_until(
|
||||
b'Type "help()" for more information.', timeout=5
|
||||
):
|
||||
tn.write(b"import machine\r\n")
|
||||
tn.write(b"machine.reset()\r\n")
|
||||
time.sleep(2)
|
||||
@ -112,7 +116,7 @@ def reset_board(args):
|
||||
|
||||
def verify_update(args):
|
||||
success = False
|
||||
firmware_tag = ''
|
||||
firmware_tag = ""
|
||||
|
||||
def find_tag(tag):
|
||||
if tag in firmware_tag:
|
||||
@ -135,21 +139,26 @@ def verify_update(args):
|
||||
print("Timeout while connecting via telnet, retrying...")
|
||||
retries += 1
|
||||
else:
|
||||
print('Error: Telnet connection timed out!')
|
||||
print("Error: Telnet connection timed out!")
|
||||
return False
|
||||
|
||||
try:
|
||||
firmware_tag = tn.read_until (b'with CC3200')
|
||||
tag_file_path = args.file.rstrip('mcuimg.bin') + 'genhdr/mpversion.h'
|
||||
firmware_tag = tn.read_until(b"with CC3200")
|
||||
tag_file_path = args.file.rstrip("mcuimg.bin") + "genhdr/mpversion.h"
|
||||
|
||||
if args.tag is not None:
|
||||
success = find_tag(bytes(args.tag, 'ascii'))
|
||||
success = find_tag(bytes(args.tag, "ascii"))
|
||||
else:
|
||||
with open(tag_file_path) as tag_file:
|
||||
for line in tag_file:
|
||||
bline = bytes(line, 'ascii')
|
||||
if b'MICROPY_GIT_HASH' in bline:
|
||||
bline = bline.lstrip(b'#define MICROPY_GIT_HASH ').replace(b'"', b'').replace(b'\r', b'').replace(b'\n', b'')
|
||||
bline = bytes(line, "ascii")
|
||||
if b"MICROPY_GIT_HASH" in bline:
|
||||
bline = (
|
||||
bline.lstrip(b"#define MICROPY_GIT_HASH ")
|
||||
.replace(b'"', b"")
|
||||
.replace(b"\r", b"")
|
||||
.replace(b"\n", b"")
|
||||
)
|
||||
success = find_tag(bline)
|
||||
break
|
||||
|
||||
@ -164,24 +173,28 @@ def verify_update(args):
|
||||
|
||||
|
||||
def main():
|
||||
cmd_parser = argparse.ArgumentParser(description='Update the WiPy firmware with the specified image file')
|
||||
cmd_parser.add_argument('-f', '--file', default=None, help='the path of the firmware file')
|
||||
cmd_parser.add_argument('-u', '--user', default='micro', help='the username')
|
||||
cmd_parser.add_argument('-p', '--password', default='python', help='the login password')
|
||||
cmd_parser.add_argument('--ip', default='192.168.1.1', help='the ip address of the WiPy')
|
||||
cmd_parser.add_argument('--verify', action='store_true', help='verify that the update succeeded')
|
||||
cmd_parser.add_argument('-t', '--tag', default=None, help='git tag of the firmware image')
|
||||
cmd_parser = argparse.ArgumentParser(
|
||||
description="Update the WiPy firmware with the specified image file"
|
||||
)
|
||||
cmd_parser.add_argument("-f", "--file", default=None, help="the path of the firmware file")
|
||||
cmd_parser.add_argument("-u", "--user", default="micro", help="the username")
|
||||
cmd_parser.add_argument("-p", "--password", default="python", help="the login password")
|
||||
cmd_parser.add_argument("--ip", default="192.168.1.1", help="the ip address of the WiPy")
|
||||
cmd_parser.add_argument(
|
||||
"--verify", action="store_true", help="verify that the update succeeded"
|
||||
)
|
||||
cmd_parser.add_argument("-t", "--tag", default=None, help="git tag of the firmware image")
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
result = 1
|
||||
|
||||
try:
|
||||
if args.file is None:
|
||||
raise ValueError('the image file path must be specified')
|
||||
raise ValueError("the image file path must be specified")
|
||||
if transfer_file(args):
|
||||
if reset_board(args):
|
||||
if args.verify:
|
||||
print ('Waiting for the WiFi connection to come up again...')
|
||||
print("Waiting for the WiFi connection to come up again...")
|
||||
# this time is to allow the system's wireless network card to
|
||||
# connect to the WiPy again.
|
||||
time.sleep(5)
|
||||
|
@ -36,18 +36,28 @@ void IRAM_ATTR esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numByte
|
||||
|
||||
uint32_t irq_state = mp_hal_quiet_timing_enter();
|
||||
for (t = time0;; t = time0) {
|
||||
if (pix & mask) t = time1; // Bit high duration
|
||||
while (((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
|
||||
if (pix & mask) {
|
||||
t = time1; // Bit high duration
|
||||
}
|
||||
while (((c = mp_hal_ticks_cpu()) - startTime) < period) {
|
||||
; // Wait for bit start
|
||||
}
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, pinMask); // Set high
|
||||
startTime = c; // Save start time
|
||||
while (((c = mp_hal_ticks_cpu()) - startTime) < t); // Wait high duration
|
||||
while (((c = mp_hal_ticks_cpu()) - startTime) < t) {
|
||||
; // Wait high duration
|
||||
}
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, pinMask); // Set low
|
||||
if (!(mask >>= 1)) { // Next bit/byte
|
||||
if(p >= end) break;
|
||||
if (p >= end) {
|
||||
break;
|
||||
}
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
}
|
||||
}
|
||||
while ((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
|
||||
while ((mp_hal_ticks_cpu() - startTime) < period) {
|
||||
; // Wait for last bit
|
||||
}
|
||||
mp_hal_quiet_timing_exit(irq_state);
|
||||
}
|
||||
|
@ -36,6 +36,6 @@ DWORD get_fattime(void) {
|
||||
timeutils_struct_time_t tm;
|
||||
timeutils_seconds_since_2000_to_struct_time(tv.tv_sec, &tm);
|
||||
|
||||
return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
|
||||
((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1));
|
||||
return ((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
|
||||
((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1);
|
||||
}
|
||||
|
@ -66,11 +66,18 @@ STATIC mp_obj_t madc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
||||
gpio_num_t pin_id = machine_pin_get_id(args[0]);
|
||||
const madc_obj_t *self = NULL;
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(madc_obj); i++) {
|
||||
if (pin_id == madc_obj[i].gpio_id) { self = &madc_obj[i]; break; }
|
||||
if (pin_id == madc_obj[i].gpio_id) {
|
||||
self = &madc_obj[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!self) {
|
||||
mp_raise_ValueError("invalid Pin for ADC");
|
||||
}
|
||||
if (!self) mp_raise_ValueError("invalid Pin for ADC");
|
||||
esp_err_t err = adc1_config_channel_atten(self->adc1_id, ADC_ATTEN_0db);
|
||||
if (err == ESP_OK) return MP_OBJ_FROM_PTR(self);
|
||||
if (err == ESP_OK) {
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
mp_raise_ValueError("Parameter Error");
|
||||
}
|
||||
|
||||
@ -82,7 +89,9 @@ STATIC void madc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||
STATIC mp_obj_t madc_read(mp_obj_t self_in) {
|
||||
madc_obj_t *self = self_in;
|
||||
int val = adc1_get_raw(self->adc1_id);
|
||||
if (val == -1) mp_raise_ValueError("Parameter Error");
|
||||
if (val == -1) {
|
||||
mp_raise_ValueError("Parameter Error");
|
||||
}
|
||||
return MP_OBJ_NEW_SMALL_INT(val);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(madc_read_obj, madc_read);
|
||||
@ -91,7 +100,9 @@ STATIC mp_obj_t madc_atten(mp_obj_t self_in, mp_obj_t atten_in) {
|
||||
madc_obj_t *self = self_in;
|
||||
adc_atten_t atten = mp_obj_get_int(atten_in);
|
||||
esp_err_t err = adc1_config_channel_atten(self->adc1_id, atten);
|
||||
if (err == ESP_OK) return mp_const_none;
|
||||
if (err == ESP_OK) {
|
||||
return mp_const_none;
|
||||
}
|
||||
mp_raise_ValueError("Parameter Error");
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(madc_atten_obj, madc_atten);
|
||||
@ -99,7 +110,9 @@ MP_DEFINE_CONST_FUN_OBJ_2(madc_atten_obj, madc_atten);
|
||||
STATIC mp_obj_t madc_width(mp_obj_t cls_in, mp_obj_t width_in) {
|
||||
adc_bits_width_t width = mp_obj_get_int(width_in);
|
||||
esp_err_t err = adc1_config_width(width);
|
||||
if (err == ESP_OK) return mp_const_none;
|
||||
if (err == ESP_OK) {
|
||||
return mp_const_none;
|
||||
}
|
||||
mp_raise_ValueError("Parameter Error");
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(madc_width_fun_obj, madc_width);
|
||||
|
@ -54,15 +54,22 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
||||
gpio_num_t pin_id = machine_pin_get_id(args[0]);
|
||||
const mdac_obj_t *self = NULL;
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(mdac_obj); i++) {
|
||||
if (pin_id == mdac_obj[i].gpio_id) { self = &mdac_obj[i]; break; }
|
||||
if (pin_id == mdac_obj[i].gpio_id) {
|
||||
self = &mdac_obj[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!self) {
|
||||
mp_raise_ValueError("invalid Pin for DAC");
|
||||
}
|
||||
if (!self) mp_raise_ValueError("invalid Pin for DAC");
|
||||
|
||||
esp_err_t err = dac_output_enable(self->dac_id);
|
||||
if (err == ESP_OK) {
|
||||
err = dac_output_voltage(self->dac_id, 0);
|
||||
}
|
||||
if (err == ESP_OK) return MP_OBJ_FROM_PTR(self);
|
||||
if (err == ESP_OK) {
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
mp_raise_ValueError("Parameter Error");
|
||||
}
|
||||
|
||||
@ -74,10 +81,14 @@ STATIC void mdac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||
STATIC mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) {
|
||||
mdac_obj_t *self = self_in;
|
||||
int value = mp_obj_get_int(value_in);
|
||||
if (value < 0 || value > 255) mp_raise_ValueError("Value out of range");
|
||||
if (value < 0 || value > 255) {
|
||||
mp_raise_ValueError("Value out of range");
|
||||
}
|
||||
|
||||
esp_err_t err = dac_output_voltage(self->dac_id, value);
|
||||
if (err == ESP_OK) return mp_const_none;
|
||||
if (err == ESP_OK) {
|
||||
return mp_const_none;
|
||||
}
|
||||
mp_raise_ValueError("Parameter Error");
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write);
|
||||
|
@ -62,9 +62,14 @@ STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
|
||||
gpio_num_t pin_id = machine_pin_get_id(args[0]);
|
||||
const mtp_obj_t *self = NULL;
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(touchpad_obj); i++) {
|
||||
if (pin_id == touchpad_obj[i].gpio_id) { self = &touchpad_obj[i]; break; }
|
||||
if (pin_id == touchpad_obj[i].gpio_id) {
|
||||
self = &touchpad_obj[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!self) {
|
||||
mp_raise_ValueError("invalid pin for touchpad");
|
||||
}
|
||||
if (!self) mp_raise_ValueError("invalid pin for touchpad");
|
||||
|
||||
static int initialized = 0;
|
||||
if (!initialized) {
|
||||
@ -72,7 +77,9 @@ STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
|
||||
initialized = 1;
|
||||
}
|
||||
esp_err_t err = touch_pad_config(self->touchpad_id, 0);
|
||||
if (err == ESP_OK) return MP_OBJ_FROM_PTR(self);
|
||||
if (err == ESP_OK) {
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
mp_raise_ValueError("Touch pad error");
|
||||
}
|
||||
|
||||
@ -80,7 +87,9 @@ STATIC mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) {
|
||||
mtp_obj_t *self = self_in;
|
||||
uint16_t value = mp_obj_get_int(value_in);
|
||||
esp_err_t err = touch_pad_config(self->touchpad_id, value);
|
||||
if (err == ESP_OK) return mp_const_none;
|
||||
if (err == ESP_OK) {
|
||||
return mp_const_none;
|
||||
}
|
||||
mp_raise_ValueError("Touch pad error");
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config);
|
||||
@ -89,7 +98,9 @@ STATIC mp_obj_t mtp_read(mp_obj_t self_in) {
|
||||
mtp_obj_t *self = self_in;
|
||||
uint16_t value;
|
||||
esp_err_t err = touch_pad_read(self->touchpad_id, &value);
|
||||
if (err == ESP_OK) return MP_OBJ_NEW_SMALL_INT(value);
|
||||
if (err == ESP_OK) {
|
||||
return MP_OBJ_NEW_SMALL_INT(value);
|
||||
}
|
||||
mp_raise_ValueError("Touch pad error");
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mtp_read_obj, mtp_read);
|
||||
|
@ -5,21 +5,21 @@ OFFSET_PARTITIONS = 0x8000
|
||||
OFFSET_APPLICATION = 0x10000
|
||||
|
||||
files_in = [
|
||||
('bootloader', OFFSET_BOOTLOADER, sys.argv[1]),
|
||||
('partitions', OFFSET_PARTITIONS, sys.argv[2]),
|
||||
('application', OFFSET_APPLICATION, sys.argv[3]),
|
||||
("bootloader", OFFSET_BOOTLOADER, sys.argv[1]),
|
||||
("partitions", OFFSET_PARTITIONS, sys.argv[2]),
|
||||
("application", OFFSET_APPLICATION, sys.argv[3]),
|
||||
]
|
||||
file_out = sys.argv[4]
|
||||
|
||||
cur_offset = OFFSET_BOOTLOADER
|
||||
with open(file_out, 'wb') as fout:
|
||||
with open(file_out, "wb") as fout:
|
||||
for name, offset, file_in in files_in:
|
||||
assert offset >= cur_offset
|
||||
fout.write(b'\xff' * (offset - cur_offset))
|
||||
fout.write(b"\xff" * (offset - cur_offset))
|
||||
cur_offset = offset
|
||||
with open(file_in, 'rb') as fin:
|
||||
with open(file_in, "rb") as fin:
|
||||
data = fin.read()
|
||||
fout.write(data)
|
||||
cur_offset += len(data)
|
||||
print('%-12s% 8d' % (name, len(data)))
|
||||
print('%-12s% 8d' % ('total', cur_offset))
|
||||
print("%-12s% 8d" % (name, len(data)))
|
||||
print("%-12s% 8d" % ("total", cur_offset))
|
||||
|
@ -101,7 +101,9 @@ NORETURN void _esp_exceptions(esp_err_t e) {
|
||||
}
|
||||
|
||||
static inline void esp_exceptions(esp_err_t e) {
|
||||
if (e != ESP_OK) _esp_exceptions(e);
|
||||
if (e != ESP_OK) {
|
||||
_esp_exceptions(e);
|
||||
}
|
||||
}
|
||||
|
||||
#define ESP_EXCEPTIONS(x) do { esp_exceptions(x); } while (0);
|
||||
@ -480,12 +482,16 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
// To set a static IP we have to disable DHCP first
|
||||
if (self->if_id == WIFI_IF_STA || self->if_id == ESP_IF_ETH) {
|
||||
esp_err_t e = tcpip_adapter_dhcpc_stop(self->if_id);
|
||||
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) _esp_exceptions(e);
|
||||
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) {
|
||||
_esp_exceptions(e);
|
||||
}
|
||||
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(self->if_id, &info));
|
||||
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
|
||||
} else if (self->if_id == WIFI_IF_AP) {
|
||||
esp_err_t e = tcpip_adapter_dhcps_stop(WIFI_IF_AP);
|
||||
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) _esp_exceptions(e);
|
||||
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) {
|
||||
_esp_exceptions(e);
|
||||
}
|
||||
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(WIFI_IF_AP, &info));
|
||||
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(WIFI_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
|
||||
ESP_EXCEPTIONS(tcpip_adapter_dhcps_start(WIFI_IF_AP));
|
||||
|
@ -182,7 +182,9 @@ int _socket_getaddrinfo(const mp_obj_t addrtuple, struct addrinfo **resp) {
|
||||
mp_uint_t len = 0;
|
||||
mp_obj_t *elem;
|
||||
mp_obj_get_array(addrtuple, &len, &elem);
|
||||
if (len != 2) return -1;
|
||||
if (len != 2) {
|
||||
return -1;
|
||||
}
|
||||
return _socket_getaddrinfo2(elem[0], elem[1], resp);
|
||||
}
|
||||
|
||||
@ -192,7 +194,9 @@ STATIC mp_obj_t socket_bind(const mp_obj_t arg0, const mp_obj_t arg1) {
|
||||
_socket_getaddrinfo(arg1, &res);
|
||||
int r = lwip_bind_r(self->fd, res->ai_addr, res->ai_addrlen);
|
||||
lwip_freeaddrinfo(res);
|
||||
if (r < 0) exception_from_errno(errno);
|
||||
if (r < 0) {
|
||||
exception_from_errno(errno);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
|
||||
@ -201,7 +205,9 @@ STATIC mp_obj_t socket_listen(const mp_obj_t arg0, const mp_obj_t arg1) {
|
||||
socket_obj_t *self = MP_OBJ_TO_PTR(arg0);
|
||||
int backlog = mp_obj_get_int(arg1);
|
||||
int r = lwip_listen_r(self->fd, backlog);
|
||||
if (r < 0) exception_from_errno(errno);
|
||||
if (r < 0) {
|
||||
exception_from_errno(errno);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
|
||||
@ -217,11 +223,17 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
new_fd = lwip_accept_r(self->fd, &addr, &addr_len);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (new_fd >= 0) break;
|
||||
if (errno != EAGAIN) exception_from_errno(errno);
|
||||
if (new_fd >= 0) {
|
||||
break;
|
||||
}
|
||||
if (errno != EAGAIN) {
|
||||
exception_from_errno(errno);
|
||||
}
|
||||
check_for_exceptions();
|
||||
}
|
||||
if (new_fd < 0) mp_raise_OSError(MP_ETIMEDOUT);
|
||||
if (new_fd < 0) {
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
}
|
||||
|
||||
// create new socket object
|
||||
socket_obj_t *sock = m_new_obj_with_finaliser(socket_obj_t);
|
||||
@ -338,8 +350,9 @@ void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms) {
|
||||
|
||||
STATIC mp_obj_t socket_settimeout(const mp_obj_t arg0, const mp_obj_t arg1) {
|
||||
socket_obj_t *self = MP_OBJ_TO_PTR(arg0);
|
||||
if (arg1 == mp_const_none) _socket_settimeout(self, UINT64_MAX);
|
||||
else {
|
||||
if (arg1 == mp_const_none) {
|
||||
_socket_settimeout(self, UINT64_MAX);
|
||||
} else {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
_socket_settimeout(self, mp_obj_get_float(arg1) * 1000L);
|
||||
#else
|
||||
@ -352,8 +365,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
|
||||
|
||||
STATIC mp_obj_t socket_setblocking(const mp_obj_t arg0, const mp_obj_t arg1) {
|
||||
socket_obj_t *self = MP_OBJ_TO_PTR(arg0);
|
||||
if (mp_obj_is_true(arg1)) _socket_settimeout(self, UINT64_MAX);
|
||||
else _socket_settimeout(self, 0);
|
||||
if (mp_obj_is_true(arg1)) {
|
||||
_socket_settimeout(self, UINT64_MAX);
|
||||
} else {
|
||||
_socket_settimeout(self, 0);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
||||
@ -452,11 +468,17 @@ int _socket_send(socket_obj_t *sock, const char *data, size_t datalen) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int r = lwip_write_r(sock->fd, data + sentlen, datalen - sentlen);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (r < 0 && errno != EWOULDBLOCK) exception_from_errno(errno);
|
||||
if (r > 0) sentlen += r;
|
||||
if (r < 0 && errno != EWOULDBLOCK) {
|
||||
exception_from_errno(errno);
|
||||
}
|
||||
if (r > 0) {
|
||||
sentlen += r;
|
||||
}
|
||||
check_for_exceptions();
|
||||
}
|
||||
if (sentlen == 0) mp_raise_OSError(MP_ETIMEDOUT);
|
||||
if (sentlen == 0) {
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
}
|
||||
return sentlen;
|
||||
}
|
||||
|
||||
@ -476,7 +498,9 @@ STATIC mp_obj_t socket_sendall(const mp_obj_t arg0, const mp_obj_t arg1) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg1, &bufinfo, MP_BUFFER_READ);
|
||||
int r = _socket_send(sock, bufinfo.buf, bufinfo.len);
|
||||
if (r < bufinfo.len) mp_raise_OSError(MP_ETIMEDOUT);
|
||||
if (r < bufinfo.len) {
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_sendall_obj, socket_sendall);
|
||||
@ -499,7 +523,9 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int ret = lwip_sendto_r(self->fd, bufinfo.buf, bufinfo.len, 0, (struct sockaddr *)&to, sizeof(to));
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (ret > 0) return mp_obj_new_int_from_uint(ret);
|
||||
if (ret > 0) {
|
||||
return mp_obj_new_int_from_uint(ret);
|
||||
}
|
||||
if (ret == -1 && errno != EWOULDBLOCK) {
|
||||
exception_from_errno(errno);
|
||||
}
|
||||
@ -531,8 +557,13 @@ STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int r = lwip_write_r(sock->fd, buf, size);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (r > 0) return r;
|
||||
if (r < 0 && errno != EWOULDBLOCK) { *errcode = errno; return MP_STREAM_ERROR; }
|
||||
if (r > 0) {
|
||||
return r;
|
||||
}
|
||||
if (r < 0 && errno != EWOULDBLOCK) {
|
||||
*errcode = errno;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
check_for_exceptions();
|
||||
}
|
||||
*errcode = sock->retries == 0 ? MP_EWOULDBLOCK : MP_ETIMEDOUT;
|
||||
@ -543,13 +574,22 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt
|
||||
socket_obj_t *socket = self_in;
|
||||
if (request == MP_STREAM_POLL) {
|
||||
|
||||
fd_set rfds; FD_ZERO(&rfds);
|
||||
fd_set wfds; FD_ZERO(&wfds);
|
||||
fd_set efds; FD_ZERO(&efds);
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
fd_set wfds;
|
||||
FD_ZERO(&wfds);
|
||||
fd_set efds;
|
||||
FD_ZERO(&efds);
|
||||
struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 };
|
||||
if (arg & MP_STREAM_POLL_RD) FD_SET(socket->fd, &rfds);
|
||||
if (arg & MP_STREAM_POLL_WR) FD_SET(socket->fd, &wfds);
|
||||
if (arg & MP_STREAM_POLL_HUP) FD_SET(socket->fd, &efds);
|
||||
if (arg & MP_STREAM_POLL_RD) {
|
||||
FD_SET(socket->fd, &rfds);
|
||||
}
|
||||
if (arg & MP_STREAM_POLL_WR) {
|
||||
FD_SET(socket->fd, &wfds);
|
||||
}
|
||||
if (arg & MP_STREAM_POLL_HUP) {
|
||||
FD_SET(socket->fd, &efds);
|
||||
}
|
||||
|
||||
int r = select((socket->fd) + 1, &rfds, &wfds, &efds, &timeout);
|
||||
if (r < 0) {
|
||||
@ -558,9 +598,15 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt
|
||||
}
|
||||
|
||||
mp_uint_t ret = 0;
|
||||
if (FD_ISSET(socket->fd, &rfds)) ret |= MP_STREAM_POLL_RD;
|
||||
if (FD_ISSET(socket->fd, &wfds)) ret |= MP_STREAM_POLL_WR;
|
||||
if (FD_ISSET(socket->fd, &efds)) ret |= MP_STREAM_POLL_HUP;
|
||||
if (FD_ISSET(socket->fd, &rfds)) {
|
||||
ret |= MP_STREAM_POLL_RD;
|
||||
}
|
||||
if (FD_ISSET(socket->fd, &wfds)) {
|
||||
ret |= MP_STREAM_POLL_WR;
|
||||
}
|
||||
if (FD_ISSET(socket->fd, &efds)) {
|
||||
ret |= MP_STREAM_POLL_HUP;
|
||||
}
|
||||
return ret;
|
||||
} else if (request == MP_STREAM_CLOSE) {
|
||||
if (socket->fd >= 0) {
|
||||
@ -680,7 +726,9 @@ STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_list_append(ret_list, mp_obj_new_tuple(5, addrinfo_objs));
|
||||
}
|
||||
|
||||
if (res) lwip_freeaddrinfo(res);
|
||||
if (res) {
|
||||
lwip_freeaddrinfo(res);
|
||||
}
|
||||
return ret_list;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_socket_getaddrinfo_obj, 2, 6, esp_socket_getaddrinfo);
|
||||
|
@ -111,7 +111,8 @@ STATIC void freertos_entry(void *arg) {
|
||||
ext_thread_entry(arg);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
for (;;);
|
||||
for (;;) {;
|
||||
}
|
||||
}
|
||||
|
||||
void mp_thread_create_ex(void *(*entry)(void *), void *arg, size_t *stack_size, int priority, char *name) {
|
||||
@ -190,7 +191,7 @@ void mp_thread_mutex_init(mp_thread_mutex_t *mutex) {
|
||||
}
|
||||
|
||||
int mp_thread_mutex_lock(mp_thread_mutex_t *mutex, int wait) {
|
||||
return (pdTRUE == xSemaphoreTake(mutex->handle, wait ? portMAX_DELAY : 0));
|
||||
return pdTRUE == xSemaphoreTake(mutex->handle, wait ? portMAX_DELAY : 0);
|
||||
}
|
||||
|
||||
void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex) {
|
||||
|
@ -46,19 +46,29 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32
|
||||
|
||||
uint32_t irq_state = mp_hal_quiet_timing_enter();
|
||||
for (t = time0;; t = time0) {
|
||||
if(pix & mask) t = time1; // Bit high duration
|
||||
while(((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
|
||||
if (pix & mask) {
|
||||
t = time1; // Bit high duration
|
||||
}
|
||||
while (((c = mp_hal_ticks_cpu()) - startTime) < period) {
|
||||
; // Wait for bit start
|
||||
}
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
|
||||
startTime = c; // Save start time
|
||||
while(((c = mp_hal_ticks_cpu()) - startTime) < t); // Wait high duration
|
||||
while (((c = mp_hal_ticks_cpu()) - startTime) < t) {
|
||||
; // Wait high duration
|
||||
}
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
|
||||
if (!(mask >>= 1)) { // Next bit/byte
|
||||
if(p >= end) break;
|
||||
if (p >= end) {
|
||||
break;
|
||||
}
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
}
|
||||
}
|
||||
while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
|
||||
while ((mp_hal_ticks_cpu() - startTime) < period) {
|
||||
; // Wait for last bit
|
||||
}
|
||||
mp_hal_quiet_timing_exit(irq_state);
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,7 @@ typedef enum {
|
||||
} TIMER_INT_MODE;
|
||||
|
||||
STATIC void ICACHE_FLASH_ATTR
|
||||
pwm_insert_sort(struct pwm_single_param pwm[], uint8 n)
|
||||
{
|
||||
pwm_insert_sort(struct pwm_single_param pwm[], uint8 n) {
|
||||
uint8 i;
|
||||
|
||||
for (i = 1; i < n; i++) {
|
||||
@ -118,8 +117,7 @@ STATIC volatile uint8 critical = 0;
|
||||
} while (0)
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
pwm_start(void)
|
||||
{
|
||||
pwm_start(void) {
|
||||
uint8 i, j;
|
||||
PWM_DBG("--Function pwm_start() is called\n");
|
||||
PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
|
||||
@ -212,8 +210,7 @@ pwm_start(void)
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
pwm_set_duty(int16_t duty, uint8 channel)
|
||||
{
|
||||
pwm_set_duty(int16_t duty, uint8 channel) {
|
||||
uint8 i;
|
||||
for (i = 0; i < pwm_channel_num; i++) {
|
||||
if (pwm_out_io_num[i] == channel) {
|
||||
@ -221,8 +218,9 @@ pwm_set_duty(int16_t duty, uint8 channel)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==pwm_channel_num) // non found
|
||||
if (i == pwm_channel_num) { // non found
|
||||
return;
|
||||
}
|
||||
|
||||
LOCK_PWM(critical); // enter critical
|
||||
if (duty < 1) {
|
||||
@ -242,8 +240,7 @@ pwm_set_duty(int16_t duty, uint8 channel)
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
pwm_set_freq(uint16 freq, uint8 channel)
|
||||
{
|
||||
pwm_set_freq(uint16 freq, uint8 channel) {
|
||||
LOCK_PWM(critical); // enter critical
|
||||
if (freq > PWM_FREQ_MAX) {
|
||||
pwm.freq = PWM_FREQ_MAX;
|
||||
@ -264,8 +261,7 @@ pwm_set_freq(uint16 freq, uint8 channel)
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
uint16 ICACHE_FLASH_ATTR
|
||||
pwm_get_duty(uint8 channel)
|
||||
{
|
||||
pwm_get_duty(uint8 channel) {
|
||||
uint8 i;
|
||||
for (i = 0; i < pwm_channel_num; i++) {
|
||||
if (pwm_out_io_num[i] == channel) {
|
||||
@ -273,8 +269,9 @@ pwm_get_duty(uint8 channel)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==pwm_channel_num) // non found
|
||||
if (i == pwm_channel_num) { // non found
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pwm.duty[channel];
|
||||
}
|
||||
@ -286,8 +283,7 @@ pwm_get_duty(uint8 channel)
|
||||
* Returns : uint16 : pwm frequency
|
||||
*******************************************************************************/
|
||||
uint16 ICACHE_FLASH_ATTR
|
||||
pwm_get_freq(uint8 channel)
|
||||
{
|
||||
pwm_get_freq(uint8 channel) {
|
||||
return pwm.freq;
|
||||
}
|
||||
|
||||
@ -299,8 +295,7 @@ pwm_get_freq(uint8 channel)
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
STATIC void ICACHE_RAM_ATTR
|
||||
pwm_tim1_intr_handler(void *dummy)
|
||||
{
|
||||
pwm_tim1_intr_handler(void *dummy) {
|
||||
(void)dummy;
|
||||
uint8 local_toggle = pwm_toggle; // pwm_toggle may change outside
|
||||
RTC_CLR_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK);
|
||||
@ -335,8 +330,7 @@ pwm_tim1_intr_handler(void *dummy)
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
pwm_init(void)
|
||||
{
|
||||
pwm_init(void) {
|
||||
uint8 i;
|
||||
|
||||
RTC_REG_WRITE(FRC1_CTRL_ADDRESS, // FRC2_AUTO_RELOAD|
|
||||
@ -376,8 +370,9 @@ pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func){
|
||||
}
|
||||
uint8 i;
|
||||
for (i = 0; i < PWM_CHANNEL; i++) {
|
||||
if(pwm_out_io_num[i]==channel) // already exist
|
||||
if (pwm_out_io_num[i] == channel) { // already exist
|
||||
return channel;
|
||||
}
|
||||
if (pwm_out_io_num[i] == -1) { // empty exist
|
||||
LOCK_PWM(critical); // enter critical
|
||||
pwm_out_io_num[i] = channel;
|
||||
|
@ -38,7 +38,9 @@ static inline int prio2id(uint8_t prio) {
|
||||
int id = PRIO2ID(prio);
|
||||
if (id < 0 || id >= MP_ARRAY_SIZE(emu_tasks)) {
|
||||
printf("task prio out of range: %d\n", prio);
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
@ -38,6 +38,6 @@ DWORD get_fattime(void) {
|
||||
timeutils_struct_time_t tm;
|
||||
timeutils_seconds_since_2000_to_struct_time(secs, &tm);
|
||||
|
||||
return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
|
||||
((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1));
|
||||
return ((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
|
||||
((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1);
|
||||
}
|
||||
|
@ -188,7 +188,9 @@ uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
|
||||
uint32_t addr_bits, uint32_t addr_data,
|
||||
uint32_t dout_bits, uint32_t dout_data,
|
||||
uint32_t din_bits, uint32_t dummy_bits) {
|
||||
while (spi_busy(spi_no)) {}; // Wait for SPI to be ready
|
||||
while (spi_busy(spi_no)) {
|
||||
}
|
||||
; // Wait for SPI to be ready
|
||||
|
||||
// Enable SPI Functions
|
||||
// Disable MOSI, MISO, ADDR, COMMAND, DUMMY in case previously set.
|
||||
@ -280,7 +282,9 @@ uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
|
||||
|
||||
// Return DIN data
|
||||
if (din_bits) {
|
||||
while (spi_busy(spi_no)) {}; // Wait for SPI transaction to complete
|
||||
while (spi_busy(spi_no)) {
|
||||
}
|
||||
; // Wait for SPI transaction to complete
|
||||
if (READ_PERI_REG(SPI_USER(spi_no)) & SPI_RD_BYTE_ORDER) {
|
||||
// Assuming data in is written to MSB. TBC
|
||||
return READ_PERI_REG(SPI_W0(spi_no)) >> (32 - din_bits);
|
||||
@ -301,7 +305,9 @@ uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
|
||||
Just do minimal work needed to send 8 bits.
|
||||
*/
|
||||
inline void spi_tx8fast(uint8_t spi_no, uint8_t dout_data) {
|
||||
while (spi_busy(spi_no)) {}; // Wait for SPI to be ready
|
||||
while (spi_busy(spi_no)) {
|
||||
}
|
||||
; // Wait for SPI to be ready
|
||||
|
||||
// Enable SPI Functions
|
||||
// Disable MOSI, MISO, ADDR, COMMAND, DUMMY in case previously set.
|
||||
|
@ -8,33 +8,33 @@ assert len(sys.argv) == 4
|
||||
|
||||
md5 = hashlib.md5()
|
||||
|
||||
with open(sys.argv[3], 'wb') as fout:
|
||||
with open(sys.argv[3], "wb") as fout:
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
with open(sys.argv[1], "rb") as f:
|
||||
data_flash = f.read()
|
||||
fout.write(data_flash)
|
||||
# First 4 bytes include flash size, etc. which may be changed
|
||||
# by esptool.py, etc.
|
||||
md5.update(data_flash[4:])
|
||||
print('flash ', len(data_flash))
|
||||
print("flash ", len(data_flash))
|
||||
|
||||
with open(sys.argv[2], 'rb') as f:
|
||||
with open(sys.argv[2], "rb") as f:
|
||||
data_rom = f.read()
|
||||
|
||||
pad = b'\xff' * (SEGS_MAX_SIZE - len(data_flash))
|
||||
pad = b"\xff" * (SEGS_MAX_SIZE - len(data_flash))
|
||||
assert len(pad) >= 4
|
||||
fout.write(pad[:-4])
|
||||
md5.update(pad[:-4])
|
||||
len_data = struct.pack("I", SEGS_MAX_SIZE + len(data_rom))
|
||||
fout.write(len_data)
|
||||
md5.update(len_data)
|
||||
print('padding ', len(pad))
|
||||
print("padding ", len(pad))
|
||||
|
||||
fout.write(data_rom)
|
||||
md5.update(data_rom)
|
||||
print('irom0text', len(data_rom))
|
||||
print("irom0text", len(data_rom))
|
||||
|
||||
fout.write(md5.digest())
|
||||
|
||||
print('total ', SEGS_MAX_SIZE + len(data_rom))
|
||||
print('md5 ', md5.hexdigest())
|
||||
print("total ", SEGS_MAX_SIZE + len(data_rom))
|
||||
print("md5 ", md5.hexdigest())
|
||||
|
@ -1,7 +1,7 @@
|
||||
print('uPy')
|
||||
print('a long string that is not interned')
|
||||
print('a string that has unicode αβγ chars')
|
||||
print(b'bytes 1234\x01')
|
||||
print("uPy")
|
||||
print("a long string that is not interned")
|
||||
print("a string that has unicode αβγ chars")
|
||||
print(b"bytes 1234\x01")
|
||||
print(123456789)
|
||||
for i in range(4):
|
||||
print(i)
|
||||
|
@ -84,11 +84,15 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
void nlr_jump_fail(void *val) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -1,2 +1,5 @@
|
||||
static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; }
|
||||
static inline void mp_hal_set_interrupt_char(char c) {}
|
||||
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
||||
return 0;
|
||||
}
|
||||
static inline void mp_hal_set_interrupt_char(char c) {
|
||||
}
|
||||
|
@ -294,8 +294,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
void HardFault_Handler(void) {
|
||||
#if defined(NRF52_SERIES)
|
||||
static volatile uint32_t reg;
|
||||
static volatile uint32_t reg2;
|
||||
@ -313,7 +312,9 @@ void HardFault_Handler(void)
|
||||
}
|
||||
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void nlr_jump_fail(void *val) {
|
||||
@ -327,4 +328,6 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
|
||||
__fatal_error("Assertion failed");
|
||||
}
|
||||
|
||||
void _start(void) {main(0, NULL);}
|
||||
void _start(void) {
|
||||
main(0, NULL);
|
||||
}
|
||||
|
@ -80,8 +80,7 @@ void mp_hal_stdout_tx_str(const char *str) {
|
||||
mp_hal_stdout_tx_strn(str, strlen(str));
|
||||
}
|
||||
|
||||
void mp_hal_delay_us(mp_uint_t us)
|
||||
{
|
||||
void mp_hal_delay_us(mp_uint_t us) {
|
||||
if (us == 0) {
|
||||
return;
|
||||
}
|
||||
@ -157,8 +156,7 @@ void mp_hal_delay_us(mp_uint_t us)
|
||||
: "+r" (delay));
|
||||
}
|
||||
|
||||
void mp_hal_delay_ms(mp_uint_t ms)
|
||||
{
|
||||
void mp_hal_delay_ms(mp_uint_t ms) {
|
||||
for (mp_uint_t i = 0; i < ms; i++)
|
||||
{
|
||||
mp_hal_delay_us(999);
|
||||
|
@ -79,17 +79,29 @@ void led_init(void) {
|
||||
void led_state(int led, int state) {
|
||||
int val = state ? LED_ON : LED_OFF;
|
||||
switch (led) {
|
||||
case 1: RED_LED = val; break;
|
||||
case 2: YELLOW_LED = val; break;
|
||||
case 3: GREEN_LED = val; break;
|
||||
case 1:
|
||||
RED_LED = val;
|
||||
break;
|
||||
case 2:
|
||||
YELLOW_LED = val;
|
||||
break;
|
||||
case 3:
|
||||
GREEN_LED = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void led_toggle(int led) {
|
||||
switch (led) {
|
||||
case 1: RED_LED ^= 1; break;
|
||||
case 2: YELLOW_LED ^= 1; break;
|
||||
case 3: GREEN_LED ^= 1; break;
|
||||
case 1:
|
||||
RED_LED ^= 1;
|
||||
break;
|
||||
case 2:
|
||||
YELLOW_LED ^= 1;
|
||||
break;
|
||||
case 3:
|
||||
GREEN_LED ^= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,8 +123,12 @@ void switch_init(void) {
|
||||
int switch_get(int sw) {
|
||||
int val = 1;
|
||||
switch (sw) {
|
||||
case 1: val = SWITCH_S1; break;
|
||||
case 2: val = SWITCH_S2; break;
|
||||
case 1:
|
||||
val = SWITCH_S1;
|
||||
break;
|
||||
case 2:
|
||||
val = SWITCH_S2;
|
||||
break;
|
||||
}
|
||||
return val == 0;
|
||||
}
|
||||
|
@ -115,11 +115,15 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
void nlr_jump_fail(void *val) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -289,8 +289,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) {
|
||||
#if defined(STM32L4) && defined(ADC_DUALMODE_REGSIMULT_INJECSIMULT)
|
||||
ADC_MultiModeTypeDef multimode;
|
||||
multimode.Mode = ADC_MODE_INDEPENDENT;
|
||||
if (HAL_ADCEx_MultiModeConfigChannel(&adc_obj->handle, &multimode) != HAL_OK)
|
||||
{
|
||||
if (HAL_ADCEx_MultiModeConfigChannel(&adc_obj->handle, &multimode) != HAL_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Can not set multimode on ADC1 channel: %d", adc_obj->channel));
|
||||
}
|
||||
#endif
|
||||
@ -672,13 +671,23 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution, uint32_t en_m
|
||||
|
||||
switch (resolution) {
|
||||
#if !defined(STM32H7)
|
||||
case 6: resolution = ADC_RESOLUTION_6B; break;
|
||||
case 6:
|
||||
resolution = ADC_RESOLUTION_6B;
|
||||
break;
|
||||
#endif
|
||||
case 8: resolution = ADC_RESOLUTION_8B; break;
|
||||
case 10: resolution = ADC_RESOLUTION_10B; break;
|
||||
case 12: resolution = ADC_RESOLUTION_12B; break;
|
||||
case 8:
|
||||
resolution = ADC_RESOLUTION_8B;
|
||||
break;
|
||||
case 10:
|
||||
resolution = ADC_RESOLUTION_10B;
|
||||
break;
|
||||
case 12:
|
||||
resolution = ADC_RESOLUTION_12B;
|
||||
break;
|
||||
#if defined(STM32H7)
|
||||
case 16: resolution = ADC_RESOLUTION_16B; break;
|
||||
case 16:
|
||||
resolution = ADC_RESOLUTION_16B;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
@ -705,12 +714,16 @@ int adc_get_resolution(ADC_HandleTypeDef *adcHandle) {
|
||||
|
||||
switch (res_reg) {
|
||||
#if !defined(STM32H7)
|
||||
case ADC_RESOLUTION_6B: return 6;
|
||||
case ADC_RESOLUTION_6B:
|
||||
return 6;
|
||||
#endif
|
||||
case ADC_RESOLUTION_8B: return 8;
|
||||
case ADC_RESOLUTION_10B: return 10;
|
||||
case ADC_RESOLUTION_8B:
|
||||
return 8;
|
||||
case ADC_RESOLUTION_10B:
|
||||
return 10;
|
||||
#if defined(STM32H7)
|
||||
case ADC_RESOLUTION_16B: return 16;
|
||||
case ADC_RESOLUTION_16B:
|
||||
return 16;
|
||||
#endif
|
||||
}
|
||||
return 12;
|
||||
|
@ -336,10 +336,19 @@ STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
} else {
|
||||
qstr mode;
|
||||
switch (self->can.Init.Mode) {
|
||||
case CAN_MODE_NORMAL: mode = MP_QSTR_NORMAL; break;
|
||||
case CAN_MODE_LOOPBACK: mode = MP_QSTR_LOOPBACK; break;
|
||||
case CAN_MODE_SILENT: mode = MP_QSTR_SILENT; break;
|
||||
case CAN_MODE_SILENT_LOOPBACK: default: mode = MP_QSTR_SILENT_LOOPBACK; break;
|
||||
case CAN_MODE_NORMAL:
|
||||
mode = MP_QSTR_NORMAL;
|
||||
break;
|
||||
case CAN_MODE_LOOPBACK:
|
||||
mode = MP_QSTR_LOOPBACK;
|
||||
break;
|
||||
case CAN_MODE_SILENT:
|
||||
mode = MP_QSTR_SILENT;
|
||||
break;
|
||||
case CAN_MODE_SILENT_LOOPBACK:
|
||||
default:
|
||||
mode = MP_QSTR_SILENT_LOOPBACK;
|
||||
break;
|
||||
}
|
||||
mp_printf(print, "CAN(%u, CAN.%q, extframe=%q, auto_restart=%q)",
|
||||
self->can_id,
|
||||
@ -855,8 +864,7 @@ STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
if (args[ARG_mode].u_int == LIST16) {
|
||||
filter.FilterMode = CAN_FILTERMODE_IDLIST;
|
||||
}
|
||||
}
|
||||
else if (args[ARG_mode].u_int == MASK32 || args[ARG_mode].u_int == LIST32) {
|
||||
} else if (args[ARG_mode].u_int == MASK32 || args[ARG_mode].u_int == LIST32) {
|
||||
if (len != 2) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -494,39 +494,219 @@ void DMA1_Ch4_7_DMA2_Ch3_5_IRQHandler(void) {
|
||||
|
||||
#elif defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
|
||||
|
||||
void DMA1_Stream0_IRQHandler(void) { IRQ_ENTER(DMA1_Stream0_IRQn); if (dma_handle[dma_id_0] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_0]); } IRQ_EXIT(DMA1_Stream0_IRQn); }
|
||||
void DMA1_Stream1_IRQHandler(void) { IRQ_ENTER(DMA1_Stream1_IRQn); if (dma_handle[dma_id_1] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_1]); } IRQ_EXIT(DMA1_Stream1_IRQn); }
|
||||
void DMA1_Stream2_IRQHandler(void) { IRQ_ENTER(DMA1_Stream2_IRQn); if (dma_handle[dma_id_2] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_2]); } IRQ_EXIT(DMA1_Stream2_IRQn); }
|
||||
void DMA1_Stream3_IRQHandler(void) { IRQ_ENTER(DMA1_Stream3_IRQn); if (dma_handle[dma_id_3] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_3]); } IRQ_EXIT(DMA1_Stream3_IRQn); }
|
||||
void DMA1_Stream4_IRQHandler(void) { IRQ_ENTER(DMA1_Stream4_IRQn); if (dma_handle[dma_id_4] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_4]); } IRQ_EXIT(DMA1_Stream4_IRQn); }
|
||||
void DMA1_Stream5_IRQHandler(void) { IRQ_ENTER(DMA1_Stream5_IRQn); if (dma_handle[dma_id_5] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_5]); } IRQ_EXIT(DMA1_Stream5_IRQn); }
|
||||
void DMA1_Stream6_IRQHandler(void) { IRQ_ENTER(DMA1_Stream6_IRQn); if (dma_handle[dma_id_6] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_6]); } IRQ_EXIT(DMA1_Stream6_IRQn); }
|
||||
void DMA1_Stream7_IRQHandler(void) { IRQ_ENTER(DMA1_Stream7_IRQn); if (dma_handle[dma_id_7] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_7]); } IRQ_EXIT(DMA1_Stream7_IRQn); }
|
||||
void DMA2_Stream0_IRQHandler(void) { IRQ_ENTER(DMA2_Stream0_IRQn); if (dma_handle[dma_id_8] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_8]); } IRQ_EXIT(DMA2_Stream0_IRQn); }
|
||||
void DMA2_Stream1_IRQHandler(void) { IRQ_ENTER(DMA2_Stream1_IRQn); if (dma_handle[dma_id_9] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_9]); } IRQ_EXIT(DMA2_Stream1_IRQn); }
|
||||
void DMA2_Stream2_IRQHandler(void) { IRQ_ENTER(DMA2_Stream2_IRQn); if (dma_handle[dma_id_10] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_10]); } IRQ_EXIT(DMA2_Stream2_IRQn); }
|
||||
void DMA2_Stream3_IRQHandler(void) { IRQ_ENTER(DMA2_Stream3_IRQn); if (dma_handle[dma_id_11] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_11]); } IRQ_EXIT(DMA2_Stream3_IRQn); }
|
||||
void DMA2_Stream4_IRQHandler(void) { IRQ_ENTER(DMA2_Stream4_IRQn); if (dma_handle[dma_id_12] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_12]); } IRQ_EXIT(DMA2_Stream4_IRQn); }
|
||||
void DMA2_Stream5_IRQHandler(void) { IRQ_ENTER(DMA2_Stream5_IRQn); if (dma_handle[dma_id_13] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_13]); } IRQ_EXIT(DMA2_Stream5_IRQn); }
|
||||
void DMA2_Stream6_IRQHandler(void) { IRQ_ENTER(DMA2_Stream6_IRQn); if (dma_handle[dma_id_14] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_14]); } IRQ_EXIT(DMA2_Stream6_IRQn); }
|
||||
void DMA2_Stream7_IRQHandler(void) { IRQ_ENTER(DMA2_Stream7_IRQn); if (dma_handle[dma_id_15] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_15]); } IRQ_EXIT(DMA2_Stream7_IRQn); }
|
||||
void DMA1_Stream0_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream0_IRQn);
|
||||
if (dma_handle[dma_id_0] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_0]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream0_IRQn);
|
||||
}
|
||||
void DMA1_Stream1_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream1_IRQn);
|
||||
if (dma_handle[dma_id_1] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_1]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream1_IRQn);
|
||||
}
|
||||
void DMA1_Stream2_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream2_IRQn);
|
||||
if (dma_handle[dma_id_2] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_2]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream2_IRQn);
|
||||
}
|
||||
void DMA1_Stream3_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream3_IRQn);
|
||||
if (dma_handle[dma_id_3] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_3]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream3_IRQn);
|
||||
}
|
||||
void DMA1_Stream4_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream4_IRQn);
|
||||
if (dma_handle[dma_id_4] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_4]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream4_IRQn);
|
||||
}
|
||||
void DMA1_Stream5_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream5_IRQn);
|
||||
if (dma_handle[dma_id_5] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_5]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream5_IRQn);
|
||||
}
|
||||
void DMA1_Stream6_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream6_IRQn);
|
||||
if (dma_handle[dma_id_6] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_6]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream6_IRQn);
|
||||
}
|
||||
void DMA1_Stream7_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Stream7_IRQn);
|
||||
if (dma_handle[dma_id_7] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_7]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Stream7_IRQn);
|
||||
}
|
||||
void DMA2_Stream0_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream0_IRQn);
|
||||
if (dma_handle[dma_id_8] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_8]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream0_IRQn);
|
||||
}
|
||||
void DMA2_Stream1_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream1_IRQn);
|
||||
if (dma_handle[dma_id_9] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_9]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream1_IRQn);
|
||||
}
|
||||
void DMA2_Stream2_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream2_IRQn);
|
||||
if (dma_handle[dma_id_10] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_10]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream2_IRQn);
|
||||
}
|
||||
void DMA2_Stream3_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream3_IRQn);
|
||||
if (dma_handle[dma_id_11] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_11]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream3_IRQn);
|
||||
}
|
||||
void DMA2_Stream4_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream4_IRQn);
|
||||
if (dma_handle[dma_id_12] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_12]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream4_IRQn);
|
||||
}
|
||||
void DMA2_Stream5_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream5_IRQn);
|
||||
if (dma_handle[dma_id_13] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_13]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream5_IRQn);
|
||||
}
|
||||
void DMA2_Stream6_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream6_IRQn);
|
||||
if (dma_handle[dma_id_14] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_14]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream6_IRQn);
|
||||
}
|
||||
void DMA2_Stream7_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Stream7_IRQn);
|
||||
if (dma_handle[dma_id_15] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_15]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Stream7_IRQn);
|
||||
}
|
||||
|
||||
#elif defined(STM32L4)
|
||||
|
||||
void DMA1_Channel1_IRQHandler(void) { IRQ_ENTER(DMA1_Channel1_IRQn); if (dma_handle[dma_id_0] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_0]); } IRQ_EXIT(DMA1_Channel1_IRQn); }
|
||||
void DMA1_Channel2_IRQHandler(void) { IRQ_ENTER(DMA1_Channel2_IRQn); if (dma_handle[dma_id_1] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_1]); } IRQ_EXIT(DMA1_Channel2_IRQn); }
|
||||
void DMA1_Channel3_IRQHandler(void) { IRQ_ENTER(DMA1_Channel3_IRQn); if (dma_handle[dma_id_2] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_2]); } IRQ_EXIT(DMA1_Channel3_IRQn); }
|
||||
void DMA1_Channel4_IRQHandler(void) { IRQ_ENTER(DMA1_Channel4_IRQn); if (dma_handle[dma_id_3] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_3]); } IRQ_EXIT(DMA1_Channel4_IRQn); }
|
||||
void DMA1_Channel5_IRQHandler(void) { IRQ_ENTER(DMA1_Channel5_IRQn); if (dma_handle[dma_id_4] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_4]); } IRQ_EXIT(DMA1_Channel5_IRQn); }
|
||||
void DMA1_Channel6_IRQHandler(void) { IRQ_ENTER(DMA1_Channel6_IRQn); if (dma_handle[dma_id_5] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_5]); } IRQ_EXIT(DMA1_Channel6_IRQn); }
|
||||
void DMA1_Channel7_IRQHandler(void) { IRQ_ENTER(DMA1_Channel7_IRQn); if (dma_handle[dma_id_6] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_6]); } IRQ_EXIT(DMA1_Channel7_IRQn); }
|
||||
void DMA2_Channel1_IRQHandler(void) { IRQ_ENTER(DMA2_Channel1_IRQn); if (dma_handle[dma_id_7] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_7]); } IRQ_EXIT(DMA2_Channel1_IRQn); }
|
||||
void DMA2_Channel2_IRQHandler(void) { IRQ_ENTER(DMA2_Channel2_IRQn); if (dma_handle[dma_id_8] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_8]); } IRQ_EXIT(DMA2_Channel2_IRQn); }
|
||||
void DMA2_Channel3_IRQHandler(void) { IRQ_ENTER(DMA2_Channel3_IRQn); if (dma_handle[dma_id_9] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_9]); } IRQ_EXIT(DMA2_Channel3_IRQn); }
|
||||
void DMA2_Channel4_IRQHandler(void) { IRQ_ENTER(DMA2_Channel4_IRQn); if (dma_handle[dma_id_10] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_10]);} IRQ_EXIT(DMA2_Channel4_IRQn); }
|
||||
void DMA2_Channel5_IRQHandler(void) { IRQ_ENTER(DMA2_Channel5_IRQn); if (dma_handle[dma_id_11] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_11]);} IRQ_EXIT(DMA2_Channel5_IRQn); }
|
||||
void DMA2_Channel6_IRQHandler(void) { IRQ_ENTER(DMA2_Channel6_IRQn); if (dma_handle[dma_id_12] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_12]);} IRQ_EXIT(DMA2_Channel6_IRQn); }
|
||||
void DMA2_Channel7_IRQHandler(void) { IRQ_ENTER(DMA2_Channel7_IRQn); if (dma_handle[dma_id_13] != NULL) { HAL_DMA_IRQHandler(dma_handle[dma_id_13]);} IRQ_EXIT(DMA2_Channel7_IRQn); }
|
||||
void DMA1_Channel1_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel1_IRQn);
|
||||
if (dma_handle[dma_id_0] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_0]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel1_IRQn);
|
||||
}
|
||||
void DMA1_Channel2_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel2_IRQn);
|
||||
if (dma_handle[dma_id_1] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_1]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel2_IRQn);
|
||||
}
|
||||
void DMA1_Channel3_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel3_IRQn);
|
||||
if (dma_handle[dma_id_2] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_2]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel3_IRQn);
|
||||
}
|
||||
void DMA1_Channel4_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel4_IRQn);
|
||||
if (dma_handle[dma_id_3] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_3]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel4_IRQn);
|
||||
}
|
||||
void DMA1_Channel5_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel5_IRQn);
|
||||
if (dma_handle[dma_id_4] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_4]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel5_IRQn);
|
||||
}
|
||||
void DMA1_Channel6_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel6_IRQn);
|
||||
if (dma_handle[dma_id_5] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_5]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel6_IRQn);
|
||||
}
|
||||
void DMA1_Channel7_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA1_Channel7_IRQn);
|
||||
if (dma_handle[dma_id_6] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_6]);
|
||||
}
|
||||
IRQ_EXIT(DMA1_Channel7_IRQn);
|
||||
}
|
||||
void DMA2_Channel1_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel1_IRQn);
|
||||
if (dma_handle[dma_id_7] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_7]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel1_IRQn);
|
||||
}
|
||||
void DMA2_Channel2_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel2_IRQn);
|
||||
if (dma_handle[dma_id_8] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_8]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel2_IRQn);
|
||||
}
|
||||
void DMA2_Channel3_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel3_IRQn);
|
||||
if (dma_handle[dma_id_9] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_9]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel3_IRQn);
|
||||
}
|
||||
void DMA2_Channel4_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel4_IRQn);
|
||||
if (dma_handle[dma_id_10] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_10]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel4_IRQn);
|
||||
}
|
||||
void DMA2_Channel5_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel5_IRQn);
|
||||
if (dma_handle[dma_id_11] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_11]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel5_IRQn);
|
||||
}
|
||||
void DMA2_Channel6_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel6_IRQn);
|
||||
if (dma_handle[dma_id_12] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_12]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel6_IRQn);
|
||||
}
|
||||
void DMA2_Channel7_IRQHandler(void) {
|
||||
IRQ_ENTER(DMA2_Channel7_IRQn);
|
||||
if (dma_handle[dma_id_13] != NULL) {
|
||||
HAL_DMA_IRQHandler(dma_handle[dma_id_13]);
|
||||
}
|
||||
IRQ_EXIT(DMA2_Channel7_IRQn);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -178,7 +178,8 @@ void flash_erase(uint32_t flash_dest, uint32_t num_word32) {
|
||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
EraseInitStruct.Banks = get_bank(flash_dest);
|
||||
EraseInitStruct.Page = get_page(flash_dest);
|
||||
EraseInitStruct.NbPages = get_page(flash_dest + 4 * num_word32 - 1) - EraseInitStruct.Page + 1;;
|
||||
EraseInitStruct.NbPages = get_page(flash_dest + 4 * num_word32 - 1) - EraseInitStruct.Page + 1;
|
||||
;
|
||||
#else
|
||||
// Clear pending flags (if any)
|
||||
#if defined(STM32H7)
|
||||
|
@ -236,14 +236,23 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
spi_clock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
uint br_prescale = spi_clock / 16000000; // datasheet says LCD can run at 20MHz, but we go for 16MHz
|
||||
if (br_prescale <= 2) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; }
|
||||
else if (br_prescale <= 4) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; }
|
||||
else if (br_prescale <= 8) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; }
|
||||
else if (br_prescale <= 16) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; }
|
||||
else if (br_prescale <= 32) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; }
|
||||
else if (br_prescale <= 64) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; }
|
||||
else if (br_prescale <= 128) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; }
|
||||
else { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; }
|
||||
if (br_prescale <= 2) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
} else if (br_prescale <= 4) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
} else if (br_prescale <= 8) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
||||
} else if (br_prescale <= 16) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||
} else if (br_prescale <= 32) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
||||
} else if (br_prescale <= 64) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
||||
} else if (br_prescale <= 128) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||
} else {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
|
||||
}
|
||||
|
||||
// data is sent bigendian, latches on rising clock
|
||||
init->CLKPolarity = SPI_POLARITY_HIGH;
|
||||
|
@ -135,10 +135,17 @@ STATIC void led_pwm_init(int led) {
|
||||
|
||||
// TIM configuration
|
||||
switch (pwm_cfg->tim_id) {
|
||||
case 1: __TIM1_CLK_ENABLE(); break;
|
||||
case 2: __TIM2_CLK_ENABLE(); break;
|
||||
case 3: __TIM3_CLK_ENABLE(); break;
|
||||
default: assert(0);
|
||||
case 1:
|
||||
__TIM1_CLK_ENABLE();
|
||||
break;
|
||||
case 2:
|
||||
__TIM2_CLK_ENABLE();
|
||||
break;
|
||||
case 3:
|
||||
__TIM3_CLK_ENABLE();
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
TIM_HandleTypeDef tim = {0};
|
||||
tim.Instance = pwm_cfg->tim;
|
||||
|
@ -272,8 +272,12 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
|
||||
// stop bits
|
||||
uint32_t stop;
|
||||
switch (args.stop.u_int) {
|
||||
case 1: stop = UART_STOPBITS_1; break;
|
||||
default: stop = UART_STOPBITS_2; break;
|
||||
case 1:
|
||||
stop = UART_STOPBITS_1;
|
||||
break;
|
||||
default:
|
||||
stop = UART_STOPBITS_2;
|
||||
break;
|
||||
}
|
||||
|
||||
// flow control
|
||||
|
@ -11,16 +11,23 @@ import re
|
||||
|
||||
# Python 2/3 compatibility
|
||||
import platform
|
||||
if platform.python_version_tuple()[0] == '2':
|
||||
|
||||
if platform.python_version_tuple()[0] == "2":
|
||||
|
||||
def convert_bytes_to_str(b):
|
||||
return b
|
||||
elif platform.python_version_tuple()[0] == '3':
|
||||
|
||||
|
||||
elif platform.python_version_tuple()[0] == "3":
|
||||
|
||||
def convert_bytes_to_str(b):
|
||||
try:
|
||||
return str(b, 'utf8')
|
||||
return str(b, "utf8")
|
||||
except ValueError:
|
||||
# some files have invalid utf8 bytes, so filter them out
|
||||
return ''.join(chr(l) for l in b if l <= 126)
|
||||
return "".join(chr(l) for l in b if l <= 126)
|
||||
|
||||
|
||||
# end compatibility code
|
||||
|
||||
# given a list of (name,regex) pairs, find the first one that matches the given line
|
||||
@ -31,29 +38,62 @@ def re_match_first(regexs, line):
|
||||
return name, match
|
||||
return None, None
|
||||
|
||||
|
||||
class LexerError(Exception):
|
||||
def __init__(self, line):
|
||||
self.line = line
|
||||
|
||||
|
||||
class Lexer:
|
||||
re_io_reg = r'__IO uint(?P<bits>8|16|32)_t +(?P<reg>[A-Z0-9]+)'
|
||||
re_comment = r'(?P<comment>[A-Za-z0-9 \-/_()&]+)'
|
||||
re_addr_offset = r'Address offset: (?P<offset>0x[0-9A-Z]{2,3})'
|
||||
re_io_reg = r"__IO uint(?P<bits>8|16|32)_t +(?P<reg>[A-Z0-9]+)"
|
||||
re_comment = r"(?P<comment>[A-Za-z0-9 \-/_()&]+)"
|
||||
re_addr_offset = r"Address offset: (?P<offset>0x[0-9A-Z]{2,3})"
|
||||
regexs = (
|
||||
('#define hex', re.compile(r'#define +(?P<id>[A-Z0-9_]+) +(?:\(\(uint32_t\))?(?P<hex>0x[0-9A-F]+)U?(?:\))?($| +/\*)')),
|
||||
('#define X', re.compile(r'#define +(?P<id>[A-Z0-9_]+) +(?P<id2>[A-Z0-9_]+)($| +/\*)')),
|
||||
('#define X+hex', re.compile(r'#define +(?P<id>[A-Za-z0-9_]+) +\((?P<id2>[A-Z0-9_]+) \+ (?P<hex>0x[0-9A-F]+)U?\)($| +/\*)')),
|
||||
('#define typedef', re.compile(r'#define +(?P<id>[A-Z0-9_]+(ext)?) +\(\([A-Za-z0-9_]+_TypeDef \*\) (?P<id2>[A-Za-z0-9_]+)\)($| +/\*)')),
|
||||
('typedef struct', re.compile(r'typedef struct$')),
|
||||
('{', re.compile(r'{$')),
|
||||
('}', re.compile(r'}$')),
|
||||
('} TypeDef', re.compile(r'} *(?P<id>[A-Z][A-Za-z0-9_]+)_(?P<global>([A-Za-z0-9_]+)?)TypeDef;$')),
|
||||
('IO reg', re.compile(re_io_reg + r'; +/\*!< ' + re_comment + r', +' + re_addr_offset + r' *\*/')),
|
||||
('IO reg array', re.compile(re_io_reg + r'\[(?P<array>[2-8])\]; +/\*!< ' + re_comment + r', +' + re_addr_offset + r'-(0x[0-9A-Z]{2,3}) *\*/')),
|
||||
(
|
||||
"#define hex",
|
||||
re.compile(
|
||||
r"#define +(?P<id>[A-Z0-9_]+) +(?:\(\(uint32_t\))?(?P<hex>0x[0-9A-F]+)U?(?:\))?($| +/\*)"
|
||||
),
|
||||
),
|
||||
("#define X", re.compile(r"#define +(?P<id>[A-Z0-9_]+) +(?P<id2>[A-Z0-9_]+)($| +/\*)")),
|
||||
(
|
||||
"#define X+hex",
|
||||
re.compile(
|
||||
r"#define +(?P<id>[A-Za-z0-9_]+) +\((?P<id2>[A-Z0-9_]+) \+ (?P<hex>0x[0-9A-F]+)U?\)($| +/\*)"
|
||||
),
|
||||
),
|
||||
(
|
||||
"#define typedef",
|
||||
re.compile(
|
||||
r"#define +(?P<id>[A-Z0-9_]+(ext)?) +\(\([A-Za-z0-9_]+_TypeDef \*\) (?P<id2>[A-Za-z0-9_]+)\)($| +/\*)"
|
||||
),
|
||||
),
|
||||
("typedef struct", re.compile(r"typedef struct$")),
|
||||
("{", re.compile(r"{$")),
|
||||
("}", re.compile(r"}$")),
|
||||
(
|
||||
"} TypeDef",
|
||||
re.compile(r"} *(?P<id>[A-Z][A-Za-z0-9_]+)_(?P<global>([A-Za-z0-9_]+)?)TypeDef;$"),
|
||||
),
|
||||
(
|
||||
"IO reg",
|
||||
re.compile(re_io_reg + r"; +/\*!< " + re_comment + r", +" + re_addr_offset + r" *\*/"),
|
||||
),
|
||||
(
|
||||
"IO reg array",
|
||||
re.compile(
|
||||
re_io_reg
|
||||
+ r"\[(?P<array>[2-8])\]; +/\*!< "
|
||||
+ re_comment
|
||||
+ r", +"
|
||||
+ re_addr_offset
|
||||
+ r"-(0x[0-9A-Z]{2,3}) *\*/"
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
def __init__(self, filename):
|
||||
self.file = open(filename, 'rb')
|
||||
self.file = open(filename, "rb")
|
||||
self.line_number = 0
|
||||
|
||||
def next_match(self, strictly_next=False):
|
||||
@ -62,7 +102,7 @@ class Lexer:
|
||||
line = convert_bytes_to_str(line)
|
||||
self.line_number += 1
|
||||
if len(line) == 0:
|
||||
return ('EOF', None)
|
||||
return ("EOF", None)
|
||||
match = re_match_first(Lexer.regexs, line.strip())
|
||||
if strictly_next or match[0] is not None:
|
||||
return match
|
||||
@ -73,6 +113,7 @@ class Lexer:
|
||||
raise LexerError(self.line_number)
|
||||
return match
|
||||
|
||||
|
||||
def parse_file(filename):
|
||||
lexer = Lexer(filename)
|
||||
|
||||
@ -81,71 +122,75 @@ def parse_file(filename):
|
||||
periphs = []
|
||||
while True:
|
||||
m = lexer.next_match()
|
||||
if m[0] == 'EOF':
|
||||
if m[0] == "EOF":
|
||||
break
|
||||
elif m[0] == '#define hex':
|
||||
elif m[0] == "#define hex":
|
||||
d = m[1].groupdict()
|
||||
consts[d['id']] = int(d['hex'], base=16)
|
||||
elif m[0] == '#define X':
|
||||
consts[d["id"]] = int(d["hex"], base=16)
|
||||
elif m[0] == "#define X":
|
||||
d = m[1].groupdict()
|
||||
if d['id2'] in consts:
|
||||
consts[d['id']] = consts[d['id2']]
|
||||
elif m[0] == '#define X+hex':
|
||||
if d["id2"] in consts:
|
||||
consts[d["id"]] = consts[d["id2"]]
|
||||
elif m[0] == "#define X+hex":
|
||||
d = m[1].groupdict()
|
||||
if d['id2'] in consts:
|
||||
consts[d['id']] = consts[d['id2']] + int(d['hex'], base=16)
|
||||
elif m[0] == '#define typedef':
|
||||
if d["id2"] in consts:
|
||||
consts[d["id"]] = consts[d["id2"]] + int(d["hex"], base=16)
|
||||
elif m[0] == "#define typedef":
|
||||
d = m[1].groupdict()
|
||||
if d['id2'] in consts:
|
||||
periphs.append((d['id'], consts[d['id2']]))
|
||||
elif m[0] == 'typedef struct':
|
||||
lexer.must_match('{')
|
||||
if d["id2"] in consts:
|
||||
periphs.append((d["id"], consts[d["id2"]]))
|
||||
elif m[0] == "typedef struct":
|
||||
lexer.must_match("{")
|
||||
m = lexer.next_match()
|
||||
regs = []
|
||||
while m[0] in ('IO reg', 'IO reg array'):
|
||||
while m[0] in ("IO reg", "IO reg array"):
|
||||
d = m[1].groupdict()
|
||||
reg = d['reg']
|
||||
offset = int(d['offset'], base=16)
|
||||
bits = int(d['bits'])
|
||||
comment = d['comment']
|
||||
if m[0] == 'IO reg':
|
||||
reg = d["reg"]
|
||||
offset = int(d["offset"], base=16)
|
||||
bits = int(d["bits"])
|
||||
comment = d["comment"]
|
||||
if m[0] == "IO reg":
|
||||
regs.append((reg, offset, bits, comment))
|
||||
else:
|
||||
for i in range(int(d['array'])):
|
||||
for i in range(int(d["array"])):
|
||||
regs.append((reg + str(i), offset + i * bits // 8, bits, comment))
|
||||
m = lexer.next_match()
|
||||
if m[0] == '}':
|
||||
if m[0] == "}":
|
||||
pass
|
||||
elif m[0] == '} TypeDef':
|
||||
reg_defs[m[1].groupdict()['id']] = regs
|
||||
elif m[0] == "} TypeDef":
|
||||
reg_defs[m[1].groupdict()["id"]] = regs
|
||||
else:
|
||||
raise LexerError(lexer.line_number)
|
||||
|
||||
return periphs, reg_defs
|
||||
|
||||
|
||||
def print_int_obj(val, needed_mpzs):
|
||||
if -0x40000000 <= val < 0x40000000:
|
||||
print('MP_ROM_INT(%#x)' % val, end='')
|
||||
print("MP_ROM_INT(%#x)" % val, end="")
|
||||
else:
|
||||
print('MP_ROM_PTR(&mpz_%08x)' % val, end='')
|
||||
print("MP_ROM_PTR(&mpz_%08x)" % val, end="")
|
||||
needed_mpzs.add(val)
|
||||
|
||||
|
||||
def print_periph(periph_name, periph_val, needed_qstrs, needed_mpzs):
|
||||
qstr = periph_name.upper()
|
||||
print('{ MP_ROM_QSTR(MP_QSTR_%s), ' % qstr, end='')
|
||||
print("{ MP_ROM_QSTR(MP_QSTR_%s), " % qstr, end="")
|
||||
print_int_obj(periph_val, needed_mpzs)
|
||||
print(' },')
|
||||
print(" },")
|
||||
needed_qstrs.add(qstr)
|
||||
|
||||
|
||||
def print_regs(reg_name, reg_defs, needed_qstrs, needed_mpzs):
|
||||
reg_name = reg_name.upper()
|
||||
for r in reg_defs:
|
||||
qstr = reg_name + '_' + r[0]
|
||||
print('{ MP_ROM_QSTR(MP_QSTR_%s), ' % qstr, end='')
|
||||
qstr = reg_name + "_" + r[0]
|
||||
print("{ MP_ROM_QSTR(MP_QSTR_%s), " % qstr, end="")
|
||||
print_int_obj(r[1], needed_mpzs)
|
||||
print(' }, // %s-bits, %s' % (r[2], r[3]))
|
||||
print(" }, // %s-bits, %s" % (r[2], r[3]))
|
||||
needed_qstrs.add(qstr)
|
||||
|
||||
|
||||
# This version of print regs groups registers together into submodules (eg GPIO submodule).
|
||||
# This makes the qstrs shorter, and makes the list of constants more manageable (since
|
||||
# they are not all in one big module) but it is then harder to compile the constants, and
|
||||
@ -154,21 +199,28 @@ def print_regs(reg_name, reg_defs, needed_qstrs, needed_mpzs):
|
||||
# And for the number of constants we have, this function seems to use about the same amount
|
||||
# of ROM as print_regs.
|
||||
def print_regs_as_submodules(reg_name, reg_defs, modules, needed_qstrs):
|
||||
mod_name_lower = reg_name.lower() + '_'
|
||||
mod_name_lower = reg_name.lower() + "_"
|
||||
mod_name_upper = mod_name_lower.upper()
|
||||
modules.append((mod_name_lower, mod_name_upper))
|
||||
|
||||
print("""
|
||||
print(
|
||||
"""
|
||||
STATIC const mp_rom_map_elem_t stm_%s_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_%s) },
|
||||
""" % (mod_name_lower, mod_name_upper))
|
||||
"""
|
||||
% (mod_name_lower, mod_name_upper)
|
||||
)
|
||||
needed_qstrs.add(mod_name_upper)
|
||||
|
||||
for r in reg_defs:
|
||||
print(' { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_INT(%#x) }, // %s-bits, %s' % (r[0], r[1], r[2], r[3]))
|
||||
print(
|
||||
" { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_INT(%#x) }, // %s-bits, %s"
|
||||
% (r[0], r[1], r[2], r[3])
|
||||
)
|
||||
needed_qstrs.add(r[0])
|
||||
|
||||
print("""};
|
||||
print(
|
||||
"""};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(stm_%s_globals, stm_%s_globals_table);
|
||||
|
||||
@ -177,23 +229,35 @@ const mp_obj_module_t stm_%s_obj = {
|
||||
.name = MP_QSTR_%s,
|
||||
.globals = (mp_obj_dict_t*)&stm_%s_globals,
|
||||
};
|
||||
""" % (mod_name_lower, mod_name_lower, mod_name_lower, mod_name_upper, mod_name_lower))
|
||||
"""
|
||||
% (mod_name_lower, mod_name_lower, mod_name_lower, mod_name_upper, mod_name_lower)
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
cmd_parser = argparse.ArgumentParser(description='Extract ST constants from a C header file.')
|
||||
cmd_parser.add_argument('file', nargs=1, help='input file')
|
||||
cmd_parser.add_argument('-q', '--qstr', dest='qstr_filename', default='build/stmconst_qstr.h',
|
||||
help='Specified the name of the generated qstr header file')
|
||||
cmd_parser.add_argument('--mpz', dest='mpz_filename', default='build/stmconst_mpz.h',
|
||||
help='the destination file of the generated mpz header')
|
||||
cmd_parser = argparse.ArgumentParser(description="Extract ST constants from a C header file.")
|
||||
cmd_parser.add_argument("file", nargs=1, help="input file")
|
||||
cmd_parser.add_argument(
|
||||
"-q",
|
||||
"--qstr",
|
||||
dest="qstr_filename",
|
||||
default="build/stmconst_qstr.h",
|
||||
help="Specified the name of the generated qstr header file",
|
||||
)
|
||||
cmd_parser.add_argument(
|
||||
"--mpz",
|
||||
dest="mpz_filename",
|
||||
default="build/stmconst_mpz.h",
|
||||
help="the destination file of the generated mpz header",
|
||||
)
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
periphs, reg_defs = parse_file(args.file[0])
|
||||
|
||||
# add legacy GPIO constants that were removed when upgrading CMSIS
|
||||
if 'GPIO' in reg_defs and 'stm32f4' in args.file[0]:
|
||||
reg_defs['GPIO'].append(['BSRRL', 0x18, 16, 'legacy register'])
|
||||
reg_defs['GPIO'].append(['BSRRH', 0x1a, 16, 'legacy register'])
|
||||
if "GPIO" in reg_defs and "stm32f4" in args.file[0]:
|
||||
reg_defs["GPIO"].append(["BSRRL", 0x18, 16, "legacy register"])
|
||||
reg_defs["GPIO"].append(["BSRRH", 0x1A, 16, "legacy register"])
|
||||
|
||||
modules = []
|
||||
needed_qstrs = set()
|
||||
@ -206,32 +270,32 @@ def main():
|
||||
print_periph(periph_name, periph_val, needed_qstrs, needed_mpzs)
|
||||
|
||||
for reg in (
|
||||
'ADC',
|
||||
"ADC",
|
||||
#'ADC_Common',
|
||||
#'CAN_TxMailBox',
|
||||
#'CAN_FIFOMailBox',
|
||||
#'CAN_FilterRegister',
|
||||
#'CAN',
|
||||
'CRC',
|
||||
'DAC',
|
||||
'DBGMCU',
|
||||
'DMA_Stream',
|
||||
'DMA',
|
||||
'EXTI',
|
||||
'FLASH',
|
||||
'GPIO',
|
||||
'SYSCFG',
|
||||
'I2C',
|
||||
'IWDG',
|
||||
'PWR',
|
||||
'RCC',
|
||||
'RTC',
|
||||
"CRC",
|
||||
"DAC",
|
||||
"DBGMCU",
|
||||
"DMA_Stream",
|
||||
"DMA",
|
||||
"EXTI",
|
||||
"FLASH",
|
||||
"GPIO",
|
||||
"SYSCFG",
|
||||
"I2C",
|
||||
"IWDG",
|
||||
"PWR",
|
||||
"RCC",
|
||||
"RTC",
|
||||
#'SDIO',
|
||||
'SPI',
|
||||
'TIM',
|
||||
'USART',
|
||||
'WWDG',
|
||||
'RNG',
|
||||
"SPI",
|
||||
"TIM",
|
||||
"USART",
|
||||
"WWDG",
|
||||
"RNG",
|
||||
):
|
||||
if reg in reg_defs:
|
||||
print_regs(reg, reg_defs[reg], needed_qstrs, needed_mpzs)
|
||||
@ -243,18 +307,23 @@ def main():
|
||||
|
||||
print("")
|
||||
|
||||
with open(args.qstr_filename, 'wt') as qstr_file:
|
||||
print('#if MICROPY_PY_STM', file=qstr_file)
|
||||
with open(args.qstr_filename, "wt") as qstr_file:
|
||||
print("#if MICROPY_PY_STM", file=qstr_file)
|
||||
for qstr in sorted(needed_qstrs):
|
||||
print('Q({})'.format(qstr), file=qstr_file)
|
||||
print('#endif // MICROPY_PY_STM', file=qstr_file)
|
||||
print("Q({})".format(qstr), file=qstr_file)
|
||||
print("#endif // MICROPY_PY_STM", file=qstr_file)
|
||||
|
||||
with open(args.mpz_filename, 'wt') as mpz_file:
|
||||
with open(args.mpz_filename, "wt") as mpz_file:
|
||||
for mpz in sorted(needed_mpzs):
|
||||
assert 0 <= mpz <= 0xffffffff
|
||||
print('STATIC const mp_obj_int_t mpz_%08x = {{&mp_type_int}, '
|
||||
'{.neg=0, .fixed_dig=1, .alloc=2, .len=2, ' '.dig=(uint16_t*)(const uint16_t[]){%#x, %#x}}};'
|
||||
% (mpz, mpz & 0xffff, (mpz >> 16) & 0xffff), file=mpz_file)
|
||||
assert 0 <= mpz <= 0xFFFFFFFF
|
||||
print(
|
||||
"STATIC const mp_obj_int_t mpz_%08x = {{&mp_type_int}, "
|
||||
"{.neg=0, .fixed_dig=1, .alloc=2, .len=2, "
|
||||
".dig=(uint16_t*)(const uint16_t[]){%#x, %#x}}};"
|
||||
% (mpz, mpz & 0xFFFF, (mpz >> 16) & 0xFFFF),
|
||||
file=mpz_file,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -281,7 +281,9 @@ STATIC NORETURN mp_obj_t machine_bootloader(void) {
|
||||
((void (*)(void)) * ((uint32_t *)0x00000004))();
|
||||
#endif
|
||||
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_bootloader_obj, machine_bootloader);
|
||||
|
||||
|
@ -143,10 +143,18 @@ STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
|
||||
|
||||
mp_uint_t type;
|
||||
switch (socket->u_param.type) {
|
||||
case MOD_NETWORK_SOCK_STREAM: type = SOCK_STREAM; break;
|
||||
case MOD_NETWORK_SOCK_DGRAM: type = SOCK_DGRAM; break;
|
||||
case MOD_NETWORK_SOCK_RAW: type = SOCK_RAW; break;
|
||||
default: *_errno = MP_EINVAL; return -1;
|
||||
case MOD_NETWORK_SOCK_STREAM:
|
||||
type = SOCK_STREAM;
|
||||
break;
|
||||
case MOD_NETWORK_SOCK_DGRAM:
|
||||
type = SOCK_DGRAM;
|
||||
break;
|
||||
case MOD_NETWORK_SOCK_RAW:
|
||||
type = SOCK_RAW;
|
||||
break;
|
||||
default:
|
||||
*_errno = MP_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// open socket
|
||||
|
@ -105,9 +105,15 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno)
|
||||
}
|
||||
|
||||
switch (socket->u_param.type) {
|
||||
case MOD_NETWORK_SOCK_STREAM: socket->u_param.type = Sn_MR_TCP; break;
|
||||
case MOD_NETWORK_SOCK_DGRAM: socket->u_param.type = Sn_MR_UDP; break;
|
||||
default: *_errno = MP_EINVAL; return -1;
|
||||
case MOD_NETWORK_SOCK_STREAM:
|
||||
socket->u_param.type = Sn_MR_TCP;
|
||||
break;
|
||||
case MOD_NETWORK_SOCK_DGRAM:
|
||||
socket->u_param.type = Sn_MR_UDP;
|
||||
break;
|
||||
default:
|
||||
*_errno = MP_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (socket->u_param.fileno == -1) {
|
||||
|
@ -109,23 +109,39 @@ int powerctrl_rcc_clock_config_pll(RCC_ClkInitTypeDef *rcc_init, uint32_t sysclk
|
||||
#if !(defined(STM32F0) || defined(STM32L4))
|
||||
|
||||
STATIC uint32_t calc_ahb_div(uint32_t wanted_div) {
|
||||
if (wanted_div <= 1) { return RCC_SYSCLK_DIV1; }
|
||||
else if (wanted_div <= 2) { return RCC_SYSCLK_DIV2; }
|
||||
else if (wanted_div <= 4) { return RCC_SYSCLK_DIV4; }
|
||||
else if (wanted_div <= 8) { return RCC_SYSCLK_DIV8; }
|
||||
else if (wanted_div <= 16) { return RCC_SYSCLK_DIV16; }
|
||||
else if (wanted_div <= 64) { return RCC_SYSCLK_DIV64; }
|
||||
else if (wanted_div <= 128) { return RCC_SYSCLK_DIV128; }
|
||||
else if (wanted_div <= 256) { return RCC_SYSCLK_DIV256; }
|
||||
else { return RCC_SYSCLK_DIV512; }
|
||||
if (wanted_div <= 1) {
|
||||
return RCC_SYSCLK_DIV1;
|
||||
} else if (wanted_div <= 2) {
|
||||
return RCC_SYSCLK_DIV2;
|
||||
} else if (wanted_div <= 4) {
|
||||
return RCC_SYSCLK_DIV4;
|
||||
} else if (wanted_div <= 8) {
|
||||
return RCC_SYSCLK_DIV8;
|
||||
} else if (wanted_div <= 16) {
|
||||
return RCC_SYSCLK_DIV16;
|
||||
} else if (wanted_div <= 64) {
|
||||
return RCC_SYSCLK_DIV64;
|
||||
} else if (wanted_div <= 128) {
|
||||
return RCC_SYSCLK_DIV128;
|
||||
} else if (wanted_div <= 256) {
|
||||
return RCC_SYSCLK_DIV256;
|
||||
} else {
|
||||
return RCC_SYSCLK_DIV512;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC uint32_t calc_apb_div(uint32_t wanted_div) {
|
||||
if (wanted_div <= 1) { return RCC_HCLK_DIV1; }
|
||||
else if (wanted_div <= 2) { return RCC_HCLK_DIV2; }
|
||||
else if (wanted_div <= 4) { return RCC_HCLK_DIV4; }
|
||||
else if (wanted_div <= 8) { return RCC_HCLK_DIV8; }
|
||||
else { return RCC_SYSCLK_DIV16; }
|
||||
if (wanted_div <= 1) {
|
||||
return RCC_HCLK_DIV1;
|
||||
} else if (wanted_div <= 2) {
|
||||
return RCC_HCLK_DIV2;
|
||||
} else if (wanted_div <= 4) {
|
||||
return RCC_HCLK_DIV4;
|
||||
} else if (wanted_div <= 8) {
|
||||
return RCC_HCLK_DIV8;
|
||||
} else {
|
||||
return RCC_SYSCLK_DIV16;
|
||||
}
|
||||
}
|
||||
|
||||
int powerctrl_set_sysclk(uint32_t sysclk, uint32_t ahb, uint32_t apb1, uint32_t apb2) {
|
||||
|
@ -540,24 +540,35 @@ STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings */
|
||||
|
||||
static inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; }
|
||||
static inline bool in_master_mode(pyb_i2c_obj_t *self) {
|
||||
return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS;
|
||||
}
|
||||
|
||||
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
uint i2c_num = 0;
|
||||
if (0) { }
|
||||
if (0) {
|
||||
}
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
else if (self->i2c->Instance == I2C1) { i2c_num = 1; }
|
||||
else if (self->i2c->Instance == I2C1) {
|
||||
i2c_num = 1;
|
||||
}
|
||||
#endif
|
||||
#if defined(MICROPY_HW_I2C2_SCL)
|
||||
else if (self->i2c->Instance == I2C2) { i2c_num = 2; }
|
||||
else if (self->i2c->Instance == I2C2) {
|
||||
i2c_num = 2;
|
||||
}
|
||||
#endif
|
||||
#if defined(MICROPY_HW_I2C3_SCL)
|
||||
else if (self->i2c->Instance == I2C3) { i2c_num = 3; }
|
||||
else if (self->i2c->Instance == I2C3) {
|
||||
i2c_num = 3;
|
||||
}
|
||||
#endif
|
||||
#if defined(MICROPY_HW_I2C4_SCL)
|
||||
else if (self->i2c->Instance == I2C4) { i2c_num = 4; }
|
||||
else if (self->i2c->Instance == I2C4) {
|
||||
i2c_num = 4;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (self->i2c->State == HAL_I2C_STATE_RESET) {
|
||||
|
@ -91,7 +91,8 @@ STATIC bool lse_magic(void) {
|
||||
while (i) {
|
||||
GPIOC->MODER = mode_out;
|
||||
GPIOC->MODER = mode_in;
|
||||
for (j = 0; j < d; j++) ;
|
||||
for (j = 0; j < d; j++) {;
|
||||
}
|
||||
i--;
|
||||
if ((GPIOC->IDR & 0x8000) == 0) {
|
||||
tc++;
|
||||
|
@ -173,8 +173,7 @@ void *sdram_end(void) {
|
||||
}
|
||||
|
||||
static void sdram_init_seq(SDRAM_HandleTypeDef
|
||||
*hsdram, FMC_SDRAM_CommandTypeDef *command)
|
||||
{
|
||||
*hsdram, FMC_SDRAM_CommandTypeDef *command) {
|
||||
/* Program the SDRAM external device */
|
||||
__IO uint32_t tmpmrd = 0;
|
||||
|
||||
|
@ -153,13 +153,25 @@ STATIC void servo_init_channel(pyb_servo_obj_t *s) {
|
||||
STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) {
|
||||
int p = mp_obj_get_int(port);
|
||||
int v = mp_obj_get_int(value);
|
||||
if (v < 50) { v = 50; }
|
||||
if (v > 250) { v = 250; }
|
||||
if (v < 50) {
|
||||
v = 50;
|
||||
}
|
||||
if (v > 250) {
|
||||
v = 250;
|
||||
}
|
||||
switch (p) {
|
||||
case 1: TIM5->CCR1 = v; break;
|
||||
case 2: TIM5->CCR2 = v; break;
|
||||
case 3: TIM5->CCR3 = v; break;
|
||||
case 4: TIM5->CCR4 = v; break;
|
||||
case 1:
|
||||
TIM5->CCR1 = v;
|
||||
break;
|
||||
case 2:
|
||||
TIM5->CCR2 = v;
|
||||
break;
|
||||
case 3:
|
||||
TIM5->CCR3 = v;
|
||||
break;
|
||||
case 4:
|
||||
TIM5->CCR4 = v;
|
||||
break;
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -201,14 +201,23 @@ void spi_set_params(const spi_t *spi_obj, uint32_t prescale, int32_t baudrate,
|
||||
#endif
|
||||
prescale = (spi_clock + baudrate - 1) / baudrate;
|
||||
}
|
||||
if (prescale <= 2) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; }
|
||||
else if (prescale <= 4) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; }
|
||||
else if (prescale <= 8) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; }
|
||||
else if (prescale <= 16) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; }
|
||||
else if (prescale <= 32) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; }
|
||||
else if (prescale <= 64) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; }
|
||||
else if (prescale <= 128) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; }
|
||||
else { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; }
|
||||
if (prescale <= 2) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
} else if (prescale <= 4) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
} else if (prescale <= 8) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
||||
} else if (prescale <= 16) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||
} else if (prescale <= 32) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
||||
} else if (prescale <= 64) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
||||
} else if (prescale <= 128) {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||
} else {
|
||||
init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
|
||||
}
|
||||
}
|
||||
|
||||
if (polarity != -1) {
|
||||
@ -515,21 +524,32 @@ void spi_print(const mp_print_t *print, const spi_t *spi_obj, bool legacy) {
|
||||
SPI_HandleTypeDef *spi = spi_obj->spi;
|
||||
|
||||
uint spi_num = 1; // default to SPI1
|
||||
if (0) { }
|
||||
if (0) {
|
||||
}
|
||||
#if defined(SPI2)
|
||||
else if (spi->Instance == SPI2) { spi_num = 2; }
|
||||
else if (spi->Instance == SPI2) {
|
||||
spi_num = 2;
|
||||
}
|
||||
#endif
|
||||
#if defined(SPI3)
|
||||
else if (spi->Instance == SPI3) { spi_num = 3; }
|
||||
else if (spi->Instance == SPI3) {
|
||||
spi_num = 3;
|
||||
}
|
||||
#endif
|
||||
#if defined(SPI4)
|
||||
else if (spi->Instance == SPI4) { spi_num = 4; }
|
||||
else if (spi->Instance == SPI4) {
|
||||
spi_num = 4;
|
||||
}
|
||||
#endif
|
||||
#if defined(SPI5)
|
||||
else if (spi->Instance == SPI5) { spi_num = 5; }
|
||||
else if (spi->Instance == SPI5) {
|
||||
spi_num = 5;
|
||||
}
|
||||
#endif
|
||||
#if defined(SPI6)
|
||||
else if (spi->Instance == SPI6) { spi_num = 6; }
|
||||
else if (spi->Instance == SPI6) {
|
||||
spi_num = 6;
|
||||
}
|
||||
#endif
|
||||
|
||||
mp_printf(print, "SPI(%u", spi_num);
|
||||
|
@ -392,25 +392,25 @@ STATIC void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) {
|
||||
__HAL_RCC_HSE_CONFIG(MICROPY_HW_CLK_HSE_STATE);
|
||||
|
||||
/* Wait till HSE is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
|
||||
{}
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
|
||||
}
|
||||
|
||||
/* Enable the main PLL. */
|
||||
__HAL_RCC_PLL_ENABLE();
|
||||
|
||||
/* Wait till PLL is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
|
||||
{}
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
|
||||
}
|
||||
|
||||
/* Select PLL as SYSCLK */
|
||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_SYSCLKSOURCE_PLLCLK);
|
||||
|
||||
#if defined(STM32H7)
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL1)
|
||||
{}
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL1) {
|
||||
}
|
||||
#else
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
|
||||
{}
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ungate PHY clock */
|
||||
|
@ -246,12 +246,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblock
|
||||
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||
switch (cmd) {
|
||||
case BP_IOCTL_INIT: storage_init(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||
case BP_IOCTL_DEINIT: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
|
||||
case BP_IOCTL_SYNC: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||
case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(storage_get_block_count());
|
||||
case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
|
||||
default: return mp_const_none;
|
||||
case BP_IOCTL_INIT:
|
||||
storage_init();
|
||||
return MP_OBJ_NEW_SMALL_INT(0);
|
||||
case BP_IOCTL_DEINIT:
|
||||
storage_flush();
|
||||
return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
|
||||
case BP_IOCTL_SYNC:
|
||||
storage_flush();
|
||||
return MP_OBJ_NEW_SMALL_INT(0);
|
||||
case BP_IOCTL_SEC_COUNT:
|
||||
return MP_OBJ_NEW_SMALL_INT(storage_get_block_count());
|
||||
case BP_IOCTL_SEC_SIZE:
|
||||
return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
|
||||
default:
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
|
||||
|
@ -208,8 +208,7 @@ const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7,
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
void SystemInit(void) {
|
||||
/* FPU settings ------------------------------------------------------------*/
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 10 * 2) | (3UL << 11 * 2)); /* set CP10 and CP11 Full Access */
|
||||
@ -370,8 +369,7 @@ void SystemInit(void)
|
||||
*
|
||||
* Timers run from APBx if APBx_PRESC=1, else 2x APBx
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
void SystemClock_Config(void) {
|
||||
#if defined(STM32F7)
|
||||
// The DFU bootloader changes the clocksource register from its default power
|
||||
// on reset value, so we set it back here, so the clocksources are the same
|
||||
@ -532,8 +530,7 @@ void SystemClock_Config(void)
|
||||
|
||||
#if defined(STM32F7)
|
||||
/* Activate the OverDrive to reach the 200 MHz Frequency */
|
||||
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
|
||||
{
|
||||
if (HAL_PWREx_EnableOverDrive() != HAL_OK) {
|
||||
__fatal_error("HAL_PWREx_EnableOverDrive");
|
||||
}
|
||||
#endif
|
||||
@ -586,8 +583,7 @@ void SystemClock_Config(void)
|
||||
| RCC_PLLSAI1_48M2CLK
|
||||
| RCC_PLLSAI1_ADC1CLK;
|
||||
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||
{
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||
__fatal_error("HAL_RCCEx_PeriphCLKConfig");
|
||||
}
|
||||
|
||||
|
@ -609,52 +609,86 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons
|
||||
|
||||
// enable TIM clock
|
||||
switch (self->tim_id) {
|
||||
case 1: __HAL_RCC_TIM1_CLK_ENABLE(); break;
|
||||
case 2: __HAL_RCC_TIM2_CLK_ENABLE(); break;
|
||||
case 1:
|
||||
__HAL_RCC_TIM1_CLK_ENABLE();
|
||||
break;
|
||||
case 2:
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
break;
|
||||
#if defined(TIM3)
|
||||
case 3: __HAL_RCC_TIM3_CLK_ENABLE(); break;
|
||||
case 3:
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM4)
|
||||
case 4: __HAL_RCC_TIM4_CLK_ENABLE(); break;
|
||||
case 4:
|
||||
__HAL_RCC_TIM4_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM5)
|
||||
case 5: __HAL_RCC_TIM5_CLK_ENABLE(); break;
|
||||
case 5:
|
||||
__HAL_RCC_TIM5_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM6)
|
||||
case 6: __HAL_RCC_TIM6_CLK_ENABLE(); break;
|
||||
case 6:
|
||||
__HAL_RCC_TIM6_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM7)
|
||||
case 7: __HAL_RCC_TIM7_CLK_ENABLE(); break;
|
||||
case 7:
|
||||
__HAL_RCC_TIM7_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM8)
|
||||
case 8: __HAL_RCC_TIM8_CLK_ENABLE(); break;
|
||||
case 8:
|
||||
__HAL_RCC_TIM8_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM9)
|
||||
case 9: __HAL_RCC_TIM9_CLK_ENABLE(); break;
|
||||
case 9:
|
||||
__HAL_RCC_TIM9_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM10)
|
||||
case 10: __HAL_RCC_TIM10_CLK_ENABLE(); break;
|
||||
case 10:
|
||||
__HAL_RCC_TIM10_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM11)
|
||||
case 11: __HAL_RCC_TIM11_CLK_ENABLE(); break;
|
||||
case 11:
|
||||
__HAL_RCC_TIM11_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM12)
|
||||
case 12: __HAL_RCC_TIM12_CLK_ENABLE(); break;
|
||||
case 12:
|
||||
__HAL_RCC_TIM12_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM13)
|
||||
case 13: __HAL_RCC_TIM13_CLK_ENABLE(); break;
|
||||
case 13:
|
||||
__HAL_RCC_TIM13_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM14)
|
||||
case 14: __HAL_RCC_TIM14_CLK_ENABLE(); break;
|
||||
case 14:
|
||||
__HAL_RCC_TIM14_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM15)
|
||||
case 15: __HAL_RCC_TIM15_CLK_ENABLE(); break;
|
||||
case 15:
|
||||
__HAL_RCC_TIM15_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM16)
|
||||
case 16: __HAL_RCC_TIM16_CLK_ENABLE(); break;
|
||||
case 16:
|
||||
__HAL_RCC_TIM16_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(TIM17)
|
||||
case 17: __HAL_RCC_TIM17_CLK_ENABLE(); break;
|
||||
case 17:
|
||||
__HAL_RCC_TIM17_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -123,38 +123,47 @@ bool uart_exists(int uart_id) {
|
||||
}
|
||||
switch (uart_id) {
|
||||
#if defined(MICROPY_HW_UART1_TX) && defined(MICROPY_HW_UART1_RX)
|
||||
case PYB_UART_1: return true;
|
||||
case PYB_UART_1:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART2_TX) && defined(MICROPY_HW_UART2_RX)
|
||||
case PYB_UART_2: return true;
|
||||
case PYB_UART_2:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART3_TX) && defined(MICROPY_HW_UART3_RX)
|
||||
case PYB_UART_3: return true;
|
||||
case PYB_UART_3:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART4_TX) && defined(MICROPY_HW_UART4_RX)
|
||||
case PYB_UART_4: return true;
|
||||
case PYB_UART_4:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART5_TX) && defined(MICROPY_HW_UART5_RX)
|
||||
case PYB_UART_5: return true;
|
||||
case PYB_UART_5:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART6_TX) && defined(MICROPY_HW_UART6_RX)
|
||||
case PYB_UART_6: return true;
|
||||
case PYB_UART_6:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART7_TX) && defined(MICROPY_HW_UART7_RX)
|
||||
case PYB_UART_7: return true;
|
||||
case PYB_UART_7:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART8_TX) && defined(MICROPY_HW_UART8_RX)
|
||||
case PYB_UART_8: return true;
|
||||
case PYB_UART_8:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
default: return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,7 @@
|
||||
|
||||
#define GPIO_NUMBER 32
|
||||
|
||||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
{
|
||||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
|
||||
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
||||
@ -24,11 +23,9 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
if ((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) {
|
||||
/* Check the Alternate function parameter */
|
||||
assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
|
||||
}
|
||||
else if (GPIO_Init->Mode == GPIO_MODE_ANALOG) {
|
||||
} else if (GPIO_Init->Mode == GPIO_MODE_ANALOG) {
|
||||
GPIO_Init->Alternate = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
GPIO_Init->Alternate = 1;
|
||||
}
|
||||
|
||||
@ -83,8 +80,7 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
#if 0
|
||||
/*--------------------- EXTI Mode Configuration ------------------------*/
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
|
||||
{
|
||||
if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) {
|
||||
/* Enable SYSCFG Clock */
|
||||
__SYSCFG_CLK_ENABLE();
|
||||
|
||||
@ -96,12 +92,10 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
EXTI->IMR &= ~((uint32_t)iocurrent);
|
||||
EXTI->EMR &= ~((uint32_t)iocurrent);
|
||||
|
||||
if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
||||
{
|
||||
if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) {
|
||||
EXTI->IMR |= iocurrent;
|
||||
}
|
||||
if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
||||
{
|
||||
if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) {
|
||||
EXTI->EMR |= iocurrent;
|
||||
}
|
||||
|
||||
@ -109,12 +103,10 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
EXTI->RTSR &= ~((uint32_t)iocurrent);
|
||||
EXTI->FTSR &= ~((uint32_t)iocurrent);
|
||||
|
||||
if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
|
||||
{
|
||||
if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) {
|
||||
EXTI->RTSR |= iocurrent;
|
||||
}
|
||||
if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
|
||||
{
|
||||
if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) {
|
||||
EXTI->FTSR |= iocurrent;
|
||||
}
|
||||
}
|
||||
|
@ -358,8 +358,7 @@ void __libc_init_array(void) {
|
||||
// ultoa is used by usb_init_serialnumber. Normally ultoa would be provided
|
||||
// by nonstd.c from the teensy core, but it conflicts with some of the
|
||||
// MicroPython functions in string0.c, so we provide ultoa here.
|
||||
char * ultoa(unsigned long val, char *buf, int radix)
|
||||
{
|
||||
char *ultoa(unsigned long val, char *buf, int radix) {
|
||||
unsigned digit;
|
||||
int i = 0, j;
|
||||
char t;
|
||||
@ -368,7 +367,9 @@ char * ultoa(unsigned long val, char *buf, int radix)
|
||||
digit = val % radix;
|
||||
buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10);
|
||||
val /= radix;
|
||||
if (val == 0) break;
|
||||
if (val == 0) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
buf[i + 1] = 0;
|
||||
|
@ -8,27 +8,28 @@ import sys
|
||||
import csv
|
||||
|
||||
SUPPORTED_FN = {
|
||||
'FTM' : ['CH0', 'CH1', 'CH2', 'CH3', 'CH4', 'CH5', 'CH6', 'CH7',
|
||||
'QD_PHA', 'QD_PHB'],
|
||||
'I2C' : ['SDA', 'SCL'],
|
||||
'UART' : ['RX', 'TX', 'CTS', 'RTS'],
|
||||
'SPI' : ['NSS', 'SCK', 'MISO', 'MOSI']
|
||||
"FTM": ["CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "QD_PHA", "QD_PHB"],
|
||||
"I2C": ["SDA", "SCL"],
|
||||
"UART": ["RX", "TX", "CTS", "RTS"],
|
||||
"SPI": ["NSS", "SCK", "MISO", "MOSI"],
|
||||
}
|
||||
|
||||
|
||||
def parse_port_pin(name_str):
|
||||
"""Parses a string and returns a (port-num, pin-num) tuple."""
|
||||
if len(name_str) < 4:
|
||||
raise ValueError("Expecting pin name to be at least 4 charcters.")
|
||||
if name_str[0:2] != 'PT':
|
||||
if name_str[0:2] != "PT":
|
||||
raise ValueError("Expecting pin name to start with PT")
|
||||
if name_str[2] not in ('A', 'B', 'C', 'D', 'E', 'Z'):
|
||||
if name_str[2] not in ("A", "B", "C", "D", "E", "Z"):
|
||||
raise ValueError("Expecting pin port to be between A and E or Z")
|
||||
port = ord(name_str[2]) - ord('A')
|
||||
pin_str = name_str[3:].split('/')[0]
|
||||
port = ord(name_str[2]) - ord("A")
|
||||
pin_str = name_str[3:].split("/")[0]
|
||||
if not pin_str.isdigit():
|
||||
raise ValueError("Expecting numeric pin number.")
|
||||
return (port, int(pin_str))
|
||||
|
||||
|
||||
def split_name_num(name_num):
|
||||
num = None
|
||||
for num_idx in range(len(name_num) - 1, -1, -1):
|
||||
@ -48,12 +49,12 @@ class AlternateFunction(object):
|
||||
self.idx = idx
|
||||
self.af_str = af_str
|
||||
|
||||
self.func = ''
|
||||
self.func = ""
|
||||
self.fn_num = None
|
||||
self.pin_type = ''
|
||||
self.pin_type = ""
|
||||
self.supported = False
|
||||
|
||||
af_words = af_str.split('_', 1)
|
||||
af_words = af_str.split("_", 1)
|
||||
self.func, self.fn_num = split_name_num(af_words[0])
|
||||
if len(af_words) > 1:
|
||||
self.pin_type = af_words[1]
|
||||
@ -69,22 +70,25 @@ class AlternateFunction(object):
|
||||
"""Returns the numbered function (i.e. USART6) for this AF."""
|
||||
if self.fn_num is None:
|
||||
return self.func
|
||||
return '{:s}{:d}'.format(self.func, self.fn_num)
|
||||
return "{:s}{:d}".format(self.func, self.fn_num)
|
||||
|
||||
def mux_name(self):
|
||||
return 'AF{:d}_{:s}'.format(self.idx, self.ptr())
|
||||
return "AF{:d}_{:s}".format(self.idx, self.ptr())
|
||||
|
||||
def print(self):
|
||||
"""Prints the C representation of this AF."""
|
||||
if self.supported:
|
||||
print(' AF', end='')
|
||||
print(" AF", end="")
|
||||
else:
|
||||
print(' //', end='')
|
||||
print(" //", end="")
|
||||
fn_num = self.fn_num
|
||||
if fn_num is None:
|
||||
fn_num = 0
|
||||
print('({:2d}, {:8s}, {:2d}, {:10s}, {:8s}), // {:s}'.format(self.idx,
|
||||
self.func, fn_num, self.pin_type, self.ptr(), self.af_str))
|
||||
print(
|
||||
"({:2d}, {:8s}, {:2d}, {:10s}, {:8s}), // {:s}".format(
|
||||
self.idx, self.func, fn_num, self.pin_type, self.ptr(), self.af_str
|
||||
)
|
||||
)
|
||||
|
||||
def qstr_list(self):
|
||||
return [self.mux_name()]
|
||||
@ -103,10 +107,10 @@ class Pin(object):
|
||||
self.board_pin = False
|
||||
|
||||
def port_letter(self):
|
||||
return chr(self.port + ord('A'))
|
||||
return chr(self.port + ord("A"))
|
||||
|
||||
def cpu_pin_name(self):
|
||||
return '{:s}{:d}'.format(self.port_letter(), self.pin)
|
||||
return "{:s}{:d}".format(self.port_letter(), self.pin)
|
||||
|
||||
def is_board_pin(self):
|
||||
return self.board_pin
|
||||
@ -115,12 +119,12 @@ class Pin(object):
|
||||
self.board_pin = True
|
||||
|
||||
def parse_adc(self, adc_str):
|
||||
if (adc_str[:3] != 'ADC'):
|
||||
if adc_str[:3] != "ADC":
|
||||
return
|
||||
(adc,channel) = adc_str.split('_')
|
||||
(adc, channel) = adc_str.split("_")
|
||||
for idx in range(3, len(adc)):
|
||||
adc_num = int(adc[idx]) # 1, 2, or 3
|
||||
self.adc_num |= (1 << (adc_num - 1))
|
||||
self.adc_num |= 1 << (adc_num - 1)
|
||||
self.adc_channel = int(channel[2:])
|
||||
|
||||
def parse_af(self, af_idx, af_strs_in):
|
||||
@ -128,7 +132,7 @@ class Pin(object):
|
||||
return
|
||||
# If there is a slash, then the slash separates 2 aliases for the
|
||||
# same alternate function.
|
||||
af_strs = af_strs_in.split('/')
|
||||
af_strs = af_strs_in.split("/")
|
||||
for af_str in af_strs:
|
||||
alt_fn = AlternateFunction(af_idx, af_str)
|
||||
self.alt_fn.append(alt_fn)
|
||||
@ -137,43 +141,50 @@ class Pin(object):
|
||||
|
||||
def alt_fn_name(self, null_if_0=False):
|
||||
if null_if_0 and self.alt_fn_count == 0:
|
||||
return 'NULL'
|
||||
return 'pin_{:s}_af'.format(self.cpu_pin_name())
|
||||
return "NULL"
|
||||
return "pin_{:s}_af".format(self.cpu_pin_name())
|
||||
|
||||
def adc_num_str(self):
|
||||
str = ''
|
||||
str = ""
|
||||
for adc_num in range(1, 4):
|
||||
if self.adc_num & (1 << (adc_num - 1)):
|
||||
if len(str) > 0:
|
||||
str += ' | '
|
||||
str += 'PIN_ADC'
|
||||
str += chr(ord('0') + adc_num)
|
||||
str += " | "
|
||||
str += "PIN_ADC"
|
||||
str += chr(ord("0") + adc_num)
|
||||
if len(str) == 0:
|
||||
str = '0'
|
||||
str = "0"
|
||||
return str
|
||||
|
||||
def print(self):
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end='')
|
||||
print('const pin_af_obj_t {:s}[] = {{'.format(self.alt_fn_name()))
|
||||
print("// ", end="")
|
||||
print("const pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()))
|
||||
for alt_fn in self.alt_fn:
|
||||
alt_fn.print()
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end='')
|
||||
print('};')
|
||||
print('')
|
||||
print('const pin_obj_t pin_{:s} = PIN({:s}, {:d}, {:d}, {:s}, {:s}, {:d});'.format(
|
||||
self.cpu_pin_name(), self.port_letter(), self.pin,
|
||||
self.alt_fn_count, self.alt_fn_name(null_if_0=True),
|
||||
self.adc_num_str(), self.adc_channel))
|
||||
print('')
|
||||
print("// ", end="")
|
||||
print("};")
|
||||
print("")
|
||||
print(
|
||||
"const pin_obj_t pin_{:s} = PIN({:s}, {:d}, {:d}, {:s}, {:s}, {:d});".format(
|
||||
self.cpu_pin_name(),
|
||||
self.port_letter(),
|
||||
self.pin,
|
||||
self.alt_fn_count,
|
||||
self.alt_fn_name(null_if_0=True),
|
||||
self.adc_num_str(),
|
||||
self.adc_channel,
|
||||
)
|
||||
)
|
||||
print("")
|
||||
|
||||
def print_header(self, hdr_file):
|
||||
hdr_file.write('extern const pin_obj_t pin_{:s};\n'.
|
||||
format(self.cpu_pin_name()))
|
||||
hdr_file.write("extern const pin_obj_t pin_{:s};\n".format(self.cpu_pin_name()))
|
||||
if self.alt_fn_count > 0:
|
||||
hdr_file.write('extern const pin_af_obj_t pin_{:s}_af[];\n'.
|
||||
format(self.cpu_pin_name()))
|
||||
hdr_file.write(
|
||||
"extern const pin_af_obj_t pin_{:s}_af[];\n".format(self.cpu_pin_name())
|
||||
)
|
||||
|
||||
def qstr_list(self):
|
||||
result = []
|
||||
@ -184,7 +195,6 @@ class Pin(object):
|
||||
|
||||
|
||||
class NamedPin(object):
|
||||
|
||||
def __init__(self, name, pin):
|
||||
self._name = name
|
||||
self._pin = pin
|
||||
@ -197,7 +207,6 @@ class NamedPin(object):
|
||||
|
||||
|
||||
class Pins(object):
|
||||
|
||||
def __init__(self):
|
||||
self.cpu_pins = [] # list of NamedPin objects
|
||||
self.board_pins = [] # list of NamedPin objects
|
||||
@ -209,7 +218,7 @@ class Pins(object):
|
||||
return pin
|
||||
|
||||
def parse_af_file(self, filename, pinname_col, af_col):
|
||||
with open(filename, 'r') as csvfile:
|
||||
with open(filename, "r") as csvfile:
|
||||
rows = csv.reader(csvfile)
|
||||
for row in rows:
|
||||
try:
|
||||
@ -223,7 +232,7 @@ class Pins(object):
|
||||
self.cpu_pins.append(NamedPin(pin.cpu_pin_name(), pin))
|
||||
|
||||
def parse_board_file(self, filename):
|
||||
with open(filename, 'r') as csvfile:
|
||||
with open(filename, "r") as csvfile:
|
||||
rows = csv.reader(csvfile)
|
||||
for row in rows:
|
||||
try:
|
||||
@ -236,52 +245,64 @@ class Pins(object):
|
||||
self.board_pins.append(NamedPin(row[0], pin))
|
||||
|
||||
def print_named(self, label, named_pins):
|
||||
print('STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
|
||||
print(
|
||||
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label)
|
||||
)
|
||||
for named_pin in named_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
print(' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}) }},'.format(named_pin.name(), pin.cpu_pin_name()))
|
||||
print('};')
|
||||
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
|
||||
print(
|
||||
" {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}) }},".format(
|
||||
named_pin.name(), pin.cpu_pin_name()
|
||||
)
|
||||
)
|
||||
print("};")
|
||||
print(
|
||||
"MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);".format(
|
||||
label, label
|
||||
)
|
||||
)
|
||||
|
||||
def print(self):
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
pin.print()
|
||||
self.print_named('cpu', self.cpu_pins)
|
||||
print('')
|
||||
self.print_named('board', self.board_pins)
|
||||
self.print_named("cpu", self.cpu_pins)
|
||||
print("")
|
||||
self.print_named("board", self.board_pins)
|
||||
|
||||
def print_adc(self, adc_num):
|
||||
print('');
|
||||
print('const pin_obj_t * const pin_adc{:d}[] = {{'.format(adc_num))
|
||||
print("")
|
||||
print("const pin_obj_t * const pin_adc{:d}[] = {{".format(adc_num))
|
||||
for channel in range(16):
|
||||
adc_found = False
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if (pin.is_board_pin() and
|
||||
(pin.adc_num & (1 << (adc_num - 1))) and (pin.adc_channel == channel)):
|
||||
print(' &pin_{:s}, // {:d}'.format(pin.cpu_pin_name(), channel))
|
||||
if (
|
||||
pin.is_board_pin()
|
||||
and (pin.adc_num & (1 << (adc_num - 1)))
|
||||
and (pin.adc_channel == channel)
|
||||
):
|
||||
print(" &pin_{:s}, // {:d}".format(pin.cpu_pin_name(), channel))
|
||||
adc_found = True
|
||||
break
|
||||
if not adc_found:
|
||||
print(' NULL, // {:d}'.format(channel))
|
||||
print('};')
|
||||
|
||||
print(" NULL, // {:d}".format(channel))
|
||||
print("};")
|
||||
|
||||
def print_header(self, hdr_filename):
|
||||
with open(hdr_filename, 'wt') as hdr_file:
|
||||
with open(hdr_filename, "wt") as hdr_file:
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
pin.print_header(hdr_file)
|
||||
hdr_file.write('extern const pin_obj_t * const pin_adc1[];\n')
|
||||
hdr_file.write('extern const pin_obj_t * const pin_adc2[];\n')
|
||||
hdr_file.write('extern const pin_obj_t * const pin_adc3[];\n')
|
||||
hdr_file.write("extern const pin_obj_t * const pin_adc1[];\n")
|
||||
hdr_file.write("extern const pin_obj_t * const pin_adc2[];\n")
|
||||
hdr_file.write("extern const pin_obj_t * const pin_adc3[];\n")
|
||||
|
||||
def print_qstr(self, qstr_filename):
|
||||
with open(qstr_filename, 'wt') as qstr_file:
|
||||
with open(qstr_filename, "wt") as qstr_file:
|
||||
qstr_set = set([])
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
@ -291,11 +312,10 @@ class Pins(object):
|
||||
for named_pin in self.board_pins:
|
||||
qstr_set |= set([named_pin.name()])
|
||||
for qstr in sorted(qstr_set):
|
||||
print('Q({})'.format(qstr), file=qstr_file)
|
||||
|
||||
print("Q({})".format(qstr), file=qstr_file)
|
||||
|
||||
def print_af_hdr(self, af_const_filename):
|
||||
with open(af_const_filename, 'wt') as af_const_file:
|
||||
with open(af_const_filename, "wt") as af_const_file:
|
||||
af_hdr_set = set([])
|
||||
mux_name_width = 0
|
||||
for named_pin in self.cpu_pins:
|
||||
@ -308,88 +328,92 @@ class Pins(object):
|
||||
if len(mux_name) > mux_name_width:
|
||||
mux_name_width = len(mux_name)
|
||||
for mux_name in sorted(af_hdr_set):
|
||||
key = 'MP_OBJ_NEW_QSTR(MP_QSTR_{}),'.format(mux_name)
|
||||
val = 'MP_OBJ_NEW_SMALL_INT(GPIO_{})'.format(mux_name)
|
||||
print(' { %-*s %s },' % (mux_name_width + 26, key, val),
|
||||
file=af_const_file)
|
||||
key = "MP_OBJ_NEW_QSTR(MP_QSTR_{}),".format(mux_name)
|
||||
val = "MP_OBJ_NEW_SMALL_INT(GPIO_{})".format(mux_name)
|
||||
print(" { %-*s %s }," % (mux_name_width + 26, key, val), file=af_const_file)
|
||||
|
||||
def print_af_py(self, af_py_filename):
|
||||
with open(af_py_filename, 'wt') as af_py_file:
|
||||
print('PINS_AF = (', file=af_py_file);
|
||||
with open(af_py_filename, "wt") as af_py_file:
|
||||
print("PINS_AF = (", file=af_py_file)
|
||||
for named_pin in self.board_pins:
|
||||
print(" ('%s', " % named_pin.name(), end='', file=af_py_file)
|
||||
print(" ('%s', " % named_pin.name(), end="", file=af_py_file)
|
||||
for af in named_pin.pin().alt_fn:
|
||||
if af.is_supported():
|
||||
print("(%d, '%s'), " % (af.idx, af.af_str), end='', file=af_py_file)
|
||||
print('),', file=af_py_file)
|
||||
print(')', file=af_py_file)
|
||||
print("(%d, '%s'), " % (af.idx, af.af_str), end="", file=af_py_file)
|
||||
print("),", file=af_py_file)
|
||||
print(")", file=af_py_file)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="make-pins.py",
|
||||
usage="%(prog)s [options] [command]",
|
||||
description="Generate board specific pin file"
|
||||
description="Generate board specific pin file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-a", "--af",
|
||||
"-a",
|
||||
"--af",
|
||||
dest="af_filename",
|
||||
help="Specifies the alternate function file for the chip",
|
||||
default="mk20dx256_af.csv"
|
||||
default="mk20dx256_af.csv",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--af-const",
|
||||
dest="af_const_filename",
|
||||
help="Specifies header file for alternate function constants.",
|
||||
default="build/pins_af_const.h"
|
||||
default="build/pins_af_const.h",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--af-py",
|
||||
dest="af_py_filename",
|
||||
help="Specifies the filename for the python alternate function mappings.",
|
||||
default="build/pins_af.py"
|
||||
default="build/pins_af.py",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-b", "--board",
|
||||
"-b",
|
||||
"--board",
|
||||
dest="board_filename",
|
||||
help="Specifies the board file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p", "--prefix",
|
||||
"-p",
|
||||
"--prefix",
|
||||
dest="prefix_filename",
|
||||
help="Specifies beginning portion of generated pins file",
|
||||
default="mk20dx256_prefix.c"
|
||||
default="mk20dx256_prefix.c",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-q", "--qstr",
|
||||
"-q",
|
||||
"--qstr",
|
||||
dest="qstr_filename",
|
||||
help="Specifies name of generated qstr header file",
|
||||
default="build/pins_qstr.h"
|
||||
default="build/pins_qstr.h",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-r", "--hdr",
|
||||
"-r",
|
||||
"--hdr",
|
||||
dest="hdr_filename",
|
||||
help="Specifies name of generated pin header file",
|
||||
default="build/pins.h"
|
||||
default="build/pins.h",
|
||||
)
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
pins = Pins()
|
||||
|
||||
print('// This file was automatically generated by make-pins.py')
|
||||
print('//')
|
||||
print("// This file was automatically generated by make-pins.py")
|
||||
print("//")
|
||||
if args.af_filename:
|
||||
print('// --af {:s}'.format(args.af_filename))
|
||||
print("// --af {:s}".format(args.af_filename))
|
||||
pins.parse_af_file(args.af_filename, 4, 3)
|
||||
|
||||
if args.board_filename:
|
||||
print('// --board {:s}'.format(args.board_filename))
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename)
|
||||
|
||||
if args.prefix_filename:
|
||||
print('// --prefix {:s}'.format(args.prefix_filename))
|
||||
print('')
|
||||
with open(args.prefix_filename, 'r') as prefix_file:
|
||||
print("// --prefix {:s}".format(args.prefix_filename))
|
||||
print("")
|
||||
with open(args.prefix_filename, "r") as prefix_file:
|
||||
print(prefix_file.read())
|
||||
pins.print()
|
||||
pins.print_adc(1)
|
||||
|
@ -78,7 +78,7 @@ typedef long mp_off_t;
|
||||
__attribute__((always_inline)) static inline uint32_t __get_PRIMASK(void) {
|
||||
uint32_t result;
|
||||
__asm volatile ("MRS %0, primask" : "=r" (result));
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void __set_PRIMASK(uint32_t priMask) {
|
||||
|
@ -36,13 +36,11 @@ typedef struct _pyb_servo_obj_t {
|
||||
|
||||
#define clamp(v, min_val, max_val) ((v) < (min_val) ? (min_val) : (v) > (max_val) ? (max_val) : (v))
|
||||
|
||||
static float map_uint_to_float(uint x, uint in_min, uint in_max, float out_min, float out_max)
|
||||
{
|
||||
static float map_uint_to_float(uint x, uint in_min, uint in_max, float out_min, float out_max) {
|
||||
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + (float)out_min;
|
||||
}
|
||||
|
||||
static uint map_float_to_uint(float x, float in_min, float in_max, uint out_min, uint out_max)
|
||||
{
|
||||
static uint map_float_to_uint(float x, float in_min, float in_max, uint out_min, uint out_max) {
|
||||
return (int)((x - in_min) * (float)(out_max - out_min) / (in_max - in_min) + (float)out_min);
|
||||
}
|
||||
|
||||
@ -221,8 +219,7 @@ mp_obj_t pyb_Servo(void) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
void pdb_isr(void)
|
||||
{
|
||||
void pdb_isr(void) {
|
||||
static int8_t channel = 0, channel_high = MAX_SERVOS;
|
||||
static uint32_t tick_accum = 0;
|
||||
uint32_t ticks;
|
||||
@ -251,8 +248,11 @@ void pdb_isr(void)
|
||||
// when all channels have output, wait for the
|
||||
// minimum refresh interval
|
||||
wait_ticks = usToTicks(REFRESH_INTERVAL) - tick_accum;
|
||||
if (wait_ticks < usToTicks(100)) wait_ticks = usToTicks(100);
|
||||
else if (wait_ticks > 60000) wait_ticks = 60000;
|
||||
if (wait_ticks < usToTicks(100)) {
|
||||
wait_ticks = usToTicks(100);
|
||||
} else if (wait_ticks > 60000) {
|
||||
wait_ticks = 60000;
|
||||
}
|
||||
tick_accum += wait_ticks;
|
||||
PDB0_IDLY += wait_ticks;
|
||||
PDB0_SC = PDB_CONFIG | PDB_SC_LDOK;
|
||||
|
@ -319,10 +319,20 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
tim->tim_id = mp_obj_get_int(args[0]);
|
||||
|
||||
switch (tim->tim_id) {
|
||||
case 0: tim->ftm.Instance = FTM0; tim->irqn = IRQ_FTM0; break;
|
||||
case 1: tim->ftm.Instance = FTM1; tim->irqn = IRQ_FTM1; break;
|
||||
case 2: tim->ftm.Instance = FTM2; tim->irqn = IRQ_FTM2; break;
|
||||
default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id));
|
||||
case 0:
|
||||
tim->ftm.Instance = FTM0;
|
||||
tim->irqn = IRQ_FTM0;
|
||||
break;
|
||||
case 1:
|
||||
tim->ftm.Instance = FTM1;
|
||||
tim->irqn = IRQ_FTM1;
|
||||
break;
|
||||
case 2:
|
||||
tim->ftm.Instance = FTM2;
|
||||
tim->irqn = IRQ_FTM2;
|
||||
break;
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id));
|
||||
}
|
||||
|
||||
if (n_args > 1 || n_kw > 0) {
|
||||
|
@ -268,8 +268,12 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp
|
||||
init->BaudRate = vals[0].u_int;
|
||||
init->WordLength = vals[1].u_int == 8 ? UART_WORDLENGTH_8B : UART_WORDLENGTH_9B;
|
||||
switch (vals[2].u_int) {
|
||||
case 1: init->StopBits = UART_STOPBITS_1; break;
|
||||
default: init->StopBits = UART_STOPBITS_2; break;
|
||||
case 1:
|
||||
init->StopBits = UART_STOPBITS_1;
|
||||
break;
|
||||
default:
|
||||
init->StopBits = UART_STOPBITS_2;
|
||||
break;
|
||||
}
|
||||
if (vals[3].u_obj == mp_const_none) {
|
||||
init->Parity = UART_PARITY_NONE;
|
||||
|
@ -7,13 +7,11 @@
|
||||
#include "usb.h"
|
||||
#include "usb_serial.h"
|
||||
|
||||
bool usb_vcp_is_connected(void)
|
||||
{
|
||||
bool usb_vcp_is_connected(void) {
|
||||
return usb_configuration && (usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS));
|
||||
}
|
||||
|
||||
bool usb_vcp_is_enabled(void)
|
||||
{
|
||||
bool usb_vcp_is_enabled(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -21,8 +19,7 @@ int usb_vcp_rx_num(void) {
|
||||
return usb_serial_available();
|
||||
}
|
||||
|
||||
int usb_vcp_recv_byte(uint8_t *ptr)
|
||||
{
|
||||
int usb_vcp_recv_byte(uint8_t *ptr) {
|
||||
int ch = usb_serial_getchar();
|
||||
if (ch < 0) {
|
||||
return 0;
|
||||
@ -31,18 +28,15 @@ int usb_vcp_recv_byte(uint8_t *ptr)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void usb_vcp_send_str(const char* str)
|
||||
{
|
||||
void usb_vcp_send_str(const char *str) {
|
||||
usb_vcp_send_strn(str, strlen(str));
|
||||
}
|
||||
|
||||
void usb_vcp_send_strn(const char* str, int len)
|
||||
{
|
||||
void usb_vcp_send_strn(const char *str, int len) {
|
||||
usb_serial_write(str, len);
|
||||
}
|
||||
|
||||
void usb_vcp_send_strn_cooked(const char *str, int len)
|
||||
{
|
||||
void usb_vcp_send_strn_cooked(const char *str, int len) {
|
||||
for (const char *top = str + len; str < top; str++) {
|
||||
if (*str == '\n') {
|
||||
usb_serial_putchar('\r');
|
||||
|
@ -605,7 +605,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
||||
MP_STATE_VM(mp_optimise_value) = argv[a][2] & 0xf;
|
||||
} else {
|
||||
MP_STATE_VM(mp_optimise_value) = 0;
|
||||
for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++);
|
||||
for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++) {;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return usage(argv);
|
||||
|
@ -97,35 +97,48 @@ STATIC const mp_obj_type_t ffifunc_type;
|
||||
STATIC const mp_obj_type_t fficallback_type;
|
||||
STATIC const mp_obj_type_t ffivar_type;
|
||||
|
||||
STATIC ffi_type *char2ffi_type(char c)
|
||||
{
|
||||
STATIC ffi_type *char2ffi_type(char c) {
|
||||
switch (c) {
|
||||
case 'b': return &ffi_type_schar;
|
||||
case 'B': return &ffi_type_uchar;
|
||||
case 'h': return &ffi_type_sshort;
|
||||
case 'H': return &ffi_type_ushort;
|
||||
case 'i': return &ffi_type_sint;
|
||||
case 'I': return &ffi_type_uint;
|
||||
case 'l': return &ffi_type_slong;
|
||||
case 'L': return &ffi_type_ulong;
|
||||
case 'q': return &ffi_type_sint64;
|
||||
case 'Q': return &ffi_type_uint64;
|
||||
case 'b':
|
||||
return &ffi_type_schar;
|
||||
case 'B':
|
||||
return &ffi_type_uchar;
|
||||
case 'h':
|
||||
return &ffi_type_sshort;
|
||||
case 'H':
|
||||
return &ffi_type_ushort;
|
||||
case 'i':
|
||||
return &ffi_type_sint;
|
||||
case 'I':
|
||||
return &ffi_type_uint;
|
||||
case 'l':
|
||||
return &ffi_type_slong;
|
||||
case 'L':
|
||||
return &ffi_type_ulong;
|
||||
case 'q':
|
||||
return &ffi_type_sint64;
|
||||
case 'Q':
|
||||
return &ffi_type_uint64;
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
case 'f': return &ffi_type_float;
|
||||
case 'd': return &ffi_type_double;
|
||||
case 'f':
|
||||
return &ffi_type_float;
|
||||
case 'd':
|
||||
return &ffi_type_double;
|
||||
#endif
|
||||
case 'O': // mp_obj_t
|
||||
case 'C': // (*)()
|
||||
case 'P': // const void*
|
||||
case 'p': // void*
|
||||
case 's': return &ffi_type_pointer;
|
||||
case 'v': return &ffi_type_void;
|
||||
default: return NULL;
|
||||
case 's':
|
||||
return &ffi_type_pointer;
|
||||
case 'v':
|
||||
return &ffi_type_void;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC ffi_type *get_ffi_type(mp_obj_t o_in)
|
||||
{
|
||||
STATIC ffi_type *get_ffi_type(mp_obj_t o_in) {
|
||||
if (MP_OBJ_IS_STR(o_in)) {
|
||||
const char *s = mp_obj_str_get_str(o_in);
|
||||
ffi_type *t = char2ffi_type(*s);
|
||||
@ -138,8 +151,7 @@ STATIC ffi_type *get_ffi_type(mp_obj_t o_in)
|
||||
mp_raise_TypeError("Unknown type");
|
||||
}
|
||||
|
||||
STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
|
||||
{
|
||||
STATIC mp_obj_t return_ffi_value(ffi_arg val, char type) {
|
||||
switch (type) {
|
||||
case 's': {
|
||||
const char *s = (const char *)(intptr_t)val;
|
||||
@ -152,7 +164,9 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
|
||||
return mp_const_none;
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
case 'f': {
|
||||
union { ffi_arg ffi; float flt; } val_union = { .ffi = val };
|
||||
union { ffi_arg ffi;
|
||||
float flt;
|
||||
} val_union = { .ffi = val };
|
||||
return mp_obj_new_float(val_union.flt);
|
||||
}
|
||||
case 'd': {
|
||||
|
@ -49,8 +49,12 @@ static inline int mp_hal_readline(vstr_t *vstr, const char *p) {
|
||||
|
||||
// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
|
||||
// "The useconds argument shall be less than one million."
|
||||
static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
|
||||
static inline void mp_hal_delay_us(mp_uint_t us) { usleep(us); }
|
||||
static inline void mp_hal_delay_ms(mp_uint_t ms) {
|
||||
usleep((ms) * 1000);
|
||||
}
|
||||
static inline void mp_hal_delay_us(mp_uint_t us) {
|
||||
usleep(us);
|
||||
}
|
||||
#define mp_hal_ticks_cpu() 0
|
||||
|
||||
#define RAISE_ERRNO(err_flag, error_val) \
|
||||
|
@ -33,8 +33,9 @@ char *to_unix_path(char *p) {
|
||||
if (p != NULL) {
|
||||
char *pp = p;
|
||||
while (*pp != 0) {
|
||||
if (*pp == '\\')
|
||||
if (*pp == '\\') {
|
||||
*pp = '/';
|
||||
}
|
||||
++pp;
|
||||
}
|
||||
}
|
||||
@ -50,15 +51,17 @@ char *realpath(const char *path, char *resolved_path) {
|
||||
errno = EINVAL;
|
||||
} else if (access(path, R_OK) == 0) {
|
||||
ret = resolved_path;
|
||||
if (ret == NULL)
|
||||
if (ret == NULL) {
|
||||
ret = malloc(_MAX_PATH);
|
||||
}
|
||||
if (ret == NULL) {
|
||||
errno = ENOMEM;
|
||||
} else {
|
||||
ret = _fullpath(ret, path, _MAX_PATH);
|
||||
if (ret == NULL)
|
||||
if (ret == NULL) {
|
||||
errno = EIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
return to_unix_path(ret);
|
||||
}
|
||||
|
@ -149,7 +149,9 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
NORETURN void nlr_jump_fail(void *val) {
|
||||
while (1);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -95,8 +95,9 @@ void asm_thumb_exit(asm_thumb_t *as);
|
||||
void asm_thumb_op16(asm_thumb_t *as, uint op);
|
||||
void asm_thumb_op32(asm_thumb_t *as, uint op1, uint op2);
|
||||
|
||||
static inline void asm_thumb_it_cc(asm_thumb_t *as, uint cc, uint mask)
|
||||
{ asm_thumb_op16(as, ASM_THUMB_OP_IT | (cc << 4) | mask); }
|
||||
static inline void asm_thumb_it_cc(asm_thumb_t *as, uint cc, uint mask) {
|
||||
asm_thumb_op16(as, ASM_THUMB_OP_IT | (cc << 4) | mask);
|
||||
}
|
||||
|
||||
// FORMAT 1: move shifted register
|
||||
|
||||
@ -129,14 +130,18 @@ static inline void asm_thumb_format_2(asm_thumb_t *as, uint op, uint rlo_dest, u
|
||||
asm_thumb_op16(as, ASM_THUMB_FORMAT_2_ENCODE(op, rlo_dest, rlo_src, src_b));
|
||||
}
|
||||
|
||||
static inline void asm_thumb_add_rlo_rlo_rlo(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, uint rlo_src_b)
|
||||
{ asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_ADD | ASM_THUMB_FORMAT_2_REG_OPERAND, rlo_dest, rlo_src_a, rlo_src_b); }
|
||||
static inline void asm_thumb_add_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, int i3_src)
|
||||
{ asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_ADD | ASM_THUMB_FORMAT_2_IMM_OPERAND, rlo_dest, rlo_src_a, i3_src); }
|
||||
static inline void asm_thumb_sub_rlo_rlo_rlo(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, uint rlo_src_b)
|
||||
{ asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_SUB | ASM_THUMB_FORMAT_2_REG_OPERAND, rlo_dest, rlo_src_a, rlo_src_b); }
|
||||
static inline void asm_thumb_sub_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, int i3_src)
|
||||
{ asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_SUB | ASM_THUMB_FORMAT_2_IMM_OPERAND, rlo_dest, rlo_src_a, i3_src); }
|
||||
static inline void asm_thumb_add_rlo_rlo_rlo(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, uint rlo_src_b) {
|
||||
asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_ADD | ASM_THUMB_FORMAT_2_REG_OPERAND, rlo_dest, rlo_src_a, rlo_src_b);
|
||||
}
|
||||
static inline void asm_thumb_add_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, int i3_src) {
|
||||
asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_ADD | ASM_THUMB_FORMAT_2_IMM_OPERAND, rlo_dest, rlo_src_a, i3_src);
|
||||
}
|
||||
static inline void asm_thumb_sub_rlo_rlo_rlo(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, uint rlo_src_b) {
|
||||
asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_SUB | ASM_THUMB_FORMAT_2_REG_OPERAND, rlo_dest, rlo_src_a, rlo_src_b);
|
||||
}
|
||||
static inline void asm_thumb_sub_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, int i3_src) {
|
||||
asm_thumb_format_2(as, ASM_THUMB_FORMAT_2_SUB | ASM_THUMB_FORMAT_2_IMM_OPERAND, rlo_dest, rlo_src_a, i3_src);
|
||||
}
|
||||
|
||||
// FORMAT 3: move/compare/add/subtract immediate
|
||||
// These instructions all do zero extension of the i8 value
|
||||
@ -153,10 +158,18 @@ static inline void asm_thumb_format_3(asm_thumb_t *as, uint op, uint rlo, int i8
|
||||
asm_thumb_op16(as, ASM_THUMB_FORMAT_3_ENCODE(op, rlo, i8));
|
||||
}
|
||||
|
||||
static inline void asm_thumb_mov_rlo_i8(asm_thumb_t *as, uint rlo, int i8) { asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_MOV, rlo, i8); }
|
||||
static inline void asm_thumb_cmp_rlo_i8(asm_thumb_t *as, uint rlo, int i8) { asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_CMP, rlo, i8); }
|
||||
static inline void asm_thumb_add_rlo_i8(asm_thumb_t *as, uint rlo, int i8) { asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_ADD, rlo, i8); }
|
||||
static inline void asm_thumb_sub_rlo_i8(asm_thumb_t *as, uint rlo, int i8) { asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_SUB, rlo, i8); }
|
||||
static inline void asm_thumb_mov_rlo_i8(asm_thumb_t *as, uint rlo, int i8) {
|
||||
asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_MOV, rlo, i8);
|
||||
}
|
||||
static inline void asm_thumb_cmp_rlo_i8(asm_thumb_t *as, uint rlo, int i8) {
|
||||
asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_CMP, rlo, i8);
|
||||
}
|
||||
static inline void asm_thumb_add_rlo_i8(asm_thumb_t *as, uint rlo, int i8) {
|
||||
asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_ADD, rlo, i8);
|
||||
}
|
||||
static inline void asm_thumb_sub_rlo_i8(asm_thumb_t *as, uint rlo, int i8) {
|
||||
asm_thumb_format_3(as, ASM_THUMB_FORMAT_3_SUB, rlo, i8);
|
||||
}
|
||||
|
||||
// FORMAT 4: ALU operations
|
||||
|
||||
@ -179,7 +192,9 @@ static inline void asm_thumb_sub_rlo_i8(asm_thumb_t *as, uint rlo, int i8) { asm
|
||||
|
||||
void asm_thumb_format_4(asm_thumb_t *as, uint op, uint rlo_dest, uint rlo_src);
|
||||
|
||||
static inline void asm_thumb_cmp_rlo_rlo(asm_thumb_t *as, uint rlo_dest, uint rlo_src) { asm_thumb_format_4(as, ASM_THUMB_FORMAT_4_CMP, rlo_dest, rlo_src); }
|
||||
static inline void asm_thumb_cmp_rlo_rlo(asm_thumb_t *as, uint rlo_dest, uint rlo_src) {
|
||||
asm_thumb_format_4(as, ASM_THUMB_FORMAT_4_CMP, rlo_dest, rlo_src);
|
||||
}
|
||||
|
||||
// FORMAT 5: hi register operations (add, cmp, mov, bx)
|
||||
// For add/cmp/mov, at least one of the args must be a high register
|
||||
@ -219,21 +234,28 @@ static inline void asm_thumb_bx_reg(asm_thumb_t *as, uint r_src) {
|
||||
#define ASM_THUMB_FORMAT_9_10_ENCODE(op, rlo_dest, rlo_base, offset) \
|
||||
((op) | (((offset) << 6) & 0x07c0) | ((rlo_base) << 3) | (rlo_dest))
|
||||
|
||||
static inline void asm_thumb_format_9_10(asm_thumb_t *as, uint op, uint rlo_dest, uint rlo_base, uint offset)
|
||||
{ asm_thumb_op16(as, ASM_THUMB_FORMAT_9_10_ENCODE(op, rlo_dest, rlo_base, offset)); }
|
||||
static inline void asm_thumb_format_9_10(asm_thumb_t *as, uint op, uint rlo_dest, uint rlo_base, uint offset) {
|
||||
asm_thumb_op16(as, ASM_THUMB_FORMAT_9_10_ENCODE(op, rlo_dest, rlo_base, offset));
|
||||
}
|
||||
|
||||
static inline void asm_thumb_str_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint rlo_base, uint word_offset)
|
||||
{ asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_STR | ASM_THUMB_FORMAT_9_WORD_TRANSFER, rlo_src, rlo_base, word_offset); }
|
||||
static inline void asm_thumb_strb_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint rlo_base, uint byte_offset)
|
||||
{ asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_STR | ASM_THUMB_FORMAT_9_BYTE_TRANSFER, rlo_src, rlo_base, byte_offset); }
|
||||
static inline void asm_thumb_strh_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint rlo_base, uint byte_offset)
|
||||
{ asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_10_STRH, rlo_src, rlo_base, byte_offset); }
|
||||
static inline void asm_thumb_ldr_rlo_rlo_i5(asm_thumb_t *as, uint rlo_dest, uint rlo_base, uint word_offset)
|
||||
{ asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER, rlo_dest, rlo_base, word_offset); }
|
||||
static inline void asm_thumb_ldrb_rlo_rlo_i5(asm_thumb_t *as, uint rlo_dest, uint rlo_base, uint byte_offset)
|
||||
{ asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_BYTE_TRANSFER , rlo_dest, rlo_base, byte_offset); }
|
||||
static inline void asm_thumb_ldrh_rlo_rlo_i5(asm_thumb_t *as, uint rlo_dest, uint rlo_base, uint byte_offset)
|
||||
{ asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_10_LDRH, rlo_dest, rlo_base, byte_offset); }
|
||||
static inline void asm_thumb_str_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint rlo_base, uint word_offset) {
|
||||
asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_STR | ASM_THUMB_FORMAT_9_WORD_TRANSFER, rlo_src, rlo_base, word_offset);
|
||||
}
|
||||
static inline void asm_thumb_strb_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint rlo_base, uint byte_offset) {
|
||||
asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_STR | ASM_THUMB_FORMAT_9_BYTE_TRANSFER, rlo_src, rlo_base, byte_offset);
|
||||
}
|
||||
static inline void asm_thumb_strh_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint rlo_base, uint byte_offset) {
|
||||
asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_10_STRH, rlo_src, rlo_base, byte_offset);
|
||||
}
|
||||
static inline void asm_thumb_ldr_rlo_rlo_i5(asm_thumb_t *as, uint rlo_dest, uint rlo_base, uint word_offset) {
|
||||
asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER, rlo_dest, rlo_base, word_offset);
|
||||
}
|
||||
static inline void asm_thumb_ldrb_rlo_rlo_i5(asm_thumb_t *as, uint rlo_dest, uint rlo_base, uint byte_offset) {
|
||||
asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_BYTE_TRANSFER, rlo_dest, rlo_base, byte_offset);
|
||||
}
|
||||
static inline void asm_thumb_ldrh_rlo_rlo_i5(asm_thumb_t *as, uint rlo_dest, uint rlo_base, uint byte_offset) {
|
||||
asm_thumb_format_9_10(as, ASM_THUMB_FORMAT_10_LDRH, rlo_dest, rlo_base, byte_offset);
|
||||
}
|
||||
|
||||
// TODO convert these to above format style
|
||||
|
||||
|
@ -486,8 +486,7 @@ void asm_x86_push_local(asm_x86_t *as, int local_num) {
|
||||
asm_x86_push_disp(as, ASM_X86_REG_ESP, asm_x86_local_offset_from_esp(as, local_num));
|
||||
}
|
||||
|
||||
void asm_x86_push_local_addr(asm_x86_t *as, int local_num, int temp_r32)
|
||||
{
|
||||
void asm_x86_push_local_addr(asm_x86_t *as, int local_num, int temp_r32) {
|
||||
asm_x86_mov_r32_r32(as, temp_r32, ASM_X86_REG_ESP);
|
||||
asm_x86_add_i32_to_r32(as, asm_x86_local_offset_from_esp(as, local_num), temp_r32);
|
||||
asm_x86_push_r32(as, temp_r32);
|
||||
|
106
py/binary.c
106
py/binary.c
@ -45,24 +45,40 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
|
||||
size_t size = 0;
|
||||
int align = 1;
|
||||
switch (struct_type) {
|
||||
case '<': case '>':
|
||||
case '<':
|
||||
case '>':
|
||||
switch (val_type) {
|
||||
case 'b': case 'B':
|
||||
size = 1; break;
|
||||
case 'h': case 'H':
|
||||
size = 2; break;
|
||||
case 'i': case 'I':
|
||||
size = 4; break;
|
||||
case 'l': case 'L':
|
||||
size = 4; break;
|
||||
case 'q': case 'Q':
|
||||
size = 8; break;
|
||||
case 'P': case 'O': case 'S':
|
||||
size = sizeof(void*); break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
size = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
size = 2;
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
size = 4;
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
size = 4;
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
size = 8;
|
||||
break;
|
||||
case 'P':
|
||||
case 'O':
|
||||
case 'S':
|
||||
size = sizeof(void *);
|
||||
break;
|
||||
case 'f':
|
||||
size = sizeof(float); break;
|
||||
size = sizeof(float);
|
||||
break;
|
||||
case 'd':
|
||||
size = sizeof(double); break;
|
||||
size = sizeof(double);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '@': {
|
||||
@ -75,29 +91,44 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
|
||||
// particular (or any) ABI.
|
||||
switch (val_type) {
|
||||
case BYTEARRAY_TYPECODE:
|
||||
case 'b': case 'B':
|
||||
align = size = 1; break;
|
||||
case 'h': case 'H':
|
||||
case 'b':
|
||||
case 'B':
|
||||
align = size = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
align = alignof(short);
|
||||
size = sizeof(short); break;
|
||||
case 'i': case 'I':
|
||||
size = sizeof(short);
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
align = alignof(int);
|
||||
size = sizeof(int); break;
|
||||
case 'l': case 'L':
|
||||
size = sizeof(int);
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
align = alignof(long);
|
||||
size = sizeof(long); break;
|
||||
case 'q': case 'Q':
|
||||
size = sizeof(long);
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
align = alignof(long long);
|
||||
size = sizeof(long long); break;
|
||||
case 'P': case 'O': case 'S':
|
||||
size = sizeof(long long);
|
||||
break;
|
||||
case 'P':
|
||||
case 'O':
|
||||
case 'S':
|
||||
align = alignof(void *);
|
||||
size = sizeof(void*); break;
|
||||
size = sizeof(void *);
|
||||
break;
|
||||
case 'f':
|
||||
align = alignof(float);
|
||||
size = sizeof(float); break;
|
||||
size = sizeof(float);
|
||||
break;
|
||||
case 'd':
|
||||
align = alignof(double);
|
||||
size = sizeof(double); break;
|
||||
size = sizeof(double);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -209,10 +240,14 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
|
||||
return mp_obj_new_str(s_val, strlen(s_val));
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
} else if (val_type == 'f') {
|
||||
union { uint32_t i; float f; } fpu = {val};
|
||||
union { uint32_t i;
|
||||
float f;
|
||||
} fpu = {val};
|
||||
return mp_obj_new_float(fpu.f);
|
||||
} else if (val_type == 'd') {
|
||||
union { uint64_t i; double f; } fpu = {val};
|
||||
union { uint64_t i;
|
||||
double f;
|
||||
} fpu = {val};
|
||||
return mp_obj_new_float(fpu.f);
|
||||
#endif
|
||||
} else if (is_signed(val_type)) {
|
||||
@ -272,13 +307,18 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
|
||||
break;
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
case 'f': {
|
||||
union { uint32_t i; float f; } fp_sp;
|
||||
union { uint32_t i;
|
||||
float f;
|
||||
} fp_sp;
|
||||
fp_sp.f = mp_obj_get_float(val_in);
|
||||
val = fp_sp.i;
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
union { uint64_t i64; uint32_t i32[2]; double f; } fp_dp;
|
||||
union { uint64_t i64;
|
||||
uint32_t i32[2];
|
||||
double f;
|
||||
} fp_dp;
|
||||
fp_dp.f = mp_obj_get_float(val_in);
|
||||
if (BYTES_PER_WORD == 8) {
|
||||
val = fp_dp.i64;
|
||||
|
@ -90,9 +90,15 @@ STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) {
|
||||
qstr mode = mp_obj_str_get_qstr(args[2]);
|
||||
mp_parse_input_kind_t parse_input_kind;
|
||||
switch (mode) {
|
||||
case MP_QSTR_single: parse_input_kind = MP_PARSE_SINGLE_INPUT; break;
|
||||
case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break;
|
||||
case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break;
|
||||
case MP_QSTR_single:
|
||||
parse_input_kind = MP_PARSE_SINGLE_INPUT;
|
||||
break;
|
||||
case MP_QSTR_exec:
|
||||
parse_input_kind = MP_PARSE_FILE_INPUT;
|
||||
break;
|
||||
case MP_QSTR_eval:
|
||||
parse_input_kind = MP_PARSE_EVAL_INPUT;
|
||||
break;
|
||||
default:
|
||||
mp_raise_ValueError("bad compile mode");
|
||||
}
|
||||
|
149
py/compile.c
149
py/compile.c
@ -1936,18 +1936,43 @@ STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||
assert(MP_PARSE_NODE_IS_TOKEN(pns1->nodes[0]));
|
||||
mp_binary_op_t op;
|
||||
switch (MP_PARSE_NODE_LEAF_ARG(pns1->nodes[0])) {
|
||||
case MP_TOKEN_DEL_PIPE_EQUAL: op = MP_BINARY_OP_INPLACE_OR; break;
|
||||
case MP_TOKEN_DEL_CARET_EQUAL: op = MP_BINARY_OP_INPLACE_XOR; break;
|
||||
case MP_TOKEN_DEL_AMPERSAND_EQUAL: op = MP_BINARY_OP_INPLACE_AND; break;
|
||||
case MP_TOKEN_DEL_DBL_LESS_EQUAL: op = MP_BINARY_OP_INPLACE_LSHIFT; break;
|
||||
case MP_TOKEN_DEL_DBL_MORE_EQUAL: op = MP_BINARY_OP_INPLACE_RSHIFT; break;
|
||||
case MP_TOKEN_DEL_PLUS_EQUAL: op = MP_BINARY_OP_INPLACE_ADD; break;
|
||||
case MP_TOKEN_DEL_MINUS_EQUAL: op = MP_BINARY_OP_INPLACE_SUBTRACT; break;
|
||||
case MP_TOKEN_DEL_STAR_EQUAL: op = MP_BINARY_OP_INPLACE_MULTIPLY; break;
|
||||
case MP_TOKEN_DEL_DBL_SLASH_EQUAL: op = MP_BINARY_OP_INPLACE_FLOOR_DIVIDE; break;
|
||||
case MP_TOKEN_DEL_SLASH_EQUAL: op = MP_BINARY_OP_INPLACE_TRUE_DIVIDE; break;
|
||||
case MP_TOKEN_DEL_PERCENT_EQUAL: op = MP_BINARY_OP_INPLACE_MODULO; break;
|
||||
case MP_TOKEN_DEL_DBL_STAR_EQUAL: default: op = MP_BINARY_OP_INPLACE_POWER; break;
|
||||
case MP_TOKEN_DEL_PIPE_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_OR;
|
||||
break;
|
||||
case MP_TOKEN_DEL_CARET_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_XOR;
|
||||
break;
|
||||
case MP_TOKEN_DEL_AMPERSAND_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_AND;
|
||||
break;
|
||||
case MP_TOKEN_DEL_DBL_LESS_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_LSHIFT;
|
||||
break;
|
||||
case MP_TOKEN_DEL_DBL_MORE_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_RSHIFT;
|
||||
break;
|
||||
case MP_TOKEN_DEL_PLUS_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_ADD;
|
||||
break;
|
||||
case MP_TOKEN_DEL_MINUS_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_SUBTRACT;
|
||||
break;
|
||||
case MP_TOKEN_DEL_STAR_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_MULTIPLY;
|
||||
break;
|
||||
case MP_TOKEN_DEL_DBL_SLASH_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_FLOOR_DIVIDE;
|
||||
break;
|
||||
case MP_TOKEN_DEL_SLASH_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_TRUE_DIVIDE;
|
||||
break;
|
||||
case MP_TOKEN_DEL_PERCENT_EQUAL:
|
||||
op = MP_BINARY_OP_INPLACE_MODULO;
|
||||
break;
|
||||
case MP_TOKEN_DEL_DBL_STAR_EQUAL:
|
||||
default:
|
||||
op = MP_BINARY_OP_INPLACE_POWER;
|
||||
break;
|
||||
}
|
||||
EMIT_ARG(binary_op, op);
|
||||
c_assign(comp, pns->nodes[0], ASSIGN_AUG_STORE); // lhs store for aug assign
|
||||
@ -2084,13 +2109,28 @@ STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||
if (MP_PARSE_NODE_IS_TOKEN(pns->nodes[i])) {
|
||||
mp_binary_op_t op;
|
||||
switch (MP_PARSE_NODE_LEAF_ARG(pns->nodes[i])) {
|
||||
case MP_TOKEN_OP_LESS: op = MP_BINARY_OP_LESS; break;
|
||||
case MP_TOKEN_OP_MORE: op = MP_BINARY_OP_MORE; break;
|
||||
case MP_TOKEN_OP_DBL_EQUAL: op = MP_BINARY_OP_EQUAL; break;
|
||||
case MP_TOKEN_OP_LESS_EQUAL: op = MP_BINARY_OP_LESS_EQUAL; break;
|
||||
case MP_TOKEN_OP_MORE_EQUAL: op = MP_BINARY_OP_MORE_EQUAL; break;
|
||||
case MP_TOKEN_OP_NOT_EQUAL: op = MP_BINARY_OP_NOT_EQUAL; break;
|
||||
case MP_TOKEN_KW_IN: default: op = MP_BINARY_OP_IN; break;
|
||||
case MP_TOKEN_OP_LESS:
|
||||
op = MP_BINARY_OP_LESS;
|
||||
break;
|
||||
case MP_TOKEN_OP_MORE:
|
||||
op = MP_BINARY_OP_MORE;
|
||||
break;
|
||||
case MP_TOKEN_OP_DBL_EQUAL:
|
||||
op = MP_BINARY_OP_EQUAL;
|
||||
break;
|
||||
case MP_TOKEN_OP_LESS_EQUAL:
|
||||
op = MP_BINARY_OP_LESS_EQUAL;
|
||||
break;
|
||||
case MP_TOKEN_OP_MORE_EQUAL:
|
||||
op = MP_BINARY_OP_MORE_EQUAL;
|
||||
break;
|
||||
case MP_TOKEN_OP_NOT_EQUAL:
|
||||
op = MP_BINARY_OP_NOT_EQUAL;
|
||||
break;
|
||||
case MP_TOKEN_KW_IN:
|
||||
default:
|
||||
op = MP_BINARY_OP_IN;
|
||||
break;
|
||||
}
|
||||
EMIT_ARG(binary_op, op);
|
||||
} else {
|
||||
@ -2147,13 +2187,27 @@ STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||
mp_binary_op_t op;
|
||||
mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]);
|
||||
switch (tok) {
|
||||
case MP_TOKEN_OP_PLUS: op = MP_BINARY_OP_ADD; break;
|
||||
case MP_TOKEN_OP_MINUS: op = MP_BINARY_OP_SUBTRACT; break;
|
||||
case MP_TOKEN_OP_STAR: op = MP_BINARY_OP_MULTIPLY; break;
|
||||
case MP_TOKEN_OP_DBL_SLASH: op = MP_BINARY_OP_FLOOR_DIVIDE; break;
|
||||
case MP_TOKEN_OP_SLASH: op = MP_BINARY_OP_TRUE_DIVIDE; break;
|
||||
case MP_TOKEN_OP_PERCENT: op = MP_BINARY_OP_MODULO; break;
|
||||
case MP_TOKEN_OP_DBL_LESS: op = MP_BINARY_OP_LSHIFT; break;
|
||||
case MP_TOKEN_OP_PLUS:
|
||||
op = MP_BINARY_OP_ADD;
|
||||
break;
|
||||
case MP_TOKEN_OP_MINUS:
|
||||
op = MP_BINARY_OP_SUBTRACT;
|
||||
break;
|
||||
case MP_TOKEN_OP_STAR:
|
||||
op = MP_BINARY_OP_MULTIPLY;
|
||||
break;
|
||||
case MP_TOKEN_OP_DBL_SLASH:
|
||||
op = MP_BINARY_OP_FLOOR_DIVIDE;
|
||||
break;
|
||||
case MP_TOKEN_OP_SLASH:
|
||||
op = MP_BINARY_OP_TRUE_DIVIDE;
|
||||
break;
|
||||
case MP_TOKEN_OP_PERCENT:
|
||||
op = MP_BINARY_OP_MODULO;
|
||||
break;
|
||||
case MP_TOKEN_OP_DBL_LESS:
|
||||
op = MP_BINARY_OP_LSHIFT;
|
||||
break;
|
||||
default:
|
||||
assert(tok == MP_TOKEN_OP_DBL_MORE);
|
||||
op = MP_BINARY_OP_RSHIFT;
|
||||
@ -2168,8 +2222,12 @@ STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||
mp_unary_op_t op;
|
||||
mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]);
|
||||
switch (tok) {
|
||||
case MP_TOKEN_OP_PLUS: op = MP_UNARY_OP_POSITIVE; break;
|
||||
case MP_TOKEN_OP_MINUS: op = MP_UNARY_OP_NEGATIVE; break;
|
||||
case MP_TOKEN_OP_PLUS:
|
||||
op = MP_UNARY_OP_POSITIVE;
|
||||
break;
|
||||
case MP_TOKEN_OP_MINUS:
|
||||
op = MP_UNARY_OP_NEGATIVE;
|
||||
break;
|
||||
default:
|
||||
assert(tok == MP_TOKEN_OP_TILDE);
|
||||
op = MP_UNARY_OP_INVERT;
|
||||
@ -2715,8 +2773,12 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
|
||||
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
|
||||
uintptr_t arg = MP_PARSE_NODE_LEAF_ARG(pn);
|
||||
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
|
||||
case MP_PARSE_NODE_ID: compile_load_id(comp, arg); break;
|
||||
case MP_PARSE_NODE_STRING: EMIT_ARG(load_const_str, arg); break;
|
||||
case MP_PARSE_NODE_ID:
|
||||
compile_load_id(comp, arg);
|
||||
break;
|
||||
case MP_PARSE_NODE_STRING:
|
||||
EMIT_ARG(load_const_str, arg);
|
||||
break;
|
||||
case MP_PARSE_NODE_BYTES:
|
||||
// only create and load the actual bytes object on the last pass
|
||||
if (comp->pass != MP_PASS_EMIT) {
|
||||
@ -2730,7 +2792,8 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
|
||||
comp->scope_cur->scope_flags |= MP_SCOPE_FLAG_HASCONSTS;
|
||||
#endif
|
||||
break;
|
||||
case MP_PARSE_NODE_TOKEN: default:
|
||||
case MP_PARSE_NODE_TOKEN:
|
||||
default:
|
||||
if (arg == MP_TOKEN_NEWLINE) {
|
||||
// this can occur when file_input lets through a NEWLINE (eg if file starts with a newline)
|
||||
// or when single_input lets through a NEWLINE (user enters a blank line)
|
||||
@ -3140,11 +3203,21 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
|
||||
if (MP_PARSE_NODE_IS_ID(pn_annotation)) {
|
||||
qstr ret_type = MP_PARSE_NODE_LEAF_ARG(pn_annotation);
|
||||
switch (ret_type) {
|
||||
case MP_QSTR_object: type_sig = MP_NATIVE_TYPE_OBJ; break;
|
||||
case MP_QSTR_bool: type_sig = MP_NATIVE_TYPE_BOOL; break;
|
||||
case MP_QSTR_int: type_sig = MP_NATIVE_TYPE_INT; break;
|
||||
case MP_QSTR_uint: type_sig = MP_NATIVE_TYPE_UINT; break;
|
||||
default: compile_syntax_error(comp, pn_annotation, "unknown type"); return;
|
||||
case MP_QSTR_object:
|
||||
type_sig = MP_NATIVE_TYPE_OBJ;
|
||||
break;
|
||||
case MP_QSTR_bool:
|
||||
type_sig = MP_NATIVE_TYPE_BOOL;
|
||||
break;
|
||||
case MP_QSTR_int:
|
||||
type_sig = MP_NATIVE_TYPE_INT;
|
||||
break;
|
||||
case MP_QSTR_uint:
|
||||
type_sig = MP_NATIVE_TYPE_UINT;
|
||||
break;
|
||||
default:
|
||||
compile_syntax_error(comp, pn_annotation, "unknown type");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
compile_syntax_error(comp, pn_annotation, "return annotation must be an identifier");
|
||||
@ -3269,7 +3342,9 @@ STATIC void scope_compute_things(scope_t *scope) {
|
||||
if (id->flags & ID_FLAG_IS_STAR_PARAM) {
|
||||
if (id_param != NULL) {
|
||||
// swap star param with last param
|
||||
id_info_t temp = *id_param; *id_param = *id; *id = temp;
|
||||
id_info_t temp = *id_param;
|
||||
*id_param = *id;
|
||||
*id = temp;
|
||||
}
|
||||
break;
|
||||
} else if (id_param == NULL && id->flags == ID_FLAG_IS_PARAM) {
|
||||
|
12
py/emitbc.c
12
py/emitbc.c
@ -526,9 +526,15 @@ void mp_emit_bc_import(emit_t *emit, qstr qst, int kind) {
|
||||
void mp_emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
|
||||
emit_bc_pre(emit, 1);
|
||||
switch (tok) {
|
||||
case MP_TOKEN_KW_FALSE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_FALSE); break;
|
||||
case MP_TOKEN_KW_NONE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_NONE); break;
|
||||
case MP_TOKEN_KW_TRUE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_TRUE); break;
|
||||
case MP_TOKEN_KW_FALSE:
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_FALSE);
|
||||
break;
|
||||
case MP_TOKEN_KW_NONE:
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_NONE);
|
||||
break;
|
||||
case MP_TOKEN_KW_TRUE:
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_TRUE);
|
||||
break;
|
||||
default:
|
||||
assert(tok == MP_TOKEN_ELLIPSIS);
|
||||
emit_write_bytecode_byte_obj(emit, MP_BC_LOAD_CONST_OBJ, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj));
|
||||
|
@ -131,7 +131,9 @@ STATIC bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t;
|
||||
typedef struct _reg_name_t { byte reg;
|
||||
byte name[3];
|
||||
} reg_name_t;
|
||||
STATIC const reg_name_t reg_name_table[] = {
|
||||
{0, "r0\0"},
|
||||
{1, "r1\0"},
|
||||
@ -157,7 +159,9 @@ STATIC const reg_name_t reg_name_table[] = {
|
||||
};
|
||||
|
||||
#define MAX_SPECIAL_REGISTER_NAME_LENGTH 7
|
||||
typedef struct _special_reg_name_t { byte reg; char name[MAX_SPECIAL_REGISTER_NAME_LENGTH + 1]; } special_reg_name_t;
|
||||
typedef struct _special_reg_name_t { byte reg;
|
||||
char name[MAX_SPECIAL_REGISTER_NAME_LENGTH + 1];
|
||||
} special_reg_name_t;
|
||||
STATIC const special_reg_name_t special_reg_name_table[] = {
|
||||
{5, "IPSR"},
|
||||
{17, "BASEPRI"},
|
||||
@ -347,7 +351,9 @@ STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct _cc_name_t { byte cc; byte name[2]; } cc_name_t;
|
||||
typedef struct _cc_name_t { byte cc;
|
||||
byte name[2];
|
||||
} cc_name_t;
|
||||
STATIC const cc_name_t cc_name_table[] = {
|
||||
{ ASM_THUMB_CC_EQ, "eq" },
|
||||
{ ASM_THUMB_CC_NE, "ne" },
|
||||
@ -365,7 +371,9 @@ STATIC const cc_name_t cc_name_table[] = {
|
||||
{ ASM_THUMB_CC_LE, "le" },
|
||||
};
|
||||
|
||||
typedef struct _format_4_op_t { byte op; char name[3]; } format_4_op_t;
|
||||
typedef struct _format_4_op_t { byte op;
|
||||
char name[3];
|
||||
} format_4_op_t;
|
||||
#define X(x) (((x) >> 4) & 0xff) // only need 1 byte to distinguish these ops
|
||||
STATIC const format_4_op_t format_4_op_table[] = {
|
||||
{ X(ASM_THUMB_FORMAT_4_EOR), "eor" },
|
||||
@ -387,7 +395,9 @@ STATIC const format_4_op_t format_4_op_table[] = {
|
||||
#undef X
|
||||
|
||||
// name is actually a qstr, which should fit in 16 bits
|
||||
typedef struct _format_9_10_op_t { uint16_t op; uint16_t name; } format_9_10_op_t;
|
||||
typedef struct _format_9_10_op_t { uint16_t op;
|
||||
uint16_t name;
|
||||
} format_9_10_op_t;
|
||||
#define X(x) (x)
|
||||
STATIC const format_9_10_op_t format_9_10_op_table[] = {
|
||||
{ X(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER), MP_QSTR_ldr },
|
||||
@ -401,7 +411,9 @@ STATIC const format_9_10_op_t format_9_10_op_table[] = {
|
||||
|
||||
#if MICROPY_EMIT_INLINE_THUMB_FLOAT
|
||||
// actual opcodes are: 0xee00 | op.hi_nibble, 0x0a00 | op.lo_nibble
|
||||
typedef struct _format_vfp_op_t { byte op; char name[3]; } format_vfp_op_t;
|
||||
typedef struct _format_vfp_op_t { byte op;
|
||||
char name[3];
|
||||
} format_vfp_op_t;
|
||||
STATIC const format_vfp_op_t format_vfp_op_table[] = {
|
||||
{ 0x30, "add" },
|
||||
{ 0x34, "sub" },
|
||||
|
@ -115,7 +115,9 @@ STATIC bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_nu
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t;
|
||||
typedef struct _reg_name_t { byte reg;
|
||||
byte name[3];
|
||||
} reg_name_t;
|
||||
STATIC const reg_name_t reg_name_table[] = {
|
||||
{0, "a0\0"},
|
||||
{1, "a1\0"},
|
||||
|
@ -138,29 +138,48 @@ typedef enum {
|
||||
|
||||
int mp_native_type_from_qstr(qstr qst) {
|
||||
switch (qst) {
|
||||
case MP_QSTR_object: return MP_NATIVE_TYPE_OBJ;
|
||||
case MP_QSTR_bool: return MP_NATIVE_TYPE_BOOL;
|
||||
case MP_QSTR_int: return MP_NATIVE_TYPE_INT;
|
||||
case MP_QSTR_uint: return MP_NATIVE_TYPE_UINT;
|
||||
case MP_QSTR_ptr: return MP_NATIVE_TYPE_PTR;
|
||||
case MP_QSTR_ptr8: return MP_NATIVE_TYPE_PTR8;
|
||||
case MP_QSTR_ptr16: return MP_NATIVE_TYPE_PTR16;
|
||||
case MP_QSTR_ptr32: return MP_NATIVE_TYPE_PTR32;
|
||||
default: return -1;
|
||||
case MP_QSTR_object:
|
||||
return MP_NATIVE_TYPE_OBJ;
|
||||
case MP_QSTR_bool:
|
||||
return MP_NATIVE_TYPE_BOOL;
|
||||
case MP_QSTR_int:
|
||||
return MP_NATIVE_TYPE_INT;
|
||||
case MP_QSTR_uint:
|
||||
return MP_NATIVE_TYPE_UINT;
|
||||
case MP_QSTR_ptr:
|
||||
return MP_NATIVE_TYPE_PTR;
|
||||
case MP_QSTR_ptr8:
|
||||
return MP_NATIVE_TYPE_PTR8;
|
||||
case MP_QSTR_ptr16:
|
||||
return MP_NATIVE_TYPE_PTR16;
|
||||
case MP_QSTR_ptr32:
|
||||
return MP_NATIVE_TYPE_PTR32;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC qstr vtype_to_qstr(vtype_kind_t vtype) {
|
||||
switch (vtype) {
|
||||
case VTYPE_PYOBJ: return MP_QSTR_object;
|
||||
case VTYPE_BOOL: return MP_QSTR_bool;
|
||||
case VTYPE_INT: return MP_QSTR_int;
|
||||
case VTYPE_UINT: return MP_QSTR_uint;
|
||||
case VTYPE_PTR: return MP_QSTR_ptr;
|
||||
case VTYPE_PTR8: return MP_QSTR_ptr8;
|
||||
case VTYPE_PTR16: return MP_QSTR_ptr16;
|
||||
case VTYPE_PTR32: return MP_QSTR_ptr32;
|
||||
case VTYPE_PTR_NONE: default: return MP_QSTR_None;
|
||||
case VTYPE_PYOBJ:
|
||||
return MP_QSTR_object;
|
||||
case VTYPE_BOOL:
|
||||
return MP_QSTR_bool;
|
||||
case VTYPE_INT:
|
||||
return MP_QSTR_int;
|
||||
case VTYPE_UINT:
|
||||
return MP_QSTR_uint;
|
||||
case VTYPE_PTR:
|
||||
return MP_QSTR_ptr;
|
||||
case VTYPE_PTR8:
|
||||
return MP_QSTR_ptr8;
|
||||
case VTYPE_PTR16:
|
||||
return MP_QSTR_ptr16;
|
||||
case VTYPE_PTR32:
|
||||
return MP_QSTR_ptr32;
|
||||
case VTYPE_PTR_NONE:
|
||||
default:
|
||||
return MP_QSTR_None;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,11 +68,20 @@ union floatbits {
|
||||
float f;
|
||||
uint32_t u;
|
||||
};
|
||||
static inline int fp_signbit(float x) { union floatbits fb = {x}; return fb.u & FLT_SIGN_MASK; }
|
||||
static inline int fp_signbit(float x) {
|
||||
union floatbits fb = {x};
|
||||
return fb.u & FLT_SIGN_MASK;
|
||||
}
|
||||
#define fp_isnan(x) isnan(x)
|
||||
#define fp_isinf(x) isinf(x)
|
||||
static inline int fp_iszero(float x) { union floatbits fb = {x}; return fb.u == 0; }
|
||||
static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u < 0x3f800000; }
|
||||
static inline int fp_iszero(float x) {
|
||||
union floatbits fb = {x};
|
||||
return fb.u == 0;
|
||||
}
|
||||
static inline int fp_isless1(float x) {
|
||||
union floatbits fb = {x};
|
||||
return fb.u < 0x3f800000;
|
||||
}
|
||||
|
||||
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
||||
|
||||
|
81
py/gc.c
81
py/gc.c
@ -472,10 +472,38 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
|
||||
n_free = 0;
|
||||
for (i = MP_STATE_MEM(gc_last_free_atb_index); i < MP_STATE_MEM(gc_alloc_table_byte_len); i++) {
|
||||
byte a = MP_STATE_MEM(gc_alloc_table_start)[i];
|
||||
if (ATB_0_IS_FREE(a)) { if (++n_free >= n_blocks) { i = i * BLOCKS_PER_ATB + 0; goto found; } } else { n_free = 0; }
|
||||
if (ATB_1_IS_FREE(a)) { if (++n_free >= n_blocks) { i = i * BLOCKS_PER_ATB + 1; goto found; } } else { n_free = 0; }
|
||||
if (ATB_2_IS_FREE(a)) { if (++n_free >= n_blocks) { i = i * BLOCKS_PER_ATB + 2; goto found; } } else { n_free = 0; }
|
||||
if (ATB_3_IS_FREE(a)) { if (++n_free >= n_blocks) { i = i * BLOCKS_PER_ATB + 3; goto found; } } else { n_free = 0; }
|
||||
if (ATB_0_IS_FREE(a)) {
|
||||
if (++n_free >= n_blocks) {
|
||||
i = i * BLOCKS_PER_ATB + 0;
|
||||
goto found;
|
||||
}
|
||||
} else {
|
||||
n_free = 0;
|
||||
}
|
||||
if (ATB_1_IS_FREE(a)) {
|
||||
if (++n_free >= n_blocks) {
|
||||
i = i * BLOCKS_PER_ATB + 1;
|
||||
goto found;
|
||||
}
|
||||
} else {
|
||||
n_free = 0;
|
||||
}
|
||||
if (ATB_2_IS_FREE(a)) {
|
||||
if (++n_free >= n_blocks) {
|
||||
i = i * BLOCKS_PER_ATB + 2;
|
||||
goto found;
|
||||
}
|
||||
} else {
|
||||
n_free = 0;
|
||||
}
|
||||
if (ATB_3_IS_FREE(a)) {
|
||||
if (++n_free >= n_blocks) {
|
||||
i = i * BLOCKS_PER_ATB + 3;
|
||||
goto found;
|
||||
}
|
||||
} else {
|
||||
n_free = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GC_EXIT();
|
||||
@ -836,7 +864,9 @@ void gc_dump_alloc_table(void) {
|
||||
}
|
||||
int c = ' ';
|
||||
switch (ATB_GET_KIND(bl)) {
|
||||
case AT_FREE: c = '.'; break;
|
||||
case AT_FREE:
|
||||
c = '.';
|
||||
break;
|
||||
/* this prints out if the object is reachable from BSS or STACK (for unix only)
|
||||
case AT_HEAD: {
|
||||
c = 'h';
|
||||
@ -866,22 +896,35 @@ void gc_dump_alloc_table(void) {
|
||||
/* this prints the uPy object type of the head block */
|
||||
case AT_HEAD: {
|
||||
void **ptr = (void **)(MP_STATE_MEM(gc_pool_start) + bl * BYTES_PER_BLOCK);
|
||||
if (*ptr == &mp_type_tuple) { c = 'T'; }
|
||||
else if (*ptr == &mp_type_list) { c = 'L'; }
|
||||
else if (*ptr == &mp_type_dict) { c = 'D'; }
|
||||
else if (*ptr == &mp_type_str || *ptr == &mp_type_bytes) { c = 'S'; }
|
||||
if (*ptr == &mp_type_tuple) {
|
||||
c = 'T';
|
||||
} else if (*ptr == &mp_type_list) {
|
||||
c = 'L';
|
||||
} else if (*ptr == &mp_type_dict) {
|
||||
c = 'D';
|
||||
} else if (*ptr == &mp_type_str || *ptr == &mp_type_bytes) {
|
||||
c = 'S';
|
||||
}
|
||||
#if MICROPY_PY_BUILTINS_BYTEARRAY
|
||||
else if (*ptr == &mp_type_bytearray) { c = 'A'; }
|
||||
else if (*ptr == &mp_type_bytearray) {
|
||||
c = 'A';
|
||||
}
|
||||
#endif
|
||||
#if MICROPY_PY_ARRAY
|
||||
else if (*ptr == &mp_type_array) { c = 'A'; }
|
||||
else if (*ptr == &mp_type_array) {
|
||||
c = 'A';
|
||||
}
|
||||
#endif
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
else if (*ptr == &mp_type_float) { c = 'F'; }
|
||||
else if (*ptr == &mp_type_float) {
|
||||
c = 'F';
|
||||
}
|
||||
#endif
|
||||
else if (*ptr == &mp_type_fun_bc) { c = 'B'; }
|
||||
else if (*ptr == &mp_type_module) { c = 'M'; }
|
||||
else {
|
||||
else if (*ptr == &mp_type_fun_bc) {
|
||||
c = 'B';
|
||||
} else if (*ptr == &mp_type_module) {
|
||||
c = 'M';
|
||||
} else {
|
||||
c = 'h';
|
||||
#if 0
|
||||
// This code prints "Q" for qstr-pool data, and "q" for qstr-str
|
||||
@ -903,8 +946,12 @@ void gc_dump_alloc_table(void) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AT_TAIL: c = '='; break;
|
||||
case AT_MARK: c = 'm'; break;
|
||||
case AT_TAIL:
|
||||
c = '=';
|
||||
break;
|
||||
case AT_MARK:
|
||||
c = 'm';
|
||||
break;
|
||||
}
|
||||
mp_printf(&mp_plat_print, "%c", c);
|
||||
}
|
||||
|
44
py/lexer.c
44
py/lexer.c
@ -305,17 +305,36 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
|
||||
switch (c) {
|
||||
// note: "c" can never be MP_LEXER_EOF because next_char
|
||||
// always inserts a newline at the end of the input stream
|
||||
case '\n': c = MP_LEXER_EOF; break; // backslash escape the newline, just ignore it
|
||||
case '\\': break;
|
||||
case '\'': break;
|
||||
case '"': break;
|
||||
case 'a': c = 0x07; break;
|
||||
case 'b': c = 0x08; break;
|
||||
case 't': c = 0x09; break;
|
||||
case 'n': c = 0x0a; break;
|
||||
case 'v': c = 0x0b; break;
|
||||
case 'f': c = 0x0c; break;
|
||||
case 'r': c = 0x0d; break;
|
||||
case '\n':
|
||||
c = MP_LEXER_EOF;
|
||||
break; // backslash escape the newline, just ignore it
|
||||
case '\\':
|
||||
break;
|
||||
case '\'':
|
||||
break;
|
||||
case '"':
|
||||
break;
|
||||
case 'a':
|
||||
c = 0x07;
|
||||
break;
|
||||
case 'b':
|
||||
c = 0x08;
|
||||
break;
|
||||
case 't':
|
||||
c = 0x09;
|
||||
break;
|
||||
case 'n':
|
||||
c = 0x0a;
|
||||
break;
|
||||
case 'v':
|
||||
c = 0x0b;
|
||||
break;
|
||||
case 'f':
|
||||
c = 0x0c;
|
||||
break;
|
||||
case 'r':
|
||||
c = 0x0d;
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
if (lex->tok_kind == MP_TOKEN_BYTES) {
|
||||
@ -324,8 +343,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
|
||||
break;
|
||||
}
|
||||
// Otherwise fall through.
|
||||
case 'x':
|
||||
{
|
||||
case 'x': {
|
||||
mp_uint_t num = 0;
|
||||
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
|
||||
// not enough hex chars for escape sequence
|
||||
|
@ -13,43 +13,44 @@ import sys
|
||||
# - iterating through bytes is different
|
||||
# - codepoint2name lives in a different module
|
||||
import platform
|
||||
if platform.python_version_tuple()[0] == '2':
|
||||
|
||||
if platform.python_version_tuple()[0] == "2":
|
||||
bytes_cons = lambda val, enc=None: bytearray(val)
|
||||
from htmlentitydefs import codepoint2name
|
||||
elif platform.python_version_tuple()[0] == '3':
|
||||
elif platform.python_version_tuple()[0] == "3":
|
||||
bytes_cons = bytes
|
||||
from html.entities import codepoint2name
|
||||
# end compatibility code
|
||||
|
||||
codepoint2name[ord('-')] = 'hyphen';
|
||||
codepoint2name[ord("-")] = "hyphen"
|
||||
|
||||
# add some custom names to map characters that aren't in HTML
|
||||
codepoint2name[ord(' ')] = 'space'
|
||||
codepoint2name[ord('\'')] = 'squot'
|
||||
codepoint2name[ord(',')] = 'comma'
|
||||
codepoint2name[ord('.')] = 'dot'
|
||||
codepoint2name[ord(':')] = 'colon'
|
||||
codepoint2name[ord(';')] = 'semicolon'
|
||||
codepoint2name[ord('/')] = 'slash'
|
||||
codepoint2name[ord('%')] = 'percent'
|
||||
codepoint2name[ord('#')] = 'hash'
|
||||
codepoint2name[ord('(')] = 'paren_open'
|
||||
codepoint2name[ord(')')] = 'paren_close'
|
||||
codepoint2name[ord('[')] = 'bracket_open'
|
||||
codepoint2name[ord(']')] = 'bracket_close'
|
||||
codepoint2name[ord('{')] = 'brace_open'
|
||||
codepoint2name[ord('}')] = 'brace_close'
|
||||
codepoint2name[ord('*')] = 'star'
|
||||
codepoint2name[ord('!')] = 'bang'
|
||||
codepoint2name[ord('\\')] = 'backslash'
|
||||
codepoint2name[ord('+')] = 'plus'
|
||||
codepoint2name[ord('$')] = 'dollar'
|
||||
codepoint2name[ord('=')] = 'equals'
|
||||
codepoint2name[ord('?')] = 'question'
|
||||
codepoint2name[ord('@')] = 'at_sign'
|
||||
codepoint2name[ord('^')] = 'caret'
|
||||
codepoint2name[ord('|')] = 'pipe'
|
||||
codepoint2name[ord('~')] = 'tilde'
|
||||
codepoint2name[ord(" ")] = "space"
|
||||
codepoint2name[ord("'")] = "squot"
|
||||
codepoint2name[ord(",")] = "comma"
|
||||
codepoint2name[ord(".")] = "dot"
|
||||
codepoint2name[ord(":")] = "colon"
|
||||
codepoint2name[ord(";")] = "semicolon"
|
||||
codepoint2name[ord("/")] = "slash"
|
||||
codepoint2name[ord("%")] = "percent"
|
||||
codepoint2name[ord("#")] = "hash"
|
||||
codepoint2name[ord("(")] = "paren_open"
|
||||
codepoint2name[ord(")")] = "paren_close"
|
||||
codepoint2name[ord("[")] = "bracket_open"
|
||||
codepoint2name[ord("]")] = "bracket_close"
|
||||
codepoint2name[ord("{")] = "brace_open"
|
||||
codepoint2name[ord("}")] = "brace_close"
|
||||
codepoint2name[ord("*")] = "star"
|
||||
codepoint2name[ord("!")] = "bang"
|
||||
codepoint2name[ord("\\")] = "backslash"
|
||||
codepoint2name[ord("+")] = "plus"
|
||||
codepoint2name[ord("$")] = "dollar"
|
||||
codepoint2name[ord("=")] = "equals"
|
||||
codepoint2name[ord("?")] = "question"
|
||||
codepoint2name[ord("@")] = "at_sign"
|
||||
codepoint2name[ord("^")] = "caret"
|
||||
codepoint2name[ord("|")] = "pipe"
|
||||
codepoint2name[ord("~")] = "tilde"
|
||||
|
||||
# this must match the equivalent function in qstr.c
|
||||
def compute_hash(qstr, bytes_hash):
|
||||
@ -59,37 +60,40 @@ def compute_hash(qstr, bytes_hash):
|
||||
# Make sure that valid hash is never zero, zero means "hash not computed"
|
||||
return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1
|
||||
|
||||
|
||||
def qstr_escape(qst):
|
||||
def esc_char(m):
|
||||
c = ord(m.group(0))
|
||||
try:
|
||||
name = codepoint2name[c]
|
||||
except KeyError:
|
||||
name = '0x%02x' % c
|
||||
return "_" + name + '_'
|
||||
return re.sub(r'[^A-Za-z0-9_]', esc_char, qst)
|
||||
name = "0x%02x" % c
|
||||
return "_" + name + "_"
|
||||
|
||||
return re.sub(r"[^A-Za-z0-9_]", esc_char, qst)
|
||||
|
||||
|
||||
def parse_input_headers(infiles):
|
||||
# read the qstrs in from the input files
|
||||
qcfgs = {}
|
||||
qstrs = {}
|
||||
for infile in infiles:
|
||||
with open(infile, 'rt') as f:
|
||||
with open(infile, "rt") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
|
||||
# is this a config line?
|
||||
match = re.match(r'^QCFG\((.+), (.+)\)', line)
|
||||
match = re.match(r"^QCFG\((.+), (.+)\)", line)
|
||||
if match:
|
||||
value = match.group(2)
|
||||
if value[0] == '(' and value[-1] == ')':
|
||||
if value[0] == "(" and value[-1] == ")":
|
||||
# strip parenthesis from config value
|
||||
value = value[1:-1]
|
||||
qcfgs[match.group(1)] = value
|
||||
continue
|
||||
|
||||
# is this a QSTR line?
|
||||
match = re.match(r'^Q\((.*)\)$', line)
|
||||
match = re.match(r"^Q\((.*)\)$", line)
|
||||
if not match:
|
||||
continue
|
||||
|
||||
@ -97,8 +101,8 @@ def parse_input_headers(infiles):
|
||||
qstr = match.group(1)
|
||||
|
||||
# special case to specify control characters
|
||||
if qstr == '\\n':
|
||||
qstr = '\n'
|
||||
if qstr == "\\n":
|
||||
qstr = "\n"
|
||||
|
||||
# work out the corresponding qstr name
|
||||
ident = qstr_escape(qstr)
|
||||
@ -127,43 +131,54 @@ def parse_input_headers(infiles):
|
||||
|
||||
return qcfgs, qstrs
|
||||
|
||||
|
||||
def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
|
||||
qbytes = bytes_cons(qstr, 'utf8')
|
||||
qbytes = bytes_cons(qstr, "utf8")
|
||||
qlen = len(qbytes)
|
||||
qhash = compute_hash(qbytes, cfg_bytes_hash)
|
||||
if all(32 <= ord(c) <= 126 and c != '\\' and c != '"' for c in qstr):
|
||||
if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr):
|
||||
# qstr is all printable ASCII so render it as-is (for easier debugging)
|
||||
qdata = qstr
|
||||
else:
|
||||
# qstr contains non-printable codes so render entire thing as hex pairs
|
||||
qdata = ''.join(('\\x%02x' % b) for b in qbytes)
|
||||
qdata = "".join(("\\x%02x" % b) for b in qbytes)
|
||||
if qlen >= (1 << (8 * cfg_bytes_len)):
|
||||
print('qstr is too long:', qstr)
|
||||
print("qstr is too long:", qstr)
|
||||
assert False
|
||||
qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
|
||||
qhash_str = ('\\x%02x' * cfg_bytes_hash) % tuple(((qhash >> (8 * i)) & 0xff) for i in range(cfg_bytes_hash))
|
||||
qlen_str = ("\\x%02x" * cfg_bytes_len) % tuple(
|
||||
((qlen >> (8 * i)) & 0xFF) for i in range(cfg_bytes_len)
|
||||
)
|
||||
qhash_str = ("\\x%02x" * cfg_bytes_hash) % tuple(
|
||||
((qhash >> (8 * i)) & 0xFF) for i in range(cfg_bytes_hash)
|
||||
)
|
||||
return '(const byte*)"%s%s" "%s"' % (qhash_str, qlen_str, qdata)
|
||||
|
||||
|
||||
def print_qstr_data(qcfgs, qstrs):
|
||||
# get config variables
|
||||
cfg_bytes_len = int(qcfgs['BYTES_IN_LEN'])
|
||||
cfg_bytes_hash = int(qcfgs['BYTES_IN_HASH'])
|
||||
cfg_bytes_len = int(qcfgs["BYTES_IN_LEN"])
|
||||
cfg_bytes_hash = int(qcfgs["BYTES_IN_HASH"])
|
||||
|
||||
# print out the starter of the generated C header file
|
||||
print('// This file was automatically generated by makeqstrdata.py')
|
||||
print('')
|
||||
print("// This file was automatically generated by makeqstrdata.py")
|
||||
print("")
|
||||
|
||||
# add NULL qstr with no hash or data
|
||||
print('QDEF(MP_QSTR_NULL, (const byte*)"%s%s" "")' % ('\\x00' * cfg_bytes_hash, '\\x00' * cfg_bytes_len))
|
||||
print(
|
||||
'QDEF(MP_QSTR_NULL, (const byte*)"%s%s" "")'
|
||||
% ("\\x00" * cfg_bytes_hash, "\\x00" * cfg_bytes_len)
|
||||
)
|
||||
|
||||
# go through each qstr and print it out
|
||||
for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
|
||||
qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)
|
||||
print('QDEF(MP_QSTR_%s, %s)' % (ident, qbytes))
|
||||
print("QDEF(MP_QSTR_%s, %s)" % (ident, qbytes))
|
||||
|
||||
|
||||
def do_work(infiles):
|
||||
qcfgs, qstrs = parse_input_headers(infiles)
|
||||
print_qstr_data(qcfgs, qstrs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
do_work(sys.argv[1:])
|
||||
|
@ -13,7 +13,7 @@ import os
|
||||
|
||||
# Blacklist of qstrings that are specially handled in further
|
||||
# processing and should be ignored
|
||||
QSTRING_BLACK_LIST = set(['NULL', 'number_of'])
|
||||
QSTRING_BLACK_LIST = set(["NULL", "number_of"])
|
||||
|
||||
|
||||
def write_out(fname, output):
|
||||
@ -23,16 +23,17 @@ def write_out(fname, output):
|
||||
with open(args.output_dir + "/" + fname + ".qstr", "w") as f:
|
||||
f.write("\n".join(output) + "\n")
|
||||
|
||||
|
||||
def process_file(f):
|
||||
re_line = re.compile(r"#[line]*\s\d+\s\"([^\"]+)\"")
|
||||
re_qstr = re.compile(r'MP_QSTR_[_a-zA-Z0-9]+')
|
||||
re_qstr = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+")
|
||||
output = []
|
||||
last_fname = None
|
||||
for line in f:
|
||||
if line.isspace():
|
||||
continue
|
||||
# match gcc-like output (# n "file") and msvc-like output (#line n "file")
|
||||
if line.startswith(('# ', '#line')):
|
||||
if line.startswith(("# ", "#line")):
|
||||
m = re_line.match(line)
|
||||
assert m is not None
|
||||
fname = m.group(1)
|
||||
@ -44,9 +45,9 @@ def process_file(f):
|
||||
last_fname = fname
|
||||
continue
|
||||
for match in re_qstr.findall(line):
|
||||
name = match.replace('MP_QSTR_', '')
|
||||
name = match.replace("MP_QSTR_", "")
|
||||
if name not in QSTRING_BLACK_LIST:
|
||||
output.append('Q(' + name + ')')
|
||||
output.append("Q(" + name + ")")
|
||||
|
||||
write_out(last_fname, output)
|
||||
return ""
|
||||
@ -55,6 +56,7 @@ def process_file(f):
|
||||
def cat_together():
|
||||
import glob
|
||||
import hashlib
|
||||
|
||||
hasher = hashlib.md5()
|
||||
all_lines = []
|
||||
outf = open(args.output_dir + "/out", "wb")
|
||||
@ -91,11 +93,12 @@ def cat_together():
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 5:
|
||||
print('usage: %s command input_filename output_dir output_file' % sys.argv[0])
|
||||
print("usage: %s command input_filename output_dir output_file" % sys.argv[0])
|
||||
sys.exit(2)
|
||||
|
||||
class Args:
|
||||
pass
|
||||
|
||||
args = Args()
|
||||
args.command = sys.argv[1]
|
||||
args.input_filename = sys.argv[2]
|
||||
|
@ -11,6 +11,7 @@ import os
|
||||
import datetime
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_version_info_from_git():
|
||||
# Python 2.6 doesn't have check_output, so check for that
|
||||
try:
|
||||
@ -21,7 +22,11 @@ def get_version_info_from_git():
|
||||
|
||||
# Note: git describe doesn't work if no tag is available
|
||||
try:
|
||||
git_tag = subprocess.check_output(["git", "describe", "--dirty", "--always"], stderr=subprocess.STDOUT, universal_newlines=True).strip()
|
||||
git_tag = subprocess.check_output(
|
||||
["git", "describe", "--dirty", "--always"],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
).strip()
|
||||
except subprocess.CalledProcessError as er:
|
||||
if er.returncode == 128:
|
||||
# git exit code of 128 means no repository found
|
||||
@ -30,7 +35,11 @@ def get_version_info_from_git():
|
||||
except OSError:
|
||||
return None
|
||||
try:
|
||||
git_hash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], stderr=subprocess.STDOUT, universal_newlines=True).strip()
|
||||
git_hash = subprocess.check_output(
|
||||
["git", "rev-parse", "--short", "HEAD"],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
).strip()
|
||||
except subprocess.CalledProcessError:
|
||||
git_hash = "unknown"
|
||||
except OSError:
|
||||
@ -38,9 +47,13 @@ def get_version_info_from_git():
|
||||
|
||||
try:
|
||||
# Check if there are any modified files.
|
||||
subprocess.check_call(["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], stderr=subprocess.STDOUT)
|
||||
subprocess.check_call(
|
||||
["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], stderr=subprocess.STDOUT
|
||||
)
|
||||
# Check if there are any staged files.
|
||||
subprocess.check_call(["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], stderr=subprocess.STDOUT)
|
||||
subprocess.check_call(
|
||||
["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], stderr=subprocess.STDOUT
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
git_hash += "-dirty"
|
||||
except OSError:
|
||||
@ -48,6 +61,7 @@ def get_version_info_from_git():
|
||||
|
||||
return git_tag, git_hash
|
||||
|
||||
|
||||
def get_version_info_from_docs_conf():
|
||||
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "docs", "conf.py")) as f:
|
||||
for line in f:
|
||||
@ -57,6 +71,7 @@ def get_version_info_from_docs_conf():
|
||||
return git_tag, "<no hash>"
|
||||
return None
|
||||
|
||||
|
||||
def make_version_header(filename):
|
||||
# Get version info using git, with fallback to docs/conf.py
|
||||
info = get_version_info_from_git()
|
||||
@ -71,12 +86,16 @@ def make_version_header(filename):
|
||||
#define MICROPY_GIT_TAG "%s"
|
||||
#define MICROPY_GIT_HASH "%s"
|
||||
#define MICROPY_BUILD_DATE "%s"
|
||||
""" % (git_tag, git_hash, datetime.date.today().strftime("%Y-%m-%d"))
|
||||
""" % (
|
||||
git_tag,
|
||||
git_hash,
|
||||
datetime.date.today().strftime("%Y-%m-%d"),
|
||||
)
|
||||
|
||||
# Check if the file contents changed from last time
|
||||
write_file = True
|
||||
if os.path.isfile(filename):
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename, "r") as f:
|
||||
existing_data = f.read()
|
||||
if existing_data == file_data:
|
||||
write_file = False
|
||||
@ -84,8 +103,9 @@ def make_version_header(filename):
|
||||
# Only write the file if we need to
|
||||
if write_file:
|
||||
print("GEN %s" % filename)
|
||||
with open(filename, 'w') as f:
|
||||
with open(filename, "w") as f:
|
||||
f.write(file_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
make_version_header(sys.argv[1])
|
||||
|
25
py/misc.h
25
py/misc.h
@ -129,9 +129,16 @@ unichar utf8_get_char(const byte *s);
|
||||
const byte *utf8_next_char(const byte *s);
|
||||
size_t utf8_charlen(const byte *str, size_t len);
|
||||
#else
|
||||
static inline unichar utf8_get_char(const byte *s) { return *s; }
|
||||
static inline const byte *utf8_next_char(const byte *s) { return s + 1; }
|
||||
static inline size_t utf8_charlen(const byte *str, size_t len) { (void)str; return len; }
|
||||
static inline unichar utf8_get_char(const byte *s) {
|
||||
return *s;
|
||||
}
|
||||
static inline const byte *utf8_next_char(const byte *s) {
|
||||
return s + 1;
|
||||
}
|
||||
static inline size_t utf8_charlen(const byte *str, size_t len) {
|
||||
(void)str;
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool unichar_isspace(unichar c);
|
||||
@ -168,9 +175,15 @@ void vstr_init_print(vstr_t *vstr, size_t alloc, struct _mp_print_t *print);
|
||||
void vstr_clear(vstr_t *vstr);
|
||||
vstr_t *vstr_new(size_t alloc);
|
||||
void vstr_free(vstr_t *vstr);
|
||||
static inline void vstr_reset(vstr_t *vstr) { vstr->len = 0; }
|
||||
static inline char *vstr_str(vstr_t *vstr) { return vstr->buf; }
|
||||
static inline size_t vstr_len(vstr_t *vstr) { return vstr->len; }
|
||||
static inline void vstr_reset(vstr_t *vstr) {
|
||||
vstr->len = 0;
|
||||
}
|
||||
static inline char *vstr_str(vstr_t *vstr) {
|
||||
return vstr->buf;
|
||||
}
|
||||
static inline size_t vstr_len(vstr_t *vstr) {
|
||||
return vstr->len;
|
||||
}
|
||||
void vstr_hint_size(vstr_t *vstr, size_t size);
|
||||
char *vstr_extend(vstr_t *vstr, size_t size);
|
||||
char *vstr_add_len(vstr_t *vstr, size_t len);
|
||||
|
@ -140,7 +140,8 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
||||
uint8_t str[4];
|
||||
int len = 0;
|
||||
if (c < 0x80) {
|
||||
*str = c; len = 1;
|
||||
*str = c;
|
||||
len = 1;
|
||||
} else if (c < 0x800) {
|
||||
str[0] = (c >> 6) | 0xC0;
|
||||
str[1] = (c & 0x3F) | 0x80;
|
||||
@ -365,7 +366,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
|
||||
|
||||
STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) {
|
||||
switch (n_args) {
|
||||
case 2: return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]);
|
||||
case 2:
|
||||
return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]);
|
||||
default:
|
||||
#if !MICROPY_PY_BUILTINS_POW3
|
||||
mp_raise_msg(&mp_type_NotImplementedError, "3-arg pow() not supported");
|
||||
@ -507,8 +509,12 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj, 1, 2, mp_builtin_round
|
||||
STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t value;
|
||||
switch (n_args) {
|
||||
case 1: value = MP_OBJ_NEW_SMALL_INT(0); break;
|
||||
default: value = args[1]; break;
|
||||
case 1:
|
||||
value = MP_OBJ_NEW_SMALL_INT(0);
|
||||
break;
|
||||
default:
|
||||
value = args[1];
|
||||
break;
|
||||
}
|
||||
mp_obj_iter_buf_t iter_buf;
|
||||
mp_obj_t iterable = mp_getiter(args[0], &iter_buf);
|
||||
|
33
py/mpprint.c
33
py/mpprint.c
@ -347,8 +347,7 @@ int mp_print_float(const mp_print_t *print, mp_float_t f, char fmt, int flags, c
|
||||
|
||||
if (flags & PF_FLAG_SHOW_SIGN) {
|
||||
sign = '+';
|
||||
}
|
||||
else
|
||||
} else
|
||||
if (flags & PF_FLAG_SPACE_SIGN) {
|
||||
sign = ' ';
|
||||
}
|
||||
@ -411,14 +410,20 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
|
||||
int flags = 0;
|
||||
char fill = ' ';
|
||||
while (*fmt != '\0') {
|
||||
if (*fmt == '-') flags |= PF_FLAG_LEFT_ADJUST;
|
||||
else if (*fmt == '+') flags |= PF_FLAG_SHOW_SIGN;
|
||||
else if (*fmt == ' ') flags |= PF_FLAG_SPACE_SIGN;
|
||||
else if (*fmt == '!') flags |= PF_FLAG_NO_TRAILZ;
|
||||
else if (*fmt == '0') {
|
||||
if (*fmt == '-') {
|
||||
flags |= PF_FLAG_LEFT_ADJUST;
|
||||
} else if (*fmt == '+') {
|
||||
flags |= PF_FLAG_SHOW_SIGN;
|
||||
} else if (*fmt == ' ') {
|
||||
flags |= PF_FLAG_SPACE_SIGN;
|
||||
} else if (*fmt == '!') {
|
||||
flags |= PF_FLAG_NO_TRAILZ;
|
||||
} else if (*fmt == '0') {
|
||||
flags |= PF_FLAG_PAD_AFTER_SIGN;
|
||||
fill = '0';
|
||||
} else break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
++fmt;
|
||||
}
|
||||
|
||||
@ -470,14 +475,12 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
|
||||
chrs += mp_print_strn(print, "false", 5, flags, fill, width);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
{
|
||||
case 'c': {
|
||||
char str = va_arg(args, int);
|
||||
chrs += mp_print_strn(print, &str, 1, flags, fill, width);
|
||||
break;
|
||||
}
|
||||
case 'q':
|
||||
{
|
||||
case 'q': {
|
||||
qstr qst = va_arg(args, qstr);
|
||||
size_t len;
|
||||
const char *str = (const char *)qstr_data(qst, &len);
|
||||
@ -487,8 +490,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
|
||||
chrs += mp_print_strn(print, str, prec, flags, fill, width);
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
{
|
||||
case 's': {
|
||||
const char *str = va_arg(args, const char *);
|
||||
#ifndef NDEBUG
|
||||
// With debugging enabled, catch printing of null string pointers
|
||||
@ -532,8 +534,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
|
||||
case 'f':
|
||||
case 'F':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
case 'G': {
|
||||
#if ((MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT) || (MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE))
|
||||
mp_float_t f = va_arg(args, double);
|
||||
chrs += mp_print_float(print, f, *fmt, flags, fill, width, prec);
|
||||
|
92
py/mpz.c
92
py/mpz.c
@ -60,13 +60,21 @@ STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) {
|
||||
assumes i, j are normalised
|
||||
*/
|
||||
STATIC int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, size_t jlen) {
|
||||
if (ilen < jlen) { return -1; }
|
||||
if (ilen > jlen) { return 1; }
|
||||
if (ilen < jlen) {
|
||||
return -1;
|
||||
}
|
||||
if (ilen > jlen) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (idig += ilen, jdig += ilen; ilen > 0; --ilen) {
|
||||
mpz_dbl_dig_signed_t cmp = (mpz_dbl_dig_t)*(--idig) - (mpz_dbl_dig_t)*(--jdig);
|
||||
if (cmp < 0) { return -1; }
|
||||
if (cmp > 0) { return 1; }
|
||||
if (cmp < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (cmp > 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -779,9 +787,11 @@ typedef uint32_t mp_float_int_t;
|
||||
union {
|
||||
mp_float_t f;
|
||||
#if MP_ENDIANNESS_LITTLE
|
||||
struct { mp_float_int_t frc:MP_FLOAT_FRAC_BITS, exp:MP_FLOAT_EXP_BITS, sgn:1; } p;
|
||||
struct { mp_float_int_t frc : MP_FLOAT_FRAC_BITS, exp : MP_FLOAT_EXP_BITS, sgn : 1;
|
||||
} p;
|
||||
#else
|
||||
struct { mp_float_int_t sgn:1, exp:MP_FLOAT_EXP_BITS, frc:MP_FLOAT_FRAC_BITS; } p;
|
||||
struct { mp_float_int_t sgn : 1, exp : MP_FLOAT_EXP_BITS, frc : MP_FLOAT_FRAC_BITS;
|
||||
} p;
|
||||
#endif
|
||||
} u = {src};
|
||||
|
||||
@ -948,28 +958,48 @@ int mpz_cmp(const mpz_t *z1, const mpz_t *z2) {
|
||||
mp_int_t mpz_cmp_sml_int(const mpz_t *z, mp_int_t sml_int) {
|
||||
mp_int_t cmp;
|
||||
if (z->neg == 0) {
|
||||
if (sml_int < 0) return 1;
|
||||
if (sml_int == 0) {
|
||||
if (z->len == 0) return 0;
|
||||
if (sml_int < 0) {
|
||||
return 1;
|
||||
}
|
||||
if (z->len == 0) return -1;
|
||||
assert(sml_int < (1 << DIG_SIZE));
|
||||
if (z->len != 1) return 1;
|
||||
cmp = z->dig[0] - sml_int;
|
||||
} else {
|
||||
if (sml_int > 0) return -1;
|
||||
if (sml_int == 0) {
|
||||
if (z->len == 0) return 0;
|
||||
if (z->len == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (z->len == 0) {
|
||||
return -1;
|
||||
}
|
||||
if (z->len == 0) return 1;
|
||||
assert(sml_int < (1 << DIG_SIZE));
|
||||
if (z->len != 1) {
|
||||
return 1;
|
||||
}
|
||||
cmp = z->dig[0] - sml_int;
|
||||
} else {
|
||||
if (sml_int > 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sml_int == 0) {
|
||||
if (z->len == 0) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (z->len == 0) {
|
||||
return 1;
|
||||
}
|
||||
assert(sml_int > -(1 << DIG_SIZE));
|
||||
if (z->len != 1) return -1;
|
||||
if (z->len != 1) {
|
||||
return -1;
|
||||
}
|
||||
cmp = -z->dig[0] - sml_int;
|
||||
}
|
||||
if (cmp < 0) return -1;
|
||||
if (cmp > 0) return 1;
|
||||
if (cmp < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (cmp > 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@ -1376,7 +1406,8 @@ void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t
|
||||
|
||||
mpz_t *x = mpz_clone(lhs);
|
||||
mpz_t *n = mpz_clone(rhs);
|
||||
mpz_t quo; mpz_init_zero(&quo);
|
||||
mpz_t quo;
|
||||
mpz_init_zero(&quo);
|
||||
|
||||
while (n->len > 0) {
|
||||
if ((n->dig[0] & 1) != 0) {
|
||||
@ -1419,7 +1450,8 @@ mpz_t *mpz_gcd(const mpz_t *z1, const mpz_t *z2) {
|
||||
|
||||
mpz_t *a = mpz_clone(z1);
|
||||
mpz_t *b = mpz_clone(z2);
|
||||
mpz_t c; mpz_init_zero(&c);
|
||||
mpz_t c;
|
||||
mpz_init_zero(&c);
|
||||
a->neg = 0;
|
||||
b->neg = 0;
|
||||
|
||||
@ -1430,7 +1462,9 @@ mpz_t *mpz_gcd(const mpz_t *z1, const mpz_t *z2) {
|
||||
mpz_deinit(&c);
|
||||
return b;
|
||||
}
|
||||
mpz_t *t = a; a = b; b = t;
|
||||
mpz_t *t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
if (!(b->len >= 2 || (b->len == 1 && b->dig[0] > 1))) { // compute b > 0; could be mpz_cmp_small_int(b, 1) > 0
|
||||
break;
|
||||
@ -1497,7 +1531,8 @@ void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const m
|
||||
if (lhs->neg != rhs->neg) {
|
||||
dest_quo->neg = 1;
|
||||
if (!mpz_is_zero(dest_rem)) {
|
||||
mpz_t mpzone; mpz_init_from_int(&mpzone, -1);
|
||||
mpz_t mpzone;
|
||||
mpz_init_from_int(&mpzone, -1);
|
||||
mpz_add_inpl(dest_quo, dest_quo, &mpzone);
|
||||
mpz_add_inpl(dest_rem, dest_rem, rhs);
|
||||
}
|
||||
@ -1512,7 +1547,8 @@ these functions are unused
|
||||
*/
|
||||
mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs) {
|
||||
mpz_t *quo = mpz_zero();
|
||||
mpz_t rem; mpz_init_zero(&rem);
|
||||
mpz_t rem;
|
||||
mpz_init_zero(&rem);
|
||||
mpz_divmod_inpl(quo, &rem, lhs, rhs);
|
||||
mpz_deinit(&rem);
|
||||
return quo;
|
||||
@ -1522,7 +1558,8 @@ mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs) {
|
||||
can have lhs, rhs the same
|
||||
*/
|
||||
mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs) {
|
||||
mpz_t quo; mpz_init_zero(&quo);
|
||||
mpz_t quo;
|
||||
mpz_init_zero(&quo);
|
||||
mpz_t *rem = mpz_zero();
|
||||
mpz_divmod_inpl(&quo, rem, lhs, rhs);
|
||||
mpz_deinit(&quo);
|
||||
@ -1659,9 +1696,10 @@ size_t mpz_as_str_inpl(const mpz_t *i, unsigned int base, const char *prefix, ch
|
||||
char *s = str;
|
||||
if (ilen == 0) {
|
||||
if (prefix) {
|
||||
while (*prefix)
|
||||
while (*prefix) {
|
||||
*s++ = *prefix++;
|
||||
}
|
||||
}
|
||||
*s++ = '0';
|
||||
*s = '\0';
|
||||
return s - str;
|
||||
|
12
py/mpz.h
12
py/mpz.h
@ -115,8 +115,12 @@ void mpz_set_from_float(mpz_t *z, mp_float_t src);
|
||||
size_t mpz_set_from_str(mpz_t *z, const char *str, size_t len, bool neg, unsigned int base);
|
||||
void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf);
|
||||
|
||||
static inline bool mpz_is_zero(const mpz_t *z) { return z->len == 0; }
|
||||
static inline bool mpz_is_neg(const mpz_t *z) { return z->len != 0 && z->neg != 0; }
|
||||
static inline bool mpz_is_zero(const mpz_t *z) {
|
||||
return z->len == 0;
|
||||
}
|
||||
static inline bool mpz_is_neg(const mpz_t *z) {
|
||||
return z->len != 0 && z->neg != 0;
|
||||
}
|
||||
int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
|
||||
|
||||
void mpz_abs_inpl(mpz_t *dest, const mpz_t *z);
|
||||
@ -134,7 +138,9 @@ void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
|
||||
void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
|
||||
void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs);
|
||||
|
||||
static inline size_t mpz_max_num_bits(const mpz_t *z) { return z->len * MPZ_DIG_SIZE; }
|
||||
static inline size_t mpz_max_num_bits(const mpz_t *z) {
|
||||
return z->len * MPZ_DIG_SIZE;
|
||||
}
|
||||
mp_int_t mpz_hash(const mpz_t *z);
|
||||
bool mpz_as_int_checked(const mpz_t *z, mp_int_t *value);
|
||||
bool mpz_as_uint_checked(const mpz_t *z, mp_uint_t *value);
|
||||
|
@ -45,10 +45,12 @@
|
||||
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
|
||||
DEBUG_printf("mp_convert_obj_to_native(%p, " UINT_FMT ")\n", obj, type);
|
||||
switch (type & 0xf) {
|
||||
case MP_NATIVE_TYPE_OBJ: return (mp_uint_t)obj;
|
||||
case MP_NATIVE_TYPE_OBJ:
|
||||
return (mp_uint_t)obj;
|
||||
case MP_NATIVE_TYPE_BOOL:
|
||||
case MP_NATIVE_TYPE_INT:
|
||||
case MP_NATIVE_TYPE_UINT: return mp_obj_get_int_truncated(obj);
|
||||
case MP_NATIVE_TYPE_UINT:
|
||||
return mp_obj_get_int_truncated(obj);
|
||||
default: { // cast obj to a pointer
|
||||
mp_buffer_info_t bufinfo;
|
||||
if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_RW)) {
|
||||
@ -69,10 +71,14 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
|
||||
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
|
||||
DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type);
|
||||
switch (type & 0xf) {
|
||||
case MP_NATIVE_TYPE_OBJ: return (mp_obj_t)val;
|
||||
case MP_NATIVE_TYPE_BOOL: return mp_obj_new_bool(val);
|
||||
case MP_NATIVE_TYPE_INT: return mp_obj_new_int(val);
|
||||
case MP_NATIVE_TYPE_UINT: return mp_obj_new_int_from_uint(val);
|
||||
case MP_NATIVE_TYPE_OBJ:
|
||||
return (mp_obj_t)val;
|
||||
case MP_NATIVE_TYPE_BOOL:
|
||||
return mp_obj_new_bool(val);
|
||||
case MP_NATIVE_TYPE_INT:
|
||||
return mp_obj_new_int(val);
|
||||
case MP_NATIVE_TYPE_UINT:
|
||||
return mp_obj_new_int_from_uint(val);
|
||||
default: // a pointer
|
||||
// we return just the value of the pointer as an integer
|
||||
return mp_obj_new_int_from_uint(val);
|
||||
|
@ -124,7 +124,8 @@ NORETURN void nlr_jump(void *val) {
|
||||
#if defined(__GNUC__)
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
for (;;); // needed to silence compiler warning
|
||||
for (;;) {; // needed to silence compiler warning
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,8 @@ NORETURN void nlr_jump(void *val) {
|
||||
: // clobbered registers
|
||||
);
|
||||
|
||||
for (;;); // needed to silence compiler warning
|
||||
for (;;) {; // needed to silence compiler warning
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICROPY_NLR_X64
|
||||
|
@ -100,7 +100,8 @@ NORETURN void nlr_jump(void *val) {
|
||||
: // clobbered registers
|
||||
);
|
||||
|
||||
for (;;); // needed to silence compiler warning
|
||||
for (;;) {; // needed to silence compiler warning
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICROPY_NLR_X86
|
||||
|
@ -77,7 +77,8 @@ NORETURN void nlr_jump(void *val) {
|
||||
: // clobbered registers
|
||||
);
|
||||
|
||||
for (;;); // needed to silence compiler warning
|
||||
for (;;) {; // needed to silence compiler warning
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICROPY_NLR_XTENSA
|
||||
|
10
py/obj.c
10
py/obj.c
@ -182,7 +182,9 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
|
||||
// both SMALL_INT, and not equal if we get here
|
||||
return false;
|
||||
} else {
|
||||
mp_obj_t temp = o2; o2 = o1; o1 = temp;
|
||||
mp_obj_t temp = o2;
|
||||
o2 = o1;
|
||||
o1 = temp;
|
||||
// o2 is now the SMALL_INT, o1 is not
|
||||
// fall through to generic op
|
||||
}
|
||||
@ -525,7 +527,9 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flag
|
||||
|
||||
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in);
|
||||
default: return MP_OBJ_NULL; // op not supported
|
||||
case MP_UNARY_OP_HASH:
|
||||
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in);
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user