diff options
| author | Angus Gratton <angus@redyak.com.au> | 2024-02-27 15:32:29 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-03-07 14:20:42 +1100 |
| commit | decf8e6a8bb940d5829ca3296790631fcece7b21 (patch) | |
| tree | 55b7cd31de14b73e4b72d49344e9084f402767a9 /ports/stm32/led.c | |
| parent | b3f2f18f927fa2fad10daf63d8c391331f5edf58 (diff) | |
all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a433d6253a61cb0f987835fbc06b2de. 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>
Diffstat (limited to 'ports/stm32/led.c')
| -rw-r--r-- | ports/stm32/led.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/ports/stm32/led.c b/ports/stm32/led.c index 39b1f7e38..795d8c110 100644 --- a/ports/stm32/led.c +++ b/ports/stm32/led.c @@ -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, |
