rw007 0.1.0

RW007 SPI WiFi module driver for embedded Rust
Documentation
# rw007

[中文](README_zh.md) | English

[![CI](https://github.com/andelf/rw007/actions/workflows/ci.yml/badge.svg)](https://github.com/andelf/rw007/actions/workflows/ci.yml)
[![crates.io](https://img.shields.io/crates/v/rw007.svg)](https://crates.io/crates/rw007)
[![docs.rs](https://docs.rs/rw007/badge.svg)](https://docs.rs/rw007)

Rust driver for **RW007** SPI WiFi module.

## Introduction

**RW007** is a high-speed SPI/UART WiFi module based on Cortex-M4 WiFi SoC, developed by Shanghai Positive Electronic Technology Co., Ltd. This crate provides a `no_std` Rust driver for the RW007 module using the SPI interface.

### Features

- `no_std` compatible - works on bare metal embedded systems
- Blocking API using `embedded-hal` 1.0 traits
- Async API using `embedded-hal-async` (with `async` feature)
- Embassy integration with `embassy-net-driver-channel`
- WiFi operations: scan, connect, disconnect, get RSSI
- Full SPI two-phase transfer protocol implementation

## Hardware

The RW007 module requires the following connections:

| Pin | Description |
|-----|-------------|
| SPI_CLK | SPI Clock |
| SPI_MOSI | SPI Master Out Slave In |
| SPI_MISO | SPI Master In Slave Out |
| CS | Chip Select (directly directly by driver) |
| RST | Reset (directly controlled by driver) |
| INT | Interrupt / Data Ready indicator |
| VCC | 3.3V Power |
| GND | Ground |

**Note**: CS pin directly controlled by the driver to support the two-phase SPI protocol.

## Usage

Add to your `Cargo.toml`:

```toml
[dependencies]
rw007 = "0.1"

# For async support with Embassy
rw007 = { version = "0.1", features = ["async"] }

# For defmt logging
rw007 = { version = "0.1", features = ["defmt"] }
```

### Blocking Example

```rust
use rw007::{Rw007, Security};

// Create driver with SPI, CS, RST, INT pins
let mut wifi = Rw007::new(spi, cs_pin, rst_pin, int_pin);

// Reset and initialize the module
wifi.reset(&mut delay)?;
wifi.init(&mut delay)?;

// Get firmware version
let version = wifi.get_version(&mut delay)?;
println!("Firmware: {}", version);

// Scan for WiFi networks
let results = wifi.scan(&mut delay)?;
for ap in results.as_slice() {
    println!("Found: {} ({} dBm)", ap.ssid.as_str().unwrap_or("?"), ap.rssi);
}

// Connect to WiFi
wifi.join("MyNetwork", "password123", Security::Wpa2Psk, &mut delay)?;
```

### Async Example (with Embassy)

```rust
use rw007::{new_async, State, Control, Runner, Security};
use embassy_net::{Stack, StackResources};
use static_cell::StaticCell;

static STATE: StaticCell<State> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();

#[embassy_executor::main]
async fn main(spawner: Spawner) {
    // Create async driver
    let state = STATE.init(State::new());
    let (net_device, mut control, runner) = new_async(state, spi, cs, rst, int);

    // Spawn WiFi runner task
    spawner.spawn(wifi_task(runner)).unwrap();

    // Initialize and connect
    control.init().await?;
    control.connect("MyNetwork", "password123", Security::Wpa2Psk).await?;

    // Create network stack
    let config = embassy_net::Config::dhcpv4(Default::default());
    let resources = RESOURCES.init(StackResources::new());
    let (stack, net_runner) = embassy_net::new(net_device, config, resources, seed);

    spawner.spawn(net_task(net_runner)).unwrap();

    // Wait for IP address
    stack.wait_config_up().await;

    // Now you can use TCP/UDP sockets!
}

#[embassy_executor::task]
async fn wifi_task(runner: Runner<'static, ...>) -> ! {
    runner.run().await
}

#[embassy_executor::task]
async fn net_task(runner: embassy_net::Runner<'static, rw007::NetDriver<'static>>) -> ! {
    runner.run().await
}
```

## Features

| Feature | Description |
|---------|-------------|
| `defmt` | Enable defmt logging support |
| `async` | Enable async driver with Embassy support |

## Supported Operations

| Operation | Blocking | Async |
|-----------|----------|-------|
| Reset |||
| Init |||
| Get Version |||
| Get MAC |||
| Scan |||
| Connect |||
| Disconnect |||
| Get RSSI |||
| TCP/UDP (via embassy-net) | - ||

## License

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT]LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

## References

- [RT-Thread RW007 Package]https://github.com/RT-Thread-packages/rw007 - Original C driver for RT-Thread
- [RW007 Module Documentation]https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/packages/rw007_module_using/an0034-rw007-module-using