codeformat
This commit is contained in:
parent
3e25d611ef
commit
b057fb8a4b
@ -57,7 +57,7 @@ STATIC void nibble_write(mp_soft_qspi_obj_t *self, uint8_t v) {
|
||||
}
|
||||
|
||||
STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) {
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||
|
||||
switch (cmd) {
|
||||
case MP_QSPI_IOCTL_INIT:
|
||||
@ -67,7 +67,7 @@ STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) {
|
||||
// Configure pins
|
||||
mp_hal_pin_write(self->clk, 0);
|
||||
mp_hal_pin_output(self->clk);
|
||||
//mp_hal_pin_write(self->clk, 1);
|
||||
// mp_hal_pin_write(self->clk, 1);
|
||||
mp_hal_pin_output(self->io0);
|
||||
mp_hal_pin_input(self->io1);
|
||||
mp_hal_pin_write(self->io2, 1);
|
||||
@ -155,19 +155,19 @@ STATIC void mp_soft_qspi_qwrite(mp_soft_qspi_obj_t *self, size_t len, const uint
|
||||
SCK_LOW(self);
|
||||
}
|
||||
|
||||
//mp_hal_pin_input(self->io1);
|
||||
// mp_hal_pin_input(self->io1);
|
||||
}
|
||||
|
||||
STATIC void mp_soft_qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||
uint32_t cmd_buf = cmd | data << 8;
|
||||
CS_LOW(self);
|
||||
mp_soft_qspi_transfer(self, 1 + len, (uint8_t*)&cmd_buf, NULL);
|
||||
mp_soft_qspi_transfer(self, 1 + len, (uint8_t *)&cmd_buf, NULL);
|
||||
CS_HIGH(self);
|
||||
}
|
||||
|
||||
STATIC void mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||
uint8_t cmd_buf[4] = {cmd, addr >> 16, addr >> 8, addr};
|
||||
CS_LOW(self);
|
||||
mp_soft_qspi_transfer(self, 4, cmd_buf, NULL);
|
||||
@ -176,16 +176,16 @@ STATIC void mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_
|
||||
}
|
||||
|
||||
STATIC uint32_t mp_soft_qspi_read_cmd(void *self_in, uint8_t cmd, size_t len) {
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||
uint32_t cmd_buf = cmd;
|
||||
CS_LOW(self);
|
||||
mp_soft_qspi_transfer(self, 1 + len, (uint8_t*)&cmd_buf, (uint8_t*)&cmd_buf);
|
||||
mp_soft_qspi_transfer(self, 1 + len, (uint8_t *)&cmd_buf, (uint8_t *)&cmd_buf);
|
||||
CS_HIGH(self);
|
||||
return cmd_buf >> 8;
|
||||
}
|
||||
|
||||
STATIC void mp_soft_qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||
uint8_t cmd_buf[7] = {cmd, addr >> 16, addr >> 8, addr};
|
||||
CS_LOW(self);
|
||||
mp_soft_qspi_transfer(self, 1, cmd_buf, NULL);
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "drivers/bus/spi.h"
|
||||
|
||||
int mp_soft_spi_ioctl(void *self_in, uint32_t cmd) {
|
||||
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t*)self_in;
|
||||
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t *)self_in;
|
||||
|
||||
switch (cmd) {
|
||||
case MP_SPI_IOCTL_INIT:
|
||||
@ -45,7 +45,7 @@ int mp_soft_spi_ioctl(void *self_in, uint32_t cmd) {
|
||||
}
|
||||
|
||||
void mp_soft_spi_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t*)self_in;
|
||||
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t *)self_in;
|
||||
uint32_t delay_half = self->delay_half;
|
||||
|
||||
// only MSB transfer is implemented
|
||||
|
@ -183,7 +183,7 @@ STATIC int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack)
|
||||
// >=0 - number of acks received
|
||||
// <0 - error, with errno being the negative of the return value
|
||||
int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uint8_t *src, size_t len, bool stop) {
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in;
|
||||
|
||||
// start the I2C transaction
|
||||
int ret = mp_hal_i2c_start(self);
|
||||
@ -229,7 +229,7 @@ int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uin
|
||||
// 0 - success
|
||||
// <0 - error, with errno being the negative of the return value
|
||||
int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t *dest, size_t len, bool stop) {
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in;
|
||||
|
||||
// start the I2C transaction
|
||||
int ret = mp_hal_i2c_start(self);
|
||||
@ -318,7 +318,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_init_obj, 1, machine_i2c_obj_init);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
|
||||
mp_obj_base_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
mp_obj_t list = mp_obj_new_list(0, NULL);
|
||||
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
|
||||
for (int addr = 0x08; addr < 0x78; ++addr) {
|
||||
@ -332,8 +332,8 @@ STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
if (i2c_p->start == NULL) {
|
||||
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
|
||||
}
|
||||
@ -346,8 +346,8 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_start_obj, machine_i2c_start);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
if (i2c_p->stop == NULL) {
|
||||
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
|
||||
}
|
||||
@ -360,8 +360,8 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_stop_obj, machine_i2c_stop);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
if (i2c_p->read == NULL) {
|
||||
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
|
||||
}
|
||||
@ -384,8 +384,8 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readinto_obj, 2, 3, machine_i2c_readinto);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
if (i2c_p->write == NULL) {
|
||||
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
|
||||
}
|
||||
@ -406,13 +406,13 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(machine_i2c_write_obj, machine_i2c_write);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, mp_obj_get_int(args[2]));
|
||||
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
||||
int ret = i2c_p->readfrom(self, addr, (uint8_t*)vstr.buf, vstr.len, stop);
|
||||
int ret = i2c_p->readfrom(self, addr, (uint8_t *)vstr.buf, vstr.len, stop);
|
||||
if (ret < 0) {
|
||||
mp_raise_OSError(-ret);
|
||||
}
|
||||
@ -421,8 +421,8 @@ STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_obj, 3, 4, machine_i2c_readfrom);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
|
||||
@ -436,8 +436,8 @@ STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_into_obj, 3, 4, machine_i2c_readfrom_into);
|
||||
|
||||
STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
|
||||
@ -452,8 +452,8 @@ STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machine_i2c_writeto);
|
||||
|
||||
STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, uint8_t *buf, size_t len) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
uint8_t memaddr_buf[4];
|
||||
size_t memaddr_len = 0;
|
||||
for (int16_t i = addrsize - 8; i >= 0; i -= 8) {
|
||||
@ -472,8 +472,8 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
|
||||
#define BUF_STACK_SIZE (12)
|
||||
|
||||
STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, const uint8_t *buf, size_t len) {
|
||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
|
||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
|
||||
|
||||
// need some memory to create the buffer to send; try to use stack if possible
|
||||
uint8_t buf2_stack[MAX_MEMADDR_SIZE + BUF_STACK_SIZE];
|
||||
@ -519,7 +519,7 @@ STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args
|
||||
|
||||
// do the transfer
|
||||
int ret = read_mem(pos_args[0], args[ARG_addr].u_int, args[ARG_memaddr].u_int,
|
||||
args[ARG_addrsize].u_int, (uint8_t*)vstr.buf, vstr.len);
|
||||
args[ARG_addrsize].u_int, (uint8_t *)vstr.buf, vstr.len);
|
||||
if (ret < 0) {
|
||||
mp_raise_OSError(-ret);
|
||||
}
|
||||
@ -594,7 +594,7 @@ STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = {
|
||||
MP_DEFINE_CONST_DICT(mp_machine_soft_i2c_locals_dict, machine_i2c_locals_dict_table);
|
||||
|
||||
int mp_machine_soft_i2c_read(mp_obj_base_t *self_in, uint8_t *dest, size_t len, bool nack) {
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in;
|
||||
while (len--) {
|
||||
int ret = mp_hal_i2c_read_byte(self, dest++, nack && (len == 0));
|
||||
if (ret != 0) {
|
||||
@ -605,7 +605,7 @@ int mp_machine_soft_i2c_read(mp_obj_base_t *self_in, uint8_t *dest, size_t len,
|
||||
}
|
||||
|
||||
int mp_machine_soft_i2c_write(mp_obj_base_t *self_in, const uint8_t *src, size_t len) {
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
||||
machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in;
|
||||
int num_acks = 0;
|
||||
while (len--) {
|
||||
int ret = mp_hal_i2c_write_byte(self, *src++);
|
||||
@ -621,8 +621,8 @@ int mp_machine_soft_i2c_write(mp_obj_base_t *self_in, const uint8_t *src, size_t
|
||||
}
|
||||
|
||||
STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = {
|
||||
.start = (int(*)(mp_obj_base_t*))mp_hal_i2c_start,
|
||||
.stop = (int(*)(mp_obj_base_t*))mp_hal_i2c_stop,
|
||||
.start = (int (*)(mp_obj_base_t *))mp_hal_i2c_start,
|
||||
.stop = (int (*)(mp_obj_base_t *))mp_hal_i2c_stop,
|
||||
.read = mp_machine_soft_i2c_read,
|
||||
.write = mp_machine_soft_i2c_write,
|
||||
.readfrom = mp_machine_soft_i2c_readfrom,
|
||||
@ -634,7 +634,7 @@ const mp_obj_type_t machine_i2c_type = {
|
||||
.name = MP_QSTR_I2C,
|
||||
.make_new = machine_i2c_make_new,
|
||||
.protocol = &mp_machine_soft_i2c_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&mp_machine_soft_i2c_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&mp_machine_soft_i2c_locals_dict,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_MACHINE_I2C
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -50,8 +50,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||
mp_pin_p_t *pin_p = NULL;
|
||||
|
||||
if (MP_OBJ_IS_OBJ(pin)) {
|
||||
mp_obj_base_t *pin_base = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||
pin_p = (mp_pin_p_t*)pin_base->type->protocol;
|
||||
mp_obj_base_t *pin_base = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||
pin_p = (mp_pin_p_t *)pin_base->type->protocol;
|
||||
}
|
||||
|
||||
if (pin_p == NULL) {
|
||||
@ -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
|
||||
{
|
||||
@ -179,7 +178,7 @@ const mp_obj_type_t machine_signal_type = {
|
||||
.make_new = signal_make_new,
|
||||
.call = signal_call,
|
||||
.protocol = &signal_pin_p,
|
||||
.locals_dict = (void*)&signal_locals_dict,
|
||||
.locals_dict = (void *)&signal_locals_dict,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_MACHINE
|
||||
|
@ -64,16 +64,16 @@ mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_obj_base_t *s = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)s->type->protocol;
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)s->type->protocol;
|
||||
spi_p->init(s, n_args - 1, args + 1, kw_args);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_spi_init_obj, 1, machine_spi_init);
|
||||
|
||||
STATIC mp_obj_t machine_spi_deinit(mp_obj_t self) {
|
||||
mp_obj_base_t *s = (mp_obj_base_t*)MP_OBJ_TO_PTR(self);
|
||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)s->type->protocol;
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(self);
|
||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)s->type->protocol;
|
||||
if (spi_p->deinit != NULL) {
|
||||
spi_p->deinit(s);
|
||||
}
|
||||
@ -82,8 +82,8 @@ STATIC mp_obj_t machine_spi_deinit(mp_obj_t self) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_spi_deinit_obj, machine_spi_deinit);
|
||||
|
||||
STATIC void mp_machine_spi_transfer(mp_obj_t self, size_t len, const void *src, void *dest) {
|
||||
mp_obj_base_t *s = (mp_obj_base_t*)MP_OBJ_TO_PTR(self);
|
||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)s->type->protocol;
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(self);
|
||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)s->type->protocol;
|
||||
spi_p->transfer(s, len, src, dest);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_readinto_obj, 2, 3, mp_machin
|
||||
STATIC mp_obj_t mp_machine_spi_write(mp_obj_t self, mp_obj_t wr_buf) {
|
||||
mp_buffer_info_t src;
|
||||
mp_get_buffer_raise(wr_buf, &src, MP_BUFFER_READ);
|
||||
mp_machine_spi_transfer(self, src.len, (const uint8_t*)src.buf, NULL);
|
||||
mp_machine_spi_transfer(self, src.len, (const uint8_t *)src.buf, NULL);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj, mp_machine_spi_write);
|
||||
@ -223,7 +223,7 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n
|
||||
}
|
||||
|
||||
STATIC void mp_machine_soft_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t*)self_in;
|
||||
mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t *)self_in;
|
||||
|
||||
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_sck, ARG_mosi, ARG_miso };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -261,7 +261,7 @@ STATIC void mp_machine_soft_spi_init(mp_obj_base_t *self_in, size_t n_args, cons
|
||||
}
|
||||
|
||||
STATIC void mp_machine_soft_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t*)self_in;
|
||||
mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t *)self_in;
|
||||
mp_soft_spi_transfer(&self->spi, len, src, dest);
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ const mp_obj_type_t mp_machine_soft_spi_type = {
|
||||
.print = mp_machine_soft_spi_print,
|
||||
.make_new = mp_machine_spi_make_new, // delegate to master constructor
|
||||
.protocol = &mp_machine_soft_spi_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&mp_machine_spi_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_MACHINE_SPI
|
||||
|
@ -55,9 +55,9 @@ typedef struct _mp_obj_btree_t {
|
||||
STATIC const mp_obj_type_t btree_type;
|
||||
|
||||
#define CHECK_ERROR(res) \
|
||||
if (res == RET_ERROR) { \
|
||||
mp_raise_OSError(errno); \
|
||||
}
|
||||
if (res == RET_ERROR) { \
|
||||
mp_raise_OSError(errno); \
|
||||
}
|
||||
|
||||
void __dbpanic(DB *db) {
|
||||
printf("__dbpanic(%p)\n", db);
|
||||
@ -95,8 +95,8 @@ STATIC mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
DBT key, val;
|
||||
key.data = (void*)mp_obj_str_get_data(args[1], &key.size);
|
||||
val.data = (void*)mp_obj_str_get_data(args[2], &val.size);
|
||||
key.data = (void *)mp_obj_str_get_data(args[1], &key.size);
|
||||
val.data = (void *)mp_obj_str_get_data(args[2], &val.size);
|
||||
return MP_OBJ_NEW_SMALL_INT(__bt_put(self->db, &key, &val, 0));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put);
|
||||
@ -104,7 +104,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put);
|
||||
STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
DBT key, val;
|
||||
key.data = (void*)mp_obj_str_get_data(args[1], &key.size);
|
||||
key.data = (void *)mp_obj_str_get_data(args[1], &key.size);
|
||||
int res = __bt_get(self->db, &key, &val, 0);
|
||||
if (res == RET_SPECIAL) {
|
||||
if (n_args > 2) {
|
||||
@ -123,7 +123,7 @@ STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) {
|
||||
int flags = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
||||
DBT key, val;
|
||||
if (n_args > 2) {
|
||||
key.data = (void*)mp_obj_str_get_data(args[2], &key.size);
|
||||
key.data = (void *)mp_obj_str_get_data(args[2], &key.size);
|
||||
}
|
||||
|
||||
int res = __bt_seq(self->db, &key, &val, flags);
|
||||
@ -198,7 +198,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
|
||||
if (self->start_key != MP_OBJ_NULL) {
|
||||
int flags = R_FIRST;
|
||||
if (self->start_key != mp_const_none) {
|
||||
key.data = (void*)mp_obj_str_get_data(self->start_key, &key.size);
|
||||
key.data = (void *)mp_obj_str_get_data(self->start_key, &key.size);
|
||||
flags = R_CURSOR;
|
||||
} else if (desc) {
|
||||
flags = R_LAST;
|
||||
@ -216,7 +216,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
|
||||
|
||||
if (self->end_key != mp_const_none) {
|
||||
DBT end_key;
|
||||
end_key.data = (void*)mp_obj_str_get_data(self->end_key, &end_key.size);
|
||||
end_key.data = (void *)mp_obj_str_get_data(self->end_key, &end_key.size);
|
||||
BTREE *t = self->db->internal;
|
||||
int cmp = t->bt_cmp(&key, &end_key);
|
||||
if (desc) {
|
||||
@ -251,7 +251,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
if (value == MP_OBJ_NULL) {
|
||||
// delete
|
||||
DBT key;
|
||||
key.data = (void*)mp_obj_str_get_data(index, &key.size);
|
||||
key.data = (void *)mp_obj_str_get_data(index, &key.size);
|
||||
int res = __bt_delete(self->db, &key, 0);
|
||||
if (res == RET_SPECIAL) {
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
||||
@ -261,7 +261,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
} else if (value == MP_OBJ_SENTINEL) {
|
||||
// load
|
||||
DBT key, val;
|
||||
key.data = (void*)mp_obj_str_get_data(index, &key.size);
|
||||
key.data = (void *)mp_obj_str_get_data(index, &key.size);
|
||||
int res = __bt_get(self->db, &key, &val, 0);
|
||||
if (res == RET_SPECIAL) {
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
||||
@ -271,8 +271,8 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
} else {
|
||||
// store
|
||||
DBT key, val;
|
||||
key.data = (void*)mp_obj_str_get_data(index, &key.size);
|
||||
val.data = (void*)mp_obj_str_get_data(value, &val.size);
|
||||
key.data = (void *)mp_obj_str_get_data(index, &key.size);
|
||||
val.data = (void *)mp_obj_str_get_data(value, &val.size);
|
||||
int res = __bt_put(self->db, &key, &val, 0);
|
||||
CHECK_ERROR(res);
|
||||
return mp_const_none;
|
||||
@ -284,7 +284,7 @@ STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
|
||||
switch (op) {
|
||||
case MP_BINARY_OP_CONTAINS: {
|
||||
DBT key, val;
|
||||
key.data = (void*)mp_obj_str_get_data(rhs_in, &key.size);
|
||||
key.data = (void *)mp_obj_str_get_data(rhs_in, &key.size);
|
||||
int res = __bt_get(self->db, &key, &val, 0);
|
||||
CHECK_ERROR(res);
|
||||
return mp_obj_new_bool(res != RET_SPECIAL);
|
||||
@ -317,7 +317,7 @@ STATIC const mp_obj_type_t btree_type = {
|
||||
.iternext = btree_iternext,
|
||||
.binary_op = btree_binary_op,
|
||||
.subscr = btree_subscr,
|
||||
.locals_dict = (void*)&btree_locals_dict,
|
||||
.locals_dict = (void *)&btree_locals_dict,
|
||||
};
|
||||
|
||||
STATIC FILEVTABLE btree_stream_fvtable = {
|
||||
@ -345,14 +345,14 @@ STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||
mp_arg_val_t minkeypage;
|
||||
} args;
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||
BTREEINFO openinfo = {0};
|
||||
openinfo.flags = args.flags.u_int;
|
||||
openinfo.cachesize = args.cachesize.u_int;
|
||||
openinfo.psize = args.pagesize.u_int;
|
||||
openinfo.minkeypage = args.minkeypage.u_int;
|
||||
|
||||
DB *db = __bt_open(MP_OBJ_TO_PTR(pos_args[0]), &btree_stream_fvtable, &openinfo, /*dflags*/0);
|
||||
DB *db = __bt_open(MP_OBJ_TO_PTR(pos_args[0]), &btree_stream_fvtable, &openinfo, /*dflags*/ 0);
|
||||
if (db == NULL) {
|
||||
mp_raise_OSError(errno);
|
||||
}
|
||||
@ -371,7 +371,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_btree_globals, mp_module_btree_globals_tab
|
||||
|
||||
const mp_obj_module_t mp_module_btree = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_btree_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_btree_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_BTREE
|
||||
|
@ -41,8 +41,8 @@ typedef struct _mp_obj_framebuf_t {
|
||||
uint8_t format;
|
||||
} mp_obj_framebuf_t;
|
||||
|
||||
typedef void (*setpixel_t)(const mp_obj_framebuf_t*, int, int, uint32_t);
|
||||
typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t*, int, int);
|
||||
typedef void (*setpixel_t)(const mp_obj_framebuf_t *, int, int, uint32_t);
|
||||
typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t *, int, int);
|
||||
typedef void (*fill_rect_t)(const mp_obj_framebuf_t *, int, int, int, int, uint32_t);
|
||||
|
||||
typedef struct _mp_framebuf_p_t {
|
||||
@ -65,20 +65,20 @@ typedef struct _mp_framebuf_p_t {
|
||||
STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||
size_t index = (x + y * fb->stride) >> 3;
|
||||
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
|
||||
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||
((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||
}
|
||||
|
||||
STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||
size_t index = (x + y * fb->stride) >> 3;
|
||||
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
|
||||
return (((uint8_t*)fb->buf)[index] >> (offset)) & 0x01;
|
||||
return (((uint8_t *)fb->buf)[index] >> (offset)) & 0x01;
|
||||
}
|
||||
|
||||
STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||
int reverse = fb->format == FRAMEBUF_MHMSB;
|
||||
int advance = fb->stride >> 3;
|
||||
while (w--) {
|
||||
uint8_t *b = &((uint8_t*)fb->buf)[(x >> 3) + y * advance];
|
||||
uint8_t *b = &((uint8_t *)fb->buf)[(x >> 3) + y * advance];
|
||||
int offset = reverse ? x & 7 : 7 - (x & 7);
|
||||
for (int hh = h; hh; --hh) {
|
||||
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||
@ -93,16 +93,16 @@ STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int
|
||||
STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||
size_t index = (y >> 3) * fb->stride + x;
|
||||
uint8_t offset = y & 0x07;
|
||||
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||
((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||
}
|
||||
|
||||
STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||
return (((uint8_t*)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01;
|
||||
return (((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01;
|
||||
}
|
||||
|
||||
STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||
while (h--) {
|
||||
uint8_t *b = &((uint8_t*)fb->buf)[(y >> 3) * fb->stride + x];
|
||||
uint8_t *b = &((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x];
|
||||
uint8_t offset = y & 0x07;
|
||||
for (int ww = w; ww; --ww) {
|
||||
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||
@ -115,15 +115,15 @@ STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, in
|
||||
// Functions for RGB565 format
|
||||
|
||||
STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||
((uint16_t*)fb->buf)[x + y * fb->stride] = col;
|
||||
((uint16_t *)fb->buf)[x + y * fb->stride] = col;
|
||||
}
|
||||
|
||||
STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||
return ((uint16_t*)fb->buf)[x + y * fb->stride];
|
||||
return ((uint16_t *)fb->buf)[x + y * fb->stride];
|
||||
}
|
||||
|
||||
STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||
uint16_t *b = &((uint16_t*)fb->buf)[x + y * fb->stride];
|
||||
uint16_t *b = &((uint16_t *)fb->buf)[x + y * fb->stride];
|
||||
while (h--) {
|
||||
for (int ww = w; ww; --ww) {
|
||||
*b++ = col;
|
||||
@ -135,7 +135,7 @@ STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, i
|
||||
// Functions for GS2_HMSB format
|
||||
|
||||
STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 2];
|
||||
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2];
|
||||
uint8_t shift = (x & 0x3) << 1;
|
||||
uint8_t mask = 0x3 << shift;
|
||||
uint8_t color = (col & 0x3) << shift;
|
||||
@ -143,14 +143,14 @@ STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_
|
||||
}
|
||||
|
||||
STATIC uint32_t gs2_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||
uint8_t pixel = ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 2];
|
||||
uint8_t pixel = ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2];
|
||||
uint8_t shift = (x & 0x3) << 1;
|
||||
return (pixel >> shift) & 0x3;
|
||||
}
|
||||
|
||||
STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||
for (int xx=x; xx < x+w; xx++) {
|
||||
for (int yy=y; yy < y+h; yy++) {
|
||||
for (int xx = x; xx < x + w; xx++) {
|
||||
for (int yy = y; yy < y + h; yy++) {
|
||||
gs2_hmsb_setpixel(fb, xx, yy, col);
|
||||
}
|
||||
}
|
||||
@ -159,7 +159,7 @@ STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
|
||||
// Functions for GS4_HMSB format
|
||||
|
||||
STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
|
||||
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1];
|
||||
|
||||
if (x % 2) {
|
||||
*pixel = ((uint8_t)col & 0x0f) | (*pixel & 0xf0);
|
||||
@ -170,15 +170,15 @@ STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_
|
||||
|
||||
STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||
if (x % 2) {
|
||||
return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f;
|
||||
return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f;
|
||||
}
|
||||
|
||||
return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] >> 4;
|
||||
return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] >> 4;
|
||||
}
|
||||
|
||||
STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||
col &= 0x0f;
|
||||
uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
|
||||
uint8_t *pixel_pair = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1];
|
||||
uint8_t col_shifted_left = col << 4;
|
||||
uint8_t col_pixel_pair = col_shifted_left | col;
|
||||
int pixel_count_till_next_line = (fb->stride - w) >> 1;
|
||||
@ -210,16 +210,16 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
|
||||
// Functions for GS8 format
|
||||
|
||||
STATIC void gs8_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride)];
|
||||
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)];
|
||||
*pixel = col & 0xff;
|
||||
}
|
||||
|
||||
STATIC uint32_t gs8_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||
return ((uint8_t*)fb->buf)[(x + y * fb->stride)];
|
||||
return ((uint8_t *)fb->buf)[(x + y * fb->stride)];
|
||||
}
|
||||
|
||||
STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride)];
|
||||
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)];
|
||||
while (h--) {
|
||||
memset(pixel, col, w);
|
||||
pixel += fb->stride;
|
||||
@ -393,9 +393,9 @@ STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t col = mp_obj_get_int(args[5]);
|
||||
|
||||
fill_rect(self, x, y, w, 1, col);
|
||||
fill_rect(self, x, y + h- 1, w, 1, col);
|
||||
fill_rect(self, x, y + h - 1, w, 1, col);
|
||||
fill_rect(self, x, y, 1, h, col);
|
||||
fill_rect(self, x + w- 1, y, 1, h, col);
|
||||
fill_rect(self, x + w - 1, y, 1, h, col);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -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;
|
||||
@ -482,7 +488,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
|
||||
(y >= self->height) ||
|
||||
(-x >= source->width) ||
|
||||
(-y >= source->height)
|
||||
) {
|
||||
) {
|
||||
// Out of bounds, no-op.
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -556,7 +562,7 @@ STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args) {
|
||||
// loop over chars
|
||||
for (; *str; ++str) {
|
||||
// get char and make sure its in range of font
|
||||
int chr = *(uint8_t*)str;
|
||||
int chr = *(uint8_t *)str;
|
||||
if (chr < 32 || chr > 127) {
|
||||
chr = 127;
|
||||
}
|
||||
@ -599,7 +605,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
|
||||
.name = MP_QSTR_FrameBuffer,
|
||||
.make_new = framebuf_make_new,
|
||||
.buffer_p = { .get_buffer = framebuf_get_buffer },
|
||||
.locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict,
|
||||
};
|
||||
|
||||
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
|
||||
@ -642,7 +648,7 @@ STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_tab
|
||||
|
||||
const mp_obj_module_t mp_module_framebuf = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&framebuf_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&framebuf_module_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_FRAMEBUF
|
||||
|
124
extmod/modlwip.c
124
extmod/modlwip.c
@ -40,7 +40,7 @@
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/udp.h"
|
||||
//#include "lwip/raw.h"
|
||||
// #include "lwip/raw.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/igmp.h"
|
||||
#if LWIP_VERSION_MAJOR < 2
|
||||
@ -92,7 +92,7 @@ void mod_lwip_register_poll(void (*poll)(void *arg), void *poll_arg);
|
||||
void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg);
|
||||
|
||||
STATIC void slip_lwip_poll(void *netif) {
|
||||
slipif_poll((struct netif*)netif);
|
||||
slipif_poll((struct netif *)netif);
|
||||
}
|
||||
|
||||
STATIC const mp_obj_type_t lwip_slip_type;
|
||||
@ -141,7 +141,7 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
|
||||
|
||||
struct netif *n = &lwip_slip_obj.lwip_netif;
|
||||
if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) {
|
||||
mp_raise_ValueError("out of memory");
|
||||
mp_raise_ValueError("out of memory");
|
||||
}
|
||||
netif_set_up(n);
|
||||
netif_set_default(n);
|
||||
@ -167,7 +167,7 @@ STATIC const mp_obj_type_t lwip_slip_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_slip,
|
||||
.make_new = lwip_slip_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&lwip_slip_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&lwip_slip_locals_dict,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_LWIP_SLIP
|
||||
@ -179,7 +179,7 @@ STATIC const mp_obj_type_t lwip_slip_type = {
|
||||
// lwIP 2 changed LWIP_VERSION and it can no longer be used in macros,
|
||||
// so we define our own equivalent version that can.
|
||||
#define LWIP_VERSION_MACRO (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 \
|
||||
| LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC)
|
||||
| LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC)
|
||||
|
||||
// Extension to lwIP error codes
|
||||
#define _ERR_BADF -16
|
||||
@ -301,11 +301,11 @@ typedef struct _lwip_socket_obj_t {
|
||||
} lwip_socket_obj_t;
|
||||
|
||||
static inline void poll_sockets(void) {
|
||||
#ifdef MICROPY_EVENT_POLL_HOOK
|
||||
#ifdef MICROPY_EVENT_POLL_HOOK
|
||||
MICROPY_EVENT_POLL_HOOK;
|
||||
#else
|
||||
#else
|
||||
mp_hal_delay_ms(1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
@ -325,7 +325,7 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
#endif
|
||||
{
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||
|
||||
if (socket->incoming.pbuf != NULL) {
|
||||
// That's why they call it "unreliable". No room in the inn, drop the packet.
|
||||
@ -339,7 +339,7 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
|
||||
// Callback for general tcp errors.
|
||||
STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||
|
||||
// Pass the error code back via the connection variable.
|
||||
socket->state = err;
|
||||
@ -349,7 +349,7 @@ STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
||||
|
||||
// Callback for tcp connection requests. Error code err is unused. (See tcp.h)
|
||||
STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||
|
||||
socket->state = STATE_CONNECTED;
|
||||
return ERR_OK;
|
||||
@ -367,9 +367,8 @@ 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)
|
||||
{
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||
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);
|
||||
return ERR_OK;
|
||||
@ -377,7 +376,7 @@ STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
||||
|
||||
// Callback for incoming tcp connections.
|
||||
STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||
tcp_recv(newpcb, _lwip_tcp_recv_unaccepted);
|
||||
|
||||
// Search for an empty slot to store the new connection
|
||||
@ -408,7 +407,7 @@ STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
||||
|
||||
// Callback for inbound tcp packets.
|
||||
STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err_t err) {
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||
|
||||
if (p == NULL) {
|
||||
// Other side has closed connection.
|
||||
@ -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;
|
||||
@ -506,16 +507,16 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
||||
pbuf_free(p);
|
||||
socket->incoming.pbuf = NULL;
|
||||
|
||||
return (mp_uint_t) result;
|
||||
return (mp_uint_t)result;
|
||||
}
|
||||
|
||||
// For use in stream virtual methods
|
||||
#define STREAM_ERROR_CHECK(socket) \
|
||||
if (socket->state < 0) { \
|
||||
*_errno = error_lookup_table[-socket->state]; \
|
||||
return MP_STREAM_ERROR; \
|
||||
} \
|
||||
assert(socket->pcb.tcp);
|
||||
if (socket->state < 0) { \
|
||||
*_errno = error_lookup_table[-socket->state]; \
|
||||
return MP_STREAM_ERROR; \
|
||||
} \
|
||||
assert(socket->pcb.tcp);
|
||||
|
||||
|
||||
// Helper function for send/sendto to handle TCP packets
|
||||
@ -614,7 +615,7 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
||||
len = remaining;
|
||||
}
|
||||
|
||||
memcpy(buf, (byte*)p->payload + socket->recv_offset, len);
|
||||
memcpy(buf, (byte *)p->payload + socket->recv_offset, len);
|
||||
|
||||
remaining -= len;
|
||||
if (remaining == 0) {
|
||||
@ -670,8 +671,9 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
socket->pcb.udp = udp_new();
|
||||
socket->incoming.pbuf = NULL;
|
||||
break;
|
||||
//case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
|
||||
default: mp_raise_OSError(MP_EINVAL);
|
||||
// case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
|
||||
default:
|
||||
mp_raise_OSError(MP_EINVAL);
|
||||
}
|
||||
|
||||
if (socket->pcb.tcp == NULL) {
|
||||
@ -681,7 +683,7 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
switch (socket->type) {
|
||||
case MOD_NETWORK_SOCK_STREAM: {
|
||||
// Register the socket object as our callback argument.
|
||||
tcp_arg(socket->pcb.tcp, (void*)socket);
|
||||
tcp_arg(socket->pcb.tcp, (void *)socket);
|
||||
// Register our error callback.
|
||||
tcp_err(socket->pcb.tcp, _lwip_tcp_error);
|
||||
break;
|
||||
@ -689,7 +691,7 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
case MOD_NETWORK_SOCK_DGRAM: {
|
||||
// Register our receive callback now. Since UDP sockets don't require binding or connection
|
||||
// before use, there's no other good time to do it.
|
||||
udp_recv(socket->pcb.udp, _lwip_udp_incoming, (void*)socket);
|
||||
udp_recv(socket->pcb.udp, _lwip_udp_incoming, (void *)socket);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -752,7 +754,7 @@ STATIC mp_obj_t lwip_socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
|
||||
socket->incoming.connection.tcp.item = NULL;
|
||||
} else {
|
||||
socket->incoming.connection.alloc = backlog;
|
||||
socket->incoming.connection.tcp.array = m_new0(struct tcp_pcb*, backlog);
|
||||
socket->incoming.connection.tcp.array = m_new0(struct tcp_pcb *, backlog);
|
||||
}
|
||||
socket->incoming.connection.iget = 0;
|
||||
socket->incoming.connection.iput = 0;
|
||||
@ -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);
|
||||
@ -825,7 +829,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
||||
socket2->state = STATE_CONNECTED;
|
||||
socket2->recv_offset = 0;
|
||||
socket2->callback = MP_OBJ_NULL;
|
||||
tcp_arg(socket2->pcb.tcp, (void*)socket2);
|
||||
tcp_arg(socket2->pcb.tcp, (void *)socket2);
|
||||
tcp_err(socket2->pcb.tcp, _lwip_tcp_error);
|
||||
tcp_recv(socket2->pcb.tcp, _lwip_tcp_recv);
|
||||
|
||||
@ -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);
|
||||
@ -892,9 +898,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
}
|
||||
}
|
||||
if (socket->state == STATE_CONNECTED) {
|
||||
err = ERR_OK;
|
||||
err = ERR_OK;
|
||||
} else {
|
||||
err = socket->state;
|
||||
err = socket->state;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -962,11 +968,11 @@ STATIC mp_obj_t lwip_socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
mp_uint_t ret = 0;
|
||||
switch (socket->type) {
|
||||
case MOD_NETWORK_SOCK_STREAM: {
|
||||
ret = lwip_tcp_receive(socket, (byte*)vstr.buf, len, &_errno);
|
||||
ret = lwip_tcp_receive(socket, (byte *)vstr.buf, len, &_errno);
|
||||
break;
|
||||
}
|
||||
case MOD_NETWORK_SOCK_DGRAM: {
|
||||
ret = lwip_udp_receive(socket, (byte*)vstr.buf, len, NULL, NULL, &_errno);
|
||||
ret = lwip_udp_receive(socket, (byte *)vstr.buf, len, NULL, NULL, &_errno);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1029,12 +1035,12 @@ STATIC mp_obj_t lwip_socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
switch (socket->type) {
|
||||
case MOD_NETWORK_SOCK_STREAM: {
|
||||
memcpy(ip, &socket->peer, sizeof(socket->peer));
|
||||
port = (mp_uint_t) socket->peer_port;
|
||||
ret = lwip_tcp_receive(socket, (byte*)vstr.buf, len, &_errno);
|
||||
port = (mp_uint_t)socket->peer_port;
|
||||
ret = lwip_tcp_receive(socket, (byte *)vstr.buf, len, &_errno);
|
||||
break;
|
||||
}
|
||||
case MOD_NETWORK_SOCK_DGRAM: {
|
||||
ret = lwip_udp_receive(socket, (byte*)vstr.buf, len, ip, &port, &_errno);
|
||||
ret = lwip_udp_receive(socket, (byte *)vstr.buf, len, ip, &port, &_errno);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1083,7 +1089,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
mp_raise_OSError(_errno);
|
||||
}
|
||||
bufinfo.len -= ret;
|
||||
bufinfo.buf = (char*)bufinfo.buf + ret;
|
||||
bufinfo.buf = (char *)bufinfo.buf + ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1161,7 +1167,7 @@ STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
// POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
|
||||
err_t err = igmp_joingroup((ip_addr_t*)bufinfo.buf + 1, bufinfo.buf);
|
||||
err_t err = igmp_joingroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf);
|
||||
if (err != ERR_OK) {
|
||||
mp_raise_OSError(error_lookup_table[-err]);
|
||||
}
|
||||
@ -1219,9 +1225,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
||||
if (socket->state == STATE_LISTENING) {
|
||||
// Listening TCP socket may have one or multiple connections waiting
|
||||
if ((socket->incoming.connection.alloc == 0
|
||||
&& socket->incoming.connection.tcp.item != NULL)
|
||||
&& socket->incoming.connection.tcp.item != NULL)
|
||||
|| socket->incoming.connection.tcp.array[socket->incoming.connection.iget] != NULL) {
|
||||
ret |= MP_STREAM_POLL_RD;
|
||||
ret |= MP_STREAM_POLL_RD;
|
||||
}
|
||||
} else {
|
||||
// Otherwise there is just one slot for incoming data
|
||||
@ -1274,8 +1280,10 @@ 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_RAW: raw_remove(socket->pcb.raw); 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;
|
||||
socket->state = _ERR_BADF;
|
||||
@ -1347,7 +1355,7 @@ STATIC const mp_obj_type_t lwip_socket_type = {
|
||||
.print = lwip_socket_print,
|
||||
.make_new = lwip_socket_make_new,
|
||||
.protocol = &lwip_socket_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&lwip_socket_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&lwip_socket_locals_dict,
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
@ -1367,18 +1375,18 @@ void sys_arch_unprotect(sys_prot_t state) {
|
||||
// itself a "list" but isn't; we only support a single interface.
|
||||
|
||||
typedef struct nic_poll {
|
||||
void (* poll)(void *arg);
|
||||
void (*poll)(void *arg);
|
||||
void *poll_arg;
|
||||
} nic_poll_t;
|
||||
|
||||
STATIC nic_poll_t lwip_poll_list;
|
||||
|
||||
void mod_lwip_register_poll(void (* poll)(void *arg), void *poll_arg) {
|
||||
void mod_lwip_register_poll(void (*poll)(void *arg), void *poll_arg) {
|
||||
lwip_poll_list.poll = poll;
|
||||
lwip_poll_list.poll_arg = poll_arg;
|
||||
}
|
||||
|
||||
void mod_lwip_deregister_poll(void (* poll)(void *arg), void *poll_arg) {
|
||||
void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg) {
|
||||
lwip_poll_list.poll = NULL;
|
||||
}
|
||||
|
||||
@ -1445,9 +1453,9 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
if (!((family == 0 || family == MOD_NETWORK_AF_INET)
|
||||
&& (type == 0 || type == MOD_NETWORK_SOCK_STREAM)
|
||||
&& proto == 0
|
||||
&& flags == 0)) {
|
||||
&& (type == 0 || type == MOD_NETWORK_SOCK_STREAM)
|
||||
&& proto == 0
|
||||
&& flags == 0)) {
|
||||
mp_warning("unsupported getaddrinfo constraints");
|
||||
}
|
||||
}
|
||||
@ -1455,7 +1463,7 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
getaddrinfo_state_t state;
|
||||
state.status = 0;
|
||||
|
||||
err_t ret = dns_gethostbyname(host, (ip_addr_t*)&state.ipaddr, lwip_getaddrinfo_cb, &state);
|
||||
err_t ret = dns_gethostbyname(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state);
|
||||
switch (ret) {
|
||||
case ERR_OK:
|
||||
// cached
|
||||
@ -1481,8 +1489,8 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
|
||||
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
|
||||
tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
|
||||
tuple->items[4] = netutils_format_inet_addr((uint8_t*)&state.ipaddr, port, NETUTILS_BIG);
|
||||
return mp_obj_new_list(1, (mp_obj_t*)&tuple);
|
||||
tuple->items[4] = netutils_format_inet_addr((uint8_t *)&state.ipaddr, port, NETUTILS_BIG);
|
||||
return mp_obj_new_list(1, (mp_obj_t *)&tuple);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_getaddrinfo_obj, 2, 6, lwip_getaddrinfo);
|
||||
|
||||
@ -1504,9 +1512,9 @@ STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
|
||||
// objects
|
||||
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) },
|
||||
#ifdef MICROPY_PY_LWIP_SLIP
|
||||
#ifdef MICROPY_PY_LWIP_SLIP
|
||||
{ MP_ROM_QSTR(MP_QSTR_slip), MP_ROM_PTR(&lwip_slip_type) },
|
||||
#endif
|
||||
#endif
|
||||
// class constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) },
|
||||
@ -1526,7 +1534,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table
|
||||
|
||||
const mp_obj_module_t mp_module_lwip = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_lwip_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_lwip_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_LWIP
|
||||
|
@ -126,7 +126,7 @@ STATIC mp_obj_t onewire_crc8(mp_obj_t data) {
|
||||
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
||||
uint8_t crc = 0;
|
||||
for (size_t i = 0; i < bufinfo.len; ++i) {
|
||||
uint8_t byte = ((uint8_t*)bufinfo.buf)[i];
|
||||
uint8_t byte = ((uint8_t *)bufinfo.buf)[i];
|
||||
for (int b = 0; b < 8; ++b) {
|
||||
uint8_t fb_bit = (crc ^ byte) & 0x01;
|
||||
if (fb_bit == 0x01) {
|
||||
@ -158,5 +158,5 @@ STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table
|
||||
|
||||
const mp_obj_module_t mp_module_onewire = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&onewire_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&onewire_module_globals,
|
||||
};
|
||||
|
@ -53,7 +53,7 @@ mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
|
||||
sep = mp_obj_str_get_str(args[1]);
|
||||
}
|
||||
vstr_init_len(&vstr, out_len);
|
||||
byte *in = bufinfo.buf, *out = (byte*)vstr.buf;
|
||||
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||
for (mp_uint_t i = bufinfo.len; i--;) {
|
||||
byte d = (*in >> 4);
|
||||
if (d > 9) {
|
||||
@ -82,7 +82,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
|
||||
}
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, bufinfo.len / 2);
|
||||
byte *in = bufinfo.buf, *out = (byte*)vstr.buf;
|
||||
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||
byte hex_byte = 0;
|
||||
for (mp_uint_t i = bufinfo.len; i--;) {
|
||||
byte hex_ch = *in++;
|
||||
@ -172,7 +172,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
||||
vstr_init_len(&vstr, ((bufinfo.len != 0) ? (((bufinfo.len - 1) / 3) + 1) * 4 : 0) + 1);
|
||||
|
||||
// First pass, we convert input buffer to numeric base 64 values
|
||||
byte *in = bufinfo.buf, *out = (byte*)vstr.buf;
|
||||
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||
mp_uint_t i;
|
||||
for (i = bufinfo.len; i >= 3; i -= 3) {
|
||||
*out++ = (in[0] & 0xFC) >> 2;
|
||||
@ -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;
|
||||
}
|
||||
@ -195,7 +194,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
||||
}
|
||||
|
||||
// Second pass, we convert number base 64 values to actual base64 ascii encoding
|
||||
out = (byte*)vstr.buf;
|
||||
out = (byte *)vstr.buf;
|
||||
for (mp_uint_t j = vstr.len - 1; j--;) {
|
||||
if (*out < 26) {
|
||||
*out += 'A';
|
||||
@ -204,7 +203,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
||||
} else if (*out < 62) {
|
||||
*out += '0' - 52;
|
||||
} else if (*out == 62) {
|
||||
*out ='+';
|
||||
*out = '+';
|
||||
} else if (*out == 63) {
|
||||
*out = '/';
|
||||
} else {
|
||||
@ -247,7 +246,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globa
|
||||
|
||||
const mp_obj_module_t mp_module_ubinascii = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_binascii_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_binascii_globals,
|
||||
};
|
||||
|
||||
#endif //MICROPY_PY_UBINASCII
|
||||
#endif // MICROPY_PY_UBINASCII
|
||||
|
@ -75,11 +75,11 @@ struct mbedtls_aes_ctx_with_key {
|
||||
typedef struct _mp_obj_aes_t {
|
||||
mp_obj_base_t base;
|
||||
AES_CTX_IMPL ctx;
|
||||
uint8_t block_mode: 6;
|
||||
uint8_t block_mode : 6;
|
||||
#define AES_KEYTYPE_NONE 0
|
||||
#define AES_KEYTYPE_ENC 1
|
||||
#define AES_KEYTYPE_DEC 2
|
||||
uint8_t key_type: 2;
|
||||
uint8_t key_type : 2;
|
||||
} mp_obj_aes_t;
|
||||
|
||||
#if MICROPY_SSL_AXTLS
|
||||
@ -97,7 +97,7 @@ STATIC void aes_final_set_key_impl(AES_CTX_IMPL *ctx, bool encrypt) {
|
||||
STATIC void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_t out[16], bool encrypt) {
|
||||
memcpy(out, in, 16);
|
||||
// We assume that out (vstr.buf or given output buffer) is uint32_t aligned
|
||||
uint32_t *p = (uint32_t*)out;
|
||||
uint32_t *p = (uint32_t *)out;
|
||||
// axTLS likes it weird and complicated with byteswaps
|
||||
for (int i = 0; i < 4; i++) {
|
||||
p[i] = MP_HTOBE32(p[i]);
|
||||
@ -220,7 +220,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
|
||||
out_buf_ptr = out_bufinfo.buf;
|
||||
} else {
|
||||
vstr_init_len(&vstr, in_bufinfo.len);
|
||||
out_buf_ptr = (uint8_t*)vstr.buf;
|
||||
out_buf_ptr = (uint8_t *)vstr.buf;
|
||||
}
|
||||
|
||||
if (AES_KEYTYPE_NONE == self->key_type) {
|
||||
@ -270,23 +270,23 @@ STATIC const mp_obj_type_t ucryptolib_aes_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_aes,
|
||||
.make_new = ucryptolib_aes_make_new,
|
||||
.locals_dict = (void*)&ucryptolib_aes_locals_dict,
|
||||
.locals_dict = (void *)&ucryptolib_aes_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ucryptolib) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&ucryptolib_aes_type) },
|
||||
#if MICROPY_PY_UCRYPTOLIB_CONSTS
|
||||
#if MICROPY_PY_UCRYPTOLIB_CONSTS
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(UCRYPTOLIB_MODE_CBC) },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_ucryptolib_globals, mp_module_ucryptolib_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_ucryptolib = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_ucryptolib_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_ucryptolib_globals,
|
||||
};
|
||||
|
||||
#endif //MICROPY_PY_UCRYPTOLIB
|
||||
#endif // MICROPY_PY_UCRYPTOLIB
|
||||
|
@ -124,7 +124,7 @@ STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||
o->base.type = type;
|
||||
o->addr = (void*)(uintptr_t)mp_obj_int_get_truncated(args[0]);
|
||||
o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]);
|
||||
o->desc = args[1];
|
||||
o->flags = LAYOUT_NATIVE;
|
||||
if (n_args == 3) {
|
||||
@ -138,18 +138,22 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
const char *typen = "unk";
|
||||
if (MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
|| MP_OBJ_IS_TYPE(self->desc, &mp_type_ordereddict)
|
||||
#endif
|
||||
) {
|
||||
#endif
|
||||
) {
|
||||
typen = "STRUCT";
|
||||
} else if (MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
||||
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";
|
||||
@ -180,10 +184,10 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
|
||||
case STRUCT:
|
||||
return uctypes_struct_size(t->items[1], layout_type, max_field_size);
|
||||
case PTR:
|
||||
if (sizeof(void*) > *max_field_size) {
|
||||
*max_field_size = sizeof(void*);
|
||||
if (sizeof(void *) > *max_field_size) {
|
||||
*max_field_size = sizeof(void *);
|
||||
}
|
||||
return sizeof(void*);
|
||||
return sizeof(void *);
|
||||
case ARRAY: {
|
||||
mp_int_t arr_sz = MP_OBJ_SMALL_INT_VALUE(t->items[1]);
|
||||
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
|
||||
@ -211,12 +215,12 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
|
||||
|
||||
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) {
|
||||
if (!MP_OBJ_IS_TYPE(desc_in, &mp_type_dict)
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
&& !MP_OBJ_IS_TYPE(desc_in, &mp_type_ordereddict)
|
||||
#endif
|
||||
) {
|
||||
#endif
|
||||
) {
|
||||
if (MP_OBJ_IS_TYPE(desc_in, &mp_type_tuple)) {
|
||||
return uctypes_struct_agg_size((mp_obj_tuple_t*)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
|
||||
return uctypes_struct_agg_size((mp_obj_tuple_t *)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
|
||||
} else if (MP_OBJ_IS_SMALL_INT(desc_in)) {
|
||||
// We allow sizeof on both type definitions and structures/structure fields,
|
||||
// but scalar structure field is lowered into native Python int, so all
|
||||
@ -311,11 +315,11 @@ static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_
|
||||
static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
|
||||
switch (val_type) {
|
||||
case UINT8:
|
||||
return *(uint8_t*)p;
|
||||
return *(uint8_t *)p;
|
||||
case UINT16:
|
||||
return *(uint16_t*)p;
|
||||
return *(uint16_t *)p;
|
||||
case UINT32:
|
||||
return *(uint32_t*)p;
|
||||
return *(uint32_t *)p;
|
||||
}
|
||||
assert(0);
|
||||
return 0;
|
||||
@ -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);
|
||||
}
|
||||
@ -336,26 +343,26 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
|
||||
STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
|
||||
switch (val_type) {
|
||||
case UINT8:
|
||||
return MP_OBJ_NEW_SMALL_INT(((uint8_t*)p)[index]);
|
||||
return MP_OBJ_NEW_SMALL_INT(((uint8_t *)p)[index]);
|
||||
case INT8:
|
||||
return MP_OBJ_NEW_SMALL_INT(((int8_t*)p)[index]);
|
||||
return MP_OBJ_NEW_SMALL_INT(((int8_t *)p)[index]);
|
||||
case UINT16:
|
||||
return MP_OBJ_NEW_SMALL_INT(((uint16_t*)p)[index]);
|
||||
return MP_OBJ_NEW_SMALL_INT(((uint16_t *)p)[index]);
|
||||
case INT16:
|
||||
return MP_OBJ_NEW_SMALL_INT(((int16_t*)p)[index]);
|
||||
return MP_OBJ_NEW_SMALL_INT(((int16_t *)p)[index]);
|
||||
case UINT32:
|
||||
return mp_obj_new_int_from_uint(((uint32_t*)p)[index]);
|
||||
return mp_obj_new_int_from_uint(((uint32_t *)p)[index]);
|
||||
case INT32:
|
||||
return mp_obj_new_int(((int32_t*)p)[index]);
|
||||
return mp_obj_new_int(((int32_t *)p)[index]);
|
||||
case UINT64:
|
||||
return mp_obj_new_int_from_ull(((uint64_t*)p)[index]);
|
||||
return mp_obj_new_int_from_ull(((uint64_t *)p)[index]);
|
||||
case INT64:
|
||||
return mp_obj_new_int_from_ll(((int64_t*)p)[index]);
|
||||
return mp_obj_new_int_from_ll(((int64_t *)p)[index]);
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
case FLOAT32:
|
||||
return mp_obj_new_float(((float*)p)[index]);
|
||||
return mp_obj_new_float(((float *)p)[index]);
|
||||
case FLOAT64:
|
||||
return mp_obj_new_float(((double*)p)[index]);
|
||||
return mp_obj_new_float(((double *)p)[index]);
|
||||
#endif
|
||||
default:
|
||||
assert(0);
|
||||
@ -368,9 +375,9 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
|
||||
if (val_type == FLOAT32 || val_type == FLOAT64) {
|
||||
mp_float_t v = mp_obj_get_float(val);
|
||||
if (val_type == FLOAT32) {
|
||||
((float*)p)[index] = v;
|
||||
((float *)p)[index] = v;
|
||||
} else {
|
||||
((double*)p)[index] = v;
|
||||
((double *)p)[index] = v;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -378,21 +385,27 @@ 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) {
|
||||
((uint64_t*)p)[index] = (uint64_t)v;
|
||||
((uint64_t *)p)[index] = (uint64_t)v;
|
||||
} else {
|
||||
// TODO: Doesn't offer atomic store semantics, but should at least try
|
||||
set_unaligned(val_type, p, MP_ENDIANNESS_BIG, val);
|
||||
@ -407,11 +420,11 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
&& !MP_OBJ_IS_TYPE(self->desc, &mp_type_ordereddict)
|
||||
#endif
|
||||
) {
|
||||
mp_raise_TypeError("struct: no fields");
|
||||
#endif
|
||||
) {
|
||||
mp_raise_TypeError("struct: no fields");
|
||||
}
|
||||
|
||||
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
|
||||
@ -419,7 +432,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref);
|
||||
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
||||
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
||||
//printf("scalar type=%d offset=%x\n", val_type, offset);
|
||||
// printf("scalar type=%d offset=%x\n", val_type, offset);
|
||||
|
||||
if (val_type <= INT64 || val_type == FLOAT32 || val_type == FLOAT64) {
|
||||
// printf("size=%d\n", GET_SCALAR_SIZE(val_type));
|
||||
@ -489,7 +502,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(sub->items[0]);
|
||||
mp_uint_t agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
offset &= VALUE_MASK(AGG_TYPE_BITS);
|
||||
//printf("agg type=%d offset=%x\n", agg_type, offset);
|
||||
// printf("agg type=%d offset=%x\n", agg_type, offset);
|
||||
|
||||
switch (agg_type) {
|
||||
case STRUCT: {
|
||||
@ -513,7 +526,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
o->desc = MP_OBJ_FROM_PTR(sub);
|
||||
o->addr = self->addr + offset;
|
||||
o->flags = self->flags;
|
||||
//printf("PTR/ARR base addr=%p\n", o->addr);
|
||||
// printf("PTR/ARR base addr=%p\n", o->addr);
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
}
|
||||
@ -593,7 +606,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
||||
}
|
||||
|
||||
} else if (agg_type == PTR) {
|
||||
byte *p = *(void**)self->addr;
|
||||
byte *p = *(void **)self->addr;
|
||||
if (MP_OBJ_IS_SMALL_INT(t->items[1])) {
|
||||
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
|
||||
return get_aligned(val_type, p, index);
|
||||
@ -623,13 +636,14 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
if (agg_type == PTR) {
|
||||
byte *p = *(void**)self->addr;
|
||||
byte *p = *(void **)self->addr;
|
||||
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
|
||||
}
|
||||
}
|
||||
/* fallthru */
|
||||
/* fallthru */
|
||||
|
||||
default: return MP_OBJ_NULL; // op not supported
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,7 +674,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof
|
||||
/// captured by reference (and thus memory pointed by bytearray may change
|
||||
/// or become invalid at later time). Use bytes_at() to capture by value.
|
||||
STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
|
||||
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)(uintptr_t)mp_obj_int_get_truncated(ptr));
|
||||
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
|
||||
|
||||
@ -669,7 +683,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear
|
||||
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference
|
||||
/// ("zero copy").
|
||||
STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
|
||||
return mp_obj_new_bytes((void*)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
|
||||
return mp_obj_new_bytes((void *)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
|
||||
|
||||
@ -772,7 +786,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals
|
||||
|
||||
const mp_obj_module_t mp_module_uctypes = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_uctypes_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_uctypes_globals,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -78,8 +78,8 @@ STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context));
|
||||
o->base.type = type;
|
||||
mbedtls_sha256_init((mbedtls_sha256_context*)&o->state);
|
||||
mbedtls_sha256_starts_ret((mbedtls_sha256_context*)&o->state, 0);
|
||||
mbedtls_sha256_init((mbedtls_sha256_context *)&o->state);
|
||||
mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -90,7 +90,7 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
mbedtls_sha256_update_ret((mbedtls_sha256_context*)&self->state, bufinfo.buf, bufinfo.len);
|
||||
mbedtls_sha256_update_ret((mbedtls_sha256_context *)&self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 32);
|
||||
mbedtls_sha256_finish_ret((mbedtls_sha256_context*)&self->state, (unsigned char *)vstr.buf);
|
||||
mbedtls_sha256_finish_ret((mbedtls_sha256_context *)&self->state, (unsigned char *)vstr.buf);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
||||
o->base.type = type;
|
||||
sha256_init((CRYAL_SHA256_CTX*)o->state);
|
||||
sha256_init((CRYAL_SHA256_CTX *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -119,7 +119,7 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
sha256_update((CRYAL_SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
|
||||
sha256_update((CRYAL_SHA256_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
||||
sha256_final((CRYAL_SHA256_CTX*)self->state, (byte*)vstr.buf);
|
||||
sha256_final((CRYAL_SHA256_CTX *)self->state, (byte *)vstr.buf);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
#endif
|
||||
@ -146,7 +146,7 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_sha256,
|
||||
.make_new = uhashlib_sha256_make_new,
|
||||
.locals_dict = (void*)&uhashlib_sha256_locals_dict,
|
||||
.locals_dict = (void *)&uhashlib_sha256_locals_dict,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -158,7 +158,7 @@ STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA1_CTX));
|
||||
o->base.type = type;
|
||||
SHA1_Init((SHA1_CTX*)o->state);
|
||||
SHA1_Init((SHA1_CTX *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -169,7 +169,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
SHA1_Update((SHA1_CTX*)self->state, bufinfo.buf, bufinfo.len);
|
||||
SHA1_Update((SHA1_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA1_SIZE);
|
||||
SHA1_Final((byte*)vstr.buf, (SHA1_CTX*)self->state);
|
||||
SHA1_Final((byte *)vstr.buf, (SHA1_CTX *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
#endif
|
||||
@ -194,8 +194,8 @@ STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context));
|
||||
o->base.type = type;
|
||||
mbedtls_sha1_init((mbedtls_sha1_context*)o->state);
|
||||
mbedtls_sha1_starts_ret((mbedtls_sha1_context*)o->state);
|
||||
mbedtls_sha1_init((mbedtls_sha1_context *)o->state);
|
||||
mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -206,7 +206,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
mbedtls_sha1_update_ret((mbedtls_sha1_context*)self->state, bufinfo.buf, bufinfo.len);
|
||||
mbedtls_sha1_update_ret((mbedtls_sha1_context *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 20);
|
||||
mbedtls_sha1_finish_ret((mbedtls_sha1_context*)self->state, (byte*)vstr.buf);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context*)self->state);
|
||||
mbedtls_sha1_finish_ret((mbedtls_sha1_context *)self->state, (byte *)vstr.buf);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
#endif
|
||||
@ -233,7 +233,7 @@ STATIC const mp_obj_type_t uhashlib_sha1_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_sha1,
|
||||
.make_new = uhashlib_sha1_make_new,
|
||||
.locals_dict = (void*)&uhashlib_sha1_locals_dict,
|
||||
.locals_dict = (void *)&uhashlib_sha1_locals_dict,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -245,7 +245,7 @@ STATIC mp_obj_t uhashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(MD5_CTX));
|
||||
o->base.type = type;
|
||||
MD5_Init((MD5_CTX*)o->state);
|
||||
MD5_Init((MD5_CTX *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -256,7 +256,7 @@ STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
MD5_Update((MD5_CTX*)self->state, bufinfo.buf, bufinfo.len);
|
||||
MD5_Update((MD5_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, MD5_SIZE);
|
||||
MD5_Final((byte*)vstr.buf, (MD5_CTX*)self->state);
|
||||
MD5_Final((byte *)vstr.buf, (MD5_CTX *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
#endif // MICROPY_SSL_AXTLS
|
||||
@ -281,8 +281,8 @@ STATIC mp_obj_t uhashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context));
|
||||
o->base.type = type;
|
||||
mbedtls_md5_init((mbedtls_md5_context*)o->state);
|
||||
mbedtls_md5_starts_ret((mbedtls_md5_context*)o->state);
|
||||
mbedtls_md5_init((mbedtls_md5_context *)o->state);
|
||||
mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -293,7 +293,7 @@ STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
mbedtls_md5_update_ret((mbedtls_md5_context*)self->state, bufinfo.buf, bufinfo.len);
|
||||
mbedtls_md5_update_ret((mbedtls_md5_context *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -301,8 +301,8 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 16);
|
||||
mbedtls_md5_finish_ret((mbedtls_md5_context*)self->state, (byte*)vstr.buf);
|
||||
mbedtls_md5_free((mbedtls_md5_context*)self->state);
|
||||
mbedtls_md5_finish_ret((mbedtls_md5_context *)self->state, (byte *)vstr.buf);
|
||||
mbedtls_md5_free((mbedtls_md5_context *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
#endif // MICROPY_SSL_MBEDTLS
|
||||
@ -320,7 +320,7 @@ STATIC const mp_obj_type_t uhashlib_md5_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_md5,
|
||||
.make_new = uhashlib_md5_make_new,
|
||||
.locals_dict = (void*)&uhashlib_md5_locals_dict,
|
||||
.locals_dict = (void *)&uhashlib_md5_locals_dict,
|
||||
};
|
||||
#endif // MICROPY_PY_UHASHLIB_MD5
|
||||
|
||||
@ -341,11 +341,11 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uhashlib_globals, mp_module_uhashlib_globa
|
||||
|
||||
const mp_obj_module_t mp_module_uhashlib = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_uhashlib_globals,
|
||||
};
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_SHA256
|
||||
#include "crypto-algorithms/sha256.c"
|
||||
#endif
|
||||
|
||||
#endif //MICROPY_PY_UHASHLIB
|
||||
#endif // MICROPY_PY_UHASHLIB
|
||||
|
@ -114,7 +114,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uheapq_globals, mp_module_uheapq_globals_t
|
||||
|
||||
const mp_obj_module_t mp_module_uheapq = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_uheapq_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_uheapq_globals,
|
||||
};
|
||||
|
||||
#endif //MICROPY_PY_UHEAPQ
|
||||
#endif // MICROPY_PY_UHEAPQ
|
||||
|
@ -100,7 +100,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
||||
mp_obj_t stack_key = MP_OBJ_NULL;
|
||||
S_NEXT(s);
|
||||
for (;;) {
|
||||
cont:
|
||||
cont:
|
||||
if (S_END(s)) {
|
||||
break;
|
||||
}
|
||||
@ -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 (;;) {
|
||||
@ -259,7 +278,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
||||
}
|
||||
}
|
||||
}
|
||||
success:
|
||||
success:
|
||||
// eat trailing whitespace
|
||||
while (unichar_isspace(S_CUR(s))) {
|
||||
S_NEXT(s);
|
||||
@ -275,7 +294,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
||||
vstr_clear(&vstr);
|
||||
return stack_top;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
mp_raise_ValueError("syntax error in JSON");
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);
|
||||
@ -283,7 +302,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);
|
||||
STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
|
||||
size_t len;
|
||||
const char *buf = mp_obj_str_get_data(obj, &len);
|
||||
vstr_t vstr = {len, len, (char*)buf, true};
|
||||
vstr_t vstr = {len, len, (char *)buf, true};
|
||||
mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL};
|
||||
return mod_ujson_load(MP_OBJ_FROM_PTR(&sio));
|
||||
}
|
||||
@ -301,7 +320,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ujson_globals, mp_module_ujson_globals_tab
|
||||
|
||||
const mp_obj_module_t mp_module_ujson = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_ujson_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_ujson_globals,
|
||||
};
|
||||
|
||||
#endif //MICROPY_PY_UJSON
|
||||
#endif // MICROPY_PY_UJSON
|
||||
|
@ -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)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
@ -219,7 +220,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_urandom_globals, mp_module_urandom_globals
|
||||
|
||||
const mp_obj_module_t mp_module_urandom = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_urandom_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_urandom_globals,
|
||||
};
|
||||
|
||||
#endif //MICROPY_PY_URANDOM
|
||||
#endif // MICROPY_PY_URANDOM
|
||||
|
@ -73,7 +73,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
|
||||
return mp_const_none;
|
||||
}
|
||||
return mp_obj_new_str_of_type(mp_obj_get_type(self->str),
|
||||
(const byte*)start, self->caps[no * 2 + 1] - start);
|
||||
(const byte *)start, self->caps[no * 2 + 1] - start);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group);
|
||||
|
||||
@ -162,7 +162,7 @@ STATIC const mp_obj_type_t match_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_match,
|
||||
.print = match_print,
|
||||
.locals_dict = (void*)&match_locals_dict,
|
||||
.locals_dict = (void *)&match_locals_dict,
|
||||
};
|
||||
|
||||
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
@ -179,12 +179,12 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
subj.begin = mp_obj_str_get_data(args[1], &len);
|
||||
subj.end = subj.begin + len;
|
||||
int caps_num = (self->re.sub + 1) * 2;
|
||||
mp_obj_match_t *match = m_new_obj_var(mp_obj_match_t, char*, caps_num);
|
||||
mp_obj_match_t *match = m_new_obj_var(mp_obj_match_t, char *, caps_num);
|
||||
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
||||
memset((char*)match->caps, 0, caps_num * sizeof(char*));
|
||||
memset((char *)match->caps, 0, caps_num * sizeof(char *));
|
||||
int res = re1_5_recursiveloopprog(&self->re, &subj, match->caps, caps_num, is_anchored);
|
||||
if (res == 0) {
|
||||
m_del_var(mp_obj_match_t, char*, caps_num, match);
|
||||
m_del_var(mp_obj_match_t, char *, caps_num, match);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -219,10 +219,10 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
mp_obj_t retval = mp_obj_new_list(0, NULL);
|
||||
const char **caps = mp_local_alloc(caps_num * sizeof(char*));
|
||||
const char **caps = mp_local_alloc(caps_num * sizeof(char *));
|
||||
while (true) {
|
||||
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
||||
memset((char**)caps, 0, caps_num * sizeof(char*));
|
||||
memset((char **)caps, 0, caps_num * sizeof(char *));
|
||||
int res = re1_5_recursiveloopprog(&self->re, &subj, caps, caps_num, false);
|
||||
|
||||
// if we didn't have a match, or had an empty match, it's time to stop
|
||||
@ -230,7 +230,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
||||
break;
|
||||
}
|
||||
|
||||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, caps[0] - subj.begin);
|
||||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte *)subj.begin, caps[0] - subj.begin);
|
||||
mp_obj_list_append(retval, s);
|
||||
if (self->re.sub > 0) {
|
||||
mp_raise_NotImplementedError("Splitting with sub-captures");
|
||||
@ -241,9 +241,9 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
// cast is a workaround for a bug in msvc (see above)
|
||||
mp_local_free((char**)caps);
|
||||
mp_local_free((char **)caps);
|
||||
|
||||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, subj.end - subj.begin);
|
||||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte *)subj.begin, subj.end - subj.begin);
|
||||
mp_obj_list_append(retval, s);
|
||||
return retval;
|
||||
}
|
||||
@ -270,14 +270,14 @@ STATIC mp_obj_t re_sub_helper(mp_obj_t self_in, size_t n_args, const mp_obj_t *a
|
||||
|
||||
vstr_t vstr_return;
|
||||
vstr_return.buf = NULL; // We'll init the vstr after the first match
|
||||
mp_obj_match_t *match = mp_local_alloc(sizeof(mp_obj_match_t) + caps_num * sizeof(char*));
|
||||
mp_obj_match_t *match = mp_local_alloc(sizeof(mp_obj_match_t) + caps_num * sizeof(char *));
|
||||
match->base.type = &match_type;
|
||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||
match->str = where;
|
||||
|
||||
for (;;) {
|
||||
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
||||
memset((char*)match->caps, 0, caps_num * sizeof(char*));
|
||||
memset((char *)match->caps, 0, caps_num * sizeof(char *));
|
||||
int res = re1_5_recursiveloopprog(&self->re, &subj, match->caps, caps_num, false);
|
||||
|
||||
// If we didn't have a match, or had an empty match, it's time to stop
|
||||
@ -294,7 +294,7 @@ STATIC mp_obj_t re_sub_helper(mp_obj_t self_in, size_t n_args, const mp_obj_t *a
|
||||
vstr_add_strn(&vstr_return, subj.begin, match->caps[0] - subj.begin);
|
||||
|
||||
// Get replacement string
|
||||
const char* repl = mp_obj_str_get_str((mp_obj_is_callable(replace) ? mp_call_function_1(replace, MP_OBJ_FROM_PTR(match)) : replace));
|
||||
const char *repl = mp_obj_str_get_str((mp_obj_is_callable(replace) ? mp_call_function_1(replace, MP_OBJ_FROM_PTR(match)) : replace));
|
||||
|
||||
// Append replacement string to result, substituting any regex groups
|
||||
while (*repl != '\0') {
|
||||
@ -378,7 +378,7 @@ STATIC const mp_obj_type_t re_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ure,
|
||||
.print = re_print,
|
||||
.locals_dict = (void*)&re_locals_dict,
|
||||
.locals_dict = (void *)&re_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
||||
@ -395,7 +395,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
int error = re1_5_compilecode(&o->re, re_str);
|
||||
if (error != 0) {
|
||||
error:
|
||||
error:
|
||||
mp_raise_ValueError("Error in regex");
|
||||
}
|
||||
if (flags & FLAG_DEBUG) {
|
||||
@ -447,7 +447,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_ure = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_re_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_re_globals,
|
||||
};
|
||||
|
||||
// Source files #include'd here to make sure they're compiled in
|
||||
@ -459,4 +459,4 @@ const mp_obj_module_t mp_module_ure = {
|
||||
#include "re1.5/recursiveloop.c"
|
||||
#include "re1.5/charclass.c"
|
||||
|
||||
#endif //MICROPY_PY_URE
|
||||
#endif // MICROPY_PY_URE
|
||||
|
@ -65,9 +65,9 @@ STATIC void poll_map_add(mp_map_t *poll_map, const mp_obj_t *obj, mp_uint_t obj_
|
||||
} else {
|
||||
// object exists; update its flags
|
||||
if (or_flags) {
|
||||
((poll_obj_t*)MP_OBJ_TO_PTR(elem->value))->flags |= flags;
|
||||
((poll_obj_t *)MP_OBJ_TO_PTR(elem->value))->flags |= flags;
|
||||
} else {
|
||||
((poll_obj_t*)MP_OBJ_TO_PTR(elem->value))->flags = flags;
|
||||
((poll_obj_t *)MP_OBJ_TO_PTR(elem->value))->flags = flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,13 +160,13 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(poll_map.table[i].value);
|
||||
if (poll_obj->flags_ret & MP_STREAM_POLL_RD) {
|
||||
((mp_obj_list_t*)MP_OBJ_TO_PTR(list_array[0]))->items[rwx_len[0]++] = poll_obj->obj;
|
||||
((mp_obj_list_t *)MP_OBJ_TO_PTR(list_array[0]))->items[rwx_len[0]++] = poll_obj->obj;
|
||||
}
|
||||
if (poll_obj->flags_ret & MP_STREAM_POLL_WR) {
|
||||
((mp_obj_list_t*)MP_OBJ_TO_PTR(list_array[1]))->items[rwx_len[1]++] = poll_obj->obj;
|
||||
((mp_obj_list_t *)MP_OBJ_TO_PTR(list_array[1]))->items[rwx_len[1]++] = poll_obj->obj;
|
||||
}
|
||||
if ((poll_obj->flags_ret & ~(MP_STREAM_POLL_RD | MP_STREAM_POLL_WR)) != 0) {
|
||||
((mp_obj_list_t*)MP_OBJ_TO_PTR(list_array[2]))->items[rwx_len[2]++] = poll_obj->obj;
|
||||
((mp_obj_list_t *)MP_OBJ_TO_PTR(list_array[2]))->items[rwx_len[2]++] = poll_obj->obj;
|
||||
}
|
||||
}
|
||||
mp_map_deinit(&poll_map);
|
||||
@ -219,7 +219,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
|
||||
if (elem == NULL) {
|
||||
mp_raise_OSError(MP_ENOENT);
|
||||
}
|
||||
((poll_obj_t*)MP_OBJ_TO_PTR(elem->value))->flags = mp_obj_get_int(eventmask_in);
|
||||
((poll_obj_t *)MP_OBJ_TO_PTR(elem->value))->flags = mp_obj_get_int(eventmask_in);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify);
|
||||
@ -344,7 +344,7 @@ STATIC const mp_obj_type_t mp_type_poll = {
|
||||
.name = MP_QSTR_poll,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = poll_iternext,
|
||||
.locals_dict = (void*)&poll_locals_dict,
|
||||
.locals_dict = (void *)&poll_locals_dict,
|
||||
};
|
||||
|
||||
/// \function poll()
|
||||
@ -372,7 +372,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_t
|
||||
|
||||
const mp_obj_module_t mp_module_uselect = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_select_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_select_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_USELECT
|
||||
|
@ -53,11 +53,11 @@ struct ssl_args {
|
||||
STATIC const mp_obj_type_t ussl_socket_type;
|
||||
|
||||
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
#else
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
#endif
|
||||
#endif
|
||||
o->base.type = &ussl_socket_type;
|
||||
o->buf = NULL;
|
||||
o->bytes_left = 0;
|
||||
@ -73,13 +73,13 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
|
||||
if (args->key.u_obj != mp_const_none) {
|
||||
size_t len;
|
||||
const byte *data = (const byte*)mp_obj_str_get_data(args->key.u_obj, &len);
|
||||
const byte *data = (const byte *)mp_obj_str_get_data(args->key.u_obj, &len);
|
||||
int res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_RSA_KEY, data, len, NULL);
|
||||
if (res != SSL_OK) {
|
||||
mp_raise_ValueError("invalid key");
|
||||
}
|
||||
|
||||
data = (const byte*)mp_obj_str_get_data(args->cert.u_obj, &len);
|
||||
data = (const byte *)mp_obj_str_get_data(args->cert.u_obj, &len);
|
||||
res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_X509_CERT, data, len, NULL);
|
||||
if (res != SSL_OK) {
|
||||
mp_raise_ValueError("invalid cert");
|
||||
@ -92,7 +92,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
SSL_EXTENSIONS *ext = ssl_ext_new();
|
||||
|
||||
if (args->server_hostname.u_obj != mp_const_none) {
|
||||
ext->host_name = (char*)mp_obj_str_get_str(args->server_hostname.u_obj);
|
||||
ext->host_name = (char *)mp_obj_str_get_str(args->server_hostname.u_obj);
|
||||
}
|
||||
|
||||
o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
|
||||
@ -203,9 +203,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
|
||||
@ -224,7 +224,7 @@ STATIC const mp_obj_type_t ussl_socket_type = {
|
||||
.getiter = NULL,
|
||||
.iternext = NULL,
|
||||
.protocol = &ussl_socket_stream_p,
|
||||
.locals_dict = (void*)&ussl_socket_locals_dict,
|
||||
.locals_dict = (void *)&ussl_socket_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
@ -241,7 +241,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||
|
||||
struct ssl_args args;
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||
|
||||
return MP_OBJ_FROM_PTR(socket_new(sock, &args));
|
||||
}
|
||||
@ -256,7 +256,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_ussl = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_ssl_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_ssl_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_USSL
|
||||
|
@ -74,7 +74,7 @@ STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, cons
|
||||
#endif
|
||||
|
||||
STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
||||
mp_obj_t sock = *(mp_obj_t*)ctx;
|
||||
mp_obj_t sock = *(mp_obj_t *)ctx;
|
||||
|
||||
const mp_stream_p_t *sock_stream = mp_get_stream(sock);
|
||||
int err;
|
||||
@ -91,7 +91,7 @@ STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
||||
}
|
||||
|
||||
STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
|
||||
mp_obj_t sock = *(mp_obj_t*)ctx;
|
||||
mp_obj_t sock = *(mp_obj_t *)ctx;
|
||||
|
||||
const mp_stream_p_t *sock_stream = mp_get_stream(sock);
|
||||
int err;
|
||||
@ -112,11 +112,11 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
// Verify the socket object has the full stream protocol
|
||||
mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
|
||||
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
#else
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
#endif
|
||||
#endif
|
||||
o->base.type = &ussl_socket_type;
|
||||
o->sock = sock;
|
||||
|
||||
@ -140,9 +140,9 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
}
|
||||
|
||||
ret = mbedtls_ssl_config_defaults(&o->conf,
|
||||
args->server_side.u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT,
|
||||
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||
MBEDTLS_SSL_PRESET_DEFAULT);
|
||||
args->server_side.u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT,
|
||||
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||
MBEDTLS_SSL_PRESET_DEFAULT);
|
||||
if (ret != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -170,13 +170,13 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
|
||||
if (args->key.u_obj != MP_OBJ_NULL) {
|
||||
size_t key_len;
|
||||
const byte *key = (const byte*)mp_obj_str_get_data(args->key.u_obj, &key_len);
|
||||
const byte *key = (const byte *)mp_obj_str_get_data(args->key.u_obj, &key_len);
|
||||
// len should include terminating null
|
||||
ret = mbedtls_pk_parse_key(&o->pkey, key, key_len + 1, NULL, 0);
|
||||
assert(ret == 0);
|
||||
|
||||
size_t cert_len;
|
||||
const byte *cert = (const byte*)mp_obj_str_get_data(args->cert.u_obj, &cert_len);
|
||||
const byte *cert = (const byte *)mp_obj_str_get_data(args->cert.u_obj, &cert_len);
|
||||
// len should include terminating null
|
||||
ret = mbedtls_x509_crt_parse(&o->cert, cert, cert_len + 1);
|
||||
assert(ret == 0);
|
||||
@ -215,7 +215,7 @@ STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) {
|
||||
if (!mp_obj_is_true(binary_form)) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
const mbedtls_x509_crt* peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl);
|
||||
const mbedtls_x509_crt *peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl);
|
||||
return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert);
|
||||
@ -290,9 +290,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
#endif
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
|
||||
};
|
||||
|
||||
@ -312,7 +312,7 @@ STATIC const mp_obj_type_t ussl_socket_type = {
|
||||
.getiter = NULL,
|
||||
.iternext = NULL,
|
||||
.protocol = &ussl_socket_stream_p,
|
||||
.locals_dict = (void*)&ussl_socket_locals_dict,
|
||||
.locals_dict = (void *)&ussl_socket_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
@ -329,7 +329,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||
|
||||
struct ssl_args args;
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||
|
||||
return MP_OBJ_FROM_PTR(socket_new(sock, &args));
|
||||
}
|
||||
@ -344,7 +344,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_ussl = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_ssl_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_ssl_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_USSL
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +215,7 @@ STATIC const mp_obj_type_t utimeq_type = {
|
||||
.name = MP_QSTR_utimeq,
|
||||
.make_new = utimeq_make_new,
|
||||
.unary_op = utimeq_unary_op,
|
||||
.locals_dict = (void*)&utimeq_locals_dict,
|
||||
.locals_dict = (void *)&utimeq_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = {
|
||||
@ -224,7 +227,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_utimeq_globals, mp_module_utimeq_globals_t
|
||||
|
||||
const mp_obj_module_t mp_module_utimeq = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_utimeq_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_utimeq_globals,
|
||||
};
|
||||
|
||||
#endif //MICROPY_PY_UTIMEQ
|
||||
#endif // MICROPY_PY_UTIMEQ
|
||||
|
@ -49,9 +49,9 @@ typedef struct _mp_obj_decompio_t {
|
||||
} mp_obj_decompio_t;
|
||||
|
||||
STATIC unsigned char read_src_stream(TINF_DATA *data) {
|
||||
byte *p = (void*)data;
|
||||
byte *p = (void *)data;
|
||||
p -= offsetof(mp_obj_decompio_t, decomp);
|
||||
mp_obj_decompio_t *self = (mp_obj_decompio_t*)p;
|
||||
mp_obj_decompio_t *self = (mp_obj_decompio_t *)p;
|
||||
|
||||
const mp_stream_p_t *stream = mp_get_stream(self->src_stream);
|
||||
int err;
|
||||
@ -91,7 +91,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size
|
||||
} else if (dict_opt >= 0) {
|
||||
dict_opt = uzlib_zlib_parse_header(&o->decomp);
|
||||
if (dict_opt < 0) {
|
||||
header_error:
|
||||
header_error:
|
||||
mp_raise_ValueError("compression header");
|
||||
}
|
||||
dict_sz = 1 << dict_opt;
|
||||
@ -119,7 +119,7 @@ STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
|
||||
*errcode = MP_EINVAL;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
return o->decomp.dest - (byte*)buf;
|
||||
return o->decomp.dest - (byte *)buf;
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
|
||||
@ -139,7 +139,7 @@ STATIC const mp_obj_type_t decompio_type = {
|
||||
.name = MP_QSTR_DecompIO,
|
||||
.make_new = decompio_make_new,
|
||||
.protocol = &decompio_stream_p,
|
||||
.locals_dict = (void*)&decompio_locals_dict,
|
||||
.locals_dict = (void *)&decompio_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
@ -190,13 +190,13 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_uint_t final_sz = decomp->dest - dest_buf;
|
||||
DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
||||
dest_buf = (byte*)m_renew(byte, dest_buf, dest_buf_size, final_sz);
|
||||
dest_buf = (byte *)m_renew(byte, dest_buf, dest_buf_size, final_sz);
|
||||
mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf);
|
||||
m_del_obj(TINF_DATA, decomp);
|
||||
return res;
|
||||
|
||||
error:
|
||||
nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)));
|
||||
nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress);
|
||||
|
||||
@ -210,7 +210,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_tab
|
||||
|
||||
const mp_obj_module_t mp_module_uzlib = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_uzlib_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_uzlib_globals,
|
||||
};
|
||||
|
||||
// Source files #include'd here to make sure they're compiled in
|
||||
|
@ -147,7 +147,7 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
|
||||
open_args[1] = MP_OBJ_NEW_QSTR(MP_QSTR_wb);
|
||||
}
|
||||
|
||||
self->cur_file = mp_builtin_open(2, open_args, (mp_map_t*)&mp_const_empty_map);
|
||||
self->cur_file = mp_builtin_open(2, open_args, (mp_map_t *)&mp_const_empty_map);
|
||||
|
||||
#if 0
|
||||
struct mp_stream_seek_t seek = { .offset = self->hdr.offset, .whence = 0 };
|
||||
@ -181,13 +181,13 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
||||
mp_obj_webrepl_t *self = self_in;
|
||||
const mp_stream_p_t *sock_stream = mp_get_stream(self->sock);
|
||||
mp_uint_t out_sz = sock_stream->read(self->sock, buf, size, errcode);
|
||||
//DEBUG_printf("webrepl: Read %d initial bytes from websocket\n", out_sz);
|
||||
// DEBUG_printf("webrepl: Read %d initial bytes from websocket\n", out_sz);
|
||||
if (out_sz == 0 || out_sz == MP_STREAM_ERROR) {
|
||||
return out_sz;
|
||||
}
|
||||
|
||||
if (self->state == STATE_PASSWD) {
|
||||
char c = *(char*)buf;
|
||||
char c = *(char *)buf;
|
||||
if (c == '\r' || c == '\n') {
|
||||
self->hdr.fname[self->data_to_recv] = 0;
|
||||
DEBUG_printf("webrepl: entered password: %s\n", self->hdr.fname);
|
||||
@ -215,8 +215,8 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
||||
DEBUG_printf("webrepl: received bin data, hdr_to_recv: %d, data_to_recv=%d\n", self->hdr_to_recv, self->data_to_recv);
|
||||
|
||||
if (self->hdr_to_recv != 0) {
|
||||
char *p = (char*)&self->hdr + sizeof(self->hdr) - self->hdr_to_recv;
|
||||
*p++ = *(char*)buf;
|
||||
char *p = (char *)&self->hdr + sizeof(self->hdr) - self->hdr_to_recv;
|
||||
*p++ = *(char *)buf;
|
||||
if (--self->hdr_to_recv != 0) {
|
||||
mp_uint_t hdr_sz = sock_stream->read(self->sock, p, self->hdr_to_recv, errcode);
|
||||
if (hdr_sz == MP_STREAM_ERROR) {
|
||||
@ -237,7 +237,7 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
||||
|
||||
if (self->data_to_recv != 0) {
|
||||
static byte filebuf[512];
|
||||
filebuf[0] = *(byte*)buf;
|
||||
filebuf[0] = *(byte *)buf;
|
||||
mp_uint_t buf_sz = 1;
|
||||
if (--self->data_to_recv != 0) {
|
||||
size_t to_read = MIN(sizeof(filebuf) - 1, self->data_to_recv);
|
||||
@ -340,7 +340,7 @@ STATIC const mp_obj_type_t webrepl_type = {
|
||||
.name = MP_QSTR__webrepl,
|
||||
.make_new = webrepl_make_new,
|
||||
.protocol = &webrepl_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&webrepl_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&webrepl_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = {
|
||||
@ -353,7 +353,7 @@ STATIC MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table
|
||||
|
||||
const mp_obj_module_t mp_module_webrepl = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&webrepl_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&webrepl_module_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_WEBREPL
|
||||
|
@ -71,11 +71,11 @@ STATIC mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
if (n_args > 1 && args[1] == mp_const_true) {
|
||||
o->opts |= BLOCKING_WRITE;
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
const mp_stream_p_t *stream_p = mp_get_stream(self->sock);
|
||||
while (1) {
|
||||
if (self->to_recv != 0) {
|
||||
@ -183,7 +183,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
||||
self->msg_sz -= out_sz;
|
||||
if (self->msg_sz == 0) {
|
||||
byte last_state;
|
||||
no_payload:
|
||||
no_payload:
|
||||
last_state = self->state;
|
||||
self->state = FRAME_HEADER;
|
||||
self->to_recv = 2;
|
||||
@ -200,7 +200,7 @@ no_payload:
|
||||
return 0;
|
||||
}
|
||||
|
||||
//DEBUG_printf("Finished receiving ctrl message %x, ignoring\n", self->last_flags);
|
||||
// DEBUG_printf("Finished receiving ctrl message %x, ignoring\n", self->last_flags);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -217,7 +217,7 @@ no_payload:
|
||||
}
|
||||
|
||||
STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
assert(size < 0x10000);
|
||||
byte header[4] = {0x80 | (self->opts & FRAME_OPCODE_MASK)};
|
||||
int hdr_sz;
|
||||
@ -296,7 +296,7 @@ STATIC const mp_obj_type_t websocket_type = {
|
||||
.name = MP_QSTR_websocket,
|
||||
.make_new = websocket_make_new,
|
||||
.protocol = &websocket_stream_p,
|
||||
.locals_dict = (void*)&websocket_locals_dict,
|
||||
.locals_dict = (void *)&websocket_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = {
|
||||
@ -308,7 +308,7 @@ STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_t
|
||||
|
||||
const mp_obj_module_t mp_module_websocket = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&websocket_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&websocket_module_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_WEBSOCKET
|
||||
|
@ -86,7 +86,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) {
|
||||
// Optimized formula avoiding if conditions. We adjust difference "forward",
|
||||
// wrap it around and adjust back.
|
||||
mp_int_t diff = ((end - start + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
|
||||
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
|
||||
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
|
||||
return MP_OBJ_NEW_SMALL_INT(diff);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj, time_ticks_diff);
|
||||
|
@ -99,7 +99,7 @@ STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) {
|
||||
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
|
||||
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
|
||||
*path_out = mp_obj_new_str_of_type(mp_obj_get_type(path_in),
|
||||
(const byte*)p_out, strlen(p_out));
|
||||
(const byte *)p_out, strlen(p_out));
|
||||
}
|
||||
return vfs;
|
||||
}
|
||||
@ -192,7 +192,7 @@ mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
|
||||
vfs->next = NULL;
|
||||
|
||||
// call the underlying object to do any mounting operation
|
||||
mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args);
|
||||
mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t *)&args);
|
||||
|
||||
// check that the destination mount point is unused
|
||||
const char *path_out;
|
||||
@ -276,7 +276,7 @@ mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
||||
#endif
|
||||
|
||||
mp_vfs_mount_t *vfs = lookup_path(args[ARG_file].u_obj, &args[ARG_file].u_obj);
|
||||
return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t*)&args);
|
||||
return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t *)&args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_vfs_open_obj, 0, mp_vfs_open);
|
||||
|
||||
@ -356,7 +356,7 @@ STATIC mp_obj_t mp_vfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
t->items[0] = mp_obj_new_str_of_type(
|
||||
self->is_str ? &mp_type_str : &mp_type_bytes,
|
||||
(const byte*)vfs->str + 1, vfs->len - 1);
|
||||
(const byte *)vfs->str + 1, vfs->len - 1);
|
||||
t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR);
|
||||
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // no inode number
|
||||
return MP_OBJ_FROM_PTR(t);
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
// return values of mp_vfs_lookup_path
|
||||
// ROOT is 0 so that the default current directory is the root directory
|
||||
#define MP_VFS_NONE ((mp_vfs_mount_t*)1)
|
||||
#define MP_VFS_ROOT ((mp_vfs_mount_t*)0)
|
||||
#define MP_VFS_NONE ((mp_vfs_mount_t *)1)
|
||||
#define MP_VFS_ROOT ((mp_vfs_mount_t *)0)
|
||||
|
||||
// MicroPython's port-standardized versions of stat constants
|
||||
#define MP_S_IFDIR (0x4000)
|
||||
|
@ -148,7 +148,7 @@ STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
if (self->is_str) {
|
||||
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
||||
} else {
|
||||
t->items[0] = mp_obj_new_bytes((const byte*)fn, strlen(fn));
|
||||
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
|
||||
}
|
||||
if (fno.fattrib & AM_DIR) {
|
||||
// dir
|
||||
@ -324,7 +324,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
|
||||
(fno.ftime >> 11) & 0x1f,
|
||||
(fno.ftime >> 5) & 0x3f,
|
||||
2 * (fno.ftime & 0x1f)
|
||||
);
|
||||
);
|
||||
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
|
||||
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
|
||||
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev
|
||||
@ -431,7 +431,7 @@ const mp_obj_type_t mp_fat_vfs_type = {
|
||||
.name = MP_QSTR_VfsFat,
|
||||
.make_new = fat_vfs_make_new,
|
||||
.protocol = &fat_vfs_proto,
|
||||
.locals_dict = (mp_obj_dict_t*)&fat_vfs_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&fat_vfs_locals_dict,
|
||||
|
||||
};
|
||||
|
||||
|
@ -50,32 +50,31 @@
|
||||
|
||||
typedef void *bdev_t;
|
||||
STATIC fs_user_mount_t *disk_get_device(void *bdev) {
|
||||
return (fs_user_mount_t*)bdev;
|
||||
return (fs_user_mount_t *)bdev;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
DRESULT disk_read(
|
||||
bdev_t pdrv, /* Physical drive nmuber (0..) */
|
||||
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;
|
||||
}
|
||||
|
||||
if (vfs->flags & FSUSER_NATIVE) {
|
||||
mp_uint_t (*f)(uint8_t*, uint32_t, uint32_t) = (void*)(uintptr_t)vfs->readblocks[2];
|
||||
mp_uint_t (*f)(uint8_t *, uint32_t, uint32_t) = (void *)(uintptr_t)vfs->readblocks[2];
|
||||
if (f(buff, sector, count) != 0) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
} else {
|
||||
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count * SECSIZE(&vfs->fatfs), buff};
|
||||
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count *SECSIZE(&vfs->fatfs), buff};
|
||||
vfs->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
|
||||
vfs->readblocks[3] = MP_OBJ_FROM_PTR(&ar);
|
||||
mp_call_method_n_kw(2, 0, vfs->readblocks);
|
||||
@ -89,13 +88,12 @@ DRESULT disk_read (
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_write (
|
||||
DRESULT disk_write(
|
||||
bdev_t pdrv, /* Physical drive nmuber (0..) */
|
||||
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;
|
||||
@ -107,12 +105,12 @@ DRESULT disk_write (
|
||||
}
|
||||
|
||||
if (vfs->flags & FSUSER_NATIVE) {
|
||||
mp_uint_t (*f)(const uint8_t*, uint32_t, uint32_t) = (void*)(uintptr_t)vfs->writeblocks[2];
|
||||
mp_uint_t (*f)(const uint8_t *, uint32_t, uint32_t) = (void *)(uintptr_t)vfs->writeblocks[2];
|
||||
if (f(buff, sector, count) != 0) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
} else {
|
||||
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count * SECSIZE(&vfs->fatfs), (void*)buff};
|
||||
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count *SECSIZE(&vfs->fatfs), (void *)buff};
|
||||
vfs->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
|
||||
vfs->writeblocks[3] = MP_OBJ_FROM_PTR(&ar);
|
||||
mp_call_method_n_kw(2, 0, vfs->writeblocks);
|
||||
@ -127,12 +125,11 @@ DRESULT disk_write (
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
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;
|
||||
@ -183,26 +180,26 @@ DRESULT disk_ioctl (
|
||||
return RES_OK;
|
||||
|
||||
case GET_SECTOR_COUNT: {
|
||||
*((DWORD*)buff) = mp_obj_get_int(ret);
|
||||
*((DWORD *)buff) = mp_obj_get_int(ret);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
case GET_SECTOR_SIZE: {
|
||||
if (ret == mp_const_none) {
|
||||
// Default sector size
|
||||
*((WORD*)buff) = 512;
|
||||
*((WORD *)buff) = 512;
|
||||
} else {
|
||||
*((WORD*)buff) = mp_obj_get_int(ret);
|
||||
*((WORD *)buff) = mp_obj_get_int(ret);
|
||||
}
|
||||
#if _MAX_SS != _MIN_SS
|
||||
// need to store ssize because we use it in disk_read/disk_write
|
||||
vfs->fatfs.ssize = *((WORD*)buff);
|
||||
vfs->fatfs.ssize = *((WORD *)buff);
|
||||
#endif
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD*)buff) = 1; // erase block size in units of sector size
|
||||
*((DWORD *)buff) = 1; // erase block size in units of sector size
|
||||
return RES_OK;
|
||||
|
||||
case IOCTL_INIT:
|
||||
@ -216,7 +213,7 @@ DRESULT disk_ioctl (
|
||||
} else {
|
||||
stat = 0;
|
||||
}
|
||||
*((DSTATUS*)buff) = stat;
|
||||
*((DSTATUS *)buff) = stat;
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
|
||||
pyb_file_obj_t *self = MP_OBJ_TO_PTR(o_in);
|
||||
|
||||
if (request == MP_STREAM_SEEK) {
|
||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)(uintptr_t)arg;
|
||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t *)(uintptr_t)arg;
|
||||
|
||||
switch (s->whence) {
|
||||
case 0: // SEEK_SET
|
||||
@ -251,7 +251,7 @@ const mp_obj_type_t mp_type_vfs_fat_fileio = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &fileio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -270,7 +270,7 @@ const mp_obj_type_t mp_type_vfs_fat_textio = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &textio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||
};
|
||||
|
||||
// Factory function for I/O stream classes
|
||||
|
@ -62,7 +62,7 @@ STATIC mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path)
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char*)) {
|
||||
STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char *)) {
|
||||
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
int ret = f(vfs_posix_get_path_str(self, path_in));
|
||||
if (ret != 0) {
|
||||
@ -188,7 +188,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
if (self->is_str) {
|
||||
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
||||
} else {
|
||||
t->items[0] = mp_obj_new_bytes((const byte*)fn, strlen(fn));
|
||||
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
|
||||
}
|
||||
|
||||
#ifdef _DIRENT_HAVE_D_TYPE
|
||||
@ -365,7 +365,7 @@ const mp_obj_type_t mp_type_vfs_posix = {
|
||||
.name = MP_QSTR_VfsPosix,
|
||||
.make_new = vfs_posix_make_new,
|
||||
.protocol = &vfs_posix_proto,
|
||||
.locals_dict = (mp_obj_dict_t*)&vfs_posix_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_locals_dict,
|
||||
};
|
||||
|
||||
#endif // MICROPY_VFS_POSIX
|
||||
|
@ -78,7 +78,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
||||
case '+':
|
||||
mode_rw = O_RDWR;
|
||||
break;
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
// If we don't have io.FileIO, then files are in text mode implicitly
|
||||
case 'b':
|
||||
type = &mp_type_vfs_posix_fileio;
|
||||
@ -86,7 +86,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
||||
case 't':
|
||||
type = &mp_type_vfs_posix_textio;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
|
||||
}
|
||||
return 0;
|
||||
case MP_STREAM_SEEK: {
|
||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
|
||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t *)arg;
|
||||
off_t off = lseek(o->fd, s->offset, s->whence);
|
||||
if (off == (off_t)-1) {
|
||||
*errcode = errno;
|
||||
@ -232,7 +232,7 @@ const mp_obj_type_t mp_type_vfs_posix_fileio = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &fileio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -251,10 +251,10 @@ const mp_obj_type_t mp_type_vfs_posix_textio = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &textio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||
};
|
||||
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_textio}, STDOUT_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_textio}, STDERR_FILENO};
|
||||
|
||||
|
@ -42,7 +42,7 @@ typedef struct _mp_reader_vfs_t {
|
||||
} mp_reader_vfs_t;
|
||||
|
||||
STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) {
|
||||
mp_reader_vfs_t *reader = (mp_reader_vfs_t*)data;
|
||||
mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data;
|
||||
if (reader->pos >= reader->len) {
|
||||
if (reader->len < sizeof(reader->buf)) {
|
||||
return MP_READER_EOF;
|
||||
@ -64,7 +64,7 @@ STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) {
|
||||
}
|
||||
|
||||
STATIC void mp_reader_vfs_close(void *data) {
|
||||
mp_reader_vfs_t *reader = (mp_reader_vfs_t*)data;
|
||||
mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data;
|
||||
mp_stream_close(reader->file);
|
||||
m_del_obj(mp_reader_vfs_t, reader);
|
||||
}
|
||||
@ -72,7 +72,7 @@ STATIC void mp_reader_vfs_close(void *data) {
|
||||
void mp_reader_new_file(mp_reader_t *reader, const char *filename) {
|
||||
mp_reader_vfs_t *rf = m_new_obj(mp_reader_vfs_t);
|
||||
mp_obj_t arg = mp_obj_new_str(filename, strlen(filename));
|
||||
rf->file = mp_vfs_open(1, &arg, (mp_map_t*)&mp_const_empty_map);
|
||||
rf->file = mp_vfs_open(1, &arg, (mp_map_t *)&mp_const_empty_map);
|
||||
int errcode;
|
||||
rf->len = mp_stream_rw(rf->file, rf->buf, sizeof(rf->buf), &errcode, MP_STREAM_RW_READ | MP_STREAM_RW_ONCE);
|
||||
if (errcode != 0) {
|
||||
|
@ -27,13 +27,13 @@
|
||||
#include "extmod/virtpin.h"
|
||||
|
||||
int mp_virtual_pin_read(mp_obj_t pin) {
|
||||
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
|
||||
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->protocol;
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(pin);
|
||||
mp_pin_p_t *pin_p = (mp_pin_p_t *)s->type->protocol;
|
||||
return pin_p->ioctl(pin, MP_PIN_READ, 0, NULL);
|
||||
}
|
||||
|
||||
void mp_virtual_pin_write(mp_obj_t pin, int value) {
|
||||
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
|
||||
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->protocol;
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(pin);
|
||||
mp_pin_p_t *pin_p = (mp_pin_p_t *)s->type->protocol;
|
||||
pin_p->ioctl(pin, MP_PIN_WRITE, value, NULL);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ void netutils_parse_ipv4_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian
|
||||
}
|
||||
const char *s = addr_str;
|
||||
const char *s_top = addr_str + addr_len;
|
||||
for (mp_uint_t i = 3 ; ; i--) {
|
||||
for (mp_uint_t i = 3; ; i--) {
|
||||
mp_uint_t val = 0;
|
||||
for (; s < s_top && *s != '.'; s++) {
|
||||
val = val * 10 + *s - '0';
|
||||
|
@ -36,11 +36,11 @@
|
||||
|
||||
#define LEAPOCH ((31 + 29) * 86400)
|
||||
|
||||
#define DAYS_PER_400Y (365*400 + 97)
|
||||
#define DAYS_PER_100Y (365*100 + 24)
|
||||
#define DAYS_PER_4Y (365*4 + 1)
|
||||
#define DAYS_PER_400Y (365 * 400 + 97)
|
||||
#define DAYS_PER_100Y (365 * 100 + 24)
|
||||
#define DAYS_PER_4Y (365 * 4 + 1)
|
||||
|
||||
STATIC const uint16_t days_since_jan1[]= { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||
STATIC const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||
|
||||
bool timeutils_is_leap_year(mp_uint_t year) {
|
||||
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
|
||||
|
@ -28,14 +28,14 @@
|
||||
#define MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H
|
||||
|
||||
typedef struct _timeutils_struct_time_t {
|
||||
uint16_t tm_year; // i.e. 2014
|
||||
uint8_t tm_mon; // 1..12
|
||||
uint8_t tm_mday; // 1..31
|
||||
uint8_t tm_hour; // 0..23
|
||||
uint8_t tm_min; // 0..59
|
||||
uint8_t tm_sec; // 0..59
|
||||
uint8_t tm_wday; // 0..6 0 = Monday
|
||||
uint16_t tm_yday; // 1..366
|
||||
uint16_t tm_year; // i.e. 2014
|
||||
uint8_t tm_mon; // 1..12
|
||||
uint8_t tm_mday; // 1..31
|
||||
uint8_t tm_hour; // 0..23
|
||||
uint8_t tm_min; // 0..59
|
||||
uint8_t tm_sec; // 0..59
|
||||
uint8_t tm_wday; // 0..6 0 = Monday
|
||||
uint16_t tm_yday; // 1..366
|
||||
} timeutils_struct_time_t;
|
||||
|
||||
bool timeutils_is_leap_year(mp_uint_t year);
|
||||
|
@ -52,7 +52,7 @@ const mp_arg_t mp_irq_init_args[] = {
|
||||
mp_irq_obj_t *mp_irq_new(const mp_irq_methods_t *methods, mp_obj_t parent) {
|
||||
mp_irq_obj_t *self = m_new0(mp_irq_obj_t, 1);
|
||||
self->base.type = &mp_irq_type;
|
||||
self->methods = (mp_irq_methods_t*)methods;
|
||||
self->methods = (mp_irq_methods_t *)methods;
|
||||
self->parent = parent;
|
||||
self->handler = mp_const_none;
|
||||
self->ishard = false;
|
||||
@ -120,5 +120,5 @@ const mp_obj_type_t mp_irq_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_irq,
|
||||
.call = mp_irq_call,
|
||||
.locals_dict = (mp_obj_dict_t*)&mp_irq_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&mp_irq_locals_dict,
|
||||
};
|
||||
|
@ -102,7 +102,7 @@ STATIC void strn_print_strn(void *data, const char *str, size_t len) {
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
// uClibc requires this alias to be defined, or there may be link errors
|
||||
// when linkings against it statically.
|
||||
int __GI_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __attribute__((weak, alias ("vsnprintf")));
|
||||
int __GI_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __attribute__((weak, alias("vsnprintf")));
|
||||
#endif
|
||||
|
||||
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) {
|
||||
@ -128,4 +128,4 @@ int snprintf(char *str, size_t size, const char *fmt, ...) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif //MICROPY_USE_INTERNAL_PRINTF
|
||||
#endif // MICROPY_USE_INTERNAL_PRINTF
|
||||
|
@ -84,7 +84,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
||||
} else if (exec_flags & EXEC_FLAG_SOURCE_IS_FILENAME) {
|
||||
lex = mp_lexer_new_from_file(source);
|
||||
} else {
|
||||
lex = (mp_lexer_t*)source;
|
||||
lex = (mp_lexer_t *)source;
|
||||
}
|
||||
// source is a lexer, parse and compile the script
|
||||
qstr source_name = lex->source_name;
|
||||
@ -114,7 +114,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
||||
mp_hal_stdout_tx_strn("\x04", 1);
|
||||
}
|
||||
// check for SystemExit
|
||||
if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t*)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
|
||||
if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
|
||||
// at the moment, the value of SystemExit is unused
|
||||
ret = pyexec_system_exit;
|
||||
} else {
|
||||
@ -132,8 +132,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
||||
size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
|
||||
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
|
||||
printf("qstr:\n n_pool=%u\n n_qstr=%u\n "
|
||||
"n_str_data_bytes=%u\n n_total_bytes=%u\n",
|
||||
(unsigned)n_pool, (unsigned)n_qstr, (unsigned)n_str_data_bytes, (unsigned)n_total_bytes);
|
||||
"n_str_data_bytes=%u\n n_total_bytes=%u\n",
|
||||
(unsigned)n_pool, (unsigned)n_qstr, (unsigned)n_str_data_bytes, (unsigned)n_total_bytes);
|
||||
}
|
||||
|
||||
#if MICROPY_ENABLE_GC
|
||||
@ -158,7 +158,7 @@ typedef struct _repl_t {
|
||||
// but it was moved to MP_STATE_VM(repl_line) as containing
|
||||
// root pointer. Still keep structure in case more state
|
||||
// will be added later.
|
||||
//vstr_t line;
|
||||
// vstr_t line;
|
||||
bool cont_line;
|
||||
} repl_t;
|
||||
|
||||
@ -271,10 +271,10 @@ STATIC int pyexec_friendly_repl_process_char(int c) {
|
||||
} else {
|
||||
|
||||
if (ret == CHAR_CTRL_C) {
|
||||
// cancel everything
|
||||
mp_hal_stdout_tx_str("\r\n");
|
||||
repl.cont_line = false;
|
||||
goto input_restart;
|
||||
// cancel everything
|
||||
mp_hal_stdout_tx_str("\r\n");
|
||||
repl.cont_line = false;
|
||||
goto input_restart;
|
||||
} else if (ret == CHAR_CTRL_D) {
|
||||
// stop entering compound statement
|
||||
goto exec;
|
||||
@ -290,13 +290,13 @@ STATIC int pyexec_friendly_repl_process_char(int c) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
exec: ;
|
||||
exec:;
|
||||
int ret = parse_compile_execute(MP_STATE_VM(repl_line), MP_PARSE_SINGLE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL | EXEC_FLAG_SOURCE_IS_VSTR);
|
||||
if (ret & PYEXEC_FORCED_EXIT) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
input_restart:
|
||||
input_restart:
|
||||
vstr_reset(MP_STATE_VM(repl_line));
|
||||
repl.cont_line = false;
|
||||
readline_init(MP_STATE_VM(repl_line), ">>> ");
|
||||
@ -373,11 +373,11 @@ int pyexec_friendly_repl(void) {
|
||||
vstr_t line;
|
||||
vstr_init(&line, 32);
|
||||
|
||||
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
|
||||
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
|
||||
// in host mode, we enable the LCD for the repl
|
||||
mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD")));
|
||||
mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
friendly_repl_reset:
|
||||
mp_hal_stdout_tx_str("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n");
|
||||
|
@ -65,7 +65,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er
|
||||
if (c == '\r') {
|
||||
c = '\n';
|
||||
}
|
||||
((byte*)buf)[i] = c;
|
||||
((byte *)buf)[i] = c;
|
||||
}
|
||||
return size;
|
||||
} else {
|
||||
@ -93,9 +93,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stdio_obj___exit___obj, 4, 4, stdio_o
|
||||
// TODO gc hook to close the file if not already closed
|
||||
|
||||
STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = {
|
||||
#if MICROPY_PY_SYS_STDIO_BUFFER
|
||||
#if MICROPY_PY_SYS_STDIO_BUFFER
|
||||
{ MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) },
|
||||
#endif
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj)},
|
||||
@ -123,7 +123,7 @@ STATIC const mp_obj_type_t stdio_obj_type = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stdio_obj_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&stdio_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&stdio_locals_dict,
|
||||
};
|
||||
|
||||
const sys_stdio_obj_t mp_sys_stdin_obj = {{&stdio_obj_type}, .fd = STDIO_FD_IN};
|
||||
@ -133,7 +133,7 @@ const sys_stdio_obj_t mp_sys_stderr_obj = {{&stdio_obj_type}, .fd = STDIO_FD_ERR
|
||||
#if MICROPY_PY_SYS_STDIO_BUFFER
|
||||
STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
for (uint i = 0; i < size; i++) {
|
||||
((byte*)buf)[i] = mp_hal_stdin_rx_chr();
|
||||
((byte *)buf)[i] = mp_hal_stdin_rx_chr();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
@ -156,7 +156,7 @@ STATIC const mp_obj_type_t stdio_buffer_obj_type = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stdio_buffer_obj_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&stdio_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&stdio_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@
|
||||
|
||||
// type definitions for the specific machine
|
||||
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
|
||||
|
||||
#define UINT_FMT "%lu"
|
||||
#define INT_FMT "%ld"
|
||||
|
@ -68,7 +68,7 @@ DWORD get_fattime(void) {
|
||||
timeutils_struct_time_t tm;
|
||||
timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm);
|
||||
|
||||
return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) |
|
||||
((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) |
|
||||
((tm.tm_min) << 5) | (tm.tm_sec >> 1);
|
||||
return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) |
|
||||
((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) |
|
||||
((tm.tm_min) << 5) | (tm.tm_sec >> 1);
|
||||
}
|
||||
|
@ -51,57 +51,58 @@
|
||||
******************************************************************************/
|
||||
|
||||
// This is the static memory (TCB and stack) for the idle task
|
||||
static StaticTask_t xIdleTaskTCB __attribute__ ((section (".rtos_heap")));
|
||||
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
|
||||
static StaticTask_t xIdleTaskTCB __attribute__ ((section(".rtos_heap")));
|
||||
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE] __attribute__ ((section(".rtos_heap"))) __attribute__((aligned(8)));
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC DATA
|
||||
******************************************************************************/
|
||||
#ifdef DEBUG
|
||||
OsiTaskHandle mpTaskHandle;
|
||||
OsiTaskHandle mpTaskHandle;
|
||||
#endif
|
||||
|
||||
// This is the FreeRTOS heap, defined here so we can put it in a special segment
|
||||
uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
|
||||
uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section(".rtos_heap"))) __attribute__((aligned(8)));
|
||||
|
||||
// This is the static memory (TCB and stack) for the main MicroPython task
|
||||
StaticTask_t mpTaskTCB __attribute__ ((section (".rtos_heap")));
|
||||
StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
|
||||
StaticTask_t mpTaskTCB __attribute__ ((section(".rtos_heap")));
|
||||
StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__ ((section(".rtos_heap"))) __attribute__((aligned(8)));
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
__attribute__ ((section (".boot")))
|
||||
int main (void) {
|
||||
__attribute__ ((section(".boot")))
|
||||
int main(void) {
|
||||
|
||||
// Initialize the clocks and the interrupt system
|
||||
HAL_SystemInit();
|
||||
|
||||
#if MICROPY_HW_ANTENNA_DIVERSITY
|
||||
#if MICROPY_HW_ANTENNA_DIVERSITY
|
||||
// configure the antenna selection pins
|
||||
antenna_init0();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Init the watchdog
|
||||
pybwdt_init0();
|
||||
|
||||
#ifndef DEBUG
|
||||
#ifndef DEBUG
|
||||
OsiTaskHandle mpTaskHandle;
|
||||
#endif
|
||||
#endif
|
||||
mpTaskHandle = xTaskCreateStatic(TASK_MicroPython, "MicroPy",
|
||||
MICROPY_TASK_STACK_LEN, NULL, MICROPY_TASK_PRIORITY, mpTaskStack, &mpTaskTCB);
|
||||
ASSERT(mpTaskHandle != NULL);
|
||||
|
||||
osi_start();
|
||||
|
||||
for ( ; ; );
|
||||
for ( ; ;) {;
|
||||
}
|
||||
}
|
||||
|
||||
// We need this when configSUPPORT_STATIC_ALLOCATION is enabled
|
||||
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
|
||||
StackType_t **ppxIdleTaskStackBuffer,
|
||||
uint32_t *pulIdleTaskStackSize ) {
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
||||
StackType_t **ppxIdleTaskStackBuffer,
|
||||
uint32_t *pulIdleTaskStackSize) {
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
|
||||
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
|
||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
|
@ -199,15 +199,15 @@ extern const struct _mp_obj_module_t mp_module_ussl;
|
||||
|
||||
|
||||
// type definitions for the specific machine
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
|
||||
#define MP_SSIZE_MAX (0x7FFFFFFF)
|
||||
|
||||
#define UINT_FMT "%u"
|
||||
#define INT_FMT "%d"
|
||||
|
||||
typedef int32_t mp_int_t; // must be pointer size
|
||||
typedef unsigned int mp_uint_t; // must be pointer size
|
||||
typedef long mp_off_t;
|
||||
typedef int32_t mp_int_t; // must be pointer size
|
||||
typedef unsigned int mp_uint_t; // must be pointer size
|
||||
typedef long mp_off_t;
|
||||
|
||||
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
|
||||
|
||||
|
@ -81,16 +81,16 @@
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void mptask_pre_init (void);
|
||||
STATIC void mptask_init_sflash_filesystem (void);
|
||||
STATIC void mptask_enter_ap_mode (void);
|
||||
STATIC void mptask_create_main_py (void);
|
||||
STATIC void mptask_pre_init(void);
|
||||
STATIC void mptask_init_sflash_filesystem(void);
|
||||
STATIC void mptask_enter_ap_mode(void);
|
||||
STATIC void mptask_create_main_py(void);
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC DATA
|
||||
******************************************************************************/
|
||||
#ifdef DEBUG
|
||||
OsiTaskHandle svTaskHandle;
|
||||
OsiTaskHandle svTaskHandle;
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
@ -100,27 +100,27 @@ static fs_user_mount_t *sflash_vfs_fat;
|
||||
|
||||
static const char fresh_main_py[] = "# main.py -- put your code here!\r\n";
|
||||
static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n"
|
||||
"# can run arbitrary Python, but best to keep it minimal\r\n"
|
||||
"# can run arbitrary Python, but best to keep it minimal\r\n"
|
||||
#if MICROPY_STDIO_UART
|
||||
"import os, machine\r\n"
|
||||
"os.dupterm(machine.UART(0, " MP_STRINGIFY(MICROPY_STDIO_UART_BAUD) "))\r\n"
|
||||
"import os, machine\r\n"
|
||||
"os.dupterm(machine.UART(0, " MP_STRINGIFY(MICROPY_STDIO_UART_BAUD) "))\r\n"
|
||||
#endif
|
||||
;
|
||||
;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
void TASK_MicroPython (void *pvParameters) {
|
||||
void TASK_MicroPython(void *pvParameters) {
|
||||
// get the top of the stack to initialize the garbage collector
|
||||
uint32_t sp = gc_helper_get_sp();
|
||||
|
||||
bool safeboot = false;
|
||||
mptask_pre_init();
|
||||
|
||||
#ifndef DEBUG
|
||||
#ifndef DEBUG
|
||||
safeboot = PRCMGetSpecialBit(PRCM_SAFE_BOOT_BIT);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
soft_reset:
|
||||
|
||||
@ -130,7 +130,7 @@ soft_reset:
|
||||
#endif
|
||||
|
||||
// initialise the stack pointer for the main thread (must be done after mp_thread_init)
|
||||
mp_stack_set_top((void*)sp);
|
||||
mp_stack_set_top((void *)sp);
|
||||
|
||||
// GC init
|
||||
gc_init(&_boot, &_eheap);
|
||||
@ -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();
|
||||
}
|
||||
@ -218,7 +217,7 @@ soft_reset:
|
||||
|
||||
// main script is finished, so now go into REPL mode.
|
||||
// the REPL mode can change, or it can request a soft reset.
|
||||
for ( ; ; ) {
|
||||
for ( ; ;) {
|
||||
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
|
||||
if (pyexec_raw_repl() != 0) {
|
||||
break;
|
||||
@ -261,16 +260,16 @@ soft_reset_exit:
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
__attribute__ ((section (".boot")))
|
||||
STATIC void mptask_pre_init (void) {
|
||||
__attribute__ ((section(".boot")))
|
||||
STATIC void mptask_pre_init(void) {
|
||||
// this one only makes sense after a poweron reset
|
||||
pyb_rtc_pre_init();
|
||||
|
||||
// Create the simple link spawn task
|
||||
ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));
|
||||
ASSERT(OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));
|
||||
|
||||
// Allocate memory for the flash file system
|
||||
ASSERT ((sflash_vfs_fat = mem_Malloc(sizeof(*sflash_vfs_fat))) != NULL);
|
||||
ASSERT((sflash_vfs_fat = mem_Malloc(sizeof(*sflash_vfs_fat))) != NULL);
|
||||
|
||||
// this one allocates memory for the nvic vault
|
||||
pyb_sleep_pre_init();
|
||||
@ -284,17 +283,17 @@ STATIC void mptask_pre_init (void) {
|
||||
// this one allocates memory for the socket semaphore
|
||||
modusocket_pre_init();
|
||||
|
||||
//CRYPTOHASH_Init();
|
||||
// CRYPTOHASH_Init();
|
||||
|
||||
#ifndef DEBUG
|
||||
#ifndef DEBUG
|
||||
OsiTaskHandle svTaskHandle;
|
||||
#endif
|
||||
#endif
|
||||
svTaskHandle = xTaskCreateStatic(TASK_Servers, "Servers",
|
||||
SERVERS_STACK_LEN, NULL, SERVERS_PRIORITY, svTaskStack, &svTaskTCB);
|
||||
ASSERT(svTaskHandle != NULL);
|
||||
}
|
||||
|
||||
STATIC void mptask_init_sflash_filesystem (void) {
|
||||
STATIC void mptask_init_sflash_filesystem(void) {
|
||||
FILINFO fno;
|
||||
|
||||
// Initialise the local flash filesystem.
|
||||
@ -377,16 +376,16 @@ STATIC void mptask_init_sflash_filesystem (void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mptask_enter_ap_mode (void) {
|
||||
STATIC void mptask_enter_ap_mode(void) {
|
||||
// append the mac only if it's not the first boot
|
||||
bool add_mac = !PRCMGetSpecialBit(PRCM_FIRST_BOOT_BIT);
|
||||
// enable simplelink in ap mode (use the MAC address to make the ssid unique)
|
||||
wlan_sl_init (ROLE_AP, MICROPY_PORT_WLAN_AP_SSID, strlen(MICROPY_PORT_WLAN_AP_SSID),
|
||||
MICROPY_PORT_WLAN_AP_SECURITY, MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY),
|
||||
MICROPY_PORT_WLAN_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, add_mac);
|
||||
wlan_sl_init(ROLE_AP, MICROPY_PORT_WLAN_AP_SSID, strlen(MICROPY_PORT_WLAN_AP_SSID),
|
||||
MICROPY_PORT_WLAN_AP_SECURITY, MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY),
|
||||
MICROPY_PORT_WLAN_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, add_mac);
|
||||
}
|
||||
|
||||
STATIC void mptask_create_main_py (void) {
|
||||
STATIC void mptask_create_main_py(void) {
|
||||
// create empty main.py
|
||||
FIL fp;
|
||||
f_open(&sflash_vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS);
|
||||
|
@ -41,6 +41,6 @@ extern StackType_t mpTaskStack[];
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
extern void TASK_MicroPython (void *pvParameters);
|
||||
extern void TASK_MicroPython(void *pvParameters);
|
||||
|
||||
#endif // MICROPY_INCLUDED_CC3200_MPTASK_H
|
||||
|
@ -68,7 +68,7 @@ void mp_thread_init(void) {
|
||||
void mp_thread_gc_others(void) {
|
||||
mp_thread_mutex_lock(&thread_mutex, 1);
|
||||
for (thread_t *th = thread; th != NULL; th = th->next) {
|
||||
gc_collect_root((void**)&th, 1);
|
||||
gc_collect_root((void **)&th, 1);
|
||||
gc_collect_root(&th->arg, 1); // probably not needed
|
||||
if (th->id == xTaskGetCurrentTaskHandle()) {
|
||||
continue;
|
||||
@ -100,7 +100,7 @@ void mp_thread_start(void) {
|
||||
mp_thread_mutex_unlock(&thread_mutex);
|
||||
}
|
||||
|
||||
STATIC void *(*ext_thread_entry)(void*) = NULL;
|
||||
STATIC void *(*ext_thread_entry)(void *) = NULL;
|
||||
|
||||
STATIC void freertos_entry(void *arg) {
|
||||
if (ext_thread_entry) {
|
||||
@ -111,7 +111,7 @@ STATIC void freertos_entry(void *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
|
||||
void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
|
||||
// store thread entry function into a global variable so we can access it
|
||||
ext_thread_entry = entry;
|
||||
|
||||
@ -129,7 +129,7 @@ void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
|
||||
mp_thread_mutex_lock(&thread_mutex, 1);
|
||||
|
||||
// create thread
|
||||
TaskHandle_t id = xTaskCreateStatic(freertos_entry, "Thread", *stack_size / sizeof(void*), arg, 2, stack, tcb);
|
||||
TaskHandle_t id = xTaskCreateStatic(freertos_entry, "Thread", *stack_size / sizeof(void *), arg, 2, stack, tcb);
|
||||
if (id == NULL) {
|
||||
mp_thread_mutex_unlock(&thread_mutex);
|
||||
mp_raise_msg(&mp_type_OSError, "can't create thread");
|
||||
|
@ -28,5 +28,5 @@
|
||||
// for machine module
|
||||
Q(/)
|
||||
// entries for sys.path
|
||||
Q(/flash)
|
||||
Q(/flash/lib)
|
||||
Q(/ flash)
|
||||
Q(/ flash / lib)
|
||||
|
@ -69,8 +69,8 @@ static volatile bool sleep_sockets = false;
|
||||
******************************************************************************/
|
||||
|
||||
// This is the static memory (TCB and stack) for the servers task
|
||||
StaticTask_t svTaskTCB __attribute__ ((section (".rtos_heap")));
|
||||
StackType_t svTaskStack[SERVERS_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
|
||||
StaticTask_t svTaskTCB __attribute__ ((section(".rtos_heap")));
|
||||
StackType_t svTaskStack[SERVERS_STACK_LEN] __attribute__ ((section(".rtos_heap"))) __attribute__((aligned(8)));
|
||||
|
||||
char servers_user[SERVERS_USER_PASS_LEN_MAX + 1];
|
||||
char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1];
|
||||
@ -78,17 +78,17 @@ char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1];
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
void TASK_Servers (void *pvParameters) {
|
||||
void TASK_Servers(void *pvParameters) {
|
||||
|
||||
bool cycle = false;
|
||||
|
||||
strcpy (servers_user, SERVERS_DEF_USER);
|
||||
strcpy (servers_pass, SERVERS_DEF_PASS);
|
||||
strcpy(servers_user, SERVERS_DEF_USER);
|
||||
strcpy(servers_pass, SERVERS_DEF_PASS);
|
||||
|
||||
telnet_init();
|
||||
ftp_init();
|
||||
|
||||
for ( ;; ) {
|
||||
for ( ;;) {
|
||||
|
||||
if (servers_data.do_enable) {
|
||||
// enable network services
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -147,12 +144,12 @@ void TASK_Servers (void *pvParameters) {
|
||||
}
|
||||
}
|
||||
|
||||
void servers_start (void) {
|
||||
void servers_start(void) {
|
||||
servers_data.do_enable = true;
|
||||
mp_hal_delay_ms(SERVERS_CYCLE_TIME_MS * 3);
|
||||
}
|
||||
|
||||
void servers_stop (void) {
|
||||
void servers_stop(void) {
|
||||
servers_data.do_disable = true;
|
||||
do {
|
||||
mp_hal_delay_ms(SERVERS_CYCLE_TIME_MS);
|
||||
@ -160,24 +157,24 @@ void servers_stop (void) {
|
||||
mp_hal_delay_ms(SERVERS_CYCLE_TIME_MS * 3);
|
||||
}
|
||||
|
||||
void servers_reset (void) {
|
||||
void servers_reset(void) {
|
||||
servers_data.do_reset = true;
|
||||
}
|
||||
|
||||
void servers_wlan_cycle_power (void) {
|
||||
void servers_wlan_cycle_power(void) {
|
||||
servers_data.do_wlan_cycle_power = true;
|
||||
}
|
||||
|
||||
bool servers_are_enabled (void) {
|
||||
bool servers_are_enabled(void) {
|
||||
return servers_data.enabled;
|
||||
}
|
||||
|
||||
void server_sleep_sockets (void) {
|
||||
void server_sleep_sockets(void) {
|
||||
sleep_sockets = true;
|
||||
mp_hal_delay_ms(SERVERS_CYCLE_TIME_MS + 1);
|
||||
}
|
||||
|
||||
void servers_close_socket (int16_t *sd) {
|
||||
void servers_close_socket(int16_t *sd) {
|
||||
if (*sd > 0) {
|
||||
modusocket_socket_delete(*sd);
|
||||
sl_Close(*sd);
|
||||
@ -185,7 +182,7 @@ void servers_close_socket (int16_t *sd) {
|
||||
}
|
||||
}
|
||||
|
||||
void servers_set_login (char *user, char *pass) {
|
||||
void servers_set_login(char *user, char *pass) {
|
||||
if (strlen(user) > SERVERS_USER_PASS_LEN_MAX || strlen(pass) > SERVERS_USER_PASS_LEN_MAX) {
|
||||
mp_raise_ValueError(mpexception_value_invalid_arguments);
|
||||
}
|
||||
@ -193,7 +190,7 @@ void servers_set_login (char *user, char *pass) {
|
||||
memcpy(servers_pass, pass, SERVERS_USER_PASS_LEN_MAX);
|
||||
}
|
||||
|
||||
void servers_set_timeout (uint32_t timeout) {
|
||||
void servers_set_timeout(uint32_t timeout) {
|
||||
if (timeout < SERVERS_MIN_TIMEOUT_MS) {
|
||||
// timeout is too low
|
||||
mp_raise_ValueError(mpexception_value_invalid_arguments);
|
||||
@ -201,7 +198,7 @@ void servers_set_timeout (uint32_t timeout) {
|
||||
servers_data.timeout = timeout;
|
||||
}
|
||||
|
||||
uint32_t servers_get_timeout (void) {
|
||||
uint32_t servers_get_timeout(void) {
|
||||
return servers_data.timeout;
|
||||
}
|
||||
|
||||
|
@ -60,16 +60,16 @@ extern char servers_pass[];
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
extern void TASK_Servers (void *pvParameters);
|
||||
extern void servers_start (void);
|
||||
extern void servers_stop (void);
|
||||
extern void servers_reset (void);
|
||||
extern void servers_wlan_cycle_power (void);
|
||||
extern bool servers_are_enabled (void);
|
||||
extern void servers_close_socket (int16_t *sd);
|
||||
extern void servers_set_login (char *user, char *pass);
|
||||
extern void server_sleep_sockets (void);
|
||||
extern void servers_set_timeout (uint32_t timeout);
|
||||
extern uint32_t servers_get_timeout (void);
|
||||
extern void TASK_Servers(void *pvParameters);
|
||||
extern void servers_start(void);
|
||||
extern void servers_stop(void);
|
||||
extern void servers_reset(void);
|
||||
extern void servers_wlan_cycle_power(void);
|
||||
extern bool servers_are_enabled(void);
|
||||
extern void servers_close_socket(int16_t *sd);
|
||||
extern void servers_set_login(char *user, char *pass);
|
||||
extern void server_sleep_sockets(void);
|
||||
extern void servers_set_timeout(uint32_t timeout);
|
||||
extern uint32_t servers_get_timeout(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_CC3200_SERVERSTASK_H
|
||||
|
@ -12,55 +12,58 @@ 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):
|
||||
|
||||
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):
|
||||
|
||||
def test_pin_shorts(pull):
|
||||
if pull == Pin.PULL_UP:
|
||||
pull_inverted = Pin.PULL_DOWN
|
||||
else:
|
||||
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
|
||||
@ -72,5 +75,4 @@ time1 = rtc.now()
|
||||
time.sleep_ms(1000)
|
||||
time2 = rtc.now()
|
||||
print(time2[5] - time1[5] == 1)
|
||||
print(time2[6] - time1[6] < 5000) # microseconds
|
||||
|
||||
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'):
|
||||
print ("Entered '/flash/sys' directory")
|
||||
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,9 +116,9 @@ def reset_board(args):
|
||||
|
||||
def verify_update(args):
|
||||
success = False
|
||||
firmware_tag = ''
|
||||
firmware_tag = ""
|
||||
|
||||
def find_tag (tag):
|
||||
def find_tag(tag):
|
||||
if tag in firmware_tag:
|
||||
print("Verification passed")
|
||||
return True
|
||||
@ -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)
|
||||
|
@ -1,31 +1,31 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Daniel Campora
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef MICROPY_INCLUDED_CC3200_VERSION_H
|
||||
#define MICROPY_INCLUDED_CC3200_VERSION_H
|
||||
|
||||
#define WIPY_SW_VERSION_NUMBER "1.2.0"
|
||||
|
||||
#endif // MICROPY_INCLUDED_CC3200_VERSION_H
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Daniel Campora
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef MICROPY_INCLUDED_CC3200_VERSION_H
|
||||
#define MICROPY_INCLUDED_CC3200_VERSION_H
|
||||
|
||||
#define WIPY_SW_VERSION_NUMBER "1.2.0"
|
||||
|
||||
#endif // MICROPY_INCLUDED_CC3200_VERSION_H
|
||||
|
@ -51,7 +51,7 @@ STATIC mp_obj_t esp32_ulp_set_wakeup_period(mp_obj_t self_in, mp_obj_t period_in
|
||||
mp_uint_t period_us = mp_obj_get_int(period_us_in);
|
||||
int _errno = ulp_set_wakeup_period(period_index, period_us);
|
||||
if (_errno != ESP_OK) {
|
||||
mp_raise_OSError(_errno);
|
||||
mp_raise_OSError(_errno);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -63,9 +63,9 @@ STATIC mp_obj_t esp32_ulp_load_binary(mp_obj_t self_in, mp_obj_t load_addr_in, m
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ);
|
||||
|
||||
int _errno = ulp_load_binary(load_addr, bufinfo.buf, bufinfo.len/sizeof(uint32_t));
|
||||
int _errno = ulp_load_binary(load_addr, bufinfo.buf, bufinfo.len / sizeof(uint32_t));
|
||||
if (_errno != ESP_OK) {
|
||||
mp_raise_OSError(_errno);
|
||||
mp_raise_OSError(_errno);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -73,9 +73,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_ulp_load_binary_obj, esp32_ulp_load_binar
|
||||
|
||||
STATIC mp_obj_t esp32_ulp_run(mp_obj_t self_in, mp_obj_t entry_point_in) {
|
||||
mp_uint_t entry_point = mp_obj_get_int(entry_point_in);
|
||||
int _errno = ulp_run(entry_point/sizeof(uint32_t));
|
||||
int _errno = ulp_run(entry_point / sizeof(uint32_t));
|
||||
if (_errno != ESP_OK) {
|
||||
mp_raise_OSError(_errno);
|
||||
mp_raise_OSError(_errno);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ void IRAM_ATTR esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numByte
|
||||
uint8_t *p, *end, pix, mask;
|
||||
uint32_t t, time0, time1, period, c, startTime, pinMask;
|
||||
|
||||
pinMask = 1 << pin;
|
||||
p = pixels;
|
||||
end = p + numBytes;
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
pinMask = 1 << pin;
|
||||
p = pixels;
|
||||
end = p + numBytes;
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
startTime = 0;
|
||||
|
||||
uint32_t fcpu = ets_get_cpu_frequency() * 1000000;
|
||||
@ -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;
|
||||
pix = *p++;
|
||||
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);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ static void gc_collect_inner(int level) {
|
||||
if (level == XCHAL_NUM_AREGS / 8) {
|
||||
// get the sp
|
||||
volatile uint32_t sp = (uint32_t)get_sp();
|
||||
gc_collect_root((void**)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t));
|
||||
gc_collect_root((void **)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -29,37 +29,37 @@
|
||||
#include "py/builtin.h"
|
||||
|
||||
const char esp32_help_text[] =
|
||||
"Welcome to MicroPython on the ESP32!\n"
|
||||
"\n"
|
||||
"For generic online docs please visit http://docs.micropython.org/\n"
|
||||
"\n"
|
||||
"For access to the hardware use the 'machine' module:\n"
|
||||
"\n"
|
||||
"import machine\n"
|
||||
"pin12 = machine.Pin(12, machine.Pin.OUT)\n"
|
||||
"pin12.value(1)\n"
|
||||
"pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)\n"
|
||||
"print(pin13.value())\n"
|
||||
"i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))\n"
|
||||
"i2c.scan()\n"
|
||||
"i2c.writeto(addr, b'1234')\n"
|
||||
"i2c.readfrom(addr, 4)\n"
|
||||
"\n"
|
||||
"Basic WiFi configuration:\n"
|
||||
"\n"
|
||||
"import network\n"
|
||||
"sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
|
||||
"sta_if.scan() # Scan for available access points\n"
|
||||
"sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
|
||||
"sta_if.isconnected() # Check for successful connection\n"
|
||||
"\n"
|
||||
"Control commands:\n"
|
||||
" CTRL-A -- on a blank line, enter raw REPL mode\n"
|
||||
" CTRL-B -- on a blank line, enter normal REPL mode\n"
|
||||
" CTRL-C -- interrupt a running program\n"
|
||||
" CTRL-D -- on a blank line, do a soft reset of the board\n"
|
||||
" CTRL-E -- on a blank line, enter paste mode\n"
|
||||
"\n"
|
||||
"For further help on a specific object, type help(obj)\n"
|
||||
"For a list of available modules, type help('modules')\n"
|
||||
"Welcome to MicroPython on the ESP32!\n"
|
||||
"\n"
|
||||
"For generic online docs please visit http://docs.micropython.org/\n"
|
||||
"\n"
|
||||
"For access to the hardware use the 'machine' module:\n"
|
||||
"\n"
|
||||
"import machine\n"
|
||||
"pin12 = machine.Pin(12, machine.Pin.OUT)\n"
|
||||
"pin12.value(1)\n"
|
||||
"pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)\n"
|
||||
"print(pin13.value())\n"
|
||||
"i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))\n"
|
||||
"i2c.scan()\n"
|
||||
"i2c.writeto(addr, b'1234')\n"
|
||||
"i2c.readfrom(addr, 4)\n"
|
||||
"\n"
|
||||
"Basic WiFi configuration:\n"
|
||||
"\n"
|
||||
"import network\n"
|
||||
"sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
|
||||
"sta_if.scan() # Scan for available access points\n"
|
||||
"sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
|
||||
"sta_if.isconnected() # Check for successful connection\n"
|
||||
"\n"
|
||||
"Control commands:\n"
|
||||
" CTRL-A -- on a blank line, enter raw REPL mode\n"
|
||||
" CTRL-B -- on a blank line, enter normal REPL mode\n"
|
||||
" CTRL-C -- interrupt a running program\n"
|
||||
" CTRL-D -- on a blank line, do a soft reset of the board\n"
|
||||
" CTRL-E -- on a blank line, enter paste mode\n"
|
||||
"\n"
|
||||
"For further help on a specific object, type help(obj)\n"
|
||||
"For a list of available modules, type help('modules')\n"
|
||||
;
|
||||
|
@ -54,7 +54,7 @@ STATIC const madc_obj_t madc_obj[] = {
|
||||
};
|
||||
|
||||
STATIC mp_obj_t madc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||
const mp_obj_t *args) {
|
||||
const mp_obj_t *args) {
|
||||
|
||||
static int initialized = 0;
|
||||
if (!initialized) {
|
||||
@ -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);
|
||||
|
@ -48,21 +48,28 @@ STATIC const mdac_obj_t mdac_obj[] = {
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||
const mp_obj_t *args) {
|
||||
const mp_obj_t *args) {
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
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);
|
||||
|
@ -94,16 +94,16 @@ STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) {
|
||||
}
|
||||
|
||||
STATIC void machine_hw_spi_init_internal(
|
||||
machine_hw_spi_obj_t *self,
|
||||
int8_t host,
|
||||
int32_t baudrate,
|
||||
int8_t polarity,
|
||||
int8_t phase,
|
||||
int8_t bits,
|
||||
int8_t firstbit,
|
||||
int8_t sck,
|
||||
int8_t mosi,
|
||||
int8_t miso) {
|
||||
machine_hw_spi_obj_t *self,
|
||||
int8_t host,
|
||||
int32_t baudrate,
|
||||
int8_t polarity,
|
||||
int8_t phase,
|
||||
int8_t bits,
|
||||
int8_t firstbit,
|
||||
int8_t sck,
|
||||
int8_t mosi,
|
||||
int8_t miso) {
|
||||
|
||||
// if we're not initialized, then we're
|
||||
// implicitly 'changed', since this is the init routine
|
||||
@ -129,7 +129,7 @@ STATIC void machine_hw_spi_init_internal(
|
||||
}
|
||||
|
||||
if (phase != -1 && phase != self->phase) {
|
||||
self->phase = phase;
|
||||
self->phase = phase;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ STATIC void machine_hw_spi_init_internal(
|
||||
.pre_cb = NULL
|
||||
};
|
||||
|
||||
//Initialize the SPI bus
|
||||
// Initialize the SPI bus
|
||||
|
||||
// Select DMA channel based on the hardware SPI host
|
||||
int dma_chan = 0;
|
||||
@ -230,7 +230,7 @@ STATIC void machine_hw_spi_init_internal(
|
||||
}
|
||||
|
||||
STATIC void machine_hw_spi_deinit(mp_obj_base_t *self_in) {
|
||||
machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *) self_in;
|
||||
machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *)self_in;
|
||||
if (self->state == MACHINE_HW_SPI_STATE_INIT) {
|
||||
self->state = MACHINE_HW_SPI_STATE_DEINIT;
|
||||
machine_hw_spi_deinit_internal(self);
|
||||
@ -295,13 +295,13 @@ STATIC void machine_hw_spi_transfer(mp_obj_base_t *self_in, size_t len, const ui
|
||||
STATIC void machine_hw_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_hw_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "SPI(id=%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%d, mosi=%d, miso=%d)",
|
||||
self->host, self->baudrate, self->polarity,
|
||||
self->phase, self->bits, self->firstbit,
|
||||
self->sck, self->mosi, self->miso);
|
||||
self->host, self->baudrate, self->polarity,
|
||||
self->phase, self->bits, self->firstbit,
|
||||
self->sck, self->mosi, self->miso);
|
||||
}
|
||||
|
||||
STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *) self_in;
|
||||
machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *)self_in;
|
||||
|
||||
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -318,7 +318,7 @@ STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args),
|
||||
allowed_args, args);
|
||||
allowed_args, args);
|
||||
int8_t sck, mosi, miso;
|
||||
|
||||
if (args[ARG_sck].u_obj == MP_OBJ_NULL) {
|
||||
@ -346,8 +346,8 @@ STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_
|
||||
}
|
||||
|
||||
machine_hw_spi_init_internal(self, args[ARG_id].u_int, args[ARG_baudrate].u_int,
|
||||
args[ARG_polarity].u_int, args[ARG_phase].u_int, args[ARG_bits].u_int,
|
||||
args[ARG_firstbit].u_int, sck, mosi, miso);
|
||||
args[ARG_polarity].u_int, args[ARG_phase].u_int, args[ARG_bits].u_int,
|
||||
args[ARG_firstbit].u_int, sck, mosi, miso);
|
||||
}
|
||||
|
||||
mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
@ -401,5 +401,5 @@ const mp_obj_type_t machine_hw_spi_type = {
|
||||
.print = machine_hw_spi_print,
|
||||
.make_new = machine_hw_spi_make_new,
|
||||
.protocol = &machine_hw_spi_p,
|
||||
.locals_dict = (mp_obj_dict_t *) &mp_machine_spi_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
||||
};
|
||||
|
@ -179,7 +179,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||
int wanted_pin = mp_obj_get_int(args[0]);
|
||||
const machine_pin_obj_t *self = NULL;
|
||||
if (0 <= wanted_pin && wanted_pin < MP_ARRAY_SIZE(machine_pin_obj)) {
|
||||
self = (machine_pin_obj_t*)&machine_pin_obj[wanted_pin];
|
||||
self = (machine_pin_obj_t *)&machine_pin_obj[wanted_pin];
|
||||
}
|
||||
if (self == NULL || self->base.type == NULL) {
|
||||
mp_raise_ValueError("invalid pin");
|
||||
@ -293,7 +293,7 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||
gpio_isr_handler_remove(self->id);
|
||||
MP_STATE_PORT(machine_pin_irq_handler)[self->id] = handler;
|
||||
gpio_set_intr_type(self->id, trigger);
|
||||
gpio_isr_handler_add(self->id, machine_pin_isr_handler, (void*)self);
|
||||
gpio_isr_handler_add(self->id, machine_pin_isr_handler, (void *)self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +341,7 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table);
|
||||
|
||||
STATIC const mp_pin_p_t pin_pin_p = {
|
||||
.ioctl = pin_ioctl,
|
||||
.ioctl = pin_ioctl,
|
||||
};
|
||||
|
||||
const mp_obj_type_t machine_pin_type = {
|
||||
@ -405,7 +405,7 @@ STATIC const machine_pin_irq_obj_t machine_pin_irq_object[] = {
|
||||
STATIC mp_obj_t machine_pin_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
machine_pin_irq_obj_t *self = self_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
machine_pin_isr_handler((void*)&machine_pin_obj[self->id]);
|
||||
machine_pin_isr_handler((void *)&machine_pin_obj[self->id]);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -430,5 +430,5 @@ STATIC const mp_obj_type_t machine_pin_irq_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_IRQ,
|
||||
.call = machine_pin_irq_call,
|
||||
.locals_dict = (mp_obj_dict_t*)&machine_pin_irq_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&machine_pin_irq_locals_dict,
|
||||
};
|
||||
|
@ -120,7 +120,7 @@ STATIC void esp32_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
|
||||
}
|
||||
|
||||
STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
|
||||
size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_freq, ARG_duty };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_freq, MP_ARG_INT, {.u_int = -1} },
|
||||
@ -183,7 +183,7 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
|
||||
// Set duty cycle?
|
||||
int dval = args[ARG_duty].u_int;
|
||||
if (dval != -1) {
|
||||
dval &= ((1 << PWRES)-1);
|
||||
dval &= ((1 << PWRES) - 1);
|
||||
dval >>= PWRES - timer_cfg.duty_resolution;
|
||||
ledc_set_duty(PWMODE, channel, dval);
|
||||
ledc_update_duty(PWMODE, channel);
|
||||
@ -191,7 +191,7 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
|
||||
}
|
||||
|
||||
STATIC mp_obj_t esp32_pwm_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
gpio_num_t pin_id = machine_pin_get_id(args[0]);
|
||||
|
||||
@ -217,7 +217,7 @@ STATIC mp_obj_t esp32_pwm_make_new(const mp_obj_type_t *type,
|
||||
}
|
||||
|
||||
STATIC mp_obj_t esp32_pwm_init(size_t n_args,
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
esp32_pwm_init_helper(args[0], n_args - 1, args + 1, kw_args);
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -270,7 +270,7 @@ STATIC mp_obj_t esp32_pwm_duty(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
// set
|
||||
duty = mp_obj_get_int(args[1]);
|
||||
duty &= ((1 << PWRES)-1);
|
||||
duty &= ((1 << PWRES) - 1);
|
||||
duty >>= PWRES - timer_cfg.duty_resolution;
|
||||
ledc_set_duty(PWMODE, self->channel, duty);
|
||||
ledc_update_duty(PWMODE, self->channel);
|
||||
@ -295,5 +295,5 @@ const mp_obj_type_t machine_pwm_type = {
|
||||
.name = MP_QSTR_PWM,
|
||||
.print = esp32_pwm_print,
|
||||
.make_new = esp32_pwm_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&esp32_pwm_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&esp32_pwm_locals_dict,
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
|
||||
machine_rtc_config_t machine_rtc_config = {
|
||||
.ext1_pins = 0,
|
||||
.ext0_pin = -1
|
||||
};
|
||||
};
|
||||
|
||||
STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
@ -130,7 +130,7 @@ STATIC mp_obj_t machine_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
// read RTC memory
|
||||
uint32_t len = rtc_user_mem_len;
|
||||
uint8_t rtcram[MEM_USER_MAXLEN];
|
||||
memcpy( (char *) rtcram, (char *) rtc_user_mem_data, len);
|
||||
memcpy((char *)rtcram, (char *)rtc_user_mem_data, len);
|
||||
return mp_obj_new_bytes(rtcram, len);
|
||||
} else {
|
||||
// write RTC memory
|
||||
@ -140,7 +140,7 @@ STATIC mp_obj_t machine_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (bufinfo.len > MEM_USER_MAXLEN) {
|
||||
mp_raise_ValueError("buffer too long");
|
||||
}
|
||||
memcpy( (char *) rtc_user_mem_data, (char *) bufinfo.buf, bufinfo.len);
|
||||
memcpy((char *)rtc_user_mem_data, (char *)bufinfo.buf, bufinfo.len);
|
||||
rtc_user_mem_len = bufinfo.len;
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 "Eric Poulsen" <eric@zyxod.com>
|
||||
* Copyright (c) 2017 "Tom Manning" <tom@manningetal.com>
|
||||
* Copyright (c) 2017 "Tom Manning" <tom@manningetal.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -129,7 +129,7 @@ STATIC void machine_timer_enable(machine_timer_obj_t *self) {
|
||||
check_esp_err(timer_set_counter_value(self->group, self->index, 0x00000000));
|
||||
check_esp_err(timer_set_alarm_value(self->group, self->index, self->period));
|
||||
check_esp_err(timer_enable_intr(self->group, self->index));
|
||||
check_esp_err(timer_isr_register(self->group, self->index, machine_timer_isr, (void*)self, TIMER_FLAGS, &self->handle));
|
||||
check_esp_err(timer_isr_register(self->group, self->index, machine_timer_isr, (void *)self, TIMER_FLAGS, &self->handle));
|
||||
check_esp_err(timer_start(self->group, self->index));
|
||||
}
|
||||
|
||||
@ -146,11 +146,11 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n
|
||||
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
|
||||
{ MP_QSTR_tick_hz, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
#else
|
||||
#else
|
||||
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
machine_timer_disable(self);
|
||||
@ -158,15 +158,15 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
if (args[ARG_freq].u_obj != mp_const_none) {
|
||||
self->period = (uint64_t)(TIMER_SCALE / mp_obj_get_float(args[ARG_freq].u_obj));
|
||||
}
|
||||
#else
|
||||
#else
|
||||
if (args[ARG_freq].u_int != 0xffffffff) {
|
||||
self->period = TIMER_SCALE / ((uint64_t)args[ARG_freq].u_int);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
else {
|
||||
self->period = (((uint64_t)args[ARG_period].u_int) * TIMER_SCALE) / args[ARG_tick_hz].u_int;
|
||||
}
|
||||
|
@ -56,15 +56,20 @@ STATIC const mtp_obj_t touchpad_obj[] = {
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||
const mp_obj_t *args) {
|
||||
const mp_obj_t *args) {
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
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);
|
||||
|
@ -222,7 +222,7 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) is disabled (dedicated to REPL)", uart_num));
|
||||
}
|
||||
|
||||
// Defaults
|
||||
// Defaults
|
||||
uart_config_t uartcfg = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
@ -413,5 +413,5 @@ const mp_obj_type_t machine_uart_type = {
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &uart_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t*)&machine_uart_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict,
|
||||
};
|
||||
|
@ -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))
|
||||
|
@ -117,7 +117,7 @@ STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t timing)
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
||||
esp_neopixel_write(mp_hal_get_pin_obj(pin),
|
||||
(uint8_t*)bufinfo.buf, bufinfo.len, mp_obj_get_int(timing));
|
||||
(uint8_t *)bufinfo.buf, bufinfo.len, mp_obj_get_int(timing));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
|
||||
@ -152,6 +152,6 @@ STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table);
|
||||
|
||||
const mp_obj_module_t esp_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&esp_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&esp_module_globals,
|
||||
};
|
||||
|
||||
|
@ -48,7 +48,7 @@ STATIC mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) {
|
||||
if (machine_rtc_config.ext0_pin != -1) {
|
||||
mp_raise_ValueError("no resources");
|
||||
}
|
||||
//nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "touchpad wakeup not available for this version of ESP-IDF"));
|
||||
// nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "touchpad wakeup not available for this version of ESP-IDF"));
|
||||
|
||||
machine_rtc_config.wake_on_touch = mp_obj_is_true(wake);
|
||||
return mp_const_none;
|
||||
@ -164,5 +164,5 @@ STATIC MP_DEFINE_CONST_DICT(esp32_module_globals, esp32_module_globals_table);
|
||||
|
||||
const mp_obj_module_t esp32_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&esp32_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&esp32_module_globals,
|
||||
};
|
||||
|
@ -2,10 +2,10 @@
|
||||
#define MICROPY_INCLUDED_ESP32_MODESP32_H
|
||||
|
||||
#define RTC_VALID_EXT_PINS \
|
||||
( \
|
||||
(1ll << 0) | \
|
||||
(1ll << 2) | \
|
||||
(1ll << 4) | \
|
||||
( \
|
||||
(1ll << 0) | \
|
||||
(1ll << 2) | \
|
||||
(1ll << 4) | \
|
||||
(1ll << 12) | \
|
||||
(1ll << 13) | \
|
||||
(1ll << 14) | \
|
||||
@ -21,7 +21,7 @@
|
||||
(1ll << 37) | \
|
||||
(1ll << 38) | \
|
||||
(1ll << 39) \
|
||||
)
|
||||
)
|
||||
|
||||
#define RTC_LAST_EXT_PIN 39
|
||||
#define RTC_IS_VALID_EXT_PIN(pin_id) ((1ll << (pin_id)) & RTC_VALID_EXT_PINS)
|
||||
|
@ -108,7 +108,7 @@ STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const
|
||||
}
|
||||
}
|
||||
|
||||
switch(wake_type) {
|
||||
switch (wake_type) {
|
||||
case MACHINE_WAKE_SLEEP:
|
||||
esp_light_sleep_start();
|
||||
break;
|
||||
@ -130,7 +130,7 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_deepsleep_obj, 0, machine_deepsleep);
|
||||
|
||||
STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
switch(rtc_get_reset_reason(0)) {
|
||||
switch (rtc_get_reset_reason(0)) {
|
||||
case POWERON_RESET:
|
||||
return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
|
||||
break;
|
||||
@ -262,7 +262,7 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table
|
||||
|
||||
const mp_obj_module_t mp_module_machine = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&machine_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&machine_module_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_MACHINE
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef enum {
|
||||
//MACHINE_WAKE_IDLE=0x01,
|
||||
// MACHINE_WAKE_IDLE=0x01,
|
||||
MACHINE_WAKE_SLEEP=0x02,
|
||||
MACHINE_WAKE_DEEPSLEEP=0x04
|
||||
} wake_type_t;
|
||||
|
@ -54,54 +54,56 @@
|
||||
#define MODNETWORK_INCLUDE_CONSTANTS (1)
|
||||
|
||||
NORETURN void _esp_exceptions(esp_err_t e) {
|
||||
switch (e) {
|
||||
case ESP_ERR_WIFI_NOT_INIT:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Initialized");
|
||||
case ESP_ERR_WIFI_NOT_STARTED:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Started");
|
||||
case ESP_ERR_WIFI_NOT_STOPPED:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Stopped");
|
||||
case ESP_ERR_WIFI_IF:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Interface");
|
||||
case ESP_ERR_WIFI_MODE:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Mode");
|
||||
case ESP_ERR_WIFI_STATE:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Internal State Error");
|
||||
case ESP_ERR_WIFI_CONN:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Internal Error");
|
||||
case ESP_ERR_WIFI_NVS:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Internal NVS Error");
|
||||
case ESP_ERR_WIFI_MAC:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid MAC Address");
|
||||
case ESP_ERR_WIFI_SSID:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi SSID Invalid");
|
||||
case ESP_ERR_WIFI_PASSWORD:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Password");
|
||||
case ESP_ERR_WIFI_TIMEOUT:
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
case ESP_ERR_WIFI_WAKE_FAIL:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Wakeup Failure");
|
||||
case ESP_ERR_WIFI_WOULD_BLOCK:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Would Block");
|
||||
case ESP_ERR_WIFI_NOT_CONNECT:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Connected");
|
||||
case ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS:
|
||||
mp_raise_msg(&mp_type_OSError, "TCP/IP Invalid Parameters");
|
||||
case ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:
|
||||
mp_raise_msg(&mp_type_OSError, "TCP/IP IF Not Ready");
|
||||
case ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED:
|
||||
mp_raise_msg(&mp_type_OSError, "TCP/IP DHCP Client Start Failed");
|
||||
case ESP_ERR_TCPIP_ADAPTER_NO_MEM:
|
||||
mp_raise_OSError(MP_ENOMEM);
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(
|
||||
&mp_type_RuntimeError, "Wifi Unknown Error 0x%04x", e
|
||||
));
|
||||
}
|
||||
switch (e) {
|
||||
case ESP_ERR_WIFI_NOT_INIT:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Initialized");
|
||||
case ESP_ERR_WIFI_NOT_STARTED:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Started");
|
||||
case ESP_ERR_WIFI_NOT_STOPPED:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Stopped");
|
||||
case ESP_ERR_WIFI_IF:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Interface");
|
||||
case ESP_ERR_WIFI_MODE:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Mode");
|
||||
case ESP_ERR_WIFI_STATE:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Internal State Error");
|
||||
case ESP_ERR_WIFI_CONN:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Internal Error");
|
||||
case ESP_ERR_WIFI_NVS:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Internal NVS Error");
|
||||
case ESP_ERR_WIFI_MAC:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid MAC Address");
|
||||
case ESP_ERR_WIFI_SSID:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi SSID Invalid");
|
||||
case ESP_ERR_WIFI_PASSWORD:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Invalid Password");
|
||||
case ESP_ERR_WIFI_TIMEOUT:
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
case ESP_ERR_WIFI_WAKE_FAIL:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Wakeup Failure");
|
||||
case ESP_ERR_WIFI_WOULD_BLOCK:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Would Block");
|
||||
case ESP_ERR_WIFI_NOT_CONNECT:
|
||||
mp_raise_msg(&mp_type_OSError, "Wifi Not Connected");
|
||||
case ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS:
|
||||
mp_raise_msg(&mp_type_OSError, "TCP/IP Invalid Parameters");
|
||||
case ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:
|
||||
mp_raise_msg(&mp_type_OSError, "TCP/IP IF Not Ready");
|
||||
case ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED:
|
||||
mp_raise_msg(&mp_type_OSError, "TCP/IP DHCP Client Start Failed");
|
||||
case ESP_ERR_TCPIP_ADAPTER_NO_MEM:
|
||||
mp_raise_OSError(MP_ENOMEM);
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(
|
||||
&mp_type_RuntimeError, "Wifi Unknown Error 0x%04x", 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);
|
||||
@ -131,67 +133,67 @@ static uint8_t wifi_sta_disconn_reason = 0;
|
||||
// This function is called by the system-event task and so runs in a different
|
||||
// thread to the main MicroPython task. It must not raise any Python exceptions.
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event) {
|
||||
switch(event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
ESP_LOGI("wifi", "STA_START");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
ESP_LOGI("network", "CONNECTED");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
ESP_LOGI("network", "GOT_IP");
|
||||
wifi_sta_connected = true;
|
||||
wifi_sta_disconn_reason = 0; // Success so clear error. (in case of new error will be replaced anyway)
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
||||
// This is a workaround as ESP32 WiFi libs don't currently
|
||||
// auto-reassociate.
|
||||
system_event_sta_disconnected_t *disconn = &event->event_info.disconnected;
|
||||
char *message = "";
|
||||
wifi_sta_disconn_reason = disconn->reason;
|
||||
switch (disconn->reason) {
|
||||
case WIFI_REASON_BEACON_TIMEOUT:
|
||||
// AP has dropped out; try to reconnect.
|
||||
message = "\nbeacon timeout";
|
||||
break;
|
||||
case WIFI_REASON_NO_AP_FOUND:
|
||||
// AP may not exist, or it may have momentarily dropped out; try to reconnect.
|
||||
message = "\nno AP found";
|
||||
break;
|
||||
case WIFI_REASON_AUTH_FAIL:
|
||||
message = "\nauthentication failed";
|
||||
wifi_sta_connect_requested = false;
|
||||
break;
|
||||
default:
|
||||
// Let other errors through and try to reconnect.
|
||||
break;
|
||||
}
|
||||
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d%s", disconn->reason, message);
|
||||
switch (event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
ESP_LOGI("wifi", "STA_START");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
ESP_LOGI("network", "CONNECTED");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
ESP_LOGI("network", "GOT_IP");
|
||||
wifi_sta_connected = true;
|
||||
wifi_sta_disconn_reason = 0; // Success so clear error. (in case of new error will be replaced anyway)
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
||||
// This is a workaround as ESP32 WiFi libs don't currently
|
||||
// auto-reassociate.
|
||||
system_event_sta_disconnected_t *disconn = &event->event_info.disconnected;
|
||||
char *message = "";
|
||||
wifi_sta_disconn_reason = disconn->reason;
|
||||
switch (disconn->reason) {
|
||||
case WIFI_REASON_BEACON_TIMEOUT:
|
||||
// AP has dropped out; try to reconnect.
|
||||
message = "\nbeacon timeout";
|
||||
break;
|
||||
case WIFI_REASON_NO_AP_FOUND:
|
||||
// AP may not exist, or it may have momentarily dropped out; try to reconnect.
|
||||
message = "\nno AP found";
|
||||
break;
|
||||
case WIFI_REASON_AUTH_FAIL:
|
||||
message = "\nauthentication failed";
|
||||
wifi_sta_connect_requested = false;
|
||||
break;
|
||||
default:
|
||||
// Let other errors through and try to reconnect.
|
||||
break;
|
||||
}
|
||||
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d%s", disconn->reason, message);
|
||||
|
||||
bool reconnected = false;
|
||||
if (wifi_sta_connect_requested) {
|
||||
wifi_mode_t mode;
|
||||
if (esp_wifi_get_mode(&mode) == ESP_OK) {
|
||||
if (mode & WIFI_MODE_STA) {
|
||||
// STA is active so attempt to reconnect.
|
||||
esp_err_t e = esp_wifi_connect();
|
||||
if (e != ESP_OK) {
|
||||
ESP_LOGI("wifi", "error attempting to reconnect: 0x%04x", e);
|
||||
} else {
|
||||
reconnected = true;
|
||||
bool reconnected = false;
|
||||
if (wifi_sta_connect_requested) {
|
||||
wifi_mode_t mode;
|
||||
if (esp_wifi_get_mode(&mode) == ESP_OK) {
|
||||
if (mode & WIFI_MODE_STA) {
|
||||
// STA is active so attempt to reconnect.
|
||||
esp_err_t e = esp_wifi_connect();
|
||||
if (e != ESP_OK) {
|
||||
ESP_LOGI("wifi", "error attempting to reconnect: 0x%04x", e);
|
||||
} else {
|
||||
reconnected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wifi_sta_connected && !reconnected) {
|
||||
// If already connected and we fail to reconnect
|
||||
wifi_sta_connected = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (wifi_sta_connected && !reconnected) {
|
||||
// If already connected and we fail to reconnect
|
||||
wifi_sta_connected = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ESP_LOGI("network", "event %d", event->event_id);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI("network", "event %d", event->event_id);
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -215,8 +217,8 @@ STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) {
|
||||
if (!initialized) {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_LOGD("modnetwork", "Initializing WiFi");
|
||||
ESP_EXCEPTIONS( esp_wifi_init(&cfg) );
|
||||
ESP_EXCEPTIONS( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
|
||||
ESP_EXCEPTIONS(esp_wifi_init(&cfg));
|
||||
ESP_EXCEPTIONS(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
ESP_LOGD("modnetwork", "Initialized");
|
||||
initialized = 1;
|
||||
}
|
||||
@ -238,7 +240,7 @@ STATIC mp_obj_t esp_initialize() {
|
||||
ESP_LOGD("modnetwork", "Initializing TCP/IP");
|
||||
tcpip_adapter_init();
|
||||
ESP_LOGD("modnetwork", "Initializing Event Loop");
|
||||
ESP_EXCEPTIONS( esp_event_loop_init(event_handler, NULL) );
|
||||
ESP_EXCEPTIONS(esp_event_loop_init(event_handler, NULL));
|
||||
ESP_LOGD("modnetwork", "esp_event_loop_init done");
|
||||
initialized = 1;
|
||||
}
|
||||
@ -318,12 +320,12 @@ STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
wifi_sta_config.sta.bssid_set = 1;
|
||||
memcpy(wifi_sta_config.sta.bssid, p, sizeof(wifi_sta_config.sta.bssid));
|
||||
}
|
||||
ESP_EXCEPTIONS( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_sta_config) );
|
||||
ESP_EXCEPTIONS(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_sta_config));
|
||||
}
|
||||
|
||||
// connect to the WiFi AP
|
||||
MP_THREAD_GIL_EXIT();
|
||||
ESP_EXCEPTIONS( esp_wifi_connect() );
|
||||
ESP_EXCEPTIONS(esp_wifi_connect());
|
||||
MP_THREAD_GIL_ENTER();
|
||||
wifi_sta_connect_requested = true;
|
||||
|
||||
@ -333,7 +335,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_connect_obj, 1, esp_connect);
|
||||
|
||||
STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) {
|
||||
wifi_sta_connect_requested = false;
|
||||
ESP_EXCEPTIONS( esp_wifi_disconnect() );
|
||||
ESP_EXCEPTIONS(esp_wifi_disconnect());
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -376,7 +378,7 @@ STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) {
|
||||
require_if(args[0], WIFI_IF_AP);
|
||||
wifi_sta_list_t station_list;
|
||||
ESP_EXCEPTIONS(esp_wifi_ap_get_sta_list(&station_list));
|
||||
wifi_sta_info_t *stations = (wifi_sta_info_t*)station_list.sta;
|
||||
wifi_sta_info_t *stations = (wifi_sta_info_t *)station_list.sta;
|
||||
mp_obj_t list = mp_obj_new_list(0, NULL);
|
||||
for (int i = 0; i < station_list.num; ++i) {
|
||||
mp_obj_tuple_t *t = mp_obj_new_tuple(1, NULL);
|
||||
@ -410,9 +412,9 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (status == 0) {
|
||||
uint16_t count = 0;
|
||||
ESP_EXCEPTIONS( esp_wifi_scan_get_ap_num(&count) );
|
||||
ESP_EXCEPTIONS(esp_wifi_scan_get_ap_num(&count));
|
||||
wifi_ap_record_t *wifi_ap_records = calloc(count, sizeof(wifi_ap_record_t));
|
||||
ESP_EXCEPTIONS( esp_wifi_scan_get_ap_records(&count, wifi_ap_records) );
|
||||
ESP_EXCEPTIONS(esp_wifi_scan_get_ap_records(&count, wifi_ap_records));
|
||||
for (uint16_t i = 0; i < count; i++) {
|
||||
mp_obj_tuple_t *t = mp_obj_new_tuple(6, NULL);
|
||||
uint8_t *x = memchr(wifi_ap_records[i].ssid, 0, sizeof(wifi_ap_records[i].ssid));
|
||||
@ -453,10 +455,10 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
mp_obj_t tuple[4] = {
|
||||
netutils_format_ipv4_addr((uint8_t*)&info.ip, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t*)&info.netmask, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t*)&info.gw, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t*)&dns_info.ip, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&info.ip, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&info.netmask, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&info.gw, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&dns_info.ip, NETUTILS_BIG),
|
||||
};
|
||||
return mp_obj_new_tuple(4, tuple);
|
||||
} else {
|
||||
@ -464,28 +466,32 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
if (MP_OBJ_IS_TYPE(args[1], &mp_type_tuple) || MP_OBJ_IS_TYPE(args[1], &mp_type_list)) {
|
||||
mp_obj_t *items;
|
||||
mp_obj_get_array_fixed_n(args[1], 4, &items);
|
||||
netutils_parse_ipv4_addr(items[0], (void*)&info.ip, NETUTILS_BIG);
|
||||
netutils_parse_ipv4_addr(items[0], (void *)&info.ip, NETUTILS_BIG);
|
||||
if (mp_obj_is_integer(items[1])) {
|
||||
// allow numeric netmask, i.e.:
|
||||
// 24 -> 255.255.255.0
|
||||
// 16 -> 255.255.0.0
|
||||
// etc...
|
||||
uint32_t* m = (uint32_t*)&info.netmask;
|
||||
uint32_t *m = (uint32_t *)&info.netmask;
|
||||
*m = htonl(0xffffffff << (32 - mp_obj_get_int(items[1])));
|
||||
} else {
|
||||
netutils_parse_ipv4_addr(items[1], (void*)&info.netmask, NETUTILS_BIG);
|
||||
netutils_parse_ipv4_addr(items[1], (void *)&info.netmask, NETUTILS_BIG);
|
||||
}
|
||||
netutils_parse_ipv4_addr(items[2], (void*)&info.gw, NETUTILS_BIG);
|
||||
netutils_parse_ipv4_addr(items[3], (void*)&dns_info.ip, NETUTILS_BIG);
|
||||
netutils_parse_ipv4_addr(items[2], (void *)&info.gw, NETUTILS_BIG);
|
||||
netutils_parse_ipv4_addr(items[3], (void *)&dns_info.ip, NETUTILS_BIG);
|
||||
// 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));
|
||||
@ -573,7 +579,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
default:
|
||||
goto unknown;
|
||||
}
|
||||
#undef QS
|
||||
#undef QS
|
||||
|
||||
// We post-check interface requirements to save on code size
|
||||
if (req_if >= 0) {
|
||||
@ -605,9 +611,9 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
}
|
||||
case QS(MP_QSTR_essid):
|
||||
if (self->if_id == WIFI_IF_STA) {
|
||||
val = mp_obj_new_str((char*)cfg.sta.ssid, strlen((char*)cfg.sta.ssid));
|
||||
val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
|
||||
} else {
|
||||
val = mp_obj_new_str((char*)cfg.ap.ssid, cfg.ap.ssid_len);
|
||||
val = mp_obj_new_str((char *)cfg.ap.ssid, cfg.ap.ssid_len);
|
||||
}
|
||||
break;
|
||||
case QS(MP_QSTR_hidden):
|
||||
@ -631,7 +637,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
default:
|
||||
goto unknown;
|
||||
}
|
||||
#undef QS
|
||||
#undef QS
|
||||
|
||||
// We post-check interface requirements to save on code size
|
||||
if (req_if >= 0) {
|
||||
@ -679,7 +685,7 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&ppp_make_new_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) },
|
||||
|
||||
#if MODNETWORK_INCLUDE_CONSTANTS
|
||||
#if MODNETWORK_INCLUDE_CONSTANTS
|
||||
{ MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(WIFI_IF_STA)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(WIFI_IF_AP)},
|
||||
|
||||
@ -706,12 +712,12 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_HANDSHAKE_TIMEOUT), MP_ROM_INT(WIFI_REASON_HANDSHAKE_TIMEOUT)},
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_network = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_network_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_network_globals,
|
||||
};
|
||||
|
@ -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,16 +194,20 @@ 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);
|
||||
|
||||
|
||||
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);
|
||||
@ -213,15 +219,21 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) {
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
|
||||
int new_fd = -1;
|
||||
for (int i=0; i<=self->retries; i++) {
|
||||
for (int i = 0; i <= self->retries; i++) {
|
||||
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);
|
||||
@ -234,8 +246,8 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) {
|
||||
_socket_settimeout(sock, UINT64_MAX);
|
||||
|
||||
// make the return value
|
||||
uint8_t *ip = (uint8_t*)&((struct sockaddr_in*)&addr)->sin_addr;
|
||||
mp_uint_t port = lwip_ntohs(((struct sockaddr_in*)&addr)->sin_port);
|
||||
uint8_t *ip = (uint8_t *)&((struct sockaddr_in *)&addr)->sin_addr;
|
||||
mp_uint_t port = lwip_ntohs(((struct sockaddr_in *)&addr)->sin_port);
|
||||
mp_obj_tuple_t *client = mp_obj_new_tuple(2, NULL);
|
||||
client->items[0] = sock;
|
||||
client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
|
||||
@ -277,7 +289,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
break;
|
||||
}
|
||||
|
||||
#if MICROPY_PY_USOCKET_EVENTS
|
||||
#if MICROPY_PY_USOCKET_EVENTS
|
||||
// level: SOL_SOCKET
|
||||
// special "register callback" option
|
||||
case 20: {
|
||||
@ -294,7 +306,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// level: IPPROTO_IP
|
||||
case IP_ADD_MEMBERSHIP: {
|
||||
@ -305,7 +317,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
// POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
|
||||
err_t err = igmp_joingroup((const ip4_addr_t*)bufinfo.buf + 1, bufinfo.buf);
|
||||
err_t err = igmp_joingroup((const ip4_addr_t *)bufinfo.buf + 1, bufinfo.buf);
|
||||
if (err != ERR_OK) {
|
||||
mp_raise_OSError(-err);
|
||||
}
|
||||
@ -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);
|
||||
@ -411,7 +427,7 @@ STATIC mp_uint_t _socket_read_data(mp_obj_t self_in, void *buf, size_t size,
|
||||
}
|
||||
|
||||
mp_obj_t _socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in,
|
||||
struct sockaddr *from, socklen_t *from_len) {
|
||||
struct sockaddr *from, socklen_t *from_len) {
|
||||
size_t len = mp_obj_get_int(len_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, len);
|
||||
@ -438,8 +454,8 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
mp_obj_t tuple[2];
|
||||
tuple[0] = _socket_recvfrom(self_in, len_in, &from, &fromlen);
|
||||
|
||||
uint8_t *ip = (uint8_t*)&((struct sockaddr_in*)&from)->sin_addr;
|
||||
mp_uint_t port = lwip_ntohs(((struct sockaddr_in*)&from)->sin_port);
|
||||
uint8_t *ip = (uint8_t *)&((struct sockaddr_in *)&from)->sin_addr;
|
||||
mp_uint_t port = lwip_ntohs(((struct sockaddr_in *)&from)->sin_port);
|
||||
tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
|
||||
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
@ -448,15 +464,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
|
||||
|
||||
int _socket_send(socket_obj_t *sock, const char *data, size_t datalen) {
|
||||
int sentlen = 0;
|
||||
for (int i=0; i<=sock->retries && sentlen < datalen; i++) {
|
||||
for (int i = 0; i <= sock->retries && sentlen < datalen; i++) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int r = lwip_write_r(sock->fd, data+sentlen, datalen-sentlen);
|
||||
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);
|
||||
@ -492,20 +516,22 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
|
||||
struct sockaddr_in to;
|
||||
to.sin_len = sizeof(to);
|
||||
to.sin_family = AF_INET;
|
||||
to.sin_port = lwip_htons(netutils_parse_inet_addr(addr_in, (uint8_t*)&to.sin_addr, NETUTILS_BIG));
|
||||
to.sin_port = lwip_htons(netutils_parse_inet_addr(addr_in, (uint8_t *)&to.sin_addr, NETUTILS_BIG));
|
||||
|
||||
// send the data
|
||||
for (int i=0; i<=self->retries; i++) {
|
||||
for (int i = 0; i <= self->retries; i++) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int ret = lwip_sendto_r(self->fd, bufinfo.buf, bufinfo.len, 0, (struct sockaddr*)&to, sizeof(to));
|
||||
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);
|
||||
}
|
||||
check_for_exceptions();
|
||||
}
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
mp_raise_OSError(MP_ETIMEDOUT);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
|
||||
|
||||
@ -527,12 +553,17 @@ STATIC mp_uint_t socket_stream_read(mp_obj_t self_in, void *buf, mp_uint_t size,
|
||||
|
||||
STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
socket_obj_t *sock = self_in;
|
||||
for (int i=0; i<=sock->retries; i++) {
|
||||
for (int i = 0; i <= sock->retries; i++) {
|
||||
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;
|
||||
@ -540,27 +571,42 @@ STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_
|
||||
}
|
||||
|
||||
STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
socket_obj_t * socket = self_in;
|
||||
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);
|
||||
int r = select((socket->fd) + 1, &rfds, &wfds, &efds, &timeout);
|
||||
if (r < 0) {
|
||||
*errcode = MP_EIO;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -664,7 +710,7 @@ STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_new_str(resi->ai_canonname, strlen(resi->ai_canonname)),
|
||||
mp_const_none
|
||||
};
|
||||
|
||||
|
||||
if (resi->ai_family == AF_INET) {
|
||||
struct sockaddr_in *addr = (struct sockaddr_in *)resi->ai_addr;
|
||||
// This looks odd, but it's really just a u32_t
|
||||
@ -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);
|
||||
@ -719,5 +767,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_t
|
||||
|
||||
const mp_obj_module_t mp_module_usocket = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_socket_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_socket_globals,
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ STATIC MP_DEFINE_ATTRTUPLE(
|
||||
(mp_obj_t)&os_uname_info_release_obj,
|
||||
(mp_obj_t)&os_uname_info_version_obj,
|
||||
(mp_obj_t)&os_uname_info_machine_obj
|
||||
);
|
||||
);
|
||||
|
||||
STATIC mp_obj_t os_uname(void) {
|
||||
return (mp_obj_t)&os_uname_info_obj;
|
||||
@ -130,5 +130,5 @@ STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
|
||||
|
||||
const mp_obj_module_t uos_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&os_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&os_module_globals,
|
||||
};
|
||||
|
@ -70,8 +70,8 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) {
|
||||
}
|
||||
|
||||
return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]),
|
||||
mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]),
|
||||
mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5])));
|
||||
mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]),
|
||||
mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5])));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime);
|
||||
|
||||
@ -102,5 +102,5 @@ STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
|
||||
|
||||
const mp_obj_module_t utime_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&time_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&time_module_globals,
|
||||
};
|
||||
|
@ -217,7 +217,7 @@ extern const struct _mp_obj_module_t mp_module_onewire;
|
||||
// type definitions for the specific machine
|
||||
|
||||
#define BYTES_PER_WORD (4)
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p)))
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))
|
||||
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
|
||||
#define MP_SSIZE_MAX (0x7fffffff)
|
||||
|
||||
@ -249,7 +249,7 @@ extern const struct _mp_obj_module_t mp_module_onewire;
|
||||
extern void mp_handle_pending(void); \
|
||||
mp_handle_pending(); \
|
||||
MICROPY_PY_USOCKET_EVENTS_HANDLER \
|
||||
asm("waiti 0"); \
|
||||
asm ("waiti 0"); \
|
||||
} while (0);
|
||||
#endif
|
||||
|
||||
|
@ -41,9 +41,9 @@ extern ringbuf_t stdin_ringbuf;
|
||||
|
||||
uint32_t mp_hal_ticks_us(void);
|
||||
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
|
||||
return ccount;
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));
|
||||
return ccount;
|
||||
}
|
||||
|
||||
void mp_hal_delay_us(uint32_t);
|
||||
|
@ -72,7 +72,7 @@ void mp_thread_init(void *stack, uint32_t stack_len) {
|
||||
void mp_thread_gc_others(void) {
|
||||
mp_thread_mutex_lock(&thread_mutex, 1);
|
||||
for (thread_t *th = thread; th != NULL; th = th->next) {
|
||||
gc_collect_root((void**)&th, 1);
|
||||
gc_collect_root((void **)&th, 1);
|
||||
gc_collect_root(&th->arg, 1); // probably not needed
|
||||
if (th->id == xTaskGetCurrentTaskHandle()) {
|
||||
continue;
|
||||
@ -104,17 +104,18 @@ void mp_thread_start(void) {
|
||||
mp_thread_mutex_unlock(&thread_mutex);
|
||||
}
|
||||
|
||||
STATIC void *(*ext_thread_entry)(void*) = NULL;
|
||||
STATIC void *(*ext_thread_entry)(void *) = NULL;
|
||||
|
||||
STATIC void freertos_entry(void *arg) {
|
||||
if (ext_thread_entry) {
|
||||
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) {
|
||||
void mp_thread_create_ex(void *(*entry)(void *), void *arg, size_t *stack_size, int priority, char *name) {
|
||||
// store thread entry function into a global variable so we can access it
|
||||
ext_thread_entry = entry;
|
||||
|
||||
@ -150,7 +151,7 @@ void mp_thread_create_ex(void *(*entry)(void*), void *arg, size_t *stack_size, i
|
||||
mp_thread_mutex_unlock(&thread_mutex);
|
||||
}
|
||||
|
||||
void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
|
||||
void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
|
||||
mp_thread_create_ex(entry, arg, stack_size, MP_THREAD_PRIORITY, "mp_thread");
|
||||
}
|
||||
|
||||
@ -170,7 +171,7 @@ void vPortCleanUpTCB(void *tcb) {
|
||||
mp_thread_mutex_lock(&thread_mutex, 1);
|
||||
for (thread_t *th = thread; th != NULL; prev = th, th = th->next) {
|
||||
// unlink the node from the list
|
||||
if ((void*)th->id == tcb) {
|
||||
if ((void *)th->id == tcb) {
|
||||
if (prev != NULL) {
|
||||
prev->next = th->next;
|
||||
} else {
|
||||
@ -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) {
|
||||
|
@ -54,7 +54,7 @@ const mp_obj_type_t lan_if_type;
|
||||
STATIC lan_if_obj_t lan_obj = {{&lan_if_type}, ESP_IF_ETH, false, false};
|
||||
|
||||
STATIC void phy_power_enable(bool enable) {
|
||||
lan_if_obj_t* self = &lan_obj;
|
||||
lan_if_obj_t *self = &lan_obj;
|
||||
|
||||
if (self->phy_power_pin != -1) {
|
||||
|
||||
@ -82,13 +82,13 @@ STATIC void phy_power_enable(bool enable) {
|
||||
}
|
||||
|
||||
STATIC void init_lan_rmii() {
|
||||
lan_if_obj_t* self = &lan_obj;
|
||||
lan_if_obj_t *self = &lan_obj;
|
||||
phy_rmii_configure_data_interface_pins();
|
||||
phy_rmii_smi_configure_pins(self->mdc_pin, self->mdio_pin);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
lan_if_obj_t* self = &lan_obj;
|
||||
lan_if_obj_t *self = &lan_obj;
|
||||
|
||||
if (self->initialized) {
|
||||
return MP_OBJ_FROM_PTR(&lan_obj);
|
||||
@ -199,5 +199,5 @@ STATIC MP_DEFINE_CONST_DICT(lan_if_locals_dict, lan_if_locals_dict_table);
|
||||
const mp_obj_type_t lan_if_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_LAN,
|
||||
.locals_dict = (mp_obj_dict_t*)&lan_if_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&lan_if_locals_dict,
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ typedef struct _ppp_if_obj_t {
|
||||
const mp_obj_type_t ppp_if_type;
|
||||
|
||||
static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
|
||||
ppp_if_obj_t* self = ctx;
|
||||
ppp_if_obj_t *self = ctx;
|
||||
struct netif *pppif = ppp_netif(self->pcb);
|
||||
|
||||
switch (err_code) {
|
||||
@ -98,14 +98,14 @@ static u32_t ppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
|
||||
}
|
||||
|
||||
static void pppos_client_task(void *self_in) {
|
||||
ppp_if_obj_t *self = (ppp_if_obj_t*)self_in;
|
||||
ppp_if_obj_t *self = (ppp_if_obj_t *)self_in;
|
||||
uint8_t buf[256];
|
||||
|
||||
while (ulTaskNotifyTake(pdTRUE, 0) == 0) {
|
||||
int err;
|
||||
int len = mp_stream_rw(self->stream, buf, sizeof(buf), &err, 0);
|
||||
if (len > 0) {
|
||||
pppos_input_tcpip(self->pcb, (u8_t*)buf, len);
|
||||
pppos_input_tcpip(self->pcb, (u8_t *)buf, len);
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
@ -158,7 +158,7 @@ STATIC mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ppp_active_obj, 1, 2, ppp_active);
|
||||
|
||||
STATIC mp_obj_t ppp_delete(mp_obj_t self_in) {
|
||||
ppp_if_obj_t* self = MP_OBJ_TO_PTR(self_in);
|
||||
ppp_if_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_t args[] = {self, mp_const_false};
|
||||
ppp_active(2, args);
|
||||
return mp_const_none;
|
||||
@ -174,10 +174,10 @@ STATIC mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
dns = dns_getserver(0);
|
||||
struct netif *pppif = ppp_netif(self->pcb);
|
||||
mp_obj_t tuple[4] = {
|
||||
netutils_format_ipv4_addr((uint8_t*)&pppif->ip_addr, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t*)&pppif->gw, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t*)&pppif->netmask, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t*)&dns, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&pppif->ip_addr, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&pppif->gw, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&pppif->netmask, NETUTILS_BIG),
|
||||
netutils_format_ipv4_addr((uint8_t *)&dns, NETUTILS_BIG),
|
||||
};
|
||||
return mp_obj_new_tuple(4, tuple);
|
||||
} else {
|
||||
@ -187,7 +187,7 @@ STATIC mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
} else {
|
||||
mp_obj_t *items;
|
||||
mp_obj_get_array_fixed_n(args[1], 4, &items);
|
||||
netutils_parse_ipv4_addr(items[3], (uint8_t*)&dns.u_addr.ip4, NETUTILS_BIG);
|
||||
netutils_parse_ipv4_addr(items[3], (uint8_t *)&dns.u_addr.ip4, NETUTILS_BIG);
|
||||
dns_setserver(0, &dns);
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -217,5 +217,5 @@ STATIC MP_DEFINE_CONST_DICT(ppp_if_locals_dict, ppp_if_locals_dict_table);
|
||||
const mp_obj_type_t ppp_if_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_PPP,
|
||||
.locals_dict = (mp_obj_dict_t*)&ppp_if_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&ppp_if_locals_dict,
|
||||
};
|
||||
|
@ -27,4 +27,4 @@
|
||||
// qstrs specific to this port, only needed if they aren't auto-generated
|
||||
|
||||
// Entries for sys.path
|
||||
Q(/lib)
|
||||
Q(/ lib)
|
||||
|
@ -36,20 +36,20 @@ void ets_printf(const char *fmt, ...);
|
||||
extern char flashchip;
|
||||
|
||||
static const uint8_t default_init_data[] __attribute__((aligned(4))) = {
|
||||
0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
|
||||
0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
|
||||
0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
|
||||
0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
|
||||
0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void firmware_start(void) {
|
||||
// For SDK 1.5.2, either address has shifted and not mirrored in
|
||||
// eagle.rom.addr.v6.ld, or extra initial member was added.
|
||||
SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
|
||||
SpiFlashChip *flash = (SpiFlashChip *)(&flashchip + 4);
|
||||
|
||||
char buf[128];
|
||||
SPIRead(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
|
||||
@ -73,5 +73,5 @@ void firmware_start(void) {
|
||||
SPIWrite(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
asm("j call_user_start");
|
||||
asm ("j call_user_start");
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ const mp_print_t mp_debug_print = {NULL, mp_hal_debug_tx_strn_cooked};
|
||||
int uart_attached_to_dupterm;
|
||||
|
||||
void mp_hal_init(void) {
|
||||
//ets_wdt_disable(); // it's a pain while developing
|
||||
// ets_wdt_disable(); // it's a pain while developing
|
||||
mp_hal_rtc_init();
|
||||
uart_init(UART_BIT_RATE_115200, UART_BIT_RATE_115200);
|
||||
uart_attached_to_dupterm = 0;
|
||||
@ -65,7 +65,7 @@ int mp_hal_stdin_rx_chr(void) {
|
||||
#if 0
|
||||
// Idles CPU but need more testing before enabling
|
||||
if (!ets_loop_iter()) {
|
||||
asm("waiti 0");
|
||||
asm ("waiti 0");
|
||||
}
|
||||
#else
|
||||
mp_hal_delay_us(1);
|
||||
@ -179,7 +179,7 @@ void mp_hal_signal_dupterm_input(void) {
|
||||
void *ets_get_esf_buf_ctlblk(void) {
|
||||
// Get literal ptr before start of esf_rx_buf_alloc func
|
||||
extern void *esf_rx_buf_alloc();
|
||||
return ((void**)esf_rx_buf_alloc)[-1];
|
||||
return ((void **)esf_rx_buf_alloc)[-1];
|
||||
}
|
||||
|
||||
// Get number of esf_buf free buffers of given type, as encoded by index
|
||||
@ -188,10 +188,10 @@ void *ets_get_esf_buf_ctlblk(void) {
|
||||
// 1 - tx buffer, 5 - management frame tx buffer; 8 - rx buffer
|
||||
int ets_esf_free_bufs(int idx) {
|
||||
uint32_t *p = ets_get_esf_buf_ctlblk();
|
||||
uint32_t *b = (uint32_t*)p[idx];
|
||||
uint32_t *b = (uint32_t *)p[idx];
|
||||
int cnt = 0;
|
||||
while (b) {
|
||||
b = (uint32_t*)b[0x20 / 4];
|
||||
b = (uint32_t *)b[0x20 / 4];
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
|
@ -48,9 +48,9 @@ void mp_hal_rtc_init(void);
|
||||
|
||||
uint32_t mp_hal_ticks_us(void);
|
||||
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
|
||||
return ccount;
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));
|
||||
return ccount;
|
||||
}
|
||||
|
||||
void mp_hal_delay_us(uint32_t);
|
||||
@ -86,16 +86,16 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin);
|
||||
#define mp_hal_pin_od_low(p) do { \
|
||||
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1) | 1); } \
|
||||
else { gpio_output_set(0, 1 << (p), 1 << (p), 0); } \
|
||||
} while (0)
|
||||
} while (0)
|
||||
#define mp_hal_pin_od_high(p) do { \
|
||||
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
|
||||
else { gpio_output_set(0, 0, 0, 1 << (p)); /* set as input to avoid glitches */ } \
|
||||
} while (0)
|
||||
} while (0)
|
||||
// The DHT driver requires using the open-drain feature of the GPIO to get it to work reliably
|
||||
#define mp_hal_pin_od_high_dht(p) do { \
|
||||
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
|
||||
else { gpio_output_set(1 << (p), 0, 1 << (p), 0); } \
|
||||
} while (0)
|
||||
} while (0)
|
||||
#define mp_hal_pin_read(p) pin_get(p)
|
||||
#define mp_hal_pin_write(p, v) pin_set((p), (v))
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "user_interface.h"
|
||||
#include "espapa102.h"
|
||||
|
||||
#define NOP asm volatile(" nop \n\t")
|
||||
#define NOP asm volatile (" nop \n\t")
|
||||
|
||||
static inline void _esp_apa102_send_byte(uint32_t clockPinMask, uint32_t dataPinMask, uint8_t byte) {
|
||||
for (uint32_t i = 0; i < 8; i++) {
|
||||
|
@ -18,48 +18,58 @@
|
||||
|
||||
void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) {
|
||||
|
||||
uint8_t *p, *end, pix, mask;
|
||||
uint32_t t, time0, time1, period, c, startTime, pinMask;
|
||||
uint8_t *p, *end, pix, mask;
|
||||
uint32_t t, time0, time1, period, c, startTime, pinMask;
|
||||
|
||||
pinMask = 1 << pin;
|
||||
p = pixels;
|
||||
end = p + numBytes;
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
startTime = 0;
|
||||
pinMask = 1 << pin;
|
||||
p = pixels;
|
||||
end = p + numBytes;
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
startTime = 0;
|
||||
|
||||
uint32_t fcpu = system_get_cpu_freq() * 1000000;
|
||||
uint32_t fcpu = system_get_cpu_freq() * 1000000;
|
||||
|
||||
#ifdef NEO_KHZ400
|
||||
if(is800KHz) {
|
||||
#endif
|
||||
time0 = fcpu / 2857143; // 0.35us
|
||||
time1 = fcpu / 1250000; // 0.8us
|
||||
period = fcpu / 800000; // 1.25us per bit
|
||||
#ifdef NEO_KHZ400
|
||||
} else { // 400 KHz bitstream
|
||||
time0 = fcpu / 2000000; // 0.5uS
|
||||
time1 = fcpu / 833333; // 1.2us
|
||||
period = fcpu / 400000; // 2.5us per bit
|
||||
}
|
||||
#endif
|
||||
#ifdef NEO_KHZ400
|
||||
if (is800KHz) {
|
||||
#endif
|
||||
time0 = fcpu / 2857143; // 0.35us
|
||||
time1 = fcpu / 1250000; // 0.8us
|
||||
period = fcpu / 800000; // 1.25us per bit
|
||||
#ifdef NEO_KHZ400
|
||||
} else { // 400 KHz bitstream
|
||||
time0 = fcpu / 2000000; // 0.5uS
|
||||
time1 = fcpu / 833333; // 1.2us
|
||||
period = fcpu / 400000; // 2.5us per bit
|
||||
}
|
||||
#endif
|
||||
|
||||
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
|
||||
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
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
|
||||
if(!(mask >>= 1)) { // Next bit/byte
|
||||
if(p >= end) break;
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
|
||||
if (!(mask >>= 1)) { // Next bit/byte
|
||||
if (p >= end) {
|
||||
break;
|
||||
}
|
||||
pix = *p++;
|
||||
mask = 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
|
||||
mp_hal_quiet_timing_exit(irq_state);
|
||||
while ((mp_hal_ticks_cpu() - startTime) < period) {
|
||||
; // Wait for last bit
|
||||
}
|
||||
mp_hal_quiet_timing_exit(irq_state);
|
||||
}
|
||||
|
||||
#endif // MICROPY_ESP8266_NEOPIXEL
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "py/mpprint.h"
|
||||
#define PWM_DBG(...)
|
||||
//#define PWM_DBG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
|
||||
// #define PWM_DBG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
|
||||
|
||||
#define ICACHE_RAM_ATTR // __attribute__((section(".text")))
|
||||
|
||||
@ -58,15 +58,15 @@ STATIC uint8_t pwm_current_channel = 0;
|
||||
STATIC uint16_t pwm_gpio = 0;
|
||||
STATIC uint8_t pwm_channel_num = 0;
|
||||
|
||||
//XXX: 0xffffffff/(80000000/16)=35A
|
||||
// XXX: 0xffffffff/(80000000/16)=35A
|
||||
#define US_TO_RTC_TIMER_TICKS(t) \
|
||||
((t) ? \
|
||||
(((t) > 0x35A) ? \
|
||||
(((t)>>2) * ((APB_CLK_FREQ>>4)/250000) + ((t)&0x3) * ((APB_CLK_FREQ>>4)/1000000)) : \
|
||||
(((t) *(APB_CLK_FREQ>>4)) / 1000000)) : \
|
||||
0)
|
||||
(((t) > 0x35A) ? \
|
||||
(((t) >> 2) * ((APB_CLK_FREQ >> 4) / 250000) + ((t) & 0x3) * ((APB_CLK_FREQ >> 4) / 1000000)) : \
|
||||
(((t) * (APB_CLK_FREQ >> 4)) / 1000000)) : \
|
||||
0)
|
||||
|
||||
//FRC1
|
||||
// FRC1
|
||||
#define FRC1_ENABLE_TIMER BIT7
|
||||
|
||||
typedef enum {
|
||||
@ -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++) {
|
||||
@ -109,17 +108,16 @@ pwm_insert_sort(struct pwm_single_param pwm[], uint8 n)
|
||||
STATIC volatile uint8 critical = 0;
|
||||
|
||||
#define LOCK_PWM(c) do { \
|
||||
while( (c)==1 ); \
|
||||
(c) = 1; \
|
||||
while ((c) == 1); \
|
||||
(c) = 1; \
|
||||
} while (0)
|
||||
|
||||
#define UNLOCK_PWM(c) do { \
|
||||
(c) = 0; \
|
||||
(c) = 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);
|
||||
@ -169,7 +167,7 @@ pwm_start(void)
|
||||
}
|
||||
|
||||
// step 5: last channel needs to clean
|
||||
local_single[*local_channel-1].gpio_clear = 0;
|
||||
local_single[*local_channel - 1].gpio_clear = 0;
|
||||
|
||||
// step 6: if first channel duty is 0, remove it
|
||||
if (local_single[0].h_time == 0) {
|
||||
@ -212,17 +210,17 @@ 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){
|
||||
for (i = 0; i < pwm_channel_num; i++) {
|
||||
if (pwm_out_io_num[i] == channel) {
|
||||
channel = i;
|
||||
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,17 +261,17 @@ 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){
|
||||
for (i = 0; i < pwm_channel_num; i++) {
|
||||
if (pwm_out_io_num[i] == channel) {
|
||||
channel = i;
|
||||
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);
|
||||
@ -310,17 +305,17 @@ pwm_tim1_intr_handler(void *dummy)
|
||||
pwm_channel = &pwm_channel_toggle[local_toggle];
|
||||
|
||||
gpio_output_set(pwm_single[*pwm_channel - 1].gpio_set,
|
||||
pwm_single[*pwm_channel - 1].gpio_clear,
|
||||
pwm_gpio,
|
||||
0);
|
||||
pwm_single[*pwm_channel - 1].gpio_clear,
|
||||
pwm_gpio,
|
||||
0);
|
||||
|
||||
pwm_current_channel = 0;
|
||||
|
||||
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
|
||||
} else {
|
||||
gpio_output_set(pwm_single[pwm_current_channel].gpio_set,
|
||||
pwm_single[pwm_current_channel].gpio_clear,
|
||||
pwm_gpio, 0);
|
||||
pwm_single[pwm_current_channel].gpio_clear,
|
||||
pwm_gpio, 0);
|
||||
|
||||
pwm_current_channel++;
|
||||
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
|
||||
@ -335,14 +330,13 @@ 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|
|
||||
DIVDED_BY_16
|
||||
| FRC1_ENABLE_TIMER
|
||||
| TM_EDGE_INT);
|
||||
RTC_REG_WRITE(FRC1_CTRL_ADDRESS, // FRC2_AUTO_RELOAD|
|
||||
DIVDED_BY_16
|
||||
| FRC1_ENABLE_TIMER
|
||||
| TM_EDGE_INT);
|
||||
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 0);
|
||||
|
||||
for (i = 0; i < PWM_CHANNEL; i++) {
|
||||
@ -359,7 +353,7 @@ pwm_init(void)
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR
|
||||
pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func){
|
||||
pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func) {
|
||||
PWM_DBG("--Function pwm_add() is called. channel:%d\n", channel);
|
||||
PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
|
||||
PWM_DBG("pwm_out_io_num[0]:%d,[1]:%d,[2]:%d\n",pwm_out_io_num[0],pwm_out_io_num[1],pwm_out_io_num[2]);
|
||||
@ -375,16 +369,17 @@ pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func){
|
||||
return -1;
|
||||
}
|
||||
uint8 i;
|
||||
for(i=0;i<PWM_CHANNEL;i++){
|
||||
if(pwm_out_io_num[i]==channel) // already exist
|
||||
for (i = 0; i < PWM_CHANNEL; i++) {
|
||||
if (pwm_out_io_num[i] == channel) { // already exist
|
||||
return channel;
|
||||
if(pwm_out_io_num[i] == -1){ // empty exist
|
||||
}
|
||||
if (pwm_out_io_num[i] == -1) { // empty exist
|
||||
LOCK_PWM(critical); // enter critical
|
||||
pwm_out_io_num[i] = channel;
|
||||
pwm.duty[i] = 0;
|
||||
pwm_gpio |= (1 << pin_num[channel]);
|
||||
PIN_FUNC_SELECT(pin_mux, pin_func);
|
||||
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain;
|
||||
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel]))) & (~GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); // disable open drain;
|
||||
pwm_channel_num++;
|
||||
UNLOCK_PWM(critical); // leave critical
|
||||
return channel;
|
||||
@ -394,23 +389,23 @@ pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func){
|
||||
}
|
||||
|
||||
bool ICACHE_FLASH_ATTR
|
||||
pwm_delete(uint8 channel){
|
||||
pwm_delete(uint8 channel) {
|
||||
PWM_DBG("--Function pwm_delete() is called. channel:%d\n", channel);
|
||||
PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
|
||||
PWM_DBG("pwm_out_io_num[0]:%d,[1]:%d,[2]:%d\n",pwm_out_io_num[0],pwm_out_io_num[1],pwm_out_io_num[2]);
|
||||
PWM_DBG("pwm.duty[0]:%d,[1]:%d,[2]:%d\n",pwm.duty[0],pwm.duty[1],pwm.duty[2]);
|
||||
uint8 i,j;
|
||||
for(i=0;i<pwm_channel_num;i++){
|
||||
if(pwm_out_io_num[i]==channel){ // exist
|
||||
for (i = 0; i < pwm_channel_num; i++) {
|
||||
if (pwm_out_io_num[i] == channel) { // exist
|
||||
LOCK_PWM(critical); // enter critical
|
||||
pwm_out_io_num[i] = -1;
|
||||
pwm_gpio &= ~(1 << pin_num[channel]); //clear the bit
|
||||
for(j=i;j<pwm_channel_num-1;j++){
|
||||
pwm_out_io_num[j] = pwm_out_io_num[j+1];
|
||||
pwm.duty[j] = pwm.duty[j+1];
|
||||
pwm_gpio &= ~(1 << pin_num[channel]); // clear the bit
|
||||
for (j = i; j < pwm_channel_num - 1; j++) {
|
||||
pwm_out_io_num[j] = pwm_out_io_num[j + 1];
|
||||
pwm.duty[j] = pwm.duty[j + 1];
|
||||
}
|
||||
pwm_out_io_num[pwm_channel_num-1] = -1;
|
||||
pwm.duty[pwm_channel_num-1] = 0;
|
||||
pwm_out_io_num[pwm_channel_num - 1] = -1;
|
||||
pwm.duty[pwm_channel_num - 1] = 0;
|
||||
pwm_channel_num--;
|
||||
UNLOCK_PWM(critical); // leave critical
|
||||
return true;
|
||||
|
@ -25,9 +25,9 @@ static void (*idle_cb)(void *);
|
||||
static void *idle_arg;
|
||||
|
||||
#if ESP_SDK_VERSION >= 010500
|
||||
# define FIRST_PRIO 0
|
||||
#define FIRST_PRIO 0
|
||||
#else
|
||||
# define FIRST_PRIO 0x14
|
||||
#define FIRST_PRIO 0x14
|
||||
#endif
|
||||
#define LAST_PRIO 0x20
|
||||
#define PRIO2ID(prio) ((prio) - FIRST_PRIO)
|
||||
@ -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;
|
||||
}
|
||||
@ -62,9 +64,9 @@ void dump_tasks(void) {
|
||||
bool ets_task(os_task_t task, uint8 prio, os_event_t *queue, uint8 qlen) {
|
||||
static unsigned cnt;
|
||||
printf("#%d ets_task(%p, %d, %p, %d)\n", cnt++, task, prio, queue, qlen);
|
||||
#if USE_ETS_TASK
|
||||
#if USE_ETS_TASK
|
||||
return _ets_task(task, prio, queue, qlen);
|
||||
#else
|
||||
#else
|
||||
int id = prio2id(prio);
|
||||
emu_tasks[id].task = task;
|
||||
emu_tasks[id].queue = queue;
|
||||
@ -72,14 +74,14 @@ bool ets_task(os_task_t task, uint8 prio, os_event_t *queue, uint8 qlen) {
|
||||
emu_tasks[id].i_get = 0;
|
||||
emu_tasks[id].i_put = 0;
|
||||
return true;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ets_post(uint8 prio, os_signal_t sig, os_param_t param) {
|
||||
// static unsigned cnt; printf("#%d ets_post(%d, %x, %x)\n", cnt++, prio, sig, param);
|
||||
#if USE_ETS_TASK
|
||||
#if USE_ETS_TASK
|
||||
return _ets_post(prio, sig, param);
|
||||
#else
|
||||
#else
|
||||
ets_intr_lock();
|
||||
|
||||
const int id = prio2id(prio);
|
||||
@ -99,13 +101,13 @@ bool ets_post(uint8 prio, os_signal_t sig, os_param_t param) {
|
||||
// queue got full
|
||||
emu_tasks[id].i_put = -1;
|
||||
}
|
||||
//printf("after ets_post: "); dump_task(prio, &emu_tasks[id]);
|
||||
//dump_tasks();
|
||||
// printf("after ets_post: "); dump_task(prio, &emu_tasks[id]);
|
||||
// dump_tasks();
|
||||
|
||||
ets_intr_unlock();
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
int ets_loop_iter_disable = 0;
|
||||
@ -135,17 +137,17 @@ bool ets_loop_iter(void) {
|
||||
extern uint32_t pend_flag_noise_check;
|
||||
uint32_t *sw_wdt = &pend_flag_noise_check - 6;
|
||||
|
||||
//static unsigned cnt;
|
||||
// static unsigned cnt;
|
||||
bool progress = false;
|
||||
for (volatile struct task_entry *t = emu_tasks; t < &emu_tasks[MP_ARRAY_SIZE(emu_tasks)]; t++) {
|
||||
if (!ets_loop_dont_feed_sw_wdt) {
|
||||
system_soft_wdt_feed();
|
||||
}
|
||||
ets_intr_lock();
|
||||
//printf("etc_loop_iter: "); dump_task(t - emu_tasks + FIRST_PRIO, t);
|
||||
// printf("etc_loop_iter: "); dump_task(t - emu_tasks + FIRST_PRIO, t);
|
||||
if (t->i_get != t->i_put) {
|
||||
progress = true;
|
||||
//printf("#%d Calling task %d(%p) (%x, %x)\n", cnt++,
|
||||
// printf("#%d Calling task %d(%p) (%x, %x)\n", cnt++,
|
||||
// t - emu_tasks + FIRST_PRIO, t->task, t->queue[t->i_get].sig, t->queue[t->i_get].par);
|
||||
int idx = t->i_get;
|
||||
if (t->i_put == -1) {
|
||||
@ -154,15 +156,15 @@ bool ets_loop_iter(void) {
|
||||
if (++t->i_get == t->qlen) {
|
||||
t->i_get = 0;
|
||||
}
|
||||
//ets_intr_unlock();
|
||||
// ets_intr_unlock();
|
||||
uint32_t old_sw_wdt = *sw_wdt;
|
||||
t->task(&t->queue[idx]);
|
||||
if (ets_loop_dont_feed_sw_wdt) {
|
||||
// Restore previous SW WDT counter, in case task fed/cleared it
|
||||
*sw_wdt = old_sw_wdt;
|
||||
}
|
||||
//ets_intr_lock();
|
||||
//printf("Done calling task %d\n", t - emu_tasks + FIRST_PRIO);
|
||||
// ets_intr_lock();
|
||||
// printf("Done calling task %d\n", t - emu_tasks + FIRST_PRIO);
|
||||
}
|
||||
ets_intr_unlock();
|
||||
}
|
||||
@ -188,7 +190,7 @@ void ets_timer_init() {
|
||||
ets_isr_attach(10, my_timer_isr, NULL);
|
||||
SET_PERI_REG_MASK(0x3FF00004, 4);
|
||||
ETS_INTR_ENABLE(10);
|
||||
ets_task((os_task_t)0x40002E3C, 0x1f, (os_event_t*)0x3FFFDDC0, 4);
|
||||
ets_task((os_task_t)0x40002E3C, 0x1f, (os_event_t *)0x3FFFDDC0, 4);
|
||||
|
||||
WRITE_PERI_REG(PERIPHS_TIMER_BASEDDR + 0x30, 0);
|
||||
WRITE_PERI_REG(PERIPHS_TIMER_BASEDDR + 0x28, 0x88);
|
||||
@ -198,36 +200,36 @@ void ets_timer_init() {
|
||||
#endif
|
||||
|
||||
bool ets_run(void) {
|
||||
#if USE_ETS_TASK
|
||||
#if USE_ETS_TASK
|
||||
#if SDK_BELOW_1_1_1
|
||||
ets_isr_attach(10, my_timer_isr, NULL);
|
||||
#endif
|
||||
_ets_run();
|
||||
#else
|
||||
#else
|
||||
// ets_timer_init();
|
||||
*(char*)0x3FFFC6FC = 0;
|
||||
*(char *)0x3FFFC6FC = 0;
|
||||
ets_intr_lock();
|
||||
printf("ets_alt_task: ets_run\n");
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
dump_tasks();
|
||||
#endif
|
||||
#endif
|
||||
ets_intr_unlock();
|
||||
while (1) {
|
||||
if (!ets_loop_iter()) {
|
||||
//printf("idle\n");
|
||||
// printf("idle\n");
|
||||
ets_intr_lock();
|
||||
if (idle_cb) {
|
||||
idle_cb(idle_arg);
|
||||
}
|
||||
asm("waiti 0");
|
||||
asm ("waiti 0");
|
||||
ets_intr_unlock();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void ets_set_idle_cb(void (*handler)(void *), void *arg) {
|
||||
//printf("ets_set_idle_cb(%p, %p)\n", handler, arg);
|
||||
// printf("ets_set_idle_cb(%p, %p)\n", handler, arg);
|
||||
idle_cb = handler;
|
||||
idle_arg = arg;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <os_type.h>
|
||||
|
||||
// see http://esp8266-re.foogod.com/wiki/Random_Number_Generator
|
||||
#define WDEV_HWRNG ((volatile uint32_t*)0x3ff20e44)
|
||||
#define WDEV_HWRNG ((volatile uint32_t *)0x3ff20e44)
|
||||
|
||||
void ets_delay_us(uint16_t us);
|
||||
void ets_intr_lock(void);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ void gc_collect(void) {
|
||||
mp_uint_t sp = gc_helper_get_regs_and_sp(regs);
|
||||
|
||||
// trace the stack, including the registers (since they live on the stack in this function)
|
||||
gc_collect_root((void**)sp, (STACK_END - sp) / sizeof(uint32_t));
|
||||
gc_collect_root((void **)sp, (STACK_END - sp) / sizeof(uint32_t));
|
||||
|
||||
// end the GC
|
||||
gc_collect_end();
|
||||
|
@ -27,28 +27,28 @@
|
||||
#include "py/builtin.h"
|
||||
|
||||
const char esp_help_text[] =
|
||||
"Welcome to MicroPython!\n"
|
||||
"\n"
|
||||
"For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n"
|
||||
"For diagnostic information to include in bug reports execute 'import port_diag'.\n"
|
||||
"\n"
|
||||
"Basic WiFi configuration:\n"
|
||||
"\n"
|
||||
"import network\n"
|
||||
"sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
|
||||
"sta_if.scan() # Scan for available access points\n"
|
||||
"sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
|
||||
"sta_if.isconnected() # Check for successful connection\n"
|
||||
"# Change name/password of ESP8266's AP:\n"
|
||||
"ap_if = network.WLAN(network.AP_IF)\n"
|
||||
"ap_if.config(essid=\"<AP_NAME>\", authmode=network.AUTH_WPA_WPA2_PSK, password=\"<password>\")\n"
|
||||
"\n"
|
||||
"Control commands:\n"
|
||||
" CTRL-A -- on a blank line, enter raw REPL mode\n"
|
||||
" CTRL-B -- on a blank line, enter normal REPL mode\n"
|
||||
" CTRL-C -- interrupt a running program\n"
|
||||
" CTRL-D -- on a blank line, do a soft reset of the board\n"
|
||||
" CTRL-E -- on a blank line, enter paste mode\n"
|
||||
"\n"
|
||||
"For further help on a specific object, type help(obj)\n"
|
||||
"Welcome to MicroPython!\n"
|
||||
"\n"
|
||||
"For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n"
|
||||
"For diagnostic information to include in bug reports execute 'import port_diag'.\n"
|
||||
"\n"
|
||||
"Basic WiFi configuration:\n"
|
||||
"\n"
|
||||
"import network\n"
|
||||
"sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
|
||||
"sta_if.scan() # Scan for available access points\n"
|
||||
"sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
|
||||
"sta_if.isconnected() # Check for successful connection\n"
|
||||
"# Change name/password of ESP8266's AP:\n"
|
||||
"ap_if = network.WLAN(network.AP_IF)\n"
|
||||
"ap_if.config(essid=\"<AP_NAME>\", authmode=network.AUTH_WPA_WPA2_PSK, password=\"<password>\")\n"
|
||||
"\n"
|
||||
"Control commands:\n"
|
||||
" CTRL-A -- on a blank line, enter raw REPL mode\n"
|
||||
" CTRL-B -- on a blank line, enter normal REPL mode\n"
|
||||
" CTRL-C -- interrupt a running program\n"
|
||||
" CTRL-D -- on a blank line, do a soft reset of the board\n"
|
||||
" CTRL-E -- on a blank line, enter paste mode\n"
|
||||
"\n"
|
||||
"For further help on a specific object, type help(obj)\n"
|
||||
;
|
||||
|
@ -36,7 +36,7 @@ void spi_init(uint8_t spi_no) {
|
||||
spi_tx_byte_order(spi_no, SPI_BYTE_ORDER_HIGH_TO_LOW);
|
||||
spi_rx_byte_order(spi_no, SPI_BYTE_ORDER_HIGH_TO_LOW);
|
||||
|
||||
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD);
|
||||
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP | SPI_CS_HOLD);
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE);
|
||||
}
|
||||
|
||||
@ -84,14 +84,14 @@ void spi_init_gpio(uint8_t spi_no, uint8_t sysclk_as_spiclk) {
|
||||
}
|
||||
if (spi_no == SPI) {
|
||||
// Set bit 8 if 80MHz sysclock required
|
||||
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005 | (clock_div_flag<<8));
|
||||
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005 | (clock_div_flag << 8));
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 1);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, 1);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, 1);
|
||||
} else if (spi_no == HSPI) {
|
||||
// Set bit 9 if 80MHz sysclock required
|
||||
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105 | (clock_div_flag<<9));
|
||||
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105 | (clock_div_flag << 9));
|
||||
// GPIO12 is HSPI MISO pin (Master Data In)
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);
|
||||
// GPIO13 is HSPI MOSI pin (Master Data Out)
|
||||
@ -117,11 +117,11 @@ void spi_clock(uint8_t spi_no, uint16_t prediv, uint8_t cntdiv) {
|
||||
WRITE_PERI_REG(SPI_CLOCK(spi_no), SPI_CLK_EQU_SYSCLK);
|
||||
} else {
|
||||
WRITE_PERI_REG(SPI_CLOCK(spi_no),
|
||||
(((prediv - 1) & SPI_CLKDIV_PRE) << SPI_CLKDIV_PRE_S) |
|
||||
(((cntdiv - 1) & SPI_CLKCNT_N) << SPI_CLKCNT_N_S) |
|
||||
(((cntdiv >> 1) & SPI_CLKCNT_H) << SPI_CLKCNT_H_S) |
|
||||
((0 & SPI_CLKCNT_L) << SPI_CLKCNT_L_S)
|
||||
);
|
||||
(((prediv - 1) & SPI_CLKDIV_PRE) << SPI_CLKDIV_PRE_S) |
|
||||
(((cntdiv - 1) & SPI_CLKCNT_N) << SPI_CLKCNT_N_S) |
|
||||
(((cntdiv >> 1) & SPI_CLKCNT_H) << SPI_CLKCNT_H_S) |
|
||||
((0 & SPI_CLKCNT_L) << SPI_CLKCNT_L_S)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,15 +185,17 @@ Note: all data is assumed to be stored in the lower bits of the data variables
|
||||
(for anything <32 bits).
|
||||
*/
|
||||
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
|
||||
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
|
||||
|
||||
// Enable SPI Functions
|
||||
// Disable MOSI, MISO, ADDR, COMMAND, DUMMY in case previously set.
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI | SPI_USR_MISO |
|
||||
SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
|
||||
SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
|
||||
|
||||
// Enable functions based on number of bits. 0 bits = disabled.
|
||||
// This is rather inefficient but allows for a very generic function.
|
||||
@ -213,25 +215,25 @@ uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
|
||||
WRITE_PERI_REG(SPI_USER1(spi_no),
|
||||
// Number of bits in Address
|
||||
((addr_bits - 1) & SPI_USR_ADDR_BITLEN) << SPI_USR_ADDR_BITLEN_S |
|
||||
// Number of bits to Send
|
||||
((dout_bits - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
|
||||
// Number of bits to receive
|
||||
((din_bits - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S |
|
||||
// Number of Dummy bits to insert
|
||||
((dummy_bits - 1) & SPI_USR_DUMMY_CYCLELEN) << SPI_USR_DUMMY_CYCLELEN_S);
|
||||
// Number of bits to Send
|
||||
((dout_bits - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
|
||||
// Number of bits to receive
|
||||
((din_bits - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S |
|
||||
// Number of Dummy bits to insert
|
||||
((dummy_bits - 1) & SPI_USR_DUMMY_CYCLELEN) << SPI_USR_DUMMY_CYCLELEN_S);
|
||||
|
||||
// Setup Command Data
|
||||
if (cmd_bits) {
|
||||
// Enable COMMAND function in SPI module
|
||||
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_COMMAND);
|
||||
// Align command data to high bits
|
||||
uint16_t command = cmd_data << (16-cmd_bits);
|
||||
uint16_t command = cmd_data << (16 - cmd_bits);
|
||||
// Swap byte order
|
||||
command = ((command>>8)&0xff) | ((command<<8)&0xff00);
|
||||
command = ((command >> 8) & 0xff) | ((command << 8) & 0xff00);
|
||||
WRITE_PERI_REG(SPI_USER2(spi_no), (
|
||||
(((cmd_bits - 1) & SPI_USR_COMMAND_BITLEN) << SPI_USR_COMMAND_BITLEN_S) |
|
||||
(command & SPI_USR_COMMAND_VALUE)
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
// Setup Address Data
|
||||
@ -246,42 +248,44 @@ uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
|
||||
if (dout_bits) {
|
||||
// Enable MOSI function in SPI module
|
||||
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI);
|
||||
// Copy data to W0
|
||||
if (READ_PERI_REG(SPI_USER(spi_no))&SPI_WR_BYTE_ORDER) {
|
||||
WRITE_PERI_REG(SPI_W0(spi_no), dout_data << (32 - dout_bits));
|
||||
} else {
|
||||
uint8_t dout_extra_bits = dout_bits%8;
|
||||
|
||||
if (dout_extra_bits) {
|
||||
// If your data isn't a byte multiple (8/16/24/32 bits) and you
|
||||
// don't have SPI_WR_BYTE_ORDER set, you need this to move the
|
||||
// non-8bit remainder to the MSBs. Not sure if there's even a use
|
||||
// case for this, but it's here if you need it... For example,
|
||||
// 0xDA4 12 bits without SPI_WR_BYTE_ORDER would usually be output
|
||||
// as if it were 0x0DA4, of which 0xA4, and then 0x0 would be
|
||||
// shifted out (first 8 bits of low byte, then 4 MSB bits of high
|
||||
// byte - ie reverse byte order).
|
||||
// The code below shifts it out as 0xA4 followed by 0xD as you
|
||||
// might require.
|
||||
WRITE_PERI_REG(SPI_W0(spi_no), (
|
||||
(0xFFFFFFFF << (dout_bits - dout_extra_bits) & dout_data)
|
||||
<< (8-dout_extra_bits) |
|
||||
((0xFFFFFFFF >> (32 - (dout_bits - dout_extra_bits)))
|
||||
& dout_data)
|
||||
));
|
||||
// Copy data to W0
|
||||
if (READ_PERI_REG(SPI_USER(spi_no)) & SPI_WR_BYTE_ORDER) {
|
||||
WRITE_PERI_REG(SPI_W0(spi_no), dout_data << (32 - dout_bits));
|
||||
} else {
|
||||
WRITE_PERI_REG(SPI_W0(spi_no), dout_data);
|
||||
uint8_t dout_extra_bits = dout_bits % 8;
|
||||
|
||||
if (dout_extra_bits) {
|
||||
// If your data isn't a byte multiple (8/16/24/32 bits) and you
|
||||
// don't have SPI_WR_BYTE_ORDER set, you need this to move the
|
||||
// non-8bit remainder to the MSBs. Not sure if there's even a use
|
||||
// case for this, but it's here if you need it... For example,
|
||||
// 0xDA4 12 bits without SPI_WR_BYTE_ORDER would usually be output
|
||||
// as if it were 0x0DA4, of which 0xA4, and then 0x0 would be
|
||||
// shifted out (first 8 bits of low byte, then 4 MSB bits of high
|
||||
// byte - ie reverse byte order).
|
||||
// The code below shifts it out as 0xA4 followed by 0xD as you
|
||||
// might require.
|
||||
WRITE_PERI_REG(SPI_W0(spi_no), (
|
||||
(0xFFFFFFFF << (dout_bits - dout_extra_bits) & dout_data)
|
||||
<< (8 - dout_extra_bits) |
|
||||
((0xFFFFFFFF >> (32 - (dout_bits - dout_extra_bits)))
|
||||
& dout_data)
|
||||
));
|
||||
} else {
|
||||
WRITE_PERI_REG(SPI_W0(spi_no), dout_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Begin SPI Transaction
|
||||
SET_PERI_REG_MASK(SPI_CMD(spi_no), SPI_USR);
|
||||
|
||||
// Return DIN data
|
||||
if (din_bits) {
|
||||
while (spi_busy(spi_no)) {}; // Wait for SPI transaction to complete
|
||||
if (READ_PERI_REG(SPI_USER(spi_no))&SPI_RD_BYTE_ORDER) {
|
||||
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);
|
||||
} else {
|
||||
@ -301,19 +305,21 @@ 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.
|
||||
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI | SPI_USR_MISO |
|
||||
SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
|
||||
SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
|
||||
|
||||
// Setup Bitlengths
|
||||
WRITE_PERI_REG(SPI_USER1(spi_no),
|
||||
// Number of bits to Send
|
||||
((8 - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
|
||||
// Number of bits to receive
|
||||
((8 - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S);
|
||||
// Number of bits to receive
|
||||
((8 - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S);
|
||||
|
||||
|
||||
// Setup DOUT data
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user