From 507864c4f16859a175c7170dcdfabcdda7ed6ee6 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Fri, 23 Sep 2022 15:51:43 +0800 Subject: [PATCH] sdio_slave: allow disabling highspeed mode --- components/driver/include/driver/sdio_slave.h | 3 +++ components/driver/sdio_slave.c | 2 +- components/hal/include/hal/sdio_slave_hal.h | 23 ++++++++----------- components/hal/include/hal/sdio_slave_types.h | 7 +++++- components/hal/sdio_slave_hal.c | 2 +- tools/ci/check_copyright_ignore.txt | 1 - 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/driver/include/driver/sdio_slave.h b/components/driver/include/driver/sdio_slave.h index f9ec3f9c72c..6d05406bb76 100644 --- a/components/driver/include/driver/sdio_slave.h +++ b/components/driver/include/driver/sdio_slave.h @@ -48,6 +48,9 @@ typedef struct { the internal pull-ups are not sufficient for stable communication, please do connect external pull-ups on the bus. This is only for example and debug use. */ +#define SDIO_SLAVE_FLAG_DEFAULT_SPEED BIT(3) /**< Disable the highspeed support of the hardware. */ +#define SDIO_SLAVE_FLAG_HIGH_SPEED 0 /**< Enable the highspeed support of the hardware. This is the + default option. The host will see highspeed capability, but the mode actually used is determined by the host. */ } sdio_slave_config_t; /** Handle of a receive buffer, register a handle by calling ``sdio_slave_recv_register_buf``. Use the handle to load the buffer to the diff --git a/components/driver/sdio_slave.c b/components/driver/sdio_slave.c index e0e848b51ed..82347167917 100644 --- a/components/driver/sdio_slave.c +++ b/components/driver/sdio_slave.c @@ -230,6 +230,7 @@ static esp_err_t init_context(const sdio_slave_config_t *config) context.hal->sending_mode = config->sending_mode; context.hal->timing = config->timing; + context.hal->no_highspeed = (config->flags & SDIO_SLAVE_FLAG_DEFAULT_SPEED) == SDIO_SLAVE_FLAG_DEFAULT_SPEED; context.hal->send_queue_size = config->send_queue_size; context.hal->recv_buffer_size = config->recv_buffer_size; //initialize ringbuffer resources @@ -312,7 +313,6 @@ static inline esp_err_t sdio_slave_hw_init(sdio_slave_config_t *config) periph_module_enable(PERIPH_SDIO_SLAVE_MODULE); sdio_slave_hal_hw_init(context.hal); - return ESP_OK; } diff --git a/components/hal/include/hal/sdio_slave_hal.h b/components/hal/include/hal/sdio_slave_hal.h index 5b252ea9ba6..210cedd4bd1 100644 --- a/components/hal/include/hal/sdio_slave_hal.h +++ b/components/hal/include/hal/sdio_slave_hal.h @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -210,6 +202,10 @@ typedef struct { * configured before using the HAL. `SDIO_SLAVE_TIMING_PSEND_PSAMPLE` is * recommended by default. */ + //some boolean flags + struct { + uint32_t no_highspeed: 1; /**< Disable the highspeed support */ + }; int send_queue_size; /**< Max buffers that can be queued before sending. Should be manually * configured before using the HAL. */ @@ -220,6 +216,7 @@ typedef struct { sdio_ringbuf_t send_desc_queue; /**< The ring buffer used to hold queued descriptors. Should be manually * initialized before using the HAL. */ + //Internal status, no need to touch. send_state_t send_state; // Current state of sending part. uint32_t tail_pkt_len; // The accumulated send length of the tail packet. diff --git a/components/hal/include/hal/sdio_slave_types.h b/components/hal/include/hal/sdio_slave_types.h index dc48dbeb666..56eaa2a3344 100644 --- a/components/hal/include/hal/sdio_slave_types.h +++ b/components/hal/include/hal/sdio_slave_types.h @@ -25,9 +25,14 @@ typedef enum { /// Timing of SDIO slave typedef enum { SDIO_SLAVE_TIMING_PSEND_PSAMPLE = 0,/**< Send at posedge, and sample at posedge. Default value for HS mode. + * If :c:macro:`SDIO_SLAVE_FLAG_HIGH_SPEED` is specified in + * :cpp:class:`sdio_slave_config_t`, this should be selected. * Normally there's no problem using this to work in DS mode. */ - SDIO_SLAVE_TIMING_NSEND_PSAMPLE ,///< Send at negedge, and sample at posedge. Default value for DS mode and below. + SDIO_SLAVE_TIMING_NSEND_PSAMPLE, /**< Send at negedge, and sample at posedge. Default value for DS mode and + * below. If :c:macro:`SDIO_SLAVE_FLAG_DEFAULT_SPEED` is specified in + * :cpp:class:`sdio_slave_config_t`, this should be selected. + */ SDIO_SLAVE_TIMING_PSEND_NSAMPLE, ///< Send at posedge, and sample at negedge SDIO_SLAVE_TIMING_NSEND_NSAMPLE, ///< Send at negedge, and sample at negedge } sdio_slave_timing_t; diff --git a/components/hal/sdio_slave_hal.c b/components/hal/sdio_slave_hal.c index efa28fab7dd..1e71cbf9539 100644 --- a/components/hal/sdio_slave_hal.c +++ b/components/hal/sdio_slave_hal.c @@ -168,7 +168,7 @@ void sdio_slave_hal_init(sdio_slave_context_t *hal) void sdio_slave_hal_hw_init(sdio_slave_context_t *hal) { sdio_slave_ll_init(hal->slc); - sdio_slave_ll_enable_hs(hal->hinf, true); + sdio_slave_ll_enable_hs(hal->hinf, !hal->no_highspeed); sdio_slave_ll_set_timing(hal->host, hal->timing); sdio_slave_ll_slvint_t intr_ena = 0xff; sdio_slave_ll_slvint_set_ena(hal->slc, &intr_ena); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 7160ebc59e1..d3cd710ce1d 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -745,7 +745,6 @@ components/hal/include/hal/esp_flash_err.h components/hal/include/hal/mpu_hal.h components/hal/include/hal/mpu_types.h components/hal/include/hal/rtc_io_types.h -components/hal/include/hal/sdio_slave_hal.h components/hal/include/hal/sdio_slave_ll.h components/hal/include/hal/sha_hal.h components/hal/include/hal/spi_flash_encrypt_hal.h