summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-06-24 12:46:36 -0700
committerScott Shawcroft <scott@tannewt.org>2020-06-24 13:10:08 -0700
commited6e81d688469138b555f3579b1083f521485382 (patch)
tree3dda2a2baaa10c3668af0b191e56260ef6c6f620
parent496e16d99b2277a09ab8a518ee94450653e63317 (diff)
Switch SPI to polling DMA and enable displayio
-rw-r--r--ports/esp32s2/background.c6
-rw-r--r--ports/esp32s2/boards/espressif_saola_1_wrover/board.c8
-rw-r--r--ports/esp32s2/common-hal/busio/I2C.c5
-rw-r--r--ports/esp32s2/common-hal/busio/SPI.c82
-rw-r--r--ports/esp32s2/common-hal/busio/SPI.h4
-rw-r--r--ports/esp32s2/common-hal/displayio/ParallelBus.c66
-rw-r--r--ports/esp32s2/common-hal/displayio/ParallelBus.h36
-rw-r--r--ports/esp32s2/common-hal/microcontroller/Pin.c2
-rw-r--r--ports/esp32s2/common-hal/microcontroller/Pin.h1
-rw-r--r--ports/esp32s2/modules/wroom.c12
-rw-r--r--ports/esp32s2/modules/wrover.c14
-rw-r--r--ports/esp32s2/mpconfigport.mk2
-rw-r--r--shared-module/displayio/Display.h4
-rw-r--r--shared-module/displayio/EPaperDisplay.h1
14 files changed, 183 insertions, 60 deletions
diff --git a/ports/esp32s2/background.c b/ports/esp32s2/background.c
index e22cf4aac..e979d7831 100644
--- a/ports/esp32s2/background.c
+++ b/ports/esp32s2/background.c
@@ -54,9 +54,9 @@ void run_background_tasks(void) {
running_background_tasks = true;
filesystem_background();
- // #if CIRCUITPY_DISPLAYIO
- // displayio_background();
- // #endif
+ #if CIRCUITPY_DISPLAYIO
+ displayio_background();
+ #endif
running_background_tasks = false;
assert_heap_ok();
diff --git a/ports/esp32s2/boards/espressif_saola_1_wrover/board.c b/ports/esp32s2/boards/espressif_saola_1_wrover/board.c
index b7b2c4ef5..9f708874b 100644
--- a/ports/esp32s2/boards/espressif_saola_1_wrover/board.c
+++ b/ports/esp32s2/boards/espressif_saola_1_wrover/board.c
@@ -30,12 +30,12 @@
void board_init(void) {
// USB
- never_reset_pin(&pin_GPIO19);
- never_reset_pin(&pin_GPIO20);
+ common_hal_never_reset_pin(&pin_GPIO19);
+ common_hal_never_reset_pin(&pin_GPIO20);
// Debug UART
- never_reset_pin(&pin_GPIO43);
- never_reset_pin(&pin_GPIO44);
+ common_hal_never_reset_pin(&pin_GPIO43);
+ common_hal_never_reset_pin(&pin_GPIO44);
}
bool board_requests_safe_mode(void) {
diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c
index 51817c95e..391d7323c 100644
--- a/ports/esp32s2/common-hal/busio/I2C.c
+++ b/ports/esp32s2/common-hal/busio/I2C.c
@@ -31,6 +31,7 @@
#include "driver/i2c.h"
#include "shared-bindings/microcontroller/__init__.h"
+#include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h"
typedef enum {
@@ -217,6 +218,6 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
never_reset_i2c(self->i2c_num);
- never_reset_pin(self->scl_pin);
- never_reset_pin(self->sda_pin);
+ common_hal_never_reset_pin(self->scl_pin);
+ common_hal_never_reset_pin(self->sda_pin);
}
diff --git a/ports/esp32s2/common-hal/busio/SPI.c b/ports/esp32s2/common-hal/busio/SPI.c
index 9790c516f..686f44cbc 100644
--- a/ports/esp32s2/common-hal/busio/SPI.c
+++ b/ports/esp32s2/common-hal/busio/SPI.c
@@ -29,7 +29,7 @@
#include "py/runtime.h"
#include "boards/board.h"
-#include "common-hal/microcontroller/Pin.h"
+#include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/rgb_led_status.h"
#include "esp_log.h"
@@ -101,7 +101,8 @@ static bool spi_bus_is_free(spi_host_device_t host_id) {
}
static void spi_interrupt_handler(void *arg) {
- // busio_spi_obj_t *self = arg;
+ busio_spi_obj_t *self = arg;
+ ESP_LOGE(TAG, "SPI interrupt %p", self);
}
// The interrupt may get invoked by the bus lock.
@@ -148,7 +149,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
mp_raise_ValueError(translate("All SPI peripherals are in use"));
}
- esp_err_t result = spi_bus_initialize(host_id, &bus_config, 0 /* dma channel */);
+ esp_err_t result = spi_bus_initialize(host_id, &bus_config, host_id /* dma channel */);
if (result == ESP_ERR_NO_MEM) {
mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed"));
} else if (result == ESP_ERR_INVALID_ARG) {
@@ -183,34 +184,35 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
spi_bus_lock_set_bg_control(spi_bus_get_attr(host_id)->lock, spi_bus_intr_enable, spi_bus_intr_disable, self);
spi_hal_context_t* hal = &self->hal_context;
- hal->hw = NULL; // Set by spi_hal_init
- hal->dmadesc_tx = NULL;
- hal->dmadesc_rx = NULL;
- hal->dmadesc_n = 0;
+
+ // spi_hal_init clears the given hal context so set everything after.
+ spi_hal_init(hal, host_id);
+ hal->dmadesc_tx = &self->tx_dma;
+ hal->dmadesc_rx = &self->rx_dma;
+ hal->dmadesc_n = 1;
// We don't use native CS.
- hal->cs_setup = 0;
- hal->cs_hold = 0;
- hal->cs_pin_id = 0;
+ // hal->cs_setup = 0;
+ // hal->cs_hold = 0;
+ // hal->cs_pin_id = 0;
hal->sio = 1;
- hal->half_duplex = 0;
- hal->tx_lsbfirst = 0;
- hal->rx_lsbfirst = 0;
- hal->dma_enabled = 0;
+ // hal->half_duplex = 0;
+ // hal->tx_lsbfirst = 0;
+ // hal->rx_lsbfirst = 0;
+ hal->dma_enabled = 1;
hal->no_compensate = 1;
// Ignore CS bits
// We don't use cmd, addr or dummy bits.
- hal->cmd = 0;
- hal->cmd_bits = 0;
- hal->addr_bits = 0;
- hal->dummy_bits = 0;
- hal->addr = 0;
+ // hal->cmd = 0;
+ // hal->cmd_bits = 0;
+ // hal->addr_bits = 0;
+ // hal->dummy_bits = 0;
+ // hal->addr = 0;
hal->io_mode = SPI_LL_IO_MODE_NORMAL;
- spi_hal_init(hal, host_id);
// This must be set after spi_hal_init.
hal->timing_conf = &self->timing_conf;
if (hal->hw == NULL) {
@@ -223,9 +225,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
spi_never_reset[self->host_id] = true;
- never_reset_pin(self->clock_pin);
- never_reset_pin(self->MOSI_pin);
- never_reset_pin(self->MISO_pin);
+ common_hal_never_reset_pin(self->clock_pin);
+ common_hal_never_reset_pin(self->MOSI_pin);
+ common_hal_never_reset_pin(self->MISO_pin);
}
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
@@ -322,17 +324,29 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
}
spi_hal_context_t* hal = &self->hal_context;
- hal->tx_bitlen = len * self->bits;
- hal->rx_bitlen = len * self->bits;
- hal->send_buffer = (uint8_t*) data_out;
- hal->rcv_buffer = data_in;
-
- spi_hal_setup_trans(hal);
- spi_hal_prepare_data(hal);
- spi_hal_user_start(hal);
- if (len >= SOC_SPI_MAXIMUM_BUFFER_SIZE && false) {
- // Set up the interrupt and wait on the lock.
- } else {
+ hal->send_buffer = NULL;
+ hal->rcv_buffer = NULL;
+ // This rounds up.
+ size_t dma_count = (len + LLDESC_MAX_NUM_PER_DESC - 1) / LLDESC_MAX_NUM_PER_DESC;
+ for (size_t i = 0; i < dma_count; i++) {
+ size_t offset = LLDESC_MAX_NUM_PER_DESC * i;
+ size_t dma_len = len - offset;
+ if (dma_len > LLDESC_MAX_NUM_PER_DESC) {
+ dma_len = LLDESC_MAX_NUM_PER_DESC;
+ }
+ hal->tx_bitlen = dma_len * self->bits;
+ hal->rx_bitlen = dma_len * self->bits;
+ if (data_out != NULL) {
+ hal->send_buffer = (uint8_t*) data_out + offset;
+ }
+ if (data_in != NULL) {
+ hal->rcv_buffer = data_in + offset;
+ }
+
+ spi_hal_setup_trans(hal);
+ spi_hal_prepare_data(hal);
+ spi_hal_user_start(hal);
+ // TODO: Switch to waiting on a lock that is given by an interrupt.
while (!spi_hal_usr_is_done(hal)) {
RUN_BACKGROUND_TASKS;
}
diff --git a/ports/esp32s2/common-hal/busio/SPI.h b/ports/esp32s2/common-hal/busio/SPI.h
index 38fbe42ff..6d8203831 100644
--- a/ports/esp32s2/common-hal/busio/SPI.h
+++ b/ports/esp32s2/common-hal/busio/SPI.h
@@ -44,6 +44,10 @@ typedef struct {
spi_hal_context_t hal_context;
spi_hal_timing_conf_t timing_conf;
intr_handle_t interrupt;
+ // IDF allocates these in DMA accessible memory so they may need to move when
+ // we use external RAM for CircuitPython.
+ lldesc_t tx_dma;
+ lldesc_t rx_dma;
uint32_t target_frequency;
int32_t real_frequency;
uint8_t polarity;
diff --git a/ports/esp32s2/common-hal/displayio/ParallelBus.c b/ports/esp32s2/common-hal/displayio/ParallelBus.c
new file mode 100644
index 000000000..314b72ff7
--- /dev/null
+++ b/ports/esp32s2/common-hal/displayio/ParallelBus.c
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Lucian Copeland 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 "shared-bindings/displayio/ParallelBus.h"
+
+#include <stdint.h>
+
+#include "common-hal/microcontroller/Pin.h"
+#include "py/runtime.h"
+#include "shared-bindings/digitalio/DigitalInOut.h"
+#include "shared-bindings/microcontroller/__init__.h"
+
+void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* self,
+ const mcu_pin_obj_t* data0, const mcu_pin_obj_t* command, const mcu_pin_obj_t* chip_select,
+ const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {
+
+ mp_raise_NotImplementedError(translate("ParallelBus not yet supported"));
+}
+
+void common_hal_displayio_parallelbus_deinit(displayio_parallelbus_obj_t* self) {
+
+}
+
+bool common_hal_displayio_parallelbus_reset(mp_obj_t obj) {
+ return false;
+}
+
+bool common_hal_displayio_parallelbus_bus_free(mp_obj_t obj) {
+ return false;
+}
+
+bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
+
+ return false;
+}
+
+void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+
+}
+
+void common_hal_displayio_parallelbus_end_transaction(mp_obj_t obj) {
+
+}
diff --git a/ports/esp32s2/common-hal/displayio/ParallelBus.h b/ports/esp32s2/common-hal/displayio/ParallelBus.h
new file mode 100644
index 000000000..cd636921d
--- /dev/null
+++ b/ports/esp32s2/common-hal/displayio/ParallelBus.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Lucian Copeland 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.
+ */
+
+#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DISPLAYIO_PARALLELBUS_H
+#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DISPLAYIO_PARALLELBUS_H
+
+#include "common-hal/digitalio/DigitalInOut.h"
+
+typedef struct {
+ mp_obj_base_t base;
+} displayio_parallelbus_obj_t;
+
+#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DISPLAYIO_PARALLELBUS_H
diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.c b/ports/esp32s2/common-hal/microcontroller/Pin.c
index 075f80abc..5a059f0bb 100644
--- a/ports/esp32s2/common-hal/microcontroller/Pin.c
+++ b/ports/esp32s2/common-hal/microcontroller/Pin.c
@@ -42,7 +42,7 @@ void never_reset_pin_number(gpio_num_t pin_number) {
never_reset_pins[pin_number / 32] |= 1 << pin_number % 32;
}
-void never_reset_pin(const mcu_pin_obj_t* pin) {
+void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
never_reset_pin_number(pin->number);
}
diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.h b/ports/esp32s2/common-hal/microcontroller/Pin.h
index ab06b388f..19985bda6 100644
--- a/ports/esp32s2/common-hal/microcontroller/Pin.h
+++ b/ports/esp32s2/common-hal/microcontroller/Pin.h
@@ -42,6 +42,5 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin);
void claim_pin(const mcu_pin_obj_t* pin);
bool pin_number_is_free(gpio_num_t pin_number);
void never_reset_pin_number(gpio_num_t pin_number);
-void never_reset_pin(const mcu_pin_obj_t* pin);
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_MICROCONTROLLER_PIN_H
diff --git a/ports/esp32s2/modules/wroom.c b/ports/esp32s2/modules/wroom.c
index 16c586118..5e530701b 100644
--- a/ports/esp32s2/modules/wroom.c
+++ b/ports/esp32s2/modules/wroom.c
@@ -28,10 +28,10 @@
void never_reset_module_internal_pins(void) {
// SPI Flash
- never_reset_pin(&pin_GPIO27);
- never_reset_pin(&pin_GPIO28);
- never_reset_pin(&pin_GPIO29);
- never_reset_pin(&pin_GPIO30);
- never_reset_pin(&pin_GPIO31);
- never_reset_pin(&pin_GPIO32);
+ common_hal_never_reset_pin(&pin_GPIO27);
+ common_hal_never_reset_pin(&pin_GPIO28);
+ common_hal_never_reset_pin(&pin_GPIO29);
+ common_hal_never_reset_pin(&pin_GPIO30);
+ common_hal_never_reset_pin(&pin_GPIO31);
+ common_hal_never_reset_pin(&pin_GPIO32);
}
diff --git a/ports/esp32s2/modules/wrover.c b/ports/esp32s2/modules/wrover.c
index d589a8fd4..23fa7ee5c 100644
--- a/ports/esp32s2/modules/wrover.c
+++ b/ports/esp32s2/modules/wrover.c
@@ -28,11 +28,11 @@
void never_reset_module_internal_pins(void) {
// SPI Flash and RAM
- never_reset_pin(&pin_GPIO26);
- never_reset_pin(&pin_GPIO27);
- never_reset_pin(&pin_GPIO28);
- never_reset_pin(&pin_GPIO29);
- never_reset_pin(&pin_GPIO30);
- never_reset_pin(&pin_GPIO31);
- never_reset_pin(&pin_GPIO32);
+ common_hal_never_reset_pin(&pin_GPIO26);
+ common_hal_never_reset_pin(&pin_GPIO27);
+ common_hal_never_reset_pin(&pin_GPIO28);
+ common_hal_never_reset_pin(&pin_GPIO29);
+ common_hal_never_reset_pin(&pin_GPIO30);
+ common_hal_never_reset_pin(&pin_GPIO31);
+ common_hal_never_reset_pin(&pin_GPIO32);
}
diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk
index 9f59c1b46..8e2745a8c 100644
--- a/ports/esp32s2/mpconfigport.mk
+++ b/ports/esp32s2/mpconfigport.mk
@@ -20,7 +20,7 @@ CIRCUITPY_BITBANGIO = 1
CIRCUITPY_BOARD = 1
CIRCUITPY_DIGITALIO = 1
CIRCUITPY_BUSIO = 1
-CIRCUITPY_DISPLAYIO = 0
+CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_MICROCONTROLLER = 1
diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h
index 8adaf597f..861a38fd7 100644
--- a/shared-module/displayio/Display.h
+++ b/shared-module/displayio/Display.h
@@ -29,7 +29,9 @@
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/displayio/Group.h"
+#if CIRCUITPY_PULSEIO
#include "shared-bindings/pulseio/PWMOut.h"
+#endif
#include "shared-module/displayio/area.h"
#include "shared-module/displayio/display_core.h"
@@ -39,7 +41,9 @@ typedef struct {
displayio_display_core_t core;
union {
digitalio_digitalinout_obj_t backlight_inout;
+ #if CIRCUITPY_PULSEIO
pulseio_pwmout_obj_t backlight_pwm;
+ #endif
};
uint64_t last_backlight_refresh;
uint64_t last_refresh_call;
diff --git a/shared-module/displayio/EPaperDisplay.h b/shared-module/displayio/EPaperDisplay.h
index d08bed546..3b9f6e368 100644
--- a/shared-module/displayio/EPaperDisplay.h
+++ b/shared-module/displayio/EPaperDisplay.h
@@ -29,7 +29,6 @@
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/displayio/Group.h"
-#include "shared-bindings/pulseio/PWMOut.h"
#include "shared-module/displayio/area.h"
#include "shared-module/displayio/display_core.h"