Skip to content

Commit 0b4f37b

Browse files
jonathanpallanteldruin
authored andcommitted
Rename Controller to VolumeManager.
Better reflects what it actually does.
1 parent 72246e4 commit 0b4f37b

File tree

11 files changed

+173
-164
lines changed

11 files changed

+173
-164
lines changed

CHANGELOG.md

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

1010
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.4.0...develop
1111

12+
- Renamed `Controller` to `VolumeManager`, to better describe what it does.
13+
1214
## [Version 0.4.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.4.0)
1315

1416
### Changes

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ designed for readability and simplicity over performance.
1111
You will need something that implements the `BlockDevice` trait, which can read and write the 512-byte blocks (or sectors) from your card. If you were to implement this over USB Mass Storage, there's no reason this crate couldn't work with a USB Thumb Drive, but we only supply a `BlockDevice` suitable for reading SD and SDHC cards over SPI.
1212

1313
```rust
14+
// Build an SD Card interface out of an SPI device
1415
let mut spi_dev = embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs);
16+
// Try and initialise the SD card
1517
write!(uart, "Init SD card...").unwrap();
1618
match spi_dev.acquire() {
1719
Ok(block) => {
18-
let mut cont = embedded_sdmmc::Controller::new(block, time_source);
20+
// The SD Card initialised, and we have a `BlockSpi` object representing
21+
// the initialised card. Now let's
22+
let mut cont = embedded_sdmmc::VolumeManager::new(block, time_source);
1923
write!(uart, "OK!\nCard size...").unwrap();
2024
match cont.device().card_size_bytes() {
2125
Ok(size) => writeln!(uart, "{}", size).unwrap(),
@@ -33,16 +37,16 @@ match spi_dev.acquire() {
3337

3438
### Open directories and files
3539

36-
By default the `Controller` will initialize with a maximum number of `4` open directories and files. This can be customized by specifying the `MAX_DIR` and `MAX_FILES` generic consts of the `Controller`:
40+
By default the `VolumeManager` will initialize with a maximum number of `4` open directories and files. This can be customized by specifying the `MAX_DIR` and `MAX_FILES` generic consts of the `VolumeManager`:
3741

3842
```rust
39-
// Create a controller with a maximum of 6 open directories and 12 open files
40-
let mut cont: Controller<
43+
// Create a volume manager with a maximum of 6 open directories and 12 open files
44+
let mut cont: VolumeManager<
4145
embedded_sdmmc::BlockSpi<DummySpi, DummyCsPin>,
4246
DummyTimeSource,
4347
6,
4448
12,
45-
> = Controller::new_with_limits(block, time_source);
49+
> = VolumeManager::new_with_limits(block, time_source);
4650
```
4751

4852
## Supported features

examples/create_test.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extern crate embedded_sdmmc;
1919
const FILE_TO_CREATE: &'static str = "CREATE.TXT";
2020

2121
use embedded_sdmmc::{
22-
Block, BlockCount, BlockDevice, BlockIdx, Controller, Error, Mode, TimeSource, Timestamp,
23-
VolumeIdx,
22+
Block, BlockCount, BlockDevice, BlockIdx, Error, Mode, TimeSource, Timestamp, VolumeIdx,
23+
VolumeManager,
2424
};
2525
use std::cell::RefCell;
2626
use std::fs::{File, OpenOptions};
@@ -118,22 +118,22 @@ fn main() {
118118
.map_err(Error::DeviceError)
119119
.unwrap();
120120
println!("lbd: {:?}", lbd);
121-
let mut controller = Controller::new(lbd, Clock);
121+
let mut volume_mgr = VolumeManager::new(lbd, Clock);
122122
for volume_idx in 0..=3 {
123-
let volume = controller.get_volume(VolumeIdx(volume_idx));
123+
let volume = volume_mgr.get_volume(VolumeIdx(volume_idx));
124124
println!("volume {}: {:#?}", volume_idx, volume);
125125
if let Ok(mut volume) = volume {
126-
let root_dir = controller.open_root_dir(&volume).unwrap();
126+
let root_dir = volume_mgr.open_root_dir(&volume).unwrap();
127127
println!("\tListing root directory:");
128-
controller
128+
volume_mgr
129129
.iterate_dir(&volume, &root_dir, |x| {
130130
println!("\t\tFound: {:?}", x);
131131
})
132132
.unwrap();
133133
println!("\nCreating file {}...", FILE_TO_CREATE);
134134
// This will panic if the file already exists, use ReadWriteCreateOrAppend or
135135
// ReadWriteCreateOrTruncate instead
136-
let mut f = controller
136+
let mut f = volume_mgr
137137
.open_file_in_dir(
138138
&mut volume,
139139
&root_dir,
@@ -145,7 +145,7 @@ fn main() {
145145
println!("FILE STARTS:");
146146
while !f.eof() {
147147
let mut buffer = [0u8; 32];
148-
let num_read = controller.read(&volume, &mut f, &mut buffer).unwrap();
148+
let num_read = volume_mgr.read(&volume, &mut f, &mut buffer).unwrap();
149149
for b in &buffer[0..num_read] {
150150
if *b == 10 {
151151
print!("\\n");
@@ -164,12 +164,12 @@ fn main() {
164164
buffer.push(b'\n');
165165
}
166166
println!("\nAppending to file");
167-
let num_written1 = controller.write(&mut volume, &mut f, &buffer1[..]).unwrap();
168-
let num_written = controller.write(&mut volume, &mut f, &buffer[..]).unwrap();
167+
let num_written1 = volume_mgr.write(&mut volume, &mut f, &buffer1[..]).unwrap();
168+
let num_written = volume_mgr.write(&mut volume, &mut f, &buffer[..]).unwrap();
169169
println!("Number of bytes written: {}\n", num_written + num_written1);
170-
controller.close_file(&volume, f).unwrap();
170+
volume_mgr.close_file(&volume, f).unwrap();
171171

172-
let mut f = controller
172+
let mut f = volume_mgr
173173
.open_file_in_dir(
174174
&mut volume,
175175
&root_dir,
@@ -183,13 +183,13 @@ fn main() {
183183
println!(
184184
"\tFound {}?: {:?}",
185185
FILE_TO_CREATE,
186-
controller.find_directory_entry(&volume, &root_dir, FILE_TO_CREATE)
186+
volume_mgr.find_directory_entry(&volume, &root_dir, FILE_TO_CREATE)
187187
);
188188
println!("\nReading from file");
189189
println!("FILE STARTS:");
190190
while !f.eof() {
191191
let mut buffer = [0u8; 32];
192-
let num_read = controller.read(&volume, &mut f, &mut buffer).unwrap();
192+
let num_read = volume_mgr.read(&volume, &mut f, &mut buffer).unwrap();
193193
for b in &buffer[0..num_read] {
194194
if *b == 10 {
195195
print!("\\n");
@@ -198,7 +198,7 @@ fn main() {
198198
}
199199
}
200200
println!("EOF");
201-
controller.close_file(&volume, f).unwrap();
201+
volume_mgr.close_file(&volume, f).unwrap();
202202
}
203203
}
204204
}

examples/delete_test.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extern crate embedded_sdmmc;
1919
const FILE_TO_DELETE: &'static str = "DELETE.TXT";
2020

2121
use embedded_sdmmc::{
22-
Block, BlockCount, BlockDevice, BlockIdx, Controller, Error, Mode, TimeSource, Timestamp,
23-
VolumeIdx,
22+
Block, BlockCount, BlockDevice, BlockIdx, Error, Mode, TimeSource, Timestamp, VolumeIdx,
23+
VolumeManager,
2424
};
2525
use std::cell::RefCell;
2626
use std::fs::{File, OpenOptions};
@@ -118,22 +118,22 @@ fn main() {
118118
.map_err(Error::DeviceError)
119119
.unwrap();
120120
println!("lbd: {:?}", lbd);
121-
let mut controller = Controller::new(lbd, Clock);
121+
let mut volume_mgr = VolumeManager::new(lbd, Clock);
122122
for volume_idx in 0..=3 {
123-
let volume = controller.get_volume(VolumeIdx(volume_idx));
123+
let volume = volume_mgr.get_volume(VolumeIdx(volume_idx));
124124
println!("volume {}: {:#?}", volume_idx, volume);
125125
if let Ok(mut volume) = volume {
126-
let root_dir = controller.open_root_dir(&volume).unwrap();
126+
let root_dir = volume_mgr.open_root_dir(&volume).unwrap();
127127
println!("\tListing root directory:");
128-
controller
128+
volume_mgr
129129
.iterate_dir(&volume, &root_dir, |x| {
130130
println!("\t\tFound: {:?}", x);
131131
})
132132
.unwrap();
133133
println!("\nCreating file {}...", FILE_TO_DELETE);
134134
// This will panic if the file already exists, use ReadWriteCreateOrAppend or
135135
// ReadWriteCreateOrTruncate instead
136-
let f = controller
136+
let f = volume_mgr
137137
.open_file_in_dir(
138138
&mut volume,
139139
&root_dir,
@@ -146,25 +146,25 @@ fn main() {
146146
println!(
147147
"\tFound {}?: {:?}",
148148
FILE_TO_DELETE,
149-
controller.find_directory_entry(&volume, &root_dir, FILE_TO_DELETE)
149+
volume_mgr.find_directory_entry(&volume, &root_dir, FILE_TO_DELETE)
150150
);
151151

152-
match controller.delete_file_in_dir(&volume, &root_dir, FILE_TO_DELETE) {
152+
match volume_mgr.delete_file_in_dir(&volume, &root_dir, FILE_TO_DELETE) {
153153
Ok(()) => (),
154154
Err(error) => println!("\tCannot delete file: {:?}", error),
155155
}
156156
println!("\tClosing {}...", FILE_TO_DELETE);
157-
controller.close_file(&volume, f).unwrap();
157+
volume_mgr.close_file(&volume, f).unwrap();
158158

159-
match controller.delete_file_in_dir(&volume, &root_dir, FILE_TO_DELETE) {
159+
match volume_mgr.delete_file_in_dir(&volume, &root_dir, FILE_TO_DELETE) {
160160
Ok(()) => println!("\tDeleted {}.", FILE_TO_DELETE),
161161
Err(error) => println!("\tCannot delete {}: {:?}", FILE_TO_DELETE, error),
162162
}
163163
println!("\tFinding {}...", FILE_TO_DELETE);
164164
println!(
165165
"\tFound {}?: {:?}",
166166
FILE_TO_DELETE,
167-
controller.find_directory_entry(&volume, &root_dir, FILE_TO_DELETE)
167+
volume_mgr.find_directory_entry(&volume, &root_dir, FILE_TO_DELETE)
168168
);
169169
}
170170
}

examples/test_mount.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const FILE_TO_PRINT: &'static str = "README.TXT";
2727
const FILE_TO_CHECKSUM: &'static str = "64MB.DAT";
2828

2929
use embedded_sdmmc::{
30-
Block, BlockCount, BlockDevice, BlockIdx, Controller, Error, Mode, TimeSource, Timestamp,
31-
VolumeIdx,
30+
Block, BlockCount, BlockDevice, BlockIdx, Error, Mode, TimeSource, Timestamp, VolumeIdx,
31+
VolumeManager,
3232
};
3333
use std::cell::RefCell;
3434
use std::fs::File;
@@ -121,14 +121,14 @@ fn main() {
121121
.map_err(Error::DeviceError)
122122
.unwrap();
123123
println!("lbd: {:?}", lbd);
124-
let mut controller = Controller::new(lbd, Clock);
124+
let mut volume_mgr = VolumeManager::new(lbd, Clock);
125125
for i in 0..=3 {
126-
let volume = controller.get_volume(VolumeIdx(i));
126+
let volume = volume_mgr.get_volume(VolumeIdx(i));
127127
println!("volume {}: {:#?}", i, volume);
128128
if let Ok(mut volume) = volume {
129-
let root_dir = controller.open_root_dir(&volume).unwrap();
129+
let root_dir = volume_mgr.open_root_dir(&volume).unwrap();
130130
println!("\tListing root directory:");
131-
controller
131+
volume_mgr
132132
.iterate_dir(&volume, &root_dir, |x| {
133133
println!("\t\tFound: {:?}", x);
134134
})
@@ -137,15 +137,15 @@ fn main() {
137137
println!(
138138
"\tFound {}?: {:?}",
139139
FILE_TO_PRINT,
140-
controller.find_directory_entry(&volume, &root_dir, FILE_TO_PRINT)
140+
volume_mgr.find_directory_entry(&volume, &root_dir, FILE_TO_PRINT)
141141
);
142-
let mut f = controller
142+
let mut f = volume_mgr
143143
.open_file_in_dir(&mut volume, &root_dir, FILE_TO_PRINT, Mode::ReadOnly)
144144
.unwrap();
145145
println!("FILE STARTS:");
146146
while !f.eof() {
147147
let mut buffer = [0u8; 32];
148-
let num_read = controller.read(&volume, &mut f, &mut buffer).unwrap();
148+
let num_read = volume_mgr.read(&volume, &mut f, &mut buffer).unwrap();
149149
for b in &buffer[0..num_read] {
150150
if *b == 10 {
151151
print!("\\n");
@@ -155,43 +155,43 @@ fn main() {
155155
}
156156
println!("EOF");
157157
// Can't open file twice
158-
assert!(controller
158+
assert!(volume_mgr
159159
.open_file_in_dir(&mut volume, &root_dir, FILE_TO_PRINT, Mode::ReadOnly)
160160
.is_err());
161-
controller.close_file(&volume, f).unwrap();
161+
volume_mgr.close_file(&volume, f).unwrap();
162162

163-
let test_dir = controller.open_dir(&volume, &root_dir, "TEST").unwrap();
163+
let test_dir = volume_mgr.open_dir(&volume, &root_dir, "TEST").unwrap();
164164
// Check we can't open it twice
165-
assert!(controller.open_dir(&volume, &root_dir, "TEST").is_err());
165+
assert!(volume_mgr.open_dir(&volume, &root_dir, "TEST").is_err());
166166
// Print the contents
167167
println!("\tListing TEST directory:");
168-
controller
168+
volume_mgr
169169
.iterate_dir(&volume, &test_dir, |x| {
170170
println!("\t\tFound: {:?}", x);
171171
})
172172
.unwrap();
173-
controller.close_dir(&volume, test_dir);
173+
volume_mgr.close_dir(&volume, test_dir);
174174

175175
// Checksum example file. We just sum the bytes, as a quick and dirty checksum.
176176
// We also read in a weird block size, just to exercise the offset calculation code.
177-
let mut f = controller
177+
let mut f = volume_mgr
178178
.open_file_in_dir(&mut volume, &root_dir, FILE_TO_CHECKSUM, Mode::ReadOnly)
179179
.unwrap();
180180
println!("Checksuming {} bytes of {}", f.length(), FILE_TO_CHECKSUM);
181181
let mut csum = 0u32;
182182
while !f.eof() {
183183
let mut buffer = [0u8; 2047];
184-
let num_read = controller.read(&volume, &mut f, &mut buffer).unwrap();
184+
let num_read = volume_mgr.read(&volume, &mut f, &mut buffer).unwrap();
185185
for b in &buffer[0..num_read] {
186186
csum += u32::from(*b);
187187
}
188188
}
189189
println!("Checksum over {} bytes: {}", f.length(), csum);
190-
controller.close_file(&volume, f).unwrap();
190+
volume_mgr.close_file(&volume, f).unwrap();
191191

192-
assert!(controller.open_root_dir(&volume).is_err());
193-
controller.close_dir(&volume, root_dir);
194-
assert!(controller.open_root_dir(&volume).is_ok());
192+
assert!(volume_mgr.open_root_dir(&volume).is_err());
193+
volume_mgr.close_dir(&volume, root_dir);
194+
assert!(volume_mgr.open_root_dir(&volume).is_ok());
195195
}
196196
}
197197
}

0 commit comments

Comments
 (0)