tosca_esp32c3/
lib.rs

1//! `tosca-esp32c3` is a library crate for building firmware for `tosca` devices
2//! using an `ESP32-C3` microcontroller.
3//!
4//! It provides APIs to:
5//!
6//! - Connect a device to a `Wi-Fi` access point
7//! - Build the network stack
8//! - Configure the `mDNS-SD` discovery service
9//! - Define events for specific route tasks
10//! - Initialize and run an `HTTP` server
11//!
12//! The device APIs are designed to guide developers in defining their own
13//! devices, aiming to minimize the ambiguities that could arise during
14//! firmware development.
15//!
16//! Device firmware consists of a description and a set of tasks, both exposed
17//! through a client-server architecture in which the firmware operates as the
18//! server and its controller as the client.
19//!
20//! A device description is defined as a sequence of fields, such as the
21//! device name, the device kind, and other data used to establish a
22//! connection with a controller.
23//!
24//! When a controller makes a request to the firmware through a route, the
25//! firmware executes the corresponding task and sends a response! back to the
26//! controller.
27//! Routes may also accept parameters to configure tasks
28//!
29//! An event can be associated with a route to monitor data produced by a
30//! sensor. Both integer and floating-point values are supported, as well as
31//! events triggered by changes in the device state configuration.
32//!
33//! Each route can define zero or more associated hazards, representing
34//! potential risks during task execution. Even if no hazards are declared,
35//! a route may still pose unknown risks to the device.
36//! In such cases, the controller must decide whether to allow or block the
37//! request based on its privacy policy.
38//!
39//! This crate **cannot** determine the outcome of device tasks at compile
40//! time, as they depend on the runtime environment. Therefore, hazards
41//! only informs a controller of the **possible** risks that might arise.
42
43#![no_std]
44#![deny(missing_docs)]
45
46extern crate alloc;
47
48/// All supported device types.
49pub mod devices;
50
51/// General device definition along with its methods.
52pub mod device;
53/// Error management.
54pub mod error;
55/// Events and their data.
56pub mod events;
57/// The `mDNS-SD` discovery service.
58pub mod mdns;
59/// The network stack builder.
60pub mod net;
61/// All route parameters.
62pub mod parameters;
63/// All responses kinds along with their payloads.
64pub mod response;
65/// The firmware server.
66pub mod server;
67/// The device state.
68pub mod state;
69/// The `Wi-Fi` controller.
70pub mod wifi;
71
72macro_rules! mk_static {
73    ($t:ty,$val:expr) => {{
74        static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
75        #[deny(unused_attributes)]
76        let x = STATIC_CELL.uninit().write($val);
77        x
78    }};
79}
80
81pub(crate) use mk_static;