all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
committed by
Damien George
parent
b3f2f18f92
commit
decf8e6a8b
@@ -89,7 +89,7 @@ void accel_init(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void accel_start(void) {
|
||||
static void accel_start(void) {
|
||||
// start the I2C bus in master mode
|
||||
i2c_init(I2C1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA, 400000, I2C_TIMEOUT_MS);
|
||||
|
||||
@@ -153,7 +153,7 @@ typedef struct _pyb_accel_obj_t {
|
||||
int16_t buf[NUM_AXIS * FILT_DEPTH];
|
||||
} pyb_accel_obj_t;
|
||||
|
||||
STATIC pyb_accel_obj_t pyb_accel_obj;
|
||||
static pyb_accel_obj_t pyb_accel_obj;
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create and return an accelerometer object.
|
||||
@@ -166,7 +166,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj;
|
||||
/// accel = pyb.Accel()
|
||||
/// pyb.delay(20)
|
||||
/// print(accel.x())
|
||||
STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -177,7 +177,7 @@ STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return MP_OBJ_FROM_PTR(&pyb_accel_obj);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t read_axis(int axis) {
|
||||
static mp_obj_t read_axis(int axis) {
|
||||
uint8_t data[1] = { axis };
|
||||
i2c_writeto(I2C1, ACCEL_ADDR, data, 1, false);
|
||||
i2c_readfrom(I2C1, ACCEL_ADDR, data, 1, true);
|
||||
@@ -186,28 +186,28 @@ STATIC mp_obj_t read_axis(int axis) {
|
||||
|
||||
/// \method x()
|
||||
/// Get the x-axis value.
|
||||
STATIC mp_obj_t pyb_accel_x(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_accel_x(mp_obj_t self_in) {
|
||||
return read_axis(ACCEL_REG_X);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_x_obj, pyb_accel_x);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_x_obj, pyb_accel_x);
|
||||
|
||||
/// \method y()
|
||||
/// Get the y-axis value.
|
||||
STATIC mp_obj_t pyb_accel_y(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_accel_y(mp_obj_t self_in) {
|
||||
return read_axis(ACCEL_REG_Y);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_y_obj, pyb_accel_y);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_y_obj, pyb_accel_y);
|
||||
|
||||
/// \method z()
|
||||
/// Get the z-axis value.
|
||||
STATIC mp_obj_t pyb_accel_z(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_accel_z(mp_obj_t self_in) {
|
||||
return read_axis(ACCEL_REG_Z);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_z_obj, pyb_accel_z);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_z_obj, pyb_accel_z);
|
||||
|
||||
/// \method tilt()
|
||||
/// Get the tilt register.
|
||||
STATIC mp_obj_t pyb_accel_tilt(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_accel_tilt(mp_obj_t self_in) {
|
||||
#if MICROPY_HW_HAS_MMA7660
|
||||
uint8_t data[1] = { ACCEL_REG_TILT };
|
||||
i2c_writeto(I2C1, ACCEL_ADDR, data, 1, false);
|
||||
@@ -218,11 +218,11 @@ STATIC mp_obj_t pyb_accel_tilt(mp_obj_t self_in) {
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_tilt_obj, pyb_accel_tilt);
|
||||
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) {
|
||||
static mp_obj_t pyb_accel_filtered_xyz(mp_obj_t 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));
|
||||
@@ -251,9 +251,9 @@ STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) {
|
||||
|
||||
return mp_obj_new_tuple(3, tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz);
|
||||
|
||||
STATIC mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) {
|
||||
static mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) {
|
||||
uint8_t data[1] = { mp_obj_get_int(reg) };
|
||||
i2c_writeto(I2C1, ACCEL_ADDR, data, 1, false);
|
||||
i2c_readfrom(I2C1, ACCEL_ADDR, data, 1, true);
|
||||
@@ -261,14 +261,14 @@ STATIC mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(pyb_accel_read_obj, pyb_accel_read);
|
||||
|
||||
STATIC mp_obj_t pyb_accel_write(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) {
|
||||
static mp_obj_t pyb_accel_write(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) {
|
||||
uint8_t data[2] = { mp_obj_get_int(reg), mp_obj_get_int(val) };
|
||||
i2c_writeto(I2C1, ACCEL_ADDR, data, 2, true);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(pyb_accel_write_obj, pyb_accel_write);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = {
|
||||
// TODO add init, deinit, and perhaps reset methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&pyb_accel_x_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&pyb_accel_y_obj) },
|
||||
@@ -279,7 +279,7 @@ STATIC const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&pyb_accel_write_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_accel_locals_dict, pyb_accel_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_accel_locals_dict, pyb_accel_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_accel_type,
|
||||
|
||||
@@ -245,7 +245,7 @@ static inline uint32_t adc_get_internal_channel(uint32_t channel) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
STATIC bool is_adcx_channel(int channel) {
|
||||
static bool is_adcx_channel(int channel) {
|
||||
#if defined(STM32F411xE)
|
||||
// The HAL has an incorrect IS_ADC_CHANNEL macro for the F411 so we check for temp
|
||||
return IS_ADC_CHANNEL(channel) || channel == ADC_CHANNEL_TEMPSENSOR;
|
||||
@@ -272,7 +272,7 @@ STATIC bool is_adcx_channel(int channel) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t timeout) {
|
||||
static void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t timeout) {
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
#if defined(STM32F4) || defined(STM32F7) || defined(STM32L1)
|
||||
while ((adcHandle->Instance->SR & ADC_FLAG_EOC) != ADC_FLAG_EOC) {
|
||||
@@ -287,7 +287,7 @@ STATIC void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t ti
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void adcx_clock_enable(ADC_HandleTypeDef *adch) {
|
||||
static void adcx_clock_enable(ADC_HandleTypeDef *adch) {
|
||||
#if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32L1)
|
||||
ADCx_CLK_ENABLE();
|
||||
#elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
|
||||
@@ -316,7 +316,7 @@ STATIC void adcx_clock_enable(ADC_HandleTypeDef *adch) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) {
|
||||
static void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) {
|
||||
adcx_clock_enable(adch);
|
||||
|
||||
adch->Init.Resolution = resolution;
|
||||
@@ -384,7 +384,7 @@ STATIC void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) {
|
||||
static void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) {
|
||||
adc_obj->handle.Instance = adc;
|
||||
adcx_init_periph(&adc_obj->handle, ADC_RESOLUTION_12B);
|
||||
|
||||
@@ -397,7 +397,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) {
|
||||
static void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) {
|
||||
ADC_ChannelConfTypeDef sConfig;
|
||||
|
||||
#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
|
||||
@@ -462,7 +462,7 @@ STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel)
|
||||
HAL_ADC_ConfigChannel(adc_handle, &sConfig);
|
||||
}
|
||||
|
||||
STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) {
|
||||
static uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) {
|
||||
uint32_t value;
|
||||
#if defined(STM32G4)
|
||||
// For STM32G4 there is errata 2.7.7, "Wrong ADC result if conversion done late after
|
||||
@@ -479,7 +479,7 @@ STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) {
|
||||
return value;
|
||||
}
|
||||
|
||||
STATIC uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t channel) {
|
||||
static uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t channel) {
|
||||
adc_config_channel(adcHandle, channel);
|
||||
uint32_t raw_value = adc_read_channel(adcHandle);
|
||||
|
||||
@@ -498,7 +498,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) {
|
||||
static void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
#if defined STM32H5
|
||||
unsigned adc_id = 1;
|
||||
@@ -516,7 +516,7 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
/// \classmethod \constructor(pin)
|
||||
/// Create an ADC object associated with the given pin.
|
||||
/// This allows you to then read analog values on that pin.
|
||||
STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@@ -587,11 +587,11 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
|
||||
/// \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) {
|
||||
static mp_obj_t adc_read(mp_obj_t 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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
|
||||
|
||||
/// \method read_timed(buf, timer)
|
||||
///
|
||||
@@ -627,7 +627,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
|
||||
/// print(val) # print the value out
|
||||
///
|
||||
/// 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) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
@@ -699,7 +699,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_
|
||||
|
||||
return mp_obj_new_int(bufinfo.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_obj, adc_read_timed);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_obj, adc_read_timed);
|
||||
|
||||
// read_timed_multi((adcx, adcy, ...), (bufx, bufy, ...), timer)
|
||||
//
|
||||
@@ -709,7 +709,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_obj, adc_read_timed);
|
||||
// the sample resolution will be reduced to 8 bits.
|
||||
//
|
||||
// This function should not allocate any heap memory.
|
||||
STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_in, mp_obj_t tim_in) {
|
||||
static mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_in, mp_obj_t tim_in) {
|
||||
size_t nadcs, nbufs;
|
||||
mp_obj_t *adc_array, *buf_array;
|
||||
mp_obj_get_array(adc_array_in, &nadcs, &adc_array);
|
||||
@@ -802,16 +802,16 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
|
||||
|
||||
return mp_obj_new_bool(success);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_multi_fun_obj, adc_read_timed_multi);
|
||||
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(adc_read_timed_multi_obj, MP_ROM_PTR(&adc_read_timed_multi_fun_obj));
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_multi_fun_obj, adc_read_timed_multi);
|
||||
static MP_DEFINE_CONST_STATICMETHOD_OBJ(adc_read_timed_multi_obj, MP_ROM_PTR(&adc_read_timed_multi_fun_obj));
|
||||
|
||||
STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t adc_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&adc_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_read_timed), MP_ROM_PTR(&adc_read_timed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_read_timed_multi), MP_ROM_PTR(&adc_read_timed_multi_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_adc_type,
|
||||
@@ -897,7 +897,7 @@ int adc_get_resolution(ADC_HandleTypeDef *adcHandle) {
|
||||
return 12;
|
||||
}
|
||||
|
||||
STATIC uint32_t adc_config_and_read_ref(ADC_HandleTypeDef *adcHandle, uint32_t channel) {
|
||||
static uint32_t adc_config_and_read_ref(ADC_HandleTypeDef *adcHandle, uint32_t channel) {
|
||||
uint32_t raw_value = adc_config_and_read_channel(adcHandle, channel);
|
||||
// Scale raw reading to the number of bits used by the calibration constants
|
||||
return raw_value << (ADC_CAL_BITS - adc_get_resolution(adcHandle));
|
||||
@@ -919,7 +919,7 @@ int adc_read_core_temp(ADC_HandleTypeDef *adcHandle) {
|
||||
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
// correction factor for reference value
|
||||
STATIC volatile float adc_refcor = 1.0f;
|
||||
static volatile float adc_refcor = 1.0f;
|
||||
|
||||
float adc_read_core_temp_float(ADC_HandleTypeDef *adcHandle) {
|
||||
#if defined(STM32G4) || defined(STM32L1) || defined(STM32L4)
|
||||
@@ -974,7 +974,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings : adc_all object */
|
||||
|
||||
STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, false);
|
||||
|
||||
@@ -990,7 +990,7 @@ STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
|
||||
static mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
|
||||
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uint32_t chan = adc_get_internal_channel(mp_obj_get_int(channel));
|
||||
if (!is_adcx_channel(chan)) {
|
||||
@@ -999,9 +999,9 @@ STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
|
||||
uint32_t data = adc_config_and_read_channel(&self->handle, chan);
|
||||
return mp_obj_new_int(data);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(adc_all_read_channel_obj, adc_all_read_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) {
|
||||
static mp_obj_t adc_all_read_core_temp(mp_obj_t 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);
|
||||
@@ -1011,32 +1011,32 @@ STATIC mp_obj_t adc_all_read_core_temp(mp_obj_t self_in) {
|
||||
return mp_obj_new_int(data);
|
||||
#endif
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_temp);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_temp);
|
||||
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
STATIC mp_obj_t adc_all_read_core_vbat(mp_obj_t self_in) {
|
||||
static mp_obj_t adc_all_read_core_vbat(mp_obj_t 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_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) {
|
||||
static mp_obj_t adc_all_read_core_vref(mp_obj_t 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_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) {
|
||||
static mp_obj_t adc_all_read_vref(mp_obj_t 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(ADC_SCALE_V * adc_refcor);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_vref_obj, adc_all_read_vref);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_vref_obj, adc_all_read_vref);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t adc_all_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t adc_all_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read_channel), MP_ROM_PTR(&adc_all_read_channel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_read_core_temp), MP_ROM_PTR(&adc_all_read_core_temp_obj) },
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
@@ -1046,7 +1046,7 @@ STATIC const mp_rom_map_elem_t adc_all_locals_dict_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_adc_all_type,
|
||||
|
||||
@@ -55,7 +55,7 @@ NORETURN void boardctrl_fatal_error(const char *msg) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void flash_error(int n) {
|
||||
static void flash_error(int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
led_state(PYB_LED_RED, 1);
|
||||
led_state(PYB_LED_GREEN, 0);
|
||||
@@ -88,7 +88,7 @@ void boardctrl_maybe_enter_mboot(size_t n_args, const void *args_in) {
|
||||
#endif
|
||||
|
||||
#if !MICROPY_HW_USES_BOOTLOADER
|
||||
STATIC uint update_reset_mode(uint reset_mode) {
|
||||
static uint update_reset_mode(uint reset_mode) {
|
||||
// Note: Must use HAL_Delay here as MicroPython is not yet initialised
|
||||
// and mp_hal_delay_ms will attempt to invoke the scheduler.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
||||
|
||||
STATIC const spi_proto_cfg_t spi_bus = {
|
||||
static const spi_proto_cfg_t spi_bus = {
|
||||
.spi = &spi_obj[0], // SPI1
|
||||
.baudrate = 25000000,
|
||||
.polarity = 0,
|
||||
@@ -13,7 +13,7 @@ STATIC const spi_proto_cfg_t spi_bus = {
|
||||
.firstbit = SPI_FIRSTBIT_MSB,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
|
||||
// Shared cache for first and second SPI block devices
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
#endif
|
||||
|
||||
// First external SPI flash uses hardware QSPI interface
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
|
||||
// Shared cache for first and second SPI block devices
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
#endif
|
||||
|
||||
// First external SPI flash uses hardware QSPI interface
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
|
||||
// Shared cache for first and second SPI block devices
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
#endif
|
||||
|
||||
// First external SPI flash uses hardware QSPI interface
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
// Mboot doesn't support hardware SPI, so use software SPI instead.
|
||||
|
||||
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
static const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
|
||||
.polarity = 0,
|
||||
.phase = 0,
|
||||
@@ -52,7 +52,7 @@ mp_spiflash_t board_mboot_spiflash;
|
||||
|
||||
#else
|
||||
|
||||
STATIC const spi_proto_cfg_t spi_bus = {
|
||||
static const spi_proto_cfg_t spi_bus = {
|
||||
.spi = &spi_obj[1], // SPI2 hardware peripheral
|
||||
.baudrate = 25000000,
|
||||
.polarity = 0,
|
||||
@@ -61,7 +61,7 @@ STATIC const spi_proto_cfg_t spi_bus = {
|
||||
.firstbit = SPI_FIRSTBIT_MSB,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#define CC2564_TIMER_BT_SLOWCLOCK_TIM_CH 4
|
||||
#endif
|
||||
|
||||
STATIC void cc2564_wait_cts_low(mp_hal_pin_obj_t cts, uint32_t timeout_ms) {
|
||||
static void cc2564_wait_cts_low(mp_hal_pin_obj_t cts, uint32_t timeout_ms) {
|
||||
for (int i = 0; i < timeout_ms; ++i) {
|
||||
if (mp_hal_pin_read(cts) == 0) {
|
||||
break;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
||||
|
||||
STATIC const spi_proto_cfg_t spi_bus = {
|
||||
static const spi_proto_cfg_t spi_bus = {
|
||||
.spi = &spi_obj[2], // SPI3 hardware peripheral
|
||||
.baudrate = 25000000,
|
||||
.polarity = 0,
|
||||
@@ -13,7 +13,7 @@ STATIC const spi_proto_cfg_t spi_bus = {
|
||||
.firstbit = SPI_FIRSTBIT_MSB,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -29,12 +29,12 @@
|
||||
|
||||
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
|
||||
// Shared cache for first and second SPI block devices
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
#endif
|
||||
|
||||
// First external SPI flash uses software QSPI interface
|
||||
|
||||
STATIC const mp_soft_qspi_obj_t soft_qspi_bus = {
|
||||
static const mp_soft_qspi_obj_t soft_qspi_bus = {
|
||||
.cs = MICROPY_HW_SPIFLASH_CS,
|
||||
.clk = MICROPY_HW_SPIFLASH_SCK,
|
||||
.io0 = MICROPY_HW_SPIFLASH_IO0,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// External SPI flash uses standard SPI interface
|
||||
|
||||
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
static const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
|
||||
.polarity = 0,
|
||||
.phase = 0,
|
||||
@@ -13,7 +13,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.miso = MICROPY_HW_SPIFLASH_MISO,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// This configuration is needed for mboot to be able to write to the external QSPI flash
|
||||
|
||||
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
#endif
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// External SPI flash uses standard SPI interface
|
||||
|
||||
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
static const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
|
||||
.polarity = 0,
|
||||
.phase = 0,
|
||||
@@ -11,7 +11,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.miso = MICROPY_HW_SPIFLASH_MISO,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// External SPI flash uses standard SPI interface
|
||||
|
||||
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
static const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
|
||||
.polarity = 0,
|
||||
.phase = 0,
|
||||
@@ -13,7 +13,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.miso = MICROPY_HW_SPIFLASH_MISO,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// External SPI flash uses standard SPI interface
|
||||
|
||||
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
static const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
|
||||
.polarity = 0,
|
||||
.phase = 0,
|
||||
@@ -13,7 +13,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = {
|
||||
.miso = MICROPY_HW_SPIFLASH_MISO,
|
||||
};
|
||||
|
||||
STATIC mp_spiflash_cache_t spi_bdev_cache;
|
||||
static mp_spiflash_cache_t spi_bdev_cache;
|
||||
|
||||
const mp_spiflash_config_t spiflash_config = {
|
||||
.bus_kind = MP_SPIFLASH_BUS_SPI,
|
||||
|
||||
@@ -312,7 +312,7 @@ HAL_StatusTypeDef CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void can_rx_irq_handler(uint can_id, uint fifo_id) {
|
||||
static void can_rx_irq_handler(uint can_id, uint fifo_id) {
|
||||
mp_obj_t callback;
|
||||
pyb_can_obj_t *self;
|
||||
mp_obj_t irq_reason = MP_OBJ_NEW_SMALL_INT(0);
|
||||
@@ -354,7 +354,7 @@ STATIC void can_rx_irq_handler(uint can_id, uint fifo_id) {
|
||||
pyb_can_handle_callback(self, fifo_id, callback, irq_reason);
|
||||
}
|
||||
|
||||
STATIC void can_sce_irq_handler(uint can_id) {
|
||||
static void can_sce_irq_handler(uint can_id) {
|
||||
pyb_can_obj_t *self = MP_STATE_PORT(pyb_can_obj_all)[can_id - 1];
|
||||
if (self) {
|
||||
self->can.Instance->MSR = CAN_MSR_ERRI;
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(TIM6)
|
||||
STATIC void TIM6_Config(uint freq) {
|
||||
static void TIM6_Config(uint freq) {
|
||||
// Init TIM6 at the required frequency (in Hz)
|
||||
TIM_HandleTypeDef *tim = timer_tim6_init(freq);
|
||||
|
||||
@@ -86,7 +86,7 @@ STATIC void TIM6_Config(uint freq) {
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC uint32_t TIMx_Config(mp_obj_t timer) {
|
||||
static uint32_t TIMx_Config(mp_obj_t timer) {
|
||||
// TRGO selection to trigger DAC
|
||||
TIM_HandleTypeDef *tim = pyb_timer_get_handle(timer);
|
||||
TIM_MasterConfigTypeDef config;
|
||||
@@ -122,7 +122,7 @@ STATIC uint32_t TIMx_Config(mp_obj_t timer) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void dac_deinit(uint32_t dac_channel) {
|
||||
static void dac_deinit(uint32_t dac_channel) {
|
||||
DAC->CR &= ~(DAC_CR_EN1 << dac_channel);
|
||||
#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4)
|
||||
DAC->MCR = (DAC->MCR & ~(DAC_MCR_MODE1_Msk << dac_channel)) | (DAC_OUTPUTBUFFER_DISABLE << dac_channel);
|
||||
@@ -138,7 +138,7 @@ void dac_deinit_all(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t outbuf) {
|
||||
static void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t outbuf) {
|
||||
DAC->CR &= ~(DAC_CR_EN1 << dac_channel);
|
||||
uint32_t cr_off = DAC_CR_DMAEN1 | DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1;
|
||||
uint32_t cr_on = trig;
|
||||
@@ -151,7 +151,7 @@ STATIC void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t out
|
||||
DAC->CR = (DAC->CR & ~(cr_off << dac_channel)) | (cr_on << dac_channel);
|
||||
}
|
||||
|
||||
STATIC void dac_set_value(uint32_t dac_channel, uint32_t align, uint32_t value) {
|
||||
static void dac_set_value(uint32_t dac_channel, uint32_t align, uint32_t value) {
|
||||
uint32_t base;
|
||||
if (dac_channel == DAC_CHANNEL_1) {
|
||||
base = (uint32_t)&DAC->DHR12R1;
|
||||
@@ -163,11 +163,11 @@ STATIC void dac_set_value(uint32_t dac_channel, uint32_t align, uint32_t value)
|
||||
*(volatile uint32_t *)(base + align) = value;
|
||||
}
|
||||
|
||||
STATIC void dac_start(uint32_t dac_channel) {
|
||||
static void dac_start(uint32_t dac_channel) {
|
||||
DAC->CR |= DAC_CR_EN1 << dac_channel;
|
||||
}
|
||||
|
||||
STATIC void dac_start_dma(uint32_t dac_channel, const dma_descr_t *dma_descr, uint32_t dma_mode, uint32_t bit_size, uint32_t dac_align, size_t len, void *buf) {
|
||||
static void dac_start_dma(uint32_t dac_channel, const dma_descr_t *dma_descr, uint32_t dma_mode, uint32_t bit_size, uint32_t dac_align, size_t len, void *buf) {
|
||||
uint32_t dma_align;
|
||||
if (bit_size == 8) {
|
||||
#if defined(STM32G4)
|
||||
@@ -216,9 +216,9 @@ typedef struct _pyb_dac_obj_t {
|
||||
uint8_t outbuf_waveform;
|
||||
} pyb_dac_obj_t;
|
||||
|
||||
STATIC pyb_dac_obj_t pyb_dac_obj[2];
|
||||
static pyb_dac_obj_t pyb_dac_obj[2];
|
||||
|
||||
STATIC void pyb_dac_reconfigure(pyb_dac_obj_t *self, uint32_t cr, uint32_t outbuf, uint32_t value) {
|
||||
static void pyb_dac_reconfigure(pyb_dac_obj_t *self, uint32_t cr, uint32_t outbuf, uint32_t value) {
|
||||
bool restart = false;
|
||||
const uint32_t cr_mask = DAC_CR_DMAEN1 | DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_EN1;
|
||||
if (((DAC->CR >> self->dac_channel) & cr_mask) != (cr | DAC_CR_EN1)) {
|
||||
@@ -240,14 +240,14 @@ STATIC void pyb_dac_reconfigure(pyb_dac_obj_t *self, uint32_t cr, uint32_t outbu
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "DAC(%u, bits=%u)",
|
||||
self->dac_channel == DAC_CHANNEL_1 ? 1 : 2,
|
||||
self->bits);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_dac_init_helper(pyb_dac_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_bits, MP_ARG_INT, {.u_int = 8} },
|
||||
{ MP_QSTR_buffering, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
|
||||
@@ -315,7 +315,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp
|
||||
///
|
||||
/// `port` can be a pin object, or an integer (1 or 2).
|
||||
/// DAC(1) is on pin X5 and DAC(2) is on pin X6.
|
||||
STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -360,25 +360,25 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
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) {
|
||||
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(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);
|
||||
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) {
|
||||
static mp_obj_t pyb_dac_deinit(mp_obj_t self_in) {
|
||||
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
dac_deinit(self->dac_channel);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit);
|
||||
|
||||
#if defined(TIM6)
|
||||
/// \method noise(freq)
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_dac_noise(mp_obj_t self_in, mp_obj_t freq) {
|
||||
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// set TIM6 to trigger the DAC at the given frequency
|
||||
@@ -390,7 +390,7 @@ STATIC mp_obj_t pyb_dac_noise(mp_obj_t self_in, mp_obj_t freq) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise);
|
||||
#endif
|
||||
|
||||
#if defined(TIM6)
|
||||
@@ -398,7 +398,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise);
|
||||
/// Generate a triangle wave. The value on the DAC output changes at
|
||||
/// the given frequency, and the frequency of the repeating triangle wave
|
||||
/// itself is 8192 times smaller.
|
||||
STATIC mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) {
|
||||
static mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) {
|
||||
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// set TIM6 to trigger the DAC at the given frequency
|
||||
@@ -410,12 +410,12 @@ STATIC mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_triangle_obj, pyb_dac_triangle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_triangle_obj, pyb_dac_triangle);
|
||||
#endif
|
||||
|
||||
/// \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) {
|
||||
static mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) {
|
||||
pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// DAC output is always 12-bit at the hardware level, and we provide support
|
||||
@@ -426,7 +426,7 @@ STATIC mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write);
|
||||
|
||||
#if defined(TIM6)
|
||||
/// \method write_timed(data, freq, *, mode=DAC.NORMAL)
|
||||
@@ -497,10 +497,10 @@ mp_obj_t pyb_dac_write_timed(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_write_timed_obj, 1, pyb_dac_write_timed);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_write_timed_obj, 1, pyb_dac_write_timed);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_dac_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_dac_deinit_obj) },
|
||||
@@ -516,7 +516,7 @@ STATIC const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_CIRCULAR), MP_ROM_INT(DMA_CIRCULAR) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_dac_locals_dict, pyb_dac_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_dac_locals_dict, pyb_dac_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_dac_type,
|
||||
|
||||
@@ -143,10 +143,10 @@ static eth_dma_t eth_dma __attribute__((aligned(16384)));
|
||||
|
||||
eth_t eth_instance;
|
||||
|
||||
STATIC void eth_mac_deinit(eth_t *self);
|
||||
STATIC void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf);
|
||||
static void eth_mac_deinit(eth_t *self);
|
||||
static void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf);
|
||||
|
||||
STATIC void eth_phy_write(uint32_t reg, uint32_t val) {
|
||||
static void eth_phy_write(uint32_t reg, uint32_t val) {
|
||||
#if defined(STM32H5) || defined(STM32H7)
|
||||
while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) {
|
||||
}
|
||||
@@ -172,7 +172,7 @@ STATIC void eth_phy_write(uint32_t reg, uint32_t val) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC uint32_t eth_phy_read(uint32_t reg) {
|
||||
static uint32_t eth_phy_read(uint32_t reg) {
|
||||
#if defined(STM32H5) || defined(STM32H7)
|
||||
while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) {
|
||||
}
|
||||
@@ -231,7 +231,7 @@ void eth_set_trace(eth_t *self, uint32_t value) {
|
||||
self->trace_flags = value;
|
||||
}
|
||||
|
||||
STATIC int eth_mac_init(eth_t *self) {
|
||||
static int eth_mac_init(eth_t *self) {
|
||||
// Configure MPU
|
||||
uint32_t irq_state = mpu_config_start();
|
||||
#if defined(STM32H5)
|
||||
@@ -540,7 +540,7 @@ STATIC int eth_mac_init(eth_t *self) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC void eth_mac_deinit(eth_t *self) {
|
||||
static void eth_mac_deinit(eth_t *self) {
|
||||
(void)self;
|
||||
HAL_NVIC_DisableIRQ(ETH_IRQn);
|
||||
#if defined(STM32H5)
|
||||
@@ -558,7 +558,7 @@ STATIC void eth_mac_deinit(eth_t *self) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC int eth_tx_buf_get(size_t len, uint8_t **buf) {
|
||||
static int eth_tx_buf_get(size_t len, uint8_t **buf) {
|
||||
if (len > TX_BUF_SIZE) {
|
||||
return -MP_EINVAL;
|
||||
}
|
||||
@@ -597,7 +597,7 @@ STATIC int eth_tx_buf_get(size_t len, uint8_t **buf) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int eth_tx_buf_send(void) {
|
||||
static int eth_tx_buf_send(void) {
|
||||
// Get TX descriptor and move to next one
|
||||
eth_dma_tx_descr_t *tx_descr = ð_dma.tx_descr[eth_dma.tx_descr_idx];
|
||||
eth_dma.tx_descr_idx = (eth_dma.tx_descr_idx + 1) % TX_BUF_NUM;
|
||||
@@ -637,7 +637,7 @@ STATIC int eth_tx_buf_send(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC void eth_dma_rx_free(void) {
|
||||
static void eth_dma_rx_free(void) {
|
||||
// Get RX descriptor, RX buffer and move to next one
|
||||
eth_dma_rx_descr_t *rx_descr = ð_dma.rx_descr[eth_dma.rx_descr_idx];
|
||||
uint8_t *buf = ð_dma.rx_buf[eth_dma.rx_descr_idx * RX_BUF_SIZE];
|
||||
@@ -727,7 +727,7 @@ void ETH_IRQHandler(void) {
|
||||
#define TRACE_ETH_RX (0x0004)
|
||||
#define TRACE_ETH_FULL (0x0008)
|
||||
|
||||
STATIC void eth_trace(eth_t *self, size_t len, const void *data, unsigned int flags) {
|
||||
static void eth_trace(eth_t *self, size_t len, const void *data, unsigned int flags) {
|
||||
if (((flags & NETUTILS_TRACE_IS_TX) && (self->trace_flags & TRACE_ETH_TX))
|
||||
|| (!(flags & NETUTILS_TRACE_IS_TX) && (self->trace_flags & TRACE_ETH_RX))) {
|
||||
const uint8_t *buf;
|
||||
@@ -747,7 +747,7 @@ STATIC void eth_trace(eth_t *self, size_t len, const void *data, unsigned int fl
|
||||
}
|
||||
}
|
||||
|
||||
STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) {
|
||||
static err_t eth_netif_output(struct netif *netif, struct pbuf *p) {
|
||||
// This function should always be called from a context where PendSV-level IRQs are disabled
|
||||
|
||||
LINK_STATS_INC(link.xmit);
|
||||
@@ -763,7 +763,7 @@ STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) {
|
||||
return ret ? ERR_BUF : ERR_OK;
|
||||
}
|
||||
|
||||
STATIC err_t eth_netif_init(struct netif *netif) {
|
||||
static err_t eth_netif_init(struct netif *netif) {
|
||||
netif->linkoutput = eth_netif_output;
|
||||
netif->output = etharp_output;
|
||||
netif->mtu = 1500;
|
||||
@@ -778,7 +778,7 @@ STATIC err_t eth_netif_init(struct netif *netif) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
STATIC void eth_lwip_init(eth_t *self) {
|
||||
static void eth_lwip_init(eth_t *self) {
|
||||
ip_addr_t ipconfig[4];
|
||||
IP4_ADDR(&ipconfig[0], 0, 0, 0, 0);
|
||||
IP4_ADDR(&ipconfig[2], 192, 168, 0, 1);
|
||||
@@ -804,7 +804,7 @@ STATIC void eth_lwip_init(eth_t *self) {
|
||||
MICROPY_PY_LWIP_EXIT
|
||||
}
|
||||
|
||||
STATIC void eth_lwip_deinit(eth_t *self) {
|
||||
static void eth_lwip_deinit(eth_t *self) {
|
||||
MICROPY_PY_LWIP_ENTER
|
||||
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (netif == &self->netif) {
|
||||
@@ -816,7 +816,7 @@ STATIC void eth_lwip_deinit(eth_t *self) {
|
||||
MICROPY_PY_LWIP_EXIT
|
||||
}
|
||||
|
||||
STATIC void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf) {
|
||||
static void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf) {
|
||||
eth_trace(self, len, buf, NETUTILS_TRACE_NEWLINE);
|
||||
|
||||
struct netif *netif = &self->netif;
|
||||
|
||||
@@ -123,11 +123,11 @@ typedef struct {
|
||||
mp_int_t line;
|
||||
} extint_obj_t;
|
||||
|
||||
STATIC uint8_t pyb_extint_mode[EXTI_NUM_VECTORS];
|
||||
STATIC bool pyb_extint_hard_irq[EXTI_NUM_VECTORS];
|
||||
static uint8_t pyb_extint_mode[EXTI_NUM_VECTORS];
|
||||
static bool pyb_extint_hard_irq[EXTI_NUM_VECTORS];
|
||||
|
||||
// The callback arg is a small-int or a ROM Pin object, so no need to scan by GC
|
||||
STATIC mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS];
|
||||
static mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS];
|
||||
|
||||
#if !defined(ETH)
|
||||
#define ETH_WKUP_IRQn 62 // Some MCUs don't have ETH, but we want a value to put in our table
|
||||
@@ -143,7 +143,7 @@ STATIC mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS];
|
||||
#define TAMP_STAMP_IRQn RTC_TAMP_LSECSS_IRQn
|
||||
#endif
|
||||
|
||||
STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
|
||||
static const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
|
||||
#if defined(STM32F0) || defined(STM32L0) || defined(STM32G0)
|
||||
|
||||
EXTI0_1_IRQn, EXTI0_1_IRQn, EXTI2_3_IRQn, EXTI2_3_IRQn,
|
||||
@@ -531,44 +531,44 @@ void extint_trigger_mode(uint line, uint32_t mode) {
|
||||
|
||||
/// \method line()
|
||||
/// Return the line number that the pin is mapped to.
|
||||
STATIC mp_obj_t extint_obj_line(mp_obj_t self_in) {
|
||||
static mp_obj_t extint_obj_line(mp_obj_t 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);
|
||||
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) {
|
||||
static mp_obj_t extint_obj_enable(mp_obj_t self_in) {
|
||||
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
extint_enable(self->line);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable);
|
||||
|
||||
/// \method disable()
|
||||
/// 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) {
|
||||
static mp_obj_t extint_obj_disable(mp_obj_t self_in) {
|
||||
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
extint_disable(self->line);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable);
|
||||
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) {
|
||||
static mp_obj_t extint_obj_swint(mp_obj_t self_in) {
|
||||
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
extint_swint(self->line);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint);
|
||||
|
||||
// TODO document as a staticmethod
|
||||
/// \classmethod regs()
|
||||
/// Dump the values of the EXTI registers.
|
||||
STATIC mp_obj_t extint_regs(void) {
|
||||
static mp_obj_t extint_regs(void) {
|
||||
const mp_print_t *print = &mp_plat_print;
|
||||
|
||||
#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL)
|
||||
@@ -621,8 +621,8 @@ 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_ROM_PTR(&extint_regs_fun_obj));
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs);
|
||||
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:
|
||||
@@ -639,7 +639,7 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs
|
||||
/// - `callback` is the function to call when the interrupt triggers. The
|
||||
/// callback function must accept exactly 1 argument, which is the line that
|
||||
/// triggered the interrupt.
|
||||
STATIC const mp_arg_t pyb_extint_make_new_args[] = {
|
||||
static const mp_arg_t pyb_extint_make_new_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_pull, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
@@ -647,7 +647,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = {
|
||||
};
|
||||
#define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args)
|
||||
|
||||
STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// type_in == extint_obj_type
|
||||
|
||||
// parse args
|
||||
@@ -660,12 +660,12 @@ STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||
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) {
|
||||
static void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<ExtInt line=%u>", self->line);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t extint_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&extint_obj_line_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&extint_obj_enable_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&extint_obj_disable_obj) },
|
||||
@@ -684,7 +684,7 @@ STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_EVT_RISING_FALLING), MP_ROM_INT(GPIO_MODE_EVT_RISING_FALLING) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
extint_type,
|
||||
|
||||
@@ -340,7 +340,7 @@ int can_receive(FDCAN_HandleTypeDef *can, int fifo, FDCAN_RxHeaderTypeDef *hdr,
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
STATIC void can_rx_irq_handler(uint can_id, uint fifo_id) {
|
||||
static void can_rx_irq_handler(uint can_id, uint fifo_id) {
|
||||
mp_obj_t callback;
|
||||
pyb_can_obj_t *self;
|
||||
mp_obj_t irq_reason = MP_OBJ_NEW_SMALL_INT(0);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#if defined(STM32F4) || defined(STM32L1)
|
||||
|
||||
STATIC uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C];
|
||||
static uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C];
|
||||
|
||||
int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t freq, uint16_t timeout_ms) {
|
||||
uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
|
||||
@@ -93,7 +93,7 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int i2c_wait_sr1_set(i2c_t *i2c, uint32_t mask) {
|
||||
static int i2c_wait_sr1_set(i2c_t *i2c, uint32_t mask) {
|
||||
uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
|
||||
uint32_t t0 = HAL_GetTick();
|
||||
while (!(i2c->SR1 & mask)) {
|
||||
@@ -105,7 +105,7 @@ STATIC int i2c_wait_sr1_set(i2c_t *i2c, uint32_t mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int i2c_wait_stop(i2c_t *i2c) {
|
||||
static int i2c_wait_stop(i2c_t *i2c) {
|
||||
uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE);
|
||||
uint32_t t0 = HAL_GetTick();
|
||||
while (i2c->CR1 & I2C_CR1_STOP) {
|
||||
@@ -284,7 +284,7 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
STATIC uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C];
|
||||
static uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C];
|
||||
|
||||
static uint32_t i2c_get_id(i2c_t *i2c) {
|
||||
#if defined(STM32H7)
|
||||
@@ -362,7 +362,7 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) {
|
||||
static int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) {
|
||||
uint32_t i2c_id = i2c_get_id(i2c);
|
||||
|
||||
uint32_t t0 = HAL_GetTick();
|
||||
@@ -375,7 +375,7 @@ STATIC int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int i2c_wait_isr_set(i2c_t *i2c, uint32_t mask) {
|
||||
static int i2c_wait_isr_set(i2c_t *i2c, uint32_t mask) {
|
||||
uint32_t i2c_id = i2c_get_id(i2c);
|
||||
|
||||
uint32_t t0 = HAL_GetTick();
|
||||
@@ -423,7 +423,7 @@ int i2c_start_addr(i2c_t *i2c, int rd_wrn, uint16_t addr, size_t len, bool stop)
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int i2c_check_stop(i2c_t *i2c) {
|
||||
static int i2c_check_stop(i2c_t *i2c) {
|
||||
if (i2c->CR2 & I2C_CR2_AUTOEND) {
|
||||
// Wait for the STOP condition and then disable the peripheral
|
||||
int ret;
|
||||
@@ -539,7 +539,7 @@ int i2c_writeto(i2c_t *i2c, uint16_t addr, const uint8_t *src, size_t len, bool
|
||||
|
||||
#endif
|
||||
|
||||
STATIC const uint8_t i2c_available =
|
||||
static const uint8_t i2c_available =
|
||||
0
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
| 1 << 1
|
||||
|
||||
@@ -36,7 +36,7 @@ uint32_t irq_stats[IRQ_STATS_MAX] = {0};
|
||||
// disable_irq()
|
||||
// Disable interrupt requests.
|
||||
// Returns the previous IRQ state which can be passed to enable_irq.
|
||||
STATIC mp_obj_t machine_disable_irq(void) {
|
||||
static mp_obj_t machine_disable_irq(void) {
|
||||
return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);
|
||||
@@ -44,7 +44,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);
|
||||
// enable_irq(state=True)
|
||||
// Enable interrupt requests, based on the argument, which is usually the
|
||||
// value returned by a previous call to disable_irq.
|
||||
STATIC mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) {
|
||||
static mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) {
|
||||
enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED);
|
||||
return mp_const_none;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj, 0, 1, machine_enable
|
||||
|
||||
#if IRQ_ENABLE_STATS
|
||||
// return a memoryview of the irq statistics array
|
||||
STATIC mp_obj_t pyb_irq_stats(void) {
|
||||
static mp_obj_t pyb_irq_stats(void) {
|
||||
return mp_obj_new_memoryview(0x80 | 'I', MP_ARRAY_SIZE(irq_stats), &irq_stats[0]);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(pyb_irq_stats_obj, pyb_irq_stats);
|
||||
|
||||
@@ -105,11 +105,11 @@ typedef struct _pyb_lcd_obj_t {
|
||||
byte pix_buf2[LCD_PIX_BUF_BYTE_SIZE];
|
||||
} pyb_lcd_obj_t;
|
||||
|
||||
STATIC void lcd_delay(void) {
|
||||
static void lcd_delay(void) {
|
||||
__asm volatile ("nop\nnop");
|
||||
}
|
||||
|
||||
STATIC void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) {
|
||||
static void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) {
|
||||
lcd_delay();
|
||||
mp_hal_pin_low(lcd->pin_cs1); // CS=0; enable
|
||||
if (instr_data == LCD_INSTR) {
|
||||
@@ -125,7 +125,7 @@ STATIC void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) {
|
||||
|
||||
// write a string to the LCD at the current cursor location
|
||||
// output it straight away (doesn't use the pixel buffer)
|
||||
STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len) {
|
||||
static void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len) {
|
||||
int redraw_min = lcd->line * LCD_CHAR_BUF_W + lcd->column;
|
||||
int redraw_max = redraw_min;
|
||||
for (; len > 0; len--, str++) {
|
||||
@@ -192,7 +192,7 @@ STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len
|
||||
///
|
||||
/// Construct an LCD object in the given skin position. `skin_position` can be 'X' or 'Y', and
|
||||
/// should match the position where the LCD pyskin is plugged in.
|
||||
STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@@ -323,7 +323,7 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
/// Send an arbitrary command to the LCD. Pass 0 for `instr_data` to send an
|
||||
/// 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) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// get whether instr or data
|
||||
@@ -341,12 +341,12 @@ STATIC mp_obj_t pyb_lcd_command(mp_obj_t self_in, mp_obj_t instr_data_in, mp_obj
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_command_obj, pyb_lcd_command);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_command_obj, pyb_lcd_command);
|
||||
|
||||
/// \method contrast(value)
|
||||
///
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_lcd_contrast(mp_obj_t self_in, mp_obj_t contrast_in) {
|
||||
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
int contrast = mp_obj_get_int(contrast_in);
|
||||
if (contrast < 0) {
|
||||
@@ -358,12 +358,12 @@ STATIC mp_obj_t pyb_lcd_contrast(mp_obj_t self_in, mp_obj_t contrast_in) {
|
||||
lcd_out(self, LCD_INSTR, contrast); // electronic volume register set
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_contrast_obj, pyb_lcd_contrast);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_contrast_obj, pyb_lcd_contrast);
|
||||
|
||||
/// \method light(value)
|
||||
///
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) {
|
||||
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
|
||||
@@ -372,26 +372,26 @@ STATIC mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_light_obj, pyb_lcd_light);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_light_obj, pyb_lcd_light);
|
||||
|
||||
/// \method write(str)
|
||||
///
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_lcd_write(mp_obj_t self_in, mp_obj_t str) {
|
||||
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);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_write_obj, pyb_lcd_write);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_write_obj, pyb_lcd_write);
|
||||
|
||||
/// \method fill(colour)
|
||||
///
|
||||
/// Fill the screen with the given colour (0 or 1 for white or black).
|
||||
///
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_lcd_fill(mp_obj_t self_in, mp_obj_t col_in) {
|
||||
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
int col = mp_obj_get_int(col_in);
|
||||
if (col) {
|
||||
@@ -401,14 +401,14 @@ STATIC mp_obj_t pyb_lcd_fill(mp_obj_t self_in, mp_obj_t col_in) {
|
||||
memset(self->pix_buf2, col, LCD_PIX_BUF_BYTE_SIZE);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_fill_obj, pyb_lcd_fill);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_fill_obj, pyb_lcd_fill);
|
||||
|
||||
/// \method get(x, y)
|
||||
///
|
||||
/// Get the pixel at the position `(x, y)`. Returns 0 or 1.
|
||||
///
|
||||
/// 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) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
int x = mp_obj_get_int(x_in);
|
||||
int y = mp_obj_get_int(y_in);
|
||||
@@ -420,14 +420,14 @@ STATIC mp_obj_t pyb_lcd_get(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
|
||||
}
|
||||
return mp_obj_new_int(0);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_get_obj, pyb_lcd_get);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_get_obj, pyb_lcd_get);
|
||||
|
||||
/// \method pixel(x, y, colour)
|
||||
///
|
||||
/// Set the pixel at `(x, y)` to the given colour (0 or 1).
|
||||
///
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) {
|
||||
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]);
|
||||
@@ -441,14 +441,14 @@ STATIC mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_pixel_obj, 4, 4, pyb_lcd_pixel);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_pixel_obj, 4, 4, pyb_lcd_pixel);
|
||||
|
||||
/// \method text(str, x, y, colour)
|
||||
///
|
||||
/// Draw the given text to the position `(x, y)` using the given colour (0 or 1).
|
||||
///
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) {
|
||||
// extract arguments
|
||||
pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
size_t len;
|
||||
@@ -490,12 +490,12 @@ STATIC mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_text_obj, 5, 5, pyb_lcd_text);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_text_obj, 5, 5, pyb_lcd_text);
|
||||
|
||||
/// \method show()
|
||||
///
|
||||
/// Show the hidden buffer on the screen.
|
||||
STATIC mp_obj_t pyb_lcd_show(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_lcd_show(mp_obj_t 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++) {
|
||||
@@ -508,9 +508,9 @@ STATIC mp_obj_t pyb_lcd_show(mp_obj_t self_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_lcd_show_obj, pyb_lcd_show);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_lcd_show_obj, pyb_lcd_show);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_command), MP_ROM_PTR(&pyb_lcd_command_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_contrast), MP_ROM_PTR(&pyb_lcd_contrast_obj) },
|
||||
@@ -523,7 +523,7 @@ STATIC const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&pyb_lcd_show_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_lcd_locals_dict, pyb_lcd_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_lcd_locals_dict, pyb_lcd_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_lcd_type,
|
||||
|
||||
@@ -50,7 +50,7 @@ typedef struct _pyb_led_obj_t {
|
||||
const machine_pin_obj_t *led_pin;
|
||||
} pyb_led_obj_t;
|
||||
|
||||
STATIC const pyb_led_obj_t pyb_led_obj[] = {
|
||||
static const pyb_led_obj_t pyb_led_obj[] = {
|
||||
{{&pyb_led_type}, 1, MICROPY_HW_LED1},
|
||||
#if defined(MICROPY_HW_LED2)
|
||||
{{&pyb_led_type}, 2, MICROPY_HW_LED2},
|
||||
@@ -125,7 +125,7 @@ typedef struct _led_pwm_config_t {
|
||||
uint8_t alt_func;
|
||||
} led_pwm_config_t;
|
||||
|
||||
STATIC const led_pwm_config_t led_pwm_config[] = {
|
||||
static const led_pwm_config_t led_pwm_config[] = {
|
||||
MICROPY_HW_LED1_PWM,
|
||||
MICROPY_HW_LED2_PWM,
|
||||
MICROPY_HW_LED3_PWM,
|
||||
@@ -134,15 +134,15 @@ STATIC const led_pwm_config_t led_pwm_config[] = {
|
||||
MICROPY_HW_LED6_PWM,
|
||||
};
|
||||
|
||||
STATIC uint8_t led_pwm_state = 0;
|
||||
static uint8_t led_pwm_state = 0;
|
||||
|
||||
static inline bool led_pwm_is_enabled(int led) {
|
||||
return (led_pwm_state & (1 << led)) != 0;
|
||||
}
|
||||
|
||||
// this function has a large stack so it should not be inlined
|
||||
STATIC void led_pwm_init(int led) __attribute__((noinline));
|
||||
STATIC void led_pwm_init(int led) {
|
||||
static void led_pwm_init(int led) __attribute__((noinline));
|
||||
static void led_pwm_init(int led) {
|
||||
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
|
||||
const led_pwm_config_t *pwm_cfg = &led_pwm_config[led - 1];
|
||||
|
||||
@@ -190,7 +190,7 @@ STATIC void led_pwm_init(int led) {
|
||||
led_pwm_state |= 1 << led;
|
||||
}
|
||||
|
||||
STATIC void led_pwm_deinit(int led) {
|
||||
static void led_pwm_deinit(int led) {
|
||||
// make the LED's pin a standard GPIO output pin
|
||||
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
|
||||
GPIO_TypeDef *g = led_pin->gpio;
|
||||
@@ -312,7 +312,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
|
||||
/// Create an LED object associated with the given LED:
|
||||
///
|
||||
/// - `id` is the LED number, 1-4.
|
||||
STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@@ -366,19 +366,19 @@ mp_obj_t led_obj_intensity(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_intensity_obj, 1, 2, led_obj_intensity);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_intensity_obj, 1, 2, led_obj_intensity);
|
||||
|
||||
STATIC const mp_rom_map_elem_t led_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t led_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_intensity), MP_ROM_PTR(&led_obj_intensity_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_led_type,
|
||||
|
||||
@@ -112,7 +112,7 @@ typedef enum _machine_adc_internal_ch_t {
|
||||
|
||||
// Convert machine_adc_internal_ch_t value to STM32 library ADC channel literal.
|
||||
// This function is required as literals are uint32_t types that don't map with MP_ROM_INT (31 bit signed).
|
||||
STATIC uint32_t adc_ll_channel(uint32_t channel_id) {
|
||||
static uint32_t adc_ll_channel(uint32_t channel_id) {
|
||||
uint32_t adc_ll_ch;
|
||||
switch (channel_id) {
|
||||
// external channels map 1:1
|
||||
@@ -154,7 +154,7 @@ static inline void adc_stabilisation_delay_us(uint32_t us) {
|
||||
mp_hal_delay_us(us + 1);
|
||||
}
|
||||
|
||||
STATIC void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) {
|
||||
static void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) {
|
||||
uint32_t t0 = mp_hal_ticks_ms();
|
||||
#if ADC_V2
|
||||
while (!(adc->ISR & ADC_ISR_EOC))
|
||||
@@ -169,9 +169,9 @@ STATIC void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) {
|
||||
}
|
||||
|
||||
#if defined(STM32H7)
|
||||
STATIC const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8};
|
||||
static const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8};
|
||||
#else
|
||||
STATIC const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6};
|
||||
static const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6};
|
||||
#endif
|
||||
|
||||
void adc_config(ADC_TypeDef *adc, uint32_t bits) {
|
||||
@@ -313,7 +313,7 @@ void adc_config(ADC_TypeDef *adc, uint32_t bits) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC int adc_get_bits(ADC_TypeDef *adc) {
|
||||
static int adc_get_bits(ADC_TypeDef *adc) {
|
||||
#if defined(STM32F0) || defined(STM32G0) || defined(STM32L0) || defined(STM32WL)
|
||||
uint32_t res = (adc->CFGR1 & ADC_CFGR1_RES) >> ADC_CFGR1_RES_Pos;
|
||||
#elif defined(STM32F4) || defined(STM32F7) || defined(STM32L1)
|
||||
@@ -324,7 +324,7 @@ STATIC int adc_get_bits(ADC_TypeDef *adc) {
|
||||
return adc_cr_to_bits_table[res];
|
||||
}
|
||||
|
||||
STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
|
||||
static void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
|
||||
#if ADC_V2
|
||||
if (!(adc->CR & ADC_CR_ADEN)) {
|
||||
if (adc->CR & 0x3f) {
|
||||
@@ -443,7 +443,7 @@ STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t samp
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC uint32_t adc_read_channel(ADC_TypeDef *adc) {
|
||||
static uint32_t adc_read_channel(ADC_TypeDef *adc) {
|
||||
uint32_t value;
|
||||
#if defined(STM32G4)
|
||||
// For STM32G4 there is errata 2.7.7, "Wrong ADC result if conversion done late after
|
||||
@@ -520,7 +520,7 @@ typedef struct _machine_adc_obj_t {
|
||||
uint32_t sample_time;
|
||||
} machine_adc_obj_t;
|
||||
|
||||
STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
unsigned adc_id = 1;
|
||||
#if defined(ADC2)
|
||||
@@ -537,7 +537,7 @@ STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
||||
}
|
||||
|
||||
// ADC(id)
|
||||
STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// Check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@@ -607,7 +607,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
}
|
||||
|
||||
// read_u16()
|
||||
STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) {
|
||||
static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) {
|
||||
return adc_config_and_read_u16(self->adc, self->channel, self->sample_time);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ typedef struct _machine_hard_i2c_obj_t {
|
||||
mp_hal_pin_obj_t sda;
|
||||
} machine_hard_i2c_obj_t;
|
||||
|
||||
STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = {
|
||||
static const machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = {
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
[0] = {{&machine_i2c_type}, I2C1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA},
|
||||
#endif
|
||||
@@ -58,7 +58,7 @@ STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_hard_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
#if defined(STM32F4) || defined(STM32L1)
|
||||
@@ -134,7 +134,7 @@ int machine_hard_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t n, m
|
||||
|
||||
typedef mp_machine_soft_i2c_obj_t machine_hard_i2c_obj_t;
|
||||
|
||||
STATIC machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = {
|
||||
static machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = {
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
[0] = {{&machine_i2c_type}, 1, I2C_POLL_DEFAULT_TIMEOUT_US, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA},
|
||||
#endif
|
||||
@@ -149,14 +149,14 @@ STATIC machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_hard_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "I2C(%u, scl=%q, sda=%q, freq=%u, timeout=%u)",
|
||||
self - &machine_hard_i2c_obj[0] + 1,
|
||||
self->scl->name, self->sda->name, 500000 / self->us_delay, self->us_timeout);
|
||||
}
|
||||
|
||||
STATIC void machine_hard_i2c_init(machine_hard_i2c_obj_t *self, uint32_t freq, uint32_t timeout) {
|
||||
static void machine_hard_i2c_init(machine_hard_i2c_obj_t *self, uint32_t freq, uint32_t timeout) {
|
||||
// set parameters
|
||||
if (freq >= 1000000) {
|
||||
// allow fastest possible bit-bang rate
|
||||
@@ -228,7 +228,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = {
|
||||
static const mp_machine_i2c_p_t machine_hard_i2c_p = {
|
||||
.transfer = machine_hard_i2c_transfer,
|
||||
};
|
||||
|
||||
|
||||
@@ -94,19 +94,19 @@ typedef struct _machine_i2s_obj_t {
|
||||
const dma_descr_t *dma_descr_rx;
|
||||
} machine_i2s_obj_t;
|
||||
|
||||
STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in);
|
||||
static mp_obj_t machine_i2s_deinit(mp_obj_t self_in);
|
||||
|
||||
// The frame map is used with the readinto() method to transform the audio sample data coming
|
||||
// from DMA memory (32-bit stereo) to the format specified
|
||||
// in the I2S constructor. e.g. 16-bit mono
|
||||
STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = {
|
||||
static const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = {
|
||||
{ 0, 1, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits
|
||||
{ 2, 3, 0, 1, -1, -1, -1, -1 }, // Mono, 32-bits
|
||||
{ 0, 1, -1, -1, 2, 3, -1, -1 }, // Stereo, 16-bits
|
||||
{ 2, 3, 0, 1, 6, 7, 4, 5 }, // Stereo, 32-bits
|
||||
};
|
||||
|
||||
STATIC const plli2s_config_t plli2s_config[] = PLLI2S_TABLE;
|
||||
static const plli2s_config_t plli2s_config[] = PLLI2S_TABLE;
|
||||
|
||||
void machine_i2s_init0() {
|
||||
for (uint8_t i = 0; i < MICROPY_HW_MAX_I2S; i++) {
|
||||
@@ -114,7 +114,7 @@ void machine_i2s_init0() {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC bool lookup_plli2s_config(int8_t bits, int32_t rate, uint16_t *plli2sn, uint16_t *plli2sr) {
|
||||
static bool lookup_plli2s_config(int8_t bits, int32_t rate, uint16_t *plli2sn, uint16_t *plli2sr) {
|
||||
for (uint16_t i = 0; i < MP_ARRAY_SIZE(plli2s_config); i++) {
|
||||
if ((plli2s_config[i].bits == bits) && (plli2s_config[i].rate == rate)) {
|
||||
*plli2sn = plli2s_config[i].plli2sn;
|
||||
@@ -148,7 +148,7 @@ STATIC bool lookup_plli2s_config(int8_t bits, int32_t rate, uint16_t *plli2sn, u
|
||||
// where:
|
||||
// LEFT Channel = 0x99, 0xBB, 0x11, 0x22
|
||||
// RIGHT Channel = 0x44, 0x55, 0xAB, 0x77
|
||||
STATIC void reformat_32_bit_samples(int32_t *sample, uint32_t num_samples) {
|
||||
static void reformat_32_bit_samples(int32_t *sample, uint32_t num_samples) {
|
||||
int16_t sample_ms;
|
||||
int16_t sample_ls;
|
||||
for (uint32_t i = 0; i < num_samples; i++) {
|
||||
@@ -158,7 +158,7 @@ STATIC void reformat_32_bit_samples(int32_t *sample, uint32_t num_samples) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) {
|
||||
static int8_t get_frame_mapping_index(int8_t bits, format_t format) {
|
||||
if (format == MONO) {
|
||||
if (bits == 16) {
|
||||
return 0;
|
||||
@@ -174,7 +174,7 @@ STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int8_t get_dma_bits(uint16_t mode, int8_t bits) {
|
||||
static int8_t get_dma_bits(uint16_t mode, int8_t bits) {
|
||||
if (mode == I2S_MODE_MASTER_TX) {
|
||||
if (bits == 16) {
|
||||
return I2S_DATAFORMAT_16B;
|
||||
@@ -189,7 +189,7 @@ STATIC int8_t get_dma_bits(uint16_t mode, int8_t bits) {
|
||||
}
|
||||
|
||||
// function is used in IRQ context
|
||||
STATIC void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
|
||||
static void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
|
||||
uint16_t dma_buffer_offset = 0;
|
||||
|
||||
if (dma_ping_pong == TOP_HALF) {
|
||||
@@ -212,7 +212,7 @@ STATIC void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
|
||||
}
|
||||
|
||||
// function is used in IRQ context
|
||||
STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
|
||||
static void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
|
||||
uint16_t dma_buffer_offset = 0;
|
||||
|
||||
if (dma_ping_pong == TOP_HALF) {
|
||||
@@ -262,7 +262,7 @@ STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
|
||||
MP_HAL_CLEAN_DCACHE(dma_buffer_p, SIZEOF_HALF_DMA_BUFFER_IN_BYTES);
|
||||
}
|
||||
|
||||
STATIC bool i2s_init(machine_i2s_obj_t *self) {
|
||||
static bool i2s_init(machine_i2s_obj_t *self) {
|
||||
|
||||
// init the GPIO lines
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
@@ -439,7 +439,7 @@ void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) {
|
||||
feed_dma(self, TOP_HALF);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) {
|
||||
static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) {
|
||||
memset(&self->hi2s, 0, sizeof(self->hi2s));
|
||||
|
||||
// are I2S pin assignments valid?
|
||||
@@ -558,7 +558,7 @@ STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar
|
||||
}
|
||||
}
|
||||
|
||||
STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) {
|
||||
static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) {
|
||||
uint8_t i2s_id_zero_base = 0;
|
||||
|
||||
if (0) {
|
||||
@@ -590,7 +590,7 @@ STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) {
|
||||
return self;
|
||||
}
|
||||
|
||||
STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
static void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
if (self->ring_buffer_storage != NULL) {
|
||||
dma_deinit(self->dma_descr_tx);
|
||||
dma_deinit(self->dma_descr_rx);
|
||||
@@ -611,7 +611,7 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) {
|
||||
static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) {
|
||||
(void)self;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
/******************************************************************************/
|
||||
// Implementation of hard SPI for machine module
|
||||
|
||||
STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
|
||||
static const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
|
||||
{{&machine_spi_type}, &spi_obj[0]},
|
||||
{{&machine_spi_type}, &spi_obj[1]},
|
||||
{{&machine_spi_type}, &spi_obj[2]},
|
||||
@@ -42,7 +42,7 @@ STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
|
||||
{{&machine_spi_type}, &spi_obj[5]},
|
||||
};
|
||||
|
||||
STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
spi_print(print, self->spi, false);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in;
|
||||
|
||||
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit };
|
||||
@@ -127,17 +127,17 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const m
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) {
|
||||
static void machine_hard_spi_deinit(mp_obj_base_t *self_in) {
|
||||
machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in;
|
||||
spi_deinit(self->spi);
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
static void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in;
|
||||
spi_transfer(self->spi, len, src, dest, SPI_TRANSFER_TIMEOUT(len));
|
||||
}
|
||||
|
||||
STATIC const mp_machine_spi_p_t machine_hard_spi_p = {
|
||||
static const mp_machine_spi_p_t machine_hard_spi_p = {
|
||||
.init = machine_hard_spi_init,
|
||||
.deinit = machine_hard_spi_deinit,
|
||||
.transfer = machine_hard_spi_transfer,
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
{ MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_IRQ_RXIDLE), MP_ROM_INT(UART_FLAG_IDLE) }, \
|
||||
|
||||
STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (!self->is_enabled) {
|
||||
#if defined(LPUART1)
|
||||
@@ -140,7 +140,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_
|
||||
/// - `timeout_char` is the timeout in milliseconds to wait between characters.
|
||||
/// - `flow` is RTS | CTS where RTS == 256, CTS == 512
|
||||
/// - `read_buf_len` is the character length of the read buffer (0 to disable).
|
||||
STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static void mp_machine_uart_init_helper(machine_uart_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_baudrate, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 9600} },
|
||||
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
|
||||
@@ -278,7 +278,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
|
||||
/// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)`
|
||||
/// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)`
|
||||
/// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)`
|
||||
STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -381,23 +381,23 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
}
|
||||
|
||||
// Turn off the UART bus.
|
||||
STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) {
|
||||
static void mp_machine_uart_deinit(machine_uart_obj_t *self) {
|
||||
uart_deinit(self);
|
||||
}
|
||||
|
||||
// Return number of characters waiting.
|
||||
STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) {
|
||||
static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) {
|
||||
return uart_rx_any(self);
|
||||
}
|
||||
|
||||
// Since uart.write() waits up to the last byte, uart.txdone() always returns True.
|
||||
STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
|
||||
static bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
|
||||
(void)self;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send a break condition.
|
||||
STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
|
||||
static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
|
||||
#if defined(STM32F0) || defined(STM32F7) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL)
|
||||
self->uartx->RQR = USART_RQR_SBKRQ; // write-only register
|
||||
#else
|
||||
@@ -407,7 +407,7 @@ STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
|
||||
|
||||
// Write a single character on the bus. `data` is an integer to write.
|
||||
// The `data` can be up to 9 bits.
|
||||
STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) {
|
||||
static void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) {
|
||||
// write the character
|
||||
int errcode;
|
||||
if (uart_tx_wait(self, self->timeout)) {
|
||||
@@ -423,7 +423,7 @@ STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) {
|
||||
|
||||
// Receive a single character on the bus.
|
||||
// Return value: The character read, as an integer. Returns -1 on timeout.
|
||||
STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) {
|
||||
static mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) {
|
||||
if (uart_rx_wait(self, self->timeout)) {
|
||||
return uart_rx_char(self);
|
||||
} else {
|
||||
@@ -432,7 +432,7 @@ STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args) {
|
||||
static mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args) {
|
||||
if (self->mp_irq_obj == NULL) {
|
||||
self->mp_irq_trigger = 0;
|
||||
self->mp_irq_obj = mp_irq_new(&uart_irq_methods, MP_OBJ_FROM_PTR(self));
|
||||
@@ -463,7 +463,7 @@ STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args
|
||||
return self->mp_irq_obj;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
byte *buf = buf_in;
|
||||
|
||||
@@ -505,7 +505,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
const byte *buf = buf_in;
|
||||
|
||||
@@ -532,7 +532,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_uint_t ret;
|
||||
if (request == MP_STREAM_POLL) {
|
||||
|
||||
@@ -37,9 +37,9 @@ typedef struct _machine_wdt_obj_t {
|
||||
mp_obj_base_t base;
|
||||
} machine_wdt_obj_t;
|
||||
|
||||
STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}};
|
||||
static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}};
|
||||
|
||||
STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) {
|
||||
static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) {
|
||||
if (id != 0) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("WDT(%d) doesn't exist"), id);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t
|
||||
return (machine_wdt_obj_t *)&machine_wdt;
|
||||
}
|
||||
|
||||
STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) {
|
||||
static void mp_machine_wdt_feed(machine_wdt_obj_t *self) {
|
||||
(void)self;
|
||||
IWDG->KR = 0xaaaa;
|
||||
}
|
||||
|
||||
@@ -90,15 +90,15 @@
|
||||
#include "subghz.h"
|
||||
|
||||
#if MICROPY_PY_THREAD
|
||||
STATIC pyb_thread_t pyb_thread_main;
|
||||
static pyb_thread_t pyb_thread_main;
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_UART_REPL)
|
||||
#ifndef MICROPY_HW_UART_REPL_RXBUF
|
||||
#define MICROPY_HW_UART_REPL_RXBUF (260)
|
||||
#endif
|
||||
STATIC machine_uart_obj_t pyb_uart_repl_obj;
|
||||
STATIC uint8_t pyb_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF];
|
||||
static machine_uart_obj_t pyb_uart_repl_obj;
|
||||
static uint8_t pyb_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF];
|
||||
#endif
|
||||
|
||||
void nlr_jump_fail(void *val) {
|
||||
@@ -119,7 +119,7 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_opt, MP_ARG_INT, {.u_int = 0} }
|
||||
};
|
||||
@@ -140,7 +140,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main);
|
||||
|
||||
#if MICROPY_HW_FLASH_MOUNT_AT_BOOT
|
||||
// avoid inlining to avoid stack usage within main()
|
||||
MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
|
||||
MP_NOINLINE static bool init_flash_fs(uint reset_mode) {
|
||||
if (reset_mode == BOARDCTRL_RESET_MODE_FACTORY_FILESYSTEM) {
|
||||
// Asked by user to reset filesystem
|
||||
factory_reset_create_filesystem();
|
||||
@@ -215,7 +215,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_SDCARD_MOUNT_AT_BOOT
|
||||
STATIC bool init_sdcard_fs(void) {
|
||||
static bool init_sdcard_fs(void) {
|
||||
bool first_part = true;
|
||||
for (int part_num = 1; part_num <= 5; ++part_num) {
|
||||
// create vfs object
|
||||
|
||||
@@ -213,7 +213,7 @@ def print_regs_as_submodules(reg_name, reg_defs, modules):
|
||||
|
||||
print(
|
||||
"""
|
||||
STATIC const mp_rom_map_elem_t stm_%s_globals_table[] = {
|
||||
static const mp_rom_map_elem_t stm_%s_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_%s) },
|
||||
"""
|
||||
% (mod_name_lower, mod_name_upper)
|
||||
@@ -228,7 +228,7 @@ STATIC const mp_rom_map_elem_t stm_%s_globals_table[] = {
|
||||
print(
|
||||
"""};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(stm_%s_globals, stm_%s_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(stm_%s_globals, stm_%s_globals_table);
|
||||
|
||||
const mp_obj_module_t stm_%s_obj = {
|
||||
.base = { &mp_type_module },
|
||||
@@ -310,7 +310,7 @@ def main():
|
||||
for mpz in sorted(needed_mpzs):
|
||||
assert 0 <= mpz <= 0xFFFFFFFF
|
||||
print(
|
||||
"STATIC const mp_obj_int_t mpz_%08x = {{&mp_type_int}, "
|
||||
"static const mp_obj_int_t mpz_%08x = {{&mp_type_int}, "
|
||||
"{.neg=0, .fixed_dig=1, .alloc=2, .len=2, "
|
||||
".dig=(uint16_t*)(const uint16_t[]){%#x, %#x}}};"
|
||||
% (mpz, mpz & 0xFFFF, (mpz >> 16) & 0xFFFF),
|
||||
|
||||
@@ -1051,7 +1051,7 @@ typedef struct _pyb_usbdd_obj_t {
|
||||
#define MSFT100_VENDOR_CODE (0x42)
|
||||
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
STATIC const uint8_t usbd_fifo_size[USBD_PMA_NUM_FIFO] = {
|
||||
static const uint8_t usbd_fifo_size[USBD_PMA_NUM_FIFO] = {
|
||||
32, 32, // EP0(out), EP0(in)
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 14x unused
|
||||
};
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
{ MP_ROM_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_ROM_INT(PYB_RESET_DEEPSLEEP) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(PYB_RESET_SOFT) }, \
|
||||
|
||||
STATIC uint32_t reset_cause;
|
||||
static uint32_t reset_cause;
|
||||
|
||||
void machine_init(void) {
|
||||
#if defined(STM32F4)
|
||||
@@ -186,7 +186,7 @@ void machine_deinit(void) {
|
||||
|
||||
// machine.info([dump_alloc_table])
|
||||
// Print out lots of information about the board.
|
||||
STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
|
||||
const mp_print_t *print = &mp_plat_print;
|
||||
|
||||
// get and print unique id; 96 bits
|
||||
@@ -277,13 +277,13 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
|
||||
// Returns a string of 12 bytes (96 bits), which is the unique ID for the MCU.
|
||||
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||
static mp_obj_t mp_machine_unique_id(void) {
|
||||
byte *id = (byte *)MP_HAL_UNIQUE_ID_ADDRESS;
|
||||
return mp_obj_new_bytes(id, 12);
|
||||
}
|
||||
|
||||
// Resets the pyboard in a manner similar to pushing the external RESET button.
|
||||
NORETURN STATIC void mp_machine_reset(void) {
|
||||
NORETURN static void mp_machine_reset(void) {
|
||||
powerctrl_mcu_reset();
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
// get or set the MCU frequencies
|
||||
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
static mp_obj_t mp_machine_get_freq(void) {
|
||||
mp_obj_t tuple[] = {
|
||||
mp_obj_new_int(HAL_RCC_GetSysClockFreq()),
|
||||
mp_obj_new_int(HAL_RCC_GetHCLKFreq()),
|
||||
@@ -326,7 +326,7 @@ STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
return mp_obj_new_tuple(MP_ARRAY_SIZE(tuple), tuple);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
#if defined(STM32F0) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32G0)
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet"));
|
||||
#else
|
||||
@@ -365,11 +365,11 @@ STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
// idle()
|
||||
// This executies a wfi machine instruction which reduces power consumption
|
||||
// of the MCU until an interrupt occurs, at which point execution continues.
|
||||
STATIC void mp_machine_idle(void) {
|
||||
static void mp_machine_idle(void) {
|
||||
__WFI();
|
||||
}
|
||||
|
||||
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args != 0) {
|
||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||
pyb_rtc_wakeup(2, args2);
|
||||
@@ -377,7 +377,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
powerctrl_enter_stop_mode();
|
||||
}
|
||||
|
||||
STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args != 0) {
|
||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||
pyb_rtc_wakeup(2, args2);
|
||||
@@ -385,6 +385,6 @@ STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
powerctrl_enter_standby_mode();
|
||||
}
|
||||
|
||||
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||
static mp_int_t mp_machine_reset_cause(void) {
|
||||
return reset_cause;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
// urandom(n)
|
||||
// Return a bytes object with n random bytes, generated by the hardware
|
||||
// random number generator.
|
||||
STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
static mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
mp_int_t n = mp_obj_get_int(num);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, n);
|
||||
@@ -43,7 +43,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
}
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
|
||||
#endif
|
||||
|
||||
bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) {
|
||||
|
||||
@@ -59,37 +59,37 @@
|
||||
|
||||
#if MICROPY_PY_PYB
|
||||
|
||||
STATIC mp_obj_t pyb_fault_debug(mp_obj_t value) {
|
||||
static mp_obj_t pyb_fault_debug(mp_obj_t value) {
|
||||
pyb_hard_fault_debug = mp_obj_is_true(value);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_fault_debug_obj, pyb_fault_debug);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_fault_debug_obj, pyb_fault_debug);
|
||||
|
||||
STATIC mp_obj_t pyb_idle(void) {
|
||||
static mp_obj_t pyb_idle(void) {
|
||||
__WFI();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_idle_obj, pyb_idle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(pyb_idle_obj, pyb_idle);
|
||||
|
||||
#if MICROPY_PY_PYB_LEGACY
|
||||
|
||||
// Returns the number of milliseconds which have elapsed since `start`.
|
||||
// This function takes care of counter wrap and always returns a positive number.
|
||||
STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
|
||||
static mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
|
||||
uint32_t startMillis = mp_obj_get_int(start);
|
||||
uint32_t currMillis = mp_hal_ticks_ms();
|
||||
return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x3fffffff);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
|
||||
|
||||
// Returns the number of microseconds which have elapsed since `start`.
|
||||
// This function takes care of counter wrap and always returns a positive number.
|
||||
STATIC mp_obj_t pyb_elapsed_micros(mp_obj_t start) {
|
||||
static mp_obj_t pyb_elapsed_micros(mp_obj_t start) {
|
||||
uint32_t startMicros = mp_obj_get_int(start);
|
||||
uint32_t currMicros = mp_hal_ticks_us();
|
||||
return MP_OBJ_NEW_SMALL_INT((currMicros - startMicros) & 0x3fffffff);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -97,7 +97,7 @@ MP_DECLARE_CONST_FUN_OBJ_KW(pyb_main_obj); // defined in main.c
|
||||
|
||||
// Get or set the UART object that the REPL is repeated on.
|
||||
// This is a legacy function, use of os.dupterm is preferred.
|
||||
STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
if (MP_STATE_PORT(pyb_stdio_uart) == NULL) {
|
||||
return mp_const_none;
|
||||
@@ -119,22 +119,22 @@ STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart);
|
||||
|
||||
#if MICROPY_PY_NETWORK
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj);
|
||||
#else
|
||||
// Provide a no-op version of pyb.country for backwards compatibility on
|
||||
// boards that don't support networking.
|
||||
STATIC mp_obj_t pyb_country(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_country(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
(void)args;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, pyb_country);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, pyb_country);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_fault_debug), MP_ROM_PTR(&pyb_fault_debug_obj) },
|
||||
@@ -262,7 +262,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
|
||||
|
||||
const mp_obj_module_t pyb_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
#include "genhdr/modstm_mpz.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t stm_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t stm_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_stm) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) },
|
||||
@@ -62,7 +62,7 @@ STATIC const mp_rom_map_elem_t stm_module_globals_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table);
|
||||
|
||||
const mp_obj_module_t stm_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "rtc.h"
|
||||
|
||||
// Return the localtime as an 8-tuple.
|
||||
STATIC mp_obj_t mp_time_localtime_get(void) {
|
||||
static mp_obj_t mp_time_localtime_get(void) {
|
||||
// get current date and time
|
||||
// note: need to call get time then get date to correctly access the registers
|
||||
rtc_init_finalise();
|
||||
@@ -51,7 +51,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) {
|
||||
}
|
||||
|
||||
// Returns the number of seconds, as an integer, since 1/1/2000.
|
||||
STATIC mp_obj_t mp_time_time_get(void) {
|
||||
static mp_obj_t mp_time_time_get(void) {
|
||||
// get date and time
|
||||
// note: need to call get time then get date to correctly access the registers
|
||||
rtc_init_finalise();
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
|
||||
|
||||
// Soft timer for scheduling a HCI poll.
|
||||
STATIC soft_timer_entry_t mp_bluetooth_hci_soft_timer;
|
||||
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
|
||||
|
||||
// This is called by soft_timer and executes at IRQ_PRI_PENDSV.
|
||||
STATIC void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
|
||||
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
|
||||
mp_bluetooth_hci_poll_now();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void mp_bluetooth_hci_init(void) {
|
||||
);
|
||||
}
|
||||
|
||||
STATIC void mp_bluetooth_hci_start_polling(void) {
|
||||
static void mp_bluetooth_hci_start_polling(void) {
|
||||
mp_bluetooth_hci_poll_now();
|
||||
}
|
||||
|
||||
@@ -67,12 +67,12 @@ void mp_bluetooth_hci_poll_in_ms_default(uint32_t ms) {
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS
|
||||
|
||||
STATIC mp_sched_node_t mp_bluetooth_hci_sched_node;
|
||||
static mp_sched_node_t mp_bluetooth_hci_sched_node;
|
||||
|
||||
// For synchronous mode, we run all BLE stack code inside a scheduled task.
|
||||
// This task is scheduled periodically via a soft timer, or
|
||||
// immediately on HCI UART RXIDLE.
|
||||
STATIC void run_events_scheduled_task(mp_sched_node_t *node) {
|
||||
static void run_events_scheduled_task(mp_sched_node_t *node) {
|
||||
// This will process all buffered HCI UART data, and run any callouts or events.
|
||||
(void)node;
|
||||
mp_bluetooth_hci_poll();
|
||||
@@ -133,7 +133,7 @@ int mp_bluetooth_hci_uart_write(const uint8_t *buf, size_t len) {
|
||||
}
|
||||
|
||||
// Callback to forward data from rfcore to the bluetooth hci handler.
|
||||
STATIC void mp_bluetooth_hci_uart_msg_cb(void *env, const uint8_t *buf, size_t len) {
|
||||
static void mp_bluetooth_hci_uart_msg_cb(void *env, const uint8_t *buf, size_t len) {
|
||||
mp_bluetooth_hci_uart_readchar_t handler = (mp_bluetooth_hci_uart_readchar_t)env;
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
handler(buf[i]);
|
||||
|
||||
@@ -106,7 +106,7 @@ static const btstack_run_loop_t mp_btstack_runloop_stm32 = {
|
||||
&mp_btstack_runloop_get_time_ms,
|
||||
};
|
||||
|
||||
STATIC const hci_transport_config_uart_t hci_transport_config_uart = {
|
||||
static const hci_transport_config_uart_t hci_transport_config_uart = {
|
||||
HCI_TRANSPORT_CONFIG_UART,
|
||||
MICROPY_HW_BLE_UART_BAUDRATE,
|
||||
MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY,
|
||||
|
||||
@@ -64,7 +64,7 @@ u32_t sys_now(void) {
|
||||
return mp_hal_ticks_ms();
|
||||
}
|
||||
|
||||
STATIC void pyb_lwip_poll(void) {
|
||||
static void pyb_lwip_poll(void) {
|
||||
#if MICROPY_PY_NETWORK_WIZNET5K
|
||||
// Poll the NIC for incoming data
|
||||
wiznet5k_poll();
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#if MICROPY_PY_THREAD
|
||||
|
||||
// the mutex controls access to the linked list
|
||||
STATIC mp_thread_mutex_t thread_mutex;
|
||||
static mp_thread_mutex_t thread_mutex;
|
||||
|
||||
void mp_thread_init(void) {
|
||||
mp_thread_mutex_init(&thread_mutex);
|
||||
|
||||
@@ -38,9 +38,9 @@ typedef struct _network_lan_obj_t {
|
||||
eth_t *eth;
|
||||
} network_lan_obj_t;
|
||||
|
||||
STATIC const network_lan_obj_t network_lan_eth0 = { { &network_lan_type }, ð_instance };
|
||||
static const network_lan_obj_t network_lan_eth0 = { { &network_lan_type }, ð_instance };
|
||||
|
||||
STATIC void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
struct netif *netif = eth_netif(self->eth);
|
||||
int status = eth_link_status(self->eth);
|
||||
@@ -53,14 +53,14 @@ STATIC void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
||||
);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
const network_lan_obj_t *self = &network_lan_eth0;
|
||||
eth_init(self->eth, MP_HAL_MAC_ETH0);
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) {
|
||||
network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_bool(eth_link_status(self->eth));
|
||||
@@ -77,21 +77,21 @@ STATIC mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_active_obj, 1, 2, network_lan_active);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_active_obj, 1, 2, network_lan_active);
|
||||
|
||||
STATIC mp_obj_t network_lan_isconnected(mp_obj_t self_in) {
|
||||
static mp_obj_t network_lan_isconnected(mp_obj_t self_in) {
|
||||
network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return mp_obj_new_bool(eth_link_status(self->eth) == 3);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_lan_isconnected_obj, network_lan_isconnected);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(network_lan_isconnected_obj, network_lan_isconnected);
|
||||
|
||||
STATIC mp_obj_t network_lan_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t network_lan_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
return mod_network_nic_ifconfig(eth_netif(self->eth), n_args - 1, args + 1);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_ifconfig_obj, 1, 2, network_lan_ifconfig);
|
||||
|
||||
STATIC mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) {
|
||||
network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
(void)self;
|
||||
|
||||
@@ -102,9 +102,9 @@ STATIC mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("unknown status param"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_status_obj, 1, 2, network_lan_status);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_status_obj, 1, 2, network_lan_status);
|
||||
|
||||
STATIC mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
static mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
|
||||
if (kwargs->used == 0) {
|
||||
@@ -147,16 +147,16 @@ STATIC mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_lan_config_obj, 1, network_lan_config);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(network_lan_config_obj, 1, network_lan_config);
|
||||
|
||||
STATIC const mp_rom_map_elem_t network_lan_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t network_lan_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_lan_active_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_lan_isconnected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_lan_ifconfig_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_lan_status_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_lan_config_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
network_lan_type,
|
||||
|
||||
@@ -92,7 +92,7 @@ void octospi_init(void) {
|
||||
OCTOSPI1->CR |= OCTOSPI_CR_EN;
|
||||
}
|
||||
|
||||
STATIC int octospi_ioctl(void *self_in, uint32_t cmd) {
|
||||
static int octospi_ioctl(void *self_in, uint32_t cmd) {
|
||||
(void)self_in;
|
||||
switch (cmd) {
|
||||
case MP_QSPI_IOCTL_INIT:
|
||||
@@ -112,7 +112,7 @@ STATIC int octospi_ioctl(void *self_in, uint32_t cmd) {
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
STATIC int octospi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
||||
static int octospi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
||||
(void)self_in;
|
||||
|
||||
OCTOSPI1->FCR = OCTOSPI_FCR_CTCF; // clear TC flag
|
||||
@@ -166,7 +166,7 @@ STATIC int octospi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int octospi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
||||
static int octospi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
||||
(void)self_in;
|
||||
|
||||
uint8_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2;
|
||||
@@ -231,7 +231,7 @@ STATIC int octospi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) {
|
||||
static int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) {
|
||||
(void)self_in;
|
||||
|
||||
OCTOSPI1->FCR = OCTOSPI_FCR_CTCF; // clear TC flag
|
||||
@@ -269,7 +269,7 @@ STATIC int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *de
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int octospi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
||||
static int octospi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
||||
(void)self_in;
|
||||
|
||||
#if defined(MICROPY_HW_OSPIFLASH_IO1) && !defined(MICROPY_HW_OSPIFLASH_IO2) && !defined(MICROPY_HW_OSPIFLASH_IO4)
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
/// how a particular object gets mapped to a pin.
|
||||
|
||||
// Pin class variables
|
||||
STATIC bool pin_class_debug;
|
||||
static bool pin_class_debug;
|
||||
|
||||
void pin_init0(void) {
|
||||
MP_STATE_PORT(pin_class_mapper) = mp_const_none;
|
||||
@@ -179,7 +179,7 @@ const machine_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) {
|
||||
static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// pin name
|
||||
@@ -238,7 +238,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
|
||||
static mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
|
||||
|
||||
/// \classmethod \constructor(id, ...)
|
||||
/// Create a new Pin object associated with the id. If additional arguments are given,
|
||||
@@ -263,7 +263,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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);
|
||||
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (n_args == 0) {
|
||||
@@ -278,31 +278,31 @@ STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_
|
||||
|
||||
/// \classmethod mapper([fun])
|
||||
/// Get or set the pin mapper function.
|
||||
STATIC mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
MP_STATE_PORT(pin_class_mapper) = args[1];
|
||||
return mp_const_none;
|
||||
}
|
||||
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_ROM_PTR(&pin_mapper_fun_obj));
|
||||
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_ROM_PTR(&pin_mapper_fun_obj));
|
||||
|
||||
/// \classmethod dict([dict])
|
||||
/// Get or set the pin mapper dictionary.
|
||||
STATIC mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
MP_STATE_PORT(pin_class_map_dict) = args[1];
|
||||
return mp_const_none;
|
||||
}
|
||||
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_ROM_PTR(&pin_map_dict_fun_obj));
|
||||
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_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) {
|
||||
static mp_obj_t pin_af_list(mp_obj_t self_in) {
|
||||
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_t result = mp_obj_new_list(0, NULL);
|
||||
|
||||
@@ -312,22 +312,22 @@ STATIC mp_obj_t pin_af_list(mp_obj_t self_in) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
|
||||
|
||||
/// \classmethod debug([state])
|
||||
/// Get or set the debugging state (`True` or `False` for on or off).
|
||||
STATIC mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
pin_class_debug = mp_obj_is_true(args[1]);
|
||||
return mp_const_none;
|
||||
}
|
||||
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_ROM_PTR(&pin_debug_fun_obj));
|
||||
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_ROM_PTR(&pin_debug_fun_obj));
|
||||
|
||||
// init(mode, pull=None, alt=-1, *, value, alt)
|
||||
STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_obj_init_helper(const machine_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_rom_obj = MP_ROM_NONE}},
|
||||
@@ -384,7 +384,7 @@ STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
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(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);
|
||||
@@ -396,27 +396,27 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
|
||||
/// - With `value` given, set the logic level of the pin. `value` can be
|
||||
/// anything that converts to a boolean. If it converts to `True`, the pin
|
||||
/// is set high, otherwise it is set low.
|
||||
STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
|
||||
return pin_call(args[0], n_args - 1, 0, args + 1);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
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) {
|
||||
static mp_obj_t pin_off(mp_obj_t self_in) {
|
||||
machine_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_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);
|
||||
|
||||
STATIC mp_obj_t pin_on(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_on(mp_obj_t self_in) {
|
||||
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_hal_pin_high(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);
|
||||
|
||||
// pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False)
|
||||
STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
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_rom_obj = MP_ROM_NONE} },
|
||||
@@ -436,19 +436,19 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
// TODO should return an IRQ object
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
|
||||
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) {
|
||||
static mp_obj_t pin_name(mp_obj_t self_in) {
|
||||
machine_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);
|
||||
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) {
|
||||
static mp_obj_t pin_names(mp_obj_t self_in) {
|
||||
machine_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));
|
||||
@@ -463,60 +463,60 @@ STATIC mp_obj_t pin_names(mp_obj_t self_in) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
|
||||
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) {
|
||||
static mp_obj_t pin_port(mp_obj_t self_in) {
|
||||
machine_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);
|
||||
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) {
|
||||
static mp_obj_t pin_pin(mp_obj_t self_in) {
|
||||
machine_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);
|
||||
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) {
|
||||
static mp_obj_t pin_gpio(mp_obj_t self_in) {
|
||||
machine_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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_gpio_obj, pin_gpio);
|
||||
|
||||
/// \method mode()
|
||||
/// Returns the currently configured mode of the pin. The integer returned
|
||||
/// 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) {
|
||||
static mp_obj_t pin_mode(mp_obj_t 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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode);
|
||||
|
||||
/// \method pull()
|
||||
/// Returns the currently configured pull of the pin. The integer returned
|
||||
/// 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) {
|
||||
static mp_obj_t pin_pull(mp_obj_t 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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull);
|
||||
|
||||
/// \method af()
|
||||
/// Returns the currently configured alternate-function of the pin. The
|
||||
/// 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) {
|
||||
static mp_obj_t pin_af(mp_obj_t 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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
|
||||
@@ -568,9 +568,9 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
#include "genhdr/pins_af_const.h"
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
|
||||
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) {
|
||||
static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
(void)errcode;
|
||||
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
@@ -586,7 +586,7 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i
|
||||
return -1;
|
||||
}
|
||||
|
||||
STATIC const mp_pin_p_t pin_pin_p = {
|
||||
static const mp_pin_p_t pin_pin_p = {
|
||||
.ioctl = pin_ioctl,
|
||||
};
|
||||
|
||||
@@ -630,43 +630,43 @@ MP_DEFINE_CONST_OBJ_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) {
|
||||
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 = 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) {
|
||||
static mp_obj_t pin_af_index(mp_obj_t 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);
|
||||
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) {
|
||||
static mp_obj_t pin_af_name(mp_obj_t 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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name);
|
||||
|
||||
/// \method reg()
|
||||
/// Return the base register associated with the peripheral assigned to this
|
||||
/// 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) {
|
||||
static mp_obj_t pin_af_reg(mp_obj_t self_in) {
|
||||
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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pin_af_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pin_af_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&pin_af_index_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_af_name_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pin_af_reg_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pin_af_type,
|
||||
|
||||
@@ -162,14 +162,14 @@ typedef struct _sysclk_scaling_table_entry_t {
|
||||
} sysclk_scaling_table_entry_t;
|
||||
|
||||
#if defined(STM32F7)
|
||||
STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
static const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
{ 151, PWR_REGULATOR_VOLTAGE_SCALE3 },
|
||||
{ 180, PWR_REGULATOR_VOLTAGE_SCALE2 },
|
||||
// Above 180MHz uses default PWR_REGULATOR_VOLTAGE_SCALE1
|
||||
};
|
||||
#elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || \
|
||||
defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
|
||||
STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
static const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
// See table 15 "FLASH recommended number of wait states and programming delay" of RM0455.
|
||||
{88, PWR_REGULATOR_VOLTAGE_SCALE3},
|
||||
{160, PWR_REGULATOR_VOLTAGE_SCALE2},
|
||||
@@ -177,7 +177,7 @@ STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
{280, PWR_REGULATOR_VOLTAGE_SCALE0},
|
||||
};
|
||||
#elif defined(STM32H7)
|
||||
STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
static const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
// See table 55 "Kernel clock distribution overview" of RM0433.
|
||||
{200, PWR_REGULATOR_VOLTAGE_SCALE3},
|
||||
{300, PWR_REGULATOR_VOLTAGE_SCALE2},
|
||||
@@ -186,7 +186,7 @@ STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
STATIC int powerctrl_config_vos(uint32_t sysclk_mhz) {
|
||||
static int powerctrl_config_vos(uint32_t sysclk_mhz) {
|
||||
#if defined(STM32F7) || defined(STM32H7)
|
||||
uint32_t volt_scale = PWR_REGULATOR_VOLTAGE_SCALE1;
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(volt_scale_table); ++i) {
|
||||
@@ -291,7 +291,7 @@ int powerctrl_rcc_clock_config_pll(RCC_ClkInitTypeDef *rcc_init, uint32_t sysclk
|
||||
|
||||
#if !defined(STM32F0) && !defined(STM32G0) && !defined(STM32L0) && !defined(STM32L1) && !defined(STM32L4)
|
||||
|
||||
STATIC uint32_t calc_ahb_div(uint32_t wanted_div) {
|
||||
static uint32_t calc_ahb_div(uint32_t wanted_div) {
|
||||
#if defined(STM32H7)
|
||||
if (wanted_div <= 1) {
|
||||
return RCC_HCLK_DIV1;
|
||||
@@ -335,7 +335,7 @@ STATIC uint32_t calc_ahb_div(uint32_t wanted_div) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC uint32_t calc_apb1_div(uint32_t wanted_div) {
|
||||
static uint32_t calc_apb1_div(uint32_t wanted_div) {
|
||||
#if defined(STM32H7)
|
||||
if (wanted_div <= 1) {
|
||||
return RCC_APB1_DIV1;
|
||||
@@ -363,7 +363,7 @@ STATIC uint32_t calc_apb1_div(uint32_t wanted_div) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC uint32_t calc_apb2_div(uint32_t wanted_div) {
|
||||
static uint32_t calc_apb2_div(uint32_t wanted_div) {
|
||||
#if defined(STM32H7)
|
||||
if (wanted_div <= 1) {
|
||||
return RCC_APB2_DIV1;
|
||||
|
||||
@@ -123,11 +123,11 @@ extern const uint8_t DLCtoBytes[16];
|
||||
#define CAN_FLAG_FIFO0_OVRF CAN_FLAG_FOV0
|
||||
#define CAN_FLAG_FIFO1_OVRF CAN_FLAG_FOV1
|
||||
|
||||
STATIC uint8_t can2_start_bank = 14;
|
||||
static uint8_t can2_start_bank = 14;
|
||||
|
||||
#endif
|
||||
|
||||
STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
if (!self->is_enabled) {
|
||||
mp_printf(print, "CAN(%u)", self->can_id);
|
||||
@@ -160,7 +160,7 @@ STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
}
|
||||
}
|
||||
|
||||
STATIC uint32_t pyb_can_get_source_freq() {
|
||||
static uint32_t pyb_can_get_source_freq() {
|
||||
uint32_t can_kern_clk = 0;
|
||||
|
||||
// Find CAN kernel clock
|
||||
@@ -192,7 +192,7 @@ STATIC uint32_t pyb_can_get_source_freq() {
|
||||
return can_kern_clk;
|
||||
}
|
||||
|
||||
STATIC void pyb_can_get_bit_timing(mp_uint_t baudrate, mp_uint_t sample_point,
|
||||
static void pyb_can_get_bit_timing(mp_uint_t baudrate, mp_uint_t sample_point,
|
||||
uint32_t max_brp, uint32_t max_bs1, uint32_t max_bs2, uint32_t min_tseg,
|
||||
mp_int_t *bs1_out, mp_int_t *bs2_out, mp_int_t *prescaler_out) {
|
||||
uint32_t can_kern_clk = pyb_can_get_source_freq();
|
||||
@@ -215,7 +215,7 @@ STATIC void pyb_can_get_bit_timing(mp_uint_t baudrate, mp_uint_t sample_point,
|
||||
}
|
||||
|
||||
// init(mode, prescaler=100, *, sjw=1, bs1=6, bs2=8)
|
||||
STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_mode, ARG_prescaler, ARG_sjw, ARG_bs1, ARG_bs2, ARG_auto_restart, ARG_baudrate, ARG_sample_point,
|
||||
ARG_num_filter_banks, ARG_brs_prescaler, ARG_brs_sjw, ARG_brs_bs1, ARG_brs_bs2, ARG_brs_baudrate, ARG_brs_sample_point };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -285,7 +285,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp
|
||||
}
|
||||
|
||||
// CAN(bus, ...)
|
||||
STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -354,21 +354,21 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
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) {
|
||||
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(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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_init_obj, 1, pyb_can_init);
|
||||
|
||||
// deinit()
|
||||
STATIC mp_obj_t pyb_can_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_can_deinit(mp_obj_t self_in) {
|
||||
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
can_deinit(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_deinit_obj, pyb_can_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_deinit_obj, pyb_can_deinit);
|
||||
|
||||
// Force a software restart of the controller, to allow transmission after a bus error
|
||||
STATIC mp_obj_t pyb_can_restart(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_can_restart(mp_obj_t self_in) {
|
||||
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (!self->is_enabled) {
|
||||
mp_raise_ValueError(NULL);
|
||||
@@ -394,10 +394,10 @@ STATIC mp_obj_t pyb_can_restart(mp_obj_t self_in) {
|
||||
#endif
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_restart_obj, pyb_can_restart);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_restart_obj, pyb_can_restart);
|
||||
|
||||
// Get the state of the controller
|
||||
STATIC mp_obj_t pyb_can_state(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_can_state(mp_obj_t self_in) {
|
||||
pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t state = CAN_STATE_STOPPED;
|
||||
if (self->is_enabled) {
|
||||
@@ -427,10 +427,10 @@ STATIC mp_obj_t pyb_can_state(mp_obj_t self_in) {
|
||||
}
|
||||
return MP_OBJ_NEW_SMALL_INT(state);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_state_obj, pyb_can_state);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_state_obj, pyb_can_state);
|
||||
|
||||
// Get info about error states and TX/RX buffers
|
||||
STATIC mp_obj_t pyb_can_info(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_can_info(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_can_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_obj_list_t *list;
|
||||
if (n_args == 1) {
|
||||
@@ -473,10 +473,10 @@ STATIC mp_obj_t pyb_can_info(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return MP_OBJ_FROM_PTR(list);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_can_info_obj, 1, 2, pyb_can_info);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_can_info_obj, 1, 2, pyb_can_info);
|
||||
|
||||
// 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) {
|
||||
static mp_obj_t pyb_can_any(mp_obj_t self_in, mp_obj_t fifo_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) {
|
||||
@@ -490,10 +490,10 @@ STATIC mp_obj_t pyb_can_any(mp_obj_t self_in, mp_obj_t fifo_in) {
|
||||
}
|
||||
return mp_const_false;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_any_obj, pyb_can_any);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_any_obj, pyb_can_any);
|
||||
|
||||
// send(send, addr, *, timeout=5000)
|
||||
STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_data, ARG_id, ARG_timeout, ARG_rtr, ARG_extframe, ARG_fdf, ARG_brs };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
@@ -611,10 +611,10 @@ STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_send_obj, 1, pyb_can_send);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_send_obj, 1, pyb_can_send);
|
||||
|
||||
// recv(fifo, list=None, *, timeout=5000)
|
||||
STATIC mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
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} },
|
||||
@@ -730,9 +730,9 @@ STATIC mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
// Return the result
|
||||
return ret_obj;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_recv_obj, 1, pyb_can_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_recv_obj, 1, pyb_can_recv);
|
||||
|
||||
STATIC mp_obj_t pyb_can_clearfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_can_clearfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_extframe };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_extframe, MP_ARG_BOOL, {.u_bool = false} },
|
||||
@@ -754,11 +754,11 @@ STATIC mp_obj_t pyb_can_clearfilter(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||
#endif
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_clearfilter_obj, 2, pyb_can_clearfilter);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_clearfilter_obj, 2, pyb_can_clearfilter);
|
||||
|
||||
// setfilter(bank, mode, fifo, params, *, rtr)
|
||||
#define EXTENDED_ID_TO_16BIT_FILTER(id) (((id & 0xC00000) >> 13) | ((id & 0x38000) >> 15)) | 8
|
||||
STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_bank, ARG_mode, ARG_fifo, ARG_params, ARG_rtr, ARG_extframe };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_bank, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
@@ -930,9 +930,9 @@ STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("CAN filter parameter error"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_setfilter_obj, 1, pyb_can_setfilter);
|
||||
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) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t fifo = mp_obj_get_int(fifo_in);
|
||||
mp_obj_t *callback;
|
||||
@@ -971,9 +971,9 @@ STATIC mp_obj_t pyb_can_rxcallback(mp_obj_t self_in, mp_obj_t fifo_in, mp_obj_t
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_can_rxcallback_obj, pyb_can_rxcallback);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_can_rxcallback_obj, pyb_can_rxcallback);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_can_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_can_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_can_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_can_deinit_obj) },
|
||||
@@ -1018,9 +1018,9 @@ STATIC const mp_rom_map_elem_t pyb_can_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_ERROR_PASSIVE), MP_ROM_INT(CAN_STATE_ERROR_PASSIVE) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUS_OFF), MP_ROM_INT(CAN_STATE_BUS_OFF) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table);
|
||||
|
||||
STATIC mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
static 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) {
|
||||
@@ -1065,7 +1065,7 @@ void pyb_can_handle_callback(pyb_can_obj_t *self, uint fifo_id, mp_obj_t callbac
|
||||
}
|
||||
}
|
||||
|
||||
STATIC const mp_stream_p_t can_stream_p = {
|
||||
static const mp_stream_p_t can_stream_p = {
|
||||
// .read = can_read, // is read sensible for CAN?
|
||||
// .write = can_write, // is write sensible for CAN?
|
||||
.ioctl = can_ioctl,
|
||||
|
||||
@@ -103,7 +103,7 @@ I2C_HandleTypeDef I2CHandle3 = {.Instance = NULL};
|
||||
I2C_HandleTypeDef I2CHandle4 = {.Instance = NULL};
|
||||
#endif
|
||||
|
||||
STATIC bool pyb_i2c_use_dma[4];
|
||||
static bool pyb_i2c_use_dma[4];
|
||||
|
||||
const pyb_i2c_obj_t pyb_i2c_obj[] = {
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
@@ -219,14 +219,14 @@ const pyb_i2c_obj_t pyb_i2c_obj[] = {
|
||||
#error "no I2C timings for this MCU"
|
||||
#endif
|
||||
|
||||
STATIC const struct {
|
||||
static const struct {
|
||||
uint32_t baudrate;
|
||||
uint32_t timing;
|
||||
} pyb_i2c_baudrate_timing[] = MICROPY_HW_I2C_BAUDRATE_TIMING;
|
||||
|
||||
#define NUM_BAUDRATE_TIMINGS MP_ARRAY_SIZE(pyb_i2c_baudrate_timing)
|
||||
|
||||
STATIC void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) {
|
||||
static void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) {
|
||||
for (int i = 0; i < NUM_BAUDRATE_TIMINGS; i++) {
|
||||
if (pyb_i2c_baudrate_timing[i].baudrate == baudrate) {
|
||||
init->Timing = pyb_i2c_baudrate_timing[i].timing;
|
||||
@@ -252,7 +252,7 @@ uint32_t pyb_i2c_get_baudrate(I2C_HandleTypeDef *i2c) {
|
||||
#define MICROPY_HW_I2C_BAUDRATE_DEFAULT (PYB_I2C_SPEED_FULL)
|
||||
#define MICROPY_HW_I2C_BAUDRATE_MAX (PYB_I2C_SPEED_FULL)
|
||||
|
||||
STATIC void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) {
|
||||
static void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) {
|
||||
init->ClockSpeed = baudrate;
|
||||
init->DutyCycle = I2C_DUTYCYCLE_16_9;
|
||||
}
|
||||
@@ -428,7 +428,7 @@ int pyb_i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq) {
|
||||
return pyb_i2c_init(self->i2c);
|
||||
}
|
||||
|
||||
STATIC void i2c_reset_after_error(I2C_HandleTypeDef *i2c) {
|
||||
static void i2c_reset_after_error(I2C_HandleTypeDef *i2c) {
|
||||
// wait for bus-busy flag to be cleared, with a timeout
|
||||
for (int timeout = 50; timeout > 0; --timeout) {
|
||||
if (!__HAL_I2C_GET_FLAG(i2c, I2C_FLAG_BUSY)) {
|
||||
@@ -581,7 +581,7 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) {
|
||||
static HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) {
|
||||
// Note: we can't use WFI to idle in this loop because the DMA completion
|
||||
// interrupt may occur before the WFI. Hence we miss it and have to wait
|
||||
// until the next sys-tick (up to 1ms).
|
||||
@@ -601,7 +601,7 @@ 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) {
|
||||
static void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
uint i2c_num = 0;
|
||||
@@ -655,7 +655,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
/// - `addr` is the 7-bit address (only sensible for a peripheral)
|
||||
/// - `baudrate` is the SCL clock rate (only sensible for a controller)
|
||||
/// - `gencall` is whether to support general call mode
|
||||
STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_init_helper(const pyb_i2c_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_INT, {.u_int = PYB_I2C_MASTER} },
|
||||
{ MP_QSTR_addr, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x12} },
|
||||
@@ -721,7 +721,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, co
|
||||
///
|
||||
/// - `I2C(1)` is on the X position: `(SCL, SDA) = (X9, X10) = (PB6, PB7)`
|
||||
/// - `I2C(2)` is on the Y position: `(SCL, SDA) = (Y9, Y10) = (PB10, PB11)`
|
||||
STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -739,23 +739,23 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
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) {
|
||||
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(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_);
|
||||
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) {
|
||||
static mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
|
||||
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
i2c_deinit(self->i2c);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);
|
||||
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 controller mode.
|
||||
STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
|
||||
static mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
|
||||
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (!in_master_mode(self)) {
|
||||
@@ -773,12 +773,12 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
|
||||
|
||||
return mp_const_false;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready);
|
||||
|
||||
/// \method scan()
|
||||
/// Scan all I2C addresses from 0x08 to 0x77 and return a list of those that respond.
|
||||
/// Only valid when in controller mode.
|
||||
STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
|
||||
pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (!in_master_mode(self)) {
|
||||
@@ -796,7 +796,7 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
|
||||
|
||||
return list;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
|
||||
|
||||
/// \method send(send, addr=0x00, timeout=5000)
|
||||
/// Send data on the bus:
|
||||
@@ -806,7 +806,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
|
||||
/// - `timeout` is the timeout in milliseconds to wait for the send
|
||||
///
|
||||
/// Return value: `None`.
|
||||
STATIC mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} },
|
||||
@@ -873,7 +873,7 @@ STATIC mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send);
|
||||
|
||||
/// \method recv(recv, addr=0x00, timeout=5000)
|
||||
///
|
||||
@@ -886,7 +886,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send);
|
||||
///
|
||||
/// Return value: if `recv` is an integer then a new buffer of the bytes received,
|
||||
/// otherwise the same buffer that was passed in to `recv`.
|
||||
STATIC mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} },
|
||||
@@ -954,7 +954,7 @@ STATIC mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv);
|
||||
|
||||
/// \method mem_read(data, addr, memaddr, timeout=5000, addr_size=8)
|
||||
///
|
||||
@@ -968,7 +968,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv);
|
||||
///
|
||||
/// Returns the read data.
|
||||
/// This is only valid in controller mode.
|
||||
STATIC const mp_arg_t pyb_i2c_mem_read_allowed_args[] = {
|
||||
static const mp_arg_t pyb_i2c_mem_read_allowed_args[] = {
|
||||
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
@@ -976,7 +976,7 @@ STATIC const mp_arg_t pyb_i2c_mem_read_allowed_args[] = {
|
||||
{ MP_QSTR_addr_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_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 = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)];
|
||||
@@ -1030,7 +1030,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read);
|
||||
|
||||
/// \method mem_write(data, addr, memaddr, timeout=5000, addr_size=8)
|
||||
///
|
||||
@@ -1044,7 +1044,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read);
|
||||
///
|
||||
/// Returns `None`.
|
||||
/// This is only valid in controller mode.
|
||||
STATIC mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
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 = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)];
|
||||
@@ -1094,9 +1094,9 @@ STATIC mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_write_obj, 1, pyb_i2c_mem_write);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_write_obj, 1, pyb_i2c_mem_write);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_i2c_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_i2c_deinit_obj) },
|
||||
@@ -1117,7 +1117,7 @@ STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_SLAVE), MP_ROM_INT(PYB_I2C_SLAVE) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_i2c_type,
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
// spi.send_recv(b'1234', buf) # send 4 bytes and receive 4 into buf
|
||||
// spi.send_recv(buf, buf) # send/recv 4 bytes from/to buf
|
||||
|
||||
STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
|
||||
static const pyb_spi_obj_t pyb_spi_obj[] = {
|
||||
{{&pyb_spi_type}, &spi_obj[0]},
|
||||
{{&pyb_spi_type}, &spi_obj[1]},
|
||||
{{&pyb_spi_type}, &spi_obj[2]},
|
||||
@@ -66,7 +66,7 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
|
||||
{{&pyb_spi_type}, &spi_obj[5]},
|
||||
};
|
||||
|
||||
STATIC void pyb_spi_print(const mp_print_t *print, 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 = MP_OBJ_TO_PTR(self_in);
|
||||
spi_print(print, self->spi, true);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
// Initialise the SPI bus with the given parameters:
|
||||
// - `mode` must be either `SPI.CONTROLLER` or `SPI.PERIPHERAL`.
|
||||
// - `baudrate` is the SCK clock rate (only sensible for a controller).
|
||||
STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_init_helper(const pyb_spi_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, {.u_int = 0} },
|
||||
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 328125} },
|
||||
@@ -136,7 +136,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, co
|
||||
//
|
||||
// At the moment, the NSS pin is not used by the SPI driver and is free
|
||||
// for other use.
|
||||
STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -156,19 +156,19 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
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) {
|
||||
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(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);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init);
|
||||
|
||||
// deinit()
|
||||
// Turn off the SPI bus.
|
||||
STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
|
||||
pyb_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
spi_deinit(self->spi);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
|
||||
|
||||
// send(send, *, timeout=5000)
|
||||
// Send data on the bus:
|
||||
@@ -176,7 +176,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
|
||||
// - `timeout` is the timeout in milliseconds to wait for the send.
|
||||
//
|
||||
// Return value: `None`.
|
||||
STATIC mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// TODO assumes transmission size is 8-bits wide
|
||||
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -199,7 +199,7 @@ STATIC mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send);
|
||||
|
||||
// recv(recv, *, timeout=5000)
|
||||
//
|
||||
@@ -210,7 +210,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send);
|
||||
//
|
||||
// Return value: if `recv` is an integer then a new buffer of the bytes received,
|
||||
// otherwise the same buffer that was passed in to `recv`.
|
||||
STATIC mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// TODO assumes transmission size is 8-bits wide
|
||||
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -237,7 +237,7 @@ STATIC mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv);
|
||||
|
||||
// send_recv(send, recv=None, *, timeout=5000)
|
||||
//
|
||||
@@ -249,7 +249,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv);
|
||||
// - `timeout` is the timeout in milliseconds to wait for the receive.
|
||||
//
|
||||
// Return value: the buffer with the received bytes.
|
||||
STATIC mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// TODO assumes transmission size is 8-bits wide
|
||||
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -306,9 +306,9 @@ STATIC mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
return mp_obj_new_bytes_from_vstr(&vstr_recv);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_recv_obj, 1, pyb_spi_send_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_recv_obj, 1, pyb_spi_send_recv);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_spi_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_spi_deinit_obj) },
|
||||
@@ -344,14 +344,14 @@ STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_NSS_HARD_OUTPUT ((uint32_t)0x00040000)
|
||||
*/
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table);
|
||||
|
||||
STATIC void spi_transfer_machine(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
static void spi_transfer_machine(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
pyb_spi_obj_t *self = (pyb_spi_obj_t *)self_in;
|
||||
spi_transfer(self->spi, len, src, dest, SPI_TRANSFER_TIMEOUT(len));
|
||||
}
|
||||
|
||||
STATIC const mp_machine_spi_p_t pyb_spi_p = {
|
||||
static const mp_machine_spi_p_t pyb_spi_p = {
|
||||
.transfer = spi_transfer_machine,
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ void pyb_thread_deinit() {
|
||||
enable_irq(irq_state);
|
||||
}
|
||||
|
||||
STATIC void pyb_thread_terminate(void) {
|
||||
static void pyb_thread_terminate(void) {
|
||||
uint32_t irq_state = disable_irq();
|
||||
pyb_thread_t *thread = pyb_thread_cur;
|
||||
// take current thread off the run list
|
||||
|
||||
@@ -172,7 +172,7 @@ void qspi_memory_map(void) {
|
||||
qspi_mpu_enable_mapped();
|
||||
}
|
||||
|
||||
STATIC int qspi_ioctl(void *self_in, uint32_t cmd) {
|
||||
static int qspi_ioctl(void *self_in, uint32_t cmd) {
|
||||
(void)self_in;
|
||||
switch (cmd) {
|
||||
case MP_QSPI_IOCTL_INIT:
|
||||
@@ -196,7 +196,7 @@ STATIC int qspi_ioctl(void *self_in, uint32_t cmd) {
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
STATIC int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
||||
static int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
||||
(void)self_in;
|
||||
|
||||
QUADSPI->FCR = QUADSPI_FCR_CTCF; // clear TC flag
|
||||
@@ -252,7 +252,7 @@ STATIC int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
||||
static int qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
||||
(void)self_in;
|
||||
|
||||
uint8_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2;
|
||||
@@ -316,7 +316,7 @@ STATIC int qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, s
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) {
|
||||
static int qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) {
|
||||
(void)self_in;
|
||||
|
||||
QUADSPI->FCR = QUADSPI_FCR_CTCF; // clear TC flag
|
||||
@@ -350,7 +350,7 @@ STATIC int qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest)
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
||||
static int qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
||||
(void)self_in;
|
||||
|
||||
uint8_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2;
|
||||
|
||||
@@ -195,33 +195,33 @@ typedef struct __attribute__((packed)) _ipcc_ref_table_t {
|
||||
// The stm32wb55xg.ld script puts .bss.ipcc_mem_* into SRAM2A and .bss_ipcc_membuf_* into SRAM2B.
|
||||
// It also leaves 64 bytes at the start of SRAM2A for the ref table.
|
||||
|
||||
STATIC ipcc_device_info_table_t ipcc_mem_dev_info_tab; // mem1
|
||||
STATIC ipcc_ble_table_t ipcc_mem_ble_tab; // mem1
|
||||
STATIC ipcc_sys_table_t ipcc_mem_sys_tab; // mem1
|
||||
STATIC ipcc_mem_manager_table_t ipcc_mem_memmgr_tab; // mem1
|
||||
static ipcc_device_info_table_t ipcc_mem_dev_info_tab; // mem1
|
||||
static ipcc_ble_table_t ipcc_mem_ble_tab; // mem1
|
||||
static ipcc_sys_table_t ipcc_mem_sys_tab; // mem1
|
||||
static ipcc_mem_manager_table_t ipcc_mem_memmgr_tab; // mem1
|
||||
|
||||
STATIC uint8_t ipcc_membuf_sys_cmd_buf[272]; // mem2
|
||||
STATIC tl_list_node_t ipcc_mem_sys_queue; // mem1
|
||||
static uint8_t ipcc_membuf_sys_cmd_buf[272]; // mem2
|
||||
static tl_list_node_t ipcc_mem_sys_queue; // mem1
|
||||
|
||||
STATIC tl_list_node_t ipcc_mem_memmgr_free_buf_queue; // mem1
|
||||
STATIC uint8_t ipcc_membuf_memmgr_ble_spare_evt_buf[272]; // mem2
|
||||
STATIC uint8_t ipcc_membuf_memmgr_sys_spare_evt_buf[272]; // mem2
|
||||
STATIC uint8_t ipcc_membuf_memmgr_evt_pool[6 * 272]; // mem2
|
||||
static tl_list_node_t ipcc_mem_memmgr_free_buf_queue; // mem1
|
||||
static uint8_t ipcc_membuf_memmgr_ble_spare_evt_buf[272]; // mem2
|
||||
static uint8_t ipcc_membuf_memmgr_sys_spare_evt_buf[272]; // mem2
|
||||
static uint8_t ipcc_membuf_memmgr_evt_pool[6 * 272]; // mem2
|
||||
|
||||
STATIC uint8_t ipcc_membuf_ble_cmd_buf[272]; // mem2
|
||||
STATIC uint8_t ipcc_membuf_ble_cs_buf[272]; // mem2
|
||||
STATIC tl_list_node_t ipcc_mem_ble_evt_queue; // mem1
|
||||
STATIC uint8_t ipcc_membuf_ble_hci_acl_data_buf[272]; // mem2
|
||||
static uint8_t ipcc_membuf_ble_cmd_buf[272]; // mem2
|
||||
static uint8_t ipcc_membuf_ble_cs_buf[272]; // mem2
|
||||
static tl_list_node_t ipcc_mem_ble_evt_queue; // mem1
|
||||
static uint8_t ipcc_membuf_ble_hci_acl_data_buf[272]; // mem2
|
||||
|
||||
/******************************************************************************/
|
||||
// Transport layer linked list
|
||||
|
||||
STATIC void tl_list_init(volatile tl_list_node_t *n) {
|
||||
static void tl_list_init(volatile tl_list_node_t *n) {
|
||||
n->next = n;
|
||||
n->prev = n;
|
||||
}
|
||||
|
||||
STATIC volatile tl_list_node_t *tl_list_unlink(volatile tl_list_node_t *n) {
|
||||
static volatile tl_list_node_t *tl_list_unlink(volatile tl_list_node_t *n) {
|
||||
volatile tl_list_node_t *next = n->next;
|
||||
volatile tl_list_node_t *prev = n->prev;
|
||||
prev->next = next;
|
||||
@@ -229,7 +229,7 @@ STATIC volatile tl_list_node_t *tl_list_unlink(volatile tl_list_node_t *n) {
|
||||
return next;
|
||||
}
|
||||
|
||||
STATIC void tl_list_append(volatile tl_list_node_t *head, volatile tl_list_node_t *n) {
|
||||
static void tl_list_append(volatile tl_list_node_t *head, volatile tl_list_node_t *n) {
|
||||
n->next = head;
|
||||
n->prev = head->prev;
|
||||
head->prev->next = n;
|
||||
@@ -239,7 +239,7 @@ STATIC void tl_list_append(volatile tl_list_node_t *head, volatile tl_list_node_
|
||||
/******************************************************************************/
|
||||
// IPCC interface
|
||||
|
||||
STATIC volatile ipcc_ref_table_t *get_buffer_table(void) {
|
||||
static volatile ipcc_ref_table_t *get_buffer_table(void) {
|
||||
// The IPCCDBA option bytes must not be changed without
|
||||
// making a corresponding change to the linker script.
|
||||
return (volatile ipcc_ref_table_t *)(SRAM2A_BASE + LL_FLASH_GetIPCCBufferAddr() * 4);
|
||||
@@ -299,9 +299,9 @@ void ipcc_init(uint32_t irq_pri) {
|
||||
// In either case we detect the failure response and inject this response
|
||||
// instead (which is HCI_EVENT_COMMAND_COMPLETE for OCF_CB_SET_EVENT_MASK2
|
||||
// with status=0).
|
||||
STATIC const uint8_t set_event_event_mask2_fix_payload[] = { 0x04, 0x0e, 0x04, 0x01, 0x63, 0x0c, 0x00 };
|
||||
static const uint8_t set_event_event_mask2_fix_payload[] = { 0x04, 0x0e, 0x04, 0x01, 0x63, 0x0c, 0x00 };
|
||||
|
||||
STATIC size_t tl_parse_hci_msg(const uint8_t *buf, parse_hci_info_t *parse) {
|
||||
static size_t tl_parse_hci_msg(const uint8_t *buf, parse_hci_info_t *parse) {
|
||||
const char *info;
|
||||
#if HCI_TRACE
|
||||
int applied_set_event_event_mask2_fix = 0;
|
||||
@@ -408,7 +408,7 @@ STATIC size_t tl_parse_hci_msg(const uint8_t *buf, parse_hci_info_t *parse) {
|
||||
return len;
|
||||
}
|
||||
|
||||
STATIC size_t tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) {
|
||||
static size_t tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) {
|
||||
volatile tl_list_node_t *cur = head->next;
|
||||
bool added_to_free_queue = false;
|
||||
size_t len = 0;
|
||||
@@ -441,7 +441,7 @@ STATIC size_t tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, par
|
||||
}
|
||||
|
||||
// Only call this when IRQs are disabled on this channel.
|
||||
STATIC size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) {
|
||||
static size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) {
|
||||
size_t len = 0;
|
||||
if (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, ch)) {
|
||||
// Process new data.
|
||||
@@ -458,7 +458,7 @@ STATIC size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse
|
||||
return len;
|
||||
}
|
||||
|
||||
STATIC void tl_hci_cmd(uint8_t *cmd, unsigned int ch, uint8_t hdr, uint16_t opcode, const uint8_t *buf, size_t len) {
|
||||
static void tl_hci_cmd(uint8_t *cmd, unsigned int ch, uint8_t hdr, uint16_t opcode, const uint8_t *buf, size_t len) {
|
||||
tl_list_node_t *n = (tl_list_node_t *)cmd;
|
||||
n->next = NULL;
|
||||
n->prev = NULL;
|
||||
@@ -480,7 +480,7 @@ STATIC void tl_hci_cmd(uint8_t *cmd, unsigned int ch, uint8_t hdr, uint16_t opco
|
||||
LL_C1_IPCC_SetFlag_CHx(IPCC, ch);
|
||||
}
|
||||
|
||||
STATIC ssize_t tl_sys_wait_ack(const uint8_t *buf, mp_int_t timeout_ms) {
|
||||
static ssize_t tl_sys_wait_ack(const uint8_t *buf, mp_int_t timeout_ms) {
|
||||
uint32_t t0 = mp_hal_ticks_ms();
|
||||
|
||||
timeout_ms = MAX(SYS_ACK_TIMEOUT_MS, timeout_ms);
|
||||
@@ -498,12 +498,12 @@ STATIC ssize_t tl_sys_wait_ack(const uint8_t *buf, mp_int_t timeout_ms) {
|
||||
return (ssize_t)tl_parse_hci_msg(buf, NULL);
|
||||
}
|
||||
|
||||
STATIC ssize_t tl_sys_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len, mp_int_t timeout_ms) {
|
||||
static ssize_t tl_sys_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len, mp_int_t timeout_ms) {
|
||||
tl_hci_cmd(ipcc_membuf_sys_cmd_buf, IPCC_CH_SYS, 0x10, opcode, buf, len);
|
||||
return tl_sys_wait_ack(ipcc_membuf_sys_cmd_buf, timeout_ms);
|
||||
}
|
||||
|
||||
STATIC int tl_ble_wait_resp(void) {
|
||||
static int tl_ble_wait_resp(void) {
|
||||
uint32_t t0 = mp_hal_ticks_ms();
|
||||
while (!LL_C2_IPCC_IsActiveFlag_CHx(IPCC, IPCC_CH_BLE)) {
|
||||
if (mp_hal_ticks_ms() - t0 > BLE_ACK_TIMEOUT_MS) {
|
||||
@@ -518,7 +518,7 @@ STATIC int tl_ble_wait_resp(void) {
|
||||
}
|
||||
|
||||
// Synchronously send a BLE command.
|
||||
STATIC void tl_ble_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len) {
|
||||
static void tl_ble_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len) {
|
||||
// Poll for completion rather than wait for IRQ->scheduler.
|
||||
LL_C1_IPCC_DisableReceiveChannel(IPCC, IPCC_CH_BLE);
|
||||
tl_hci_cmd(ipcc_membuf_ble_cmd_buf, IPCC_CH_BLE, HCI_KIND_BT_CMD, opcode, buf, len);
|
||||
@@ -743,19 +743,19 @@ void IPCC_C1_RX_IRQHandler(void) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC mp_obj_t rfcore_status(void) {
|
||||
static mp_obj_t rfcore_status(void) {
|
||||
return mp_obj_new_int_from_uint(ipcc_mem_dev_info_tab.fus.table_state);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(rfcore_status_obj, rfcore_status);
|
||||
|
||||
STATIC mp_obj_t get_version_tuple(uint32_t data) {
|
||||
static mp_obj_t get_version_tuple(uint32_t data) {
|
||||
mp_obj_t items[] = {
|
||||
MP_OBJ_NEW_SMALL_INT(data >> 24), MP_OBJ_NEW_SMALL_INT(data >> 16 & 0xFF), MP_OBJ_NEW_SMALL_INT(data >> 8 & 0xFF), MP_OBJ_NEW_SMALL_INT(data >> 4 & 0xF), MP_OBJ_NEW_SMALL_INT(data & 0xF)
|
||||
};
|
||||
return mp_obj_new_tuple(5, items);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t rfcore_fw_version(mp_obj_t fw_id_in) {
|
||||
static mp_obj_t rfcore_fw_version(mp_obj_t fw_id_in) {
|
||||
if (ipcc_mem_dev_info_tab.fus.table_state == MAGIC_IPCC_MEM_INCORRECT) {
|
||||
mp_raise_OSError(MP_EINVAL);
|
||||
}
|
||||
@@ -773,7 +773,7 @@ STATIC mp_obj_t rfcore_fw_version(mp_obj_t fw_id_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(rfcore_fw_version_obj, rfcore_fw_version);
|
||||
|
||||
STATIC mp_obj_t rfcore_sys_hci(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rfcore_sys_hci(size_t n_args, const mp_obj_t *args) {
|
||||
if (ipcc_mem_dev_info_tab.fus.table_state == MAGIC_IPCC_MEM_INCORRECT) {
|
||||
mp_raise_OSError(MP_EINVAL);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ uint32_t rng_get(void) {
|
||||
}
|
||||
|
||||
// Return a 30-bit hardware generated random number.
|
||||
STATIC mp_obj_t pyb_rng_get(void) {
|
||||
static mp_obj_t pyb_rng_get(void) {
|
||||
return mp_obj_new_int(rng_get() >> 2);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get);
|
||||
@@ -72,7 +72,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get);
|
||||
|
||||
// Yasmarang random number generator by Ilya Levin
|
||||
// http://www.literatecode.com/yasmarang
|
||||
STATIC uint32_t pyb_rng_yasmarang(void) {
|
||||
static uint32_t pyb_rng_yasmarang(void) {
|
||||
static bool seeded = false;
|
||||
static uint32_t pad = 0, n = 0, d = 0;
|
||||
static uint8_t dat = 0;
|
||||
|
||||
@@ -67,18 +67,18 @@ static mp_uint_t rtc_info;
|
||||
#define RTC_SYNCH_PREDIV (0x00ff)
|
||||
#endif
|
||||
|
||||
STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc);
|
||||
STATIC void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp);
|
||||
STATIC HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc);
|
||||
STATIC void RTC_CalendarConfig(void);
|
||||
static HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc);
|
||||
static void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp);
|
||||
static HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc);
|
||||
static void RTC_CalendarConfig(void);
|
||||
|
||||
#if MICROPY_HW_RTC_USE_LSE || MICROPY_HW_RTC_USE_BYPASS
|
||||
STATIC bool rtc_use_lse = true;
|
||||
static bool rtc_use_lse = true;
|
||||
#else
|
||||
STATIC bool rtc_use_lse = false;
|
||||
static bool rtc_use_lse = false;
|
||||
#endif
|
||||
STATIC uint32_t rtc_startup_tick;
|
||||
STATIC bool rtc_need_init_finalise = false;
|
||||
static uint32_t rtc_startup_tick;
|
||||
static bool rtc_need_init_finalise = false;
|
||||
|
||||
#if defined(STM32L0)
|
||||
#define BDCR CSR
|
||||
@@ -262,7 +262,7 @@ void rtc_init_finalise() {
|
||||
rtc_need_init_finalise = false;
|
||||
}
|
||||
|
||||
STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) {
|
||||
static HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) {
|
||||
/*------------------------------ LSI Configuration -------------------------*/
|
||||
if ((RCC_OscInitStruct->OscillatorType & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) {
|
||||
// Check the LSI State
|
||||
@@ -331,7 +331,7 @@ STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) {
|
||||
static HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) {
|
||||
// Check the RTC peripheral state
|
||||
if (hrtc == NULL) {
|
||||
return HAL_ERROR;
|
||||
@@ -399,7 +399,7 @@ STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp) {
|
||||
static void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp) {
|
||||
/* To change the source clock of the RTC feature (LSE, LSI), You have to:
|
||||
- Enable the power clock using __PWR_CLK_ENABLE()
|
||||
- Enable write access using HAL_PWR_EnableBkUpAccess() function before to
|
||||
@@ -443,7 +443,7 @@ STATIC void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool
|
||||
#define MICROPY_HW_RTC_BYP_TIMEOUT_MS 150
|
||||
#endif
|
||||
|
||||
STATIC HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc) {
|
||||
static HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc) {
|
||||
// we already had a kick so now wait for the corresponding ready state...
|
||||
if (rtc_use_lse) {
|
||||
// we now have to wait for LSE ready or timeout
|
||||
@@ -486,7 +486,7 @@ STATIC HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc) {
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
STATIC void RTC_CalendarConfig(void) {
|
||||
static void RTC_CalendarConfig(void) {
|
||||
// set the date to 1st Jan 2015
|
||||
RTC_DateTypeDef date;
|
||||
date.Year = 15;
|
||||
@@ -538,11 +538,11 @@ typedef struct _pyb_rtc_obj_t {
|
||||
mp_obj_base_t base;
|
||||
} pyb_rtc_obj_t;
|
||||
|
||||
STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}};
|
||||
static const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}};
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create an RTC object.
|
||||
STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -862,14 +862,14 @@ mp_obj_t pyb_rtc_calibration(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_calibration_obj, 1, 2, pyb_rtc_calibration);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_rtc_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_rtc_info_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&pyb_rtc_datetime_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_wakeup), MP_ROM_PTR(&pyb_rtc_wakeup_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&pyb_rtc_calibration_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_rtc_type,
|
||||
|
||||
@@ -208,7 +208,7 @@ void sdcard_select_mmc(void) {
|
||||
pyb_sdmmc_flags |= PYB_SDMMC_FLAG_MMC;
|
||||
}
|
||||
|
||||
STATIC void sdmmc_msp_init(void) {
|
||||
static void sdmmc_msp_init(void) {
|
||||
// enable SDIO clock
|
||||
SDMMC_CLK_ENABLE();
|
||||
|
||||
@@ -264,7 +264,7 @@ bool sdcard_is_present(void) {
|
||||
}
|
||||
|
||||
#if MICROPY_HW_ENABLE_SDCARD
|
||||
STATIC HAL_StatusTypeDef sdmmc_init_sd(void) {
|
||||
static HAL_StatusTypeDef sdmmc_init_sd(void) {
|
||||
// SD device interface configuration
|
||||
sdmmc_handle.sd.Instance = SDIO;
|
||||
sdmmc_handle.sd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
||||
@@ -299,7 +299,7 @@ STATIC HAL_StatusTypeDef sdmmc_init_sd(void) {
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_ENABLE_MMCARD
|
||||
STATIC HAL_StatusTypeDef sdmmc_init_mmc(void) {
|
||||
static HAL_StatusTypeDef sdmmc_init_mmc(void) {
|
||||
// MMC device interface configuration
|
||||
sdmmc_handle.mmc.Instance = SDIO;
|
||||
sdmmc_handle.mmc.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
||||
@@ -410,7 +410,7 @@ uint64_t sdcard_get_capacity_in_bytes(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void sdmmc_irq_handler(void) {
|
||||
static void sdmmc_irq_handler(void) {
|
||||
switch (pyb_sdmmc_flags) {
|
||||
#if MICROPY_HW_ENABLE_SDCARD
|
||||
case PYB_SDMMC_FLAG_ACTIVE | PYB_SDMMC_FLAG_SD:
|
||||
@@ -431,7 +431,7 @@ void SDMMC_IRQHandler(void) {
|
||||
IRQ_EXIT(SDMMC_IRQn);
|
||||
}
|
||||
|
||||
STATIC void sdcard_reset_periph(void) {
|
||||
static void sdcard_reset_periph(void) {
|
||||
// Fully reset the SDMMC peripheral before calling HAL SD DMA functions.
|
||||
// (There could be an outstanding DTIMEOUT event from a previous call and the
|
||||
// HAL function enables IRQs before fully configuring the SDMMC peripheral.)
|
||||
@@ -441,7 +441,7 @@ STATIC void sdcard_reset_periph(void) {
|
||||
SDIO->ICR = SDMMC_STATIC_FLAGS;
|
||||
}
|
||||
|
||||
STATIC HAL_StatusTypeDef sdcard_wait_finished(uint32_t timeout) {
|
||||
static HAL_StatusTypeDef sdcard_wait_finished(uint32_t timeout) {
|
||||
// Wait for HAL driver to be ready (eg for DMA to finish)
|
||||
uint32_t start = HAL_GetTick();
|
||||
for (;;) {
|
||||
@@ -699,7 +699,7 @@ const mp_obj_base_t pyb_mmcard_obj = {&pyb_mmcard_type};
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_ENABLE_SDCARD
|
||||
STATIC mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -717,7 +717,7 @@ STATIC mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, si
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_ENABLE_MMCARD
|
||||
STATIC mp_obj_t pyb_mmcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_mmcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -734,12 +734,12 @@ STATIC mp_obj_t pyb_mmcard_make_new(const mp_obj_type_t *type, size_t n_args, si
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t sd_present(mp_obj_t self) {
|
||||
static mp_obj_t sd_present(mp_obj_t self) {
|
||||
return mp_obj_new_bool(sdcard_is_present());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present);
|
||||
|
||||
STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) {
|
||||
static mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) {
|
||||
bool result;
|
||||
if (mp_obj_is_true(state)) {
|
||||
result = sdcard_power_on();
|
||||
@@ -749,9 +749,9 @@ STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) {
|
||||
}
|
||||
return mp_obj_new_bool(result);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(sd_power_obj, sd_power);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(sd_power_obj, sd_power);
|
||||
|
||||
STATIC mp_obj_t sd_info(mp_obj_t self) {
|
||||
static mp_obj_t sd_info(mp_obj_t self) {
|
||||
if (!(pyb_sdmmc_flags & PYB_SDMMC_FLAG_ACTIVE)) {
|
||||
return mp_const_none;
|
||||
}
|
||||
@@ -778,10 +778,10 @@ STATIC mp_obj_t sd_info(mp_obj_t self) {
|
||||
};
|
||||
return mp_obj_new_tuple(3, tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info);
|
||||
|
||||
// now obsolete, kept for backwards compatibility
|
||||
STATIC mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
|
||||
static mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
|
||||
uint8_t *dest = m_new(uint8_t, SDCARD_BLOCK_SIZE);
|
||||
mp_uint_t ret = sdcard_read_blocks(dest, mp_obj_get_int(block_num), 1);
|
||||
|
||||
@@ -792,10 +792,10 @@ STATIC mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
|
||||
|
||||
return mp_obj_new_bytearray_by_ref(SDCARD_BLOCK_SIZE, dest);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read);
|
||||
|
||||
// now obsolete, kept for backwards compatibility
|
||||
STATIC mp_obj_t sd_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t data) {
|
||||
static mp_obj_t sd_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t data) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
||||
if (bufinfo.len % SDCARD_BLOCK_SIZE != 0) {
|
||||
@@ -810,25 +810,25 @@ STATIC mp_obj_t sd_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t data) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(sd_write_obj, sd_write);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(sd_write_obj, sd_write);
|
||||
|
||||
STATIC mp_obj_t pyb_sdcard_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
static mp_obj_t pyb_sdcard_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
|
||||
mp_uint_t ret = sdcard_read_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE);
|
||||
return mp_obj_new_bool(ret == 0);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_readblocks_obj, pyb_sdcard_readblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_readblocks_obj, pyb_sdcard_readblocks);
|
||||
|
||||
STATIC mp_obj_t pyb_sdcard_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
static mp_obj_t pyb_sdcard_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
||||
mp_uint_t ret = sdcard_write_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE);
|
||||
return mp_obj_new_bool(ret == 0);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_writeblocks_obj, pyb_sdcard_writeblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_writeblocks_obj, pyb_sdcard_writeblocks);
|
||||
|
||||
STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
static mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||
switch (cmd) {
|
||||
case MP_BLOCKDEV_IOCTL_INIT:
|
||||
@@ -855,9 +855,9 @@ STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in
|
||||
return MP_OBJ_NEW_SMALL_INT(-1); // error
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_ioctl_obj, pyb_sdcard_ioctl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_ioctl_obj, pyb_sdcard_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&sd_present_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_power), MP_ROM_PTR(&sd_power_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&sd_info_obj) },
|
||||
@@ -869,7 +869,7 @@ STATIC const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_sdcard_ioctl_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_sdcard_locals_dict, pyb_sdcard_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_sdcard_locals_dict, pyb_sdcard_locals_dict_table);
|
||||
|
||||
#if MICROPY_HW_ENABLE_SDCARD
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
|
||||
@@ -60,7 +60,7 @@ typedef struct _pyb_servo_obj_t {
|
||||
uint16_t time_left;
|
||||
} pyb_servo_obj_t;
|
||||
|
||||
STATIC pyb_servo_obj_t pyb_servo_obj[PYB_SERVO_NUM];
|
||||
static pyb_servo_obj_t pyb_servo_obj[PYB_SERVO_NUM];
|
||||
|
||||
void servo_init(void) {
|
||||
// reset servo objects
|
||||
@@ -123,7 +123,7 @@ void servo_timer_irq_callback(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void servo_init_channel(pyb_servo_obj_t *s) {
|
||||
static void servo_init_channel(pyb_servo_obj_t *s) {
|
||||
static const uint8_t channel_table[4] =
|
||||
{TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4};
|
||||
uint32_t channel = channel_table[s->pin->pin];
|
||||
@@ -150,7 +150,7 @@ STATIC void servo_init_channel(pyb_servo_obj_t *s) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) {
|
||||
static mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) {
|
||||
int p = mp_obj_get_int(port);
|
||||
int v = mp_obj_get_int(value);
|
||||
if (v < 50) {
|
||||
@@ -178,7 +178,7 @@ STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) {
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(pyb_servo_set_obj, pyb_servo_set);
|
||||
|
||||
STATIC mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) {
|
||||
static mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) {
|
||||
int pe = mp_obj_get_int(period);
|
||||
int pu = mp_obj_get_int(pulse);
|
||||
TIM5->ARR = pe;
|
||||
@@ -188,14 +188,14 @@ 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) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<Servo %u at %uus>", self - &pyb_servo_obj[0] + 1, 10 * self->pulse_cur);
|
||||
}
|
||||
|
||||
/// \classmethod \constructor(id)
|
||||
/// Create a servo object. `id` is 1-4.
|
||||
STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@@ -218,7 +218,7 @@ STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
|
||||
/// \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) {
|
||||
static mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get pulse width, in us
|
||||
@@ -231,12 +231,12 @@ STATIC mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_pulse_width_obj, 1, 2, pyb_servo_pulse_width);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_pulse_width_obj, 1, 2, pyb_servo_pulse_width);
|
||||
|
||||
/// \method calibration([pulse_min, pulse_max, pulse_centre, [pulse_angle_90, pulse_speed_100]])
|
||||
/// 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) {
|
||||
static mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get calibration values
|
||||
@@ -264,14 +264,14 @@ STATIC mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) {
|
||||
// bad number of arguments
|
||||
mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("calibration expecting 1, 4 or 6 arguments, got %d"), n_args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_calibration_obj, 1, 6, pyb_servo_calibration);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_calibration_obj, 1, 6, pyb_servo_calibration);
|
||||
|
||||
/// \method angle([angle, time=0])
|
||||
/// Get or set the angle of the servo.
|
||||
///
|
||||
/// - `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) {
|
||||
static mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get angle
|
||||
@@ -294,14 +294,14 @@ STATIC mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle);
|
||||
|
||||
/// \method speed([speed, time=0])
|
||||
/// Get or set the speed of a continuous rotation 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) {
|
||||
static mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get speed
|
||||
@@ -325,16 +325,16 @@ STATIC mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_speed_obj, 1, 3, pyb_servo_speed);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_speed_obj, 1, 3, pyb_servo_speed);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_servo_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_servo_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_pulse_width), MP_ROM_PTR(&pyb_servo_pulse_width_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&pyb_servo_calibration_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_angle), MP_ROM_PTR(&pyb_servo_angle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_speed), MP_ROM_PTR(&pyb_servo_speed_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_servo_type,
|
||||
|
||||
@@ -46,22 +46,22 @@
|
||||
// SPI6_RX: DMA2_Stream6.CHANNEL_1
|
||||
|
||||
#if defined(MICROPY_HW_SPI1_SCK)
|
||||
STATIC SPI_HandleTypeDef SPIHandle1 = {.Instance = NULL};
|
||||
static SPI_HandleTypeDef SPIHandle1 = {.Instance = NULL};
|
||||
#endif
|
||||
#if defined(MICROPY_HW_SPI2_SCK)
|
||||
STATIC SPI_HandleTypeDef SPIHandle2 = {.Instance = NULL};
|
||||
static SPI_HandleTypeDef SPIHandle2 = {.Instance = NULL};
|
||||
#endif
|
||||
#if defined(MICROPY_HW_SPI3_SCK)
|
||||
STATIC SPI_HandleTypeDef SPIHandle3 = {.Instance = NULL};
|
||||
static SPI_HandleTypeDef SPIHandle3 = {.Instance = NULL};
|
||||
#endif
|
||||
#if defined(MICROPY_HW_SPI4_SCK)
|
||||
STATIC SPI_HandleTypeDef SPIHandle4 = {.Instance = NULL};
|
||||
static SPI_HandleTypeDef SPIHandle4 = {.Instance = NULL};
|
||||
#endif
|
||||
#if defined(MICROPY_HW_SPI5_SCK)
|
||||
STATIC SPI_HandleTypeDef SPIHandle5 = {.Instance = NULL};
|
||||
static SPI_HandleTypeDef SPIHandle5 = {.Instance = NULL};
|
||||
#endif
|
||||
#if defined(MICROPY_HW_SPI6_SCK)
|
||||
STATIC SPI_HandleTypeDef SPIHandle6 = {.Instance = NULL};
|
||||
static SPI_HandleTypeDef SPIHandle6 = {.Instance = NULL};
|
||||
#endif
|
||||
#if defined(MICROPY_HW_SUBGHZSPI_ID)
|
||||
static SPI_HandleTypeDef SPIHandleSubGhz = {.Instance = NULL};
|
||||
@@ -231,7 +231,7 @@ int spi_find_index(mp_obj_t id) {
|
||||
return spi_id;
|
||||
}
|
||||
|
||||
STATIC uint32_t spi_get_source_freq(SPI_HandleTypeDef *spi) {
|
||||
static uint32_t spi_get_source_freq(SPI_HandleTypeDef *spi) {
|
||||
#if defined(STM32F0) || defined(STM32G0)
|
||||
return HAL_RCC_GetPCLK1Freq();
|
||||
#elif defined(STM32H5)
|
||||
@@ -545,7 +545,7 @@ void spi_deinit(const spi_t *spi_obj) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC HAL_StatusTypeDef spi_wait_dma_finished(const spi_t *spi, uint32_t t_start, uint32_t timeout) {
|
||||
static HAL_StatusTypeDef spi_wait_dma_finished(const spi_t *spi, uint32_t t_start, uint32_t timeout) {
|
||||
volatile HAL_SPI_StateTypeDef *state = &spi->spi->State;
|
||||
for (;;) {
|
||||
// Do an atomic check of the state; WFI will exit even if IRQs are disabled
|
||||
@@ -768,7 +768,7 @@ mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t o) {
|
||||
/******************************************************************************/
|
||||
// Implementation of low-level SPI C protocol
|
||||
|
||||
STATIC int spi_proto_ioctl(void *self_in, uint32_t cmd) {
|
||||
static int spi_proto_ioctl(void *self_in, uint32_t cmd) {
|
||||
spi_proto_cfg_t *self = (spi_proto_cfg_t *)self_in;
|
||||
|
||||
switch (cmd) {
|
||||
@@ -790,7 +790,7 @@ STATIC int spi_proto_ioctl(void *self_in, uint32_t cmd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC void spi_proto_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
static void spi_proto_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
spi_proto_cfg_t *self = (spi_proto_cfg_t *)self_in;
|
||||
spi_transfer(self->spi, len, src, dest, SPI_TRANSFER_TIMEOUT(len));
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ extern PCD_HandleTypeDef pcd_hs_handle;
|
||||
// More information about decoding the fault registers can be found here:
|
||||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0646a/Cihdjcfc.html
|
||||
|
||||
STATIC char *fmt_hex(uint32_t val, char *buf) {
|
||||
static char *fmt_hex(uint32_t val, char *buf) {
|
||||
const char *hexDig = "0123456789abcdef";
|
||||
|
||||
buf[0] = hexDig[(val >> 28) & 0x0f];
|
||||
@@ -114,7 +114,7 @@ STATIC char *fmt_hex(uint32_t val, char *buf) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
STATIC void print_reg(const char *label, uint32_t val) {
|
||||
static void print_reg(const char *label, uint32_t val) {
|
||||
char hexStr[9];
|
||||
|
||||
mp_hal_stdout_tx_str(label);
|
||||
@@ -122,7 +122,7 @@ STATIC void print_reg(const char *label, uint32_t val) {
|
||||
mp_hal_stdout_tx_str("\r\n");
|
||||
}
|
||||
|
||||
STATIC void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) {
|
||||
static void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) {
|
||||
char hex_str[9];
|
||||
mp_hal_stdout_tx_str(label);
|
||||
mp_hal_stdout_tx_str(fmt_hex(val1, hex_str));
|
||||
@@ -356,7 +356,7 @@ void OTG_HS_IRQHandler(void) {
|
||||
* @param *pcd_handle for FS or HS
|
||||
* @retval None
|
||||
*/
|
||||
STATIC void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) {
|
||||
static void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) {
|
||||
|
||||
if (pcd_handle->Init.low_power_enable) {
|
||||
/* Reset SLEEPDEEP bit of Cortex System Control Register */
|
||||
|
||||
@@ -273,7 +273,7 @@ const pyb_flash_obj_t pyb_flash_obj = {
|
||||
0, // actual size handled in ioctl, MP_BLOCKDEV_IOCTL_BLOCK_COUNT case
|
||||
};
|
||||
|
||||
STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self == &pyb_flash_obj) {
|
||||
mp_printf(print, "Flash()");
|
||||
@@ -282,7 +282,7 @@ STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// Parse arguments
|
||||
enum { ARG_start, ARG_len };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -322,7 +322,7 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
uint32_t block_num = mp_obj_get_int(args[1]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
@@ -347,9 +347,9 @@ STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
#endif
|
||||
return MP_OBJ_NEW_SMALL_INT(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks);
|
||||
|
||||
STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
uint32_t block_num = mp_obj_get_int(args[1]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
@@ -374,9 +374,9 @@ STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
#endif
|
||||
return MP_OBJ_NEW_SMALL_INT(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks);
|
||||
|
||||
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
static mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||
switch (cmd) {
|
||||
@@ -438,15 +438,15 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_flash_type,
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
// Interface to the STM32WL series "SUBGHZ Radio" module
|
||||
|
||||
STATIC void handle_radio_irq() {
|
||||
static void handle_radio_irq() {
|
||||
// Level-triggered interrupts means the interrupt has to be cleared before
|
||||
// this function returns.
|
||||
//
|
||||
@@ -90,7 +90,7 @@ void subghz_deinit(void) {
|
||||
__HAL_RCC_SUBGHZ_RADIO_RELEASE_RESET();
|
||||
}
|
||||
|
||||
STATIC mp_obj_t subghz_cs(mp_obj_t value) {
|
||||
static mp_obj_t subghz_cs(mp_obj_t value) {
|
||||
// Treat the same as normal SPI - truthy is "unselected",
|
||||
// falsey is active low "selected",
|
||||
if (mp_obj_is_true(value)) {
|
||||
@@ -103,7 +103,7 @@ STATIC mp_obj_t subghz_cs(mp_obj_t value) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(subghz_cs_obj, subghz_cs);
|
||||
|
||||
STATIC mp_obj_t subghz_irq(mp_obj_t handler) {
|
||||
static mp_obj_t subghz_irq(mp_obj_t handler) {
|
||||
MP_STATE_PORT(subghz_callback) = handler;
|
||||
|
||||
if (mp_obj_is_true(handler)) {
|
||||
@@ -117,7 +117,7 @@ STATIC mp_obj_t subghz_irq(mp_obj_t handler) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(subghz_irq_obj, subghz_irq);
|
||||
|
||||
STATIC mp_obj_t subghz_is_busy(void) {
|
||||
static mp_obj_t subghz_is_busy(void) {
|
||||
// Read the raw unmasked busy signal. This should be checked before driving
|
||||
// CS low to start a command.
|
||||
//
|
||||
|
||||
@@ -93,7 +93,7 @@ typedef enum {
|
||||
CHANNEL_MODE_ENC_AB,
|
||||
} pyb_channel_mode;
|
||||
|
||||
STATIC const struct {
|
||||
static const struct {
|
||||
qstr name;
|
||||
uint32_t oc_mode;
|
||||
} channel_mode_info[] = {
|
||||
@@ -147,9 +147,9 @@ TIM_HandleTypeDef TIM6_Handle;
|
||||
|
||||
#define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(MP_STATE_PORT(pyb_timer_obj_all))
|
||||
|
||||
STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in);
|
||||
STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback);
|
||||
STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback);
|
||||
static mp_obj_t pyb_timer_deinit(mp_obj_t self_in);
|
||||
static mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback);
|
||||
static mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback);
|
||||
|
||||
void timer_init0(void) {
|
||||
for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) {
|
||||
@@ -304,14 +304,14 @@ uint32_t timer_get_source_freq(uint32_t tim_id) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings */
|
||||
|
||||
STATIC const mp_obj_type_t pyb_timer_channel_type;
|
||||
static const mp_obj_type_t pyb_timer_channel_type;
|
||||
|
||||
// This is the largest value that we can multiply by 100 and have the result
|
||||
// fit in a uint32_t.
|
||||
#define MAX_PERIOD_DIV_100 42949672
|
||||
|
||||
// computes prescaler and period so TIM triggers at freq-Hz
|
||||
STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj_t freq_in, uint32_t *period_out) {
|
||||
static uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj_t freq_in, uint32_t *period_out) {
|
||||
uint32_t source_freq = timer_get_source_freq(self->tim_id);
|
||||
uint32_t prescaler = 1;
|
||||
uint32_t period;
|
||||
@@ -357,7 +357,7 @@ STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj
|
||||
}
|
||||
|
||||
// computes prescaler and period so TIM triggers with a period of t_num/t_den seconds
|
||||
STATIC uint32_t compute_prescaler_period_from_t(pyb_timer_obj_t *self, int32_t t_num, int32_t t_den, uint32_t *period_out) {
|
||||
static uint32_t compute_prescaler_period_from_t(pyb_timer_obj_t *self, int32_t t_num, int32_t t_den, uint32_t *period_out) {
|
||||
uint32_t source_freq = timer_get_source_freq(self->tim_id);
|
||||
if (t_num <= 0 || t_den <= 0) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("must have positive freq"));
|
||||
@@ -391,7 +391,7 @@ STATIC uint32_t compute_prescaler_period_from_t(pyb_timer_obj_t *self, int32_t t
|
||||
}
|
||||
|
||||
// Helper function for determining the period used for calculating percent
|
||||
STATIC uint32_t compute_period(pyb_timer_obj_t *self) {
|
||||
static uint32_t compute_period(pyb_timer_obj_t *self) {
|
||||
// In center mode, compare == period corresponds to 100%
|
||||
// In edge mode, compare == (period + 1) corresponds to 100%
|
||||
uint32_t period = (__HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self));
|
||||
@@ -408,7 +408,7 @@ STATIC uint32_t compute_period(pyb_timer_obj_t *self) {
|
||||
// Helper function to compute PWM value from timer period and percent value.
|
||||
// 'percent_in' can be an int or a float between 0 and 100 (out of range
|
||||
// values are clamped).
|
||||
STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent_in) {
|
||||
static uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent_in) {
|
||||
uint32_t cmp;
|
||||
if (0) {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
@@ -441,7 +441,7 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent
|
||||
}
|
||||
|
||||
// Helper function to compute percentage from timer perion and PWM value.
|
||||
STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) {
|
||||
static mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
mp_float_t percent;
|
||||
if (cmp >= period) {
|
||||
@@ -472,7 +472,7 @@ STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) {
|
||||
// 128-256 ticks in increments of 2
|
||||
// 256-512 ticks in increments of 8
|
||||
// 512-1008 ticks in increments of 16
|
||||
STATIC uint32_t compute_dtg_from_ticks(mp_int_t ticks) {
|
||||
static uint32_t compute_dtg_from_ticks(mp_int_t ticks) {
|
||||
if (ticks <= 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -493,7 +493,7 @@ STATIC uint32_t compute_dtg_from_ticks(mp_int_t ticks) {
|
||||
|
||||
// Given the 8-bit value stored in the DTG field of the BDTR register, compute
|
||||
// the number of ticks.
|
||||
STATIC mp_int_t compute_ticks_from_dtg(uint32_t dtg) {
|
||||
static mp_int_t compute_ticks_from_dtg(uint32_t dtg) {
|
||||
if ((dtg & 0x80) == 0) {
|
||||
return dtg & 0x7F;
|
||||
}
|
||||
@@ -506,7 +506,7 @@ STATIC mp_int_t compute_ticks_from_dtg(uint32_t dtg) {
|
||||
return 512 + ((dtg & 0x1F) * 16);
|
||||
}
|
||||
|
||||
STATIC void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks, mp_int_t brk) {
|
||||
static void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks, mp_int_t brk) {
|
||||
TIM_BreakDeadTimeConfigTypeDef deadTimeConfig = {0};
|
||||
deadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
deadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||
@@ -534,7 +534,7 @@ TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer) {
|
||||
return &self->tim;
|
||||
}
|
||||
|
||||
STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (self->tim.State == HAL_TIM_STATE_RESET) {
|
||||
@@ -628,7 +628,7 @@ 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 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) {
|
||||
enum { ARG_freq, ARG_prescaler, ARG_period, ARG_tick_hz, ARG_mode, ARG_div, ARG_callback, ARG_deadtime, ARG_brk };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
|
||||
@@ -834,7 +834,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons
|
||||
// This table encodes the timer instance and irq number (for the update irq).
|
||||
// It assumes that timer instance pointer has the lower 8 bits cleared.
|
||||
#define TIM_ENTRY(id, irq) [id - 1] = (uint32_t)TIM##id | irq
|
||||
STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = {
|
||||
static const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = {
|
||||
#if defined(TIM1)
|
||||
#if defined(STM32F0) || defined(STM32G0)
|
||||
TIM_ENTRY(1, TIM1_BRK_UP_TRG_COM_IRQn),
|
||||
@@ -977,7 +977,7 @@ STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = {
|
||||
/// Construct a new timer object of the given id. If additional
|
||||
/// arguments are given, then the timer is initialised by `init(...)`.
|
||||
/// `id` can be 1 to 14, excluding 3.
|
||||
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -1026,13 +1026,13 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
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) {
|
||||
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(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);
|
||||
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) {
|
||||
static mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
|
||||
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// Disable the base interrupt
|
||||
@@ -1055,7 +1055,7 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
|
||||
|
||||
/// \method channel(channel, mode, ...)
|
||||
///
|
||||
@@ -1129,7 +1129,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
|
||||
/// timer = pyb.Timer(2, freq=1000)
|
||||
/// ch2 = timer.channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.X2, pulse_width=210000)
|
||||
/// ch3 = timer.channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.X3, pulse_width=420000)
|
||||
STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
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_rom_obj = MP_ROM_NONE} },
|
||||
@@ -1386,11 +1386,11 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
|
||||
return MP_OBJ_FROM_PTR(chan);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
|
||||
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) {
|
||||
static mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -1401,20 +1401,20 @@ STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_timer_counter);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_timer_counter);
|
||||
|
||||
/// \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) {
|
||||
static mp_obj_t pyb_timer_source_freq(mp_obj_t 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);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_source_freq_obj, pyb_timer_source_freq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_source_freq_obj, pyb_timer_source_freq);
|
||||
|
||||
/// \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) {
|
||||
static mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -1445,11 +1445,11 @@ STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_freq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_freq);
|
||||
|
||||
/// \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) {
|
||||
static mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -1460,11 +1460,11 @@ STATIC mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_timer_prescaler);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_timer_prescaler);
|
||||
|
||||
/// \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) {
|
||||
static mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -1475,13 +1475,13 @@ STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer_period);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer_period);
|
||||
|
||||
/// \method callback(fun)
|
||||
/// Set the function to be called when the timer triggers.
|
||||
/// `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) {
|
||||
static mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) {
|
||||
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (callback == mp_const_none) {
|
||||
// stop interrupt (but not timer)
|
||||
@@ -1501,9 +1501,9 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_callback_obj, pyb_timer_callback);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_callback_obj, pyb_timer_callback);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) },
|
||||
@@ -1538,7 +1538,7 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_BRK_LOW), MP_ROM_INT(BRK_LOW) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BRK_HIGH), MP_ROM_INT(BRK_HIGH) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_timer_type,
|
||||
@@ -1555,7 +1555,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
/// Timer channels are used to generate/capture a signal using a timer.
|
||||
///
|
||||
/// 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) {
|
||||
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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
mp_printf(print, "TimerChannel(timer=%u, channel=%u, mode=%s)",
|
||||
@@ -1581,7 +1581,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) {
|
||||
static mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -1592,7 +1592,7 @@ STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj, 1, 2, pyb_timer_channel_capture_compare);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj, 1, 2, pyb_timer_channel_capture_compare);
|
||||
|
||||
/// \method pulse_width_percent([value])
|
||||
/// Get or set the pulse width percentage associated with a channel. The value
|
||||
@@ -1600,7 +1600,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj
|
||||
/// for which the pulse is active. The value can be an integer or
|
||||
/// 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) {
|
||||
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 = MP_OBJ_TO_PTR(args[0]);
|
||||
uint32_t period = compute_period(self->timer);
|
||||
if (n_args == 1) {
|
||||
@@ -1614,13 +1614,13 @@ STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_ob
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_pulse_width_percent_obj, 1, 2, pyb_timer_channel_pulse_width_percent);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_pulse_width_percent_obj, 1, 2, pyb_timer_channel_pulse_width_percent);
|
||||
|
||||
/// \method callback(fun)
|
||||
/// Set the function to be called when the timer channel triggers.
|
||||
/// `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) {
|
||||
static mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) {
|
||||
pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (callback == mp_const_none) {
|
||||
// stop interrupt (but not timer)
|
||||
@@ -1668,9 +1668,9 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_channel_callback_obj, pyb_timer_channel_callback);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_channel_callback_obj, pyb_timer_channel_callback);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_channel_callback_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pulse_width), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
|
||||
@@ -1678,9 +1678,9 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_compare), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_timer_channel_type,
|
||||
MP_QSTR_TimerChannel,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
@@ -1688,7 +1688,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &pyb_timer_channel_locals_dict
|
||||
);
|
||||
|
||||
STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) {
|
||||
static void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) {
|
||||
uint32_t irq_mask = TIMER_IRQ_MASK(channel);
|
||||
|
||||
if (__HAL_TIM_GET_FLAG(&tim->tim, irq_mask) != RESET) {
|
||||
|
||||
@@ -122,7 +122,7 @@ typedef struct _machine_uart_irq_map_t {
|
||||
uint16_t flag;
|
||||
} machine_uart_irq_map_t;
|
||||
|
||||
STATIC const machine_uart_irq_map_t mp_uart_irq_map[] = {
|
||||
static const machine_uart_irq_map_t mp_uart_irq_map[] = {
|
||||
{ USART_CR1_IDLEIE, UART_FLAG_IDLE}, // RX idle
|
||||
{ USART_CR1_PEIE, UART_FLAG_PE}, // parity error
|
||||
#if defined(STM32G0) || defined(STM32WL)
|
||||
@@ -1038,7 +1038,7 @@ bool uart_tx_wait(machine_uart_obj_t *self, uint32_t timeout) {
|
||||
|
||||
// Waits at most timeout milliseconds for UART flag to be set.
|
||||
// Returns true if flag is/was set, false on timeout.
|
||||
STATIC bool uart_wait_flag_set(machine_uart_obj_t *self, uint32_t flag, uint32_t timeout) {
|
||||
static bool uart_wait_flag_set(machine_uart_obj_t *self, uint32_t flag, uint32_t timeout) {
|
||||
// Note: we don't use WFI to idle in this loop because UART tx doesn't generate
|
||||
// an interrupt and the flag can be set quickly if the baudrate is large.
|
||||
uint32_t start = HAL_GetTick();
|
||||
@@ -1215,7 +1215,7 @@ void uart_irq_handler(mp_uint_t uart_id) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
static mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uart_irq_config(self, false);
|
||||
self->mp_irq_trigger = new_trigger;
|
||||
@@ -1223,7 +1223,7 @@ STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
static mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (info_type == MP_IRQ_INFO_FLAGS) {
|
||||
return self->mp_irq_flags;
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
// Constants for USB_VCP.irq trigger.
|
||||
#define USBD_CDC_IRQ_RX (1)
|
||||
|
||||
STATIC void pyb_usb_vcp_init0(void);
|
||||
static void pyb_usb_vcp_init0(void);
|
||||
|
||||
// this will be persistent across a soft-reset
|
||||
mp_uint_t pyb_usb_flags = 0;
|
||||
@@ -97,14 +97,14 @@ pyb_usb_storage_medium_t pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_NONE;
|
||||
// Units of FIFO size arrays below are 4x 16-bit words = 8 bytes
|
||||
// There are 512x 16-bit words it total to use here (when using PCD_SNG_BUF)
|
||||
|
||||
STATIC const uint8_t usbd_fifo_size_cdc1[USBD_PMA_NUM_FIFO] = {
|
||||
static const uint8_t usbd_fifo_size_cdc1[USBD_PMA_NUM_FIFO] = {
|
||||
16, 16, 16, 16, // EP0(out), EP0(in), MSC/HID(out), MSC/HID(in)
|
||||
0, 16, 16, 16, // unused, CDC_CMD(in), CDC_DATA(out), CDC_DATA(in)
|
||||
0, 0, 0, 0, 0, 0, 0, 0, // 8x unused
|
||||
};
|
||||
|
||||
#if MICROPY_HW_USB_CDC_NUM >= 2
|
||||
STATIC const uint8_t usbd_fifo_size_cdc2[USBD_PMA_NUM_FIFO] = {
|
||||
static const uint8_t usbd_fifo_size_cdc2[USBD_PMA_NUM_FIFO] = {
|
||||
8, 8, 16, 16, // EP0(out), EP0(in), MSC/HID(out), MSC/HID(in)
|
||||
0, 8, 16, 8, // unused, CDC_CMD(in), CDC_DATA(out), CDC_DATA(in)
|
||||
0, 8, 16, 8, // unused, CDC2_CMD(in), CDC2_DATA(out), CDC2_DATA(in)
|
||||
@@ -112,7 +112,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2[USBD_PMA_NUM_FIFO] = {
|
||||
};
|
||||
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD/HID, CDC2_DATA, HID
|
||||
STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[USBD_PMA_NUM_FIFO] = {
|
||||
static const uint8_t usbd_fifo_size_cdc2_msc_hid[USBD_PMA_NUM_FIFO] = {
|
||||
8, 8, 16, 16, // EP0(out), EP0(in), MSC/HID(out), MSC/HID(in)
|
||||
0, 8, 8, 8, // unused, CDC_CMD(in), CDC_DATA(out), CDC_DATA(in)
|
||||
0, 8, 8, 8, // unused, CDC2_CMD(in), CDC2_DATA(out), CDC2_DATA(in)
|
||||
@@ -128,7 +128,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[USBD_PMA_NUM_FIFO] = {
|
||||
// HS: there are 1024x 32-bit words in total to use here
|
||||
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA
|
||||
STATIC const uint8_t usbd_fifo_size_cdc1[] = {
|
||||
static const uint8_t usbd_fifo_size_cdc1[] = {
|
||||
32, 8, 16, 8, 16, 0, 0, // FS: RX, EP0(in), 5x IN endpoints
|
||||
#if MICROPY_HW_USB_HS
|
||||
116, 8, 64, 4, 64, 0, 0, 0, 0, 0, // HS: RX, EP0(in), 8x IN endpoints
|
||||
@@ -136,7 +136,7 @@ STATIC const uint8_t usbd_fifo_size_cdc1[] = {
|
||||
};
|
||||
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, HID
|
||||
STATIC const uint8_t usbd_fifo_size_cdc1_msc_hid[] = {
|
||||
static const uint8_t usbd_fifo_size_cdc1_msc_hid[] = {
|
||||
32, 8, 16, 4, 12, 8, 0,
|
||||
#if MICROPY_HW_USB_HS
|
||||
116, 8, 64, 4, 56, 8, 0, 0, 0, 0,
|
||||
@@ -145,7 +145,7 @@ STATIC const uint8_t usbd_fifo_size_cdc1_msc_hid[] = {
|
||||
|
||||
#if MICROPY_HW_USB_CDC_NUM >= 2
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD, CDC2_DATA
|
||||
STATIC const uint8_t usbd_fifo_size_cdc2[] = {
|
||||
static const uint8_t usbd_fifo_size_cdc2[] = {
|
||||
32, 8, 16, 4, 8, 4, 8,
|
||||
#if MICROPY_HW_USB_HS
|
||||
116, 8, 64, 2, 32, 2, 32, 0, 0, 0,
|
||||
@@ -153,7 +153,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2[] = {
|
||||
};
|
||||
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD/HID, CDC2_DATA, HID
|
||||
STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[] = {
|
||||
static const uint8_t usbd_fifo_size_cdc2_msc_hid[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, // FS: can't support 2xVCP+MSC+HID
|
||||
#if MICROPY_HW_USB_HS
|
||||
102, 8, 64, 2, 32, 8, 32, 8, 0, 0,
|
||||
@@ -163,7 +163,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[] = {
|
||||
|
||||
#if MICROPY_HW_USB_CDC_NUM >= 3
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD, CDC2_DATA, CDC3_CMD, CDC3_DATA
|
||||
STATIC const uint8_t usbd_fifo_size_cdc3[] = {
|
||||
static const uint8_t usbd_fifo_size_cdc3[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, // FS: can't support 3x VCP mode
|
||||
#if MICROPY_HW_USB_HS
|
||||
82, 8, 64, 2, 32, 2, 32, 2, 32, 0,
|
||||
@@ -171,7 +171,7 @@ STATIC const uint8_t usbd_fifo_size_cdc3[] = {
|
||||
};
|
||||
|
||||
// RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD/HID, CDC2_DATA, CDC3_CMD/HID, CDC3_DATA, HID
|
||||
STATIC const uint8_t usbd_fifo_size_cdc3_msc_hid[] = {
|
||||
static const uint8_t usbd_fifo_size_cdc3_msc_hid[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, // FS: can't support 3x VCP mode
|
||||
#if MICROPY_HW_USB_HS
|
||||
82, 8, 64, 2, 25, 8, 25, 8, 25, 8,
|
||||
@@ -183,7 +183,7 @@ STATIC const uint8_t usbd_fifo_size_cdc3_msc_hid[] = {
|
||||
|
||||
#if MICROPY_HW_USB_HID
|
||||
// predefined hid mouse data
|
||||
STATIC const mp_obj_str_t pyb_usb_hid_mouse_desc_obj = {
|
||||
static const mp_obj_str_t pyb_usb_hid_mouse_desc_obj = {
|
||||
{&mp_type_bytes},
|
||||
0, // hash not valid
|
||||
USBD_HID_MOUSE_REPORT_DESC_SIZE,
|
||||
@@ -202,7 +202,7 @@ const mp_rom_obj_tuple_t pyb_usb_hid_mouse_obj = {
|
||||
};
|
||||
|
||||
// predefined hid keyboard data
|
||||
STATIC const mp_obj_str_t pyb_usb_hid_keyboard_desc_obj = {
|
||||
static const mp_obj_str_t pyb_usb_hid_keyboard_desc_obj = {
|
||||
{&mp_type_bytes},
|
||||
0, // hash not valid
|
||||
USBD_HID_KEYBOARD_REPORT_DESC_SIZE,
|
||||
@@ -423,7 +423,7 @@ typedef struct _pyb_usb_mode_table_t {
|
||||
|
||||
// These are all the modes supported by USBD_SelectMode.
|
||||
// Note: there are some names (eg CDC, VCP+VCP) which are supported for backwards compatibility.
|
||||
STATIC const pyb_usb_mode_table_t pyb_usb_mode_table[] = {
|
||||
static const pyb_usb_mode_table_t pyb_usb_mode_table[] = {
|
||||
{ USBD_MODE_CDC, MP_QSTR_VCP, "CDC", MICROPY_HW_USB_PID_CDC },
|
||||
{ USBD_MODE_MSC, MP_QSTR_MSC, NULL, MICROPY_HW_USB_PID_MSC },
|
||||
{ USBD_MODE_CDC_MSC, MP_QSTR_VCP_plus_MSC, "CDC+MSC", MICROPY_HW_USB_PID_CDC_MSC },
|
||||
@@ -443,7 +443,7 @@ STATIC const pyb_usb_mode_table_t pyb_usb_mode_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum {
|
||||
ARG_mode, ARG_port, ARG_vid, ARG_pid,
|
||||
#if MICROPY_HW_USB_MSC
|
||||
@@ -638,9 +638,9 @@ const pyb_usb_vcp_obj_t pyb_usb_vcp_obj[MICROPY_HW_USB_CDC_NUM] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC bool pyb_usb_vcp_irq_scheduled[MICROPY_HW_USB_CDC_NUM];
|
||||
static bool pyb_usb_vcp_irq_scheduled[MICROPY_HW_USB_CDC_NUM];
|
||||
|
||||
STATIC void pyb_usb_vcp_init0(void) {
|
||||
static void pyb_usb_vcp_init0(void) {
|
||||
for (size_t i = 0; i < MICROPY_HW_USB_CDC_NUM; ++i) {
|
||||
MP_STATE_PORT(pyb_usb_vcp_irq)[i] = mp_const_none;
|
||||
pyb_usb_vcp_irq_scheduled[i] = false;
|
||||
@@ -651,7 +651,7 @@ STATIC void pyb_usb_vcp_init0(void) {
|
||||
usb_vcp_attach_to_repl(&pyb_usb_vcp_obj[0], true);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_usb_vcp_irq_run(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_usb_vcp_irq_run(mp_obj_t self_in) {
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uint8_t idx = self->cdc_itf->cdc_idx;
|
||||
mp_obj_t callback = MP_STATE_PORT(pyb_usb_vcp_irq)[idx];
|
||||
@@ -661,7 +661,7 @@ STATIC mp_obj_t pyb_usb_vcp_irq_run(mp_obj_t self_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_irq_run_obj, pyb_usb_vcp_irq_run);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_irq_run_obj, pyb_usb_vcp_irq_run);
|
||||
|
||||
void usbd_cdc_rx_event_callback(usbd_cdc_itf_t *cdc) {
|
||||
uint8_t idx = cdc->cdc_idx;
|
||||
@@ -672,7 +672,7 @@ void usbd_cdc_rx_event_callback(usbd_cdc_itf_t *cdc) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
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 *)MP_OBJ_TO_PTR(self_in))->cdc_itf->cdc_idx;
|
||||
mp_printf(print, "USB_VCP(%u)", id);
|
||||
}
|
||||
@@ -689,7 +689,7 @@ void usb_vcp_attach_to_repl(const pyb_usb_vcp_obj_t *self, bool attached) {
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create a new USB_VCP object.
|
||||
STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
@@ -704,7 +704,7 @@ STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
}
|
||||
|
||||
// init(*, flow=-1)
|
||||
STATIC mp_obj_t pyb_usb_vcp_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_usb_vcp_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_flow };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_flow, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
@@ -722,29 +722,29 @@ STATIC mp_obj_t pyb_usb_vcp_init(size_t n_args, const mp_obj_t *pos_args, mp_map
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_init_obj, 1, pyb_usb_vcp_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_init_obj, 1, pyb_usb_vcp_init);
|
||||
|
||||
STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) {
|
||||
static mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) {
|
||||
mp_hal_set_interrupt_char(mp_obj_get_int(int_chr_in));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt);
|
||||
|
||||
STATIC mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) {
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return mp_obj_new_bool(usbd_cdc_is_connected(self->cdc_itf));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected);
|
||||
|
||||
// deprecated in favour of USB_VCP.isconnected
|
||||
STATIC mp_obj_t pyb_have_cdc(void) {
|
||||
static mp_obj_t pyb_have_cdc(void) {
|
||||
return pyb_usb_vcp_isconnected(MP_OBJ_FROM_PTR(&pyb_usb_vcp_obj[0]));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(pyb_have_cdc_obj, pyb_have_cdc);
|
||||
|
||||
/// \method any()
|
||||
/// Return `True` if any characters waiting, else `False`.
|
||||
STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) {
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (usbd_cdc_rx_num(self->cdc_itf) > 0) {
|
||||
return mp_const_true;
|
||||
@@ -752,7 +752,7 @@ STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) {
|
||||
return mp_const_false;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_any_obj, pyb_usb_vcp_any);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_any_obj, pyb_usb_vcp_any);
|
||||
|
||||
/// \method send(data, *, timeout=5000)
|
||||
/// Send data over the USB VCP:
|
||||
@@ -761,13 +761,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_any_obj, pyb_usb_vcp_any);
|
||||
/// - `timeout` is the timeout in milliseconds to wait for the send.
|
||||
///
|
||||
/// Return value: number of bytes sent.
|
||||
STATIC const mp_arg_t pyb_usb_vcp_send_args[] = {
|
||||
static const mp_arg_t pyb_usb_vcp_send_args[] = {
|
||||
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
|
||||
};
|
||||
#define PYB_USB_VCP_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_usb_vcp_send_args)
|
||||
|
||||
STATIC mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_arg_val_t vals[PYB_USB_VCP_SEND_NUM_ARGS];
|
||||
@@ -783,7 +783,7 @@ STATIC mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t *
|
||||
|
||||
return mp_obj_new_int(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send);
|
||||
|
||||
/// \method recv(data, *, timeout=5000)
|
||||
///
|
||||
@@ -795,7 +795,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send);
|
||||
///
|
||||
/// Return value: if `data` is an integer then a new buffer of the bytes received,
|
||||
/// otherwise the number of bytes read into `data` is returned.
|
||||
STATIC mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_arg_val_t vals[PYB_USB_VCP_SEND_NUM_ARGS];
|
||||
@@ -816,10 +816,10 @@ STATIC mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t *
|
||||
return mp_obj_new_bytes_from_vstr(&vstr); // create a new buffer
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_recv_obj, 1, pyb_usb_vcp_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_recv_obj, 1, pyb_usb_vcp_recv);
|
||||
|
||||
// irq(handler=None, trigger=IRQ_RX, hard=False)
|
||||
STATIC mp_obj_t pyb_usb_vcp_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_usb_vcp_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_rom_obj = MP_ROM_NONE} },
|
||||
@@ -856,9 +856,9 @@ STATIC mp_obj_t pyb_usb_vcp_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_irq_obj, 1, pyb_usb_vcp_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_irq_obj, 1, pyb_usb_vcp_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_usb_vcp_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setinterrupt), MP_ROM_PTR(&pyb_usb_vcp_setinterrupt_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&pyb_usb_vcp_isconnected_obj) },
|
||||
@@ -882,9 +882,9 @@ STATIC const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_IRQ_RX), MP_ROM_INT(USBD_CDC_IRQ_RX) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_usb_vcp_locals_dict, pyb_usb_vcp_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_usb_vcp_locals_dict, pyb_usb_vcp_locals_dict_table);
|
||||
|
||||
STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
int ret = usbd_cdc_rx(self->cdc_itf, (byte *)buf, size, 0);
|
||||
if (ret == 0) {
|
||||
@@ -895,7 +895,7 @@ STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, i
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
int ret = usbd_cdc_tx_flow(self->cdc_itf, (const byte *)buf, size);
|
||||
if (ret == 0) {
|
||||
@@ -906,7 +906,7 @@ 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, uintptr_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) {
|
||||
@@ -927,7 +927,7 @@ STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC const mp_stream_p_t pyb_usb_vcp_stream_p = {
|
||||
static const mp_stream_p_t pyb_usb_vcp_stream_p = {
|
||||
.read = pyb_usb_vcp_read,
|
||||
.write = pyb_usb_vcp_write,
|
||||
.ioctl = pyb_usb_vcp_ioctl,
|
||||
@@ -953,9 +953,9 @@ typedef struct _pyb_usb_hid_obj_t {
|
||||
usb_device_t *usb_dev;
|
||||
} pyb_usb_hid_obj_t;
|
||||
|
||||
STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}, &usb_device};
|
||||
static const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}, &usb_device};
|
||||
|
||||
STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -975,7 +975,7 @@ STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
///
|
||||
/// Return value: if `data` is an integer then a new buffer of the bytes received,
|
||||
/// otherwise the number of bytes read into `data` is returned.
|
||||
STATIC mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
|
||||
@@ -1006,9 +1006,9 @@ STATIC mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t *
|
||||
return mp_obj_new_bytes_from_vstr(&vstr); // create a new buffer
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_hid_recv_obj, 1, pyb_usb_hid_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_hid_recv_obj, 1, pyb_usb_hid_recv);
|
||||
|
||||
STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
|
||||
static mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
|
||||
pyb_usb_hid_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
byte temp_buf[8];
|
||||
@@ -1035,22 +1035,22 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_hid_send_obj, pyb_usb_hid_send);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_hid_send_obj, pyb_usb_hid_send);
|
||||
|
||||
// deprecated in favour of USB_HID.send
|
||||
STATIC mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
|
||||
static mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
|
||||
return pyb_usb_hid_send(MP_OBJ_FROM_PTR(&pyb_usb_hid_obj), arg);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_usb_hid_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_usb_hid_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&pyb_usb_hid_send_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&pyb_usb_hid_recv_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_usb_hid_locals_dict, 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, uintptr_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) {
|
||||
@@ -1069,7 +1069,7 @@ STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC const mp_stream_p_t pyb_usb_hid_stream_p = {
|
||||
static const mp_stream_p_t pyb_usb_hid_stream_p = {
|
||||
.ioctl = pyb_usb_hid_ioctl,
|
||||
};
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ static uint8_t usbd_cdc_connect_tx_timer;
|
||||
|
||||
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH
|
||||
static mp_sched_node_t mp_bootloader_sched_node;
|
||||
STATIC void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) {
|
||||
static void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) {
|
||||
mp_hal_delay_ms(250);
|
||||
machine_bootloader(0, NULL);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void USBD_SetVIDPIDRelease(usbd_cdc_msc_hid_state_t *usbd, uint16_t vid, uint16_
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
STATIC uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
|
||||
static uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
|
||||
uint8_t *dev_desc = ((usbd_cdc_msc_hid_state_t *)pdev->pClassData)->usbd_device_desc;
|
||||
*length = USB_LEN_DEV_DESC;
|
||||
return dev_desc;
|
||||
@@ -98,7 +98,7 @@ STATIC uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer, or NULL if idx is invalid
|
||||
*/
|
||||
STATIC uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16_t *length) {
|
||||
static uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16_t *length) {
|
||||
char str_buf[16];
|
||||
const char *str = NULL;
|
||||
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
|
||||
#define FLAGS_READONLY (0x02)
|
||||
|
||||
STATIC const void *usbd_msc_lu_data[USBD_MSC_MAX_LUN];
|
||||
STATIC uint8_t usbd_msc_lu_num;
|
||||
STATIC uint16_t usbd_msc_lu_flags;
|
||||
static const void *usbd_msc_lu_data[USBD_MSC_MAX_LUN];
|
||||
static uint8_t usbd_msc_lu_num;
|
||||
static uint16_t usbd_msc_lu_flags;
|
||||
|
||||
static inline void lu_flag_set(uint8_t lun, uint8_t flag) {
|
||||
usbd_msc_lu_flags |= flag << (lun * 2);
|
||||
@@ -75,7 +75,7 @@ const uint8_t USBD_MSC_Mode_Sense10_Data[8] = {
|
||||
0x00, 0x00, // block descriptor length
|
||||
};
|
||||
|
||||
STATIC const uint8_t usbd_msc_vpd00[6] = {
|
||||
static const uint8_t usbd_msc_vpd00[6] = {
|
||||
0x00, // peripheral qualifier; peripheral device type
|
||||
0x00, // page code
|
||||
0x00, // reserved
|
||||
@@ -84,13 +84,13 @@ STATIC const uint8_t usbd_msc_vpd00[6] = {
|
||||
0x83, // page 0x83 supported
|
||||
};
|
||||
|
||||
STATIC const uint8_t usbd_msc_vpd83[4] = {
|
||||
static const uint8_t usbd_msc_vpd83[4] = {
|
||||
0x00, // peripheral qualifier; peripheral device type
|
||||
0x83, // page code
|
||||
0x00, 0x00, // page length (additional bytes beyond this entry)
|
||||
};
|
||||
|
||||
STATIC const int8_t usbd_msc_inquiry_data[STANDARD_INQUIRY_DATA_LEN] = \
|
||||
static const int8_t usbd_msc_inquiry_data[STANDARD_INQUIRY_DATA_LEN] = \
|
||||
"\x00" // peripheral qualifier; peripheral device type
|
||||
"\x80" // 0x00 for a fixed drive, 0x80 for a removable drive
|
||||
"\x02" // version
|
||||
@@ -110,7 +110,7 @@ void usbd_msc_init_lu(size_t lu_n, const void *lu_data) {
|
||||
}
|
||||
|
||||
// Helper function to perform an ioctl on a logical unit
|
||||
STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
|
||||
static int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
|
||||
if (lun >= usbd_msc_lu_num) {
|
||||
return -1;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
|
||||
}
|
||||
|
||||
// Initialise all logical units (it's only ever called once, with lun_in=0)
|
||||
STATIC int8_t usbd_msc_Init(uint8_t lun_in) {
|
||||
static int8_t usbd_msc_Init(uint8_t lun_in) {
|
||||
if (lun_in != 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ STATIC int8_t usbd_msc_Init(uint8_t lun_in) {
|
||||
}
|
||||
|
||||
// Process SCSI INQUIRY command for the logical unit
|
||||
STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_out) {
|
||||
static int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_out) {
|
||||
if (params[1] & 1) {
|
||||
// EVPD set - return vital product data parameters
|
||||
uint8_t page_code = params[2];
|
||||
@@ -234,7 +234,7 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou
|
||||
}
|
||||
|
||||
// Get storage capacity of a logical unit
|
||||
STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) {
|
||||
static int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) {
|
||||
uint32_t block_size_u32 = 0;
|
||||
int res = lu_ioctl(lun, MP_BLOCKDEV_IOCTL_BLOCK_SIZE, &block_size_u32);
|
||||
if (res != 0) {
|
||||
@@ -245,7 +245,7 @@ STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *b
|
||||
}
|
||||
|
||||
// Check if a logical unit is ready
|
||||
STATIC int8_t usbd_msc_IsReady(uint8_t lun) {
|
||||
static int8_t usbd_msc_IsReady(uint8_t lun) {
|
||||
if (lun >= usbd_msc_lu_num) {
|
||||
return -1;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ STATIC int8_t usbd_msc_IsReady(uint8_t lun) {
|
||||
}
|
||||
|
||||
// Check if a logical unit is write protected
|
||||
STATIC int8_t usbd_msc_IsWriteProtected(uint8_t lun) {
|
||||
static int8_t usbd_msc_IsWriteProtected(uint8_t lun) {
|
||||
if (lun >= usbd_msc_lu_num) {
|
||||
return -1;
|
||||
}
|
||||
@@ -261,7 +261,7 @@ STATIC int8_t usbd_msc_IsWriteProtected(uint8_t lun) {
|
||||
}
|
||||
|
||||
// Start or stop a logical unit
|
||||
STATIC int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) {
|
||||
static int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) {
|
||||
if (lun >= usbd_msc_lu_num) {
|
||||
return -1;
|
||||
}
|
||||
@@ -274,14 +274,14 @@ STATIC int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) {
|
||||
}
|
||||
|
||||
// Prepare a logical unit for possible removal
|
||||
STATIC int8_t usbd_msc_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) {
|
||||
static int8_t usbd_msc_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) {
|
||||
uint32_t dummy;
|
||||
// Sync the logical unit so the device can be unplugged/turned off
|
||||
return lu_ioctl(lun, MP_BLOCKDEV_IOCTL_SYNC, &dummy);
|
||||
}
|
||||
|
||||
// Read data from a logical unit
|
||||
STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) {
|
||||
static int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) {
|
||||
if (lun >= usbd_msc_lu_num) {
|
||||
return -1;
|
||||
}
|
||||
@@ -305,7 +305,7 @@ STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16
|
||||
}
|
||||
|
||||
// Write data to a logical unit
|
||||
STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) {
|
||||
static int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) {
|
||||
if (lun >= usbd_msc_lu_num) {
|
||||
return -1;
|
||||
}
|
||||
@@ -329,7 +329,7 @@ STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint1
|
||||
}
|
||||
|
||||
// Get the number of attached logical units
|
||||
STATIC int8_t usbd_msc_GetMaxLun(void) {
|
||||
static int8_t usbd_msc_GetMaxLun(void) {
|
||||
return usbd_msc_lu_num - 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ typedef struct _pyb_switch_obj_t {
|
||||
mp_obj_base_t base;
|
||||
} pyb_switch_obj_t;
|
||||
|
||||
STATIC const pyb_switch_obj_t pyb_switch_obj = {{&pyb_switch_type}};
|
||||
static const pyb_switch_obj_t pyb_switch_obj = {{&pyb_switch_type}};
|
||||
|
||||
void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
mp_print_str(print, "Switch()");
|
||||
@@ -76,7 +76,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create and return a switch object.
|
||||
STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -100,15 +100,15 @@ mp_obj_t pyb_switch_value(mp_obj_t self_in) {
|
||||
(void)self_in;
|
||||
return mp_obj_new_bool(switch_get());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value);
|
||||
|
||||
STATIC mp_obj_t switch_callback(mp_obj_t line) {
|
||||
static mp_obj_t switch_callback(mp_obj_t line) {
|
||||
if (MP_STATE_PORT(pyb_switch_callback) != mp_const_none) {
|
||||
mp_call_function_0(MP_STATE_PORT(pyb_switch_callback));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(switch_callback_obj, switch_callback);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(switch_callback_obj, switch_callback);
|
||||
|
||||
/// \method callback(fun)
|
||||
/// Register the given function to be called when the switch is pressed down.
|
||||
@@ -125,14 +125,14 @@ mp_obj_t pyb_switch_callback(mp_obj_t self_in, mp_obj_t callback) {
|
||||
true);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_switch_callback_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_switch_type,
|
||||
|
||||
Reference in New Issue
Block a user