Skip to content

Commit 2ae073d

Browse files
committed
Demonstrate GPIO interrupts on the LPC55S69-EVK board.
Pressing the USER button generates an interrupt to the button task. A single press will increment the RGB pattern. Quick (~1.5s) successive presses 2nd, 3rd, and subsequent will respecitvely - turn off LEDs - blink LEDs - cycle through RBG pattern including all off. Minor updates to other app.toml files: - add `pint` and `inputmux` peripherals to their `gpio_driver` tasks. - when compiling all targets, some needed slight allocation adjustments not related to this PR.
1 parent 5d2a62f commit 2ae073d

File tree

9 files changed

+638
-0
lines changed

9 files changed

+638
-0
lines changed

Cargo.lock

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lpc55xpresso/app-button.toml

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name = "lpc55xpresso-button"
2+
target = "thumbv8m.main-none-eabihf"
3+
board = "lpcxpresso55s69"
4+
chip = "../../chips/lpc55"
5+
stacksize = 1024
6+
image-names = ["a", "b"]
7+
fwid = true
8+
9+
[kernel]
10+
name = "lpc55xpresso"
11+
features = ["dump", "dice-self"]
12+
requires = {flash = 55040, ram = 4096}
13+
14+
[caboose]
15+
region = "flash"
16+
size = 256
17+
default = true
18+
19+
[tasks.jefe]
20+
name = "task-jefe"
21+
priority = 0
22+
max-sizes = {flash = 16384, ram = 2048}
23+
start = true
24+
features = ["dump"]
25+
stacksize = 1536
26+
notifications = ["fault", "timer"]
27+
extern-regions = ["sram2"]
28+
29+
[tasks.jefe.config.allowed-callers]
30+
request_reset = ["update_server"]
31+
32+
[tasks.hiffy]
33+
name = "task-hiffy"
34+
priority = 5
35+
features = ["lpc55", "gpio"]
36+
max-sizes = {flash = 32768, ram = 16384 }
37+
stacksize = 2048
38+
start = true
39+
task-slots = ["gpio_driver", "update_server"]
40+
41+
[tasks.idle]
42+
name = "task-idle"
43+
priority = 7
44+
max-sizes = {flash = 256, ram = 256}
45+
stacksize = 256
46+
start = true
47+
48+
[tasks.update_server]
49+
name = "lpc55-update-server"
50+
priority = 3
51+
max-sizes = {flash = 26720, ram = 16704}
52+
stacksize = 8192
53+
start = true
54+
sections = {bootstate = "usbsram"}
55+
uses = ["flash_controller", "hash_crypt"]
56+
notifications = ["flash-irq", "hashcrypt-irq"]
57+
interrupts = {"flash_controller.irq" = "flash-irq", "hash_crypt.irq" = "hashcrypt-irq"}
58+
task-slots = [{"syscon" = "syscon_driver"}, "jefe"]
59+
60+
[tasks.syscon_driver]
61+
name = "drv-lpc55-syscon"
62+
priority = 2
63+
max-sizes = {flash = 8192, ram = 2048}
64+
uses = ["syscon", "anactrl", "pmc"]
65+
start = true
66+
stacksize = 1000
67+
task-slots = ["jefe"]
68+
69+
[tasks.gpio_driver]
70+
name = "drv-lpc55-gpio"
71+
priority = 3
72+
max-sizes = {flash = 8192, ram = 2048}
73+
uses = ["gpio", "iocon", "pint", "inputmux"]
74+
start = true
75+
stacksize = 1000
76+
task-slots = ["syscon_driver"]
77+
78+
[tasks.user_leds]
79+
name = "drv-user-leds"
80+
features = ["lpc55"]
81+
priority = 4
82+
max-sizes = {flash = 8192, ram = 2048}
83+
start = true
84+
stacksize = 1000
85+
task-slots = ["gpio_driver"]
86+
notifications = ["timer"]
87+
88+
[tasks.button]
89+
name = "task-button"
90+
priority = 6
91+
start = true
92+
notifications = ["timer", "button-irq"]
93+
interrupts = { "pint.irq0" = "button-irq"}
94+
stacksize = 4096
95+
task-slots = ["gpio_driver", {"syscon" = "syscon_driver"}]
96+
97+
[tasks.button.config]
98+
pins = [
99+
{ name = "BUTTON", pin = { port = 1, pin = 9}, alt = 0, pint = 0, direction = "input", opendrain = "normal" },
100+
{ name = "RED_LED", pin = { port = 1, pin = 6}, alt = 0, direction = "output", value = true },
101+
{ name = "GREEN_LED", pin = { port = 1, pin = 7}, alt = 0, direction = "output", value = true },
102+
{ name = "BLUE_LED", pin = { port = 1, pin = 4}, alt = 0, direction = "output", value = true },
103+
]
104+
105+
[tasks.usart_driver]
106+
name = "drv-lpc55-usart"
107+
priority = 4
108+
max-sizes = {flash = 8192, ram = 2048}
109+
uses = ["flexcomm0"]
110+
start = true
111+
notifications = ["usart-irq"]
112+
interrupts = {"flexcomm0.irq" = "usart-irq"}
113+
stacksize = 1000
114+
task-slots = ["gpio_driver", "syscon_driver"]
115+
116+
[tasks.usart_driver.config]
117+
pins = [
118+
{ pin = { port = 0, pin = 29}, alt = 1},
119+
{ pin = { port = 0, pin = 30}, alt = 1}
120+
]
121+
122+
[tasks.i2c_driver]
123+
name = "drv-lpc55-i2c"
124+
priority = 4
125+
uses = ["flexcomm4"]
126+
start = true
127+
stacksize = 1000
128+
task-slots = ["gpio_driver", "syscon_driver"]
129+
130+
[tasks.rng_driver]
131+
name = "drv-lpc55-rng"
132+
priority = 3
133+
max-sizes = {flash = 16384, ram = 4096}
134+
uses = ["rng", "pmc"]
135+
start = true
136+
stacksize = 2200
137+
task-slots = ["syscon_driver"]
138+
139+
[tasks.dump_agent]
140+
name = "task-dump-agent"
141+
features = ["no-rot"]
142+
priority = 5
143+
max-sizes = {flash = 32768, ram = 2240 }
144+
start = true
145+
task-slots = ["jefe"]
146+
stacksize = 1536
147+
extern-regions = ["sram2"]
148+
149+
[tasks.attest]
150+
name = "task-attest"
151+
priority = 5
152+
max-sizes = {flash = 35072, ram = 16384}
153+
stacksize = 12304
154+
start = false
155+
extern-regions = ["dice_alias", "dice_certs"]
156+
157+
[signing.certs]
158+
signing-certs = ["../../support/fake_certs/fake_certificate.der.crt"]
159+
root-certs = ["../../support/fake_certs/fake_certificate.der.crt"]
160+
private-key = "../../support/fake_certs/fake_private_key.pem"

idl/button.idol

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// User Button and LED API
2+
3+
Interface(
4+
name: "Button",
5+
ops: {
6+
"press": (
7+
reply: Result(
8+
ok: "u8",
9+
err: CLike("ButtonError"),
10+
),
11+
idempotent: true,
12+
),
13+
"off": (
14+
reply: Result(
15+
ok: "()",
16+
err: CLike("ButtonError"),
17+
),
18+
idempotent: true,
19+
),
20+
"set": (
21+
args: {
22+
"rgb": "u8",
23+
},
24+
reply: Result(
25+
ok: "()",
26+
err: CLike("ButtonError"),
27+
),
28+
idempotent: true,
29+
),
30+
"blink": (
31+
description: "blinks the LED at a fixed speed",
32+
args: {
33+
"on": "u32",
34+
"off": "u32",
35+
},
36+
reply: Result(
37+
ok: "()",
38+
err: CLike("ButtonError"),
39+
),
40+
idempotent: true,
41+
),
42+
},
43+
)

task/button-api/Cargo.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "button-api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[features]
7+
8+
[dependencies]
9+
counters = { path = "../../lib/counters" }
10+
derive-idol-err = { path = "../../lib/derive-idol-err" }
11+
hubpack = { workspace = true }
12+
idol-runtime = { workspace = true }
13+
num-traits = { workspace = true }
14+
serde = { workspace = true }
15+
userlib = { path = "../../sys/userlib", features = ["panic-messages"] }
16+
zerocopy = { workspace = true }
17+
18+
[build-dependencies]
19+
idol = { workspace = true }
20+
serde = { workspace = true }
21+
22+
[lib]
23+
test = false
24+
doctest = false
25+
bench = false
26+
27+
[lints]
28+
workspace = true

task/button-api/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
use std::error::Error;
6+
7+
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
8+
idol::client::build_client_stub("../../idl/button.idol", "client_stub.rs")?;
9+
Ok(())
10+
}

task/button-api/src/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! API crate for the 'button' task.
6+
7+
#![no_std]
8+
9+
use derive_idol_err::IdolError;
10+
use userlib::{sys_send, FromPrimitive};
11+
12+
#[derive(Copy, Clone, Debug, FromPrimitive, IdolError, counters::Count)]
13+
pub enum ButtonError {
14+
InvalidValue = 1,
15+
TaskRestarted = 2,
16+
}
17+
18+
impl From<idol_runtime::ServerDeath> for ButtonError {
19+
fn from(_: idol_runtime::ServerDeath) -> Self {
20+
ButtonError::TaskRestarted
21+
}
22+
}
23+
24+
include!(concat!(env!("OUT_DIR"), "/client_stub.rs"));

task/button/Cargo.toml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "task-button"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
drv-lpc55-gpio-api = { path = "../../drv/lpc55-gpio-api"}
8+
button-api = { path = "../button-api"}
9+
arrayvec.workspace = true
10+
hubpack = { workspace = true }
11+
idol-runtime = { workspace = true }
12+
num-traits = { workspace = true }
13+
serde = { workspace = true }
14+
serde_with = { version = "3.3.0", default-features = false, features = ["macros"] }
15+
static-cell = { path = "../../lib/static-cell" }
16+
unwrap-lite = { path = "../../lib/unwrap-lite" }
17+
userlib = { path = "../../sys/userlib", features = ["panic-messages"] }
18+
zerocopy = { workspace = true }
19+
20+
[build-dependencies]
21+
anyhow.workspace = true
22+
idol.workspace = true
23+
serde.workspace = true
24+
quote = { workspace = true }
25+
build-lpc55pins = { path = "../../build/lpc55pins" }
26+
build-util = { path = "../../build/util" }
27+
28+
[features]
29+
no-ipc-counters = ["idol/no-counters"]
30+
31+
[[bin]]
32+
name = "task-button"
33+
test = false
34+
doctest = false
35+
bench = false
36+
37+
[lints]
38+
workspace = true

task/button/build.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
use anyhow::Result;
6+
use build_lpc55pins::PinConfig;
7+
use idol::{server::ServerStyle, CounterSettings};
8+
use serde::Deserialize;
9+
10+
#[derive(Deserialize)]
11+
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
12+
struct TaskConfig {
13+
pins: Vec<PinConfig>,
14+
}
15+
16+
fn main() -> Result<()> {
17+
build_util::expose_target_board();
18+
build_util::build_notifications()?;
19+
20+
idol::Generator::new()
21+
.with_counters(CounterSettings::default().with_server_counters(false))
22+
.build_server_support(
23+
"../../idl/button.idol",
24+
"server_stub.rs",
25+
ServerStyle::InOrder,
26+
)
27+
.unwrap();
28+
29+
let task_config = build_util::task_config::<TaskConfig>()?;
30+
build_lpc55pins::codegen(task_config.pins)?;
31+
32+
Ok(())
33+
}

0 commit comments

Comments
 (0)