summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authormicroDev <70126934+microDev1@users.noreply.github.com>2020-11-24 11:11:11 +0530
committermicroDev <70126934+microDev1@users.noreply.github.com>2020-11-24 11:11:11 +0530
commit9dd1783da547bf9d632fa307abcf42f36d260ccf (patch)
tree1c2df3a5e6c96dfb63574bf12ca5d8edd32236f3 /ports
parent040eaa044344562ec1f9905d67b612ea2ec12949 (diff)
parentebdc48ae22589080300da249f416bd55f1c121bd (diff)
Merge branch 'main' into ps2io-S2
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/boards/cp_sapling_m0/board.c40
-rw-r--r--ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.h57
-rw-r--r--ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk24
-rw-r--r--ports/atmel-samd/boards/cp_sapling_m0/pins.c38
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/PDMIn.c8
-rw-r--r--ports/cxd56/supervisor/port.c6
-rw-r--r--ports/esp32s2/Makefile1
-rw-r--r--ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c9
-rw-r--r--ports/esp32s2/common-hal/frequencyio/FrequencyIn.c193
-rw-r--r--ports/esp32s2/common-hal/frequencyio/FrequencyIn.h45
-rw-r--r--ports/esp32s2/common-hal/frequencyio/__init__.c1
-rw-r--r--ports/esp32s2/common-hal/microcontroller/__init__.c2
-rw-r--r--ports/esp32s2/common-hal/pulseio/PulseIn.c8
-rw-r--r--ports/esp32s2/common-hal/wifi/Radio.c7
-rw-r--r--ports/esp32s2/common-hal/wifi/__init__.c10
-rw-r--r--ports/esp32s2/mpconfigport.mk2
-rw-r--r--ports/esp32s2/peripherals/timer.c76
-rw-r--r--ports/esp32s2/peripherals/timer.h41
-rw-r--r--ports/esp32s2/supervisor/port.c24
-rw-r--r--ports/stm/boards/meowbit_v121/mpconfigboard.mk2
-rw-r--r--ports/stm/boards/thunderpack/mpconfigboard.mk2
-rw-r--r--ports/unix/modjni.c4
22 files changed, 582 insertions, 18 deletions
diff --git a/ports/atmel-samd/boards/cp_sapling_m0/board.c b/ports/atmel-samd/boards/cp_sapling_m0/board.c
new file mode 100644
index 000000000..ce5636676
--- /dev/null
+++ b/ports/atmel-samd/boards/cp_sapling_m0/board.c
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+#include "common-hal/microcontroller/Pin.h"
+#include "supervisor/shared/board.h"
+#include "hal/include/hal_gpio.h"
+
+void board_init(void) {
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
+
+void reset_board(void) {
+}
diff --git a/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.h b/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.h
new file mode 100644
index 000000000..c67f022eb
--- /dev/null
+++ b/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.h
@@ -0,0 +1,57 @@
+#define MICROPY_HW_BOARD_NAME "CP Sapling M0"
+#define MICROPY_HW_MCU_NAME "samd21e18"
+
+#define MICROPY_HW_NEOPIXEL (&pin_PA15)
+
+#define MICROPY_PORT_A (0)
+#define MICROPY_PORT_B (0)
+#define MICROPY_PORT_C (0)
+
+#define IGNORE_PIN_PA02 1
+#define IGNORE_PIN_PA03 1
+#define IGNORE_PIN_PA04 1
+#define IGNORE_PIN_PA05 1
+#define IGNORE_PIN_PA06 1
+#define IGNORE_PIN_PA07 1
+#define IGNORE_PIN_PA12 1
+#define IGNORE_PIN_PA13 1
+#define IGNORE_PIN_PA14 1
+#define IGNORE_PIN_PA20 1
+#define IGNORE_PIN_PA21 1
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
+#define IGNORE_PIN_PA27 1
+#define IGNORE_PIN_PA28 1
+#define IGNORE_PIN_PA30 1
+#define IGNORE_PIN_PA31 1
+#define IGNORE_PIN_PB01 1
+#define IGNORE_PIN_PB02 1
+#define IGNORE_PIN_PB03 1
+#define IGNORE_PIN_PB04 1
+#define IGNORE_PIN_PB05 1
+#define IGNORE_PIN_PB06 1
+#define IGNORE_PIN_PB07 1
+#define IGNORE_PIN_PB08 1
+#define IGNORE_PIN_PB09 1
+#define IGNORE_PIN_PB10 1
+#define IGNORE_PIN_PB11 1
+#define IGNORE_PIN_PB12 1
+#define IGNORE_PIN_PB13 1
+#define IGNORE_PIN_PB14 1
+#define IGNORE_PIN_PB15 1
+#define IGNORE_PIN_PB16 1
+#define IGNORE_PIN_PB17 1
+#define IGNORE_PIN_PB22 1
+#define IGNORE_PIN_PB23 1
+#define IGNORE_PIN_PB30 1
+#define IGNORE_PIN_PB31 1
+#define IGNORE_PIN_PB00 1
+
+#define DEFAULT_I2C_BUS_SCL (&pin_PA09)
+#define DEFAULT_I2C_BUS_SDA (&pin_PA08)
+
+#define DEFAULT_SPI_BUS_SS (&pin_PA22)
+#define DEFAULT_SPI_BUS_SCK (&pin_PA19)
+#define DEFAULT_SPI_BUS_MOSI (&pin_PA18)
+#define DEFAULT_SPI_BUS_MISO (&pin_PA17)
diff --git a/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk
new file mode 100644
index 000000000..861a0a5f7
--- /dev/null
+++ b/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk
@@ -0,0 +1,24 @@
+USB_VID = 0x1209
+USB_PID = 0x4DDD
+USB_PRODUCT = "CP Sapling"
+USB_MANUFACTURER = "Oak Development Technologies"
+
+CHIP_VARIANT = SAMD21E18A
+CHIP_FAMILY = samd21
+
+INTERNAL_FLASH_FILESYSTEM = 1
+LONGINT_IMPL = NONE
+CIRCUITPY_FULL_BUILD = 0
+
+SUPEROPT_GC = 0
+
+CFLAGS_BOARD = --param max-inline-insns-auto=15
+ifeq ($(TRANSLATION), zh_Latn_pinyin)
+RELEASE_NEEDS_CLEAN_BUILD = 1
+CFLAGS_INLINE_LIMIT = 35
+endif
+ifeq ($(TRANSLATION), de_DE)
+RELEASE_NEEDS_CLEAN_BUILD = 1
+CFLAGS_INLINE_LIMIT = 35
+SUPEROPT_VM = 0
+endif
diff --git a/ports/atmel-samd/boards/cp_sapling_m0/pins.c b/ports/atmel-samd/boards/cp_sapling_m0/pins.c
new file mode 100644
index 000000000..d527aaddc
--- /dev/null
+++ b/ports/atmel-samd/boards/cp_sapling_m0/pins.c
@@ -0,0 +1,38 @@
+#include "shared-bindings/board/__init__.h"
+
+STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
+
+ { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA08) },
+ { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) },
+
+ { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA00) },
+ { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA00) },
+
+ { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA01) },
+ { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA01) },
+
+ { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA09) },
+ { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) },
+
+ { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA22) },
+ { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA22) },
+ { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PA22) },
+
+ { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA19) },
+ { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA19) },
+ { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA19) },
+
+ { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA17) },
+ { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA17) },
+ { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) },
+
+ { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA18) },
+ { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA18) },
+ { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) },
+
+ { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) },
+
+ { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
+ { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
+};
+MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);
diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
index 3c9ec05c2..8911aef2f 100644
--- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -337,7 +337,11 @@ const uint16_t sinc_filter [OVERSAMPLING] = {
94, 63, 39, 21, 9, 2, 0, 0
};
-#define REPEAT_16_TIMES(X) X X X X X X X X X X X X X X X X
+#ifdef SAMD21
+#define REPEAT_16_TIMES(X) do { for(uint8_t j=0; j<4; j++) { X X X X } } while (0)
+#else
+#define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while(0)
+#endif
static uint16_t filter_sample(uint32_t pdm_samples[4]) {
uint16_t running_sum = 0;
@@ -354,7 +358,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
filter_ptr++;
pdm_sample <<= 1;
}
- )
+ );
}
return running_sum;
}
diff --git a/ports/cxd56/supervisor/port.c b/ports/cxd56/supervisor/port.c
index 92d335cd5..086c2d198 100644
--- a/ports/cxd56/supervisor/port.c
+++ b/ports/cxd56/supervisor/port.c
@@ -98,8 +98,12 @@ void reset_to_bootloader(void) {
}
}
+supervisor_allocation _fixed_stack;
+
supervisor_allocation* port_fixed_stack(void) {
- return NULL;
+ _fixed_stack.ptr = port_stack_get_limit();
+ _fixed_stack.length = (port_stack_get_top() - port_stack_get_limit()) * sizeof(uint32_t);
+ return &_fixed_stack;
}
uint32_t *port_stack_get_limit(void) {
diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile
index 55d6e91d4..931e4d063 100644
--- a/ports/esp32s2/Makefile
+++ b/ports/esp32s2/Makefile
@@ -188,6 +188,7 @@ SRC_C += \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
lib/utils/sys_stdio_mphal.c \
+ peripherals/timer.c \
peripherals/pcnt.c \
peripherals/pins.c \
peripherals/rmt.c \
diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c
index 40c9e91e4..0cefb6dfb 100644
--- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c
+++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c
@@ -16,11 +16,19 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO15) },
+ { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_PTR(&pin_GPIO14) },
+ { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) },
+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_C), MP_ROM_PTR(&pin_GPIO12) },
+ { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) },
+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_D), MP_ROM_PTR(&pin_GPIO11) },
+ { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_GPIO3) },
+ { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO4) },
@@ -36,6 +44,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO1) },
+ { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
diff --git a/ports/esp32s2/common-hal/frequencyio/FrequencyIn.c b/ports/esp32s2/common-hal/frequencyio/FrequencyIn.c
new file mode 100644
index 000000000..12d612abb
--- /dev/null
+++ b/ports/esp32s2/common-hal/frequencyio/FrequencyIn.c
@@ -0,0 +1,193 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/frequencyio/FrequencyIn.h"
+
+#include "py/runtime.h"
+
+static void IRAM_ATTR pcnt_overflow_handler(void *self_in) {
+ frequencyio_frequencyin_obj_t * self = self_in;
+ // reset counter
+ pcnt_counter_clear(self->unit);
+
+ // increase multiplier
+ self->multiplier++;
+
+ // reset interrupt
+ PCNT.int_clr.val = BIT(self->unit);
+}
+
+static void IRAM_ATTR timer_interrupt_handler(void *self_in) {
+ frequencyio_frequencyin_obj_t * self = self_in;
+ // get counter value
+ int16_t count;
+ pcnt_get_counter_value(self->unit, &count);
+ self->frequency = ((count / 2.0) + (self->multiplier * INT16_MAX / 4.0)) / (self->capture_period);
+
+ // reset multiplier
+ self->multiplier = 0;
+
+ // reset counter
+ pcnt_counter_clear(self->unit);
+
+ // reset interrupt
+ timg_dev_t *device = self->timer.group ? &(TIMERG1) : &(TIMERG0);
+ if (self->timer.idx) {
+ device->int_clr.t1 = 1;
+ } else {
+ device->int_clr.t0 = 1;
+ }
+ device->hw_timer[self->timer.idx].config.alarm_en = 1;
+}
+
+static void init_pcnt(frequencyio_frequencyin_obj_t* self) {
+ // Prepare configuration for the PCNT unit
+ const pcnt_config_t pcnt_config = {
+ // Set PCNT input signal and control GPIOs
+ .pulse_gpio_num = self->pin,
+ .ctrl_gpio_num = PCNT_PIN_NOT_USED,
+ .channel = PCNT_CHANNEL_0,
+ // What to do on the positive / negative edge of pulse input?
+ .pos_mode = PCNT_COUNT_INC, // count both rising and falling edges
+ .neg_mode = PCNT_COUNT_INC,
+ // Set counter limit
+ .counter_h_lim = INT16_MAX,
+ .counter_l_lim = 0,
+ };
+
+ // initialize PCNT
+ const int8_t unit = peripherals_pcnt_init(pcnt_config);
+ if (unit == -1) {
+ mp_raise_RuntimeError(translate("All PCNT units in use"));
+ }
+
+ // set the GPIO back to high-impedance, as pcnt_unit_config sets it as pull-up
+ gpio_set_pull_mode(self->pin, GPIO_FLOATING);
+
+ self->unit = (pcnt_unit_t)unit;
+
+ // enable pcnt interrupt
+ pcnt_event_enable(self->unit, PCNT_EVT_H_LIM);
+ pcnt_isr_register(pcnt_overflow_handler, (void *)self, ESP_INTR_FLAG_IRAM, &self->handle);
+ pcnt_intr_enable(self->unit);
+}
+
+static void init_timer(frequencyio_frequencyin_obj_t* self) {
+ // Prepare configuration for the timer module
+ const timer_config_t config = {
+ .alarm_en = true,
+ .counter_en = false,
+ .intr_type = TIMER_INTR_LEVEL,
+ .counter_dir = TIMER_COUNT_UP,
+ .auto_reload = true,
+ .divider = 80 // 1 us per tick
+ };
+
+ // initialize Timer
+ peripherals_timer_init(&config, &self->timer);
+ if (self->timer.idx == TIMER_MAX || self->timer.group == TIMER_GROUP_MAX) {
+ mp_raise_RuntimeError(translate("All timers in use"));
+ }
+
+ timer_idx_t idx = self->timer.idx;
+ timer_group_t group = self->timer.group;
+
+ // enable timer interrupt
+ timer_set_alarm_value(group, idx, self->capture_period * 1000000);
+ timer_isr_register(group, idx, timer_interrupt_handler, (void *)self, ESP_INTR_FLAG_IRAM, &self->handle);
+ timer_enable_intr(group, idx);
+
+ // start timer
+ timer_start(self->timer.group, self->timer.idx);
+}
+
+void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* self,
+ const mcu_pin_obj_t* pin, const uint16_t capture_period) {
+ if ((capture_period == 0) || (capture_period > 500)) {
+ mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
+ }
+
+ self->pin = pin->number;
+ self->handle = NULL;
+ self->multiplier = 0;
+ self->capture_period = capture_period;
+
+ // initialize pcnt and timer
+ init_pcnt(self);
+ init_timer(self);
+
+ claim_pin(pin);
+}
+
+bool common_hal_frequencyio_frequencyin_deinited(frequencyio_frequencyin_obj_t* self) {
+ return self->unit == PCNT_UNIT_MAX;
+}
+
+void common_hal_frequencyio_frequencyin_deinit(frequencyio_frequencyin_obj_t* self) {
+ if (common_hal_frequencyio_frequencyin_deinited(self)) {
+ return;
+ }
+ reset_pin_number(self->pin);
+ peripherals_pcnt_deinit(&self->unit);
+ peripherals_timer_deinit(&self->timer);
+ if (self->handle) {
+ esp_intr_free(self->handle);
+ self->handle = NULL;
+ }
+}
+
+uint32_t common_hal_frequencyio_frequencyin_get_item(frequencyio_frequencyin_obj_t* self) {
+ return self->frequency;
+}
+
+void common_hal_frequencyio_frequencyin_pause(frequencyio_frequencyin_obj_t* self) {
+ pcnt_counter_pause(self->unit);
+ timer_pause(self->timer.group, self->timer.idx);
+}
+
+void common_hal_frequencyio_frequencyin_resume(frequencyio_frequencyin_obj_t* self) {
+ pcnt_counter_resume(self->unit);
+ timer_start(self->timer.group, self->timer.idx);
+}
+
+void common_hal_frequencyio_frequencyin_clear(frequencyio_frequencyin_obj_t* self) {
+ self->frequency = 0;
+ pcnt_counter_clear(self->unit);
+ timer_set_counter_value(self->timer.group, self->timer.idx, 0);
+}
+
+uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequencyin_obj_t *self) {
+ return self->capture_period;
+}
+
+void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period) {
+ if ((capture_period == 0) || (capture_period > 500)) {
+ mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
+ }
+ self->capture_period = capture_period;
+ common_hal_frequencyio_frequencyin_clear(self);
+ timer_set_alarm_value(self->timer.group, self->timer.idx, capture_period * 1000000);
+}
diff --git a/ports/esp32s2/common-hal/frequencyio/FrequencyIn.h b/ports/esp32s2/common-hal/frequencyio/FrequencyIn.h
new file mode 100644
index 000000000..cf9d2ae53
--- /dev/null
+++ b/ports/esp32s2/common-hal/frequencyio/FrequencyIn.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H
+#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H
+
+#include "py/obj.h"
+#include "peripherals/pcnt.h"
+#include "peripherals/timer.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ pcnt_unit_t unit;
+ timer_index_t timer;
+ intr_handle_t handle;
+ uint8_t pin;
+ uint8_t multiplier;
+ uint32_t frequency;
+ uint16_t capture_period;
+} frequencyio_frequencyin_obj_t;
+
+#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H
diff --git a/ports/esp32s2/common-hal/frequencyio/__init__.c b/ports/esp32s2/common-hal/frequencyio/__init__.c
new file mode 100644
index 000000000..487814bd0
--- /dev/null
+++ b/ports/esp32s2/common-hal/frequencyio/__init__.c
@@ -0,0 +1 @@
+// No ferquencyio module functions.
diff --git a/ports/esp32s2/common-hal/microcontroller/__init__.c b/ports/esp32s2/common-hal/microcontroller/__init__.c
index e5cfc7eef..dba12b88b 100644
--- a/ports/esp32s2/common-hal/microcontroller/__init__.c
+++ b/ports/esp32s2/common-hal/microcontroller/__init__.c
@@ -42,7 +42,7 @@
#include "freertos/FreeRTOS.h"
void common_hal_mcu_delay_us(uint32_t delay) {
-
+ mp_hal_delay_us(delay);
}
volatile uint32_t nesting_count = 0;
diff --git a/ports/esp32s2/common-hal/pulseio/PulseIn.c b/ports/esp32s2/common-hal/pulseio/PulseIn.c
index f7429ec12..9feeea147 100644
--- a/ports/esp32s2/common-hal/pulseio/PulseIn.c
+++ b/ports/esp32s2/common-hal/pulseio/PulseIn.c
@@ -77,7 +77,9 @@ void pulsein_reset(void) {
for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) {
handles[i] = NULL;
}
- supervisor_disable_tick();
+ if (refcount != 0) {
+ supervisor_disable_tick();
+ }
refcount = 0;
}
@@ -122,8 +124,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu
// start RMT RX, and enable ticks so the core doesn't turn off.
rmt_rx_start(channel, true);
- supervisor_enable_tick();
refcount++;
+ if (refcount == 1) {
+ supervisor_enable_tick();
+ }
}
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c
index 1945da207..f7c431a56 100644
--- a/ports/esp32s2/common-hal/wifi/Radio.c
+++ b/ports/esp32s2/common-hal/wifi/Radio.c
@@ -142,6 +142,13 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
} else {
config->sta.bssid_set = 0;
}
+ // If channel is 0 (default/unset) and BSSID is not given, do a full scan instead of fast scan
+ // This will ensure that the best AP in range is chosen automatically
+ if ((config->sta.bssid_set == 0) && (config->sta.channel == 0)) {
+ config->sta.scan_method = WIFI_ALL_CHANNEL_SCAN;
+ } else {
+ config->sta.scan_method = WIFI_FAST_SCAN;
+ }
esp_wifi_set_config(ESP_IF_WIFI_STA, config);
self->starting_retries = 5;
self->retries_left = 5;
diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c
index 833ef0623..f53e68fc2 100644
--- a/ports/esp32s2/common-hal/wifi/__init__.c
+++ b/ports/esp32s2/common-hal/wifi/__init__.c
@@ -88,14 +88,17 @@ static void event_handler(void* arg, esp_event_base_t event_base,
}
}
-static bool wifi_inited;
+static bool wifi_inited, wifi_ever_inited;
void common_hal_wifi_init(void) {
wifi_inited = true;
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
- ESP_ERROR_CHECK(esp_netif_init());
- ESP_ERROR_CHECK(esp_event_loop_create_default());
+ if (!wifi_ever_inited) {
+ ESP_ERROR_CHECK(esp_netif_init());
+ ESP_ERROR_CHECK(esp_event_loop_create_default());
+ }
+ wifi_ever_inited = true;
wifi_radio_obj_t* self = &common_hal_wifi_radio_obj;
self->netif = esp_netif_create_default_wifi_sta();
@@ -144,7 +147,6 @@ void wifi_reset(void) {
ESP_ERROR_CHECK(esp_wifi_deinit());
esp_netif_destroy(radio->netif);
radio->netif = NULL;
- ESP_ERROR_CHECK(esp_netif_deinit());
}
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address) {
diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk
index 26bb51611..93f222cb3 100644
--- a/ports/esp32s2/mpconfigport.mk
+++ b/ports/esp32s2/mpconfigport.mk
@@ -18,7 +18,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1
CIRCUITPY_COUNTIO = 1
-CIRCUITPY_FREQUENCYIO = 0
+CIRCUITPY_FREQUENCYIO = 1
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 1
CIRCUITPY_NVM = 0
diff --git a/ports/esp32s2/peripherals/timer.c b/ports/esp32s2/peripherals/timer.c
new file mode 100644
index 000000000..0ae140387
--- /dev/null
+++ b/ports/esp32s2/peripherals/timer.c
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "peripherals/timer.h"
+
+#define TIMER_FREE 1
+#define TIMER_BUSY 0
+
+static uint8_t timer_state[2][2];
+
+void peripherals_timer_reset(void) {
+ timer_index_t timer;
+ for (uint8_t i = 0; i < 2; i++) {
+ for (uint8_t j = 0; j < 2; j++) {
+ if (timer_state[i][j] == TIMER_BUSY) {
+ timer.idx = (timer_idx_t)j;
+ timer.group = (timer_group_t)i;
+ timer_state[i][j] = TIMER_FREE;
+ peripherals_timer_deinit(&timer);
+ }
+ }
+ }
+}
+
+void peripherals_timer_init(const timer_config_t * config, timer_index_t * timer) {
+ bool break_loop = false;
+
+ // get free timer
+ for (uint8_t i = 0; i < 2; i++) {
+ for (uint8_t j = 0; j < 2; j++) {
+ if (timer_state[i][j] == TIMER_FREE) {
+ timer->idx = (timer_idx_t)j;
+ timer->group = (timer_group_t)i;
+ timer_state[i][j] = TIMER_BUSY;
+ break_loop = true;
+ break;
+ } else if (i == 1 && j == 1) {
+ timer->idx = TIMER_MAX;
+ timer->group = TIMER_GROUP_MAX;
+ return;
+ }
+ }
+ if (break_loop) {break;}
+ }
+
+ // initialize timer module
+ timer_init(timer->group, timer->idx, config);
+ timer_set_counter_value(timer->group, timer->idx, 0);
+}
+
+void peripherals_timer_deinit(timer_index_t * timer) {
+ timer_deinit(timer->group, timer->idx);
+}
diff --git a/ports/esp32s2/peripherals/timer.h b/ports/esp32s2/peripherals/timer.h
new file mode 100644
index 000000000..8c9ebd91c
--- /dev/null
+++ b/ports/esp32s2/peripherals/timer.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H
+#define MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H
+
+#include "driver/timer.h"
+
+typedef struct {
+ timer_idx_t idx;
+ timer_group_t group;
+} timer_index_t;
+
+extern void peripherals_timer_init(const timer_config_t * config, timer_index_t * timer);
+extern void peripherals_timer_deinit(timer_index_t * timer);
+extern void peripherals_timer_reset(void);
+
+#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H
diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c
index f66a8511a..aff7dbda4 100644
--- a/ports/esp32s2/supervisor/port.c
+++ b/ports/esp32s2/supervisor/port.c
@@ -52,6 +52,7 @@
#include "peripherals/rmt.h"
#include "peripherals/pcnt.h"
+#include "peripherals/timer.h"
#include "components/heap/include/esp_heap_caps.h"
#include "components/soc/soc/esp32s2/include/soc/cache_memory.h"
@@ -128,6 +129,19 @@ void reset_port(void) {
peripherals_pcnt_reset();
#endif
+#if CIRCUITPY_FREQUENCYIO
+ peripherals_timer_reset();
+#endif
+
+#if CIRCUITPY_PULSEIO
+ esp32s2_peripherals_rmt_reset();
+ pulsein_reset();
+#endif
+
+#if CIRCUITPY_PWMIO
+ pwmout_reset();
+#endif
+
#if CIRCUITPY_RTC
rtc_reset();
#endif
@@ -196,14 +210,14 @@ uint32_t port_get_saved_word(void) {
}
uint64_t port_get_raw_ticks(uint8_t* subticks) {
- struct timeval tv_now;
- gettimeofday(&tv_now, NULL);
- // convert usec back to ticks
- uint64_t all_subticks = (uint64_t)(tv_now.tv_usec * 2) / 71;
+ // Convert microseconds to subticks of 1/32768 seconds
+ // 32768/1000000 = 64/15625 in lowest terms
+ // this arithmetic overflows after 570 years
+ int64_t all_subticks = esp_timer_get_time() * 512 / 15625;
if (subticks != NULL) {
*subticks = all_subticks % 32;
}
- return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32;
+ return all_subticks / 32;
}
// Enable 1/1024 second tick.
diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk
index c416700e3..86b0cb5ab 100644
--- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk
+++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk
@@ -20,3 +20,5 @@ LD_COMMON = boards/common_default.ld
LD_FILE = boards/STM32F401xe_boot.ld
# For debugging - also comment BOOTLOADER_OFFSET and BOARD_VTOR_DEFER
# LD_FILE = boards/STM32F401xe_fs.ld
+
+CIRCUITPY_ULAB = 0
diff --git a/ports/stm/boards/thunderpack/mpconfigboard.mk b/ports/stm/boards/thunderpack/mpconfigboard.mk
index d303582e0..8f645068d 100644
--- a/ports/stm/boards/thunderpack/mpconfigboard.mk
+++ b/ports/stm/boards/thunderpack/mpconfigboard.mk
@@ -15,3 +15,5 @@ MCU_PACKAGE = UFQFPN48
LD_COMMON = boards/common_nvm.ld
LD_FILE = boards/STM32F411_nvm.ld
+
+CIRCUITPY_ULAB = 0
diff --git a/ports/unix/modjni.c b/ports/unix/modjni.c
index 8ec5ae54d..82d1ccd55 100644
--- a/ports/unix/modjni.c
+++ b/ports/unix/modjni.c
@@ -102,9 +102,9 @@ STATIC void check_exception(void) {
mp_obj_t py_e = new_jobject(exc);
JJ1(ExceptionClear);
if (JJ(IsInstanceOf, exc, IndexException_class)) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, py_e));
+ mp_raise_arg1(&mp_type_IndexError, py_e);
}
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_Exception, py_e));
+ mp_raise_arg1(&mp_type_Exception, py_e);
}
}