diff --git a/build.rs b/build.rs index 2b667f4..94cfdd2 100644 --- a/build.rs +++ b/build.rs @@ -31,5 +31,5 @@ fn main() { // `memory.x` is changed. println!("cargo:rerun-if-changed=memory.x"); - femtopb_build::compile_protos(&["src/api.proto"], &["src"]).unwrap(); + femtopb_build::compile_protos_into(&["src/api.proto"], &["src"], "src").unwrap(); } diff --git a/src/api.proto b/src/api.proto index 09adfa8..6725f05 100644 --- a/src/api.proto +++ b/src/api.proto @@ -1,7 +1,32 @@ syntax = "proto3"; -message SearchRequest { - uint32 query = 1; - uint32 page_number = 2; - uint32 results_per_page = 3; +enum RequestType { + PING = 0; + SET_PIN_DIRECTION = 1; + SET_PIN_VALUE = 2; + GET_PIN_DIRECTION = 3; + GET_PIN_VALUE = 4; +} + +enum PinValue { + LOW = 0; + HIGH = 1; + INPUT = 2; + OUTPUT = 3; +} + +message PicohaDioRequest { + RequestType type = 1; + uint32 pin_num = 2; + PinValue value = 3; +} + +enum AnswerType { + SUCCESS = 0; + FAILURE = 1; +} + +message PicohaDioAnswer { + AnswerType type = 1; + optional PinValue value = 3; } diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..82627ae --- /dev/null +++ b/src/api.rs @@ -0,0 +1,151 @@ +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::femtopb::Message)] +pub struct PicohaDioRequest<'a> { + #[femtopb(enumeration, tag = 1)] + pub r#type: ::femtopb::enumeration::EnumValue, + #[femtopb(uint32, tag = 2)] + pub pin_num: u32, + #[femtopb(enumeration, tag = 3)] + pub value: ::femtopb::enumeration::EnumValue, + #[femtopb(unknown_fields)] + pub unknown_fields: femtopb::UnknownFields<'a>, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::femtopb::Message)] +pub struct PicohaDioAnswer<'a> { + #[femtopb(enumeration, tag = 1)] + pub r#type: ::femtopb::enumeration::EnumValue, + #[femtopb(enumeration, optional, tag = 3)] + pub value: ::core::option::Option<::femtopb::enumeration::EnumValue>, + #[femtopb(unknown_fields)] + pub unknown_fields: femtopb::UnknownFields<'a>, +} +#[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::femtopb::Enumeration +)] +#[repr(i32)] +#[derive(Default)] +pub enum RequestType { + #[default] + Ping = 0, + SetPinDirection = 1, + SetPinValue = 2, + GetPinDirection = 3, + GetPinValue = 4, +} +impl RequestType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + RequestType::Ping => "PING", + RequestType::SetPinDirection => "SET_PIN_DIRECTION", + RequestType::SetPinValue => "SET_PIN_VALUE", + RequestType::GetPinDirection => "GET_PIN_DIRECTION", + RequestType::GetPinValue => "GET_PIN_VALUE", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "PING" => Some(Self::Ping), + "SET_PIN_DIRECTION" => Some(Self::SetPinDirection), + "SET_PIN_VALUE" => Some(Self::SetPinValue), + "GET_PIN_DIRECTION" => Some(Self::GetPinDirection), + "GET_PIN_VALUE" => Some(Self::GetPinValue), + _ => None, + } + } +} +#[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::femtopb::Enumeration +)] +#[repr(i32)] +#[derive(Default)] +pub enum PinValue { + #[default] + Low = 0, + High = 1, + Input = 2, + Output = 3, +} +impl PinValue { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + PinValue::Low => "LOW", + PinValue::High => "HIGH", + PinValue::Input => "INPUT", + PinValue::Output => "OUTPUT", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "LOW" => Some(Self::Low), + "HIGH" => Some(Self::High), + "INPUT" => Some(Self::Input), + "OUTPUT" => Some(Self::Output), + _ => None, + } + } +} +#[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::femtopb::Enumeration +)] +#[repr(i32)] +#[derive(Default)] +pub enum AnswerType { + #[default] + Success = 0, + Failure = 1, +} +impl AnswerType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + AnswerType::Success => "SUCCESS", + AnswerType::Failure => "FAILURE", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "SUCCESS" => Some(Self::Success), + "FAILURE" => Some(Self::Failure), + _ => None, + } + } +} diff --git a/src/main.rs b/src/main.rs index 98930cf..634f271 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use bsp::entry; use defmt::*; use defmt_rtt as _; use embedded_hal::digital::OutputPin; +use femtopb::Message; use panic_probe as _; use rp2040_hal::pio::PIOExt; @@ -39,8 +40,7 @@ use bsp::hal::{ use rp_pico::hal::gpio::{FunctionPio0, Pin}; -// use no_proto::error::NP_Error; -// use no_proto::NP_Factory; +mod api; use serial_line_ip; @@ -52,6 +52,16 @@ fn main() -> ! { let mut watchdog = Watchdog::new(pac.WATCHDOG); let sio = Sio::new(pac.SIO); + let mes = api::PicohaDioRequest { + r#type: femtopb::EnumValue::Known(api::RequestType::Ping), + pin_num: 0, + value: femtopb::EnumValue::Known(api::PinValue::Low), + unknown_fields: Default::default(), + }; + + // let mut cursor = femtopb::Cursor::new(); + // let rr = mes.encoded_len() + // let user_factory = NP_Factory::new( // r#" // struct({ fields: {