mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
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
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user