Skip to content

Commit

Permalink
Add basic support for the Wi-Fi peripheral on the ESP32. (#284)
Browse files Browse the repository at this point in the history
* Added support for the WiFi peripheral.

* Added basic crypto and cleaned up filtering.

* Added some statistic registers.

* Regenerated PAC.

* Fixed addressOffset fields for filters.

* Revert "Fixed addressOffset fields for filters."

This reverts commit 6bc584d.

* Added unknown PMD register.

* Temporarily removed crypto support
  • Loading branch information
Frostie314159 authored Dec 17, 2024
1 parent 046f3b3 commit ffbee35
Show file tree
Hide file tree
Showing 50 changed files with 2,603 additions and 0 deletions.
49 changes: 49 additions & 0 deletions esp32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,52 @@ impl core::fmt::Debug for UHCI1 {
}
#[doc = "Universal Host Controller Interface 1"]
pub use self::uhci0 as uhci1;
#[doc = "MAC controller for Wi-Fi peripheral"]
pub struct WIFI {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for WIFI {}
impl WIFI {
#[doc = r"Pointer to the register block"]
pub const PTR: *const wifi::RegisterBlock = 0x3ff7_3000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const wifi::RegisterBlock {
Self::PTR
}
#[doc = r" Steal an instance of this peripheral"]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc = r" Ensure that the new instance of the peripheral cannot be used in a way"]
#[doc = r" that may race with any existing instances, for example by only"]
#[doc = r" accessing read-only or write-only registers, or by consuming the"]
#[doc = r" original peripheral and using critical sections to coordinate"]
#[doc = r" access between multiple new instances."]
#[doc = r""]
#[doc = r" Additionally, other software such as HALs may rely on only one"]
#[doc = r" peripheral instance existing to ensure memory safety; ensure"]
#[doc = r" no stolen instances are passed to such software."]
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl Deref for WIFI {
type Target = wifi::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for WIFI {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("WIFI").finish()
}
}
#[doc = "MAC controller for Wi-Fi peripheral"]
pub mod wifi;
#[no_mangle]
static mut DEVICE_PERIPHERALS: bool = false;
#[doc = r" All the peripherals."]
Expand Down Expand Up @@ -2640,6 +2686,8 @@ pub struct Peripherals {
pub UHCI0: UHCI0,
#[doc = "UHCI1"]
pub UHCI1: UHCI1,
#[doc = "WIFI"]
pub WIFI: WIFI,
}
impl Peripherals {
#[doc = r" Returns all the peripherals *once*."]
Expand Down Expand Up @@ -2708,6 +2756,7 @@ impl Peripherals {
UART2: UART2::steal(),
UHCI0: UHCI0::steal(),
UHCI1: UHCI1::steal(),
WIFI: WIFI::steal(),
}
}
}
371 changes: 371 additions & 0 deletions esp32/src/wifi.rs

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions esp32/src/wifi/crypto_key_entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[repr(C)]
#[cfg_attr(feature = "impl-register-debug", derive(Debug))]
#[doc = "The cryptographic keys, to be used by the MAC"]
pub struct CRYPTO_KEY_ENTRY {
addr_low: ADDR_LOW,
addr_high: ADDR_HIGH,
_reserved_end: [u8; 0x20],
}
impl CRYPTO_KEY_ENTRY {
#[doc = "0x00 - "]
#[inline(always)]
pub const fn addr_low(&self) -> &ADDR_LOW {
&self.addr_low
}
#[doc = "0x04 - "]
#[inline(always)]
pub const fn addr_high(&self) -> &ADDR_HIGH {
&self.addr_high
}
}
#[doc = "ADDR_LOW (rw) register accessor: \n\nYou can [`read`](crate::Reg::read) this register and get [`addr_low::R`]. You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`addr_low::W`]. You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [`mod@addr_low`] module"]
pub type ADDR_LOW = crate::Reg<addr_low::ADDR_LOW_SPEC>;
#[doc = ""]
pub mod addr_low;
#[doc = "ADDR_HIGH (rw) register accessor: \n\nYou can [`read`](crate::Reg::read) this register and get [`addr_high::R`]. You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`addr_high::W`]. You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [`mod@addr_high`] module"]
pub type ADDR_HIGH = crate::Reg<addr_high::ADDR_HIGH_SPEC>;
#[doc = ""]
pub mod addr_high;
92 changes: 92 additions & 0 deletions esp32/src/wifi/crypto_key_entry/addr_high.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#[doc = "Register `ADDR_HIGH` reader"]
pub type R = crate::R<ADDR_HIGH_SPEC>;
#[doc = "Register `ADDR_HIGH` writer"]
pub type W = crate::W<ADDR_HIGH_SPEC>;
#[doc = "Field `ADDR` reader - "]
pub type ADDR_R = crate::FieldReader<u16>;
#[doc = "Field `ADDR` writer - "]
pub type ADDR_W<'a, REG> = crate::FieldWriter<'a, REG, 16, u16>;
#[doc = "Field `ALGORITHM` reader - "]
pub type ALGORITHM_R = crate::FieldReader;
#[doc = "Field `ALGORITHM` writer - "]
pub type ALGORITHM_W<'a, REG> = crate::FieldWriter<'a, REG, 3>;
#[doc = "Field `INTERFACE` reader - "]
pub type INTERFACE_R = crate::FieldReader;
#[doc = "Field `INTERFACE` writer - "]
pub type INTERFACE_W<'a, REG> = crate::FieldWriter<'a, REG, 2>;
#[doc = "Field `SUPPLICANT_KEY_INDEX` reader - "]
pub type SUPPLICANT_KEY_INDEX_R = crate::FieldReader;
#[doc = "Field `SUPPLICANT_KEY_INDEX` writer - "]
pub type SUPPLICANT_KEY_INDEX_W<'a, REG> = crate::FieldWriter<'a, REG, 2>;
impl R {
#[doc = "Bits 0:15"]
#[inline(always)]
pub fn addr(&self) -> ADDR_R {
ADDR_R::new((self.bits & 0xffff) as u16)
}
#[doc = "Bits 18:20"]
#[inline(always)]
pub fn algorithm(&self) -> ALGORITHM_R {
ALGORITHM_R::new(((self.bits >> 18) & 7) as u8)
}
#[doc = "Bits 24:25"]
#[inline(always)]
pub fn interface(&self) -> INTERFACE_R {
INTERFACE_R::new(((self.bits >> 24) & 3) as u8)
}
#[doc = "Bits 30:31"]
#[inline(always)]
pub fn supplicant_key_index(&self) -> SUPPLICANT_KEY_INDEX_R {
SUPPLICANT_KEY_INDEX_R::new(((self.bits >> 30) & 3) as u8)
}
}
#[cfg(feature = "impl-register-debug")]
impl core::fmt::Debug for R {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("ADDR_HIGH")
.field("addr", &self.addr())
.field("algorithm", &self.algorithm())
.field("interface", &self.interface())
.field("supplicant_key_index", &self.supplicant_key_index())
.finish()
}
}
impl W {
#[doc = "Bits 0:15"]
#[inline(always)]
pub fn addr(&mut self) -> ADDR_W<ADDR_HIGH_SPEC> {
ADDR_W::new(self, 0)
}
#[doc = "Bits 18:20"]
#[inline(always)]
pub fn algorithm(&mut self) -> ALGORITHM_W<ADDR_HIGH_SPEC> {
ALGORITHM_W::new(self, 18)
}
#[doc = "Bits 24:25"]
#[inline(always)]
pub fn interface(&mut self) -> INTERFACE_W<ADDR_HIGH_SPEC> {
INTERFACE_W::new(self, 24)
}
#[doc = "Bits 30:31"]
#[inline(always)]
pub fn supplicant_key_index(&mut self) -> SUPPLICANT_KEY_INDEX_W<ADDR_HIGH_SPEC> {
SUPPLICANT_KEY_INDEX_W::new(self, 30)
}
}
#[doc = "\n\nYou can [`read`](crate::Reg::read) this register and get [`addr_high::R`](R). You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`addr_high::W`](W). You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
pub struct ADDR_HIGH_SPEC;
impl crate::RegisterSpec for ADDR_HIGH_SPEC {
type Ux = u32;
}
#[doc = "`read()` method returns [`addr_high::R`](R) reader structure"]
impl crate::Readable for ADDR_HIGH_SPEC {}
#[doc = "`write(|w| ..)` method takes [`addr_high::W`](W) writer structure"]
impl crate::Writable for ADDR_HIGH_SPEC {
type Safety = crate::Unsafe;
const ZERO_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
const ONE_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
}
#[doc = "`reset()` method sets ADDR_HIGH to value 0"]
impl crate::Resettable for ADDR_HIGH_SPEC {
const RESET_VALUE: u32 = 0;
}
28 changes: 28 additions & 0 deletions esp32/src/wifi/crypto_key_entry/addr_low.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[doc = "Register `ADDR_LOW` reader"]
pub type R = crate::R<ADDR_LOW_SPEC>;
#[doc = "Register `ADDR_LOW` writer"]
pub type W = crate::W<ADDR_LOW_SPEC>;
#[cfg(feature = "impl-register-debug")]
impl core::fmt::Debug for R {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.bits())
}
}
impl W {}
#[doc = "\n\nYou can [`read`](crate::Reg::read) this register and get [`addr_low::R`](R). You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`addr_low::W`](W). You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
pub struct ADDR_LOW_SPEC;
impl crate::RegisterSpec for ADDR_LOW_SPEC {
type Ux = u32;
}
#[doc = "`read()` method returns [`addr_low::R`](R) reader structure"]
impl crate::Readable for ADDR_LOW_SPEC {}
#[doc = "`write(|w| ..)` method takes [`addr_low::W`](W) writer structure"]
impl crate::Writable for ADDR_LOW_SPEC {
type Safety = crate::Unsafe;
const ZERO_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
const ONE_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
}
#[doc = "`reset()` method sets ADDR_LOW to value 0"]
impl crate::Resettable for ADDR_LOW_SPEC {
const RESET_VALUE: u32 = 0;
}
28 changes: 28 additions & 0 deletions esp32/src/wifi/ctrl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[doc = "Register `CTRL` reader"]
pub type R = crate::R<CTRL_SPEC>;
#[doc = "Register `CTRL` writer"]
pub type W = crate::W<CTRL_SPEC>;
#[cfg(feature = "impl-register-debug")]
impl core::fmt::Debug for R {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.bits())
}
}
impl W {}
#[doc = "Exact name and meaning unknown, used for initializing the MAC\n\nYou can [`read`](crate::Reg::read) this register and get [`ctrl::R`](R). You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`ctrl::W`](W). You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
pub struct CTRL_SPEC;
impl crate::RegisterSpec for CTRL_SPEC {
type Ux = u32;
}
#[doc = "`read()` method returns [`ctrl::R`](R) reader structure"]
impl crate::Readable for CTRL_SPEC {}
#[doc = "`write(|w| ..)` method takes [`ctrl::W`](W) writer structure"]
impl crate::Writable for CTRL_SPEC {
type Safety = crate::Unsafe;
const ZERO_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
const ONE_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
}
#[doc = "`reset()` method sets CTRL to value 0"]
impl crate::Resettable for CTRL_SPEC {
const RESET_VALUE: u32 = 0;
}
119 changes: 119 additions & 0 deletions esp32/src/wifi/filter_bank.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#[repr(C)]
#[cfg_attr(feature = "impl-register-debug", derive(Debug))]
#[doc = "Filter banks for frame reception. Bank zero is for the BSSID and bank one for the RA. Each filter bank has registers for two interfaces."]
pub struct FILTER_BANK {
addr_low: (),
_reserved1: [u8; 0x04],
addr_high: (),
_reserved2: [u8; 0x1c],
mask_low: (),
_reserved3: [u8; 0x04],
mask_high: (),
_reserved_end: [u8; 0x1c],
}
impl FILTER_BANK {
#[doc = "0x00..0x08 - First 4 bytes of BSSID MAC address filter"]
#[inline(always)]
pub const fn addr_low(&self, n: usize) -> &ADDR_LOW {
#[allow(clippy::no_effect)]
[(); 2][n];
unsafe { &*core::ptr::from_ref(self).cast::<u8>().add(8 * n).cast() }
}
#[doc = "Iterator for array of:"]
#[doc = "0x00..0x08 - First 4 bytes of BSSID MAC address filter"]
#[inline(always)]
pub fn addr_low_iter(&self) -> impl Iterator<Item = &ADDR_LOW> {
(0..2).map(move |n| unsafe { &*core::ptr::from_ref(self).cast::<u8>().add(8 * n).cast() })
}
#[doc = "0x04..0x0c - last 2 bytes of BSSID MAC address filter"]
#[inline(always)]
pub const fn addr_high(&self, n: usize) -> &ADDR_HIGH {
#[allow(clippy::no_effect)]
[(); 2][n];
unsafe {
&*core::ptr::from_ref(self)
.cast::<u8>()
.add(4)
.add(8 * n)
.cast()
}
}
#[doc = "Iterator for array of:"]
#[doc = "0x04..0x0c - last 2 bytes of BSSID MAC address filter"]
#[inline(always)]
pub fn addr_high_iter(&self) -> impl Iterator<Item = &ADDR_HIGH> {
(0..2).map(move |n| unsafe {
&*core::ptr::from_ref(self)
.cast::<u8>()
.add(4)
.add(8 * n)
.cast()
})
}
#[doc = "0x20..0x28 - First 4 bytes of BSSID MAC address filter mask"]
#[inline(always)]
pub const fn mask_low(&self, n: usize) -> &MASK_LOW {
#[allow(clippy::no_effect)]
[(); 2][n];
unsafe {
&*core::ptr::from_ref(self)
.cast::<u8>()
.add(32)
.add(8 * n)
.cast()
}
}
#[doc = "Iterator for array of:"]
#[doc = "0x20..0x28 - First 4 bytes of BSSID MAC address filter mask"]
#[inline(always)]
pub fn mask_low_iter(&self) -> impl Iterator<Item = &MASK_LOW> {
(0..2).map(move |n| unsafe {
&*core::ptr::from_ref(self)
.cast::<u8>()
.add(32)
.add(8 * n)
.cast()
})
}
#[doc = "0x24..0x2c - last 2 bytes of BSSID MAC address filter mask"]
#[inline(always)]
pub const fn mask_high(&self, n: usize) -> &MASK_HIGH {
#[allow(clippy::no_effect)]
[(); 2][n];
unsafe {
&*core::ptr::from_ref(self)
.cast::<u8>()
.add(36)
.add(8 * n)
.cast()
}
}
#[doc = "Iterator for array of:"]
#[doc = "0x24..0x2c - last 2 bytes of BSSID MAC address filter mask"]
#[inline(always)]
pub fn mask_high_iter(&self) -> impl Iterator<Item = &MASK_HIGH> {
(0..2).map(move |n| unsafe {
&*core::ptr::from_ref(self)
.cast::<u8>()
.add(36)
.add(8 * n)
.cast()
})
}
}
#[doc = "ADDR_LOW (rw) register accessor: First 4 bytes of BSSID MAC address filter\n\nYou can [`read`](crate::Reg::read) this register and get [`addr_low::R`]. You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`addr_low::W`]. You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [`mod@addr_low`] module"]
pub type ADDR_LOW = crate::Reg<addr_low::ADDR_LOW_SPEC>;
#[doc = "First 4 bytes of BSSID MAC address filter"]
pub mod addr_low;
#[doc = "ADDR_HIGH (rw) register accessor: last 2 bytes of BSSID MAC address filter\n\nYou can [`read`](crate::Reg::read) this register and get [`addr_high::R`]. You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`addr_high::W`]. You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [`mod@addr_high`] module"]
pub type ADDR_HIGH = crate::Reg<addr_high::ADDR_HIGH_SPEC>;
#[doc = "last 2 bytes of BSSID MAC address filter"]
pub mod addr_high;
#[doc = "MASK_LOW (rw) register accessor: First 4 bytes of BSSID MAC address filter mask\n\nYou can [`read`](crate::Reg::read) this register and get [`mask_low::R`]. You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`mask_low::W`]. You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [`mod@mask_low`] module"]
pub type MASK_LOW = crate::Reg<mask_low::MASK_LOW_SPEC>;
#[doc = "First 4 bytes of BSSID MAC address filter mask"]
pub mod mask_low;
#[doc = "MASK_HIGH (rw) register accessor: last 2 bytes of BSSID MAC address filter mask\n\nYou can [`read`](crate::Reg::read) this register and get [`mask_high::R`]. You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`mask_high::W`]. You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [`mod@mask_high`] module"]
pub type MASK_HIGH = crate::Reg<mask_high::MASK_HIGH_SPEC>;
#[doc = "last 2 bytes of BSSID MAC address filter mask"]
pub mod mask_high;
Loading

0 comments on commit ffbee35

Please sign in to comment.