mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
This commit is contained in:
@@ -99,7 +99,7 @@ static int dhcp_socket_new_dgram(struct udp_pcb **udp, void *cb_data, udp_recv_f
|
||||
}
|
||||
|
||||
// Register callback
|
||||
udp_recv(*udp, cb_udp_recv, (void*)cb_data);
|
||||
udp_recv(*udp, cb_udp_recv, (void *)cb_data);
|
||||
|
||||
return 0; // success
|
||||
}
|
||||
@@ -202,7 +202,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
dhcp_msg.op = DHCPOFFER;
|
||||
memcpy(&dhcp_msg.yiaddr, &d->ip.addr, 4);
|
||||
|
||||
uint8_t *opt = (uint8_t*)&dhcp_msg.options;
|
||||
uint8_t *opt = (uint8_t *)&dhcp_msg.options;
|
||||
opt += 4; // assume magic cookie: 99, 130, 83, 99
|
||||
|
||||
switch (opt[2]) {
|
||||
@@ -281,7 +281,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have mulitple addresses
|
||||
opt_write_u32(&opt, DHCP_OPT_IP_LEASE_TIME, DEFAULT_LEASE_TIME_S);
|
||||
*opt++ = DHCP_OPT_END;
|
||||
dhcp_socket_sendto(&d->udp, &dhcp_msg, opt - (uint8_t*)&dhcp_msg, 0xffffffff, PORT_DHCP_CLIENT);
|
||||
dhcp_socket_sendto(&d->udp, &dhcp_msg, opt - (uint8_t *)&dhcp_msg, 0xffffffff, PORT_DHCP_CLIENT);
|
||||
|
||||
ignore_request:
|
||||
pbuf_free(p);
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -44,10 +44,14 @@ static void dump_hex_bytes(const mp_print_t *print, size_t len, const uint8_t *b
|
||||
static const char *ethertype_str(uint16_t type) {
|
||||
// A value between 0x0000 - 0x05dc (inclusive) indicates a length, not type
|
||||
switch (type) {
|
||||
case 0x0800: return "IPv4";
|
||||
case 0x0806: return "ARP";
|
||||
case 0x86dd: return "IPv6";
|
||||
default: return NULL;
|
||||
case 0x0800:
|
||||
return "IPv4";
|
||||
case 0x0806:
|
||||
return "ARP";
|
||||
case 0x86dd:
|
||||
return "IPv6";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,14 +117,30 @@ void netutils_ethernet_trace(const mp_print_t *print, size_t len, const uint8_t
|
||||
buf += n;
|
||||
mp_printf(print, " opts:");
|
||||
switch (buf[6]) {
|
||||
case 1: mp_printf(print, " DISCOVER"); break;
|
||||
case 2: mp_printf(print, " OFFER"); break;
|
||||
case 3: mp_printf(print, " REQUEST"); break;
|
||||
case 4: mp_printf(print, " DECLINE"); break;
|
||||
case 5: mp_printf(print, " ACK"); break;
|
||||
case 6: mp_printf(print, " NACK"); break;
|
||||
case 7: mp_printf(print, " RELEASE"); break;
|
||||
case 8: mp_printf(print, " INFORM"); break;
|
||||
case 1:
|
||||
mp_printf(print, " DISCOVER");
|
||||
break;
|
||||
case 2:
|
||||
mp_printf(print, " OFFER");
|
||||
break;
|
||||
case 3:
|
||||
mp_printf(print, " REQUEST");
|
||||
break;
|
||||
case 4:
|
||||
mp_printf(print, " DECLINE");
|
||||
break;
|
||||
case 5:
|
||||
mp_printf(print, " ACK");
|
||||
break;
|
||||
case 6:
|
||||
mp_printf(print, " NACK");
|
||||
break;
|
||||
case 7:
|
||||
mp_printf(print, " RELEASE");
|
||||
break;
|
||||
case 8:
|
||||
mp_printf(print, " INFORM");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -89,7 +89,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;
|
||||
@@ -122,7 +122,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 {
|
||||
@@ -141,8 +141,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
|
||||
@@ -316,10 +316,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;
|
||||
@@ -335,13 +335,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;
|
||||
repl.paste_mode = false;
|
||||
@@ -419,11 +419,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 {
|
||||
@@ -103,9 +103,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)},
|
||||
@@ -134,7 +134,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};
|
||||
@@ -144,7 +144,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;
|
||||
}
|
||||
@@ -168,7 +168,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
|
||||
|
||||
Reference in New Issue
Block a user