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

Overhaul of GPIO module & adjusted Serial module accordingly. #36

Merged
merged 35 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9658b79
Ignore accidental core files
arjanmels Jun 22, 2020
52d8af6
Corrected multithreaded safety for park/unpark/start
arjanmels Jun 22, 2020
cd43221
Added retrieval of rtc_tick_count
arjanmels Jun 22, 2020
306556a
Moved config to seperate file
arjanmels Jun 22, 2020
9f2fcd8
Updated examples to latest changes in xtensa_lx6
arjanmels Jun 12, 2020
12630be
Updated prelude & timer example
arjanmels Jun 7, 2020
26284c3
Changed all to CriticalSectionSpinLockMutex
arjanmels Jun 13, 2020
929d617
Corrected multithreaded safety for park/unpark/start
arjanmels Jun 11, 2020
0d820b5
Added retrieval of rtc_tick_count
arjanmels Jun 12, 2020
5c2e3f2
Renamed rtc_io_ fields
arjanmels Jun 14, 2020
5c0031b
Renamed GPIO fields
arjanmels Jun 14, 2020
abca882
Simplified GPIO macros
arjanmels Jun 14, 2020
cb96589
Corrected setting open drain mode
arjanmels Jun 14, 2020
041e7c7
Move common code for input to common function
arjanmels Jun 14, 2020
d6b2174
Added soem configuration functions
arjanmels Jun 15, 2020
7de0643
Added iomux enums
arjanmels Jun 16, 2020
612cfe8
Simplified gpio by using register arrays
arjanmels Jun 16, 2020
b687d41
Generalized traits
arjanmels Jun 16, 2020
4b119a7
Improve dgpio functionality
arjanmels Jun 20, 2020
c06cb5e
Corrected enable_wt1c to w1ts
arjanmels Jun 20, 2020
8c5292e
Automatic use of Alternate Function
arjanmels Jun 21, 2020
e3151cf
Adjusted serial example to new gpio
arjanmels Jun 21, 2020
20d5144
Remove usage of macro
arjanmels Jun 21, 2020
727fc78
Fixed enable/rset for all 3 uart
arjanmels Jun 22, 2020
0ec9e00
Added pin initialization & refactor rx/tx
arjanmels Jun 22, 2020
460fc7e
Update example
arjanmels Jun 22, 2020
c198a60
Minor cleanup
arjanmels Jun 22, 2020
9285d4a
Indent fixed
arjanmels Jun 22, 2020
cedabc5
Updated examples
arjanmels Jun 22, 2020
d014035
Updated documentation
arjanmels Jun 22, 2020
ef86077
Changed pin initial state to Unknown
arjanmels Jun 22, 2020
180232f
Apply suggestions from code review for comments and formatting
arjanmels Jun 23, 2020
fd10800
Added todo's to comments
arjanmels Jun 23, 2020
87fc489
Merge branch 'feature-gpio-rename' of github.com:arjanmels/esp32-hal …
arjanmels Jun 23, 2020
7e53a92
bump esp32
MabezDev Jun 24, 2020
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
procmacros/target
**/*.rs.bk
Cargo.lock
.vscode/.cortex-debug*
.vscode/.cortex-debug*
core
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ rt = ["esp32/rt", "xtensa-lx6-rt"]
[dependencies]
esp32-hal-proc-macros = { path = "procmacros" }

xtensa-lx6-rt = { version = "0.2.0", optional = true }
xtensa-lx6 = "0.1.0"
esp32 = { version = "0.5.0", default-features = false }
xtensa-lx6-rt = { version = "0.3.0", optional = true }
xtensa-lx6 = "0.2.0"
esp32 = { version = "0.6.0", default-features = false }
bare-metal = "0.2"
nb = "0.1.2"
spin = "0.5.2"
embedded-hal = { version = "0.2.3", features = ["unproven"] }
linked_list_allocator = { version = "0.8.4", optional = true, default-features = false, features = ["alloc_ref"] }
void = { version = "1.0.2", default-features = false }
Expand Down
Binary file removed core
Binary file not shown.
15 changes: 10 additions & 5 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use esp32_hal::analog::adc::ADC;
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::serial::{config::Config, Serial};
use esp32_hal::target;

#[no_mangle]
Expand Down Expand Up @@ -38,10 +38,16 @@ fn main() -> ! {
let (clkcntrl_config, mut watchdog) = clkcntrl.freeze().unwrap();
watchdog.disable();

/* Setup serial connection */
let serial = Serial::uart0(
let gpios = dp.GPIO.split();

let serial: Serial<_, _, _> = Serial::new(
dp.UART0,
(NoTx, NoRx),
esp32_hal::serial::Pins {
tx: gpios.gpio1,
rx: gpios.gpio3,
cts: None,
rts: None,
},
Config::default(),
clkcntrl_config,
&mut dport,
Expand All @@ -51,7 +57,6 @@ fn main() -> ! {
let (mut tx, _rx) = serial.split();

/* Set ADC pins to analog mode */
let gpios = dp.GPIO.split();
let mut pin36 = gpios.gpio36.into_analog();
let mut pin25 = gpios.gpio25.into_analog();

Expand Down
4 changes: 2 additions & 2 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ extern crate esp32_hal as hal;
extern crate panic_halt;
extern crate xtensa_lx6_rt;

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

/// The default clock source is the onboard crystal
/// In most cases 40mhz (but can be as low as 2mhz depending on the board)
Expand Down
122 changes: 59 additions & 63 deletions examples/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,66 @@ use esp32_hal::clock_control::{sleep, CPUSource::PLL, ClockControl};
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::serial::{config::Config, Serial};
use esp32_hal::target;
use esp32_hal::Core::PRO;

static TX: spin::Mutex<Option<esp32_hal::serial::Tx<target::UART0>>> = spin::Mutex::new(None);
// !!! Cannot use CriticalSectionSpinLockMutex here, because an NMI is fires from within a locked
// section which leads to a deadlock in the NMI interrupt handler. This is not a problem in this
// case as this is a single threaded example. !!!
static TX: xtensa_lx6::mutex::CriticalSectionMutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> =
xtensa_lx6::mutex::CriticalSectionMutex::new(None);

fn locked_print(str: &str) {
(&TX).lock(|tx| {
let tx = tx.as_mut().unwrap();

writeln!(
tx,
" {}, Level: {}",
str,
xtensa_lx6::interrupt::get_level()
)
.unwrap();
});
}

#[interrupt]
fn FROM_CPU_INTR0() {
writeln!(
TX.lock().as_mut().unwrap(),
" FROM_CPU_INTR0, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("FROM_CPU_INTR0");
clear_software_interrupt(Interrupt::FROM_CPU_INTR0).unwrap();
}

#[interrupt]
fn FROM_CPU_INTR1() {
writeln!(
TX.lock().as_mut().unwrap(),
" Start FROM_CPU_INTR1, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("Start FROM_CPU_INTR1");
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR0).unwrap();
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR2).unwrap();
writeln!(
TX.lock().as_mut().unwrap(),
" End FROM_CPU_INTR1, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("End FROM_CPU_INTR1");
clear_software_interrupt(Interrupt::FROM_CPU_INTR1).unwrap();
}

#[interrupt]
fn FROM_CPU_INTR2() {
writeln!(
TX.lock().as_mut().unwrap(),
" FROM_CPU_INTR2, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("FROM_CPU_INTR2");
clear_software_interrupt(Interrupt::FROM_CPU_INTR2).unwrap();
}

#[interrupt]
fn FROM_CPU_INTR3() {
writeln!(
TX.lock().as_mut().unwrap(),
" FROM_CPU_INTR3, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("FROM_CPU_INTR3");
clear_software_interrupt(Interrupt::FROM_CPU_INTR3).unwrap();
}

#[interrupt(INTERNAL_SOFTWARE_LEVEL_3_INTR)]
fn software_level_3() {
writeln!(
TX.lock().as_mut().unwrap(),
" INTERNAL_SOFTWARE_LEVEL_3_INTR, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("INTERNAL_SOFTWARE_LEVEL_3_INTR");
clear_software_interrupt(Interrupt::FROM_CPU_INTR3).unwrap();
}

#[interrupt(INTERNAL_SOFTWARE_LEVEL_1_INTR)]
fn random_name() {
writeln!(
TX.lock().as_mut().unwrap(),
" INTERNAL_SOFTWARE_LEVEL_1_INTR, level: {}",
xtensa_lx6::interrupt::get_level()
)
.unwrap();
locked_print("INTERNAL_SOFTWARE_LEVEL_1_INTR");
clear_software_interrupt(Interrupt::FROM_CPU_INTR3).unwrap();
}

Expand All @@ -98,13 +81,10 @@ fn other_exception(
cause: xtensa_lx6_rt::exception::ExceptionCause,
frame: xtensa_lx6_rt::exception::Context,
) {
writeln!(
TX.lock().as_mut().unwrap(),
"Exception {:?}, {:08x?}",
cause,
frame
)
.unwrap();
(&TX).lock(|tx| {
let tx = tx.as_mut().unwrap();
writeln!(tx, "Exception {:?}, {:08x?}", cause, frame).unwrap();
});
loop {}
}

Expand Down Expand Up @@ -140,10 +120,16 @@ fn main() -> ! {

watchdog.start(20.s());

let gpios = dp.GPIO.split();
// setup serial controller
let mut uart0 = Serial::uart0(
let mut uart0: Serial<_, _, _> = Serial::new(
dp.UART0,
(NoTx, NoRx),
esp32_hal::serial::Pins {
tx: gpios.gpio1,
rx: gpios.gpio3,
cts: None,
rts: None,
},
Config::default(),
clock_control_config,
&mut dport,
Expand All @@ -156,7 +142,7 @@ fn main() -> ! {
writeln!(uart0, "\n\nReboot!\n",).unwrap();

let (tx, _) = uart0.split();
*TX.lock() = Some(tx);
(&TX).lock(|tx_locked| *tx_locked = Some(tx));

interrupt::enable_with_priority(PRO, Interrupt::FROM_CPU_INTR0, InterruptLevel(2)).unwrap();
interrupt::enable_with_priority(PRO, Interrupt::FROM_CPU_INTR1, InterruptLevel(4)).unwrap();
Expand All @@ -167,32 +153,40 @@ fn main() -> ! {

// Trigger various software interrupts, because done in an interrupt free section will
// actually trigger at the end in order of priority
interrupt::free(|_| {
writeln!(TX.lock().as_mut().unwrap(), "Start Trigger Interrupts",).unwrap();
(&TX).lock(|tx| {
let tx = tx.as_mut().unwrap();

writeln!(tx, "Start Trigger Interrupts",).unwrap();
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR0).unwrap();
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR1).unwrap();
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR2).unwrap();
// this one will trigger immediately as level 7 is Non-Maskable Intterupt (NMI)
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR3).unwrap();
interrupt::set_software_interrupt(Interrupt::INTERNAL_SOFTWARE_LEVEL_1_INTR).unwrap();
interrupt::set_software_interrupt(Interrupt::INTERNAL_SOFTWARE_LEVEL_3_INTR).unwrap();
writeln!(TX.lock().as_mut().unwrap(), "End Trigger Interrupts",).unwrap();
writeln!(tx, "End Trigger Interrupts",).unwrap();
});

// Trigger outside of interrupt free section, triggers immediately
writeln!(TX.lock().as_mut().unwrap(), "Start Trigger Interrupt",).unwrap();
(&TX).lock(|tx| {
let tx = tx.as_mut().unwrap();
writeln!(tx, "Start Trigger Interrupt",).unwrap();
});
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR0).unwrap();
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR1).unwrap();
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR2).unwrap();
// this one will trigger immediately as level 7 is Non-Maskable Intterupt (NMI)
interrupt::set_software_interrupt(Interrupt::FROM_CPU_INTR3).unwrap();
interrupt::set_software_interrupt(Interrupt::INTERNAL_SOFTWARE_LEVEL_1_INTR).unwrap();
interrupt::set_software_interrupt(Interrupt::INTERNAL_SOFTWARE_LEVEL_3_INTR).unwrap();
writeln!(TX.lock().as_mut().unwrap(), "End Trigger Interrupt",).unwrap();

// Trigger a LoadStoreError due to unaligned access in the IRAM
(&TX).lock(|tx| {
let tx = tx.as_mut().unwrap();
writeln!(tx, "End Trigger Interrupt",).unwrap();
writeln!(tx, "\nTrigger exception:",).unwrap();
});

writeln!(TX.lock().as_mut().unwrap(), "\nTrigger exception:",).unwrap();
// Trigger a LoadStoreError due to unaligned access in the IRAM

#[link_section = ".rwtext"]
static mut IRAM: [u8; 12] = [0; 12];
Expand All @@ -203,8 +197,10 @@ fn main() -> ! {

loop {
sleep(1.s());
interrupt::free(|_| {
writeln!(TX.lock().as_mut().unwrap(), "Wait for watchdog reset").unwrap()
(&TX).lock(|tx| {
let tx = tx.as_mut().unwrap();

writeln!(tx, "Wait for watchdog reset").unwrap()
});
}
}
Expand Down
16 changes: 11 additions & 5 deletions examples/hall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use esp32_hal::analog::adc::ADC;
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::serial::{config::Config, Serial};
use esp32_hal::target;

#[no_mangle]
Expand Down Expand Up @@ -38,19 +38,25 @@ fn main() -> ! {
let (clkcntrl_config, mut watchdog) = clkcntrl.freeze().unwrap();
watchdog.disable();

/* Setup serial connection */
let serial = Serial::uart0(
let gpios = dp.GPIO.split();
// setup serial controller
let serial: Serial<_, _, _> = Serial::new(
dp.UART0,
(NoTx, NoRx),
esp32_hal::serial::Pins {
tx: gpios.gpio1,
rx: gpios.gpio3,
cts: None,
rts: None,
},
Config::default(),
clkcntrl_config,
&mut dport,
)
.unwrap();

let (mut tx, _rx) = serial.split();

/* Set ADC pins to analog mode */
let gpios = dp.GPIO.split();
let mut pin36 = gpios.gpio36.into_analog();
let mut pin39 = gpios.gpio39.into_analog();

Expand Down
Loading