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

Commit 845676e

Browse files
authored
Merge pull request #37 from chocol4te/feat_target
Use crate::target pattern
2 parents faa5450 + fc4c0d8 commit 845676e

29 files changed

+128
-105
lines changed

examples/adc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use esp32_hal::analog::config::{Adc1Config, Adc2Config, Attenuation};
1111
use esp32_hal::clock_control::sleep;
1212
use esp32_hal::dport::Split;
1313
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
14+
use esp32_hal::target;
1415

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

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

8182
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
8283

83-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
84+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
8485
timg0
8586
.wdtwprotect
8687
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/alloc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use esp32_hal::clock_control::{sleep, ClockControl};
1919
use esp32_hal::dport::Split;
2020
use esp32_hal::dprintln;
2121
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
22+
use esp32_hal::target;
2223

2324
#[macro_use]
2425
extern crate alloc;
@@ -48,7 +49,7 @@ macro_rules! print_info {
4849

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

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

158159
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
159160

160-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
161+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
161162
timg0
162163
.wdtwprotect
163164
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/blinky.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate panic_halt;
66
extern crate xtensa_lx6_rt;
77

88
use hal::prelude::*;
9+
use hal::target;
910
use xtensa_lx6::get_cycle_count;
1011

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

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

2122
let mut rtccntl = dp.RTCCNTL;
2223
let mut timg0 = dp.TIMG0;
@@ -39,7 +40,7 @@ fn main() -> ! {
3940
}
4041
}
4142

42-
fn disable_rtc_wdt(rtccntl: &mut hal::esp32::RTCCNTL) {
43+
fn disable_rtc_wdt(rtccntl: &mut target::RTCCNTL) {
4344
/* Disables the RTCWDT */
4445
rtccntl
4546
.wdtwprotect
@@ -61,7 +62,7 @@ fn disable_rtc_wdt(rtccntl: &mut hal::esp32::RTCCNTL) {
6162
rtccntl.wdtwprotect.write(|w| unsafe { w.bits(0x0) });
6263
}
6364

64-
fn disable_timg_wdts(timg0: &mut hal::esp32::TIMG0, timg1: &mut hal::esp32::TIMG1) {
65+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
6566
timg0
6667
.wdtwprotect
6768
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/dac.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use esp32_hal::prelude::*;
88
use esp32_hal::analog::dac::DAC;
99
use esp32_hal::clock_control::sleep;
1010
use esp32_hal::dport::Split;
11+
use esp32_hal::target;
1112

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

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

6162
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
6263

63-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
64+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
6465
timg0
6566
.wdtwprotect
6667
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/exception.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ use esp32_hal::dport::Split;
1313
use esp32_hal::dprintln;
1414
use esp32_hal::interrupt::{clear_software_interrupt, Interrupt, Interrupt::*, InterruptLevel};
1515
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
16+
use esp32_hal::target;
1617
use esp32_hal::Core::PRO;
1718

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

2021
#[interrupt]
2122
fn FROM_CPU_INTR0() {
@@ -109,7 +110,7 @@ fn other_exception(
109110

110111
#[entry]
111112
fn main() -> ! {
112-
let dp = esp32::Peripherals::take().unwrap();
113+
let dp = target::Peripherals::take().unwrap();
113114

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

211212
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
212213

213-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
214+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
214215
timg0
215216
.wdtwprotect
216217
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/hall.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use esp32_hal::analog::config::{Adc1Config, Attenuation};
1111
use esp32_hal::clock_control::sleep;
1212
use esp32_hal::dport::Split;
1313
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
14+
use esp32_hal::target;
1415

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

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

7576
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
7677

77-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
78+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
7879
timg0
7980
.wdtwprotect
8081
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/mem.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use esp32_hal::dport::Split;
1515
use esp32_hal::dprintln;
1616
use esp32_hal::mem::{memcmp, memcpy, memcpy_reverse, memset};
1717
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
18+
use esp32_hal::target;
1819

1920
use xtensa_lx6::get_cycle_count;
2021

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

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

3132
let mut timg0 = dp.TIMG0;
3233
let mut timg1 = dp.TIMG1;
@@ -186,7 +187,7 @@ unsafe fn time_memcpy(
186187

187188
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
188189

189-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
190+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
190191
timg0
191192
.wdtwprotect
192193
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/multicore.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ use esp32_hal::clock_control::{CPUSource, ClockControl, ClockControlConfig};
1010
use esp32_hal::dport::Split;
1111
use esp32_hal::dprintln;
1212
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
13+
use esp32_hal::target;
1314

1415
use xtensa_lx6::{get_cycle_count, get_stack_pointer};
1516

1617
const BLINK_HZ: Hertz = Hertz(1);
1718

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

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

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

199200
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
200201

201-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
202+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
202203
timg0
203204
.wdtwprotect
204205
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/ram.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ use esp32_hal::clock_control::{sleep, ClockControl};
1010
use esp32_hal::dport::Split;
1111
use esp32_hal::dprintln;
1212
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
13+
use esp32_hal::target;
1314

1415
use xtensa_lx6::get_program_counter;
1516

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

2021
let mut timg0 = dp.TIMG0;
2122
let mut timg1 = dp.TIMG1;
@@ -65,7 +66,7 @@ fn main() -> ! {
6566
}
6667
}
6768

68-
fn attr_none_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
69+
fn attr_none_fn(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
6970
writeln!(
7071
uart,
7172
"{:<40}: {:08x?}",
@@ -76,7 +77,7 @@ fn attr_none_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>
7677
}
7778

7879
#[ram]
79-
fn attr_ram_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
80+
fn attr_ram_fn(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
8081
writeln!(
8182
uart,
8283
"{:<40}: {:08x?}",
@@ -87,7 +88,7 @@ fn attr_ram_fn(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>)
8788
}
8889

8990
#[ram(rtc_slow)]
90-
fn attr_ram_fn_rtc_slow(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
91+
fn attr_ram_fn_rtc_slow(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
9192
writeln!(
9293
uart,
9394
"{:<40}: {:08x?}",
@@ -98,7 +99,7 @@ fn attr_ram_fn_rtc_slow(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx
9899
}
99100

100101
#[ram(rtc_fast)]
101-
fn attr_ram_fn_rtc_fast(uart: &mut esp32_hal::serial::Serial<esp32::UART0, (NoTx, NoRx)>) {
102+
fn attr_ram_fn_rtc_fast(uart: &mut esp32_hal::serial::Serial<target::UART0, (NoTx, NoRx)>) {
102103
writeln!(
103104
uart,
104105
"{:<40}: {:08x?}",
@@ -169,7 +170,7 @@ macro_rules! print_info {
169170
};
170171
}
171172

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

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

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

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

220221
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
221222

222-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
223+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
223224
timg0
224225
.wdtwprotect
225226
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/rtccntl.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ use esp32_hal::clock_control::{sleep, CPUSource, ClockControl, ClockControlConfi
1010
use esp32_hal::dport::Split;
1111
use esp32_hal::dprintln;
1212
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
13+
use esp32_hal::target;
14+
1315
const BLINK_HZ: Hertz = Hertz(1);
1416

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

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

147149
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
148150

149-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
151+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
150152
timg0
151153
.wdtwprotect
152154
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/serial.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ use esp32_hal::prelude::*;
1010
use esp32_hal::clock_control::sleep;
1111
use esp32_hal::dport::Split;
1212
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
13+
use esp32_hal::target;
1314

1415
const BLINK_HZ: Hertz = Hertz(2);
1516

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

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

7273
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
7374

74-
fn disable_timg_wdts(timg0: &mut esp32::TIMG0, timg1: &mut esp32::TIMG1) {
75+
fn disable_timg_wdts(timg0: &mut target::TIMG0, timg1: &mut target::TIMG1) {
7576
timg0
7677
.wdtwprotect
7778
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) });

examples/timer.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@ use esp32_hal::dport::Split;
1414
use esp32_hal::dprintln;
1515
use esp32_hal::interrupt::{Interrupt, InterruptLevel};
1616
use esp32_hal::serial::{config::Config, NoRx, NoTx, Serial};
17+
use esp32_hal::target;
1718
use esp32_hal::timer::watchdog::{self, WatchDogResetDuration, WatchdogAction, WatchdogConfig};
1819
use esp32_hal::timer::{Timer, Timer0, Timer1, TimerLact, TimerWithInterrupt};
1920
use esp32_hal::Core::PRO;
2021
use spin::Mutex;
2122

2223
const BLINK_HZ: Hertz = Hertz(2);
2324

24-
static TIMER0: Mutex<RefCell<Option<Timer<esp32::TIMG0, Timer0>>>> = Mutex::new(RefCell::new(None));
25-
static TIMER2: Mutex<RefCell<Option<Timer<esp32::TIMG0, TimerLact>>>> =
25+
static TIMER0: Mutex<RefCell<Option<Timer<target::TIMG0, Timer0>>>> =
2626
Mutex::new(RefCell::new(None));
27-
static TIMER3: Mutex<RefCell<Option<Timer<esp32::TIMG1, Timer0>>>> = Mutex::new(RefCell::new(None));
28-
static TIMER4: Mutex<RefCell<Option<Timer<esp32::TIMG1, Timer1>>>> = Mutex::new(RefCell::new(None));
29-
static TIMER5: Mutex<RefCell<Option<Timer<esp32::TIMG1, TimerLact>>>> =
27+
static TIMER2: Mutex<RefCell<Option<Timer<target::TIMG0, TimerLact>>>> =
28+
Mutex::new(RefCell::new(None));
29+
static TIMER3: Mutex<RefCell<Option<Timer<target::TIMG1, Timer0>>>> =
30+
Mutex::new(RefCell::new(None));
31+
static TIMER4: Mutex<RefCell<Option<Timer<target::TIMG1, Timer1>>>> =
32+
Mutex::new(RefCell::new(None));
33+
static TIMER5: Mutex<RefCell<Option<Timer<target::TIMG1, TimerLact>>>> =
3034
Mutex::new(RefCell::new(None));
3135

32-
static WATCHDOG1: Mutex<RefCell<Option<watchdog::Watchdog<esp32::TIMG1>>>> =
36+
static WATCHDOG1: Mutex<RefCell<Option<watchdog::Watchdog<target::TIMG1>>>> =
3337
Mutex::new(RefCell::new(None));
34-
static TX: Mutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> = spin::Mutex::new(None);
38+
static TX: Mutex<Option<esp32_hal::serial::Tx<target::UART0>>> = spin::Mutex::new(None);
3539

3640
#[no_mangle]
3741
fn main() -> ! {
38-
let dp = esp32::Peripherals::take().unwrap();
42+
let dp = target::Peripherals::take().unwrap();
3943

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

src/analog/adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
2222
use core::marker::PhantomData;
2323
use embedded_hal::adc::{Channel, OneShot};
24-
use esp32::{RTCIO, SENS};
2524

2625
use crate::analog::config;
2726
use crate::analog::{ADC1, ADC2};
2827
use crate::gpio::*;
28+
use crate::target::{RTCIO, SENS};
2929

3030
pub struct ADC<ADC> {
3131
adc: PhantomData<ADC>,

0 commit comments

Comments
 (0)