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:
Angus Gratton
2024-02-27 15:32:29 +11:00
committed by Damien George
parent b3f2f18f92
commit decf8e6a8b
482 changed files with 6287 additions and 6293 deletions

View File

@@ -85,7 +85,7 @@ static uint8_t resolution[] = {
extern mp_int_t log2i(mp_int_t num);
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) {
(void)kind;
machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -94,7 +94,7 @@ STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p
self->adc_config.channel, self->bits, 1 << self->avg, self->vref);
}
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) {
enum { ARG_id, ARG_bits, ARG_average, ARG_vref };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -138,7 +138,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) {
Adc *adc = adc_bases[self->adc_config.device];
// Set the reference voltage. Default: external AREFA.
adc->REFCTRL.reg = adc_vref_table[self->vref];
@@ -156,7 +156,7 @@ STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) {
}
// deinit() : release the ADC channel
STATIC void mp_machine_adc_deinit(machine_adc_obj_t *self) {
static void mp_machine_adc_deinit(machine_adc_obj_t *self) {
busy_flags &= ~((1 << (self->adc_config.device * 16 + self->adc_config.channel)));
}

View File

@@ -44,7 +44,7 @@ typedef struct _dac_obj_t {
uint8_t vref;
} dac_obj_t;
STATIC dac_obj_t dac_obj[] = {
static dac_obj_t dac_obj[] = {
#if defined(MCU_SAMD21)
{{&machine_dac_type}, 0, PIN_PA02},
#elif defined(MCU_SAMD51)
@@ -76,7 +76,7 @@ static bool dac_init = false;
#endif
STATIC mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
static mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
const mp_obj_t *all_args) {
enum { ARG_id, ARG_vref };
@@ -150,12 +150,12 @@ STATIC mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
return MP_OBJ_FROM_PTR(self);
}
STATIC void dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
static void dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
dac_obj_t *self = self_in;
mp_printf(print, "DAC(%u, Pin=%q, vref=%d)", self->id, pin_find_by_id(self->gpio_id)->name, self->vref);
}
STATIC mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) {
static mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) {
Dac *dac = dac_bases[0]; // Just one DAC
int value = mp_obj_get_int(value_in);
if (value < 0 || value > MAX_DAC_VALUE) {
@@ -172,11 +172,11 @@ STATIC mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) {
}
MP_DEFINE_CONST_FUN_OBJ_2(dac_write_obj, dac_write);
STATIC const mp_rom_map_elem_t dac_locals_dict_table[] = {
static const mp_rom_map_elem_t dac_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&dac_write_obj) },
};
STATIC MP_DEFINE_CONST_DICT(dac_locals_dict, dac_locals_dict_table);
static MP_DEFINE_CONST_DICT(dac_locals_dict, dac_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
machine_dac_type,

View File

@@ -70,7 +70,7 @@ typedef struct _machine_i2c_obj_t {
uint8_t *buf;
} machine_i2c_obj_t;
STATIC void i2c_send_command(Sercom *i2c, uint8_t command) {
static void i2c_send_command(Sercom *i2c, uint8_t command) {
i2c->I2CM.CTRLB.bit.CMD = command;
while (i2c->I2CM.SYNCBUSY.bit.SYSOP) {
}
@@ -117,7 +117,7 @@ void common_i2c_irq_handler(int i2c_id) {
}
}
STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "I2C(%u, freq=%u, scl=%u, sda=%u)",
self->id, self->freq, self->scl, self->sda);
@@ -212,7 +212,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
return MP_OBJ_FROM_PTR(self);
}
STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) {
static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) {
machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in;
Sercom *i2c = self->instance;
@@ -260,7 +260,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
return len;
}
STATIC const mp_machine_i2c_p_t machine_i2c_p = {
static const mp_machine_i2c_p_t machine_i2c_p = {
.transfer = mp_machine_i2c_transfer_adaptor,
.transfer_single = machine_i2c_transfer_single,
};

View File

@@ -69,7 +69,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
locals_dict, &machine_pin_board_pins_locals_dict
);
STATIC const mp_irq_methods_t machine_pin_irq_methods;
static const mp_irq_methods_t machine_pin_irq_methods;
bool EIC_occured;
@@ -78,7 +78,7 @@ uint32_t machine_pin_open_drain_mask[4];
// Open drain behaviour is simulated.
#define GPIO_IS_OPEN_DRAIN(id) (machine_pin_open_drain_mask[id / 32] & (1 << (id % 32)))
STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_pin_obj_t *self = self_in;
char *mode_str;
char *pull_str[] = {"PULL_OFF", "PULL_UP", "PULL_DOWN"};
@@ -94,14 +94,14 @@ STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
pull_str[mp_hal_get_pull_mode(self->pin_id)]);
}
STATIC void pin_validate_drive(bool strength) {
static void pin_validate_drive(bool strength) {
if (strength != GPIO_STRENGTH_2MA && strength != GPIO_STRENGTH_8MA) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
}
}
// Pin.init(mode, pull=None, *, value=None, drive=0). No 'alt' yet.
STATIC mp_obj_t machine_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 machine_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) {
enum { ARG_mode, ARG_pull, ARG_value, ARG_drive, ARG_alt };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}},
@@ -193,7 +193,7 @@ mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
}
// Pin.init(mode, pull)
STATIC mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
static mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init);
@@ -202,18 +202,18 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init);
mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) {
return machine_pin_call(args[0], n_args - 1, 0, args + 1);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value);
// Pin.disable(pin)
STATIC mp_obj_t machine_pin_disable(mp_obj_t self_in) {
static mp_obj_t machine_pin_disable(mp_obj_t self_in) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
gpio_set_pin_direction(self->pin_id, GPIO_DIRECTION_OFF); // Disables the pin (low power state)
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_disable_obj, machine_pin_disable);
static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_disable_obj, machine_pin_disable);
// Pin.low() Totem-pole (push-pull)
STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) {
static mp_obj_t machine_pin_low(mp_obj_t self_in) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (GPIO_IS_OPEN_DRAIN(self->pin_id)) {
mp_hal_pin_od_low(self->pin_id);
@@ -225,7 +225,7 @@ STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low);
// Pin.high() Totem-pole (push-pull)
STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) {
static mp_obj_t machine_pin_high(mp_obj_t self_in) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (GPIO_IS_OPEN_DRAIN(self->pin_id)) {
mp_hal_pin_od_high(self->pin_id);
@@ -237,7 +237,7 @@ STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high);
// Pin.toggle(). Only TOGGLE pins set as OUTPUT.
STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) {
static mp_obj_t machine_pin_toggle(mp_obj_t self_in) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
// Determine DIRECTION of PIN.
@@ -259,7 +259,7 @@ STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle);
// Pin.drive(). Normal (0) is 2mA, High (1) allows 8mA.
STATIC mp_obj_t machine_pin_drive(size_t n_args, const mp_obj_t *args) {
static mp_obj_t machine_pin_drive(size_t n_args, const mp_obj_t *args) {
machine_pin_obj_t *self = args[0]; // Pin
if (n_args == 1) {
return mp_const_none;
@@ -274,10 +274,10 @@ STATIC mp_obj_t machine_pin_drive(size_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_drive_obj, 1, 2, machine_pin_drive);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_drive_obj, 1, 2, machine_pin_drive);
// pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False)
STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static mp_obj_t machine_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} },
@@ -375,7 +375,7 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
}
return MP_OBJ_FROM_PTR(irq);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq);
static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq);
void pin_irq_deinit_all(void) {
@@ -412,7 +412,7 @@ void EIC_Handler() {
}
}
STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
// instance methods
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) },
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) },
@@ -441,9 +441,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_IRQ_EDGE_RISE) },
{ MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_IRQ_EDGE_FALL) },
};
STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table);
static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_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 = self_in;
@@ -459,7 +459,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,
};
@@ -484,7 +484,7 @@ static uint8_t find_eic_id(int pin) {
return 0xff;
}
STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
static mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint8_t eic_id = find_eic_id(self->pin_id);
if (eic_id != 0xff) {
@@ -497,7 +497,7 @@ STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger
return 0;
}
STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
static mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint8_t eic_id = find_eic_id(self->pin_id);
if (eic_id != 0xff) {
@@ -511,7 +511,7 @@ STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
return 0;
}
STATIC const mp_irq_methods_t machine_pin_irq_methods = {
static const mp_irq_methods_t machine_pin_irq_methods = {
.trigger = machine_pin_irq_trigger,
.info = machine_pin_irq_info,
};

View File

@@ -105,21 +105,21 @@ static uint8_t device_status[TCC_INST_NUM];
static uint8_t output_active[TCC_INST_NUM];
const uint16_t prescaler_table[] = {1, 2, 4, 8, 16, 64, 256, 1024};
STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq);
STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16);
STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns);
STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self);
STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self);
static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq);
static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16);
static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns);
static void mp_machine_pwm_start(machine_pwm_obj_t *self);
static void mp_machine_pwm_stop(machine_pwm_obj_t *self);
STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "PWM(%q, device=%u, channel=%u, output=%u)",
pin_find_by_id(self->pin_id)->name, self->device, self->channel, self->output);
}
// called by the constructor and init()
STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self,
static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self,
size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device };
static const mp_arg_t allowed_args[] = {
@@ -225,7 +225,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self,
}
// PWM(pin)
STATIC mp_obj_t mp_machine_pwm_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_pwm_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, MP_OBJ_FUN_ARGS_MAX, true);
@@ -245,7 +245,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
return MP_OBJ_FROM_PTR(self);
}
STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self) {
static void mp_machine_pwm_stop(machine_pwm_obj_t *self) {
Tcc *tcc = tcc_instance[self->device];
tcc->CTRLA.bit.ENABLE = 0;
while (tcc->SYNCBUSY.reg & TCC_SYNCBUSY_ENABLE) {
@@ -271,7 +271,7 @@ void pwm_deinit_all(void) {
// switch off that device.
// This stops all channels, but keeps the configuration
// Calling pwm.freq(n), pwm.duty_x() or pwm.init() will start it again.
STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
mp_hal_clr_pin_mux(self->pin_id); // Switch the output off
output_active[self->device] &= ~(1 << self->output); // clear output flasg
// Stop the device, if no output is active.
@@ -280,7 +280,7 @@ STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
}
}
STATIC void wait_for_register_update(Tcc *tcc) {
static void wait_for_register_update(Tcc *tcc) {
// Wait for a period's end (may be long) to have the change settled
// Each loop cycle takes at least 1 ms, giving an implicit timeout.
for (int i = 0; i < PWM_UPDATE_TIMEOUT; i++) {
@@ -293,7 +293,7 @@ STATIC void wait_for_register_update(Tcc *tcc) {
tcc->INTFLAG.reg = TCC_INTFLAG_OVF;
}
STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) {
static void mp_machine_pwm_start(machine_pwm_obj_t *self) {
// Start the PWM. The period counter is 24 bit or 16 bit with a pre-scaling
// of up to 1024, allowing a range from 24 MHz down to 1 Hz.
static const uint32_t max_period[5] = {1 << 24, 1 << 24, 1 << 16, 1 << 16, 1 << 16};
@@ -357,16 +357,16 @@ STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) {
tcc->CTRLBCLR.reg = TCC_CTRLBCLR_LUPD;
}
STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) {
static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) {
return MP_OBJ_NEW_SMALL_INT(self->freq);
}
STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
self->freq = freq;
mp_machine_pwm_start(self);
}
STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
if (duty_type_flags[self->device] & (1 << self->channel)) {
return MP_OBJ_NEW_SMALL_INT(get_duty_value(self->device, self->channel));
} else {
@@ -374,13 +374,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
}
}
STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) {
static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) {
put_duty_value(self->device, self->channel, duty_u16);
duty_type_flags[self->device] |= 1 << self->channel;
mp_machine_pwm_start(self);
}
STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
if (!(duty_type_flags[self->device] & (1 << self->channel))) {
return MP_OBJ_NEW_SMALL_INT(get_duty_value(self->device, self->channel));
} else {
@@ -388,7 +388,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
}
}
STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) {
static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) {
put_duty_value(self->device, self->channel, duty_ns);
duty_type_flags[self->device] &= ~(1 << self->channel);
mp_machine_pwm_start(self);

View File

@@ -37,7 +37,7 @@ typedef struct _machine_rtc_obj_t {
} machine_rtc_obj_t;
// Singleton RTC object.
STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
// Start the RTC Timer.
void machine_rtc_start(bool force) {
@@ -85,7 +85,7 @@ void rtc_gettime(timeutils_struct_time_t *tm) {
tm->tm_sec = RTC->MODE2.CLOCK.bit.SECOND;
}
STATIC mp_obj_t machine_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 machine_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);
// RTC was already started at boot time. So nothing to do here.
@@ -93,7 +93,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
return (mp_obj_t)&machine_rtc_obj;
}
STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) {
static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) {
// Rtc *rtc = RTC;
if (n_args == 1) {
// Get date and time.
@@ -137,21 +137,21 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
}
}
STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
return machine_rtc_datetime_helper(n_args, args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
mp_obj_t args[2] = {self_in, date};
machine_rtc_datetime_helper(2, args);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);
static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);
// calibration(cal)
// When the argument is a number in the range [-16 to 15], set the calibration value.
STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) {
static mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) {
int8_t cal = 0;
// Make it negative for a "natural" behavior:
// value > 0: faster, value < 0: slower
@@ -159,14 +159,14 @@ STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) {
RTC->MODE2.FREQCORR.reg = (uint8_t)cal;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration);
static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration);
STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_rtc_init_obj) },
{ MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) },
{ MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&machine_rtc_calibration_obj) },
};
STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table);
static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
machine_rtc_type,

View File

@@ -80,13 +80,13 @@ void common_spi_irq_handler(int spi_id) {
}
}
STATIC void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
static void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "SPI(%u, baudrate=%u, firstbit=%u, polarity=%u, phase=%u, bits=8)",
self->id, self->baudrate, self->firstbit, self->polarity, self->phase);
}
STATIC void machine_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_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_firstbit,
ARG_sck, ARG_mosi, ARG_miso};
static const mp_arg_t allowed_args[] = {
@@ -231,7 +231,7 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj
}
}
STATIC mp_obj_t machine_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 machine_spi_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, 1, MP_OBJ_FUN_ARGS_MAX, true);
// Get SPI bus.
@@ -260,7 +260,7 @@ STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, s
return self;
}
STATIC void machine_sercom_deinit(mp_obj_base_t *self_in) {
static void machine_sercom_deinit(mp_obj_base_t *self_in) {
machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
Sercom *spi = sercom_instance[self->id];
// Disable interrupts (if any)
@@ -270,7 +270,7 @@ STATIC void machine_sercom_deinit(mp_obj_base_t *self_in) {
MP_STATE_PORT(sercom_table[self->id]) = NULL;
}
STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
machine_spi_obj_t *self = (machine_spi_obj_t *)self_in;
Sercom *spi = sercom_instance[self->id];
@@ -316,7 +316,7 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
}
STATIC const mp_machine_spi_p_t machine_spi_p = {
static const mp_machine_spi_p_t machine_spi_p = {
.init = machine_spi_init,
.deinit = machine_sercom_deinit,
.transfer = machine_spi_transfer,

View File

@@ -69,12 +69,12 @@ typedef struct _machine_uart_obj_t {
#endif
} machine_uart_obj_t;
STATIC const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3
static const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3
// Irq handler
// take all bytes from the fifo and store them in the buffer
STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self, Sercom *uart) {
static void uart_drain_rx_fifo(machine_uart_obj_t *self, Sercom *uart) {
while (uart->USART.INTFLAG.bit.RXC != 0) {
if (ringbuf_free(&self->read_buffer) > 0) {
// get a byte from uart and put into the buffer
@@ -114,7 +114,7 @@ void common_uart_irq_handler(int uart_id) {
}
// Configure the Sercom device
STATIC void machine_sercom_configure(machine_uart_obj_t *self) {
static void machine_sercom_configure(machine_uart_obj_t *self) {
Sercom *uart = sercom_instance[self->id];
// Reset (clear) the peripheral registers.
@@ -192,7 +192,7 @@ void machine_uart_set_baudrate(mp_obj_t self_in, uint32_t baudrate) {
machine_sercom_configure(self);
}
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);
mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, "
"timeout=%u, timeout_char=%u, rxbuf=%d"
@@ -215,7 +215,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_
);
}
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) {
enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_tx, ARG_rx,
ARG_timeout, ARG_timeout_char, ARG_rxbuf, ARG_txbuf, ARG_rts, ARG_cts };
static const mp_arg_t allowed_args[] = {
@@ -363,7 +363,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_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) {
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) {
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
// Get UART bus.
@@ -396,7 +396,7 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
return MP_OBJ_FROM_PTR(self);
}
STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) {
static void mp_machine_uart_deinit(machine_uart_obj_t *self) {
// Check if it is the active object.
if (MP_STATE_PORT(sercom_table)[self->id] == self) {
Sercom *uart = sercom_instance[self->id];
@@ -409,11 +409,11 @@ STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) {
}
}
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 ringbuf_avail(&self->read_buffer);
}
STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
static bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
Sercom *uart = sercom_instance[self->id];
return uart->USART.INTFLAG.bit.DRE
@@ -423,7 +423,7 @@ STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
&& uart->USART.INTFLAG.bit.TXC;
}
STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
uint32_t break_time_us = 13 * 1000000 / self->baudrate;
// Wait for the tx buffer to drain.
@@ -445,7 +445,7 @@ STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
mp_hal_set_pin_mux(self->tx, self->tx_pad_config.alt_fct);
}
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);
Sercom *uart = sercom_instance[self->id];
uint64_t t = mp_hal_ticks_ms_64() + self->timeout;
@@ -475,7 +475,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
return size;
}
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);
size_t i = 0;
const uint8_t *src = buf_in;
@@ -514,7 +514,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
return size;
}
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 = self_in;
mp_uint_t ret;
Sercom *uart = sercom_instance[self->id];

View File

@@ -45,9 +45,9 @@ mp_int_t log2i(mp_int_t num) {
return res;
}
STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}};
static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}};
STATIC void set_timeout(uint32_t timeout) {
static void set_timeout(uint32_t timeout) {
// Set new timeout. Have to disable WDT first.
// Confine to the valid range
@@ -76,7 +76,7 @@ STATIC void set_timeout(uint32_t timeout) {
#endif
}
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 defined(MCU_SAMD51)
// Verify the WDT id. SAMD51 only, saving a few bytes for SAMD21
if (id != 0) {
@@ -105,12 +105,12 @@ 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;
WDT->CLEAR.reg = 0xa5;
}
STATIC void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self, mp_int_t timeout_ms) {
static void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self, mp_int_t timeout_ms) {
(void)self;
set_timeout(timeout_ms);
}

View File

@@ -65,7 +65,7 @@
extern bool EIC_occured;
extern uint32_t _dbl_tap_addr;
NORETURN STATIC void mp_machine_reset(void) {
NORETURN static void mp_machine_reset(void) {
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
#ifdef DBL_TAP_ADDR_ALT
*DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_RESET;
@@ -81,28 +81,28 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
NVIC_SystemReset();
}
STATIC mp_obj_t mp_machine_get_freq(void) {
static mp_obj_t mp_machine_get_freq(void) {
return MP_OBJ_NEW_SMALL_INT(get_cpu_freq());
}
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) {
uint32_t freq = mp_obj_get_int(args[0]);
if (freq >= 1000000 && freq <= MAX_CPU_FREQ) {
set_cpu_freq(freq);
}
}
STATIC mp_obj_t mp_machine_unique_id(void) {
static mp_obj_t mp_machine_unique_id(void) {
samd_unique_id_t id;
samd_get_unique_id(&id);
return mp_obj_new_bytes((byte *)&id.bytes, sizeof(id.bytes));
}
STATIC void mp_machine_idle(void) {
static void mp_machine_idle(void) {
MICROPY_EVENT_POLL_HOOK;
}
STATIC mp_int_t mp_machine_reset_cause(void) {
static mp_int_t mp_machine_reset_cause(void) {
#if defined(MCU_SAMD21)
return PM->RCAUSE.reg;
#elif defined(MCU_SAMD51)
@@ -112,7 +112,7 @@ STATIC mp_int_t mp_machine_reset_cause(void) {
#endif
}
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) {
int32_t duration = -1;
uint32_t freq = get_cpu_freq();
if (n_args > 0) {
@@ -164,7 +164,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
set_cpu_freq(freq);
}
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
mp_machine_lightsleep(n_args, args);
mp_machine_reset();
}

View File

@@ -40,7 +40,7 @@
#if defined(MCU_SAMD51)
static bool initialized = false;
STATIC void trng_start(void) {
static void trng_start(void) {
if (!initialized) {
MCLK->APBCMASK.bit.TRNG_ = 1;
REG_TRNG_CTRLA = TRNG_CTRLA_ENABLE;
@@ -73,7 +73,7 @@ uint32_t trng_random_u32(int delay) {
#endif
#if MICROPY_PY_OS_URANDOM
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);
@@ -89,7 +89,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 // MICROPY_PY_OS_URANDOM

View File

@@ -45,7 +45,7 @@ extern const mp_obj_type_t samd_spiflash_type;
#define SPIFLASH_TYPE samd_spiflash_type
#endif
STATIC mp_obj_t samd_pininfo(mp_obj_t pin_obj) {
static mp_obj_t samd_pininfo(mp_obj_t pin_obj) {
const machine_pin_obj_t *pin_af = pin_find(pin_obj);
#if defined(MCU_SAMD21)
mp_obj_t tuple[7] = {
@@ -74,14 +74,14 @@ STATIC mp_obj_t samd_pininfo(mp_obj_t pin_obj) {
#endif
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(samd_pininfo_obj, samd_pininfo);
static MP_DEFINE_CONST_FUN_OBJ_1(samd_pininfo_obj, samd_pininfo);
STATIC const mp_rom_map_elem_t samd_module_globals_table[] = {
static const mp_rom_map_elem_t samd_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_samd) },
{ MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&SPIFLASH_TYPE) },
{ MP_ROM_QSTR(MP_QSTR_pininfo), MP_ROM_PTR(&samd_pininfo_obj) },
};
STATIC MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table);
static MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table);
const mp_obj_module_t mp_module_samd = {
.base = { &mp_type_module },

View File

@@ -29,7 +29,7 @@
#include "modmachine.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) {
timeutils_struct_time_t tm;
rtc_gettime(&tm);
tm.tm_wday = timeutils_calc_weekday(tm.tm_year, tm.tm_mon, tm.tm_mday);
@@ -48,7 +48,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) {
}
// Returns the number of seconds, as an integer, since the Epoch.
STATIC mp_obj_t mp_time_time_get(void) {
static mp_obj_t mp_time_time_get(void) {
timeutils_struct_time_t tm;
rtc_gettime(&tm);
return mp_obj_new_int_from_uint(timeutils_mktime(

View File

@@ -40,7 +40,7 @@
extern volatile uint32_t ticks_us64_upper;
STATIC uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN];
static uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN];
ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0 };
// Explicitly run the USB stack in case the scheduler is locked (eg we are in an

View File

@@ -53,7 +53,7 @@ const machine_pin_obj_t *pin_find_by_id(int pin_id) {
mp_raise_ValueError(MP_ERROR_TEXT("not a Pin"));
}
STATIC const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
static const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t *)&named_pins->map, name, MP_MAP_LOOKUP);
if (named_elem != NULL) {
return named_elem->value;

View File

@@ -45,7 +45,7 @@
#endif
static struct flash_descriptor flash_desc;
STATIC mp_int_t BLOCK_SIZE = VFS_BLOCK_SIZE_BYTES; // Board specific: mpconfigboard.h
static mp_int_t BLOCK_SIZE = VFS_BLOCK_SIZE_BYTES; // Board specific: mpconfigboard.h
extern const mp_obj_type_t samd_flash_type;
typedef struct _samd_flash_obj_t {
@@ -57,7 +57,7 @@ typedef struct _samd_flash_obj_t {
extern uint8_t _oflash_fs, _sflash_fs;
// Build a Flash storage at top.
STATIC samd_flash_obj_t samd_flash_obj = {
static samd_flash_obj_t samd_flash_obj = {
.base = { &samd_flash_type },
.flash_base = (uint32_t)&_oflash_fs, // Get from MCU-Specific loader script.
.flash_size = (uint32_t)&_sflash_fs, // Get from MCU-Specific loader script.
@@ -65,7 +65,7 @@ STATIC samd_flash_obj_t samd_flash_obj = {
// Flash init (from cctpy)
// Method is needed for when MP starts up in _boot.py
STATIC void samd_flash_init(void) {
static void samd_flash_init(void) {
#ifdef SAMD51
hri_mclk_set_AHBMASK_NVMCTRL_bit(MCLK);
#endif
@@ -76,7 +76,7 @@ STATIC void samd_flash_init(void) {
flash_init(&flash_desc, NVMCTRL);
}
STATIC mp_obj_t samd_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 samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
// No args required. bdev=Flash(). Start Addr & Size defined in samd_flash_obj.
mp_arg_check_num(n_args, n_kw, 0, 0, false);
@@ -87,7 +87,7 @@ STATIC mp_obj_t samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, si
}
// Function for ioctl.
STATIC mp_obj_t eraseblock(uint32_t sector_in) {
static mp_obj_t eraseblock(uint32_t sector_in) {
// Destination address aligned with page start to be erased.
uint32_t DEST_ADDR = sector_in; // Number of pages to be erased.
mp_int_t PAGE_SIZE = flash_get_page_size(&flash_desc); // adf4 API call
@@ -97,12 +97,12 @@ STATIC mp_obj_t eraseblock(uint32_t sector_in) {
return mp_const_none;
}
STATIC mp_obj_t samd_flash_version(void) {
static mp_obj_t samd_flash_version(void) {
return MP_OBJ_NEW_SMALL_INT(flash_get_version());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_version_obj, samd_flash_version);
static MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_version_obj, samd_flash_version);
STATIC mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) {
static mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) {
uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base;
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
@@ -115,9 +115,9 @@ STATIC mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_readblocks_obj, 3, 4, samd_flash_readblocks);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_readblocks_obj, 3, 4, samd_flash_readblocks);
STATIC mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
static mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base;
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
@@ -132,9 +132,9 @@ STATIC mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
// TODO check return value
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_writeblocks_obj, 3, 4, samd_flash_writeblocks);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_writeblocks_obj, 3, 4, samd_flash_writeblocks);
STATIC mp_obj_t samd_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
static mp_obj_t samd_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
samd_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t cmd = mp_obj_get_int(cmd_in);
@@ -159,15 +159,15 @@ STATIC mp_obj_t samd_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(samd_flash_ioctl_obj, samd_flash_ioctl);
static MP_DEFINE_CONST_FUN_OBJ_3(samd_flash_ioctl_obj, samd_flash_ioctl);
STATIC const mp_rom_map_elem_t samd_flash_locals_dict_table[] = {
static const mp_rom_map_elem_t samd_flash_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_flash_version), MP_ROM_PTR(&samd_flash_version_obj) },
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&samd_flash_readblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&samd_flash_writeblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&samd_flash_ioctl_obj) },
};
STATIC MP_DEFINE_CONST_DICT(samd_flash_locals_dict, samd_flash_locals_dict_table);
static MP_DEFINE_CONST_DICT(samd_flash_locals_dict, samd_flash_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
samd_flash_type,

View File

@@ -257,7 +257,7 @@ int get_sfdp_table(uint8_t *table, int maxlen) {
return len;
}
STATIC mp_obj_t samd_qspiflash_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 samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
// The QSPI is a singleton
@@ -374,7 +374,7 @@ STATIC mp_obj_t samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args
return self;
}
STATIC mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) {
static mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) {
if (len > 0) {
wait_for_flash_ready();
// Command 0x6B 1 line address, 4 line Data
@@ -385,7 +385,7 @@ STATIC mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, u
return mp_const_none;
}
STATIC mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) {
static mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) {
uint32_t length = len;
uint32_t pos = 0;
uint8_t *buf = src;
@@ -405,7 +405,7 @@ STATIC mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr,
return mp_const_none;
}
STATIC mp_obj_t samd_qspiflash_erase(uint32_t addr) {
static mp_obj_t samd_qspiflash_erase(uint32_t addr) {
wait_for_flash_ready();
write_enable();
erase_command(QSPI_CMD_ERASE_SECTOR, addr);
@@ -413,7 +413,7 @@ STATIC mp_obj_t samd_qspiflash_erase(uint32_t addr) {
return mp_const_none;
}
STATIC mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) {
static mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) {
samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize);
mp_buffer_info_t bufinfo;
@@ -427,9 +427,9 @@ STATIC mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_readblocks_obj, 3, 4, samd_qspiflash_readblocks);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_readblocks_obj, 3, 4, samd_qspiflash_readblocks);
STATIC mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args) {
static mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args) {
samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize);
mp_buffer_info_t bufinfo;
@@ -445,9 +445,9 @@ STATIC mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args)
// TODO check return value
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_writeblocks_obj, 3, 4, samd_qspiflash_writeblocks);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_writeblocks_obj, 3, 4, samd_qspiflash_writeblocks);
STATIC mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
static mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t cmd = mp_obj_get_int(cmd_in);
@@ -471,14 +471,14 @@ STATIC mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(samd_qspiflash_ioctl_obj, samd_qspiflash_ioctl);
static MP_DEFINE_CONST_FUN_OBJ_3(samd_qspiflash_ioctl_obj, samd_qspiflash_ioctl);
STATIC const mp_rom_map_elem_t samd_qspiflash_locals_dict_table[] = {
static const mp_rom_map_elem_t samd_qspiflash_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&samd_qspiflash_readblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&samd_qspiflash_writeblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&samd_qspiflash_ioctl_obj) },
};
STATIC MP_DEFINE_CONST_DICT(samd_qspiflash_locals_dict, samd_qspiflash_locals_dict_table);
static MP_DEFINE_CONST_DICT(samd_qspiflash_locals_dict, samd_qspiflash_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
samd_qspiflash_type,

View File

@@ -128,7 +128,7 @@ static void get_sfdp(spiflash_obj_t *self, uint32_t addr, uint8_t *buffer, int s
mp_hal_pin_write(self->cs, 1);
}
STATIC mp_obj_t spiflash_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 spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
// Set up the object
@@ -179,7 +179,7 @@ STATIC mp_obj_t spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size
return self;
}
STATIC mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) {
static mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) {
if (len > 0) {
write_addr(self, self->commands[_READ_INDEX], addr);
spi_transfer(self->spi, len, dest, dest);
@@ -189,7 +189,7 @@ STATIC mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest
return mp_const_none;
}
STATIC mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) {
static mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) {
uint32_t length = len;
uint32_t pos = 0;
uint8_t *buf = src;
@@ -211,7 +211,7 @@ STATIC mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src
return mp_const_none;
}
STATIC mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) {
static mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) {
write_enable(self);
write_addr(self, self->commands[_SECTOR_ERASE_INDEX], addr);
mp_hal_pin_write(self->cs, 1);
@@ -220,7 +220,7 @@ STATIC mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) {
return mp_const_none;
}
STATIC mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) {
static mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) {
spiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize);
mp_buffer_info_t bufinfo;
@@ -234,9 +234,9 @@ STATIC mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_readblocks_obj, 3, 4, spiflash_readblocks);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_readblocks_obj, 3, 4, spiflash_readblocks);
STATIC mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) {
static mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) {
spiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize);
mp_buffer_info_t bufinfo;
@@ -252,9 +252,9 @@ STATIC mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) {
// TODO check return value
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_writeblocks_obj, 3, 4, spiflash_writeblocks);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_writeblocks_obj, 3, 4, spiflash_writeblocks);
STATIC mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
static mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
spiflash_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t cmd = mp_obj_get_int(cmd_in);
@@ -278,14 +278,14 @@ STATIC mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_i
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(spiflash_ioctl_obj, spiflash_ioctl);
static MP_DEFINE_CONST_FUN_OBJ_3(spiflash_ioctl_obj, spiflash_ioctl);
STATIC const mp_rom_map_elem_t spiflash_locals_dict_table[] = {
static const mp_rom_map_elem_t spiflash_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&spiflash_readblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&spiflash_writeblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&spiflash_ioctl_obj) },
};
STATIC MP_DEFINE_CONST_DICT(spiflash_locals_dict, spiflash_locals_dict_table);
static MP_DEFINE_CONST_DICT(spiflash_locals_dict, spiflash_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
samd_spiflash_type,