12
12
#![ deny( unsafe_code) ]
13
13
14
14
use core:: ops:: { Add , Sub } ;
15
+ use heapless:: { consts:: * , Vec } ;
15
16
use nb;
16
17
17
18
/// Currently contains [`OverlapIterator`]
@@ -66,8 +67,8 @@ pub trait Region {
66
67
fn contains ( & self , address : Address ) -> bool ;
67
68
}
68
69
69
- /// Storage trait
70
- pub trait ReadWrite {
70
+ /// Transparent storage trait
71
+ pub trait ReadWriteStorage {
71
72
/// An enumeration of storage errors
72
73
type Error ;
73
74
@@ -86,8 +87,57 @@ pub trait ReadWrite {
86
87
fn range ( & self ) -> ( Address , Address ) ;
87
88
88
89
/// Erase the given storage range, clearing all data within `[from..to]`.
90
+ fn try_erase ( & mut self , from : Address , to : Address ) -> nb:: Result < ( ) , Self :: Error > ;
91
+ }
92
+
93
+ /// NOR flash region trait.
94
+ pub trait NorFlashRegion {
95
+ /// The range of possible addresses within the region.
96
+ ///
97
+ /// (start_addr, end_addr)
98
+ fn range ( & self ) -> ( Address , Address ) ;
99
+ /// Maximum number of bytes that can be written at once.
100
+ fn page_size ( & self ) -> usize ;
101
+ /// List of avalable erase sizes in this region.
102
+ /// Should be sorted in ascending order.
103
+ /// Currently limited to 5 sizes, but could be increased if necessary.
104
+ fn erase_sizes ( & self ) -> Vec < usize , U5 > ;
105
+ }
106
+
107
+ /// NOR flash storage trait
108
+ pub trait NorFlash {
109
+ /// An enumeration of storage errors
110
+ type Error ;
111
+ /// Region type
112
+ type Region : NorFlashRegion ;
113
+
114
+ /// Read a slice of data from the storage peripheral, starting the read
115
+ /// operation at the given address, and reading until end address
116
+ /// (`self.range().1`) or buffer length, whichever comes first.
117
+ fn try_read ( & mut self , address : Address , bytes : & mut [ u8 ] ) -> nb:: Result < ( ) , Self :: Error > ;
118
+
119
+ /// Write a slice of data to the storage peripheral, starting the write
120
+ /// operation at the given address.
121
+ ///
122
+ /// Since this is done on a NOR flash all bytes are anded with the current
123
+ /// content in the flash. This means no 0s can to turned into 1s this way.
124
+ fn try_write ( & mut self , address : Address , bytes : & [ u8 ] ) -> nb:: Result < ( ) , Self :: Error > ;
125
+
126
+ /// Erase the given storage range, clearing all data within `[from..to]`.
127
+ /// The given range will contain all 1s afterwards.
89
128
///
90
129
/// This should return an error if the range is not aligned to a proper
91
130
/// erase resolution
92
131
fn try_erase ( & mut self , from : Address , to : Address ) -> nb:: Result < ( ) , Self :: Error > ;
132
+
133
+ /// The range of possible addresses within the peripheral.
134
+ ///
135
+ /// (start_addr, end_addr)
136
+ fn range ( & self ) -> ( Address , Address ) ;
137
+
138
+ /// Get all distinct memory reagions. These must not overlap, but can be disjoint.
139
+ /// Most chips will return a single region, but some chips have regions with
140
+ /// different erase sizes.
141
+ /// Currently limited to 4 regions, but could be increased if necessary
142
+ fn regions ( & self ) -> Vec < Self :: Region , U4 > ;
93
143
}
0 commit comments