Skip to content

Commit

Permalink
chore: remove BSP_SD_DetectITConfig
Browse files Browse the repository at this point in the history
Interrupt have to be managed using Arduino interrupt API

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Sep 26, 2024
1 parent ac3768f commit f4bf655
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 76 deletions.
3 changes: 1 addition & 2 deletions src/Sd2Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
76 changes: 4 additions & 72 deletions src/bsp_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/bsp_sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f4bf655

Please sign in to comment.