PaulStoffregen / Encoder

Quadrature Encoder Library for Arduino
http://www.pjrc.com/teensy/td_libs_Encoder.html
540 stars 239 forks source link

Support for STM32 #72

Open mfouadthabet opened 2 years ago

mfouadthabet commented 2 years ago

Description

Tried to use the lib with STM32 bluepill , it seems that it is not yet supported here is the build error: #error "Interrupts are unknown for this board, please add to this code"

For some reason this library is tagged as supporting STM32 in platformio documentation.

Do you have plans to support it soon? Is it a matter of only adding a new define segment in the interrupt_pins.h header file?

PaulStoffregen commented 2 years ago

Is it a matter of only adding a new define segment in the interrupt_pins.h header file?

Yes (or probably yes), just a matter of missing defines. Help wanted from any STM32 experts to send a pull request.

Just to be clear, I do not have any STM32 boards. I'm depending on the open source community to send pull requests to add the appropriate defines.

lucky62 commented 1 month ago

As I know in STM32F103C8 any GPIO pin can be used for interrupts. Just it is not clear for me how to define pins.

For example this is defined for ESP8266: image

The questions:

lucky62 commented 1 month ago

ok, I created the definitions for BluePill according this and seems encoder is working.

I am using PlatformIO (arduino framework). So I created the extra file with definitions and added it to build flags: build_flags = -include src/stm32f103C8_interrupt_pins.h

I am not sure if it is 100% correct, but simply it is working. File is attached. Note that I must use the pin names without underscore (like PB12, not PB_12 as are in the mentioned board variant file). stm32f103C8_interrupt_pins.zip

My encoder generates 4 steps per "click", so I must divide the value by 4. ESPRotary Library has the parameter CLICKS_PER_STEP and it makes the calculations internally.