Relationship between GPIO ports and Teensy pins #127
-
Hi there! I'm quite new to embedded development outside of the Arduino/Teensyduino framework, and one thing that's been a source of confusion is the difference between GPIO ports and pins, which pins correspond to which GPIO ports, and which member of #![no_std]
#![no_main]
use teensy4_panic as _;
#[rtic::app(device = teensy4_bsp, peripherals = false)]
mod app {
use bsp::{
board,
hal::{
gpio,
iomuxc::{self, Config, Hysteresis, PullKeeper},
},
};
use teensy4_bsp as bsp;
#[shared]
struct Shared {}
#[local]
struct Local {
led: board::Led,
button: gpio::Input<bsp::pins::t40::P4>,
}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
let instances = board::instances();
let board::Resources {
mut pins,
mut gpio2,
mut gpio4,
..
} = board::t40(instances);
let led = board::led(&mut gpio2, pins.p13);
iomuxc::configure(
&mut pins.p4,
Config::zero()
.set_hysteresis(Hysteresis::Enabled)
.set_pull_keeper(Some(PullKeeper::Pullup100k)),
);
let button = gpio4.input(pins.p4);
gpio4.set_interrupt(&button, Some(gpio::Trigger::EitherEdge));
(Shared {}, Local { led, button }, init::Monotonics())
}
#[task(binds = GPIO4_COMBINED_0_15, local = [led, button])]
fn on_button_change(cx: on_button_change::Context) {
let on_button_change::LocalResources { led, button } = cx.local;
if button.is_set() {
led.clear()
} else {
led.set();
}
button.clear_triggered();
}
} At first I tried Then I tried creating the interrupt task, first by just blindly trying Are there any resources that could help me get a grasp on these things? I scanned over the Rust Embedded Book before I got started, but I don't have either of the example boards that was written for, and anyway it wouldn't help me resolve the Teensy-specific confusions. I don't see any references to "GPIO" on the Teensy 4.0 page, but I do see a handful of UpdateOn further investigation, the GPIO port number and pin number do need to match because of how the Update 2Nope, nevermind, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Great job working through this, and thanks for sharing your findings. Sounds like you're correctly interpreting the (common) pin table. But for future readers, here's what we're talking about: Scan down the left-most Pin column to find board pin 4. Then, scan the row until you find (I'm using the term "offset" to not overload the term "pin." Sometimes it's denoted like
That's right. You'll need to check the GPIO inputs that you configured to figure out which one actually activated. So if board pin 2 ( If you really need a 1:1 mapping of interrupt to GPIO input, know that the first eight offsets of GPIO port 1 have dedicated interrupts. Teensy board pins 0 and 1 are candidates for this feature. The interrupt is named like this. |
Beta Was this translation helpful? Give feedback.
Great job working through this, and thanks for sharing your findings.
Sounds like you're correctly interpreting the (common) pin table. But for future readers, here's what we're talking about: Scan down the left-most Pin column to find board pin 4. Then, scan the row until you find
GPIO4_IO06
in one of the columns (ignore the "pad ID" column). TheGPIO4_IO06
entry indicates that pin 4 works with GPIO port 4. Its offset is 6. This explains why the board pin 4 objectpins.p4
only works withgpio4
and notgpio2
.(I'm using the term "offset" to not overload the term "pin." Sometimes it's denoted like
GPIO4[6]
, which looks like an array offset.)GPIO4_COMBINED_0_15
will pend whenever something…