Switch SPI to polling DMA and enable displayio
This commit is contained in:
parent
496e16d99b
commit
ed6e81d688
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
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);
|
||||
if (len >= SOC_SPI_MAXIMUM_BUFFER_SIZE && false) {
|
||||
// Set up the interrupt and wait on the lock.
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue