Skip to content

Commit f560b3c

Browse files
committed
Add ESP32 support
1 parent 99b5c17 commit f560b3c

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

src/generate/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ pub fn render(
9797
extern crate riscv_rt;
9898
});
9999
}
100+
Target::ESP32 => {
101+
out.extend(quote! {
102+
extern crate xtensa_lx6_rt;
103+
});
104+
}
100105
Target::None => {}
101106
}
102107

@@ -226,6 +231,7 @@ pub fn render(
226231
Target::CortexM => Some(Ident::new("cortex_m", span)),
227232
Target::Msp430 => Some(Ident::new("msp430", span)),
228233
Target::RISCV => Some(Ident::new("riscv", span)),
234+
Target::ESP32 => Some(Ident::new("xtensa_lx6_rt", span)),
229235
Target::None => None,
230236
}
231237
.map(|krate| {

src/generate/interrupt.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ pub fn render(
125125
});
126126
}
127127
Target::RISCV => {}
128+
Target::ESP32 => {
129+
for name in &names {
130+
writeln!(device_x, "PROVIDE({} = DefaultHandler);", name)?;
131+
}
132+
133+
root.extend(quote! {
134+
#[cfg(feature = "rt")]
135+
extern "C" {
136+
#(fn #names();)*
137+
}
138+
139+
#[doc(hidden)]
140+
pub union Vector {
141+
pub _handler: unsafe extern "C" fn(),
142+
_reserved: u32,
143+
}
144+
145+
#[cfg(feature = "rt")]
146+
#[doc(hidden)]
147+
pub static __INTERRUPTS: [Vector; #n] = [
148+
#elements
149+
];
150+
});
151+
}
128152
Target::None => {}
129153
}
130154

@@ -137,7 +161,7 @@ pub fn render(
137161

138162
let interrupt_enum = quote! {
139163
///Enumeration of all the interrupts
140-
#[derive(Copy, Clone, Debug)]
164+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
141165
#enum_repr
142166
pub enum Interrupt {
143167
#variants
@@ -178,7 +202,7 @@ pub fn render(
178202
_ => "C",
179203
};
180204

181-
if target != Target::CortexM && target != Target::Msp430 {
205+
if target != Target::CortexM && target != Target::Msp430 && target != Target::ESP32 {
182206
mod_items.extend(quote! {
183207
#[cfg(feature = "rt")]
184208
#[macro_export]

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
//!
1919
//! # Usage
2020
//!
21-
//! `svd2rust` supports Cortex-M, MSP430 and RISCV microcontrollers. The generated crate can be
22-
//! tailored for either architecture using the `--target` flag. The flag accepts "cortex-m",
23-
//! "msp430", "riscv" and "none" as values. "none" can be used to generate a crate that's
21+
//! `svd2rust` supports Cortex-M, MSP430, RISCV and ESP32 microcontrollers. The generated crate can
22+
//! be tailored for either architecture using the `--target` flag. The flag accepts "cortex-m",
23+
//! "msp430", "riscv", "esp32" and "none" as values. "none" can be used to generate a crate that's
2424
//! architecture agnostic and that should work for architectures that `svd2rust` doesn't currently
2525
//! know about like the Cortex-A architecture.
2626
//!

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn run() -> Result<()> {
103103
file.write_all(data.as_ref())
104104
.expect("Could not write code to lib.rs");
105105

106-
if target == Target::CortexM || target == Target::Msp430 {
106+
if target == Target::CortexM || target == Target::Msp430 || target == Target::ESP32 {
107107
writeln!(File::create("device.x")?, "{}", device_x)?;
108108
writeln!(File::create("build.rs")?, "{}", build_rs())?;
109109
}

src/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum Target {
1818
CortexM,
1919
Msp430,
2020
RISCV,
21+
ESP32,
2122
None,
2223
}
2324

@@ -27,6 +28,7 @@ impl Target {
2728
"cortex-m" => Target::CortexM,
2829
"msp430" => Target::Msp430,
2930
"riscv" => Target::RISCV,
31+
"esp32" => Target::ESP32,
3032
"none" => Target::None,
3133
_ => bail!("unknown target {}", s),
3234
})

0 commit comments

Comments
 (0)