tangled
alpha
login
or
join now
baileytownsend.dev
/
rusty-badger
0
fork
atom
A personal rust firmware for the Badger 2040 W
0
fork
atom
overview
issues
pulls
pipelines
it builds again
baileytownsend.dev
5 months ago
7d6fde6e
2d4e3465
+67
-98
4 changed files
expand all
collapse all
unified
split
Cargo.lock
rust-toolchain-nightly.toml
src
cyw43_driver.rs
main.rs
+20
-20
Cargo.lock
···
198
199
[[package]]
200
name = "byte-slice-cast"
201
-
version = "1.2.2"
202
source = "registry+https://github.com/rust-lang/crates.io-index"
203
-
checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c"
204
205
[[package]]
206
name = "bytemuck"
···
1141
1142
[[package]]
1143
name = "getrandom"
1144
-
version = "0.2.15"
1145
source = "registry+https://github.com/rust-lang/crates.io-index"
1146
-
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
1147
dependencies = [
1148
"cfg-if",
1149
"libc",
···
1254
1255
[[package]]
1256
name = "hermit-abi"
1257
-
version = "0.3.9"
1258
source = "registry+https://github.com/rust-lang/crates.io-index"
1259
-
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
1260
1261
[[package]]
1262
name = "hex"
···
1315
1316
[[package]]
1317
name = "is-terminal"
1318
-
version = "0.4.12"
1319
source = "registry+https://github.com/rust-lang/crates.io-index"
1320
-
checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
1321
dependencies = [
1322
"hermit-abi",
1323
"libc",
···
1422
1423
[[package]]
1424
name = "libredox"
1425
-
version = "0.1.3"
1426
source = "registry+https://github.com/rust-lang/crates.io-index"
1427
-
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
1428
dependencies = [
1429
"bitflags 2.6.0",
1430
"libc",
···
1914
1915
[[package]]
1916
name = "redox_users"
1917
-
version = "0.4.5"
1918
source = "registry+https://github.com/rust-lang/crates.io-index"
1919
-
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
1920
dependencies = [
1921
"getrandom",
1922
"libredox",
1923
-
"thiserror 1.0.63",
1924
]
1925
1926
[[package]]
···
2343
2344
[[package]]
2345
name = "thiserror"
2346
-
version = "1.0.63"
2347
source = "registry+https://github.com/rust-lang/crates.io-index"
2348
-
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
2349
dependencies = [
2350
-
"thiserror-impl 1.0.63",
2351
]
2352
2353
[[package]]
···
2361
2362
[[package]]
2363
name = "thiserror-impl"
2364
-
version = "1.0.63"
2365
source = "registry+https://github.com/rust-lang/crates.io-index"
2366
-
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
2367
dependencies = [
2368
"proc-macro2",
2369
"quote",
···
2482
2483
[[package]]
2484
name = "wasi"
2485
-
version = "0.11.0+wasi-snapshot-preview1"
2486
source = "registry+https://github.com/rust-lang/crates.io-index"
2487
-
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
2488
2489
[[package]]
2490
name = "winapi"
···
198
199
[[package]]
200
name = "byte-slice-cast"
201
+
version = "1.2.3"
202
source = "registry+https://github.com/rust-lang/crates.io-index"
203
+
checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d"
204
205
[[package]]
206
name = "bytemuck"
···
1141
1142
[[package]]
1143
name = "getrandom"
1144
+
version = "0.2.16"
1145
source = "registry+https://github.com/rust-lang/crates.io-index"
1146
+
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
1147
dependencies = [
1148
"cfg-if",
1149
"libc",
···
1254
1255
[[package]]
1256
name = "hermit-abi"
1257
+
version = "0.5.2"
1258
source = "registry+https://github.com/rust-lang/crates.io-index"
1259
+
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
1260
1261
[[package]]
1262
name = "hex"
···
1315
1316
[[package]]
1317
name = "is-terminal"
1318
+
version = "0.4.16"
1319
source = "registry+https://github.com/rust-lang/crates.io-index"
1320
+
checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
1321
dependencies = [
1322
"hermit-abi",
1323
"libc",
···
1422
1423
[[package]]
1424
name = "libredox"
1425
+
version = "0.1.10"
1426
source = "registry+https://github.com/rust-lang/crates.io-index"
1427
+
checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb"
1428
dependencies = [
1429
"bitflags 2.6.0",
1430
"libc",
···
1914
1915
[[package]]
1916
name = "redox_users"
1917
+
version = "0.4.6"
1918
source = "registry+https://github.com/rust-lang/crates.io-index"
1919
+
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
1920
dependencies = [
1921
"getrandom",
1922
"libredox",
1923
+
"thiserror 1.0.69",
1924
]
1925
1926
[[package]]
···
2343
2344
[[package]]
2345
name = "thiserror"
2346
+
version = "1.0.69"
2347
source = "registry+https://github.com/rust-lang/crates.io-index"
2348
+
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
2349
dependencies = [
2350
+
"thiserror-impl 1.0.69",
2351
]
2352
2353
[[package]]
···
2361
2362
[[package]]
2363
name = "thiserror-impl"
2364
+
version = "1.0.69"
2365
source = "registry+https://github.com/rust-lang/crates.io-index"
2366
+
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
2367
dependencies = [
2368
"proc-macro2",
2369
"quote",
···
2482
2483
[[package]]
2484
name = "wasi"
2485
+
version = "0.11.1+wasi-snapshot-preview1"
2486
source = "registry+https://github.com/rust-lang/crates.io-index"
2487
+
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
2488
2489
[[package]]
2490
name = "winapi"
+1
-1
rust-toolchain-nightly.toml
···
1
[toolchain]
2
-
channel = "nightly-2024-11-04"
3
components = ["rust-src", "rustfmt", "llvm-tools", "miri"]
4
targets = ["thumbv6m-none-eabi"]
···
1
[toolchain]
2
+
channel = "nightly-202-11-04"
3
components = ["rust-src", "rustfmt", "llvm-tools", "miri"]
4
targets = ["thumbv6m-none-eabi"]
-69
src/cyw43_driver.rs
···
1
-
use cyw43::Control;
2
-
use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi};
3
-
use defmt::unwrap;
4
-
use embassy_executor::Spawner;
5
-
use embassy_net_wiznet::Device;
6
-
use embassy_rp::bind_interrupts;
7
-
use embassy_rp::gpio::{Level, Output};
8
-
use embassy_rp::peripherals::{DMA_CH0, PIO0};
9
-
use embassy_rp::peripherals::{PIN_23, PIN_24, PIN_25, PIN_29};
10
-
use embassy_rp::pio::{InterruptHandler, Pio};
11
-
use static_cell::StaticCell;
12
-
13
-
bind_interrupts!(struct Irqs {
14
-
PIO0_IRQ_0 => InterruptHandler<PIO0>;
15
-
});
16
-
17
-
#[embassy_executor::task]
18
-
async fn cyw43_task(
19
-
runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>,
20
-
) -> ! {
21
-
runner.run().await
22
-
}
23
-
24
-
pub async fn setup_cyw43<'a>(
25
-
pio0: PIO0,
26
-
p_23: PIN_23,
27
-
p_24: PIN_24,
28
-
p_25: PIN_25,
29
-
p_29: PIN_29,
30
-
dma_ch0: DMA_CH0,
31
-
spawner: Spawner,
32
-
) -> (Device<'a>, Control<'a>) {
33
-
let fw = include_bytes!("../cyw43-firmware/43439A0.bin");
34
-
let clm = include_bytes!("../cyw43-firmware/43439A0_clm.bin");
35
-
36
-
// To make flashing faster for development, you may want to flash the firmwares independently
37
-
// at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
38
-
// probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000
39
-
// probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x10140000
40
-
41
-
// let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
42
-
// let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
43
-
44
-
let pwr = Output::new(*p_23, Level::Low);
45
-
let cs = Output::new(*p_25, Level::High);
46
-
let mut pio = Pio::new(*pio0, Irqs);
47
-
let spi = PioSpi::new(
48
-
&mut pio.common,
49
-
pio.sm0,
50
-
DEFAULT_CLOCK_DIVIDER,
51
-
*pio.irq0,
52
-
*cs,
53
-
*p_24,
54
-
*p_29,
55
-
*dma_ch0,
56
-
);
57
-
// let input = Input::new(p_29, Pull::Up);
58
-
59
-
static STATE: StaticCell<cyw43::State> = StaticCell::new();
60
-
let state = STATE.init(cyw43::State::new());
61
-
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
62
-
unwrap!(spawner.spawn(cyw43_task(runner)));
63
-
64
-
control.init(clm).await;
65
-
control
66
-
.set_power_management(cyw43::PowerManagementMode::PowerSave)
67
-
.await;
68
-
(net_device, control)
69
-
}
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+46
-8
src/main.rs
···
14
use core::fmt::Write;
15
use core::str::from_utf8;
16
use cyw43::JoinOptions;
17
-
use cyw43_driver::setup_cyw43;
0
18
use defmt::info;
19
use defmt::*;
20
use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
···
26
use embassy_rp::flash::Async;
27
use embassy_rp::gpio::Input;
28
use embassy_rp::i2c::I2c;
29
-
use embassy_rp::peripherals::{I2C0, SPI0};
0
30
use embassy_rp::rtc::{DateTime, DayOfWeek};
31
use embassy_rp::spi::Spi;
32
use embassy_rp::spi::{self};
33
-
use embassy_rp::{gpio, i2c};
34
use embassy_sync::blocking_mutex::NoopMutex;
35
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
36
use embassy_sync::mutex::Mutex;
···
49
use {defmt_rtt as _, panic_probe as _};
50
51
mod badge_display;
52
-
mod cyw43_driver;
53
mod env;
54
mod helpers;
55
mod save;
···
64
65
const FLASH_SIZE: usize = 2 * 1024 * 1024;
66
0
0
0
0
67
#[embassy_executor::main]
68
async fn main(spawner: Spawner) {
69
let p = embassy_rp::init(Default::default());
70
let mut user_led = Output::new(p.PIN_22, Level::High);
71
user_led.set_high();
72
73
-
let (net_device, mut control) = setup_cyw43(
74
-
*p.PIO0, *p.PIN_23, *p.PIN_24, *p.PIN_25, *p.PIN_29, *p.DMA_CH0, spawner,
75
-
)
76
-
.await;
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
77
78
let miso = p.PIN_16;
79
let mosi = p.PIN_19;
···
451
452
#[embassy_executor::task]
453
async fn net_task(mut runner: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! {
0
0
0
0
0
0
0
454
runner.run().await
455
}
456
···
14
use core::fmt::Write;
15
use core::str::from_utf8;
16
use cyw43::JoinOptions;
17
+
// use cyw43_driver::setup_cyw43;
18
+
use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi};
19
use defmt::info;
20
use defmt::*;
21
use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
···
27
use embassy_rp::flash::Async;
28
use embassy_rp::gpio::Input;
29
use embassy_rp::i2c::I2c;
30
+
use embassy_rp::peripherals::{DMA_CH0, I2C0, PIO0, SPI0};
31
+
use embassy_rp::pio::{InterruptHandler, Pio};
32
use embassy_rp::rtc::{DateTime, DayOfWeek};
33
use embassy_rp::spi::Spi;
34
use embassy_rp::spi::{self};
35
+
use embassy_rp::{bind_interrupts, gpio, i2c};
36
use embassy_sync::blocking_mutex::NoopMutex;
37
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
38
use embassy_sync::mutex::Mutex;
···
51
use {defmt_rtt as _, panic_probe as _};
52
53
mod badge_display;
0
54
mod env;
55
mod helpers;
56
mod save;
···
65
66
const FLASH_SIZE: usize = 2 * 1024 * 1024;
67
68
+
bind_interrupts!(struct Irqs {
69
+
PIO0_IRQ_0 => InterruptHandler<PIO0>;
70
+
});
71
+
72
#[embassy_executor::main]
73
async fn main(spawner: Spawner) {
74
let p = embassy_rp::init(Default::default());
75
let mut user_led = Output::new(p.PIN_22, Level::High);
76
user_led.set_high();
77
78
+
//Wifi driver and cyw43 setup
79
+
let fw = include_bytes!("../cyw43-firmware/43439A0.bin");
80
+
let clm = include_bytes!("../cyw43-firmware/43439A0_clm.bin");
81
+
82
+
let pwr = Output::new(p.PIN_23, Level::Low);
83
+
let cs = Output::new(p.PIN_25, Level::High);
84
+
let mut pio = Pio::new(p.PIO0, Irqs);
85
+
let spi = PioSpi::new(
86
+
&mut pio.common,
87
+
pio.sm0,
88
+
DEFAULT_CLOCK_DIVIDER,
89
+
pio.irq0,
90
+
cs,
91
+
p.PIN_24,
92
+
p.PIN_29,
93
+
p.DMA_CH0,
94
+
);
95
+
static STATE: StaticCell<cyw43::State> = StaticCell::new();
96
+
let state = STATE.init(cyw43::State::new());
97
+
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
98
+
spawner.spawn(cyw43_task(runner));
99
+
100
+
control.init(clm).await;
101
+
control
102
+
.set_power_management(cyw43::PowerManagementMode::PowerSave)
103
+
.await;
104
+
// let (net_device, mut control) = setup_cyw43(
105
+
// p.PIO0, p.PIN_23, p.PIN_24, p.PIN_25, p.PIN_29, p.DMA_CH0, spawner,
106
+
// )
107
+
// .await;
108
109
let miso = p.PIN_16;
110
let mosi = p.PIN_19;
···
482
483
#[embassy_executor::task]
484
async fn net_task(mut runner: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! {
485
+
runner.run().await
486
+
}
487
+
488
+
#[embassy_executor::task]
489
+
async fn cyw43_task(
490
+
runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>,
491
+
) -> ! {
492
runner.run().await
493
}
494