drone-fatfs 0.2.3

Bindings to ChaN's FatFs.
//! FatFs runtime.

pub use drone_fatfs_raw::{
  ATA_GET_MODEL, ATA_GET_REV, ATA_GET_SN, BYTE, CTRL_EJECT, CTRL_FORMAT,
  CTRL_LOCK, CTRL_POWER, CTRL_SYNC, CTRL_TRIM, DRESULT, DSTATUS, DWORD,
  FF_MAX_SS, FF_MIN_SS, GET_BLOCK_SIZE, GET_SECTOR_COUNT, GET_SECTOR_SIZE,
  ISDIO_MRITE, ISDIO_READ, ISDIO_WRITE, MMC_GET_CID, MMC_GET_CSD, MMC_GET_OCR,
  MMC_GET_SDSTAT, MMC_GET_TYPE, STA_NODISK, STA_NOINIT, STA_PROTECT, UINT,
  WCHAR, WORD,
};

use core::char;
use fat_time::FatTime;

/// Low-level disk I/O layer.
pub trait Rt {
  /// Initializes the storage device.
  fn disk_initialize() -> u8;

  /// Inquires the current drive status.
  fn disk_status() -> u8;

  /// Controls device specific features and miscellaneous functions other than
  /// generic read/write.
  fn disk_ioctl(cmd: u8, buff: *mut u8) -> DRESULT;

  /// Reads data from the sector(s) of storage device.
  fn disk_read(buff: *mut u8, sector: u32, count: u32) -> DRESULT;

  /// Writes data to the sector(s) of storage device.
  fn disk_write(buff: *const u8, sector: u32, count: u32) -> DRESULT;
}

/// Real-time clock layer.
pub trait RtcRt {
  /// Returns the current time.
  fn get_current_time() -> FatTime;
}

#[doc(hidden)]
#[inline(always)]
pub fn ff_oem2uni(oem: WCHAR, _cp: WORD) -> WCHAR {
  if oem < 0x80 {
    oem
  } else {
    0
  }
}

#[doc(hidden)]
#[inline(always)]
pub fn ff_uni2oem(uni: DWORD, _cp: WORD) -> WCHAR {
  if uni < 0x80 {
    uni as _
  } else {
    0
  }
}

#[doc(hidden)]
#[inline(always)]
pub fn ff_wtoupper(uni: DWORD) -> DWORD {
  if let Some(c) = char::from_u32(uni as u32) {
    let mut iter = c.to_uppercase();
    if let Some(c) = iter.next() {
      if iter.next().is_none() {
        return c as _;
      }
    }
  }
  uni
}