examples: Simplify & fix naming

fix-spi
Harry Ho 2021-04-29 17:08:18 +08:00
parent b9b28f0725
commit 78e4d82660
2 changed files with 15 additions and 16 deletions

View File

@ -17,8 +17,7 @@ use stm32f4xx_hal::{
spi::Spi, spi::Spi,
time::Hertz time::Hertz
}; };
use enc424j600; use enc424j600::smoltcp_phy;
use enc424j600::{smoltcp_phy, EthController};
use smoltcp::wire::{ use smoltcp::wire::{
EthernetAddress, IpAddress, IpCidr, Ipv6Cidr EthernetAddress, IpAddress, IpCidr, Ipv6Cidr
@ -78,7 +77,7 @@ use stm32f4xx_hal::{
Alternate, AF5, Output, PushPull Alternate, AF5, Output, PushPull
} }
}; };
type BoosterSpiEth = enc424j600::SpiEth< type SpiEth = enc424j600::Enc424j600<
Spi<SPI1, (PA5<Alternate<AF5>>, PA6<Alternate<AF5>>, PA7<Alternate<AF5>>)>, Spi<SPI1, (PA5<Alternate<AF5>>, PA6<Alternate<AF5>>, PA7<Alternate<AF5>>)>,
PA4<Output<PushPull>>, PA4<Output<PushPull>>,
fn(u32) -> () fn(u32) -> ()
@ -102,7 +101,7 @@ const APP: () = {
struct Resources { struct Resources {
eth_iface: EthernetInterface< eth_iface: EthernetInterface<
'static, 'static,
smoltcp_phy::SmoltcpDevice<BoosterSpiEth>>, smoltcp_phy::SmoltcpDevice<SpiEth>>,
itm: ITM itm: ITM
} }
@ -157,11 +156,11 @@ const APP: () = {
let delay_ns_fp: fn(u32) -> () = |time_ns| { let delay_ns_fp: fn(u32) -> () = |time_ns| {
cortex_m::asm::delay((time_ns*21)/125 + 1) cortex_m::asm::delay((time_ns*21)/125 + 1)
}; };
enc424j600::SpiEth::new(spi_eth_port, spi1_nss, delay_ns_fp) SpiEth::new(spi_eth_port, spi1_nss, delay_ns_fp)
}; };
// Init controller // Init controller
match spi_eth.init_dev() { match spi_eth.reset() {
Ok(_) => { Ok(_) => {
iprintln!(stim0, "Initializing Ethernet...") iprintln!(stim0, "Initializing Ethernet...")
} }
@ -172,7 +171,7 @@ const APP: () = {
// Read MAC // Read MAC
let mut eth_mac_addr: [u8; 6] = [0; 6]; let mut eth_mac_addr: [u8; 6] = [0; 6];
spi_eth.read_from_mac(&mut eth_mac_addr); spi_eth.read_mac_addr(&mut eth_mac_addr);
for i in 0..6 { for i in 0..6 {
let byte = eth_mac_addr[i]; let byte = eth_mac_addr[i];
match i { match i {

View File

@ -17,8 +17,7 @@ use stm32f4xx_hal::{
spi::Spi, spi::Spi,
time::Hertz time::Hertz
}; };
use enc424j600; use enc424j600::EthPhy;
use enc424j600::EthController;
/// ///
use stm32f4xx_hal::{ use stm32f4xx_hal::{
@ -28,15 +27,16 @@ use stm32f4xx_hal::{
Alternate, AF5, Output, PushPull Alternate, AF5, Output, PushPull
}, },
}; };
type BoosterSpiEth = enc424j600::SpiEth< type SpiEth = enc424j600::Enc424j600<
Spi<SPI1, (PA5<Alternate<AF5>>, PA6<Alternate<AF5>>, PA7<Alternate<AF5>>)>, Spi<SPI1, (PA5<Alternate<AF5>>, PA6<Alternate<AF5>>, PA7<Alternate<AF5>>)>,
PA4<Output<PushPull>>, PA4<Output<PushPull>>,
fn(u32)>; fn(u32) -> ()
>;
#[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] #[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
const APP: () = { const APP: () = {
struct Resources { struct Resources {
spi_eth: BoosterSpiEth, spi_eth: SpiEth,
delay: Delay, delay: Delay,
itm: ITM, itm: ITM,
} }
@ -87,11 +87,11 @@ const APP: () = {
let delay_ns: fn(u32) -> () = |time_ns| { let delay_ns: fn(u32) -> () = |time_ns| {
cortex_m::asm::delay((time_ns*21)/125 + 1) cortex_m::asm::delay((time_ns*21)/125 + 1)
}; };
enc424j600::SpiEth::new(spi_eth_port, spi1_nss, delay_ns) SpiEth::new(spi_eth_port, spi1_nss, delay_ns)
}; };
// Init // Init
match spi_eth.init_dev() { match spi_eth.reset() {
Ok(_) => { Ok(_) => {
iprintln!(stim0, "Initializing Ethernet...") iprintln!(stim0, "Initializing Ethernet...")
} }
@ -102,7 +102,7 @@ const APP: () = {
// Read MAC // Read MAC
let mut eth_mac_addr: [u8; 6] = [0; 6]; let mut eth_mac_addr: [u8; 6] = [0; 6];
spi_eth.read_from_mac(&mut eth_mac_addr); spi_eth.read_mac_addr(&mut eth_mac_addr);
for i in 0..6 { for i in 0..6 {
let byte = eth_mac_addr[i]; let byte = eth_mac_addr[i];
match i { match i {
@ -157,7 +157,7 @@ const APP: () = {
_ => () _ => ()
}; };
} }
c.resources.spi_eth.send_raw_packet(&eth_tx_packet); c.resources.spi_eth.send_packet(&eth_tx_packet);
iprintln!(stim0, "Packet sent"); iprintln!(stim0, "Packet sent");
c.resources.delay.delay_ms(100_u32); c.resources.delay.delay_ms(100_u32);
} }