Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MiscDrivers): Add API for Setting SDHC Data Width #1045

Merged
merged 9 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Examples/*/*/*/buildrv
.vscode/settings.json
Libraries/PeriphDrivers/Documentation/MAX*
Libraries/PeriphDrivers/bin
docs
Documentation/Libraries
Documentation/res
Examples/MAX78000/PowerTest
Expand Down Expand Up @@ -38,3 +37,5 @@ node_modules
package-lock.json
package.json
.python-version
mxc_version.h
mxc_version.mk
24 changes: 0 additions & 24 deletions Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't delete this

This file was deleted.

6 changes: 5 additions & 1 deletion Libraries/SDHC/Include/sdhc_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
typedef enum {
MXC_SDHC_LIB_SINGLE_DATA = 1,
MXC_SDHC_LIB_QUAD_DATA,
MXC_SDHC_LIB_DEFAULT_DATA,
} mxc_sdhc_data_width;

typedef enum {
Expand Down Expand Up @@ -123,7 +124,10 @@ int MXC_SDHC_Lib_WriteAsync(unsigned int dst_addr, void *src_addr, unsigned int

/* ************************************************************************** */
int MXC_SDHC_Lib_ReadAsync(void *dst_addr, unsigned int src_addr, unsigned int cnt, mxc_sdhc_data_width width, mxc_sdhc_callback_fn callback);

/* ************************************************************************** */
void MXC_SDHC_Set_Default_DataWidth(mxc_sdhc_data_width width);
/* ************************************************************************** */
mxc_sdhc_data_width MXC_SDHC_Get_Default_DataWidth(void);

/**@} end of group sdhc */

Expand Down
26 changes: 26 additions & 0 deletions Libraries/SDHC/Source/sdhc_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ int card_rca;
mxc_sdhc_lib_card_type card_type = CARD_NONE;
mxc_sdhc_csd_regs_t g_csd;
bool g_csd_is_cached = false;
static mxc_sdhc_data_width default_data_width = MXC_SDHC_LIB_SINGLE_DATA;

/* **** Functions **** */

Expand Down Expand Up @@ -236,6 +237,8 @@ int MXC_SDHC_Lib_SetBusWidth(mxc_sdhc_data_width bus_width)
uint32_t card_status;
int result;

bus_width = bus_width == MXC_SDHC_LIB_DEFAULT_DATA ? MXC_SDHC_Get_Default_DataWidth() : bus_width;
Copy link
Contributor

@Jake-Carter Jake-Carter Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be cleaner to come in "over the top" and avoid adding the extra enum value. A direct getter/setter to the state variable would work, so your call from diskio.c would look like:

MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_Get_DataWidth())

Usually you're not gonna change your data width more than once at run-time, so a mechanism for setting the default value might be better implemented as a build-time option. Users can use the setter API you've exposed on initialization.

This would let us avoid these modifications to sdhc_lib.c, since the data width is already an arg to the SDHC functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what is set as in diskio.c. The point of doing this extra step was to not break the API if someone uses it directly. Since Get/Set default data width doesn't really do more than allow us to get it at the higher level. It is a little Awkard that you set it and then have to pass it anyway. I am fine deleting those modifications though.


cmd_cfg.direction = MXC_SDHC_DIRECTION_CFG;
cmd_cfg.callback = NULL;

Expand Down Expand Up @@ -445,6 +448,9 @@ int MXC_SDHC_Lib_Prepare_Trans(mxc_sdhc_data_width width)
mxc_sdhc_cmd_cfg_t cmd_cfg;
int result;

width = width == MXC_SDHC_LIB_DEFAULT_DATA ? MXC_SDHC_Get_Default_DataWidth() : width;


cmd_cfg.direction = MXC_SDHC_DIRECTION_CFG;
cmd_cfg.arg_1 = 0;
cmd_cfg.host_control_1 = MXC_SDHC_Get_Host_Cn_1();
Expand Down Expand Up @@ -499,6 +505,8 @@ int MXC_SDHC_Lib_Write(unsigned int dst_addr, void *src_addr, unsigned int cnt,
int result;
mxc_sdhc_cmd_cfg_t cmd_cfg;

width = width == MXC_SDHC_LIB_DEFAULT_DATA ? MXC_SDHC_Get_Default_DataWidth() : width;

result = MXC_SDHC_Lib_Prepare_Trans(width);
if (result != E_NO_ERROR) {
return result;
Expand Down Expand Up @@ -527,6 +535,9 @@ int MXC_SDHC_Lib_Read(void *dst_addr, unsigned int src_addr, unsigned int cnt, m
int result;
mxc_sdhc_cmd_cfg_t cmd_cfg;

width = width == MXC_SDHC_LIB_DEFAULT_DATA ? MXC_SDHC_Get_Default_DataWidth() : width;


result = MXC_SDHC_Lib_Prepare_Trans(width);
if (result != E_NO_ERROR) {
return result;
Expand Down Expand Up @@ -555,6 +566,8 @@ int MXC_SDHC_Lib_WriteAsync(unsigned int dst_addr, void *src_addr, unsigned int
int data;
mxc_sdhc_cmd_cfg_t cmd_cfg;

width = width == MXC_SDHC_LIB_DEFAULT_DATA ? MXC_SDHC_Get_Default_DataWidth() : width;

data = MXC_SDHC_Lib_Prepare_Trans(width);
if (data == E_BUSY) {
return E_BUSY;
Expand Down Expand Up @@ -586,6 +599,8 @@ int MXC_SDHC_Lib_ReadAsync(void *dst_addr, unsigned int src_addr, unsigned int c
int data;
mxc_sdhc_cmd_cfg_t cmd_cfg;

width = width == MXC_SDHC_LIB_DEFAULT_DATA ? MXC_SDHC_Get_Default_DataWidth() : width;

data = MXC_SDHC_Lib_Prepare_Trans(width);
if (data == E_BUSY) {
return E_BUSY;
Expand All @@ -610,4 +625,15 @@ int MXC_SDHC_Lib_ReadAsync(void *dst_addr, unsigned int src_addr, unsigned int c

return MXC_SDHC_SendCommandAsync(&cmd_cfg);
}
void MXC_SDHC_Set_Default_DataWidth(mxc_sdhc_data_width width)
{
MXC_ASSERT(width == MXC_SDHC_LIB_SINGLE_DATA || width == MXC_SDHC_LIB_QUAD_DATA);
default_data_width = width;
}

mxc_sdhc_data_width MXC_SDHC_Get_Default_DataWidth(void)
{
return default_data_width;
}

/**@} end of group sdhc */
4 changes: 2 additions & 2 deletions Libraries/SDHC/ff13/Source/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ DRESULT disk_read (
switch(pdrv){
case DEV_SD:

if (MXC_SDHC_Lib_Read(buff, sector, count, MXC_SDHC_LIB_SINGLE_DATA) != E_NO_ERROR) {
if (MXC_SDHC_Lib_Read(buff, sector, count, MXC_SDHC_Get_Default_DataWidth()) != E_NO_ERROR) {
status = RES_ERROR;
} else {
status = RES_OK;
Expand Down Expand Up @@ -196,7 +196,7 @@ DRESULT disk_write (
switch(pdrv){
case DEV_SD:

if (MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_LIB_SINGLE_DATA) != E_NO_ERROR) {
if (MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_Get_Default_DataWidth()) != E_NO_ERROR) {
status = RES_ERROR;
} else {
status = RES_OK;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/SDHC/ff14/Source/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ DRESULT disk_read (
{
DRESULT status;

if (MXC_SDHC_Lib_Read(buff, sector, count, MXC_SDHC_LIB_SINGLE_DATA) != E_NO_ERROR) {
if (MXC_SDHC_Lib_Read(buff, sector, count, MXC_SDHC_Get_Default_DataWidth()) != E_NO_ERROR) {
status = RES_ERROR;
} else {
status = RES_OK;
Expand All @@ -135,7 +135,7 @@ DRESULT disk_write (
{
DRESULT status;

if (MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_LIB_SINGLE_DATA) != E_NO_ERROR) {
if (MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_Get_Default_DataWidth()) != E_NO_ERROR) {
status = RES_ERROR;
} else {
status = RES_OK;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/SDHC/ff15/source/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ DRESULT disk_read (
switch(pdrv){
case DEV_SD:

if (MXC_SDHC_Lib_Read(buff, sector, count, MXC_SDHC_LIB_SINGLE_DATA) != E_NO_ERROR) {
if (MXC_SDHC_Lib_Read(buff, sector, count, MXC_SDHC_Get_Default_DataWidth()) != E_NO_ERROR) {
status = RES_ERROR;
} else {
status = RES_OK;
Expand Down Expand Up @@ -196,7 +196,7 @@ DRESULT disk_write (
switch(pdrv){
case DEV_SD:

if (MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_LIB_SINGLE_DATA) != E_NO_ERROR) {
if (MXC_SDHC_Lib_Write(sector, (void *)buff, count, MXC_SDHC_Get_Default_DataWidth()) != E_NO_ERROR) {
status = RES_ERROR;
} else {
status = RES_OK;
Expand Down

This file was deleted.

37 changes: 0 additions & 37 deletions mxc_version.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this

This file was deleted.

Loading