Files
luban-lite-t3e-pro/bsp/artinchip/drv/sdmc/drv_sdcard.c

63 lines
1.5 KiB
C
Raw Normal View History

2023-11-09 20:19:51 +08:00
/*
2025-01-08 19:12:06 +08:00
* Copyright (c) 2023-2024, ArtInChip Technology Co., Ltd
2023-11-09 20:19:51 +08:00
*
* SPDX-License-Identifier: Apache-2.0
*
2024-04-03 16:40:57 +08:00
* Authors: zrq <ruiqi.zheng@artinchip.com>
2023-11-09 20:19:51 +08:00
*/
#include "aic_core.h"
2025-01-08 19:12:06 +08:00
#ifdef AIC_SDMC1_USING_HOTPLUG
2023-11-09 20:19:51 +08:00
#include <drivers/mmcsd_core.h>
#include <dfs_fs.h>
2025-01-08 19:12:06 +08:00
#define HOTPLUG_SDMC 1
#define SD_CHECK_PIN (rt_pin_get(AIC_SDMC1_HOTPLUG_PIN))
#define SD_DEVICE "sd0"
2023-11-09 20:19:51 +08:00
2025-01-08 19:12:06 +08:00
extern void aic_mmcsd_change(u8 id);
2023-11-09 20:19:51 +08:00
static void sd_hotplug_detection_thread(void *parameter)
{
rt_uint8_t re_sd_check_pin = 1;
rt_device_t device;
2025-01-08 19:12:06 +08:00
rt_thread_mdelay(500);
2023-11-09 20:19:51 +08:00
while (1)
{
rt_thread_mdelay(200);
if (re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) == 0) {
printf("card insertion detected!\n");
2025-01-08 19:12:06 +08:00
device = rt_device_find(SD_DEVICE);
2023-11-09 20:19:51 +08:00
if (device == NULL)
2025-01-08 19:12:06 +08:00
aic_mmcsd_change(HOTPLUG_SDMC);
2023-11-09 20:19:51 +08:00
}
if (!re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) != 0) {
printf("card removal detected!\n");
2025-01-08 19:12:06 +08:00
aic_mmcsd_change(HOTPLUG_SDMC);
2023-11-09 20:19:51 +08:00
}
}
}
int aic_sd_hotplug_detection(void)
{
rt_thread_t tid;
rt_pin_mode(SD_CHECK_PIN, PIN_MODE_INPUT_PULLUP);
tid = rt_thread_create("sd_hotplug_detection", sd_hotplug_detection_thread, RT_NULL,
2025-01-08 19:12:06 +08:00
2048, RT_THREAD_PRIORITY_MAX - 2, 20);
2023-11-09 20:19:51 +08:00
if (tid != RT_NULL)
rt_thread_startup(tid);
else
printf("create sd_hotplug_detection thread err!\n");
return RT_EOK;
}
2025-01-08 19:12:06 +08:00
INIT_LATE_APP_EXPORT(aic_sd_hotplug_detection);
2023-11-09 20:19:51 +08:00
#endif