stm32-rs / stm32f0xx-hal

A Rust `embedded-hal` implementation for all MCUs in the STM32 F0 family
BSD Zero Clause License
134 stars 59 forks source link

implement TscPin for remaining touch pins #120

Closed evils closed 4 years ago

evils commented 4 years ago

some touch pins were missing the TscPin trait

evils commented 4 years ago

odd that the CI failed, it works locally (but i'm not using gpiod or gpioe for touch) help would be appreciated

therealprof commented 4 years ago

Hi and thanks for the PR!

Relating to the build failure you will need to feature gate according to the specific model, since not all families do have the ports/pin you're trying to add here.

There's a tools/check.py which allows you to run all the CI tests locally.

In your specific case one model that is failing is stm32f031:

Running `cargo check --examples --features=stm32f031,rt,stm32-usbd`...
   Compiling stm32f0 v0.11.0
    Checking stm32f0xx-hal v0.17.0 (/Users/egger/OSS/stm32f0xx-hal)
error[E0432]: unresolved imports `crate::gpio::gpiod`, `crate::gpio::gpioe`
  --> src/tsc.rs:10:40
   |
10 | use crate::gpio::{gpioa, gpiob, gpioc, gpiod, gpioe, Alternate, AF0, AF3};
   |                                        ^^^^^  ^^^^^ no `gpioe` in `gpio`
   |                                        |
   |                                        no `gpiod` in `gpio`
   |
help: a similar name exists in the module
   |
10 | use crate::gpio::{gpioa, gpiob, gpioc, gpioa, gpioe, Alternate, AF0, AF3};
   |                                        ^^^^^
help: a similar name exists in the module
   |
10 | use crate::gpio::{gpioa, gpiob, gpioc, gpiod, gpioa, Alternate, AF0, AF3};
   |                                               ^^^^^

error[E0412]: cannot find type `PC5` in module `gpioc`
   --> src/tsc.rs:70:12
    |
70  |     gpioc::PC5<Alternate<AF0>> => (3_u8, 1_u8),
    |            ^^^
    |
   ::: src/gpio.rs:247:21
    |
247 |                     pub struct $PXi<MODE> {
    |                     --------------------- similarly named struct `PC15` defined here
    |
help: there is an enum variant `crate::pac::syscfg::exticr2::EXTI5_A::PC5` and 1 other; try using the variant's enum
    |
70  |     crate::pac::syscfg::exticr2::EXTI5_A => (3_u8, 1_u8),
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70  |     stm32f0::stm32f0x1::syscfg::exticr2::EXTI5_A => (3_u8, 1_u8),
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: a struct with a similar name exists
    |
70  |     gpioc::PC15<Alternate<AF0>> => (3_u8, 1_u8),
    |            ^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0412, E0432.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `stm32f0xx-hal`.

To learn more, run the command again with --verbose.
therealprof commented 4 years ago

odd that the CI failed, it works locally (but i'm not using gpiod or gpioe for touch) help would be appreciated

Well, you changed the imports here:

use crate::gpio::{gpioa, gpiob, gpioc, gpiod, gpioe, Alternate, AF0, AF3};

Whether you actually use it or not is not important, if it does not exist you can't import it (and even if it does exist, then you shouldn't import it if you don't use it 😉).

evils commented 4 years ago

odd that the CI failed, it works locally (but i'm not using gpiod or gpioe for touch) help would be appreciated

Well, you changed the imports here:

use crate::gpio::{gpioa, gpiob, gpioc, gpiod, gpioe, Alternate, AF0, AF3};

Whether you actually use it or not is not important, if it does not exist you can't import it (and even if it does exist, then you shouldn't import it if you don't use it wink).

i meant i'm not using those ports for touch in my project, and speculated that that is related to the CI failure here i do use them in the code i added here

... you will need to feature gate according to the specific model

like these?
is it possible to directly reuse those?

therealprof commented 4 years ago

i meant i'm not using those ports for touch in my project, and speculated that that is related to the CI failure here i do use them in the code i added here

Exactly. But all code that is added needs to compile for all supported chips and the only way to do that is to feature gate accordingly.

... you will need to feature gate according to the specific model

like these? is it possible to directly reuse those?

That's part of a macro, it would be possible to do the same here but that would mean you'd have to rewrite the macros and all callers of tsc_pin! which is a bit gnarly especially for a beginner.

I think you'd be easier off with a blanket import of all gpio ports like:

use crate::{gpio::*, rcc::Rcc, time::Bps};

and traditional feature gating like https://github.com/stm32-rs/stm32f0xx-hal/blob/0bbb50f5fac00bc4e40fb5dfdfde57cfa90a1824/src/serial.rs#L117-L131

therealprof commented 4 years ago

Nice. Would you mind adding a brief entry to the CHANGELOG about the additions?

evils commented 4 years ago

because i think it's a bit of a cleaner representation, here are my notes on this

stm32f0xx family members with a TSC (touch sensing controller)
51
groups 1-6
71
groups 1-8
91
groups 1-8
42
groups 1-5
(missing PC5)
72
groups 1-8
48
groups 1-5
(missing PC5)
58
groups 1-6
(missing PB2)
78
groups 1-8
(missing PB2)
98
groups 1-8
(missing PB2)
bors[bot] commented 4 years ago

Timed out.

therealprof commented 4 years ago

bors retry

bors[bot] commented 4 years ago

Timed out.