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
@@ -35,7 +35,7 @@
|
||||
#define ADC_CHANNEL_FROM_GPIO(gpio) ((gpio) - 26)
|
||||
#define ADC_CHANNEL_TEMPSENSOR (4)
|
||||
|
||||
STATIC uint16_t adc_config_and_read_u16(uint32_t channel) {
|
||||
static uint16_t adc_config_and_read_u16(uint32_t channel) {
|
||||
adc_select_input(channel);
|
||||
uint32_t raw = adc_read();
|
||||
const uint32_t bits = 12;
|
||||
@@ -57,13 +57,13 @@ typedef struct _machine_adc_obj_t {
|
||||
#endif
|
||||
} 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);
|
||||
mp_printf(print, "<ADC channel=%u>", self->channel);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -132,7 +132,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) {
|
||||
#if MICROPY_HW_ADC_EXT_COUNT
|
||||
if (self->is_ext) {
|
||||
return machine_pin_ext_read_u16(self->channel);
|
||||
|
||||
@@ -83,12 +83,12 @@ typedef struct _machine_i2c_obj_t {
|
||||
uint32_t timeout;
|
||||
} machine_i2c_obj_t;
|
||||
|
||||
STATIC machine_i2c_obj_t machine_i2c_obj[] = {
|
||||
static machine_i2c_obj_t machine_i2c_obj[] = {
|
||||
{{&machine_i2c_type}, i2c0, 0, MICROPY_HW_I2C0_SCL, MICROPY_HW_I2C0_SDA, 0},
|
||||
{{&machine_i2c_type}, i2c1, 1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA, 0},
|
||||
};
|
||||
|
||||
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, timeout=%u)",
|
||||
self->i2c_id, self->freq, self->scl, self->sda, self->timeout);
|
||||
@@ -148,7 +148,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;
|
||||
int ret;
|
||||
bool nostop = !(flags & MP_MACHINE_I2C_FLAG_STOP);
|
||||
@@ -189,7 +189,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -97,14 +97,14 @@ typedef struct _machine_i2s_obj_t {
|
||||
// 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] = {
|
||||
{-1, -1, 0, 1, -1, -1, -1, -1 }, // Mono, 16-bits
|
||||
{ 0, 1, 2, 3, -1, -1, -1, -1 }, // Mono, 32-bits
|
||||
{-1, -1, 0, 1, -1, -1, 2, 3 }, // Stereo, 16-bits
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // Stereo, 32-bits
|
||||
};
|
||||
|
||||
STATIC const PIO pio_instances[NUM_PIOS] = {pio0, pio1};
|
||||
static const PIO pio_instances[NUM_PIOS] = {pio0, pio1};
|
||||
|
||||
// PIO program for 16-bit write
|
||||
// set(x, 14) .side(0b01)
|
||||
@@ -117,8 +117,8 @@ STATIC const PIO pio_instances[NUM_PIOS] = {pio0, pio1};
|
||||
// out(pins, 1) .side(0b10)
|
||||
// jmp(x_dec, "right_channel") .side(0b11)
|
||||
// out(pins, 1) .side(0b00)
|
||||
STATIC const uint16_t pio_instructions_write_16[] = {59438, 24577, 2113, 28673, 63534, 28673, 6213, 24577};
|
||||
STATIC const pio_program_t pio_write_16 = {
|
||||
static const uint16_t pio_instructions_write_16[] = {59438, 24577, 2113, 28673, 63534, 28673, 6213, 24577};
|
||||
static const pio_program_t pio_write_16 = {
|
||||
pio_instructions_write_16,
|
||||
sizeof(pio_instructions_write_16) / sizeof(uint16_t),
|
||||
-1
|
||||
@@ -135,8 +135,8 @@ STATIC const pio_program_t pio_write_16 = {
|
||||
// out(pins, 1) .side(0b10)
|
||||
// jmp(x_dec, "right_channel") .side(0b11)
|
||||
// out(pins, 1) .side(0b00)
|
||||
STATIC const uint16_t pio_instructions_write_32[] = {59454, 24577, 2113, 28673, 63550, 28673, 6213, 24577};
|
||||
STATIC const pio_program_t pio_write_32 = {
|
||||
static const uint16_t pio_instructions_write_32[] = {59454, 24577, 2113, 28673, 63550, 28673, 6213, 24577};
|
||||
static const pio_program_t pio_write_32 = {
|
||||
pio_instructions_write_32,
|
||||
sizeof(pio_instructions_write_32) / sizeof(uint16_t),
|
||||
-1
|
||||
@@ -153,17 +153,17 @@ STATIC const pio_program_t pio_write_32 = {
|
||||
// in_(pins, 1) .side(0b11)
|
||||
// jmp(x_dec, "right_channel") .side(0b10)
|
||||
// in_(pins, 1) .side(0b01)
|
||||
STATIC const uint16_t pio_instructions_read_32[] = {57406, 18433, 65, 22529, 61502, 22529, 4165, 18433};
|
||||
STATIC const pio_program_t pio_read_32 = {
|
||||
static const uint16_t pio_instructions_read_32[] = {57406, 18433, 65, 22529, 61502, 22529, 4165, 18433};
|
||||
static const pio_program_t pio_read_32 = {
|
||||
pio_instructions_read_32,
|
||||
sizeof(pio_instructions_read_32) / sizeof(uint16_t),
|
||||
-1
|
||||
};
|
||||
|
||||
STATIC uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits);
|
||||
STATIC void dma_irq0_handler(void);
|
||||
STATIC void dma_irq1_handler(void);
|
||||
STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in);
|
||||
static uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits);
|
||||
static void dma_irq0_handler(void);
|
||||
static void dma_irq1_handler(void);
|
||||
static mp_obj_t machine_i2s_deinit(mp_obj_t self_in);
|
||||
|
||||
void machine_i2s_init0(void) {
|
||||
for (uint8_t i = 0; i < MAX_I2S_RP2; i++) {
|
||||
@@ -171,7 +171,7 @@ void machine_i2s_init0(void) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -188,7 +188,7 @@ STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) {
|
||||
}
|
||||
|
||||
// function is used in IRQ context
|
||||
STATIC void empty_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
static void empty_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
// when space exists, copy samples into ring buffer
|
||||
if (ringbuf_available_space(&self->ring_buffer) >= SIZEOF_HALF_DMA_BUFFER_IN_BYTES) {
|
||||
for (uint32_t i = 0; i < SIZEOF_HALF_DMA_BUFFER_IN_BYTES; i++) {
|
||||
@@ -198,7 +198,7 @@ STATIC void empty_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
}
|
||||
|
||||
// function is used in IRQ context
|
||||
STATIC void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
static void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
// when data exists, copy samples from ring buffer
|
||||
if (ringbuf_available_data(&self->ring_buffer) >= SIZEOF_HALF_DMA_BUFFER_IN_BYTES) {
|
||||
|
||||
@@ -230,7 +230,7 @@ STATIC void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void irq_configure(machine_i2s_obj_t *self) {
|
||||
static void irq_configure(machine_i2s_obj_t *self) {
|
||||
if (self->i2s_id == 0) {
|
||||
irq_add_shared_handler(DMA_IRQ_0, dma_irq0_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
|
||||
irq_set_enabled(DMA_IRQ_0, true);
|
||||
@@ -240,7 +240,7 @@ STATIC void irq_configure(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void irq_deinit(machine_i2s_obj_t *self) {
|
||||
static void irq_deinit(machine_i2s_obj_t *self) {
|
||||
if (self->i2s_id == 0) {
|
||||
irq_remove_handler(DMA_IRQ_0, dma_irq0_handler);
|
||||
} else {
|
||||
@@ -248,7 +248,7 @@ STATIC void irq_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pio_configure(machine_i2s_obj_t *self) {
|
||||
static void pio_configure(machine_i2s_obj_t *self) {
|
||||
if (self->mode == TX) {
|
||||
if (self->bits == 16) {
|
||||
self->pio_program = &pio_write_16;
|
||||
@@ -322,7 +322,7 @@ STATIC void pio_configure(machine_i2s_obj_t *self) {
|
||||
pio_sm_set_config(self->pio, self->sm, &config);
|
||||
}
|
||||
|
||||
STATIC void pio_deinit(machine_i2s_obj_t *self) {
|
||||
static void pio_deinit(machine_i2s_obj_t *self) {
|
||||
if (self->pio) {
|
||||
pio_sm_set_enabled(self->pio, self->sm, false);
|
||||
pio_sm_unclaim(self->pio, self->sm);
|
||||
@@ -330,14 +330,14 @@ STATIC void pio_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void gpio_init_i2s(PIO pio, uint8_t sm, mp_hal_pin_obj_t pin_num, uint8_t pin_val, gpio_dir_t pin_dir) {
|
||||
static void gpio_init_i2s(PIO pio, uint8_t sm, mp_hal_pin_obj_t pin_num, uint8_t pin_val, gpio_dir_t pin_dir) {
|
||||
uint32_t pinmask = 1 << pin_num;
|
||||
pio_sm_set_pins_with_mask(pio, sm, pin_val << pin_num, pinmask);
|
||||
pio_sm_set_pindirs_with_mask(pio, sm, pin_dir << pin_num, pinmask);
|
||||
pio_gpio_init(pio, pin_num);
|
||||
}
|
||||
|
||||
STATIC void gpio_configure(machine_i2s_obj_t *self) {
|
||||
static void gpio_configure(machine_i2s_obj_t *self) {
|
||||
gpio_init_i2s(self->pio, self->sm, self->sck, 0, GP_OUTPUT);
|
||||
gpio_init_i2s(self->pio, self->sm, self->ws, 0, GP_OUTPUT);
|
||||
if (self->mode == TX) {
|
||||
@@ -347,7 +347,7 @@ STATIC void gpio_configure(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits) {
|
||||
static uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits) {
|
||||
if (mode == TX) {
|
||||
return bits;
|
||||
} else { // RX
|
||||
@@ -357,7 +357,7 @@ STATIC uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits) {
|
||||
}
|
||||
|
||||
// determine which DMA channel is associated to this IRQ
|
||||
STATIC uint dma_map_irq_to_channel(uint irq_index) {
|
||||
static uint dma_map_irq_to_channel(uint irq_index) {
|
||||
for (uint ch = 0; ch < NUM_DMA_CHANNELS; ch++) {
|
||||
if ((dma_irqn_get_channel_status(irq_index, ch))) {
|
||||
return ch;
|
||||
@@ -368,7 +368,7 @@ STATIC uint dma_map_irq_to_channel(uint irq_index) {
|
||||
}
|
||||
|
||||
// note: first DMA channel is mapped to the top half of buffer, second is mapped to the bottom half
|
||||
STATIC uint8_t *dma_get_buffer(machine_i2s_obj_t *i2s_obj, uint channel) {
|
||||
static uint8_t *dma_get_buffer(machine_i2s_obj_t *i2s_obj, uint channel) {
|
||||
for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) {
|
||||
if (i2s_obj->dma_channel[ch] == channel) {
|
||||
return i2s_obj->dma_buffer + (SIZEOF_HALF_DMA_BUFFER_IN_BYTES * ch);
|
||||
@@ -378,7 +378,7 @@ STATIC uint8_t *dma_get_buffer(machine_i2s_obj_t *i2s_obj, uint channel) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC void dma_configure(machine_i2s_obj_t *self) {
|
||||
static void dma_configure(machine_i2s_obj_t *self) {
|
||||
uint8_t num_free_dma_channels = 0;
|
||||
for (uint8_t ch = 0; ch < NUM_DMA_CHANNELS; ch++) {
|
||||
if (!dma_channel_is_claimed(ch)) {
|
||||
@@ -433,7 +433,7 @@ STATIC void dma_configure(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void dma_deinit(machine_i2s_obj_t *self) {
|
||||
static void dma_deinit(machine_i2s_obj_t *self) {
|
||||
for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) {
|
||||
int channel = self->dma_channel[ch];
|
||||
|
||||
@@ -448,7 +448,7 @@ STATIC void dma_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void dma_irq_handler(uint8_t irq_index) {
|
||||
static void dma_irq_handler(uint8_t irq_index) {
|
||||
int dma_channel = dma_map_irq_to_channel(irq_index);
|
||||
if (dma_channel == -1) {
|
||||
// This should never happen
|
||||
@@ -488,15 +488,15 @@ STATIC void dma_irq_handler(uint8_t irq_index) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void dma_irq0_handler(void) {
|
||||
static void dma_irq0_handler(void) {
|
||||
dma_irq_handler(0);
|
||||
}
|
||||
|
||||
STATIC void dma_irq1_handler(void) {
|
||||
static void dma_irq1_handler(void) {
|
||||
dma_irq_handler(1);
|
||||
}
|
||||
|
||||
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) {
|
||||
// are Pins valid?
|
||||
mp_hal_pin_obj_t sck = args[ARG_sck].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_sck].u_obj);
|
||||
mp_hal_pin_obj_t ws = args[ARG_ws].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_ws].u_obj);
|
||||
@@ -563,7 +563,7 @@ STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar
|
||||
dma_channel_start(self->dma_channel[0]);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (i2s_id >= MAX_I2S_RP2) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid id"));
|
||||
}
|
||||
@@ -581,7 +581,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) {
|
||||
// use self->pio as in indication that I2S object has already been de-initialized
|
||||
if (self->pio != NULL) {
|
||||
pio_deinit(self);
|
||||
@@ -592,7 +592,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,21 +85,21 @@ typedef struct _machine_pin_irq_obj_t {
|
||||
uint32_t trigger;
|
||||
} machine_pin_irq_obj_t;
|
||||
|
||||
STATIC const mp_irq_methods_t machine_pin_irq_methods;
|
||||
static const mp_irq_methods_t machine_pin_irq_methods;
|
||||
extern const machine_pin_obj_t machine_pin_obj_table[NUM_BANK0_GPIOS];
|
||||
|
||||
// Mask with "1" indicating that the corresponding pin is in simulated open-drain mode.
|
||||
uint32_t machine_pin_open_drain_mask;
|
||||
|
||||
#if MICROPY_HW_PIN_EXT_COUNT
|
||||
STATIC inline bool is_ext_pin(__unused const machine_pin_obj_t *self) {
|
||||
static inline bool is_ext_pin(__unused const machine_pin_obj_t *self) {
|
||||
return self->is_ext;
|
||||
}
|
||||
#else
|
||||
#define is_ext_pin(x) false
|
||||
#endif
|
||||
|
||||
STATIC void gpio_irq(void) {
|
||||
static void gpio_irq(void) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
uint32_t intr = iobank0_hw->intr[i];
|
||||
if (intr) {
|
||||
@@ -196,7 +196,7 @@ const machine_pin_obj_t *machine_pin_find(mp_obj_t pin) {
|
||||
mp_raise_ValueError("invalid pin");
|
||||
}
|
||||
|
||||
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;
|
||||
uint funcsel = GPIO_GET_FUNCSEL(self->id);
|
||||
qstr mode_qst;
|
||||
@@ -252,7 +252,7 @@ static const mp_arg_t allowed_args[] = {
|
||||
{MP_QSTR_alt, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = GPIO_FUNC_SIO}},
|
||||
};
|
||||
|
||||
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) {
|
||||
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
@@ -329,7 +329,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 machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t machine_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 = self_in;
|
||||
if (n_args == 0) {
|
||||
@@ -359,19 +359,19 @@ STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// pin.value([value])
|
||||
STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) {
|
||||
static 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.low()
|
||||
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 (is_ext_pin(self)) {
|
||||
#if MICROPY_HW_PIN_EXT_COUNT
|
||||
@@ -384,10 +384,10 @@ STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low);
|
||||
|
||||
// pin.high()
|
||||
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 (is_ext_pin(self)) {
|
||||
#if MICROPY_HW_PIN_EXT_COUNT
|
||||
@@ -401,10 +401,10 @@ STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high);
|
||||
|
||||
// pin.toggle()
|
||||
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);
|
||||
if (is_ext_pin(self)) {
|
||||
#if MICROPY_HW_PIN_EXT_COUNT
|
||||
@@ -421,9 +421,9 @@ STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle);
|
||||
|
||||
STATIC machine_pin_irq_obj_t *machine_pin_get_irq(mp_hal_pin_obj_t pin) {
|
||||
static machine_pin_irq_obj_t *machine_pin_get_irq(mp_hal_pin_obj_t pin) {
|
||||
// Get the IRQ object.
|
||||
machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_obj[pin]);
|
||||
|
||||
@@ -459,7 +459,7 @@ void mp_hal_pin_interrupt(mp_hal_pin_obj_t pin, mp_obj_t handler, mp_uint_t trig
|
||||
}
|
||||
|
||||
// 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} },
|
||||
@@ -485,9 +485,9 @@ 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);
|
||||
|
||||
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) },
|
||||
@@ -523,9 +523,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_ALT_GPCK), MP_ROM_INT(GPIO_FUNC_GPCK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ALT_USB), MP_ROM_INT(GPIO_FUNC_USB) },
|
||||
};
|
||||
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;
|
||||
|
||||
@@ -553,7 +553,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,
|
||||
};
|
||||
|
||||
@@ -568,7 +568,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &machine_pin_locals_dict
|
||||
);
|
||||
|
||||
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);
|
||||
machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_obj[self->id]);
|
||||
gpio_set_irq_enabled(self->id, GPIO_IRQ_ALL, false);
|
||||
@@ -578,7 +578,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);
|
||||
machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_obj[self->id]);
|
||||
if (info_type == MP_IRQ_INFO_FLAGS) {
|
||||
@@ -589,7 +589,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,
|
||||
};
|
||||
|
||||
@@ -50,7 +50,7 @@ enum {
|
||||
DUTY_NS
|
||||
};
|
||||
|
||||
STATIC machine_pwm_obj_t machine_pwm_obj[] = {
|
||||
static machine_pwm_obj_t machine_pwm_obj[] = {
|
||||
{{&machine_pwm_type}, 0, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 },
|
||||
{{&machine_pwm_type}, 0, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 },
|
||||
{{&machine_pwm_type}, 1, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 },
|
||||
@@ -69,14 +69,14 @@ STATIC machine_pwm_obj_t machine_pwm_obj[] = {
|
||||
{{&machine_pwm_type}, 7, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 },
|
||||
};
|
||||
|
||||
STATIC bool defer_start;
|
||||
STATIC bool slice_freq_set[8];
|
||||
static bool defer_start;
|
||||
static bool slice_freq_set[8];
|
||||
|
||||
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_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_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 slice=%u channel=%u invert=%u>",
|
||||
self->slice, self->channel, self->invert);
|
||||
@@ -94,7 +94,7 @@ void machine_pwm_start(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -128,7 +128,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self,
|
||||
}
|
||||
|
||||
// PWM(pin [, 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 *all_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 *all_args) {
|
||||
// Check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -161,7 +161,7 @@ void machine_pwm_deinit_all(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
|
||||
static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
|
||||
pwm_set_enabled(self->slice, false);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ uint32_t get_slice_hz_ceil(uint32_t div16) {
|
||||
return get_slice_hz(div16 - 1, div16);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (slice_freq_set[self->slice] == true) {
|
||||
uint32_t div16 = pwm_hw->slice[self->slice].div;
|
||||
uint32_t top = pwm_hw->slice[self->slice].top;
|
||||
@@ -199,7 +199,7 @@ STATIC mp_obj_t mp_machine_pwm_freq_get(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_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
// Set the frequency, making "top" as large as possible for maximum resolution.
|
||||
// Maximum "top" is set at 65534 to be able to achieve 100% duty with 65535.
|
||||
#define TOP_MAX 65534
|
||||
@@ -248,7 +248,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
}
|
||||
}
|
||||
|
||||
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 (self->duty_type != DUTY_NOT_SET && slice_freq_set[self->slice] == true) {
|
||||
uint32_t top = pwm_hw->slice[self->slice].top;
|
||||
uint32_t cc = pwm_hw->slice[self->slice].cc;
|
||||
@@ -262,7 +262,7 @@ 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) {
|
||||
uint32_t top = pwm_hw->slice[self->slice].top;
|
||||
|
||||
// Limit duty_u16 to 65535
|
||||
@@ -277,7 +277,7 @@ STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u
|
||||
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 (self->duty_type != DUTY_NOT_SET && slice_freq_set[self->slice] == true) {
|
||||
uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div);
|
||||
uint32_t cc = pwm_hw->slice[self->slice].cc;
|
||||
@@ -288,7 +288,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) {
|
||||
uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div);
|
||||
uint32_t cc = ((uint64_t)duty_ns * slice_hz + 500000000ULL) / 1000000000ULL;
|
||||
uint32_t top = pwm_hw->slice[self->slice].top;
|
||||
|
||||
@@ -45,9 +45,9 @@ 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}};
|
||||
|
||||
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);
|
||||
bool r = rtc_running();
|
||||
@@ -64,7 +64,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(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) {
|
||||
if (n_args == 1) {
|
||||
bool ret;
|
||||
datetime_t t;
|
||||
@@ -110,12 +110,12 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
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 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_datetime), MP_ROM_PTR(&machine_rtc_datetime_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,
|
||||
|
||||
@@ -103,7 +103,7 @@ typedef struct _machine_spi_obj_t {
|
||||
uint32_t baudrate;
|
||||
} machine_spi_obj_t;
|
||||
|
||||
STATIC machine_spi_obj_t machine_spi_obj[] = {
|
||||
static machine_spi_obj_t machine_spi_obj[] = {
|
||||
{
|
||||
{&machine_spi_type}, spi0, 0,
|
||||
DEFAULT_SPI_POLARITY, DEFAULT_SPI_PHASE, DEFAULT_SPI_BITS, DEFAULT_SPI_FIRSTBIT,
|
||||
@@ -118,7 +118,7 @@ STATIC machine_spi_obj_t machine_spi_obj[] = {
|
||||
},
|
||||
};
|
||||
|
||||
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, polarity=%u, phase=%u, bits=%u, sck=%u, mosi=%u, miso=%u)",
|
||||
self->spi_id, self->baudrate, self->polarity, self->phase, self->bits,
|
||||
@@ -197,7 +197,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
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_bits, ARG_firstbit };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
@@ -242,7 +242,7 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
// Use DMA for large transfers if channels are available
|
||||
const size_t dma_min_size_threshold = 32;
|
||||
@@ -304,7 +304,7 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
|
||||
|
||||
// Buffer protocol implementation for SPI.
|
||||
// The buffer represents the SPI data FIFO.
|
||||
STATIC mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
static mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
machine_spi_obj_t *self = MP_OBJ_TO_PTR(o_in);
|
||||
|
||||
bufinfo->len = 4;
|
||||
@@ -314,7 +314,7 @@ STATIC mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo,
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC const mp_machine_spi_p_t machine_spi_p = {
|
||||
static const mp_machine_spi_p_t machine_spi_p = {
|
||||
.init = machine_spi_init,
|
||||
.transfer = machine_spi_transfer,
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct _machine_timer_obj_t {
|
||||
|
||||
const mp_obj_type_t machine_timer_type;
|
||||
|
||||
STATIC int64_t alarm_callback(alarm_id_t id, void *user_data) {
|
||||
static int64_t alarm_callback(alarm_id_t id, void *user_data) {
|
||||
machine_timer_obj_t *self = user_data;
|
||||
mp_sched_schedule(self->callback, MP_OBJ_FROM_PTR(self));
|
||||
if (self->mode == TIMER_MODE_ONE_SHOT) {
|
||||
@@ -54,7 +54,7 @@ STATIC int64_t alarm_callback(alarm_id_t id, void *user_data) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
qstr mode = self->mode == TIMER_MODE_ONE_SHOT ? MP_QSTR_ONE_SHOT : MP_QSTR_PERIODIC;
|
||||
mp_printf(print, "Timer(mode=%q, tick_hz=1000000, period=", mode);
|
||||
@@ -65,7 +65,7 @@ STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIMER_MODE_PERIODIC} },
|
||||
@@ -104,7 +104,7 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_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 machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
machine_timer_obj_t *self = mp_obj_malloc_with_finaliser(machine_timer_obj_t, &machine_timer_type);
|
||||
self->pool = alarm_pool_get_default();
|
||||
self->alarm_id = ALARM_ID_INVALID;
|
||||
@@ -130,7 +130,7 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
machine_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (self->alarm_id != ALARM_ID_INVALID) {
|
||||
alarm_pool_cancel_alarm(self->pool, self->alarm_id);
|
||||
@@ -138,9 +138,9 @@ STATIC mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t
|
||||
}
|
||||
return machine_timer_init_helper(self, n_args - 1, args + 1, kw_args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init);
|
||||
|
||||
STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
|
||||
machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->alarm_id != ALARM_ID_INVALID) {
|
||||
alarm_pool_cancel_alarm(self->pool, self->alarm_id);
|
||||
@@ -148,9 +148,9 @@ STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit);
|
||||
|
||||
STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t machine_timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&machine_timer_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_timer_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_timer_deinit_obj) },
|
||||
@@ -158,7 +158,7 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(TIMER_MODE_ONE_SHOT) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(TIMER_MODE_PERIODIC) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
machine_timer_type,
|
||||
|
||||
@@ -81,10 +81,10 @@
|
||||
#define UART_HWCONTROL_CTS (1)
|
||||
#define UART_HWCONTROL_RTS (2)
|
||||
|
||||
STATIC mutex_t write_mutex_0;
|
||||
STATIC mutex_t write_mutex_1;
|
||||
STATIC mutex_t read_mutex_0;
|
||||
STATIC mutex_t read_mutex_1;
|
||||
static mutex_t write_mutex_0;
|
||||
static mutex_t write_mutex_1;
|
||||
static mutex_t read_mutex_0;
|
||||
static mutex_t read_mutex_1;
|
||||
|
||||
auto_init_mutex(write_mutex_0);
|
||||
auto_init_mutex(write_mutex_1);
|
||||
@@ -113,7 +113,7 @@ typedef struct _machine_uart_obj_t {
|
||||
mutex_t *write_mutex;
|
||||
} machine_uart_obj_t;
|
||||
|
||||
STATIC machine_uart_obj_t machine_uart_obj[] = {
|
||||
static machine_uart_obj_t machine_uart_obj[] = {
|
||||
{{&machine_uart_type}, uart0, 0, 0, DEFAULT_UART_BITS, UART_PARITY_NONE, DEFAULT_UART_STOP,
|
||||
MICROPY_HW_UART0_TX, MICROPY_HW_UART0_RX, MICROPY_HW_UART0_CTS, MICROPY_HW_UART0_RTS,
|
||||
0, 0, 0, 0, {NULL, 1, 0, 0}, &read_mutex_0, {NULL, 1, 0, 0}, &write_mutex_0},
|
||||
@@ -122,8 +122,8 @@ STATIC machine_uart_obj_t machine_uart_obj[] = {
|
||||
0, 0, 0, 0, {NULL, 1, 0, 0}, &read_mutex_1, {NULL, 1, 0, 0}, &write_mutex_1},
|
||||
};
|
||||
|
||||
STATIC const char *_parity_name[] = {"None", "0", "1"};
|
||||
STATIC const char *_invert_name[] = {"None", "INV_TX", "INV_RX", "INV_TX|INV_RX"};
|
||||
static const char *_parity_name[] = {"None", "0", "1"};
|
||||
static const char *_invert_name[] = {"None", "INV_TX", "INV_RX", "INV_TX|INV_RX"};
|
||||
|
||||
/******************************************************************************/
|
||||
// IRQ and buffer handling
|
||||
@@ -145,7 +145,7 @@ static inline void read_mutex_unlock(machine_uart_obj_t *u) {
|
||||
}
|
||||
|
||||
// take all bytes from the fifo and store them in the buffer
|
||||
STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self) {
|
||||
static void uart_drain_rx_fifo(machine_uart_obj_t *self) {
|
||||
if (read_mutex_try_lock(self)) {
|
||||
while (uart_is_readable(self->uart) && ringbuf_free(&self->read_buffer) > 0) {
|
||||
// Get a byte from uart and put into the buffer. Every entry from
|
||||
@@ -176,7 +176,7 @@ STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self) {
|
||||
|
||||
// take bytes from the buffer and put them into the UART FIFO
|
||||
// Re-entrancy: quit if an instance already running
|
||||
STATIC void uart_fill_tx_fifo(machine_uart_obj_t *self) {
|
||||
static void uart_fill_tx_fifo(machine_uart_obj_t *self) {
|
||||
if (write_mutex_try_lock(self)) {
|
||||
while (uart_is_writable(self->uart) && ringbuf_avail(&self->write_buffer) > 0) {
|
||||
// get a byte from the buffer and put it into the uart
|
||||
@@ -186,7 +186,7 @@ STATIC void uart_fill_tx_fifo(machine_uart_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC inline void uart_service_interrupt(machine_uart_obj_t *self) {
|
||||
static inline void uart_service_interrupt(machine_uart_obj_t *self) {
|
||||
if (uart_get_hw(self->uart)->mis & (UART_UARTMIS_RXMIS_BITS | UART_UARTMIS_RTMIS_BITS)) { // rx interrupt?
|
||||
// clear all interrupt bits but tx
|
||||
uart_get_hw(self->uart)->icr = UART_UARTICR_BITS & (~UART_UARTICR_TXIC_BITS);
|
||||
@@ -199,11 +199,11 @@ STATIC inline void uart_service_interrupt(machine_uart_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void uart0_irq_handler(void) {
|
||||
static void uart0_irq_handler(void) {
|
||||
uart_service_interrupt(&machine_uart_obj[0]);
|
||||
}
|
||||
|
||||
STATIC void uart1_irq_handler(void) {
|
||||
static void uart1_irq_handler(void) {
|
||||
uart_service_interrupt(&machine_uart_obj[1]);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ STATIC void uart1_irq_handler(void) {
|
||||
{ MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HWCONTROL_RTS) }, \
|
||||
|
||||
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, tx=%d, rx=%d, "
|
||||
"txbuf=%d, rxbuf=%d, timeout=%u, timeout_char=%u, invert=%s)",
|
||||
@@ -225,7 +225,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_
|
||||
self->timeout, self->timeout_char, _invert_name[self->invert]);
|
||||
}
|
||||
|
||||
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_cts, ARG_rts,
|
||||
ARG_timeout, ARG_timeout_char, ARG_invert, ARG_flow, ARG_txbuf, ARG_rxbuf};
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@@ -411,7 +411,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.
|
||||
@@ -431,7 +431,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) {
|
||||
uart_deinit(self->uart);
|
||||
if (self->uart_id == 0) {
|
||||
irq_set_enabled(UART0_IRQ, false);
|
||||
@@ -443,24 +443,24 @@ STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) {
|
||||
MP_STATE_PORT(rp2_uart_tx_buffer[self->uart_id]) = NULL;
|
||||
}
|
||||
|
||||
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) {
|
||||
// get all bytes from the fifo first
|
||||
uart_drain_rx_fifo(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) {
|
||||
return ringbuf_avail(&self->write_buffer) == 0
|
||||
&& (uart_get_hw(self->uart)->fr & UART_UARTFR_TXFE_BITS);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
|
||||
static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
|
||||
uart_set_break(self->uart, true);
|
||||
mp_hal_delay_us(13000000 / self->baudrate + 1);
|
||||
uart_set_break(self->uart, false);
|
||||
}
|
||||
|
||||
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);
|
||||
mp_uint_t start = mp_hal_ticks_ms();
|
||||
mp_uint_t timeout = self->timeout;
|
||||
@@ -492,7 +492,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);
|
||||
mp_uint_t start = mp_hal_ticks_ms();
|
||||
mp_uint_t timeout = self->timeout;
|
||||
@@ -534,7 +534,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;
|
||||
if (request == MP_STREAM_POLL) {
|
||||
|
||||
@@ -36,9 +36,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) {
|
||||
// Verify the WDT id.
|
||||
if (id != 0) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("WDT(%d) doesn't exist"), id);
|
||||
@@ -54,7 +54,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;
|
||||
watchdog_update();
|
||||
}
|
||||
|
||||
@@ -55,20 +55,20 @@
|
||||
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(RP2_RESET_PWRON) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(RP2_RESET_WDT) }, \
|
||||
|
||||
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||
static mp_obj_t mp_machine_unique_id(void) {
|
||||
pico_unique_board_id_t id;
|
||||
pico_get_unique_board_id(&id);
|
||||
return mp_obj_new_bytes(id.id, sizeof(id.id));
|
||||
}
|
||||
|
||||
NORETURN STATIC void mp_machine_reset(void) {
|
||||
NORETURN static void mp_machine_reset(void) {
|
||||
watchdog_reboot(0, SRAM_END, 0);
|
||||
for (;;) {
|
||||
__wfi();
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||
static mp_int_t mp_machine_reset_cause(void) {
|
||||
int reset_cause;
|
||||
if (watchdog_caused_reboot()) {
|
||||
reset_cause = RP2_RESET_WDT;
|
||||
@@ -86,11 +86,11 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
static mp_obj_t mp_machine_get_freq(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(mp_hal_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) {
|
||||
mp_int_t freq = mp_obj_get_int(args[0]);
|
||||
if (!set_sys_clock_khz(freq / 1000, false)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("cannot change frequency"));
|
||||
@@ -101,11 +101,11 @@ STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void mp_machine_idle(void) {
|
||||
static void mp_machine_idle(void) {
|
||||
__wfe();
|
||||
}
|
||||
|
||||
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) {
|
||||
mp_int_t delay_ms = 0;
|
||||
bool use_timer_alarm = false;
|
||||
|
||||
@@ -189,7 +189,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
restore_interrupts(my_interrupts);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
uint8_t rosc_random_u8(size_t cycles);
|
||||
|
||||
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);
|
||||
@@ -37,4 +37,4 @@ 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);
|
||||
|
||||
@@ -44,7 +44,7 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj);
|
||||
|
||||
// Improved version of
|
||||
// https://github.com/raspberrypi/pico-examples/blob/master/picoboard/button/button.c
|
||||
STATIC bool __no_inline_not_in_flash_func(bootsel_button)(void) {
|
||||
static bool __no_inline_not_in_flash_func(bootsel_button)(void) {
|
||||
const uint CS_PIN_INDEX = 1;
|
||||
|
||||
// Disable interrupts and the other core since they might be
|
||||
@@ -77,13 +77,13 @@ STATIC bool __no_inline_not_in_flash_func(bootsel_button)(void) {
|
||||
return button_state;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t rp2_bootsel_button(void) {
|
||||
static mp_obj_t rp2_bootsel_button(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(bootsel_button());
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(rp2_bootsel_button_obj, rp2_bootsel_button);
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t rp2_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t rp2_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_rp2) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&rp2_flash_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PIO), MP_ROM_PTR(&rp2_pio_type) },
|
||||
@@ -96,7 +96,7 @@ STATIC const mp_rom_map_elem_t rp2_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) },
|
||||
#endif
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(rp2_module_globals, rp2_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(rp2_module_globals, rp2_module_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_rp2 = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "hardware/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) {
|
||||
datetime_t t;
|
||||
rtc_get_datetime(&t);
|
||||
mp_obj_t tuple[8] = {
|
||||
@@ -46,7 +46,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) {
|
||||
}
|
||||
|
||||
// Return the number of seconds since the Epoch.
|
||||
STATIC mp_obj_t mp_time_time_get(void) {
|
||||
static mp_obj_t mp_time_time_get(void) {
|
||||
datetime_t t;
|
||||
rtc_get_datetime(&t);
|
||||
return mp_obj_new_int_from_ull(timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec));
|
||||
|
||||
@@ -65,7 +65,7 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
|
||||
|
||||
// For synchronous mode, we run all BLE stack code inside a scheduled task.
|
||||
// This task is scheduled periodically via a timer, or immediately after UART RX IRQ.
|
||||
STATIC void run_events_scheduled_task(mp_sched_node_t *node) {
|
||||
static void run_events_scheduled_task(mp_sched_node_t *node) {
|
||||
(void)node;
|
||||
// This will process all buffered HCI UART data, and run any callouts or events.
|
||||
mp_bluetooth_hci_poll();
|
||||
@@ -81,7 +81,7 @@ void mp_bluetooth_hci_poll_now(void) {
|
||||
|
||||
mp_obj_t mp_bthci_uart;
|
||||
|
||||
STATIC void mp_bluetooth_hci_start_polling(void) {
|
||||
static void mp_bluetooth_hci_start_polling(void) {
|
||||
mp_bluetooth_hci_poll_now();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
// This needs to be added to the result of time_us_64() to get the number of
|
||||
// microseconds since the Epoch.
|
||||
STATIC uint64_t time_us_64_offset_from_epoch;
|
||||
static uint64_t time_us_64_offset_from_epoch;
|
||||
|
||||
static alarm_id_t soft_timer_alarm_id = 0;
|
||||
|
||||
@@ -54,7 +54,7 @@ static alarm_id_t soft_timer_alarm_id = 0;
|
||||
#define MICROPY_HW_STDIN_BUFFER_LEN 512
|
||||
#endif
|
||||
|
||||
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) };
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,14 +39,14 @@ extern uint8_t __StackTop, __StackBottom;
|
||||
void *core_state[2];
|
||||
|
||||
// This will be non-NULL while Python code is executing.
|
||||
STATIC void *(*core1_entry)(void *) = NULL;
|
||||
static void *(*core1_entry)(void *) = NULL;
|
||||
|
||||
STATIC void *core1_arg = NULL;
|
||||
STATIC uint32_t *core1_stack = NULL;
|
||||
STATIC size_t core1_stack_num_words = 0;
|
||||
static void *core1_arg = NULL;
|
||||
static uint32_t *core1_stack = NULL;
|
||||
static size_t core1_stack_num_words = 0;
|
||||
|
||||
// Thread mutex.
|
||||
STATIC mutex_t atomic_mutex;
|
||||
static mutex_t atomic_mutex;
|
||||
|
||||
uint32_t mp_thread_begin_atomic_section(void) {
|
||||
if (core1_entry) {
|
||||
@@ -102,7 +102,7 @@ void mp_thread_gc_others(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void core1_entry_wrapper(void) {
|
||||
static void core1_entry_wrapper(void) {
|
||||
// Allow MICROPY_BEGIN_ATOMIC_SECTION to be invoked from core0.
|
||||
multicore_lockout_victim_init();
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ typedef struct _rp2_dma_ctrl_field_t {
|
||||
uint8_t read_only : 1;
|
||||
} rp2_dma_ctrl_field_t;
|
||||
|
||||
STATIC rp2_dma_ctrl_field_t rp2_dma_ctrl_fields_table[] = {
|
||||
static rp2_dma_ctrl_field_t rp2_dma_ctrl_fields_table[] = {
|
||||
{ MP_QSTR_enable, 0, 1, 0 },
|
||||
{ MP_QSTR_high_pri, 1, 1, 0 },
|
||||
{ MP_QSTR_size, 2, 2, 0 },
|
||||
@@ -76,14 +76,14 @@ STATIC rp2_dma_ctrl_field_t rp2_dma_ctrl_fields_table[] = {
|
||||
{ MP_QSTR_ahb_err, 31, 1, 1 },
|
||||
};
|
||||
|
||||
STATIC const uint32_t rp2_dma_ctrl_field_count = MP_ARRAY_SIZE(rp2_dma_ctrl_fields_table);
|
||||
static const uint32_t rp2_dma_ctrl_field_count = MP_ARRAY_SIZE(rp2_dma_ctrl_fields_table);
|
||||
|
||||
#define REG_TYPE_COUNT 0 // Accept just integers
|
||||
#define REG_TYPE_CONF 1 // Accept integers or ctrl values
|
||||
#define REG_TYPE_ADDR_READ 2 // Accept integers, buffers or objects that can be read from
|
||||
#define REG_TYPE_ADDR_WRITE 3 // Accept integers, buffers or objects that can be written to
|
||||
|
||||
STATIC uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) {
|
||||
static uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) {
|
||||
if (reg_type == REG_TYPE_ADDR_READ || reg_type == REG_TYPE_ADDR_WRITE) {
|
||||
mp_buffer_info_t buf_info;
|
||||
mp_uint_t flags = (reg_type == REG_TYPE_ADDR_READ) ? MP_BUFFER_READ : MP_BUFFER_WRITE;
|
||||
@@ -95,7 +95,7 @@ STATIC uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) {
|
||||
return mp_obj_get_int_truncated(o);
|
||||
}
|
||||
|
||||
STATIC void rp2_dma_irq_handler(void) {
|
||||
static void rp2_dma_irq_handler(void) {
|
||||
// Main IRQ handler
|
||||
uint32_t irq_bits = dma_hw->ints0;
|
||||
|
||||
@@ -113,7 +113,7 @@ STATIC void rp2_dma_irq_handler(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t rp2_dma_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
static mp_uint_t rp2_dma_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
irq_set_enabled(DMA_IRQ_0, false);
|
||||
self->irq_flag = 0;
|
||||
@@ -122,7 +122,7 @@ STATIC mp_uint_t rp2_dma_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t rp2_dma_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
static mp_uint_t rp2_dma_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (info_type == MP_IRQ_INFO_FLAGS) {
|
||||
return self->irq_flag;
|
||||
@@ -132,12 +132,12 @@ STATIC mp_uint_t rp2_dma_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC const mp_irq_methods_t rp2_dma_irq_methods = {
|
||||
static const mp_irq_methods_t rp2_dma_irq_methods = {
|
||||
.trigger = rp2_dma_irq_trigger,
|
||||
.info = rp2_dma_irq_info,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t rp2_dma_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 rp2_dma_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);
|
||||
|
||||
int dma_channel = dma_claim_unused_channel(false);
|
||||
@@ -152,13 +152,13 @@ STATIC mp_obj_t rp2_dma_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC void rp2_dma_error_if_closed(rp2_dma_obj_t *self) {
|
||||
static void rp2_dma_error_if_closed(rp2_dma_obj_t *self) {
|
||||
if (self->channel == CHANNEL_CLOSED) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("channel closed"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void rp2_dma_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
|
||||
static void rp2_dma_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (dest[0] == MP_OBJ_NULL) {
|
||||
@@ -215,13 +215,13 @@ STATIC void rp2_dma_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void rp2_dma_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void rp2_dma_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "DMA(%u)", self->channel);
|
||||
}
|
||||
|
||||
// DMA.config(*, read, write, count, ctrl, trigger)
|
||||
STATIC mp_obj_t rp2_dma_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_dma_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(*pos_args);
|
||||
|
||||
rp2_dma_error_if_closed(self);
|
||||
@@ -277,10 +277,10 @@ STATIC mp_obj_t rp2_dma_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_config_obj, 1, rp2_dma_config);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_config_obj, 1, rp2_dma_config);
|
||||
|
||||
// DMA.active([value])
|
||||
STATIC mp_obj_t rp2_dma_active(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_dma_active(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
rp2_dma_error_if_closed(self);
|
||||
|
||||
@@ -295,13 +295,13 @@ STATIC mp_obj_t rp2_dma_active(size_t n_args, const mp_obj_t *args) {
|
||||
uint32_t busy = dma_channel_is_busy(self->channel);
|
||||
return mp_obj_new_bool((mp_int_t)busy);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_dma_active_obj, 1, 2, rp2_dma_active);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_dma_active_obj, 1, 2, rp2_dma_active);
|
||||
|
||||
// Default is quiet, unpaced, read and write incrementing, word transfers, enabled
|
||||
#define DEFAULT_DMA_CONFIG (1 << 21) | (0x3f << 15) | (1 << 5) | (1 << 4) | (2 << 2) | (1 << 0)
|
||||
|
||||
// DMA.pack_ctrl(...)
|
||||
STATIC mp_obj_t rp2_dma_pack_ctrl(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_dma_pack_ctrl(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// Pack keyword settings into a control register value, using either the default for this
|
||||
// DMA channel or the provided defaults
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
@@ -346,10 +346,10 @@ STATIC mp_obj_t rp2_dma_pack_ctrl(size_t n_pos_args, const mp_obj_t *pos_args, m
|
||||
|
||||
return mp_obj_new_int_from_uint(value);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_pack_ctrl_obj, 1, rp2_dma_pack_ctrl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_pack_ctrl_obj, 1, rp2_dma_pack_ctrl);
|
||||
|
||||
// DMA.unpack_ctrl(value)
|
||||
STATIC mp_obj_t rp2_dma_unpack_ctrl(mp_obj_t value_obj) {
|
||||
static mp_obj_t rp2_dma_unpack_ctrl(mp_obj_t value_obj) {
|
||||
// Return a dict representing the unpacked fields of a control register value
|
||||
mp_obj_t result_dict[rp2_dma_ctrl_field_count * 2];
|
||||
|
||||
@@ -364,10 +364,10 @@ STATIC mp_obj_t rp2_dma_unpack_ctrl(mp_obj_t value_obj) {
|
||||
|
||||
return mp_obj_dict_make_new(&mp_type_dict, 0, rp2_dma_ctrl_field_count, result_dict);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_unpack_ctrl_fun_obj, rp2_dma_unpack_ctrl);
|
||||
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(rp2_dma_unpack_ctrl_obj, MP_ROM_PTR(&rp2_dma_unpack_ctrl_fun_obj));
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_unpack_ctrl_fun_obj, rp2_dma_unpack_ctrl);
|
||||
static MP_DEFINE_CONST_STATICMETHOD_OBJ(rp2_dma_unpack_ctrl_obj, MP_ROM_PTR(&rp2_dma_unpack_ctrl_fun_obj));
|
||||
|
||||
STATIC mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_handler, ARG_hard };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = mp_const_none} },
|
||||
@@ -409,10 +409,10 @@ STATIC mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
|
||||
return MP_OBJ_FROM_PTR(irq);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_irq_obj, 1, rp2_dma_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_irq_obj, 1, rp2_dma_irq);
|
||||
|
||||
// DMA.close()
|
||||
STATIC mp_obj_t rp2_dma_close(mp_obj_t self_in) {
|
||||
static mp_obj_t rp2_dma_close(mp_obj_t self_in) {
|
||||
rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uint8_t channel = self->channel;
|
||||
|
||||
@@ -431,9 +431,9 @@ STATIC mp_obj_t rp2_dma_close(mp_obj_t self_in) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_close_obj, rp2_dma_close);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_close_obj, rp2_dma_close);
|
||||
|
||||
STATIC const mp_rom_map_elem_t rp2_dma_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t rp2_dma_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&rp2_dma_config_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&rp2_dma_active_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&rp2_dma_irq_obj) },
|
||||
@@ -442,7 +442,7 @@ STATIC const mp_rom_map_elem_t rp2_dma_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_pack_ctrl), MP_ROM_PTR(&rp2_dma_pack_ctrl_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_unpack_ctrl), MP_ROM_PTR(&rp2_dma_unpack_ctrl_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(rp2_dma_locals_dict, rp2_dma_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(rp2_dma_locals_dict, rp2_dma_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
rp2_dma_type,
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef struct _rp2_flash_obj_t {
|
||||
uint32_t flash_size;
|
||||
} rp2_flash_obj_t;
|
||||
|
||||
STATIC rp2_flash_obj_t rp2_flash_obj = {
|
||||
static rp2_flash_obj_t rp2_flash_obj = {
|
||||
.base = { &rp2_flash_type },
|
||||
.flash_base = MICROPY_HW_FLASH_STORAGE_BASE,
|
||||
.flash_size = MICROPY_HW_FLASH_STORAGE_BYTES,
|
||||
@@ -86,7 +86,7 @@ static void end_critical_flash_section(uint32_t state) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t rp2_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 rp2_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[] = {
|
||||
@@ -128,7 +128,7 @@ STATIC mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
uint32_t offset = mp_obj_get_int(args[1]) * BLOCK_SIZE_BYTES;
|
||||
mp_buffer_info_t bufinfo;
|
||||
@@ -143,9 +143,9 @@ STATIC mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
mp_event_handle_nowait();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_readblocks_obj, 3, 4, rp2_flash_readblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_readblocks_obj, 3, 4, rp2_flash_readblocks);
|
||||
|
||||
STATIC mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
uint32_t offset = mp_obj_get_int(args[1]) * BLOCK_SIZE_BYTES;
|
||||
mp_buffer_info_t bufinfo;
|
||||
@@ -166,9 +166,9 @@ STATIC mp_obj_t rp2_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(rp2_flash_writeblocks_obj, 3, 4, rp2_flash_writeblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_writeblocks_obj, 3, 4, rp2_flash_writeblocks);
|
||||
|
||||
STATIC mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
static mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
rp2_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||
switch (cmd) {
|
||||
@@ -194,14 +194,14 @@ STATIC mp_obj_t rp2_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(rp2_flash_ioctl_obj, rp2_flash_ioctl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(rp2_flash_ioctl_obj, rp2_flash_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t rp2_flash_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t rp2_flash_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&rp2_flash_readblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&rp2_flash_writeblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&rp2_flash_ioctl_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(rp2_flash_locals_dict, rp2_flash_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(rp2_flash_locals_dict, rp2_flash_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
rp2_flash_type,
|
||||
|
||||
@@ -65,17 +65,17 @@ typedef struct _rp2_state_machine_irq_obj_t {
|
||||
uint8_t trigger;
|
||||
} rp2_state_machine_irq_obj_t;
|
||||
|
||||
STATIC const rp2_state_machine_obj_t rp2_state_machine_obj[8];
|
||||
STATIC uint8_t rp2_state_machine_initial_pc[8];
|
||||
static const rp2_state_machine_obj_t rp2_state_machine_obj[8];
|
||||
static uint8_t rp2_state_machine_initial_pc[8];
|
||||
|
||||
// These masks keep track of PIO instruction memory used by this module.
|
||||
STATIC uint32_t rp2_pio_instruction_memory_usage_mask[2];
|
||||
static uint32_t rp2_pio_instruction_memory_usage_mask[2];
|
||||
|
||||
STATIC const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id);
|
||||
STATIC void rp2_state_machine_reset_all(void);
|
||||
STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
static const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id);
|
||||
static void rp2_state_machine_reset_all(void);
|
||||
static mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
|
||||
STATIC void pio_irq0(PIO pio) {
|
||||
static void pio_irq0(PIO pio) {
|
||||
uint32_t ints = pio->ints0;
|
||||
|
||||
// Acknowledge SM0-3 IRQs if they are enabled on this IRQ0.
|
||||
@@ -98,16 +98,16 @@ STATIC void pio_irq0(PIO pio) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pio0_irq0(void) {
|
||||
static void pio0_irq0(void) {
|
||||
pio_irq0(pio0);
|
||||
}
|
||||
|
||||
STATIC void pio1_irq0(void) {
|
||||
static void pio1_irq0(void) {
|
||||
pio_irq0(pio1);
|
||||
}
|
||||
|
||||
// Calls pio_add_program() and keeps track of used instruction memory.
|
||||
STATIC uint rp2_pio_add_managed_program(PIO pio, struct pio_program *pio_program) {
|
||||
static uint rp2_pio_add_managed_program(PIO pio, struct pio_program *pio_program) {
|
||||
uint offset = pio_add_program(pio, pio_program);
|
||||
uint32_t mask = ((1 << pio_program->length) - 1) << offset;
|
||||
rp2_pio_instruction_memory_usage_mask[pio_get_index(pio)] |= mask;
|
||||
@@ -115,7 +115,7 @@ STATIC uint rp2_pio_add_managed_program(PIO pio, struct pio_program *pio_program
|
||||
}
|
||||
|
||||
// Calls pio_remove_program() and keeps track of used instruction memory.
|
||||
STATIC void rp2_pio_remove_managed_program(PIO pio, struct pio_program *pio_program, uint offset) {
|
||||
static void rp2_pio_remove_managed_program(PIO pio, struct pio_program *pio_program, uint offset) {
|
||||
pio_remove_program(pio, pio_program, offset);
|
||||
uint32_t mask = ((1 << pio_program->length) - 1) << offset;
|
||||
rp2_pio_instruction_memory_usage_mask[pio_get_index(pio)] &= ~mask;
|
||||
@@ -123,7 +123,7 @@ STATIC void rp2_pio_remove_managed_program(PIO pio, struct pio_program *pio_prog
|
||||
|
||||
// Calls pio_remove_program() for all programs registered with rp2_pio_add_managed_program(),
|
||||
// that weren't already removed via rp2_pio_remove_managed_program().
|
||||
STATIC void rp2_pio_remove_all_managed_programs(PIO pio) {
|
||||
static void rp2_pio_remove_all_managed_programs(PIO pio) {
|
||||
uint32_t mask = rp2_pio_instruction_memory_usage_mask[pio_get_index(pio)];
|
||||
for (size_t i = 0; i < 32; ++i) {
|
||||
if (mask & (1 << i)) {
|
||||
@@ -188,13 +188,13 @@ typedef struct _asm_pio_config_t {
|
||||
uint32_t pinvals;
|
||||
} asm_pio_config_t;
|
||||
|
||||
STATIC void asm_pio_override_shiftctrl(mp_obj_t arg, uint32_t bits, uint32_t lsb, pio_sm_config *config) {
|
||||
static void asm_pio_override_shiftctrl(mp_obj_t arg, uint32_t bits, uint32_t lsb, pio_sm_config *config) {
|
||||
if (arg != mp_const_none) {
|
||||
config->shiftctrl = (config->shiftctrl & ~bits) | (mp_obj_get_int(arg) << lsb);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void asm_pio_get_pins(const char *type, mp_obj_t prog_pins, mp_obj_t arg_base, asm_pio_config_t *config) {
|
||||
static void asm_pio_get_pins(const char *type, mp_obj_t prog_pins, mp_obj_t arg_base, asm_pio_config_t *config) {
|
||||
if (prog_pins != mp_const_none) {
|
||||
// The PIO program specified pins for initialisation on out/set/sideset.
|
||||
if (mp_obj_is_integer(prog_pins)) {
|
||||
@@ -223,7 +223,7 @@ STATIC void asm_pio_get_pins(const char *type, mp_obj_t prog_pins, mp_obj_t arg_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) {
|
||||
static void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) {
|
||||
uint32_t pinmask = ((1 << config->count) - 1) << config->base;
|
||||
pio_sm_set_pins_with_mask(pio, sm, config->pinvals << config->base, pinmask);
|
||||
pio_sm_set_pindirs_with_mask(pio, sm, config->pindirs << config->base, pinmask);
|
||||
@@ -235,20 +235,20 @@ STATIC void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) {
|
||||
/******************************************************************************/
|
||||
// PIO object
|
||||
|
||||
STATIC const mp_irq_methods_t rp2_pio_irq_methods;
|
||||
static const mp_irq_methods_t rp2_pio_irq_methods;
|
||||
|
||||
STATIC rp2_pio_obj_t rp2_pio_obj[] = {
|
||||
static rp2_pio_obj_t rp2_pio_obj[] = {
|
||||
{ { &rp2_pio_type }, pio0, PIO0_IRQ_0 },
|
||||
{ { &rp2_pio_type }, pio1, PIO1_IRQ_0 },
|
||||
};
|
||||
|
||||
STATIC void rp2_pio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void rp2_pio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "PIO(%u)", self->pio == pio0 ? 0 : 1);
|
||||
}
|
||||
|
||||
// constructor(id)
|
||||
STATIC mp_obj_t rp2_pio_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 rp2_pio_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, 1, false);
|
||||
|
||||
// Get the PIO object.
|
||||
@@ -263,7 +263,7 @@ STATIC mp_obj_t rp2_pio_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
}
|
||||
|
||||
// PIO.add_program(prog)
|
||||
STATIC mp_obj_t rp2_pio_add_program(mp_obj_t self_in, mp_obj_t prog_in) {
|
||||
static mp_obj_t rp2_pio_add_program(mp_obj_t self_in, mp_obj_t prog_in) {
|
||||
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// Get the program data.
|
||||
@@ -284,10 +284,10 @@ STATIC mp_obj_t rp2_pio_add_program(mp_obj_t self_in, mp_obj_t prog_in) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(rp2_pio_add_program_obj, rp2_pio_add_program);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(rp2_pio_add_program_obj, rp2_pio_add_program);
|
||||
|
||||
// PIO.remove_program([prog])
|
||||
STATIC mp_obj_t rp2_pio_remove_program(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_pio_remove_program(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
|
||||
// Default to remove all programs.
|
||||
@@ -315,10 +315,10 @@ STATIC mp_obj_t rp2_pio_remove_program(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_pio_remove_program_obj, 1, 2, rp2_pio_remove_program);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_pio_remove_program_obj, 1, 2, rp2_pio_remove_program);
|
||||
|
||||
// PIO.state_machine(id, prog, freq=-1, *, set=None)
|
||||
STATIC mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
|
||||
// Get and verify the state machine id.
|
||||
@@ -340,7 +340,7 @@ STATIC mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, m
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(rp2_pio_state_machine_obj, 2, rp2_pio_state_machine);
|
||||
|
||||
// PIO.irq(handler=None, trigger=IRQ_SM0|IRQ_SM1|IRQ_SM2|IRQ_SM3, hard=False)
|
||||
STATIC mp_obj_t rp2_pio_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_pio_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} },
|
||||
@@ -388,9 +388,9 @@ STATIC mp_obj_t rp2_pio_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
|
||||
return MP_OBJ_FROM_PTR(irq);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_pio_irq_obj, 1, rp2_pio_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_pio_irq_obj, 1, rp2_pio_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_add_program), MP_ROM_PTR(&rp2_pio_add_program_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_program), MP_ROM_PTR(&rp2_pio_remove_program_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_state_machine), MP_ROM_PTR(&rp2_pio_state_machine_obj) },
|
||||
@@ -413,7 +413,7 @@ STATIC const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_IRQ_SM2), MP_ROM_INT(0x400) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_IRQ_SM3), MP_ROM_INT(0x800) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(rp2_pio_locals_dict, rp2_pio_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(rp2_pio_locals_dict, rp2_pio_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
rp2_pio_type,
|
||||
@@ -424,7 +424,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &rp2_pio_locals_dict
|
||||
);
|
||||
|
||||
STATIC mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
static mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
rp2_pio_irq_obj_t *irq = MP_STATE_PORT(rp2_pio_irq_obj[PIO_NUM(self->pio)]);
|
||||
irq_set_enabled(self->irq, false);
|
||||
@@ -434,7 +434,7 @@ STATIC mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t rp2_pio_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
static mp_uint_t rp2_pio_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
rp2_pio_irq_obj_t *irq = MP_STATE_PORT(rp2_pio_irq_obj[PIO_NUM(self->pio)]);
|
||||
if (info_type == MP_IRQ_INFO_FLAGS) {
|
||||
@@ -445,7 +445,7 @@ STATIC mp_uint_t rp2_pio_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC const mp_irq_methods_t rp2_pio_irq_methods = {
|
||||
static const mp_irq_methods_t rp2_pio_irq_methods = {
|
||||
.trigger = rp2_pio_irq_trigger,
|
||||
.info = rp2_pio_irq_info,
|
||||
};
|
||||
@@ -454,11 +454,11 @@ STATIC const mp_irq_methods_t rp2_pio_irq_methods = {
|
||||
// StateMachine object
|
||||
|
||||
// This mask keeps track of state machines claimed by this module.
|
||||
STATIC uint32_t rp2_state_machine_claimed_mask;
|
||||
static uint32_t rp2_state_machine_claimed_mask;
|
||||
|
||||
STATIC const mp_irq_methods_t rp2_state_machine_irq_methods;
|
||||
static const mp_irq_methods_t rp2_state_machine_irq_methods;
|
||||
|
||||
STATIC const rp2_state_machine_obj_t rp2_state_machine_obj[] = {
|
||||
static const rp2_state_machine_obj_t rp2_state_machine_obj[] = {
|
||||
{ { &rp2_state_machine_type }, pio0, PIO0_IRQ_0, 0, 0 },
|
||||
{ { &rp2_state_machine_type }, pio0, PIO0_IRQ_0, 1, 1 },
|
||||
{ { &rp2_state_machine_type }, pio0, PIO0_IRQ_0, 2, 2 },
|
||||
@@ -469,7 +469,7 @@ STATIC const rp2_state_machine_obj_t rp2_state_machine_obj[] = {
|
||||
{ { &rp2_state_machine_type }, pio1, PIO1_IRQ_0, 3, 7 },
|
||||
};
|
||||
|
||||
STATIC const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id) {
|
||||
static const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id) {
|
||||
if (!(0 <= sm_id && sm_id < MP_ARRAY_SIZE(rp2_state_machine_obj))) {
|
||||
mp_raise_ValueError("invalid StateMachine");
|
||||
}
|
||||
@@ -487,7 +487,7 @@ STATIC const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_i
|
||||
return sm_obj;
|
||||
}
|
||||
|
||||
STATIC void rp2_state_machine_reset_all(void) {
|
||||
static void rp2_state_machine_reset_all(void) {
|
||||
for (size_t i = 0; i < MP_ARRAY_SIZE(rp2_state_machine_obj); ++i) {
|
||||
if (rp2_state_machine_claimed_mask & (1 << i)) {
|
||||
const rp2_state_machine_obj_t *sm_obj = &rp2_state_machine_obj[i];
|
||||
@@ -498,7 +498,7 @@ STATIC void rp2_state_machine_reset_all(void) {
|
||||
rp2_state_machine_claimed_mask = 0;
|
||||
}
|
||||
|
||||
STATIC void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "StateMachine(%u)", self->id);
|
||||
}
|
||||
@@ -508,7 +508,7 @@ STATIC void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, m
|
||||
// sideset_base=None, in_shiftdir=None, out_shiftdir=None,
|
||||
// push_thresh=None, pull_thresh=None,
|
||||
// )
|
||||
STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum {
|
||||
ARG_prog, ARG_freq,
|
||||
ARG_in_base, ARG_out_base, ARG_set_base, ARG_jmp_pin, ARG_sideset_base,
|
||||
@@ -639,7 +639,7 @@ STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *sel
|
||||
}
|
||||
|
||||
// StateMachine(id, ...)
|
||||
STATIC mp_obj_t rp2_state_machine_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 rp2_state_machine_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 the StateMachine object.
|
||||
@@ -657,32 +657,32 @@ STATIC mp_obj_t rp2_state_machine_make_new(const mp_obj_type_t *type, size_t n_a
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t rp2_state_machine_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_state_machine_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return rp2_state_machine_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_init_obj, 1, rp2_state_machine_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_init_obj, 1, rp2_state_machine_init);
|
||||
|
||||
// StateMachine.active([value])
|
||||
STATIC mp_obj_t rp2_state_machine_active(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_state_machine_active(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
if (n_args > 1) {
|
||||
pio_sm_set_enabled(self->pio, self->sm, mp_obj_is_true(args[1]));
|
||||
}
|
||||
return mp_obj_new_bool((self->pio->ctrl >> self->sm) & 1);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_active_obj, 1, 2, rp2_state_machine_active);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_active_obj, 1, 2, rp2_state_machine_active);
|
||||
|
||||
// StateMachine.restart()
|
||||
STATIC mp_obj_t rp2_state_machine_restart(mp_obj_t self_in) {
|
||||
static mp_obj_t rp2_state_machine_restart(mp_obj_t self_in) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
pio_sm_restart(self->pio, self->sm);
|
||||
pio_sm_exec(self->pio, self->sm, pio_encode_jmp(rp2_state_machine_initial_pc[self->id]));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_restart_obj, rp2_state_machine_restart);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_restart_obj, rp2_state_machine_restart);
|
||||
|
||||
// StateMachine.exec(instr)
|
||||
STATIC mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) {
|
||||
static mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t encoded = 0;
|
||||
if (!mp_obj_get_int_maybe(instr_in, &encoded)) {
|
||||
@@ -700,10 +700,10 @@ STATIC mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) {
|
||||
pio_sm_exec(self->pio, self->sm, encoded);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(rp2_state_machine_exec_obj, rp2_state_machine_exec);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(rp2_state_machine_exec_obj, rp2_state_machine_exec);
|
||||
|
||||
// StateMachine.get(buf=None, shift=0)
|
||||
STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
bufinfo.buf = NULL;
|
||||
@@ -752,10 +752,10 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get);
|
||||
|
||||
// StateMachine.put(value, shift=0)
|
||||
STATIC mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
uint32_t shift = 0;
|
||||
if (n_args > 2) {
|
||||
@@ -793,26 +793,26 @@ STATIC mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_put_obj, 2, 3, rp2_state_machine_put);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_put_obj, 2, 3, rp2_state_machine_put);
|
||||
|
||||
// StateMachine.rx_fifo()
|
||||
STATIC mp_obj_t rp2_state_machine_rx_fifo(mp_obj_t self_in) {
|
||||
static mp_obj_t rp2_state_machine_rx_fifo(mp_obj_t self_in) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_NEW_SMALL_INT(pio_sm_get_rx_fifo_level(self->pio, self->sm));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_rx_fifo_obj, rp2_state_machine_rx_fifo);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_rx_fifo_obj, rp2_state_machine_rx_fifo);
|
||||
|
||||
// StateMachine.tx_fifo()
|
||||
STATIC mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) {
|
||||
static mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_NEW_SMALL_INT(pio_sm_get_tx_fifo_level(self->pio, self->sm));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_tx_fifo_obj, rp2_state_machine_tx_fifo);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_tx_fifo_obj, rp2_state_machine_tx_fifo);
|
||||
|
||||
// Buffer protocol implementation for StateMachine.
|
||||
// The buffer represents one of the FIFO ports of the state machine. Note that a different
|
||||
// pointer is returned depending on if this is for reading or writing.
|
||||
STATIC mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
static mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(o_in);
|
||||
|
||||
bufinfo->len = 4;
|
||||
@@ -827,7 +827,7 @@ STATIC mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bu
|
||||
}
|
||||
|
||||
// StateMachine.irq(handler=None, trigger=0|1, hard=False)
|
||||
STATIC mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t rp2_state_machine_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} },
|
||||
@@ -880,9 +880,9 @@ STATIC mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, m
|
||||
|
||||
return MP_OBJ_FROM_PTR(irq);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_irq_obj, 1, rp2_state_machine_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_irq_obj, 1, rp2_state_machine_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&rp2_state_machine_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&rp2_state_machine_active_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_restart), MP_ROM_PTR(&rp2_state_machine_restart_obj) },
|
||||
@@ -893,7 +893,7 @@ STATIC const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_tx_fifo), MP_ROM_PTR(&rp2_state_machine_tx_fifo_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&rp2_state_machine_irq_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(rp2_state_machine_locals_dict, rp2_state_machine_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(rp2_state_machine_locals_dict, rp2_state_machine_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
rp2_state_machine_type,
|
||||
@@ -905,7 +905,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &rp2_state_machine_locals_dict
|
||||
);
|
||||
|
||||
STATIC mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
static mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
rp2_state_machine_irq_obj_t *irq = MP_STATE_PORT(rp2_state_machine_irq_obj[PIO_NUM(self->pio)]);
|
||||
irq_set_enabled(self->irq, false);
|
||||
@@ -915,7 +915,7 @@ STATIC mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t rp2_state_machine_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
static mp_uint_t rp2_state_machine_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
rp2_state_machine_irq_obj_t *irq = MP_STATE_PORT(rp2_state_machine_irq_obj[PIO_NUM(self->pio)]);
|
||||
if (info_type == MP_IRQ_INFO_FLAGS) {
|
||||
@@ -926,7 +926,7 @@ STATIC mp_uint_t rp2_state_machine_irq_info(mp_obj_t self_in, mp_uint_t info_typ
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC const mp_irq_methods_t rp2_state_machine_irq_methods = {
|
||||
static const mp_irq_methods_t rp2_state_machine_irq_methods = {
|
||||
.trigger = rp2_state_machine_irq_trigger,
|
||||
.info = rp2_state_machine_irq_info,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user