我想弄清楚如何把锈蚀等效为
pinMode(PIN_D7, INPUT_PULLUP); // Pushbutton
(来自https://www.pjrc.com/teensy/td_digital.html)
我使用模板https://github.com/mciantyre/teensy4-rs-template创建了一个项目,如https://github.com/mciantyre/teensy4-rs的“入门”部分所概述的那样。
不幸的是,Rust arduino代码是IntelliJ IDEA无法完全导航的一个兔子洞(它们使用宏生成struct
s和impl
s),因此我无法获得任何有用的完成结果,从而帮助我确定哪些方法和字段可用。
我不知道如何用pins.p7
激活拉起电阻,甚至取样。追逐从p7
到P7
到B1_01
到Pad
的文档让我仍然困惑不解。
发布于 2021-12-06 16:28:41
基于对https://github.com/mciantyre/teensy4-rs/issues/107的响应和https://github.com/imxrt-rs/imxrt-hal/issues/112上的代码,我创建了下面的示例,该示例似乎适用于我的teensy4.0
let cfg = Config::zero()
.set_hysteresis(Hysteresis::Enabled)
.set_pull_keep(PullKeep::Enabled)
.set_pull_keep_select(PullKeepSelect::Pull)
.set_pullupdown(PullUpDown::Pulldown100k);
iomuxc::configure(&mut switch_pin, cfg);
let switch_gpio = GPIO::new(switch_pin);
loop {
if switch_gpio.is_set() {
led.toggle()
}
systick.delay(LED_PERIOD_MS);
}
发布于 2021-11-30 19:04:11
(这里记录了一些故障)
我在板条箱上做了一些实验和一些文本搜索,找到了Config
结构。
不幸的是,当我这样使用它时,结果是不可靠的。
// pull-down resistor. Switch drags to 3.3v
fn mission1(mut switch_pin: B0_10, led: &mut LED, systick: &mut SysTick) -> !
{
let cfg = teensy4_bsp::hal::iomuxc::Config::zero().set_pullupdown(PullUpDown::Pulldown100k);
iomuxc::configure(&mut switch_pin, cfg);
let bacon = GPIO::new(switch_pin);
loop {
if bacon.is_set() {
led.toggle()
}
systick.delay(300);
}
}
它仍然捕捉到虚假的按钮点击。我把事情扭转过来,试着把它装起来。
// pull-up resistor. Switch drags to ground
fn mission2(mut switch_pin: B0_10, led: &mut LED, systick: &mut SysTick) -> !
{
let pull_up = match 22
{
100 => PullUpDown::Pullup100k, // unreliable
47 => PullUpDown::Pullup47k, // unreliable
_ => PullUpDown::Pullup22k,
};
let cfg = teensy4_bsp::hal::iomuxc::Config::zero().set_pullupdown(pull_up);
iomuxc::configure(&mut switch_pin, cfg);
let bacon = GPIO::new(switch_pin);
loop {
if ! bacon.is_set() {
led.toggle()
}
systick.delay(300);
}
}
所有三个拉动选项都没有用。我附上了一个万用表,它是大约0.67v之间的引脚和地面与开关打开和22k拉电阻选项。
当我连接一个物理的10K电阻时,它的行为就像我预期的那样,万用表的测量值为3.23V。如果我将两个10 it串联起来,它的长度为3.20V。
我要说的是,对于Teensy 4.0来说,这不是合适的技术。
https://stackoverflow.com/questions/70102418
复制相似问题