Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reorganization #164

Merged
merged 7 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed an issue where I2C NACK is encountered randomly while setting the MAX6639 fan speed
([#140](https://github.com/quartiq/booster/issues/140)), by using a I2C transfer retry mechanism.
[#158](https://github.com/quartiq/booster/pull/158)
* Code reorganized to move hardware configuration into a module
18 changes: 0 additions & 18 deletions src/error.rs

This file was deleted.

18 changes: 3 additions & 15 deletions src/booster_channels.rs → src/hardware/booster_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
//! Unauthorized usage, editing, or copying is strictly prohibited.
//! Proprietary and confidential.

use super::Channel;
use enum_iterator::IntoEnumIterator;
use stm32f4xx_hal as hal;
use tca9548::{self, Tca9548};

use super::rf_channel::{ChannelPins as RfChannelPins, RfChannel};
use super::{I2cBusManager, I2cProxy};
use crate::error::Error;
use crate::rf_channel::{ChannelPins as RfChannelPins, RfChannel};
use crate::Error;
use embedded_hal::blocking::delay::DelayUs;

/// Represents a control structure for interfacing to booster RF channels.
Expand All @@ -21,19 +22,6 @@ pub struct BoosterChannels {
mux: Tca9548<I2cProxy>,
}

/// Indicates a booster RF channel.
#[derive(IntoEnumIterator, Copy, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum Channel {
Zero = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
}

impl Into<tca9548::Bus> for Channel {
fn into(self) -> tca9548::Bus {
match self {
Expand Down
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions src/hardware/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Booster module-level hardware definitions
//!
//! # Copyright
//! Copyright (C) 2020 QUARTIQ GmbH - All Rights Reserved
//! Unauthorized usage, editing, or copying is strictly prohibited.
//! Proprietary and confidential.

use enum_iterator::IntoEnumIterator;
use serde::{Deserialize, Serialize};
use stm32f4xx_hal as hal;

pub mod booster_channels;
pub mod chassis_fans;
mod mutex;
pub mod platform;
pub mod rf_channel;
pub mod setup;
pub mod user_interface;

pub const CPU_FREQ: u32 = 168_000_000;

#[cfg(feature = "phy_enc424j600")]
mod enc424j600_api;

#[cfg(feature = "phy_enc424j600")]
use smoltcp_nal::NetworkStack;

// Convenience type definition for the I2C bus used for booster RF channels.
pub type I2C = hal::i2c::I2c<
hal::stm32::I2C1,
(
hal::gpio::gpiob::PB6<hal::gpio::AlternateOD<hal::gpio::AF4>>,
hal::gpio::gpiob::PB7<hal::gpio::AlternateOD<hal::gpio::AF4>>,
),
>;

pub type I2C2 = hal::i2c::I2c<
hal::stm32::I2C2,
(
hal::gpio::gpiob::PB10<hal::gpio::AlternateOD<hal::gpio::AF4>>,
hal::gpio::gpiob::PB11<hal::gpio::AlternateOD<hal::gpio::AF4>>,
),
>;

pub type SPI = hal::spi::Spi<
hal::stm32::SPI1,
(
hal::gpio::gpioa::PA5<hal::gpio::Alternate<hal::gpio::AF5>>,
hal::gpio::gpioa::PA6<hal::gpio::Alternate<hal::gpio::AF5>>,
hal::gpio::gpioa::PA7<hal::gpio::Alternate<hal::gpio::AF5>>,
),
>;

#[cfg(feature = "phy_w5500")]
pub type Ethernet =
w5500::Interface<hal::gpio::gpioa::PA4<hal::gpio::Output<hal::gpio::PushPull>>, SPI>;
#[cfg(feature = "phy_enc424j600")]
pub type Enc424j600 =
enc424j600::Enc424j600<SPI, hal::gpio::gpioa::PA4<hal::gpio::Output<hal::gpio::PushPull>>>;
#[cfg(feature = "phy_enc424j600")]
pub type Ethernet =
NetworkStack<'static, 'static, enc424j600::smoltcp_phy::SmoltcpDevice<Enc424j600>>;
#[cfg(feature = "phy_enc424j600")]
pub type NalClock = enc424j600_api::EpochClock<CPU_FREQ>;
pub type MqttClient = minimq::MqttClient<minimq::consts::U1024, Ethernet>;

pub type I2cBusManager = mutex::AtomicCheckManager<I2C>;
pub type I2cProxy = shared_bus::I2cProxy<'static, mutex::AtomicCheckMutex<I2C>>;
pub type I2cError = hal::i2c::Error;

pub type UsbBus = hal::otg_fs::UsbBus<hal::otg_fs::USB>;
pub type Eeprom = microchip_24aa02e48::Microchip24AA02E48<I2C2>;

/// Indicates a booster RF channel.
#[derive(IntoEnumIterator, Copy, Clone, Debug, Serialize, Deserialize)]
pub enum Channel {
Zero = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
}
4 changes: 2 additions & 2 deletions src/mutex.rs → src/hardware/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub type AtomicCheckManager<T> = shared_bus::BusManager<AtomicCheckMutex<T>>;
macro_rules! new_atomic_check_manager {
($bus_type:ty = $bus:expr) => {{
let m: Option<&'static mut _> = cortex_m::singleton!(
: $crate::mutex::AtomicCheckManager<$bus_type> =
$crate::mutex::AtomicCheckManager::new($bus)
: $crate::hardware::mutex::AtomicCheckManager<$bus_type> =
$crate::hardware::mutex::AtomicCheckManager::new($bus)
);

m
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions src/rf_channel.rs → src/hardware/rf_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ use max6642::Max6642;
use mcp3221::Mcp3221;
use microchip_24aa02e48::Microchip24AA02E48;

use super::{I2cBusManager, I2cProxy};
use crate::{
linear_transformation::LinearTransformation, platform, settings::BoosterChannelSettings, Error,
};
use super::{platform, I2cBusManager, I2cProxy};
use crate::{linear_transformation::LinearTransformation, settings::BoosterChannelSettings, Error};
use embedded_hal::blocking::delay::DelayUs;
use stm32f4xx_hal::{
self as hal,
Expand Down
Loading