Skip to content

Commit 3691709

Browse files
committed
Adressed a few clippy lints
Signed-off-by: Daniel Egger <[email protected]>
1 parent f6155f9 commit 3691709

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
### Added
11+
1112
- Added ADC helper functions to read more intuitive values (#22) - @HarkonenBade
1213

14+
### Changed
15+
16+
- Fixed a few clippy lints
17+
1318
## [v0.10.1] - 2018-12-25
1419

1520
### Added

src/adc.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum AdcSampleTime {
9191

9292
#[cfg(feature = "device-selected")]
9393
impl AdcSampleTime {
94-
fn write_bits(&self, adc: &mut stm32::ADC) {
94+
fn write_bits(self, adc: &mut stm32::ADC) {
9595
unsafe {
9696
adc.smpr.write(|w| {
9797
w.smpr().bits(match self {
@@ -139,7 +139,7 @@ pub enum AdcAlign {
139139

140140
#[cfg(feature = "device-selected")]
141141
impl AdcAlign {
142-
fn write_bits(&self, adc: &mut stm32::ADC) {
142+
fn write_bits(self, adc: &mut stm32::ADC) {
143143
adc.cfgr1.write(|w| {
144144
w.align().bit(match self {
145145
AdcAlign::Left => true,
@@ -170,7 +170,7 @@ pub enum AdcPrecision {
170170

171171
#[cfg(feature = "device-selected")]
172172
impl AdcPrecision {
173-
fn write_bits(&self, adc: &mut stm32::ADC) {
173+
fn write_bits(self, adc: &mut stm32::ADC) {
174174
unsafe {
175175
adc.cfgr1.write(|w| {
176176
w.res().bits(match self {
@@ -226,11 +226,11 @@ adc_pins!(
226226
gpioc::PC5<Analog> => 15_u8,
227227
);
228228

229-
#[derive(Debug)]
229+
#[derive(Debug, Default)]
230230
/// Internal temperature sensor (ADC Channel 16)
231231
pub struct VTemp;
232232

233-
#[derive(Debug)]
233+
#[derive(Debug, Default)]
234234
/// Internal voltage reference (ADC Channel 17)
235235
pub struct VRef;
236236

@@ -244,7 +244,7 @@ adc_pins!(
244244
impl VTemp {
245245
/// Init a new VTemp
246246
pub fn new() -> Self {
247-
VTemp {}
247+
VTemp::default()
248248
}
249249

250250
/// Enable the internal temperature sense, this has a wake up time
@@ -270,8 +270,8 @@ impl VTemp {
270270
let vtemp30_cal = i32::from(unsafe { ptr::read(VTEMPCAL30) }) * 100;
271271
let vtemp110_cal = i32::from(unsafe { ptr::read(VTEMPCAL110) }) * 100;
272272

273-
let mut temperature: i32 = (vtemp as i32) * 100;
274-
temperature = (temperature * (vdda as i32) / (VDD_CALIB as i32)) - vtemp30_cal;
273+
let mut temperature = i32::from(vtemp) * 100;
274+
temperature = (temperature * (i32::from(vdda) / i32::from(VDD_CALIB))) - vtemp30_cal;
275275
temperature *= (110 - 30) * 100;
276276
temperature /= vtemp110_cal - vtemp30_cal;
277277
temperature += 3000;
@@ -318,7 +318,7 @@ impl VTemp {
318318
impl VRef {
319319
/// Init a new VRef
320320
pub fn new() -> Self {
321-
VRef {}
321+
VRef::default()
322322
}
323323

324324
/// Enable the internal voltage reference, remember to disable when not in use.
@@ -356,12 +356,12 @@ impl VRef {
356356

357357
adc.restore_cfg(prev_cfg);
358358

359-
((VDD_CALIB as u32) * vrefint_cal / vref_val) as u16
359+
(u32::from(VDD_CALIB) * vrefint_cal / vref_val) as u16
360360
}
361361
}
362362

363363
#[cfg(feature = "stm32f042")]
364-
#[derive(Debug)]
364+
#[derive(Debug, Default)]
365365
/// Battery reference voltage (ADC Channel 18)
366366
pub struct VBat;
367367

@@ -374,7 +374,7 @@ adc_pins!(
374374
impl VBat {
375375
/// Init a new VBat
376376
pub fn new() -> Self {
377-
VBat {}
377+
VBat::default()
378378
}
379379

380380
/// Enable the internal VBat sense, remember to disable when not in use
@@ -483,7 +483,7 @@ impl Adc {
483483
match self.align {
484484
AdcAlign::Left => u16::max_value(),
485485
AdcAlign::LeftAsRM => match self.precision {
486-
AdcPrecision::B_6 => u8::max_value() as u16,
486+
AdcPrecision::B_6 => u16::from(u8::max_value()),
487487
_ => u16::max_value(),
488488
},
489489
AdcAlign::Right => match self.precision {
@@ -497,9 +497,9 @@ impl Adc {
497497

498498
/// Read the value of a channel and converts the result to milli-volts
499499
pub fn read_abs_mv<PIN: Channel<Adc, ID = u8>>(&mut self, pin: &mut PIN) -> u16 {
500-
let vdda = VRef::read_vdda(self) as u32;
500+
let vdda = u32::from(VRef::read_vdda(self));
501501
let v: u32 = self.read(pin).unwrap();
502-
let max_samp = self.max_sample() as u32;
502+
let max_samp = u32::from(self.max_sample());
503503

504504
(v * vdda / max_samp) as u16
505505
}

src/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl DelayMs<u32> for Delay {
6666

6767
impl DelayMs<u16> for Delay {
6868
fn delay_ms(&mut self, ms: u16) {
69-
self.delay_us(ms as u32 * 1_000);
69+
self.delay_us(u32::from(ms) * 1_000);
7070
}
7171
}
7272

src/timers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ impl Timer<SYST> {
5959
}
6060

6161
/// Starts listening for an `event`
62-
pub fn listen(&mut self, event: Event) {
62+
pub fn listen(&mut self, event: &Event) {
6363
match event {
6464
Event::TimeOut => self.tim.enable_interrupt(),
6565
}
6666
}
6767

6868
/// Stops listening for an `event`
69-
pub fn unlisten(&mut self, event: Event) {
69+
pub fn unlisten(&mut self, event: &Event) {
7070
match event {
7171
Event::TimeOut => self.tim.disable_interrupt(),
7272
}

0 commit comments

Comments
 (0)