1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* mod.rs
 *
 * Developed by Tim Walls <tim.walls@snowgoons.com>
 * Copyright (c) All Rights Reserved, Tim Walls
 */
//! Generic traits for the various devices that can be attached to our AVR
//! device
use core::marker::PhantomData;

pub mod datatypes;
pub mod callback;
pub mod timer;
pub mod port;
pub mod watchdog;
pub mod cpu;
pub mod serial;
pub mod eeprom;
pub mod twi;

#[lang = "eh_personality"]
#[no_mangle]
#[cfg(target_arch="avr")]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn rust_eh_personality() {
}

pub(crate) struct MutDeviceRef<T> {
  address: usize,
  _phantom: PhantomData<T>
}

impl<T> MutDeviceRef<T> {
  pub fn new(devaddr: u16) -> Self {
    MutDeviceRef {
      address: devaddr as usize,
      _phantom: PhantomData::default()
    }
  }

  pub fn borrow_mut(&self, _isotoken: avr_oxide::concurrency::interrupt::token::Isolated) -> &mut T {
    unsafe {
      core::mem::transmute(self.address as *mut T)
    }
  }
}

/**
 * Trait implemented to allow us to set portmux control bits
 */
pub trait MuxControl {
  /**
   * Set the relevant hardware controls to route this appropriately.
   */
  fn route(&self);
}