Commit 7f9d1d6a authored by Damien George's avatar Damien George
Browse files

py: Overhaul and simplify printf/pfenv mechanism.

Previous to this patch the printing mechanism was a bit of a tangled
mess.  This patch attempts to consolidate printing into one interface.

All (non-debug) printing now uses the mp_print* family of functions,
mainly mp_printf.  All these functions take an mp_print_t structure as
their first argument, and this structure defines the printing backend
through the "print_strn" function of said structure.

Printing from the uPy core can reach the platform-defined print code via
two paths: either through mp_sys_stdout_obj (defined pert port) in
conjunction with mp_stream_write; or through the mp_plat_print structure
which uses the MP_PLAT_PRINT_STRN macro to define how string are printed
on the platform.  The former is only used when MICROPY_PY_IO is defined.

With this new scheme printing is generally more efficient (less layers
to go through, less arguments to pass), and, given an mp_print_t*
structure, one can call mp_print_str for efficiency instead of
mp_printf("%s", ...).  Code size is also reduced by around 200 bytes on
Thumb2 archs.
parent 56beb017
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "py/compile.h" #include "py/compile.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/repl.h" #include "py/repl.h"
#include "py/pfenv.h"
void do_str(const char *src) { void do_str(const char *src) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
...@@ -23,7 +22,7 @@ void do_str(const char *src) { ...@@ -23,7 +22,7 @@ void do_str(const char *src) {
nlr_pop(); nlr_pop();
} else { } else {
// uncaught exception // uncaught exception
mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val); mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
} }
} }
......
...@@ -37,9 +37,9 @@ ...@@ -37,9 +37,9 @@
#include "pybpin.h" #include "pybpin.h"
#include MICROPY_HAL_H #include MICROPY_HAL_H
STATIC void pin_named_pins_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pin_named_pins_obj_t *self = self_in; pin_named_pins_obj_t *self = self_in;
print(env, "<Pin.%s>", qstr_str(self->name)); mp_printf(print, "<Pin.%s>", qstr_str(self->name));
} }
const mp_obj_type_t pin_cpu_pins_obj_type = { const mp_obj_type_t pin_cpu_pins_obj_type = {
......
...@@ -691,19 +691,19 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k ...@@ -691,19 +691,19 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
return &wlan_obj; return &wlan_obj;
} }
STATIC void wlan_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void wlan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
wlan_obj_t *self = self_in; wlan_obj_t *self = self_in;
print(env, "<WLAN, mode=%u", self->mode); mp_printf(print, "<WLAN, mode=%u", self->mode);
// only print the bssid if in station mode // only print the bssid if in station mode
if (self->mode != ROLE_AP && GET_STATUS_BIT(self->status, STATUS_BIT_CONNECTION)) { if (self->mode != ROLE_AP && GET_STATUS_BIT(self->status, STATUS_BIT_CONNECTION)) {
print(env, ", connected to: ssid=%s, bssid=%02x:%02x:%02x:%02x:%02x:%02x", self->ssid, mp_printf(print, ", connected to: ssid=%s, bssid=%02x:%02x:%02x:%02x:%02x:%02x", self->ssid,
self->bssid[0], self->bssid[1], self->bssid[2], self->bssid[3], self->bssid[4], self->bssid[5]); self->bssid[0], self->bssid[1], self->bssid[2], self->bssid[3], self->bssid[4], self->bssid[5]);
} }
else { else {
print(env, ", ssid=%s", self->ssid); mp_printf(print, ", ssid=%s", self->ssid);
} }
print(env, ", security=%u>", self->security); mp_printf(print, ", security=%u>", self->security);
} }
/// \method connect(ssid, security=OPEN, key=None, bssid=None) /// \method connect(ssid, security=OPEN, key=None, bssid=None)
......
...@@ -100,9 +100,9 @@ STATIC pyb_adc_obj_t pyb_adc_obj[PYB_ADC_NUM_CHANNELS]; ...@@ -100,9 +100,9 @@ STATIC pyb_adc_obj_t pyb_adc_obj[PYB_ADC_NUM_CHANNELS];
/******************************************************************************/ /******************************************************************************/
/* Micro Python bindings : adc object */ /* Micro Python bindings : adc object */
STATIC void adc_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_adc_obj_t *self = self_in; pyb_adc_obj_t *self = self_in;
print(env, "<ADC, channel=%u>", self->num); mp_printf(print, "<ADC, channel=%u>", self->num);
} }
/// \classmethod \constructor(channel) /// \classmethod \constructor(channel)
......
...@@ -294,13 +294,13 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n ...@@ -294,13 +294,13 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
return (mp_obj_t)self; return (mp_obj_t)self;
} }
STATIC void pyb_i2c_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_i2c_obj_t *self = self_in; pyb_i2c_obj_t *self = self_in;
if (self->baudrate > 0) { if (self->baudrate > 0) {
print(env, "<I2C0, I2C.MASTER, baudrate=%u>)", self->baudrate); mp_printf(print, "<I2C0, I2C.MASTER, baudrate=%u>)", self->baudrate);
} }
else { else {
print(env, "<I2C0>"); mp_print_str(print, "<I2C0>");
} }
} }
......
...@@ -429,14 +429,14 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_ ...@@ -429,14 +429,14 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_
/// \method print() /// \method print()
/// Return a string describing the pin object. /// Return a string describing the pin object.
STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pin_obj_t *self = self_in; pin_obj_t *self = self_in;
uint32_t af = MAP_PinModeGet(self->pin_num); uint32_t af = MAP_PinModeGet(self->pin_num);
uint32_t type = pin_get_type(self); uint32_t type = pin_get_type(self);
uint32_t strength = pin_get_strenght(self); uint32_t strength = pin_get_strenght(self);
// pin name // pin name
print(env, "<Pin.cpu.%s, af=%u", qstr_str(self->name), af); mp_printf(print, "<Pin.cpu.%s, af=%u", qstr_str(self->name), af);
if (af == PIN_MODE_0) { if (af == PIN_MODE_0) {
// IO mode // IO mode
...@@ -447,7 +447,7 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env, ...@@ -447,7 +447,7 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env,
} else { } else {
mode_qst = MP_QSTR_OUT; mode_qst = MP_QSTR_OUT;
} }
print(env, ", mode=Pin.%s", qstr_str(mode_qst)); // safe because mode_qst has no formatting chars mp_printf(print, ", mode=Pin.%s", qstr_str(mode_qst));
} }
// pin type // pin type
...@@ -465,7 +465,7 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env, ...@@ -465,7 +465,7 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env,
} else { } else {
type_qst = MP_QSTR_OD_PD; type_qst = MP_QSTR_OD_PD;
} }
print(env, ", pull=Pin.%s", qstr_str(type_qst)); mp_printf(print, ", pull=Pin.%s", qstr_str(type_qst));
// Strength // Strength
qstr str_qst; qstr str_qst;
...@@ -476,7 +476,7 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env, ...@@ -476,7 +476,7 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env,
} else { } else {
str_qst = MP_QSTR_S6MA; str_qst = MP_QSTR_S6MA;
} }
print(env, ", strength=Pin.%s>", qstr_str(str_qst)); mp_printf(print, ", strength=Pin.%s>", qstr_str(str_qst));
} }
/// \classmethod \constructor(id, ...) /// \classmethod \constructor(id, ...)
......
...@@ -163,15 +163,15 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda ...@@ -163,15 +163,15 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda
/******************************************************************************/ /******************************************************************************/
/* Micro Python bindings */ /* Micro Python bindings */
/******************************************************************************/ /******************************************************************************/
STATIC void pyb_spi_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_spi_obj_t *self = self_in; pyb_spi_obj_t *self = self_in;
if (self->baudrate > 0) { if (self->baudrate > 0) {
print(env, "<SPI0, SPI.MASTER, baudrate=%u, config=%u, submode=%u, bits=%u>", mp_printf(print, "<SPI0, SPI.MASTER, baudrate=%u, config=%u, submode=%u, bits=%u>",
self->baudrate, self->config, self->submode, (self->wlen * 8)); self->baudrate, self->config, self->submode, (self->wlen * 8));
} }
else { else {
print(env, "<SPI0>"); mp_print_str(print, "<SPI0>");
} }
} }
......
...@@ -312,37 +312,37 @@ STATIC void uart_callback_disable (mp_obj_t self_in) { ...@@ -312,37 +312,37 @@ STATIC void uart_callback_disable (mp_obj_t self_in) {
/******************************************************************************/ /******************************************************************************/
/* Micro Python bindings */ /* Micro Python bindings */
STATIC void pyb_uart_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_uart_obj_t *self = self_in; pyb_uart_obj_t *self = self_in;
if (self->baudrate > 0) { if (self->baudrate > 0) {
print(env, "<UART%u, baudrate=%u, bits=", self->uart_id, self->baudrate); mp_printf(print, "<UART%u, baudrate=%u, bits=", self->uart_id, self->baudrate);
switch (self->config & UART_CONFIG_WLEN_MASK) { switch (self->config & UART_CONFIG_WLEN_MASK) {
case UART_CONFIG_WLEN_5: case UART_CONFIG_WLEN_5:
print(env, "5"); mp_print_str(print, "5");
break; break;
case UART_CONFIG_WLEN_6: case UART_CONFIG_WLEN_6:
print(env, "6"); mp_print_str(print, "6");
break; break;
case UART_CONFIG_WLEN_7: case UART_CONFIG_WLEN_7:
print(env, "7"); mp_print_str(print, "7");
break; break;
case UART_CONFIG_WLEN_8: case UART_CONFIG_WLEN_8:
print(env, "8"); mp_print_str(print, "8");
break; break;
default: default:
break; break;
} }
if ((self->config & UART_CONFIG_PAR_MASK) == UART_CONFIG_PAR_NONE) { if ((self->config & UART_CONFIG_PAR_MASK) == UART_CONFIG_PAR_NONE) {
print(env, ", parity=None"); mp_print_str(print, ", parity=None");
} else { } else {
print(env, ", parity=%u", (self->config & UART_CONFIG_PAR_MASK) == UART_CONFIG_PAR_EVEN ? 0 : 1); mp_printf(print, ", parity=%u", (self->config & UART_CONFIG_PAR_MASK) == UART_CONFIG_PAR_EVEN ? 0 : 1);
} }
print(env, ", stop=%u, timeout=%u, timeout_char=%u, read_buf_len=%u>", mp_printf(print, ", stop=%u, timeout=%u, timeout_char=%u, read_buf_len=%u>",
(self->config & UART_CONFIG_STOP_MASK) == UART_CONFIG_STOP_ONE ? 1 : 2, (self->config & UART_CONFIG_STOP_MASK) == UART_CONFIG_STOP_ONE ? 1 : 2,
self->timeout, self->timeout_char, self->read_buf_len); self->timeout, self->timeout_char, self->read_buf_len);
} }
else { else {
print(env, "<UART%u>", self->uart_id); mp_printf(print, "<UART%u>", self->uart_id);
} }
} }
......
...@@ -146,6 +146,9 @@ typedef void *machine_ptr_t; // must be of pointer size ...@@ -146,6 +146,9 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t; typedef long mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "py/obj.h" #include "py/obj.h"
#include "py/gc.h" #include "py/gc.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/pfenv.h"
#include MICROPY_HAL_H #include MICROPY_HAL_H
#include "queue.h" #include "queue.h"
#include "user_interface.h" #include "user_interface.h"
...@@ -52,7 +51,7 @@ mp_obj_t call_function_1_protected(mp_obj_t fun, mp_obj_t arg) { ...@@ -52,7 +51,7 @@ mp_obj_t call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
if (nlr_push(&nlr) == 0) { if (nlr_push(&nlr) == 0) {
return mp_call_function_1(fun, arg); return mp_call_function_1(fun, arg);
} else { } else {
mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val); mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
return (mp_obj_t)nlr.ret_val; return (mp_obj_t)nlr.ret_val;
} }
} }
......
...@@ -65,11 +65,11 @@ STATIC const pyb_pin_obj_t pyb_pin_obj[] = { ...@@ -65,11 +65,11 @@ STATIC const pyb_pin_obj_t pyb_pin_obj[] = {
{{&pyb_pin_type}, 15, 15, PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15}, {{&pyb_pin_type}, 15, 15, PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15},
}; };
STATIC void pyb_pin_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pyb_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_pin_obj_t *self = self_in; pyb_pin_obj_t *self = self_in;
// pin name // pin name
print(env, "Pin(%u)", self->pin_id); mp_printf(print, "Pin(%u)", self->pin_id);
} }
// pin.init(mode, pull=Pin.PULL_NONE, af=-1) // pin.init(mode, pull=Pin.PULL_NONE, af=-1)
......
...@@ -52,6 +52,9 @@ typedef void *machine_ptr_t; // must be of pointer size ...@@ -52,6 +52,9 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t; typedef long mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace // extra built in names to add to the global namespace
extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
#define MICROPY_PORT_BUILTINS \ #define MICROPY_PORT_BUILTINS \
......
...@@ -137,7 +137,7 @@ STATIC mp_obj_t uctypes_struct_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_u ...@@ -137,7 +137,7 @@ STATIC mp_obj_t uctypes_struct_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_u
return o; return o;
} }
STATIC void uctypes_struct_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind; (void)kind;
mp_obj_uctypes_struct_t *self = self_in; mp_obj_uctypes_struct_t *self = self_in;
const char *typen = "unk"; const char *typen = "unk";
...@@ -154,7 +154,7 @@ STATIC void uctypes_struct_print(void (*print)(void *env, const char *fmt, ...), ...@@ -154,7 +154,7 @@ STATIC void uctypes_struct_print(void (*print)(void *env, const char *fmt, ...),
} else { } else {
typen = "ERROR"; typen = "ERROR";
} }
print(env, "<struct %s %p>", typen, self->addr); mp_printf(print, "<struct %s %p>", typen, self->addr);
} }
// Get size of any type descriptor // Get size of any type descriptor
......
...@@ -35,8 +35,9 @@ ...@@ -35,8 +35,9 @@
STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) { STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) {
vstr_t vstr; vstr_t vstr;
vstr_init(&vstr, 8); mp_print_t print;
mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, &vstr, obj, PRINT_JSON); vstr_init_print(&vstr, 8, &print);
mp_obj_print_helper(&print, obj, PRINT_JSON);
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps);
......
...@@ -51,10 +51,10 @@ typedef struct _mp_obj_match_t { ...@@ -51,10 +51,10 @@ typedef struct _mp_obj_match_t {
} mp_obj_match_t; } mp_obj_match_t;
STATIC void match_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind; (void)kind;
mp_obj_match_t *self = self_in; mp_obj_match_t *self = self_in;
print(env, "<match num=%d>", self->num_matches); mp_printf(print, "<match num=%d>", self->num_matches);
} }
STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
...@@ -86,10 +86,10 @@ STATIC const mp_obj_type_t match_type = { ...@@ -86,10 +86,10 @@ STATIC const mp_obj_type_t match_type = {
.locals_dict = (mp_obj_t)&match_locals_dict, .locals_dict = (mp_obj_t)&match_locals_dict,
}; };
STATIC void re_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind; (void)kind;
mp_obj_re_t *self = self_in; mp_obj_re_t *self = self_in;
print(env, "<re %p>", self); mp_printf(print, "<re %p>", self);
} }
STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "py/compile.h" #include "py/compile.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/repl.h" #include "py/repl.h"
#include "py/pfenv.h"
#include "py/gc.h" #include "py/gc.h"
#include "pyexec.h" #include "pyexec.h"
...@@ -26,7 +25,7 @@ void do_str(const char *src) { ...@@ -26,7 +25,7 @@ void do_str(const char *src) {
nlr_pop(); nlr_pop();
} else { } else {
// uncaught exception // uncaught exception
mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val); mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
} }
} }
......
...@@ -60,6 +60,9 @@ typedef void *machine_ptr_t; // must be of pointer size ...@@ -60,6 +60,9 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t; typedef long mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace // extra built in names to add to the global namespace
extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
#define MICROPY_PORT_BUILTINS \ #define MICROPY_PORT_BUILTINS \
......
...@@ -41,9 +41,9 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = { ...@@ -41,9 +41,9 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = {
#define NUM_LED MP_ARRAY_SIZE(pyb_led_obj) #define NUM_LED MP_ARRAY_SIZE(pyb_led_obj)
#define LED_ID(obj) ((obj) - &pyb_led_obj[0] + 1) #define LED_ID(obj) ((obj) - &pyb_led_obj[0] + 1)
void pyb_led_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { void pyb_led_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_led_obj_t *self = self_in; pyb_led_obj_t *self = self_in;
print(env, "LED(%u)", LED_ID(self)); mp_printf(print, "LED(%u)", LED_ID(self));
} }
STATIC mp_obj_t pyb_led_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t pyb_led_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
......
...@@ -40,9 +40,9 @@ STATIC const pyb_switch_obj_t pyb_switch_obj[] = { ...@@ -40,9 +40,9 @@ STATIC const pyb_switch_obj_t pyb_switch_obj[] = {
#define NUM_SWITCH MP_ARRAY_SIZE(pyb_switch_obj) #define NUM_SWITCH MP_ARRAY_SIZE(pyb_switch_obj)
#define SWITCH_ID(obj) ((obj) - &pyb_switch_obj[0] + 1) #define SWITCH_ID(obj) ((obj) - &pyb_switch_obj[0] + 1)
void pyb_switch_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_switch_obj_t *self = self_in; pyb_switch_obj_t *self = self_in;
print(env, "Switch(%u)", SWITCH_ID(self)); mp_printf(print, "Switch(%u)", SWITCH_ID(self));
} }
STATIC mp_obj_t pyb_switch_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t pyb_switch_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
......
...@@ -86,6 +86,9 @@ typedef void *machine_ptr_t; // must be pointer size ...@@ -86,6 +86,9 @@ typedef void *machine_ptr_t; // must be pointer size
typedef const void *machine_const_ptr_t; // must be pointer size typedef const void *machine_const_ptr_t; // must be pointer size
typedef int mp_off_t; typedef int mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra builtin names to add to the global namespace // extra builtin names to add to the global namespace
extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
#define MICROPY_PORT_BUILTINS \ #define MICROPY_PORT_BUILTINS \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment