#![no_std]
#![forbid(unsafe_code)]
use postcard_rpc::{endpoints, topics, TopicDirection};
use postcard_schema::Schema;
use serde::{Deserialize, Serialize};
pub const PROTOCOL_VERSION: u32 = 0;
pub mod paths {
pub const NODE_IDENTIFY: &str = "banc/node/identify";
pub const NODE_RESET: &str = "banc/node/reset";
pub const GPIO_CONFIG: &str = "banc/assistant/gpio/config";
pub const GPIO_SET: &str = "banc/assistant/gpio/set";
pub const GPIO_READ: &str = "banc/assistant/gpio/read";
pub const PIN_MONITOR: &str = "banc/assistant/pin/monitor";
pub const PIN_EDGE: &str = "banc/assistant/pin/edge";
pub const UART_CONFIG: &str = "banc/assistant/uart/config";
pub const UART_TX: &str = "banc/assistant/uart/tx";
pub const UART_RX: &str = "banc/assistant/uart/rx";
pub const SPI_TRANSFER: &str = "banc/assistant/spi/transfer";
pub const I2C_TRANSACTION: &str = "banc/assistant/i2c/transaction";
pub const CAPTURE_CONTROL: &str = "banc/assistant/capture/control";
pub const CAPTURE_READ: &str = "banc/assistant/capture/read";
}
pub mod node {
use super::*;
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeRole {
Assistant,
Custom,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, PartialEq, Eq)]
pub struct Identity {
pub role: NodeRole,
pub protocol_version: u32,
pub unique_id: u64,
pub fw_name: heapless::String<32>,
pub fw_version: heapless::String<16>,
}
}
pub mod assistant {
use super::*;
pub const CHUNK: usize = 64;
pub const EVENTS_PER_CHUNK: usize = 16;
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub enum Level {
Low,
High,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub enum Pull {
None,
Up,
Down,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub enum PinMode {
Input(Pull),
Output,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
Unsupported,
Busy,
Hardware,
Invalid,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct GpioConfig {
pub pin: u8,
pub mode: PinMode,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct GpioSet {
pub pin: u8,
pub level: Level,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct GpioRead {
pub pin: u8,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct PinEvent {
pub pin: u8,
pub level: Level,
pub timestamp_us: u64,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct PinMonitor {
pub pin: u8,
pub enable: bool,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct UartConfig {
pub baud: u32,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, PartialEq, Eq)]
pub struct Chunk {
pub data: heapless::Vec<u8, CHUNK>,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, PartialEq, Eq)]
pub struct UartRxChunk {
pub timestamp_us: u64,
pub data: heapless::Vec<u8, CHUNK>,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, PartialEq, Eq)]
pub struct SpiTransfer {
pub write: heapless::Vec<u8, CHUNK>,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, PartialEq, Eq)]
pub struct I2cTransaction {
pub addr: u8,
pub write: heapless::Vec<u8, CHUNK>,
pub read_len: u8,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CaptureAction {
Start,
Stop,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct CaptureControl {
pub pin: u8,
pub action: CaptureAction,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct CaptureStatus {
pub count: u32,
pub dropped: u32,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, Copy, PartialEq, Eq)]
pub struct CaptureRead {
pub offset: u32,
}
#[derive(Serialize, Deserialize, Schema, Debug, Clone, PartialEq, Eq)]
pub struct CaptureChunk {
pub events: heapless::Vec<PinEvent, EVENTS_PER_CHUNK>,
pub remaining: u32,
}
pub type AckResult = Result<(), Error>;
pub type LevelResult = Result<Level, Error>;
pub type ChunkResult = Result<Chunk, Error>;
pub type CaptureStatusResult = Result<CaptureStatus, Error>;
pub type CaptureChunkResult = Result<CaptureChunk, Error>;
}
use assistant::*;
use node::*;
endpoints! {
list = ENDPOINT_LIST;
| EndpointTy | RequestTy | ResponseTy | Path |
| ---------- | --------- | ---------- | ---- |
| IdentifyEndpoint | () | Identity | "banc/node/identify" |
| ResetEndpoint | () | () | "banc/node/reset" |
| GpioConfigEndpoint | GpioConfig | AckResult | "banc/assistant/gpio/config" |
| GpioSetEndpoint | GpioSet | AckResult | "banc/assistant/gpio/set" |
| GpioReadEndpoint | GpioRead | LevelResult | "banc/assistant/gpio/read" |
| PinMonitorEndpoint | PinMonitor | AckResult | "banc/assistant/pin/monitor" |
| UartConfigEndpoint | UartConfig | AckResult | "banc/assistant/uart/config" |
| UartTxEndpoint | Chunk | AckResult | "banc/assistant/uart/tx" |
| SpiTransferEndpoint | SpiTransfer | ChunkResult | "banc/assistant/spi/transfer" |
| I2cTransactionEndpoint| I2cTransaction | ChunkResult | "banc/assistant/i2c/transaction" |
| CaptureControlEndpoint| CaptureControl | CaptureStatusResult | "banc/assistant/capture/control" |
| CaptureReadEndpoint | CaptureRead | CaptureChunkResult | "banc/assistant/capture/read" |
}
topics! {
list = TOPICS_OUT_LIST;
direction = TopicDirection::ToClient;
| TopicTy | MessageTy | Path |
| ------- | --------- | ---- |
| PinEdgeTopic | PinEvent | "banc/assistant/pin/edge" |
| UartRxTopic | UartRxChunk | "banc/assistant/uart/rx" |
}
topics! {
list = TOPICS_IN_LIST;
direction = TopicDirection::ToServer;
| TopicTy | MessageTy | Path |
| ------- | --------- | ---- |
}