Overwrite DiskIO functions from LPC framework to use Marlin Sd2Card API
This commit is contained in:
parent
21674b2879
commit
fdb698936e
1 changed files with 110 additions and 0 deletions
|
|
@ -79,4 +79,114 @@ uint8_t HAL_get_reset_source(void) {
|
||||||
return RST_POWER_ON;
|
return RST_POWER_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Overwrite DiskIO functions from LPC framework to use Marlin Sd2Card API.
|
||||||
|
// TODO: need a define to enable/disable it... maybe a file only for this code!
|
||||||
|
|
||||||
|
#include <chanfs/diskio.h>
|
||||||
|
#include "../../sd/cardreader.h"
|
||||||
|
|
||||||
|
DRESULT disk_read (
|
||||||
|
BYTE drv, /* Physical drive number (0) */
|
||||||
|
BYTE *buff, /* Pointer to the data buffer to store read data */
|
||||||
|
DWORD sector, /* Start sector number (LBA) */
|
||||||
|
UINT count /* Number of sectors to read (1..128) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto sd2card = card.getSd2Card();
|
||||||
|
if (count == 1) {
|
||||||
|
sd2card.readBlock(sector, buff);
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
sd2card.readStart(sector);
|
||||||
|
while (count--) {
|
||||||
|
sd2card.readData(buff);
|
||||||
|
buff += 512;
|
||||||
|
}
|
||||||
|
sd2card.readStop();
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSTATUS disk_status (
|
||||||
|
BYTE drv /* Physical drive number (0) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSTATUS disk_initialize (
|
||||||
|
BYTE drv /* Physical drive number (0) */
|
||||||
|
) {
|
||||||
|
//if already mounted, its already initialized!
|
||||||
|
if (card.isMounted()) {
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto sd2card = card.getSd2Card();
|
||||||
|
if (!sd2card.init(SPI_SPEED, SDSS)
|
||||||
|
#if defined(LCD_SDSS) && (LCD_SDSS != SDSS)
|
||||||
|
&& !sd2card.init(SPI_SPEED, LCD_SDSS)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
return RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _DISKIO_WRITE
|
||||||
|
DRESULT disk_write (
|
||||||
|
BYTE drv, /* Physical drive number (0) */
|
||||||
|
const BYTE *buff, /* Ponter to the data to write */
|
||||||
|
DWORD sector, /* Start sector number (LBA) */
|
||||||
|
UINT count /* Number of sectors to write (1..128) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto sd2card = card.getSd2Card();
|
||||||
|
if (count == 1) {
|
||||||
|
sd2card.writeBlock(sector, buff);
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
sd2card.writeStart(sector, count);
|
||||||
|
while (count--)
|
||||||
|
{
|
||||||
|
sd2card.writeData(buff);
|
||||||
|
buff += 512;
|
||||||
|
}
|
||||||
|
sd2card.writeStop();
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
#endif // _DISKIO_WRITE
|
||||||
|
|
||||||
|
#if _DISKIO_IOCTL
|
||||||
|
|
||||||
|
DRESULT disk_ioctl (
|
||||||
|
BYTE drv, /* Physical drive number (0) */
|
||||||
|
BYTE cmd, /* Control command code */
|
||||||
|
void *buff /* Pointer to the conrtol data */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DWORD *dp, st, ed;
|
||||||
|
|
||||||
|
auto sd2card = card.getSd2Card();
|
||||||
|
switch (cmd) {
|
||||||
|
case CTRL_SYNC: /* Wait for end of internal write process of the drive */
|
||||||
|
break;
|
||||||
|
case GET_SECTOR_COUNT: /* Get drive capacity in unit of sector (DWORD) */
|
||||||
|
*(int32_t*)buff = sd2card.cardSize();
|
||||||
|
break;
|
||||||
|
case GET_BLOCK_SIZE: /* Get erase block size in unit of sector (DWORD) */
|
||||||
|
break;
|
||||||
|
case CTRL_TRIM: /* Erase a block of sectors (used when _USE_TRIM in ffconf.h is 1) */
|
||||||
|
dp = (DWORD*)buff; st = dp[0]; ed = dp[1]; /* Load sector block */
|
||||||
|
sd2card.erase(st, ed);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _DISKIO_IOCTL
|
||||||
|
|
||||||
#endif // TARGET_LPC1768
|
#endif // TARGET_LPC1768
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue