Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Use crate::target pattern #37

Merged
merged 2 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use esp32_hal::analog::config::{Adc1Config, Adc2Config, Attenuation};
use esp32_hal::clock_control::sleep;
use esp32_hal::dport::Split;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

#[no_mangle]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -80,7 +81,7 @@ fn main() -> ! {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
5 changes: 3 additions & 2 deletions examples/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use esp32_hal::clock_control::{sleep, ClockControl};
use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

#[macro_use]
extern crate alloc;
Expand Down Expand Up @@ -48,7 +49,7 @@ macro_rules! print_info {

#[entry]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -157,7 +158,7 @@ fn print_heap_info(output: &mut dyn core::fmt::Write) {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
7 changes: 4 additions & 3 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate panic_halt;
extern crate xtensa_lx6_rt;

use hal::prelude::*;
use hal::target;
use xtensa_lx6::get_cycle_count;

/// The default clock source is the onboard crystal
Expand All @@ -16,7 +17,7 @@ const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

#[no_mangle]
fn main() -> ! {
let dp = unsafe { hal::esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut rtccntl = dp.RTCCNTL;
let mut timg0 = dp.TIMG0;
Expand All @@ -39,7 +40,7 @@ fn main() -> ! {
}
}

fn disable_rtc_wdt(rtccntl: &mut hal::esp32::RTCCNTL) {
fn disable_rtc_wdt(rtccntl: &mut target::RTCCNTL) {
/* Disables the RTCWDT */
rtccntl
.wdtwprotect
Expand All @@ -61,7 +62,7 @@ fn disable_rtc_wdt(rtccntl: &mut hal::esp32::RTCCNTL) {
rtccntl.wdtwprotect.write(|w| unsafe { w.bits(0x0) });
}

fn disable_timg_wdts(timg0: &mut hal::esp32::TIMG0, timg1: &mut hal::esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
5 changes: 3 additions & 2 deletions examples/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use esp32_hal::prelude::*;
use esp32_hal::analog::dac::DAC;
use esp32_hal::clock_control::sleep;
use esp32_hal::dport::Split;
use esp32_hal::target;

#[no_mangle]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -60,7 +61,7 @@ fn main() -> ! {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
7 changes: 4 additions & 3 deletions examples/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::interrupt::{clear_software_interrupt, Interrupt, Interrupt::*, InterruptLevel};
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;
use esp32_hal::Core::PRO;

static TX: spin::Mutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> = spin::Mutex::new(None);
static TX: spin::Mutex<Option<esp32_hal::serial::Tx<target::UART0>>> = spin::Mutex::new(None);

#[interrupt]
fn FROM_CPU_INTR0() {
Expand Down Expand Up @@ -109,7 +110,7 @@ fn other_exception(

#[entry]
fn main() -> ! {
let dp = esp32::Peripherals::take().unwrap();
let dp = target::Peripherals::take().unwrap();

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -210,7 +211,7 @@ fn main() -> ! {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
5 changes: 3 additions & 2 deletions examples/hall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use esp32_hal::analog::config::{Adc1Config, Attenuation};
use esp32_hal::clock_control::sleep;
use esp32_hal::dport::Split;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

#[no_mangle]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -74,7 +75,7 @@ fn main() -> ! {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
5 changes: 3 additions & 2 deletions examples/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::mem::{memcmp, memcpy, memcpy_reverse, memset};
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

use xtensa_lx6::get_cycle_count;

Expand All @@ -26,7 +27,7 @@ pub static GLOBAL_ALLOCATOR: Allocator = DRAM_ALLOCATOR;

#[entry]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -186,7 +187,7 @@ unsafe fn time_memcpy(

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
7 changes: 4 additions & 3 deletions examples/multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ use esp32_hal::clock_control::{CPUSource, ClockControl, ClockControlConfig};
use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

use xtensa_lx6::{get_cycle_count, get_stack_pointer};

const BLINK_HZ: Hertz = Hertz(1);

static GLOBAL_COUNT: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0);
static TX: spin::Mutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> = spin::Mutex::new(None);
static TX: spin::Mutex<Option<esp32_hal::serial::Tx<target::UART0>>> = spin::Mutex::new(None);

#[no_mangle]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -198,7 +199,7 @@ fn print_info(loop_count: u32, spin_loop_count: u32, prev_ccount: &mut u32) {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
19 changes: 10 additions & 9 deletions examples/ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use esp32_hal::clock_control::{sleep, ClockControl};
use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

use xtensa_lx6::get_program_counter;

#[entry]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -65,7 +66,7 @@ fn main() -> ! {
}
}

fn attr_none_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
fn attr_none_fn(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
writeln!(
uart,
"{:<40}: {:08x?}",
Expand All @@ -76,7 +77,7 @@ fn attr_none_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>
}

#[ram]
fn attr_ram_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
fn attr_ram_fn(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
writeln!(
uart,
"{:<40}: {:08x?}",
Expand All @@ -87,7 +88,7 @@ fn attr_ram_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>)
}

#[ram(rtc_slow)]
fn attr_ram_fn_rtc_slow(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
fn attr_ram_fn_rtc_slow(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
writeln!(
uart,
"{:<40}: {:08x?}",
Expand All @@ -98,7 +99,7 @@ fn attr_ram_fn_rtc_slow(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx
}

#[ram(rtc_fast)]
fn attr_ram_fn_rtc_fast(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
fn attr_ram_fn_rtc_fast(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
writeln!(
uart,
"{:<40}: {:08x?}",
Expand Down Expand Up @@ -169,7 +170,7 @@ macro_rules! print_info {
};
}

fn ram_tests(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
fn ram_tests(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
writeln!(uart).unwrap();

attr_none_fn(uart);
Expand Down Expand Up @@ -206,10 +207,10 @@ fn ram_tests(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
}

#[cfg(not(feature = "external_ram"))]
fn external_ram(_uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {}
fn external_ram(_uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {}

#[cfg(feature = "external_ram")]
fn external_ram(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
fn external_ram(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
unsafe {
print_info!(uart, ATTR_RAM_STATIC_EXTERNAL);
print_info!(uart, ATTR_RAM_STATIC_EXTERNAL_BSS);
Expand All @@ -219,7 +220,7 @@ fn external_ram(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
6 changes: 4 additions & 2 deletions examples/rtccntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use esp32_hal::clock_control::{sleep, CPUSource, ClockControl, ClockControlConfi
use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

const BLINK_HZ: Hertz = Hertz(1);

#[no_mangle]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -146,7 +148,7 @@ fn main() -> ! {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
5 changes: 3 additions & 2 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use esp32_hal::prelude::*;
use esp32_hal::clock_control::sleep;
use esp32_hal::dport::Split;
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;

const BLINK_HZ: Hertz = Hertz(2);

#[no_mangle]
fn main() -> ! {
let dp = unsafe { esp32::Peripherals::steal() };
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");

let mut timg0 = dp.TIMG0;
let mut timg1 = dp.TIMG1;
Expand Down Expand Up @@ -71,7 +72,7 @@ fn main() -> ! {

const WDT_WKEY_VALUE: u32 = 0x50D83AA1;

fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
timg0
.wdtwprotect
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });
Expand Down
20 changes: 12 additions & 8 deletions examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ use esp32_hal::dport::Split;
use esp32_hal::dprintln;
use esp32_hal::interrupt::{Interrupt, InterruptLevel};
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
use esp32_hal::target;
use esp32_hal::timer::watchdog::{self, WatchDogResetDuration, WatchdogAction, WatchdogConfig};
use esp32_hal::timer::{Timer, Timer0, Timer1, TimerLact, TimerWithInterrupt};
use esp32_hal::Core::PRO;
use spin::Mutex;

const BLINK_HZ: Hertz = Hertz(2);

static TIMER0: Mutex<RefCell<Option<Timer<esp32::TIMG0, Timer0>>>> = Mutex::new(RefCell::new(None));
static TIMER2: Mutex<RefCell<Option<Timer<esp32::TIMG0, TimerLact>>>> =
static TIMER0: Mutex<RefCell<Option<Timer<target::TIMG0, Timer0>>>> =
Mutex::new(RefCell::new(None));
static TIMER3: Mutex<RefCell<Option<Timer<esp32::TIMG1, Timer0>>>> = Mutex::new(RefCell::new(None));
static TIMER4: Mutex<RefCell<Option<Timer<esp32::TIMG1, Timer1>>>> = Mutex::new(RefCell::new(None));
static TIMER5: Mutex<RefCell<Option<Timer<esp32::TIMG1, TimerLact>>>> =
static TIMER2: Mutex<RefCell<Option<Timer<target::TIMG0, TimerLact>>>> =
Mutex::new(RefCell::new(None));
static TIMER3: Mutex<RefCell<Option<Timer<target::TIMG1, Timer0>>>> =
Mutex::new(RefCell::new(None));
static TIMER4: Mutex<RefCell<Option<Timer<target::TIMG1, Timer1>>>> =
Mutex::new(RefCell::new(None));
static TIMER5: Mutex<RefCell<Option<Timer<target::TIMG1, TimerLact>>>> =
Mutex::new(RefCell::new(None));

static WATCHDOG1: Mutex<RefCell<Option<watchdog::Watchdog<esp32::TIMG1>>>> =
static WATCHDOG1: Mutex<RefCell<Option<watchdog::Watchdog<target::TIMG1>>>> =
Mutex::new(RefCell::new(None));
static TX: Mutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> = spin::Mutex::new(None);
static TX: Mutex<Option<esp32_hal::serial::Tx<target::UART0>>> = spin::Mutex::new(None);

#[no_mangle]
fn main() -> ! {
let dp = esp32::Peripherals::take().unwrap();
let dp = target::Peripherals::take().unwrap();

let (mut dport, dport_clock_control) = dp.DPORT.split();

Expand Down
2 changes: 1 addition & 1 deletion src/analog/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

use core::marker::PhantomData;
use embedded_hal::adc::{Channel, OneShot};
use esp32::{RTCIO, SENS};

use crate::analog::config;
use crate::analog::{ADC1, ADC2};
use crate::gpio::*;
use crate::target::{RTCIO, SENS};

pub struct ADC<ADC> {
adc: PhantomData<ADC>,
Expand Down
Loading