stm32: Support compiling with object representation D.

With this and previous patches the stm32 port can now be compiled using
object representation D (nan boxing).  Note that native code and frozen mpy
files with float constants are currently not supported with this object
representation.
pull/3937/head
Damien George 2018-07-08 23:25:11 +10:00
rodzic aa735dc6a4
commit e1ae9939ac
28 zmienionych plików z 276 dodań i 276 usunięć

Wyświetl plik

@ -122,7 +122,7 @@ STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, siz
pyb_accel_obj.base.type = &pyb_accel_type;
accel_start();
return &pyb_accel_obj;
return MP_OBJ_FROM_PTR(&pyb_accel_obj);
}
STATIC mp_obj_t read_axis(int axis) {
@ -166,7 +166,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_tilt_obj, pyb_accel_tilt);
/// \method filtered_xyz()
/// Get a 3-tuple of filtered x, y and z values.
STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) {
pyb_accel_obj_t *self = self_in;
pyb_accel_obj_t *self = MP_OBJ_TO_PTR(self_in);
memmove(self->buf, self->buf + NUM_AXIS, NUM_AXIS * (FILT_DEPTH - 1) * sizeof(int16_t));

Wyświetl plik

@ -322,7 +322,7 @@ STATIC uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32
/* MicroPython bindings : adc object (single channel) */
STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_obj_adc_t *self = self_in;
pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in);
mp_print_str(print, "<ADC on ");
mp_obj_print_helper(print, self->pin_name, PRINT_STR);
mp_printf(print, " channel=%u>", self->channel);
@ -371,14 +371,14 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
o->channel = channel;
adc_init_single(o);
return o;
return MP_OBJ_FROM_PTR(o);
}
/// \method read()
/// Read the value on the analog pin and return it. The returned value
/// will be between 0 and 4095.
STATIC mp_obj_t adc_read(mp_obj_t self_in) {
pyb_obj_adc_t *self = self_in;
pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(adc_config_and_read_channel(&self->handle, self->channel));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
@ -418,7 +418,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
///
/// This function does not allocate any memory.
STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_in) {
pyb_obj_adc_t *self = self_in;
pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE);
@ -531,7 +531,7 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
tim = pyb_timer_get_handle(tim_in);
// Start adc; this is slow so wait for it to start
pyb_obj_adc_t *adc0 = adc_array[0];
pyb_obj_adc_t *adc0 = MP_OBJ_TO_PTR(adc_array[0]);
adc_config_channel(&adc0->handle, adc0->channel);
HAL_ADC_Start(&adc0->handle);
// Wait for sample to complete and discard
@ -560,7 +560,7 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
__HAL_TIM_CLEAR_FLAG(tim, TIM_FLAG_UPDATE);
for (size_t array_index = 0; array_index < nadcs; array_index++) {
pyb_obj_adc_t *adc = adc_array[array_index];
pyb_obj_adc_t *adc = MP_OBJ_TO_PTR(adc_array[array_index]);
// configure the ADC channel
adc_config_channel(&adc->handle, adc->channel);
// for the first sample we need to turn the ADC on
@ -587,7 +587,7 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
}
// Turn the ADC off
adc0 = adc_array[0];
adc0 = MP_OBJ_TO_PTR(adc_array[0]);
HAL_ADC_Stop(&adc0->handle);
return mp_obj_new_bool(success);
@ -735,11 +735,11 @@ STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_
}
adc_init_all(o, res, en_mask);
return o;
return MP_OBJ_FROM_PTR(o);
}
STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
pyb_adc_all_obj_t *self = self_in;
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint32_t chan = adc_get_internal_channel(mp_obj_get_int(channel));
uint32_t data = adc_config_and_read_channel(&self->handle, chan);
return mp_obj_new_int(data);
@ -747,7 +747,7 @@ STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(adc_all_read_channel_obj, adc_all_read_channel);
STATIC mp_obj_t adc_all_read_core_temp(mp_obj_t self_in) {
pyb_adc_all_obj_t *self = self_in;
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
#if MICROPY_PY_BUILTINS_FLOAT
float data = adc_read_core_temp_float(&self->handle);
return mp_obj_new_float(data);
@ -760,21 +760,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_t
#if MICROPY_PY_BUILTINS_FLOAT
STATIC mp_obj_t adc_all_read_core_vbat(mp_obj_t self_in) {
pyb_adc_all_obj_t *self = self_in;
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
float data = adc_read_core_vbat(&self->handle);
return mp_obj_new_float(data);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vbat_obj, adc_all_read_core_vbat);
STATIC mp_obj_t adc_all_read_core_vref(mp_obj_t self_in) {
pyb_adc_all_obj_t *self = self_in;
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
float data = adc_read_core_vref(&self->handle);
return mp_obj_new_float(data);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_vref);
STATIC mp_obj_t adc_all_read_vref(mp_obj_t self_in) {
pyb_adc_all_obj_t *self = self_in;
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
adc_read_core_vref(&self->handle);
return mp_obj_new_float(3.3 * adc_refcor);
}

Wyświetl plik

@ -169,7 +169,7 @@ void can_deinit(void) {
for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(pyb_can_obj_all)); i++) {
pyb_can_obj_t *can_obj = MP_STATE_PORT(pyb_can_obj_all)[i];
if (can_obj != NULL) {
pyb_can_deinit(can_obj);
pyb_can_deinit(MP_OBJ_FROM_PTR(can_obj));
}
}
}
@ -330,7 +330,7 @@ STATIC HAL_StatusTypeDef CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout)
// MicroPython bindings
STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_can_obj_t *self = self_in;
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!self->is_enabled) {
mp_printf(print, "CAN(%u)", self->can_id);
} else {
@ -445,7 +445,7 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_
if (self->is_enabled) {
// The caller is requesting a reconfiguration of the hardware
// this can only be done if the hardware is in init mode
pyb_can_deinit(self);
pyb_can_deinit(MP_OBJ_FROM_PTR(self));
}
self->rxcallback0 = mp_const_none;
@ -461,18 +461,18 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_
}
}
return self;
return MP_OBJ_FROM_PTR(self);
}
STATIC mp_obj_t pyb_can_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_can_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pyb_can_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_init_obj, 1, pyb_can_init);
/// \method deinit()
/// Turn off the CAN bus.
STATIC mp_obj_t pyb_can_deinit(mp_obj_t self_in) {
pyb_can_obj_t *self = self_in;
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->is_enabled = false;
HAL_CAN_DeInit(&self->can);
if (self->can.Instance == CAN1) {
@ -566,7 +566,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_can_info_obj, 1, 2, pyb_can_info)
/// \method any(fifo)
/// Return `True` if any message waiting on the FIFO, else `False`.
STATIC mp_obj_t pyb_can_any(mp_obj_t self_in, mp_obj_t fifo_in) {
pyb_can_obj_t *self = self_in;
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t fifo = mp_obj_get_int(fifo_in);
if (fifo == 0) {
if (__HAL_CAN_MSG_PENDING(&self->can, CAN_FIFO0) != 0) {
@ -599,7 +599,7 @@ STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
};
// parse args
pyb_can_obj_t *self = pos_args[0];
pyb_can_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -655,12 +655,12 @@ STATIC mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
enum { ARG_fifo, ARG_list, ARG_timeout };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_fifo, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_list, MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_list, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
};
// parse args
pyb_can_obj_t *self = pos_args[0];
pyb_can_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -765,10 +765,10 @@ STATIC mp_obj_t pyb_can_initfilterbanks(mp_obj_t self, mp_obj_t bank_in) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_initfilterbanks_fun_obj, pyb_can_initfilterbanks);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pyb_can_initfilterbanks_obj, (const mp_obj_t)&pyb_can_initfilterbanks_fun_obj);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pyb_can_initfilterbanks_obj, MP_ROM_PTR(&pyb_can_initfilterbanks_fun_obj));
STATIC mp_obj_t pyb_can_clearfilter(mp_obj_t self_in, mp_obj_t bank_in) {
pyb_can_obj_t *self = self_in;
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t f = mp_obj_get_int(bank_in);
if (self->can_id == 2) {
f += can2_start_bank;
@ -792,7 +792,7 @@ STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_ma
};
// parse args
pyb_can_obj_t *self = pos_args[0];
pyb_can_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -908,7 +908,7 @@ error:
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_setfilter_obj, 1, pyb_can_setfilter);
STATIC mp_obj_t pyb_can_rxcallback(mp_obj_t self_in, mp_obj_t fifo_in, mp_obj_t callback_in) {
pyb_can_obj_t *self = self_in;
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t fifo = mp_obj_get_int(fifo_in);
mp_obj_t *callback;
@ -981,11 +981,11 @@ STATIC const mp_rom_map_elem_t pyb_can_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table);
mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
pyb_can_obj_t *self = self_in;
mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
uintptr_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD)
&& ((__HAL_CAN_MSG_PENDING(&self->can, CAN_FIFO0) != 0)
@ -1046,13 +1046,13 @@ void can_rx_irq_handler(uint can_id, uint fifo_id) {
gc_lock();
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_call_function_2(callback, self, irq_reason);
mp_call_function_2(callback, MP_OBJ_FROM_PTR(self), irq_reason);
nlr_pop();
} else {
// Uncaught exception; disable the callback so it doesn't run again.
pyb_can_rxcallback(self, MP_OBJ_NEW_SMALL_INT(fifo_id), mp_const_none);
pyb_can_rxcallback(MP_OBJ_FROM_PTR(self), MP_OBJ_NEW_SMALL_INT(fifo_id), mp_const_none);
printf("uncaught exception in CAN(%u) rx interrupt handler\n", self->can_id);
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
gc_unlock();
mp_sched_unlock();
@ -1087,7 +1087,7 @@ const mp_obj_type_t pyb_can_type = {
.print = pyb_can_print,
.make_new = pyb_can_make_new,
.protocol = &can_stream_p,
.locals_dict = (mp_obj_t)&pyb_can_locals_dict,
.locals_dict = (mp_obj_dict_t*)&pyb_can_locals_dict,
};
#endif // MICROPY_HW_ENABLE_CAN

Wyświetl plik

@ -272,18 +272,18 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
pyb_dac_init_helper(dac, n_args - 1, args + 1, &kw_args);
// return object
return dac;
return MP_OBJ_FROM_PTR(dac);
}
STATIC mp_obj_t pyb_dac_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_dac_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pyb_dac_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_init_obj, 1, pyb_dac_init);
/// \method deinit()
/// Turn off the DAC, enable other use of pin.
STATIC mp_obj_t pyb_dac_deinit(mp_obj_t self_in) {
pyb_dac_obj_t *self = self_in;
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->dac_channel == DAC_CHANNEL_1) {
DAC_Handle.Instance->CR &= ~DAC_CR_EN1;
#if defined(STM32H7) || defined(STM32L4)
@ -308,7 +308,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit);
/// Generate a pseudo-random noise signal. A new random sample is written
/// to the DAC output at the given frequency.
STATIC mp_obj_t pyb_dac_noise(mp_obj_t self_in, mp_obj_t freq) {
pyb_dac_obj_t *self = self_in;
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
// set TIM6 to trigger the DAC at the given frequency
TIM6_Config(mp_obj_get_int(freq));
@ -338,7 +338,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise);
/// the given frequency, and the frequence of the repeating triangle wave
/// itself is 256 (or 1024, need to check) times smaller.
STATIC mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) {
pyb_dac_obj_t *self = self_in;
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
// set TIM6 to trigger the DAC at the given frequency
TIM6_Config(mp_obj_get_int(freq));
@ -365,7 +365,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_triangle_obj, pyb_dac_triangle);
/// \method write(value)
/// Direct access to the DAC output (8 bit only at the moment).
STATIC mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) {
pyb_dac_obj_t *self = self_in;
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->state != DAC_STATE_WRITE_SINGLE) {
DAC_ChannelConfTypeDef config;
@ -414,7 +414,7 @@ mp_obj_t pyb_dac_write_timed(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
};
// parse args
pyb_dac_obj_t *self = pos_args[0];
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

Wyświetl plik

@ -238,7 +238,7 @@ void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"ExtInt vector %d is already in use", line));
} else {
const pin_obj_t *other_pin = (const pin_obj_t*)pyb_extint_callback_arg[line];
const pin_obj_t *other_pin = MP_OBJ_TO_PTR(pyb_extint_callback_arg[line]);
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"IRQ resource already taken by Pin('%q')", other_pin->name));
}
@ -356,7 +356,7 @@ void extint_swint(uint line) {
/// \method line()
/// Return the line number that the pin is mapped to.
STATIC mp_obj_t extint_obj_line(mp_obj_t self_in) {
extint_obj_t *self = self_in;
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(self->line);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_line_obj, extint_obj_line);
@ -364,7 +364,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_line_obj, extint_obj_line);
/// \method enable()
/// Enable a disabled interrupt.
STATIC mp_obj_t extint_obj_enable(mp_obj_t self_in) {
extint_obj_t *self = self_in;
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
extint_enable(self->line);
return mp_const_none;
}
@ -374,7 +374,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable);
/// Disable the interrupt associated with the ExtInt object.
/// This could be useful for debouncing.
STATIC mp_obj_t extint_obj_disable(mp_obj_t self_in) {
extint_obj_t *self = self_in;
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
extint_disable(self->line);
return mp_const_none;
}
@ -383,7 +383,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable);
/// \method swint()
/// Trigger the callback from software.
STATIC mp_obj_t extint_obj_swint(mp_obj_t self_in) {
extint_obj_t *self = self_in;
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
extint_swint(self->line);
return mp_const_none;
}
@ -436,7 +436,7 @@ STATIC mp_obj_t extint_regs(void) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs);
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, (mp_obj_t)&extint_regs_fun_obj);
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs_fun_obj));
/// \classmethod \constructor(pin, mode, pull, callback)
/// Create an ExtInt object:
@ -472,11 +472,11 @@ STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t
self->base.type = type;
self->line = extint_register(vals[0].u_obj, vals[1].u_int, vals[2].u_int, vals[3].u_obj, false);
return self;
return MP_OBJ_FROM_PTR(self);
}
STATIC void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
extint_obj_t *self = self_in;
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<ExtInt line=%u>", self->line);
}
@ -542,7 +542,7 @@ void Handle_EXTI_Irq(uint32_t line) {
*cb = mp_const_none;
extint_disable(line);
printf("Uncaught exception in ExtInt interrupt handler line %u\n", (unsigned int)line);
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
gc_unlock();
mp_sched_unlock();

Wyświetl plik

@ -33,7 +33,7 @@
#include "gccollect.h"
#include "systick.h"
mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs);
uintptr_t gc_helper_get_regs_and_sp(uintptr_t *regs);
void gc_collect(void) {
// get current time, in case we want to time the GC
@ -45,8 +45,8 @@ void gc_collect(void) {
gc_collect_start();
// get the registers and the sp
mp_uint_t regs[10];
mp_uint_t sp = gc_helper_get_regs_and_sp(regs);
uintptr_t regs[10];
uintptr_t sp = gc_helper_get_regs_and_sp(regs);
// trace the stack, including the registers (since they live on the stack in this function)
#if MICROPY_PY_THREAD

Wyświetl plik

@ -307,7 +307,7 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_
memset(lcd->pix_buf, 0, LCD_PIX_BUF_BYTE_SIZE);
memset(lcd->pix_buf2, 0, LCD_PIX_BUF_BYTE_SIZE);
return lcd;
return MP_OBJ_FROM_PTR(lcd);
}
/// \method command(instr_data, buf)
@ -316,7 +316,7 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_
/// instruction, otherwise pass 1 to send data. `buf` is a buffer with the
/// instructions/data to send.
STATIC mp_obj_t pyb_lcd_command(mp_obj_t self_in, mp_obj_t instr_data_in, mp_obj_t val) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get whether instr or data
int instr_data = mp_obj_get_int(instr_data_in);
@ -339,7 +339,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_command_obj, pyb_lcd_command);
///
/// Set the contrast of the LCD. Valid values are between 0 and 47.
STATIC mp_obj_t pyb_lcd_contrast(mp_obj_t self_in, mp_obj_t contrast_in) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
int contrast = mp_obj_get_int(contrast_in);
if (contrast < 0) {
contrast = 0;
@ -356,7 +356,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_contrast_obj, pyb_lcd_contrast);
///
/// Turn the backlight on/off. True or 1 turns it on, False or 0 turns it off.
STATIC mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (mp_obj_is_true(value)) {
mp_hal_pin_high(self->pin_bl); // set pin high to turn backlight on
} else {
@ -370,7 +370,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_light_obj, pyb_lcd_light);
///
/// Write the string `str` to the screen. It will appear immediately.
STATIC mp_obj_t pyb_lcd_write(mp_obj_t self_in, mp_obj_t str) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
size_t len;
const char *data = mp_obj_str_get_data(str, &len);
lcd_write_strn(self, data, len);
@ -384,7 +384,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_write_obj, pyb_lcd_write);
///
/// This method writes to the hidden buffer. Use `show()` to show the buffer.
STATIC mp_obj_t pyb_lcd_fill(mp_obj_t self_in, mp_obj_t col_in) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
int col = mp_obj_get_int(col_in);
if (col) {
col = 0xff;
@ -401,7 +401,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_fill_obj, pyb_lcd_fill);
///
/// This method reads from the visible buffer.
STATIC mp_obj_t pyb_lcd_get(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
int x = mp_obj_get_int(x_in);
int y = mp_obj_get_int(y_in);
if (0 <= x && x <= 127 && 0 <= y && y <= 31) {
@ -420,7 +420,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_get_obj, pyb_lcd_get);
///
/// This method writes to the hidden buffer. Use `show()` to show the buffer.
STATIC mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) {
pyb_lcd_obj_t *self = args[0];
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(args[0]);
int x = mp_obj_get_int(args[1]);
int y = mp_obj_get_int(args[2]);
if (0 <= x && x <= 127 && 0 <= y && y <= 31) {
@ -442,7 +442,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_pixel_obj, 4, 4, pyb_lcd_pixe
/// This method writes to the hidden buffer. Use `show()` to show the buffer.
STATIC mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) {
// extract arguments
pyb_lcd_obj_t *self = args[0];
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(args[0]);
size_t len;
const char *data = mp_obj_str_get_data(args[1], &len);
int x0 = mp_obj_get_int(args[2]);
@ -488,7 +488,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_text_obj, 5, 5, pyb_lcd_text)
///
/// Show the hidden buffer on the screen.
STATIC mp_obj_t pyb_lcd_show(mp_obj_t self_in) {
pyb_lcd_obj_t *self = self_in;
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
memcpy(self->pix_buf, self->pix_buf2, LCD_PIX_BUF_BYTE_SIZE);
for (uint page = 0; page < 4; page++) {
lcd_out(self, LCD_INSTR, 0xb0 | page); // page address set

Wyświetl plik

@ -280,7 +280,7 @@ void led_debug(int n, int delay) {
/* MicroPython bindings */
void led_obj_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 = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "LED(%u)", self->led_id);
}
@ -301,13 +301,13 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
}
// return static led object
return (mp_obj_t)&pyb_led_obj[led_id - 1];
return MP_OBJ_FROM_PTR(&pyb_led_obj[led_id - 1]);
}
/// \method on()
/// Turn the LED on.
mp_obj_t led_obj_on(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
pyb_led_obj_t *self = MP_OBJ_TO_PTR(self_in);
led_state(self->led_id, 1);
return mp_const_none;
}
@ -315,7 +315,7 @@ mp_obj_t led_obj_on(mp_obj_t self_in) {
/// \method off()
/// Turn the LED off.
mp_obj_t led_obj_off(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
pyb_led_obj_t *self = MP_OBJ_TO_PTR(self_in);
led_state(self->led_id, 0);
return mp_const_none;
}
@ -323,7 +323,7 @@ mp_obj_t led_obj_off(mp_obj_t self_in) {
/// \method toggle()
/// Toggle the LED between on and off.
mp_obj_t led_obj_toggle(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
pyb_led_obj_t *self = MP_OBJ_TO_PTR(self_in);
led_toggle(self->led_id);
return mp_const_none;
}
@ -333,7 +333,7 @@ mp_obj_t led_obj_toggle(mp_obj_t self_in) {
/// If no argument is given, return the LED intensity.
/// If an argument is given, set the LED intensity and return `None`.
mp_obj_t led_obj_intensity(size_t n_args, const mp_obj_t *args) {
pyb_led_obj_t *self = args[0];
pyb_led_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
return mp_obj_new_int(led_get_intensity(self->led_id));
} else {

Wyświetl plik

@ -101,7 +101,7 @@ void NORETURN __fatal_error(const char *msg) {
void nlr_jump_fail(void *val) {
printf("FATAL: uncaught exception %p\n", val);
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)val);
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(val));
__fatal_error("");
}
@ -564,9 +564,9 @@ soft_reset:
// MicroPython init
mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
mp_obj_list_init(mp_sys_argv, 0);
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
// Initialise low-level sub-systems. Here we need to very basic things like
// zeroing out memory and resetting any of the sub-systems. Following this

Wyświetl plik

@ -175,9 +175,9 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
// qstr info
{
mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
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=" UINT_FMT "\n n_qstr=" UINT_FMT "\n n_str_data_bytes=" UINT_FMT "\n n_total_bytes=" UINT_FMT "\n", 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", n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
}
// GC info
@ -185,9 +185,9 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
gc_info_t info;
gc_info(&info);
printf("GC:\n");
printf(" " UINT_FMT " total\n", info.total);
printf(" " UINT_FMT " : " UINT_FMT "\n", info.used, info.free);
printf(" 1=" UINT_FMT " 2=" UINT_FMT " m=" UINT_FMT "\n", info.num_1block, info.num_2block, info.max_block);
printf(" %u total\n", info.total);
printf(" %u : %u\n", info.used, info.free);
printf(" 1=%u 2=%u m=%u\n", info.num_1block, info.num_2block, info.max_block);
}
// free space on flash

Wyświetl plik

@ -80,7 +80,7 @@ void mod_network_register_nic(mp_obj_t nic) {
}
}
// nic not registered so add to list
mp_obj_list_append(&MP_STATE_PORT(mod_network_nic_list), nic);
mp_obj_list_append(MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list)), nic);
}
mp_obj_t mod_network_find_nic(const uint8_t *ip) {
@ -96,7 +96,7 @@ mp_obj_t mod_network_find_nic(const uint8_t *ip) {
}
STATIC mp_obj_t network_route(void) {
return &MP_STATE_PORT(mod_network_nic_list);
return MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route);

Wyświetl plik

@ -93,7 +93,7 @@ STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
if (MP_STATE_PORT(pyb_stdio_uart) == NULL) {
return mp_const_none;
} else {
return MP_STATE_PORT(pyb_stdio_uart);
return MP_OBJ_FROM_PTR(MP_STATE_PORT(pyb_stdio_uart));
}
} else {
if (args[0] == mp_const_none) {
@ -102,7 +102,7 @@ STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
MP_STATE_PORT(pyb_stdio_uart) = NULL;
}
} else if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
MP_STATE_PORT(pyb_stdio_uart) = args[0];
MP_STATE_PORT(pyb_stdio_uart) = MP_OBJ_TO_PTR(args[0]);
uart_attach_to_repl(MP_STATE_PORT(pyb_stdio_uart), true);
} else {
mp_raise_ValueError("need a UART object");

Wyświetl plik

@ -67,15 +67,15 @@ STATIC MP_DEFINE_ATTRTUPLE(
os_uname_info_obj,
os_uname_info_fields,
5,
(mp_obj_t)&os_uname_info_sysname_obj,
(mp_obj_t)&os_uname_info_nodename_obj,
(mp_obj_t)&os_uname_info_release_obj,
(mp_obj_t)&os_uname_info_version_obj,
(mp_obj_t)&os_uname_info_machine_obj
MP_ROM_PTR(&os_uname_info_sysname_obj),
MP_ROM_PTR(&os_uname_info_nodename_obj),
MP_ROM_PTR(&os_uname_info_release_obj),
MP_ROM_PTR(&os_uname_info_version_obj),
MP_ROM_PTR(&os_uname_info_machine_obj)
);
STATIC mp_obj_t os_uname(void) {
return (mp_obj_t)&os_uname_info_obj;
return MP_OBJ_FROM_PTR(&os_uname_info_obj);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);

Wyświetl plik

@ -48,7 +48,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
// create socket object (not bound to any NIC yet)
mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t);
s->base.type = (mp_obj_t)&socket_type;
s->base.type = &socket_type;
s->nic = MP_OBJ_NULL;
s->nic_type = NULL;
s->u_param.domain = MOD_NETWORK_AF_INET;
@ -64,7 +64,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
}
}
return s;
return MP_OBJ_FROM_PTR(s);
}
STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
@ -83,7 +83,7 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
// method socket.bind(address)
STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get address
uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
@ -104,7 +104,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
// method socket.listen(backlog)
STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
@ -123,12 +123,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
// method socket.accept()
STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// create new socket object
// starts with empty NIC so that finaliser doesn't run close() method if accept() fails
mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t);
socket2->base.type = (mp_obj_t)&socket_type;
socket2->base.type = &socket_type;
socket2->nic = MP_OBJ_NULL;
socket2->nic_type = NULL;
@ -145,17 +145,17 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
socket2->nic_type = self->nic_type;
// make the return value
mp_obj_tuple_t *client = mp_obj_new_tuple(2, NULL);
client->items[0] = socket2;
mp_obj_tuple_t *client = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
client->items[0] = MP_OBJ_FROM_PTR(socket2);
client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
return client;
return MP_OBJ_FROM_PTR(client);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
// method socket.connect(address)
STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get address
uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
@ -176,7 +176,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
// method socket.send(bytes)
STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_EPIPE);
@ -194,7 +194,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
// method socket.recv(bufsize)
STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_ENOTCONN);
@ -217,7 +217,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
// method socket.sendto(bytes, address)
STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get the data
mp_buffer_info_t bufinfo;
@ -243,7 +243,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
// method socket.recvfrom(bufsize)
STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_ENOTCONN);
@ -271,7 +271,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
// method socket.setsockopt(level, optname, value)
STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = args[0];
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_int_t level = mp_obj_get_int(args[1]);
mp_int_t opt = mp_obj_get_int(args[2]);
@ -304,7 +304,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_s
// timeout=None means blocking
// otherwise, timeout is in seconds
STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
mod_network_socket_obj_t *self = self_in;
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_ENOTCONN);
@ -355,8 +355,8 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
mod_network_socket_obj_t *self = self_in;
mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (request == MP_STREAM_CLOSE) {
if (self->nic != MP_OBJ_NULL) {
self->nic_type->close(self);
@ -423,7 +423,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "no available NIC"));
}
mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL);
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);

Wyświetl plik

@ -106,29 +106,29 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
// If a pin was provided, then use it
if (MP_OBJ_IS_TYPE(user_obj, &pin_type)) {
pin_obj = user_obj;
pin_obj = MP_OBJ_TO_PTR(user_obj);
if (pin_class_debug) {
printf("Pin map passed pin ");
mp_obj_print((mp_obj_t)pin_obj, PRINT_STR);
mp_obj_print(MP_OBJ_FROM_PTR(pin_obj), PRINT_STR);
printf("\n");
}
return pin_obj;
}
if (MP_STATE_PORT(pin_class_mapper) != mp_const_none) {
pin_obj = mp_call_function_1(MP_STATE_PORT(pin_class_mapper), user_obj);
if (pin_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) {
mp_obj_t o = mp_call_function_1(MP_STATE_PORT(pin_class_mapper), user_obj);
if (o != mp_const_none) {
if (!MP_OBJ_IS_TYPE(o, &pin_type)) {
mp_raise_ValueError("Pin.mapper didn't return a Pin object");
}
if (pin_class_debug) {
printf("Pin.mapper maps ");
mp_obj_print(user_obj, PRINT_REPR);
printf(" to ");
mp_obj_print((mp_obj_t)pin_obj, PRINT_STR);
mp_obj_print(o, PRINT_STR);
printf("\n");
}
return pin_obj;
return MP_OBJ_TO_PTR(o);
}
// The pin mapping function returned mp_const_none, fall through to
// other lookup methods.
@ -137,16 +137,16 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
if (MP_STATE_PORT(pin_class_map_dict) != mp_const_none) {
mp_map_t *pin_map_map = mp_obj_dict_get_map(MP_STATE_PORT(pin_class_map_dict));
mp_map_elem_t *elem = mp_map_lookup(pin_map_map, user_obj, MP_MAP_LOOKUP);
if (elem != NULL && elem->value != NULL) {
pin_obj = elem->value;
if (elem != NULL && elem->value != MP_OBJ_NULL) {
mp_obj_t o = elem->value;
if (pin_class_debug) {
printf("Pin.map_dict maps ");
mp_obj_print(user_obj, PRINT_REPR);
printf(" to ");
mp_obj_print((mp_obj_t)pin_obj, PRINT_STR);
mp_obj_print(o, PRINT_STR);
printf("\n");
}
return pin_obj;
return MP_OBJ_TO_PTR(o);
}
}
@ -157,7 +157,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
printf("Pin.board maps ");
mp_obj_print(user_obj, PRINT_REPR);
printf(" to ");
mp_obj_print((mp_obj_t)pin_obj, PRINT_STR);
mp_obj_print(MP_OBJ_FROM_PTR(pin_obj), PRINT_STR);
printf("\n");
}
return pin_obj;
@ -170,7 +170,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
printf("Pin.cpu maps ");
mp_obj_print(user_obj, PRINT_REPR);
printf(" to ");
mp_obj_print((mp_obj_t)pin_obj, PRINT_STR);
mp_obj_print(MP_OBJ_FROM_PTR(pin_obj), PRINT_STR);
printf("\n");
}
return pin_obj;
@ -182,7 +182,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
/// \method __str__()
/// Return a string describing the pin object.
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 = MP_OBJ_TO_PTR(self_in);
// pin name
mp_printf(print, "Pin(Pin.cpu.%q, mode=Pin.", self->name);
@ -258,13 +258,13 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
pin_obj_init_helper(pin, n_args - 1, args + 1, &kw_args);
}
return (mp_obj_t)pin;
return MP_OBJ_FROM_PTR(pin);
}
// fast method for getting/setting pin value
STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (n_args == 0) {
// get pin
return MP_OBJ_NEW_SMALL_INT(mp_hal_pin_read(self));
@ -285,7 +285,7 @@ STATIC mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) {
return MP_STATE_PORT(pin_class_mapper);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, (mp_obj_t)&pin_mapper_fun_obj);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, MP_ROM_PTR(&pin_mapper_fun_obj));
/// \classmethod dict([dict])
/// Get or set the pin mapper dictionary.
@ -297,17 +297,17 @@ STATIC mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) {
return MP_STATE_PORT(pin_class_map_dict);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, (mp_obj_t)&pin_map_dict_fun_obj);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dict_fun_obj));
/// \classmethod af_list()
/// Returns an array of alternate functions available for this pin.
STATIC mp_obj_t pin_af_list(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t result = mp_obj_new_list(0, NULL);
const pin_af_obj_t *af = self->af;
for (mp_uint_t i = 0; i < self->num_af; i++, af++) {
mp_obj_list_append(result, (mp_obj_t)af);
mp_obj_list_append(result, MP_OBJ_FROM_PTR(af));
}
return result;
}
@ -323,13 +323,13 @@ STATIC mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_bool(pin_class_debug);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj));
// init(mode, pull=None, af=-1, *, value, alt)
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none}},
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)}},
{ MP_QSTR_af, MP_ARG_INT, {.u_int = -1}}, // legacy
{ MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}},
{ MP_QSTR_alt, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1}},
@ -384,7 +384,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, size_t n_args, const
}
STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pin_obj_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
@ -401,14 +401,14 @@ STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
STATIC mp_obj_t pin_off(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_hal_pin_low(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);
STATIC mp_obj_t pin_on(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_hal_pin_high(self);
return mp_const_none;
}
@ -418,7 +418,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);
STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_handler, ARG_trigger, ARG_hard };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_handler, MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_trigger, MP_ARG_INT, {.u_int = GPIO_MODE_IT_RISING | GPIO_MODE_IT_FALLING} },
{ MP_QSTR_hard, MP_ARG_BOOL, {.u_bool = false} },
};
@ -440,7 +440,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
/// \method name()
/// Get the pin name.
STATIC mp_obj_t pin_name(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_QSTR(self->name);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
@ -448,7 +448,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
/// \method names()
/// Returns the cpu and board names for this pin.
STATIC mp_obj_t pin_names(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t result = mp_obj_new_list(0, NULL);
mp_obj_list_append(result, MP_OBJ_NEW_QSTR(self->name));
@ -456,7 +456,7 @@ STATIC mp_obj_t pin_names(mp_obj_t self_in) {
mp_map_elem_t *elem = map->table;
for (mp_uint_t i = 0; i < map->used; i++, elem++) {
if (elem->value == self) {
if (elem->value == self_in) {
mp_obj_list_append(result, elem->key);
}
}
@ -467,7 +467,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
/// \method port()
/// Get the pin port.
STATIC mp_obj_t pin_port(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(self->port);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
@ -475,7 +475,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
/// \method pin()
/// Get the pin number.
STATIC mp_obj_t pin_pin(mp_obj_t self_in) {
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(self->pin);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
@ -483,8 +483,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
/// \method gpio()
/// Returns the base address of the GPIO block associated with this pin.
STATIC mp_obj_t pin_gpio(mp_obj_t self_in) {
pin_obj_t *self = self_in;
return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->gpio);
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT((intptr_t)self->gpio);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_gpio_obj, pin_gpio);
@ -493,7 +493,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_gpio_obj, pin_gpio);
/// will match one of the allowed constants for the mode argument to the init
/// function.
STATIC mp_obj_t pin_mode(mp_obj_t self_in) {
return MP_OBJ_NEW_SMALL_INT(pin_get_mode(self_in));
return MP_OBJ_NEW_SMALL_INT(pin_get_mode(MP_OBJ_TO_PTR(self_in)));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode);
@ -502,7 +502,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode);
/// will match one of the allowed constants for the pull argument to the init
/// function.
STATIC mp_obj_t pin_pull(mp_obj_t self_in) {
return MP_OBJ_NEW_SMALL_INT(pin_get_pull(self_in));
return MP_OBJ_NEW_SMALL_INT(pin_get_pull(MP_OBJ_TO_PTR(self_in)));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull);
@ -511,7 +511,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull);
/// integer returned will match one of the allowed constants for the af
/// argument to the init function.
STATIC mp_obj_t pin_af(mp_obj_t self_in) {
return MP_OBJ_NEW_SMALL_INT(pin_get_af(self_in));
return MP_OBJ_NEW_SMALL_INT(pin_get_af(MP_OBJ_TO_PTR(self_in)));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
@ -571,7 +571,7 @@ STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
(void)errcode;
pin_obj_t *self = self_in;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
switch (request) {
case MP_PIN_READ: {
@ -629,14 +629,14 @@ const mp_obj_type_t pin_type = {
/// \method __str__()
/// Return a string describing the alternate function.
STATIC void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pin_af_obj_t *self = self_in;
pin_af_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "Pin.%q", self->name);
}
/// \method index()
/// Return the alternate function index.
STATIC mp_obj_t pin_af_index(mp_obj_t self_in) {
pin_af_obj_t *af = self_in;
pin_af_obj_t *af = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(af->idx);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index);
@ -644,7 +644,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index);
/// \method name()
/// Return the name of the alternate function.
STATIC mp_obj_t pin_af_name(mp_obj_t self_in) {
pin_af_obj_t *af = self_in;
pin_af_obj_t *af = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_QSTR(af->name);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name);
@ -654,8 +654,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name);
/// alternate function. For example, if the alternate function were TIM2_CH3
/// this would return stm.TIM2
STATIC mp_obj_t pin_af_reg(mp_obj_t self_in) {
pin_af_obj_t *af = self_in;
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)af->reg);
pin_af_obj_t *af = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT((uintptr_t)af->reg);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg);

Wyświetl plik

@ -34,20 +34,20 @@
const mp_obj_type_t pin_cpu_pins_obj_type = {
{ &mp_type_type },
.name = MP_QSTR_cpu,
.locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict,
.locals_dict = (mp_obj_dict_t*)&pin_cpu_pins_locals_dict,
};
const mp_obj_type_t pin_board_pins_obj_type = {
{ &mp_type_type },
.name = MP_QSTR_board,
.locals_dict = (mp_obj_t)&pin_board_pins_locals_dict,
.locals_dict = (mp_obj_dict_t*)&pin_board_pins_locals_dict,
};
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
const mp_map_t *named_map = &named_pins->map;
mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t*)named_map, name, MP_MAP_LOOKUP);
if (named_elem != NULL && named_elem->value != NULL) {
return named_elem->value;
if (named_elem != NULL && named_elem->value != MP_OBJ_NULL) {
return MP_OBJ_TO_PTR(named_elem->value);
}
return NULL;
}

Wyświetl plik

@ -542,7 +542,7 @@ STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t
static inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; }
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_i2c_obj_t *self = self_in;
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint i2c_num = 0;
if (0) { }
@ -677,18 +677,18 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
pyb_i2c_init_helper(i2c_obj, n_args - 1, args + 1, &kw_args);
}
return (mp_obj_t)i2c_obj;
return MP_OBJ_FROM_PTR(i2c_obj);
}
STATIC mp_obj_t pyb_i2c_init_(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_i2c_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pyb_i2c_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init_);
/// \method deinit()
/// Turn off the I2C bus.
STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
i2c_deinit(self->i2c);
return mp_const_none;
}
@ -697,7 +697,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);
/// \method is_ready(addr)
/// Check if an I2C device responds to the given address. Only valid when in master mode.
STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
pyb_i2c_obj_t *self = self_in;
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!in_master_mode(self)) {
mp_raise_TypeError("I2C must be a master");
@ -720,7 +720,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready);
/// Scan all I2C addresses from 0x08 to 0x77 and return a list of those that respond.
/// Only valid when in master mode.
STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!in_master_mode(self)) {
mp_raise_TypeError("I2C must be a master");
@ -755,7 +755,7 @@ STATIC mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
};
// parse args
pyb_i2c_obj_t *self = pos_args[0];
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -835,7 +835,7 @@ STATIC mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
};
// parse args
pyb_i2c_obj_t *self = pos_args[0];
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -919,7 +919,7 @@ STATIC const mp_arg_t pyb_i2c_mem_read_allowed_args[] = {
STATIC mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
pyb_i2c_obj_t *self = pos_args[0];
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args), pyb_i2c_mem_read_allowed_args, args);
@ -987,7 +987,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read);
/// This is only valid in master mode.
STATIC mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args (same as mem_read)
pyb_i2c_obj_t *self = pos_args[0];
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args), pyb_i2c_mem_read_allowed_args, args);

Wyświetl plik

@ -439,7 +439,7 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_
mp_arg_check_num(n_args, n_kw, 0, 0, false);
// return constant object
return (mp_obj_t)&pyb_rtc_obj;
return MP_OBJ_FROM_PTR(&pyb_rtc_obj);
}
// force rtc to re-initialise

Wyświetl plik

@ -437,7 +437,7 @@ STATIC mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, si
mp_arg_check_num(n_args, n_kw, 0, 0, false);
// return singleton object
return (mp_obj_t)&pyb_sdcard_obj;
return MP_OBJ_FROM_PTR(&pyb_sdcard_obj);
}
STATIC mp_obj_t sd_present(mp_obj_t self) {
@ -576,14 +576,14 @@ void sdcard_init_vfs(fs_user_mount_t *vfs, int part) {
vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL;
vfs->fatfs.drv = vfs;
vfs->fatfs.part = part;
vfs->readblocks[0] = (mp_obj_t)&pyb_sdcard_readblocks_obj;
vfs->readblocks[1] = (mp_obj_t)&pyb_sdcard_obj;
vfs->readblocks[2] = (mp_obj_t)sdcard_read_blocks; // native version
vfs->writeblocks[0] = (mp_obj_t)&pyb_sdcard_writeblocks_obj;
vfs->writeblocks[1] = (mp_obj_t)&pyb_sdcard_obj;
vfs->writeblocks[2] = (mp_obj_t)sdcard_write_blocks; // native version
vfs->u.ioctl[0] = (mp_obj_t)&pyb_sdcard_ioctl_obj;
vfs->u.ioctl[1] = (mp_obj_t)&pyb_sdcard_obj;
vfs->readblocks[0] = MP_OBJ_FROM_PTR(&pyb_sdcard_readblocks_obj);
vfs->readblocks[1] = MP_OBJ_FROM_PTR(&pyb_sdcard_obj);
vfs->readblocks[2] = MP_OBJ_FROM_PTR(sdcard_read_blocks); // native version
vfs->writeblocks[0] = MP_OBJ_FROM_PTR(&pyb_sdcard_writeblocks_obj);
vfs->writeblocks[1] = MP_OBJ_FROM_PTR(&pyb_sdcard_obj);
vfs->writeblocks[2] = MP_OBJ_FROM_PTR(sdcard_write_blocks); // native version
vfs->u.ioctl[0] = MP_OBJ_FROM_PTR(&pyb_sdcard_ioctl_obj);
vfs->u.ioctl[1] = MP_OBJ_FROM_PTR(&pyb_sdcard_obj);
}
#endif // MICROPY_HW_HAS_SDCARD

Wyświetl plik

@ -175,7 +175,7 @@ STATIC mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) {
MP_DEFINE_CONST_FUN_OBJ_2(pyb_pwm_set_obj, pyb_pwm_set);
STATIC void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_servo_obj_t *self = self_in;
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<Servo %u at %uus>", self - &pyb_servo_obj[0] + 1, 10 * self->pulse_cur);
}
@ -199,13 +199,13 @@ STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, siz
s->time_left = 0;
servo_init_channel(s);
return s;
return MP_OBJ_FROM_PTR(s);
}
/// \method pulse_width([value])
/// Get or set the pulse width in milliseconds.
STATIC mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get pulse width, in us
return mp_obj_new_int(10 * self->pulse_cur);
@ -223,7 +223,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_pulse_width_obj, 1, 2, pyb_
/// Get or set the calibration of the servo timing.
// TODO should accept 1 arg, a 5-tuple of values to set
STATIC mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get calibration values
mp_obj_t tuple[5];
@ -258,7 +258,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_calibration_obj, 1, 6, pyb_
/// - `angle` is the angle to move to in degrees.
/// - `time` is the number of milliseconds to take to get to the specified angle.
STATIC mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get angle
return mp_obj_new_int((self->pulse_cur - self->pulse_centre) * 90 / self->pulse_angle_90);
@ -288,7 +288,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_
/// - `speed` is the speed to move to change to, between -100 and 100.
/// - `time` is the number of milliseconds to take to get to the specified speed.
STATIC mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get speed
return mp_obj_new_int((self->pulse_cur - self->pulse_centre) * 100 / self->pulse_speed_100);

Wyświetl plik

@ -603,7 +603,7 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
};
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 = MP_OBJ_TO_PTR(self_in);
spi_print(print, self->spi, true);
}
@ -625,7 +625,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, co
{ MP_QSTR_nss, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SPI_NSS_SOFT} },
{ MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SPI_FIRSTBIT_MSB} },
{ MP_QSTR_ti, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
{ MP_QSTR_crc, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_crc, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
};
// parse args
@ -688,18 +688,18 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
pyb_spi_init_helper(spi_obj, n_args - 1, args + 1, &kw_args);
}
return (mp_obj_t)spi_obj;
return MP_OBJ_FROM_PTR(spi_obj);
}
STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_spi_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pyb_spi_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init);
/// \method deinit()
/// Turn off the SPI bus.
STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
pyb_spi_obj_t *self = self_in;
pyb_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
spi_deinit(self->spi);
return mp_const_none;
}
@ -721,7 +721,7 @@ STATIC mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
};
// parse args
pyb_spi_obj_t *self = pos_args[0];
pyb_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -756,7 +756,7 @@ STATIC mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
};
// parse args
pyb_spi_obj_t *self = pos_args[0];
pyb_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -797,7 +797,7 @@ STATIC mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_ma
};
// parse args
pyb_spi_obj_t *self = pos_args[0];
pyb_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -918,7 +918,7 @@ STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
};
STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
spi_print(print, self->spi, false);
}
@ -1016,15 +1016,15 @@ const mp_obj_type_t machine_hard_spi_type = {
.print = machine_hard_spi_print,
.make_new = mp_machine_spi_make_new, // delegate to master constructor
.protocol = &machine_hard_spi_p,
.locals_dict = (mp_obj_t)&mp_machine_spi_locals_dict,
.locals_dict = (mp_obj_dict_t*)&mp_machine_spi_locals_dict,
};
const spi_t *spi_from_mp_obj(mp_obj_t o) {
if (MP_OBJ_IS_TYPE(o, &pyb_spi_type)) {
pyb_spi_obj_t *self = o;
pyb_spi_obj_t *self = MP_OBJ_TO_PTR(o);
return self->spi;
} else if (MP_OBJ_IS_TYPE(o, &machine_hard_spi_type)) {
machine_hard_spi_obj_t *self = o;;
machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(o);
return self->spi;
} else {
mp_raise_TypeError("expecting an SPI object");

Wyświetl plik

@ -225,7 +225,7 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz
mp_arg_check_num(n_args, n_kw, 0, 0, false);
// return singleton object
return (mp_obj_t)&pyb_flash_obj;
return MP_OBJ_FROM_PTR(&pyb_flash_obj);
}
STATIC mp_obj_t pyb_flash_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
@ -277,14 +277,14 @@ void pyb_flash_init_vfs(fs_user_mount_t *vfs) {
vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL;
vfs->fatfs.drv = vfs;
vfs->fatfs.part = 1; // flash filesystem lives on first partition
vfs->readblocks[0] = (mp_obj_t)&pyb_flash_readblocks_obj;
vfs->readblocks[1] = (mp_obj_t)&pyb_flash_obj;
vfs->readblocks[2] = (mp_obj_t)storage_read_blocks; // native version
vfs->writeblocks[0] = (mp_obj_t)&pyb_flash_writeblocks_obj;
vfs->writeblocks[1] = (mp_obj_t)&pyb_flash_obj;
vfs->writeblocks[2] = (mp_obj_t)storage_write_blocks; // native version
vfs->u.ioctl[0] = (mp_obj_t)&pyb_flash_ioctl_obj;
vfs->u.ioctl[1] = (mp_obj_t)&pyb_flash_obj;
vfs->readblocks[0] = MP_OBJ_FROM_PTR(&pyb_flash_readblocks_obj);
vfs->readblocks[1] = MP_OBJ_FROM_PTR(&pyb_flash_obj);
vfs->readblocks[2] = MP_OBJ_FROM_PTR(storage_read_blocks); // native version
vfs->writeblocks[0] = MP_OBJ_FROM_PTR(&pyb_flash_writeblocks_obj);
vfs->writeblocks[1] = MP_OBJ_FROM_PTR(&pyb_flash_obj);
vfs->writeblocks[2] = MP_OBJ_FROM_PTR(storage_write_blocks); // native version
vfs->u.ioctl[0] = MP_OBJ_FROM_PTR(&pyb_flash_ioctl_obj);
vfs->u.ioctl[1] = MP_OBJ_FROM_PTR(&pyb_flash_obj);
}
#endif

Wyświetl plik

@ -157,7 +157,7 @@ void timer_deinit(void) {
for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) {
pyb_timer_obj_t *tim = MP_STATE_PORT(pyb_timer_obj_all)[i];
if (tim != NULL) {
pyb_timer_deinit(tim);
pyb_timer_deinit(MP_OBJ_FROM_PTR(tim));
}
}
}
@ -444,12 +444,12 @@ TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer) {
if (mp_obj_get_type(timer) != &pyb_timer_type) {
mp_raise_ValueError("need a Timer object");
}
pyb_timer_obj_t *self = timer;
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(timer);
return &self->tim;
}
STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_timer_obj_t *self = self_in;
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->tim.State == HAL_TIM_STATE_RESET) {
mp_printf(print, "Timer(%u)", self->tim_id);
@ -530,12 +530,12 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
/// You must either specify freq or both of period and prescaler.
STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_prescaler, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
{ MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIM_COUNTERMODE_UP} },
{ MP_QSTR_div, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_deadtime, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
};
@ -649,7 +649,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons
if (args[5].u_obj == mp_const_none) {
HAL_TIM_Base_Start(&self->tim);
} else {
pyb_timer_callback(self, args[5].u_obj);
pyb_timer_callback(MP_OBJ_FROM_PTR(self), args[5].u_obj);
}
return mp_const_none;
@ -772,17 +772,17 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
pyb_timer_init_helper(tim, n_args - 1, args + 1, &kw_args);
}
return (mp_obj_t)tim;
return MP_OBJ_FROM_PTR(tim);
}
STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_timer_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pyb_timer_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
// timer.deinit()
STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
pyb_timer_obj_t *self = self_in;
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
// Disable the base interrupt
pyb_timer_callback(self_in, mp_const_none);
@ -792,7 +792,7 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
// Disable the channel interrupts
while (chan != NULL) {
pyb_timer_channel_callback(chan, mp_const_none);
pyb_timer_channel_callback(MP_OBJ_FROM_PTR(chan), mp_const_none);
pyb_timer_channel_obj_t *prev_chan = chan;
chan = chan->next;
prev_chan->next = NULL;
@ -881,15 +881,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_pulse_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_pulse_width_percent, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_pulse_width_percent, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_compare, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
};
pyb_timer_obj_t *self = pos_args[0];
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_int_t channel = mp_obj_get_int(pos_args[1]);
if (channel < 1 || channel > 4) {
@ -911,7 +911,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
// channel (or None if no previous channel).
if (n_args == 2 && kw_args->used == 0) {
if (chan) {
return chan;
return MP_OBJ_FROM_PTR(chan);
}
return mp_const_none;
}
@ -921,7 +921,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
// the IRQ handler.
if (chan) {
// Turn off any IRQ associated with the channel.
pyb_timer_channel_callback(chan, mp_const_none);
pyb_timer_channel_callback(MP_OBJ_FROM_PTR(chan), mp_const_none);
// Unlink the channel from the list.
if (prev_chan) {
@ -948,14 +948,14 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) {
mp_raise_ValueError("pin argument needs to be be a Pin type");
}
const pin_obj_t *pin = pin_obj;
const pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
const pin_af_obj_t *af = pin_find_af(pin, AF_FN_TIM, self->tim_id);
if (af == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%q) doesn't have an af for Timer(%d)", pin->name, self->tim_id));
}
// pin.init(mode=AF_PP, af=idx)
const mp_obj_t args2[6] = {
(mp_obj_t)&pin_init_obj,
MP_OBJ_FROM_PTR(&pin_init_obj),
pin_obj,
MP_OBJ_NEW_QSTR(MP_QSTR_mode), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_AF_PP),
MP_OBJ_NEW_QSTR(MP_QSTR_af), MP_OBJ_NEW_SMALL_INT(af->idx)
@ -994,7 +994,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
if (chan->callback == mp_const_none) {
HAL_TIM_PWM_Start(&self->tim, TIMER_CHANNEL(chan));
} else {
pyb_timer_channel_callback(chan, chan->callback);
pyb_timer_channel_callback(MP_OBJ_FROM_PTR(chan), chan->callback);
}
// Start the complimentary channel too (if its supported)
if (IS_TIM_CCXN_INSTANCE(self->tim.Instance, TIMER_CHANNEL(chan))) {
@ -1032,7 +1032,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
if (chan->callback == mp_const_none) {
HAL_TIM_OC_Start(&self->tim, TIMER_CHANNEL(chan));
} else {
pyb_timer_channel_callback(chan, chan->callback);
pyb_timer_channel_callback(MP_OBJ_FROM_PTR(chan), chan->callback);
}
// Start the complimentary channel too (if its supported)
if (IS_TIM_CCXN_INSTANCE(self->tim.Instance, TIMER_CHANNEL(chan))) {
@ -1059,7 +1059,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
if (chan->callback == mp_const_none) {
HAL_TIM_IC_Start(&self->tim, TIMER_CHANNEL(chan));
} else {
pyb_timer_channel_callback(chan, chan->callback);
pyb_timer_channel_callback(MP_OBJ_FROM_PTR(chan), chan->callback);
}
break;
}
@ -1119,14 +1119,14 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid mode (%d)", chan->mode));
}
return chan;
return MP_OBJ_FROM_PTR(chan);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
/// \method counter([value])
/// Get or set the timer counter.
STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get
return mp_obj_new_int(self->tim.Instance->CNT);
@ -1141,7 +1141,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_time
/// \method source_freq()
/// Get the frequency of the source of the timer.
STATIC mp_obj_t pyb_timer_source_freq(mp_obj_t self_in) {
pyb_timer_obj_t *self = self_in;
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint32_t source_freq = timer_get_source_freq(self->tim_id);
return mp_obj_new_int(source_freq);
}
@ -1150,7 +1150,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_source_freq_obj, pyb_timer_source_fre
/// \method freq([value])
/// Get or set the frequency for the timer (changes prescaler and period if set).
STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get
uint32_t prescaler = self->tim.Instance->PSC & 0xffff;
@ -1179,7 +1179,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_f
/// \method prescaler([value])
/// Get or set the prescaler for the timer.
STATIC mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get
return mp_obj_new_int(self->tim.Instance->PSC & 0xffff);
@ -1194,7 +1194,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_ti
/// \method period([value])
/// Get or set the period of the timer.
STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get
return mp_obj_new_int(__HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self));
@ -1211,7 +1211,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer
/// `fun` is passed 1 argument, the timer object.
/// If `fun` is `None` then the callback will be disabled.
STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) {
pyb_timer_obj_t *self = self_in;
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (callback == mp_const_none) {
// stop interrupt (but not timer)
__HAL_TIM_DISABLE_IT(&self->tim, TIM_IT_UPDATE);
@ -1280,7 +1280,7 @@ const mp_obj_type_t pyb_timer_type = {
///
/// TimerChannel objects are created using the Timer.channel() method.
STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_timer_channel_obj_t *self = self_in;
pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "TimerChannel(timer=%u, channel=%u, mode=%s)",
self->timer->tim_id,
@ -1306,7 +1306,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
/// In edge aligned mode, a pulse_width of `period + 1` corresponds to a duty cycle of 100%
/// In center aligned mode, a pulse width of `period` corresponds to a duty cycle of 100%
STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// get
return mp_obj_new_int(__HAL_TIM_GET_COMPARE(&self->timer->tim, TIMER_CHANNEL(self)) & TIMER_CNT_MASK(self->timer));
@ -1325,7 +1325,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj
/// floating-point number for more accuracy. For example, a value of 25 gives
/// a duty cycle of 25%.
STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t period = compute_period(self->timer);
if (n_args == 1) {
// get
@ -1345,7 +1345,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_pulse_width_percent
/// `fun` is passed 1 argument, the timer object.
/// If `fun` is `None` then the callback will be disabled.
STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) {
pyb_timer_channel_obj_t *self = self_in;
pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (callback == mp_const_none) {
// stop interrupt (but not timer)
__HAL_TIM_DISABLE_IT(&self->timer->tim, TIMER_IRQ_MASK(self->channel));
@ -1421,7 +1421,7 @@ STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_o
gc_lock();
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_call_function_1(callback, tim);
mp_call_function_1(callback, MP_OBJ_FROM_PTR(tim));
nlr_pop();
} else {
// Uncaught exception; disable the callback so it doesn't run again.
@ -1432,7 +1432,7 @@ STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_o
} else {
printf("uncaught exception in Timer(%u) channel %u interrupt handler\n", tim->tim_id, channel);
}
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
gc_unlock();
mp_sched_unlock();

Wyświetl plik

@ -123,7 +123,7 @@ void uart_deinit(void) {
for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(pyb_uart_obj_all)); i++) {
pyb_uart_obj_t *uart_obj = MP_STATE_PORT(pyb_uart_obj_all)[i];
if (uart_obj != NULL) {
pyb_uart_deinit(uart_obj);
pyb_uart_deinit(MP_OBJ_FROM_PTR(uart_obj));
}
}
}
@ -542,7 +542,7 @@ void uart_irq_handler(mp_uint_t uart_id) {
/* MicroPython bindings */
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 = MP_OBJ_TO_PTR(self_in);
if (!self->is_enabled) {
mp_printf(print, "UART(%u)", self->uart_id);
} else {
@ -596,7 +596,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_baudrate, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 9600} },
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
{ MP_QSTR_parity, MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_parity, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_flow, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = UART_HWCONTROL_NONE} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
@ -835,18 +835,18 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
pyb_uart_init_helper(self, n_args - 1, args + 1, &kw_args);
}
return self;
return MP_OBJ_FROM_PTR(self);
}
STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_uart_init_helper(args[0], n_args - 1, args + 1, kw_args);
return pyb_uart_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
/// \method deinit()
/// Turn off the UART bus.
STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->is_enabled = false;
UART_HandleTypeDef *uart = &self->uart;
HAL_UART_DeInit(uart);
@ -912,7 +912,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit);
/// \method any()
/// Return `True` if any characters waiting, else `False`.
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(uart_rx_any(self));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
@ -921,7 +921,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
/// Write a single character on the bus. `char` is an integer to write.
/// Return value: `None`.
STATIC mp_obj_t pyb_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get the character to write (might be 9 bits)
uint16_t data = mp_obj_get_int(char_in);
@ -946,7 +946,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_uart_writechar_obj, pyb_uart_writechar);
/// Receive a single character on the bus.
/// Return value: The character read, as an integer. Returns -1 on timeout.
STATIC mp_obj_t pyb_uart_readchar(mp_obj_t self_in) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (uart_rx_wait(self, self->timeout)) {
return MP_OBJ_NEW_SMALL_INT(uart_rx_char(self));
} else {
@ -958,7 +958,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
// uart.sendbreak()
STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
#if defined(STM32F0) || defined(STM32F7) || defined(STM32L4) || defined(STM32H7)
self->uart.Instance->RQR = USART_RQR_SBKRQ; // write-only register
#else
@ -996,7 +996,7 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
byte *buf = buf_in;
// check that size is a multiple of character width
@ -1038,7 +1038,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
}
STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
pyb_uart_obj_t *self = self_in;
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
const byte *buf = buf_in;
// check that size is a multiple of character width
@ -1064,11 +1064,11 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
}
}
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
pyb_uart_obj_t *self = self_in;
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
uintptr_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD) && uart_rx_any(self)) {
ret |= MP_STREAM_POLL_RD;

Wyświetl plik

@ -79,15 +79,15 @@ STATIC const mp_obj_str_t pyb_usb_hid_mouse_desc_obj = {
USBD_HID_MOUSE_REPORT_DESC_SIZE,
USBD_HID_MOUSE_ReportDesc,
};
const mp_obj_tuple_t pyb_usb_hid_mouse_obj = {
const mp_rom_obj_tuple_t pyb_usb_hid_mouse_obj = {
{&mp_type_tuple},
5,
{
MP_OBJ_NEW_SMALL_INT(1), // subclass: boot
MP_OBJ_NEW_SMALL_INT(2), // protocol: mouse
MP_OBJ_NEW_SMALL_INT(USBD_HID_MOUSE_MAX_PACKET),
MP_OBJ_NEW_SMALL_INT(8), // polling interval: 8ms
(mp_obj_t)&pyb_usb_hid_mouse_desc_obj,
MP_ROM_INT(1), // subclass: boot
MP_ROM_INT(2), // protocol: mouse
MP_ROM_INT(USBD_HID_MOUSE_MAX_PACKET),
MP_ROM_INT(8), // polling interval: 8ms
MP_ROM_PTR(&pyb_usb_hid_mouse_desc_obj),
},
};
@ -98,15 +98,15 @@ STATIC const mp_obj_str_t pyb_usb_hid_keyboard_desc_obj = {
USBD_HID_KEYBOARD_REPORT_DESC_SIZE,
USBD_HID_KEYBOARD_ReportDesc,
};
const mp_obj_tuple_t pyb_usb_hid_keyboard_obj = {
const mp_rom_obj_tuple_t pyb_usb_hid_keyboard_obj = {
{&mp_type_tuple},
5,
{
MP_OBJ_NEW_SMALL_INT(1), // subclass: boot
MP_OBJ_NEW_SMALL_INT(1), // protocol: keyboard
MP_OBJ_NEW_SMALL_INT(USBD_HID_KEYBOARD_MAX_PACKET),
MP_OBJ_NEW_SMALL_INT(8), // polling interval: 8ms
(mp_obj_t)&pyb_usb_hid_keyboard_desc_obj,
MP_ROM_INT(1), // subclass: boot
MP_ROM_INT(1), // protocol: keyboard
MP_ROM_INT(USBD_HID_KEYBOARD_MAX_PACKET),
MP_ROM_INT(8), // polling interval: 8ms
MP_ROM_PTR(&pyb_usb_hid_keyboard_desc_obj),
},
};
@ -224,10 +224,10 @@ usbd_cdc_itf_t *usb_vcp_get(int idx) {
STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_vid, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = USBD_VID} },
{ MP_QSTR_pid, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_hid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = (mp_obj_t)&pyb_usb_hid_mouse_obj} },
{ MP_QSTR_hid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&pyb_usb_hid_mouse_obj)} },
#if USBD_SUPPORT_HS_MODE
{ MP_QSTR_high_speed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
#endif
@ -385,7 +385,7 @@ STATIC const pyb_usb_vcp_obj_t pyb_usb_vcp2_obj = {{&pyb_usb_vcp_type}, &usb_dev
#endif
STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
int id = ((pyb_usb_vcp_obj_t*)self_in)->cdc_itf - &usb_device.usbd_cdc_itf;
int id = ((pyb_usb_vcp_obj_t*)MP_OBJ_TO_PTR(self_in))->cdc_itf - &usb_device.usbd_cdc_itf;
mp_printf(print, "USB_VCP(%u)", id);
}
@ -549,11 +549,11 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t
return ret;
}
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
mp_uint_t ret;
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
uintptr_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD) && usbd_cdc_rx_num(self->cdc_itf) > 0) {
ret |= MP_STREAM_POLL_RD;
@ -602,7 +602,7 @@ STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, s
// TODO raise exception if USB is not configured for HID
// return the USB HID object
return (mp_obj_t)&pyb_usb_hid_obj;
return MP_OBJ_FROM_PTR(&pyb_usb_hid_obj);
}
/// \method recv(data, *, timeout=5000)
@ -685,11 +685,11 @@ STATIC const mp_rom_map_elem_t pyb_usb_hid_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_usb_hid_locals_dict, pyb_usb_hid_locals_dict_table);
STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
pyb_usb_hid_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
uintptr_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD) && usbd_hid_rx_num(&self->usb_dev->usbd_hid_itf) > 0) {
ret |= MP_STREAM_POLL_RD;

Wyświetl plik

@ -51,8 +51,8 @@ typedef enum {
extern mp_uint_t pyb_usb_flags;
extern pyb_usb_storage_medium_t pyb_usb_storage_medium;
extern const struct _mp_obj_tuple_t pyb_usb_hid_mouse_obj;
extern const struct _mp_obj_tuple_t pyb_usb_hid_keyboard_obj;
extern const struct _mp_rom_obj_tuple_t pyb_usb_hid_mouse_obj;
extern const struct _mp_rom_obj_tuple_t pyb_usb_hid_keyboard_obj;
extern const mp_obj_type_t pyb_usb_vcp_type;
extern const mp_obj_type_t pyb_usb_hid_type;
MP_DECLARE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj);

Wyświetl plik

@ -85,7 +85,7 @@ STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, si
// then no extint will be called until it is set via the callback method.
// return static switch object
return (mp_obj_t)&pyb_switch_obj;
return MP_OBJ_FROM_PTR(&pyb_switch_obj);
}
/// \method \call()
@ -118,10 +118,10 @@ mp_obj_t pyb_switch_callback(mp_obj_t self_in, mp_obj_t callback) {
// Init the EXTI each time this function is called, since the EXTI
// may have been disabled by an exception in the interrupt, or the
// user disabling the line explicitly.
extint_register((mp_obj_t)MICROPY_HW_USRSW_PIN,
extint_register(MP_OBJ_FROM_PTR(MICROPY_HW_USRSW_PIN),
MICROPY_HW_USRSW_EXTI_MODE,
MICROPY_HW_USRSW_PULL,
callback == mp_const_none ? mp_const_none : (mp_obj_t)&switch_callback_obj,
callback == mp_const_none ? mp_const_none : MP_OBJ_FROM_PTR(&switch_callback_obj),
true);
return mp_const_none;
}

Wyświetl plik

@ -86,7 +86,7 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_
// start the watch dog
IWDG->KR = 0xcccc;
return (mp_obj_t)&pyb_wdt;
return MP_OBJ_FROM_PTR(&pyb_wdt);
}
STATIC mp_obj_t pyb_wdt_feed(mp_obj_t self_in) {