flash.rs 710 B

1234567891011121314151617181920212223242526272829303132333435
  1. //! Flash memory
  2. use stm32::{flash, FLASH};
  3. /// Extension trait to constrain the FLASH peripheral
  4. pub trait FlashExt {
  5. /// Constrains the FLASH peripheral to play nicely with the other abstractions
  6. fn constrain(self) -> Parts;
  7. }
  8. impl FlashExt for FLASH {
  9. fn constrain(self) -> Parts {
  10. Parts {
  11. acr: ACR { _0: () },
  12. }
  13. }
  14. }
  15. /// Constrained FLASH peripheral
  16. pub struct Parts {
  17. /// Opaque ACR register
  18. pub acr: ACR,
  19. }
  20. /// Opaque ACR register
  21. pub struct ACR {
  22. _0: (),
  23. }
  24. impl ACR {
  25. pub(crate) fn acr(&mut self) -> &flash::ACR {
  26. // NOTE(unsafe) this proxy grants exclusive access to this register
  27. unsafe { &(*FLASH::ptr()).acr }
  28. }
  29. }