Skip to content

Commit 519d729

Browse files
Update to new stm32l0 release
1 parent 1aed4b2 commit 519d729

File tree

8 files changed

+88
-127
lines changed

8 files changed

+88
-127
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ version = "0.4.0"
2727
features = ["stm32l0x1", "rt"]
2828

2929
[dependencies]
30+
stm32l0 = "0.9.0"
3031
as-slice = "0.1.0"
3132
embedded-hal = { version = "0.2.3", features = ["unproven"] }
3233
cortex-m = {version = "0.6.1", features = ["const-fn"] }
@@ -36,9 +37,6 @@ void = { version = "1.0.2", default-features = false }
3637
cast = { version = "0.2.2", default-features = false }
3738
nb = "0.1.2"
3839

39-
[dependencies.stm32l0]
40-
version = "0.8.0"
41-
4240
[dev-dependencies]
4341
aligned = "0.3.1"
4442
heapless = "0.5.0"

src/adc.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,12 @@ impl Adc {
110110
while self.rb.cr.read().aden().bit_is_set() {}
111111
}
112112

113-
#[cfg(feature = "stm32l0x1")]
114113
fn write_smpr(&mut self) {
115114
self.rb
116115
.smpr
117116
.modify(|_, w| w.smp().bits(self.sample_time as u8));
118117
}
119118

120-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
121-
fn write_smpr(&mut self) {
122-
self.rb
123-
.smpr
124-
// Safe, because `self.sample_time` is of type `SampleTime`, which
125-
// defines only valid values.
126-
.modify(|_, w| unsafe { w.smpr().bits(self.sample_time as u8) });
127-
}
128-
129119
pub fn release(self) -> ADC {
130120
self.rb
131121
}
@@ -156,8 +146,7 @@ where
156146
//
157147
// The `bits` method is not unsafe on STM32L0x1, so we need to
158148
// suppress the warning there.
159-
#[cfg_attr(feature = "stm32l0x1", allow(unused_unsafe))]
160-
let w = unsafe { w.res().bits(self.precision as u8) };
149+
let w = w.res().bits(self.precision as u8);
161150
w.align().bit(self.align == Align::Left)
162151
});
163152

src/dma.rs

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
i2c,
3131
pac::{
3232
self,
33-
dma1::ccr1,
33+
dma1::ch::cr,
3434
I2C1,
3535
I2C2,
3636
I2C3,
@@ -222,37 +222,37 @@ impl<T, C, B> fmt::Debug for TransferResources<T, C, B> {
222222

223223

224224
/// The priority of the DMA transfer
225-
pub struct Priority(ccr1::PLW);
225+
pub struct Priority(cr::PL_A);
226226

227227
impl Priority {
228228
pub fn low() -> Self {
229-
Self(ccr1::PLW::LOW)
229+
Self(cr::PL_A::LOW)
230230
}
231231

232232
pub fn medium() -> Self {
233-
Self(ccr1::PLW::MEDIUM)
233+
Self(cr::PL_A::MEDIUM)
234234
}
235235

236236
pub fn high() -> Self {
237-
Self(ccr1::PLW::HIGH)
237+
Self(cr::PL_A::HIGH)
238238
}
239239

240240
pub fn very_high() -> Self {
241-
Self(ccr1::PLW::VERYHIGH)
241+
Self(cr::PL_A::VERYHIGH)
242242
}
243243
}
244244

245245

246246
/// The direction of the DMA transfer
247-
pub(crate) struct Direction(ccr1::DIRW);
247+
pub(crate) struct Direction(cr::DIR_A);
248248

249249
impl Direction {
250250
pub fn memory_to_peripheral() -> Self {
251-
Self(ccr1::DIRW::FROMMEMORY)
251+
Self(cr::DIR_A::FROMMEMORY)
252252
}
253253

254254
pub fn peripheral_to_memory() -> Self {
255-
Self(ccr1::DIRW::FROMPERIPHERAL)
255+
Self(cr::DIR_A::FROMPERIPHERAL)
256256
}
257257
}
258258

@@ -268,8 +268,8 @@ pub trait Channel: Sized {
268268
fn set_transfer_len(&self, _: &mut Handle, len: u16);
269269
fn configure<Word>(&self,
270270
_: &mut Handle,
271-
priority: ccr1::PLW,
272-
dir: ccr1::DIRW,
271+
priority: cr::PL_A,
272+
dir: cr::DIR_A,
273273
)
274274
where Word: SupportedWordSize;
275275
fn enable_interrupts(&self, interrupts: Interrupts);
@@ -284,11 +284,8 @@ macro_rules! impl_channel {
284284
$(
285285
$channel:ident,
286286
$field:ident,
287+
$chfield:ident,
287288
$cxs:ident,
288-
$cpar:ident,
289-
$cmar:ident,
290-
$cndtr:ident,
291-
$ccr:ident,
292289
$tcif:ident,
293290
$teif:ident,
294291
$ctcif:ident,
@@ -322,51 +319,51 @@ macro_rules! impl_channel {
322319
handle: &mut Handle,
323320
address: u32,
324321
) {
325-
handle.dma.$cpar.write(|w| w.pa().bits(address));
322+
handle.dma.$chfield.par.write(|w| w.pa().bits(address));
326323
}
327324

328325
fn set_memory_address(&self,
329326
handle: &mut Handle,
330327
address: u32,
331328
) {
332-
handle.dma.$cmar.write(|w| w.ma().bits(address));
329+
handle.dma.$chfield.mar.write(|w| w.ma().bits(address));
333330
}
334331

335332
fn set_transfer_len(&self, handle: &mut Handle, len: u16) {
336-
handle.dma.$cndtr.write(|w| w.ndt().bits(len));
333+
handle.dma.$chfield.ndtr.write(|w| w.ndt().bits(len));
337334
}
338335

339336
fn configure<Word>(&self,
340337
handle: &mut Handle,
341-
priority: ccr1::PLW,
342-
dir: ccr1::DIRW,
338+
priority: cr::PL_A,
339+
dir: cr::DIR_A,
343340
)
344341
where Word: SupportedWordSize
345342
{
346-
handle.dma.$ccr.write(|w| {
343+
handle.dma.$chfield.cr.write(|w| {
347344
// Safe, as the enum we use should only provide valid
348345
// bit patterns.
349346
let w = unsafe {
350347
w
351348
// Word size in memory
352-
.msize().bits(Word::size()._bits())
349+
.msize().variant(Word::size())
353350
// Word size in peripheral
354-
.psize().bits(Word::size()._bits())
351+
.psize().variant(Word::size())
355352
};
356353

357354
w
358355
// Memory-to-memory mode disabled
359356
.mem2mem().disabled()
360357
// Priority level
361-
.pl().bits(priority._bits())
358+
.pl().variant(priority)
362359
// Increment memory pointer
363360
.minc().enabled()
364361
// Don't increment peripheral pointer
365362
.pinc().disabled()
366363
// Circular mode disabled
367364
.circ().disabled()
368365
// Data transfer direction
369-
.dir().bit(dir._bits())
366+
.dir().variant(dir)
370367
// Disable interrupts
371368
.teie().disabled()
372369
.htie().disabled()
@@ -377,7 +374,7 @@ macro_rules! impl_channel {
377374
fn enable_interrupts(&self, interrupts: Interrupts) {
378375
// Safe, because we're only accessing a register that this
379376
// channel has exclusive access to.
380-
let ccr = &unsafe { &*pac::DMA1::ptr() }.$ccr;
377+
let ccr = &unsafe { &*pac::DMA1::ptr() }.$chfield.cr;
381378

382379
ccr.modify(|_, w|
383380
w
@@ -390,7 +387,7 @@ macro_rules! impl_channel {
390387
fn start(&self) {
391388
// Safe, because we're only accessing a register that this
392389
// channel has exclusive access to.
393-
let ccr = &unsafe { &*pac::DMA1::ptr() }.$ccr;
390+
let ccr = &unsafe { &*pac::DMA1::ptr() }.$chfield.cr;
394391

395392
// Start transfer
396393
ccr.modify(|_, w| w.en().enabled());
@@ -419,7 +416,7 @@ macro_rules! impl_channel {
419416

420417
if dma.isr.read().$tcif().is_complete() {
421418
dma.ifcr.write(|w| w.$ctcif().set_bit());
422-
dma.$ccr.modify(|_, w| w.en().disabled());
419+
dma.$chfield.cr.modify(|_, w| w.en().disabled());
423420
}
424421
}
425422

@@ -444,27 +441,20 @@ macro_rules! impl_channel {
444441
}
445442

446443
impl_channel!(
447-
Channel1, channel1,
448-
c1s, cpar1, cmar1, cndtr1, ccr1,
449-
tcif1, teif1, ctcif1, cteif1;
450-
Channel2, channel2,
451-
c2s, cpar2, cmar2, cndtr2, ccr2,
452-
tcif2, teif2, ctcif2, cteif2;
453-
Channel3, channel3,
454-
c3s, cpar3, cmar3, cndtr3, ccr3,
455-
tcif3, teif3, ctcif3, cteif3;
456-
Channel4, channel4,
457-
c4s, cpar4, cmar4, cndtr4, ccr4,
458-
tcif4, teif4, ctcif4, cteif4;
459-
Channel5, channel5,
460-
c5s, cpar5, cmar5, cndtr5, ccr5,
461-
tcif5, teif5, ctcif5, cteif5;
462-
Channel6, channel6,
463-
c6s, cpar6, cmar6, cndtr6, ccr6,
464-
tcif6, teif6, ctcif6, cteif6;
465-
Channel7, channel7,
466-
c7s, cpar7, cmar7, cndtr7, ccr7,
467-
tcif7, teif7, ctcif7, cteif7;
444+
Channel1, channel1, ch1,
445+
c1s, tcif1, teif1, ctcif1, cteif1;
446+
Channel2, channel2, ch2,
447+
c2s, tcif2, teif2, ctcif2, cteif2;
448+
Channel3, channel3, ch3,
449+
c3s, tcif3, teif3, ctcif3, cteif3;
450+
Channel4, channel4, ch4,
451+
c4s, tcif4, teif4, ctcif4, cteif4;
452+
Channel5, channel5, ch5,
453+
c5s, tcif5, teif5, ctcif5, cteif5;
454+
Channel6, channel6, ch6,
455+
c6s, tcif6, teif6, ctcif6, cteif6;
456+
Channel7, channel7, ch7,
457+
c7s, tcif7, teif7, ctcif7, cteif7;
468458
);
469459

470460

@@ -580,24 +570,24 @@ impl<Word> Buffer<Word> for PtrBuffer<Word> {
580570

581571

582572
pub trait SupportedWordSize {
583-
fn size() -> ccr1::MSIZEW;
573+
fn size() -> cr::MSIZE_A;
584574
}
585575

586576
impl SupportedWordSize for u8 {
587-
fn size() -> ccr1::MSIZEW {
588-
ccr1::MSIZEW::BITS8
577+
fn size() -> cr::MSIZE_A {
578+
cr::MSIZE_A::BITS8
589579
}
590580
}
591581

592582
impl SupportedWordSize for u16 {
593-
fn size() -> ccr1::MSIZEW {
594-
ccr1::MSIZEW::BITS16
583+
fn size() -> cr::MSIZE_A {
584+
cr::MSIZE_A::BITS16
595585
}
596586
}
597587

598588
impl SupportedWordSize for u32 {
599-
fn size() -> ccr1::MSIZEW {
600-
ccr1::MSIZEW::BITS32
589+
fn size() -> cr::MSIZE_A {
590+
cr::MSIZE_A::BITS32
601591
}
602592
}
603593

src/i2c.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::gpio::{AltMode, OpenDrain, Output};
2828
use crate::pac::{
2929
i2c1::{
3030
RegisterBlock,
31-
cr2::RD_WRNW,
31+
cr2::RD_WRN_A,
3232
}
3333
};
3434
pub use crate::pac::I2C1;
@@ -162,7 +162,7 @@ where
162162
(self.i2c, self.sda, self.scl)
163163
}
164164

165-
fn start_transfer(&mut self, addr: u8, len: usize, direction: RD_WRNW) {
165+
fn start_transfer(&mut self, addr: u8, len: usize, direction: RD_WRN_A) {
166166
self.i2c.cr2.write(|w|
167167
w
168168
// Start transfer
@@ -243,7 +243,7 @@ where
243243
Buffer::Target: AsSlice<Element=u8>,
244244
{
245245
assert!(buffer.len() >= num_words);
246-
self.start_transfer(address, buffer.as_slice().len(), RD_WRNW::WRITE);
246+
self.start_transfer(address, buffer.as_slice().len(), RD_WRN_A::WRITE);
247247

248248
// This token represents the transmission capability of I2C and this is
249249
// what the `dma::Target` trait is implemented for. It can't be
@@ -316,7 +316,7 @@ where
316316
Buffer::Target: AsMutSlice<Element=u8>,
317317
{
318318
assert!(buffer.len() >= num_words);
319-
self.start_transfer(address, buffer.as_slice().len(), RD_WRNW::READ);
319+
self.start_transfer(address, buffer.as_slice().len(), RD_WRN_A::READ);
320320

321321
// See explanation of tokens in `write_all`.
322322
let token = Rx(PhantomData);
@@ -370,7 +370,7 @@ where
370370
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
371371
while self.i2c.isr.read().busy().is_busy() {}
372372

373-
self.start_transfer(addr, bytes.len(), RD_WRNW::WRITE);
373+
self.start_transfer(addr, bytes.len(), RD_WRN_A::WRITE);
374374

375375
// Send bytes
376376
for c in bytes {
@@ -390,7 +390,7 @@ where
390390
fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
391391
while self.i2c.isr.read().busy().is_busy() {}
392392

393-
self.start_transfer(addr, buffer.len(), RD_WRNW::READ);
393+
self.start_transfer(addr, buffer.len(), RD_WRN_A::READ);
394394

395395
// Receive bytes into buffer
396396
for c in buffer {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub mod adc;
2424
#[cfg(any(feature = "stm32l062", feature = "stm32l082"))]
2525
pub mod aes;
2626
pub mod delay;
27-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
2827
pub mod dma;
2928
pub mod exti;
3029
pub mod gpio;

src/rcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl RccExt for RCC {
230230
#[cfg(feature = "stm32l0x1")]
231231
self.icscr.write(|w| w.msirange().bits(range));
232232
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
233-
self.icscr.write(|w| unsafe { w.msirange().bits(range) });
233+
self.icscr.write(|w| w.msirange().bits(range));
234234

235235
// Enable MSI
236236
self.cr.write(|w| w.msion().set_bit());

0 commit comments

Comments
 (0)