#![no_std]
#![doc = include_str!("../README.md")]

//! # SW2303 USB PD Controller Driver
//!
//! This crate provides a driver for the SW2303 USB PD (Power Delivery) controller chip.
//! The SW2303 is a USB PD controller that supports charging management and device detection.
//!
//! ## Features
//!
//! - **Device Detection**: Monitor sink device connection status
//! - **Power Management**: USB PD charging control and monitoring
//! - **Protocol Configuration**: Complete USB PD and fast charging protocol configuration
//! - **Status Monitoring**: Real-time controller and charging status information
//! - **Async/Sync Support**: Compatible with both blocking and async I2C implementations
//! - **Optional defmt logging support**
//!
//! ### Supported Protocols
//!
//! - **USB Power Delivery (PD)**: PD 2.0/3.0 with fixed voltages and PPS support
//! - **Qualcomm Quick Charge**: QC 2.0/3.0 protocols
//! - **Fast Charging Protocols**: FCP, AFC, SCP, PE2.0, SFCP
//! - **USB Battery Charging**: BC1.2 protocol
//! - **Type-C**: Current broadcast and configuration
//!
//! ## Installation
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! sw2303 = "0.1.0"
//! # For async support
//! sw2303 = { version = "0.1.0", features = ["async"] }
//! # For defmt logging support
//! sw2303 = { version = "0.1.0", features = ["defmt"] }
//! # For both async and defmt
//! sw2303 = { version = "0.1.0", features = ["async", "defmt"] }
//! ```
//!
//! ## Usage
//!
//! ### Synchronous Version
//!
//! ```rust,no_run
//! use sw2303::{
//!     PdConfiguration, PpsConfigMode, ProtocolConfiguration, SW2303,
//!     registers::constants::DEFAULT_ADDRESS,
//! };
//! use embedded_hal::i2c::I2c;
//!
//! # #[cfg(not(feature = "async"))]
//! # fn example<I2C: I2c>(mut i2c: I2C) -> Result<(), sw2303::error::Error<I2C::Error>>
//! # where I2C::Error: core::fmt::Debug
//! # {
//! // Initialize the driver
//! let mut sw2303 = SW2303::new(&mut i2c, DEFAULT_ADDRESS);
//! sw2303.init()?;
//!
//! // Configure power (requires unlock for REG 0xAF)
//! sw2303.unlock_write_enable_0()?;
//! sw2303.set_power_config(65)?; // Set to 65W
//!
//! // Configure protocols
//! let protocol_config = ProtocolConfiguration {
//!     pd_enabled: true,
//!     qc20_enabled: true,
//!     qc30_enabled: true,
//!     fcp_enabled: true,
//!     ..Default::default()
//! };
//! sw2303.configure_protocols(protocol_config)?;
//!
//! // Configure PD with specific voltage levels
//! let pd_config = PdConfiguration {
//!     enabled: true,
//!     fixed_voltages: [true, true, false, false], // Enable 9V and 12V
//!     pps_enabled: true,
//!     pps_config_mode: PpsConfigMode::Auto,
//!     ..Default::default()
//! };
//! sw2303.configure_pd(pd_config)?;
//!
//! // Check if a sink device is connected
//! if sw2303.is_sink_device_connected()? {
//!     // Check which protocol was negotiated
//!     if let Some(protocol) = sw2303.get_negotiated_protocol()? {
//!         // Handle specific protocol
//!     }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ### Asynchronous Version (requires "async" feature)
//!
//! ```rust,no_run
//! # #[cfg(feature = "async")]
//! # async fn async_example() -> Result<(), sw2303::error::Error<()>> {
//! use sw2303::{SW2303, registers::constants::DEFAULT_ADDRESS};
//! use embedded_hal_async::i2c::I2c;
//!
//! // Initialize the driver
//! // let mut sw2303 = SW2303::new(&mut i2c, DEFAULT_ADDRESS);
//! // sw2303.init().await?;
//!
//! // Check if a sink device is connected
//! // if sw2303.is_sink_device_connected().await? {
//! //     // Sink device connected
//! // }
//! # Ok(())
//! # }
//! ```
//!
//! ## Feature Flags
//!
//! - `async`: Enable asynchronous I2C support
//! - `defmt`: Enable defmt logging support

mod data_types;
pub mod driver;
pub mod error;
pub mod registers;

use crate::error::Error;
pub use data_types::*;
pub use driver::SW2303;

/// Result type for SW2303 operations
pub type Result<T, I2cError> = core::result::Result<T, Error<I2cError>>;

/// SW2303 driver version
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
