From f4bf6556d1e6471962387b5256f05bf2a5100097 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 17 Sep 2024 10:00:50 +0200 Subject: [PATCH] chore: remove BSP_SD_DetectITConfig Interrupt have to be managed using Arduino interrupt API Signed-off-by: Frederic Pillon --- src/Sd2Card.cpp | 3 +- src/bsp_sd.c | 76 +++---------------------------------------------- src/bsp_sd.h | 3 +- 3 files changed, 6 insertions(+), 76 deletions(-) diff --git a/src/Sd2Card.cpp b/src/Sd2Card.cpp index 4178f84..5b96782 100644 --- a/src/Sd2Card.cpp +++ b/src/Sd2Card.cpp @@ -57,8 +57,7 @@ bool Sd2Card::init(uint32_t detect, uint32_t level) if (detect != SD_DETECT_NONE) { PinName p = digitalPinToPinName(detect); if ((p == NC) || \ - BSP_SD_DetectPin(set_GPIO_Port_Clock(STM_PORT(p)), - STM_LL_GPIO_PIN(p), level) != MSD_OK) { + BSP_SD_DetectPin(p, level) != MSD_OK) { return false; } } diff --git a/src/bsp_sd.c b/src/bsp_sd.c index 1cabd56..d624125 100644 --- a/src/bsp_sd.c +++ b/src/bsp_sd.c @@ -381,13 +381,14 @@ uint8_t BSP_SD_TransceiverPin(GPIO_TypeDef *enport, uint32_t enpin, GPIO_TypeDef /** * @brief Set the SD card device detect pin, port and level. - * @param port one of the gpio port - * @param pin one of the gpio pin + * @param p PinName of the detect pin * @param level the level of the detect pin (HIGH or LOW) * @retval SD status */ -uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin, uint32_t level) +uint8_t BSP_SD_DetectPin(PinName p, uint32_t level) { + GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(p)); + uint32_t pin = STM_LL_GPIO_PIN(p); if (port != 0) { SD_detect_ll_gpio_pin = pin; SD_detect_gpio_port = port; @@ -397,75 +398,6 @@ uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin, uint32_t level) return MSD_ERROR; } -/** - * @brief Configures Interrupt mode for SD detection pin. - * @retval Status - */ -uint8_t BSP_SD_DetectITConfig(void (*callback)(void)) -{ - uint8_t sd_state = MSD_ERROR; - if (SD_detect_ll_gpio_pin != LL_GPIO_PIN_ALL) { - LL_GPIO_SetPinPull(SD_detect_gpio_port, SD_detect_ll_gpio_pin, LL_GPIO_PULL_UP); - uint16_t SD_detect_gpio_pin = GPIO_PIN_All; - switch (SD_detect_ll_gpio_pin) { - case LL_GPIO_PIN_0: - SD_detect_gpio_pin = GPIO_PIN_0; - break; - case LL_GPIO_PIN_1: - SD_detect_gpio_pin = GPIO_PIN_1; - break; - case LL_GPIO_PIN_2: - SD_detect_gpio_pin = GPIO_PIN_2; - break; - case LL_GPIO_PIN_3: - SD_detect_gpio_pin = GPIO_PIN_3; - break; - case LL_GPIO_PIN_4: - SD_detect_gpio_pin = GPIO_PIN_4; - break; - case LL_GPIO_PIN_5: - SD_detect_gpio_pin = GPIO_PIN_5; - break; - case LL_GPIO_PIN_6: - SD_detect_gpio_pin = GPIO_PIN_6; - break; - case LL_GPIO_PIN_7: - SD_detect_gpio_pin = GPIO_PIN_7; - break; - case LL_GPIO_PIN_8: - SD_detect_gpio_pin = GPIO_PIN_8; - break; - case LL_GPIO_PIN_9: - SD_detect_gpio_pin = GPIO_PIN_9; - break; - case LL_GPIO_PIN_10: - SD_detect_gpio_pin = GPIO_PIN_10; - break; - case LL_GPIO_PIN_11: - SD_detect_gpio_pin = GPIO_PIN_11; - break; - case LL_GPIO_PIN_12: - SD_detect_gpio_pin = GPIO_PIN_12; - break; - case LL_GPIO_PIN_13: - SD_detect_gpio_pin = GPIO_PIN_13; - break; - case LL_GPIO_PIN_14: - SD_detect_gpio_pin = GPIO_PIN_14; - break; - case LL_GPIO_PIN_15: - SD_detect_gpio_pin = GPIO_PIN_15; - break; - default: - Error_Handler(); - break; - } - stm32_interrupt_enable(SD_detect_gpio_port, SD_detect_gpio_pin, callback, GPIO_MODE_IT_RISING_FALLING); - sd_state = MSD_OK; - } - return sd_state; -} - /** * @brief Detects if SD card is correctly plugged in the memory slot or not. * @retval Returns if SD is detected or not diff --git a/src/bsp_sd.h b/src/bsp_sd.h index e964403..bf95f49 100644 --- a/src/bsp_sd.h +++ b/src/bsp_sd.h @@ -174,8 +174,7 @@ uint8_t BSP_SD_DeInit(void); #if defined(USE_SD_TRANSCEIVER) && (USE_SD_TRANSCEIVER != 0U) uint8_t BSP_SD_TransceiverPin(GPIO_TypeDef *enport, uint32_t enpin, GPIO_TypeDef *selport, uint32_t selpin); #endif -uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin, uint32_t level); -uint8_t BSP_SD_DetectITConfig(void (*callback)(void)); +uint8_t BSP_SD_DetectPin(PinName p, uint32_t level); uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout); uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout); uint8_t BSP_SD_Erase(uint64_t StartAddr, uint64_t EndAddr);