From c466db250c1f2254c44e1ca067a93f489dabf931 Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Tue, 8 Aug 2017 14:19:35 -0300 Subject: USBH: testhal example: improve support for multiple FAT devices --- os/various/fatfs_bindings/fatfs.mk | 2 +- os/various/fatfs_bindings/fatfs_devices.h | 59 +++++++++++++++++++++++++++++ os/various/fatfs_bindings/fatfs_diskio.c | 63 ++++++++----------------------- 3 files changed, 76 insertions(+), 48 deletions(-) create mode 100644 os/various/fatfs_bindings/fatfs_devices.h (limited to 'os/various') diff --git a/os/various/fatfs_bindings/fatfs.mk b/os/various/fatfs_bindings/fatfs.mk index 238037e..e3ab0c7 100644 --- a/os/various/fatfs_bindings/fatfs.mk +++ b/os/various/fatfs_bindings/fatfs.mk @@ -4,4 +4,4 @@ FATFSSRC = ${CHIBIOS_CONTRIB}/os/various/fatfs_bindings/fatfs_diskio.c \ ${CHIBIOS}/ext/fatfs/src/ff.c \ ${CHIBIOS}/ext/fatfs/src/option/unicode.c -FATFSINC = ${CHIBIOS}/ext/fatfs/src +FATFSINC = ${CHIBIOS}/ext/fatfs/src ${CHIBIOS_CONTRIB}/os/various/fatfs_bindings diff --git a/os/various/fatfs_bindings/fatfs_devices.h b/os/various/fatfs_bindings/fatfs_devices.h new file mode 100644 index 0000000..5ec05ca --- /dev/null +++ b/os/various/fatfs_bindings/fatfs_devices.h @@ -0,0 +1,59 @@ +/* + ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio + Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail) + + 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. +*/ + +#ifndef FATFS_DEVICES_H_ +#define FATFS_DEVICES_H_ + +#include "hal.h" + +#if HAL_USE_MMC_SPI && HAL_USE_SDC +#error "cannot specify both MMC_SPI and SDC drivers" +#endif + +#if HAL_USE_MMC_SPI +extern MMCDriver MMCD1; +#elif HAL_USE_SDC +extern SDCDriver SDCD1; +#elif HAL_USBH_USE_MSD + +#else +#error "MMC_SPI, SDC or USBH_MSD driver must be specified" +#endif + +/*-----------------------------------------------------------------------*/ +/* Correspondence between physical drive number and physical drive. */ +#if HAL_USE_MMC_SPI +#define FATFSDEV_MMC 0 +#define FATFSDEV_MMC_DRIVE "0:" +#endif + +#if HAL_USE_SDC +#define FATFSDEV_SDC 0 +#define FATFSDEV_SDC_DRIVE "0:" +#endif + +#if HAL_USBH_USE_MSD +#if defined(FATFSDEV_MMC) || defined(FATFSDEV_SDC) +#define FATFSDEV_MSDLUN0 1 +#define FATFSDEV_MSDLUN0_DRIVE "1:" +#else +#define FATFSDEV_MSDLUN0 0 +#define FATFSDEV_MSDLUN0_DRIVE "0:" +#endif +#endif + +#endif /* FATFS_DEVICES_H_ */ diff --git a/os/various/fatfs_bindings/fatfs_diskio.c b/os/various/fatfs_bindings/fatfs_diskio.c index 9fa41e2..f80c85c 100644 --- a/os/various/fatfs_bindings/fatfs_diskio.c +++ b/os/various/fatfs_bindings/fatfs_diskio.c @@ -9,38 +9,7 @@ #include "ffconf.h" #include "diskio.h" #include "usbh/dev/msd.h" - -#if HAL_USE_MMC_SPI && HAL_USE_SDC -#error "cannot specify both MMC_SPI and SDC drivers" -#endif - -#if HAL_USE_MMC_SPI -extern MMCDriver MMCD1; -#elif HAL_USE_SDC -extern SDCDriver SDCD1; -#elif HAL_USBH_USE_MSD - -#else -#error "MMC_SPI, SDC or USBH_MSD driver must be specified" -#endif - -/*-----------------------------------------------------------------------*/ -/* Correspondence between physical drive number and physical drive. */ -#if HAL_USE_MMC_SPI -#define MMC 0 -#endif - -#if HAL_USE_SDC -#define SDC 0 -#endif - -#if HAL_USBH_USE_MSD -#if defined(MMC) || defined(SDC) -#define MSDLUN0 1 -#else -#define MSDLUN0 0 -#endif -#endif +#include "fatfs_devices.h" /*-----------------------------------------------------------------------*/ /* Inidialize a Drive */ @@ -53,7 +22,7 @@ DSTATUS disk_initialize ( switch (pdrv) { #if HAL_USE_MMC_SPI - case MMC: + case FATFSDEV_MMC: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MMCD1) != BLK_READY) @@ -62,7 +31,7 @@ DSTATUS disk_initialize ( stat |= STA_PROTECT; return stat; #elif HAL_USE_SDC - case SDC: + case FATFSDEV_SDC: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&SDCD1) != BLK_READY) @@ -72,7 +41,7 @@ DSTATUS disk_initialize ( return stat; #endif #if HAL_USBH_USE_MSD - case MSDLUN0: + case FATFSDEV_MSDLUN0: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY) @@ -96,7 +65,7 @@ DSTATUS disk_status ( switch (pdrv) { #if HAL_USE_MMC_SPI - case MMC: + case FATFSDEV_MMC: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MMCD1) != BLK_READY) @@ -105,7 +74,7 @@ DSTATUS disk_status ( stat |= STA_PROTECT; return stat; #elif HAL_USE_SDC - case SDC: + case FATFSDEV_SDC: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&SDCD1) != BLK_READY) @@ -115,7 +84,7 @@ DSTATUS disk_status ( return stat; #endif #if HAL_USBH_USE_MSD - case MSDLUN0: + case FATFSDEV_MSDLUN0: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY) @@ -140,7 +109,7 @@ DRESULT disk_read ( { switch (pdrv) { #if HAL_USE_MMC_SPI - case MMC: + case FATFSDEV_MMC: if (blkGetDriverState(&MMCD1) != BLK_READY) return RES_NOTRDY; if (mmcStartSequentialRead(&MMCD1, sector)) @@ -155,7 +124,7 @@ DRESULT disk_read ( return RES_ERROR; return RES_OK; #elif HAL_USE_SDC - case SDC: + case FATFSDEV_SDC: if (blkGetDriverState(&SDCD1) != BLK_READY) return RES_NOTRDY; if (sdcRead(&SDCD1, sector, buff, count)) @@ -163,7 +132,7 @@ DRESULT disk_read ( return RES_OK; #endif #if HAL_USBH_USE_MSD - case MSDLUN0: + case FATFSDEV_MSDLUN0: /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY) return RES_NOTRDY; @@ -189,7 +158,7 @@ DRESULT disk_write ( { switch (pdrv) { #if HAL_USE_MMC_SPI - case MMC: + case FATFSDEV_MMC: if (blkGetDriverState(&MMCD1) != BLK_READY) return RES_NOTRDY; if (mmcIsWriteProtected(&MMCD1)) @@ -206,7 +175,7 @@ DRESULT disk_write ( return RES_ERROR; return RES_OK; #elif HAL_USE_SDC - case SDC: + case FATFSDEV_SDC: if (blkGetDriverState(&SDCD1) != BLK_READY) return RES_NOTRDY; if (sdcWrite(&SDCD1, sector, buff, count)) @@ -214,7 +183,7 @@ DRESULT disk_write ( return RES_OK; #endif #if HAL_USBH_USE_MSD - case MSDLUN0: + case FATFSDEV_MSDLUN0: /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY) return RES_NOTRDY; @@ -239,7 +208,7 @@ DRESULT disk_ioctl ( { switch (pdrv) { #if HAL_USE_MMC_SPI - case MMC: + case FATFSDEV_MMC: switch (cmd) { case CTRL_SYNC: return RES_OK; @@ -257,7 +226,7 @@ DRESULT disk_ioctl ( return RES_PARERR; } #elif HAL_USE_SDC - case SDC: + case FATFSDEV_SDC: switch (cmd) { case CTRL_SYNC: return RES_OK; @@ -282,7 +251,7 @@ DRESULT disk_ioctl ( } #endif #if HAL_USBH_USE_MSD - case MSDLUN0: + case FATFSDEV_MSDLUN0: switch (cmd) { case CTRL_SYNC: return RES_OK; -- cgit v1.2.3