Skip to content

Commit deca72a

Browse files
authored
Merge pull request #2221 from armink/fix_sfud
[DeviceDriver][SFUD] Change the rt_sfud_flash_find() function position.
2 parents 1acb641 + 9e7254e commit deca72a

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

components/drivers/spi/spi_flash_sfud.c

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,35 @@ rt_err_t rt_sfud_flash_delete(rt_spi_flash_device_t spi_flash_dev) {
455455
return RT_EOK;
456456
}
457457

458+
sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
459+
{
460+
rt_spi_flash_device_t rtt_dev = RT_NULL;
461+
struct rt_spi_device *rt_spi_device = RT_NULL;
462+
sfud_flash_t sfud_dev = RT_NULL;
463+
464+
rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
465+
if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice)
466+
{
467+
rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
468+
goto error;
469+
}
470+
471+
rtt_dev = (rt_spi_flash_device_t)(rt_spi_device->user_data);
472+
if (rtt_dev && rtt_dev->user_data)
473+
{
474+
sfud_dev = (sfud_flash_t)(rtt_dev->user_data);
475+
return sfud_dev;
476+
}
477+
else
478+
{
479+
rt_kprintf("ERROR: SFUD flash device not found!\n");
480+
goto error;
481+
}
482+
483+
error:
484+
return RT_NULL;
485+
}
486+
458487
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
459488

460489
#include <finsh.h>
@@ -698,36 +727,6 @@ static void sf(uint8_t argc, char **argv) {
698727
}
699728
}
700729
MSH_CMD_EXPORT(sf, SPI Flash operate.);
701-
702-
sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
703-
{
704-
rt_spi_flash_device_t rtt_dev = RT_NULL;
705-
struct rt_spi_device *rt_spi_device = RT_NULL;
706-
sfud_flash_t sfud_dev = RT_NULL;
707-
708-
rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
709-
if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice)
710-
{
711-
rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
712-
goto error;
713-
}
714-
715-
rtt_dev = (rt_spi_flash_device_t)(rt_spi_device->user_data);
716-
if (rtt_dev && rtt_dev->user_data)
717-
{
718-
sfud_dev = (sfud_flash_t)(rtt_dev->user_data);
719-
return sfud_dev;
720-
}
721-
else
722-
{
723-
rt_kprintf("ERROR: SFUD flash device not found!\n");
724-
goto error;
725-
}
726-
727-
error:
728-
return RT_NULL;
729-
}
730-
731730
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */
732731

733732
#endif /* RT_USING_SFUD */

0 commit comments

Comments
 (0)