-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform/nuttx): add usbd_fs & usbh_serial
Signed-off-by: sakumisu <[email protected]>
- Loading branch information
Showing
3 changed files
with
372 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2025, sakumisu | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <nuttx/fs/fs.h> | ||
|
||
#include "usbd_core.h" | ||
#include "usbd_msc.h" | ||
|
||
#ifndef CONFIG_USBDEV_MSC_THREAD | ||
#error "CONFIG_USBDEV_MSC_THREAD must be enabled" | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_DEVPATH0 | ||
#define CONFIG_USBDEV_MSC_DEVPATH0 "/dev/ram1" | ||
#endif | ||
|
||
static FAR struct inode *inode; | ||
static struct geometry geo; | ||
|
||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size) | ||
{ | ||
int ret; | ||
|
||
/* Open the block driver */ | ||
|
||
ret = open_blockdriver(CONFIG_USBDEV_MSC_DEVPATH0, 0, &inode); | ||
if (ret < 0) { | ||
*block_num = 0; | ||
*block_size = 0; | ||
return; | ||
} | ||
|
||
/* Get the drive geometry */ | ||
|
||
if (!inode || !inode->u.i_bops || !inode->u.i_bops->geometry || | ||
inode->u.i_bops->geometry(inode, &geo) != OK || !geo.geo_available) { | ||
*block_num = 0; | ||
*block_size = 0; | ||
return; | ||
} | ||
|
||
*block_num = geo.geo_nsectors; | ||
*block_size = geo.geo_sectorsize; | ||
|
||
USB_LOG_INFO("block_num: %ld, block_size: %ld\n", *block_num, *block_size); | ||
} | ||
|
||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length) | ||
{ | ||
if (inode->u.i_bops->read) { | ||
inode->u.i_bops->read(inode, buffer, sector, length / geo.geo_sectorsize); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length) | ||
{ | ||
if (inode->u.i_bops->write) { | ||
inode->u.i_bops->write(inode, buffer, sector, length / geo.geo_sectorsize); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.