diff --git a/porky/src/porky.rs b/porky/src/porky.rs index e55c16683..c124476fb 100644 --- a/porky/src/porky.rs +++ b/porky/src/porky.rs @@ -35,7 +35,9 @@ use heapless::FnvIndexMap; use heapless::Vec; use hw_definition::config::HardwareConfigMessage::*; use hw_definition::config::{HardwareConfig, HardwareConfigMessage, InputPull, LevelChange}; -use hw_definition::description::{HardwareDescription, HardwareDetails, PinDescriptionSet}; +use hw_definition::description::{ + HardwareDescription, HardwareDetails, PinDescriptionSet, PinNumberingScheme, +}; use hw_definition::pin_function::PinFunction; use hw_definition::{BCMPinNumber, PinLevel}; use panic_probe as _; @@ -341,6 +343,7 @@ async fn tcp_accept(socket: &mut TcpSocket<'_>, ip_address: &Ipv4Address, device let hw_desc = HardwareDescription { details, pins: PinDescriptionSet { + pin_numbering: PinNumberingScheme::CounterClockwise, pins: Vec::from_slice(&PIN_DESCRIPTIONS).unwrap(), }, }; diff --git a/src/hw/fake_hw.rs b/src/hw/fake_hw.rs index 481e7c176..912b7a084 100644 --- a/src/hw/fake_hw.rs +++ b/src/hw/fake_hw.rs @@ -4,7 +4,9 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::{io, thread}; use crate::hw::{BCMPinNumber, PinFunction, PinLevel}; -use crate::hw_definition::description::{HardwareDetails, PinDescription, PinDescriptionSet}; +use crate::hw_definition::description::{ + HardwareDetails, PinDescription, PinDescriptionSet, PinNumberingScheme, +}; use super::Hardware; use super::HardwareDescription; @@ -36,6 +38,7 @@ impl Hardware for HW { model: "Fake Hardware".to_string(), }, pins: PinDescriptionSet { + pin_numbering: PinNumberingScheme::Rows, pins: FAKE_PIN_DESCRIPTIONS.to_vec(), }, }) diff --git a/src/hw/mod.rs b/src/hw/mod.rs index 1a3108e57..8e8300c08 100644 --- a/src/hw/mod.rs +++ b/src/hw/mod.rs @@ -96,7 +96,9 @@ pub trait Hardware { mod test { use crate::hw; use crate::hw::Hardware; - use crate::hw_definition::description::{PinDescription, PinDescriptionSet}; + use crate::hw_definition::description::{ + PinDescription, PinDescriptionSet, PinNumberingScheme, + }; use crate::hw_definition::pin_function::PinFunction; use std::borrow::Cow; @@ -209,6 +211,7 @@ mod test { pin7.clone(), ]; let pin_set = PinDescriptionSet { + pin_numbering: PinNumberingScheme::Rows, pins: pins.to_vec(), }; assert_eq!( diff --git a/src/hw/pi_hw.rs b/src/hw/pi_hw.rs index 4087de5ce..cfaf67919 100644 --- a/src/hw/pi_hw.rs +++ b/src/hw/pi_hw.rs @@ -77,6 +77,7 @@ impl Hardware for HW { Ok(HardwareDescription { details: Self::get_details()?, pins: PinDescriptionSet { + pin_numbering: PinNumberingScheme::Rows, pins: GPIO_PIN_DESCRIPTIONS.to_vec(), }, }) diff --git a/src/hw_definition/description.rs b/src/hw_definition/description.rs index c537116be..a5761c149 100644 --- a/src/hw_definition/description.rs +++ b/src/hw_definition/description.rs @@ -57,9 +57,9 @@ pub struct HardwareDetails<'a> { #[cfg(feature = "std")] /// [PinDescription] describes a pins in the connected hardware. /// Array indexed from 0 so, index = board_pin_number -1, as pin numbering start at 1 -#[derive(Serialize)] -#[cfg_attr(feature = "std", derive(Debug, Clone, Deserialize))] +#[derive(Serialize, Debug, Clone, Deserialize)] pub struct PinDescriptionSet { + pub(crate) pin_numbering: PinNumberingScheme, pub(crate) pins: Vec, } @@ -67,8 +67,8 @@ pub struct PinDescriptionSet { /// [PinDescription] describes a pins in the connected hardware. /// Array indexed from 0 so, index = board_pin_number -1, as pin numbering start at 1 #[derive(Serialize)] -#[cfg_attr(feature = "std", derive(Debug, Clone, Deserialize))] pub struct PinDescriptionSet<'a> { + pub(crate) pin_numbering: PinNumberingScheme, pub(crate) pins: Vec, 40>, } @@ -95,3 +95,26 @@ pub struct PinDescription<'a> { pub name: &'static str, pub options: &'a [PinFunction], } + +/// RaspberryPi and Raspberry Pi Pico use two different pin numbering schemes +/// +/// RPi uses "Rows": +/// - top-left is pin 1 +/// - top-right is pin 2 +/// and so on down row-by-row +/// - bottom-left is pin 39 +/// - bottom-right is pin 40 +/// +/// RPi Pico numbers pins from one (top left) down the left column then up the right column +/// ending at 40 at the top right +/// - top-left is pin 1 +/// - bottom-left is pin 20 +/// - bottom-right is pin 21 +/// - top-right is pin 40 +#[derive(Serialize)] +#[cfg_attr(feature = "std", derive(Debug, Clone, Deserialize))] +#[allow(dead_code)] // for porky +pub enum PinNumberingScheme { + Rows, + CounterClockwise, +}