/* Send SET_DATA_WIDTH command to set SD bus width.  */
static status_t SD_SetDataBusWidth(sd_card_t *card, sd_data_bus_width_t width)
/* Send SET_DATA_WIDTH command to set SD bus width.  */
static status_t SD_SetDataBusWidth(sd_card_t *card, sd_data_bus_width_t width)
{
    assert(card);
    sdhc_transfer_t content = {0};
    sdhc_command_t command = {0};
    if (kStatus_Success != SD_SendApplicationCmd(card))
    {
        return kStatus_SDMMC_SendApplicationCommandFailed;
    }
    command.index = kSD_ApplicationSetBusWdith;
    command.responseType = kSDHC_ResponseTypeR1;
    switch (width)
    {
        case kSD_DataBusWidth1Bit:
            command.argument = 0U;
            break;
        case kSD_DataBusWidth4Bit:
            command.argument = 2U;
            break;
        default:
            return kStatus_InvalidArgument;
    }
    content.command = &command;
    content.data = NULL;
    if ((kStatus_Success != card->host.transfer(card->host.base, &content)) ||
        ((command.response[0U]) & kSDMMC_R1ErrorAllFlag))
    {
        return kStatus_SDMMC_TransferFailed;
    }
    return kStatus_Success;
}