STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { case BP_IOCTL_INIT: if (!sdcard_power_on()) { return MP_OBJ_NEW_SMALL_INT(-1); // error } return MP_OBJ_NEW_SMALL_INT(0); // success case BP_IOCTL_DEINIT: sdcard_power_off(); return MP_OBJ_NEW_SMALL_INT(0); // success case BP_IOCTL_SYNC: // nothing to do return MP_OBJ_NEW_SMALL_INT(0); // success case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(sdcard_get_capacity_in_bytes() / SDCARD_BLOCK_SIZE); case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(SDCARD_BLOCK_SIZE); default: // unknown command return MP_OBJ_NEW_SMALL_INT(-1); // error } }
DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber (0..) */ ) { switch (pdrv) { case PD_FLASH: storage_init(); return 0; #if MICROPY_HW_HAS_SDCARD case PD_SDCARD: if (!sdcard_power_on()) { return STA_NODISK; } // TODO return STA_PROTECT if SD card is read only return 0; #endif case PD_USER: if (MP_STATE_PORT(fs_user_mount) == NULL) { return STA_NODISK; } if (MP_STATE_PORT(fs_user_mount)->writeblocks[0] == MP_OBJ_NULL) { return STA_PROTECT; } return 0; } return STA_NOINIT; }
static mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { bool result; if (mp_obj_is_true(state)) { result = sdcard_power_on(); } else { sdcard_power_off(); result = true; } return MP_BOOL(result); }
STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { bool result; if (mp_obj_is_true(state)) { result = sdcard_power_on(); } else { sdcard_power_off(); result = true; } return mp_obj_new_bool(result); }
DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber (0..) */ ) { switch (pdrv) { case PD_FLASH: storage_init(); return 0; case PD_SDCARD: if (!sdcard_power_on()) { return STA_NODISK; } // TODO return STA_PROTECT if SD card is read only return 0; } return STA_NOINIT; }
/** * @brief Initialize the storage medium * @param lun : logical unit number * @retval Status */ int8_t SDCARD_STORAGE_Init(uint8_t lun) { /* #ifndef USE_STM3210C_EVAL NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); #endif if( SD_Init() != 0) { return (-1); } */ if (!sdcard_power_on()) { return -1; } return 0; }