Skip to content

Commit

Permalink
Allow constructing a Controller without specifying generic parameters
Browse files Browse the repository at this point in the history
Fixes #61
  • Loading branch information
jannic authored and eldruin committed Jan 18, 2023
1 parent a33b10f commit 51f29bd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changes
- Add `MAX_DIRS` and `MAX_FILES` generics to `Controller` to allow an arbitrary numbers of concurrent open directories and files.
- Add new constructor method `Controller::new_custom_max(block_device: D, timesource: T) -> Controller<D, T, MAX_DIRS, MAX_FILES>`
to create a `Controller` with custom limits.

## [Version 0.4.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.4.0)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let mut cont: Controller<
DummyTimeSource,
6,
12,
> = Controller::new(block, time_source);
> = Controller::new_custom_max(block, time_source);
```

## Supported features
Expand Down
2 changes: 1 addition & 1 deletion examples/create_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn main() {
.map_err(Error::DeviceError)
.unwrap();
println!("lbd: {:?}", lbd);
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
let mut controller = Controller::new(lbd, Clock);
for volume_idx in 0..=3 {
let volume = controller.get_volume(VolumeIdx(volume_idx));
println!("volume {}: {:#?}", volume_idx, volume);
Expand Down
2 changes: 1 addition & 1 deletion examples/delete_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn main() {
.map_err(Error::DeviceError)
.unwrap();
println!("lbd: {:?}", lbd);
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
let mut controller = Controller::new(lbd, Clock);
for volume_idx in 0..=3 {
let volume = controller.get_volume(VolumeIdx(volume_idx));
println!("volume {}: {:#?}", volume_idx, volume);
Expand Down
2 changes: 1 addition & 1 deletion examples/test_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn main() {
.map_err(Error::DeviceError)
.unwrap();
println!("lbd: {:?}", lbd);
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
let mut controller = Controller::new(lbd, Clock);
for i in 0..=3 {
let volume = controller.get_volume(VolumeIdx(i));
println!("volume {}: {:#?}", i, volume);
Expand Down
2 changes: 1 addition & 1 deletion examples/write_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn main() {
.map_err(Error::DeviceError)
.unwrap();
println!("lbd: {:?}", lbd);
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
let mut controller = Controller::new(lbd, Clock);
for volume_idx in 0..=3 {
let volume = controller.get_volume(VolumeIdx(volume_idx));
println!("volume {}: {:#?}", volume_idx, volume);
Expand Down
20 changes: 19 additions & 1 deletion src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ where
open_files: [(VolumeIdx, Cluster); MAX_FILES],
}

impl<D, T> Controller<D, T, 4, 4>
where
D: BlockDevice,
T: TimeSource,
<D as BlockDevice>::Error: core::fmt::Debug,
{
/// Create a new Disk Controller using a generic `BlockDevice`. From this
/// controller we can open volumes (partitions) and with those we can open
/// files.
///
/// This creates a Controller with default values
/// MAX_DIRS = 4, MAX_FILES = 4. Call `Controller::new_custom_max(block_device, timesource)`
/// if you need different limits.
pub fn new(block_device: D, timesource: T) -> Controller<D, T, 4, 4> {
Self::new_custom_max(block_device, timesource)
}
}

impl<D, T, const MAX_DIRS: usize, const MAX_FILES: usize> Controller<D, T, MAX_DIRS, MAX_FILES>
where
D: BlockDevice,
Expand All @@ -38,7 +56,7 @@ where
/// Create a new Disk Controller using a generic `BlockDevice`. From this
/// controller we can open volumes (partitions) and with those we can open
/// files.
pub fn new(block_device: D, timesource: T) -> Controller<D, T, MAX_DIRS, MAX_FILES> {
pub fn new_custom_max(block_device: D, timesource: T) -> Controller<D, T, MAX_DIRS, MAX_FILES> {
debug!("Creating new embedded-sdmmc::Controller");
Controller {
block_device,
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,9 @@ mod tests {

#[test]
fn partition0() {
let mut c: Controller<DummyBlockDevice, Clock, 4, 4> =
Controller::new(DummyBlockDevice, Clock);
let mut c: Controller<DummyBlockDevice, Clock, 2, 2> =
Controller::new_custom_max(DummyBlockDevice, Clock);

let v = c.get_volume(VolumeIdx(0)).unwrap();
assert_eq!(
v,
Expand Down

0 comments on commit 51f29bd

Please sign in to comment.