Skip to content

Commit 51f29bd

Browse files
janniceldruin
authored andcommitted
Allow constructing a Controller without specifying generic parameters
Fixes #61
1 parent a33b10f commit 51f29bd

File tree

8 files changed

+29
-8
lines changed

8 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

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

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let mut cont: Controller<
4242
DummyTimeSource,
4343
6,
4444
12,
45-
> = Controller::new(block, time_source);
45+
> = Controller::new_custom_max(block, time_source);
4646
```
4747

4848
## Supported features

examples/create_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn main() {
118118
.map_err(Error::DeviceError)
119119
.unwrap();
120120
println!("lbd: {:?}", lbd);
121-
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
121+
let mut controller = Controller::new(lbd, Clock);
122122
for volume_idx in 0..=3 {
123123
let volume = controller.get_volume(VolumeIdx(volume_idx));
124124
println!("volume {}: {:#?}", volume_idx, volume);

examples/delete_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn main() {
118118
.map_err(Error::DeviceError)
119119
.unwrap();
120120
println!("lbd: {:?}", lbd);
121-
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
121+
let mut controller = Controller::new(lbd, Clock);
122122
for volume_idx in 0..=3 {
123123
let volume = controller.get_volume(VolumeIdx(volume_idx));
124124
println!("volume {}: {:#?}", volume_idx, volume);

examples/test_mount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn main() {
121121
.map_err(Error::DeviceError)
122122
.unwrap();
123123
println!("lbd: {:?}", lbd);
124-
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
124+
let mut controller = Controller::new(lbd, Clock);
125125
for i in 0..=3 {
126126
let volume = controller.get_volume(VolumeIdx(i));
127127
println!("volume {}: {:#?}", i, volume);

examples/write_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn main() {
118118
.map_err(Error::DeviceError)
119119
.unwrap();
120120
println!("lbd: {:?}", lbd);
121-
let mut controller: Controller<LinuxBlockDevice, Clock, 4, 4> = Controller::new(lbd, Clock);
121+
let mut controller = Controller::new(lbd, Clock);
122122
for volume_idx in 0..=3 {
123123
let volume = controller.get_volume(VolumeIdx(volume_idx));
124124
println!("volume {}: {:#?}", volume_idx, volume);

src/controller.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ where
2929
open_files: [(VolumeIdx, Cluster); MAX_FILES],
3030
}
3131

32+
impl<D, T> Controller<D, T, 4, 4>
33+
where
34+
D: BlockDevice,
35+
T: TimeSource,
36+
<D as BlockDevice>::Error: core::fmt::Debug,
37+
{
38+
/// Create a new Disk Controller using a generic `BlockDevice`. From this
39+
/// controller we can open volumes (partitions) and with those we can open
40+
/// files.
41+
///
42+
/// This creates a Controller with default values
43+
/// MAX_DIRS = 4, MAX_FILES = 4. Call `Controller::new_custom_max(block_device, timesource)`
44+
/// if you need different limits.
45+
pub fn new(block_device: D, timesource: T) -> Controller<D, T, 4, 4> {
46+
Self::new_custom_max(block_device, timesource)
47+
}
48+
}
49+
3250
impl<D, T, const MAX_DIRS: usize, const MAX_FILES: usize> Controller<D, T, MAX_DIRS, MAX_FILES>
3351
where
3452
D: BlockDevice,
@@ -38,7 +56,7 @@ where
3856
/// Create a new Disk Controller using a generic `BlockDevice`. From this
3957
/// controller we can open volumes (partitions) and with those we can open
4058
/// files.
41-
pub fn new(block_device: D, timesource: T) -> Controller<D, T, MAX_DIRS, MAX_FILES> {
59+
pub fn new_custom_max(block_device: D, timesource: T) -> Controller<D, T, MAX_DIRS, MAX_FILES> {
4260
debug!("Creating new embedded-sdmmc::Controller");
4361
Controller {
4462
block_device,

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,9 @@ mod tests {
460460

461461
#[test]
462462
fn partition0() {
463-
let mut c: Controller<DummyBlockDevice, Clock, 4, 4> =
464-
Controller::new(DummyBlockDevice, Clock);
463+
let mut c: Controller<DummyBlockDevice, Clock, 2, 2> =
464+
Controller::new_custom_max(DummyBlockDevice, Clock);
465+
465466
let v = c.get_volume(VolumeIdx(0)).unwrap();
466467
assert_eq!(
467468
v,

0 commit comments

Comments
 (0)