Library 57- Buttons for STM32F4xx

I had some free time so I made a new library for web. It can handle buttons, connected to your STM32F4xx device.

It supports basically unlimited number of buttons with different triggering. Currently, callback functions can be called on these events:

  • Button on pressed: Called directly when button is pressed
  • Button normal press: Called when button is released after specific amount of time
  • Button long press: Called when button is pressed for specific “long” amount of time

It uses malloc() to allocate memory, so you have to make sure that your heap is big enough. It also allows you to select state when button is pressed, high or low.

Currently, it does not support double click event but this will be done (I hope) in near future.

You just have to make sure, that your button is properly connected to STM device with capacitor and pull resistor!

Library

Features

  • Supports buttons connected to STM32F4xx
  • Support different button trigger events

Dependencies

  • CMSIS
    • STM32F4xx
  • TM
    • TM GPIO
    • TM DELAY
    • defines.h

Library uses some predefined constants which can be changed in your defines.h file:

Functions and enumerations

Example

Example below is done for Nucleo or Discovery board. 2 buttons on specific pins are initialized for use. Output is on PA2 for USART.

Project is available on my Github account, download library below.

Icon
TM STM32F4 BUTTON Library

tilz0R

Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Pingback: All STM32F4 libraries - STM32F4 Discovery()

  • leonardo

    Hi! I like this library, I found very usefull. But I have some doubt about button bounce. I think that funciont for TM_BUTTON_PressType_OnPressed will execute several time on real button becouse of bounce.
    I will try to add a couple of states to eliminate bounce and maybe a long long function.

  • leonardo

    Hi!, just one comment, I’m using this library (with some porting) on a LPC11u67 and I have to add initialization code for Button State. Maybe keil initialize the struct fields with 0, by on LPCXpresso, when the button struct is created State is not 0.
    On TM_BUTTON_Init I modify this part of code:
    http://pastebin.com/raw.php?i=GxeQLfy0

    Regards!