Ver Fonte

Mark bit banding functions as unsafe

TheZoq2 há 3 anos atrás
pai
commit
eba4d94bea
2 ficheiros alterados com 5 adições e 7 exclusões
  1. 1 3
      CHANGELOG.md
  2. 4 4
      src/bb.rs

+ 1 - 3
CHANGELOG.md

@@ -11,15 +11,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 
 - MonoTimer now takes ownership of the DCB register
 - SPI objects now have a `FrameSize` type field
+- Bit banding functions (`bb::*`) are now correctly marked as unsafe
 
 ### Added
 
 - Add 16 bit dataframe size for `SPI`
 - Implement `timer::Cancel` trait for `CountDownTimer`
 - Changing Output pin slew rates through the OutputSpeed trait
-
-### Added
-
 - Add support for ADC continuous conversion
 - Add supoort for ADC discontinuous mode
 

+ 4 - 4
src/bb.rs

@@ -2,15 +2,15 @@
 
 use core::ptr;
 
-pub fn clear<T>(register: *const T, bit: u8) {
+pub unsafe fn clear<T>(register: *const T, bit: u8) {
     write(register, bit, false);
 }
 
-pub fn set<T>(register: *const T, bit: u8) {
+pub unsafe fn set<T>(register: *const T, bit: u8) {
     write(register, bit, true);
 }
 
-pub fn write<T>(register: *const T, bit: u8, set: bool) {
+pub unsafe fn write<T>(register: *const T, bit: u8, set: bool) {
     let addr = register as usize;
 
     assert!(addr >= 0x4000_0000 && addr <= 0x4010_0000);
@@ -18,5 +18,5 @@ pub fn write<T>(register: *const T, bit: u8, set: bool) {
 
     let bit = bit as usize;
     let bb_addr = (0x4200_0000 + (addr - 0x4000_0000) * 32) + 4 * bit;
-    unsafe { ptr::write_volatile(bb_addr as *mut u32, if set { 1 } else { 0 }) }
+    ptr::write_volatile(bb_addr as *mut u32, if set { 1 } else { 0 })
 }