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