Contiki 3.x
button.c
Go to the documentation of this file.
1 /** @file /hal/micro/cortexm3/button.c
2  * @brief button APIs
3  *
4  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
5  */
6 
7 #include PLATFORM_HEADER
8 #include BOARD_HEADER
9 #include "hal/micro/button.h"
10 #include "hal/micro/micro-common.h"
12 
13 void halInitButton(void)
14 {
15  uint8_t i;
16  /* Configure GPIO for BUTTONSs */
17  ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
18  for (i = 0; i < boardDescription->buttons; i++) {
19  halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
20  halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
21  }
22 }/* end halInitButton() */
23 
24 
25 uint8_t halGetButtonStatus(HalBoardButton button)
26 {
27  uint8_t port = (button >> 3) & 0xf;
28  uint8_t pin = button & 0x7;
29 
30  if (button != DUMMY_BUTTON)
31  {
32  return (BUTTON_INPUT_GPIO(port) & (1 << pin)) ? BUTTON_RELEASED : BUTTON_PRESSED;
33  }
34  return BUTTON_UNKNOWN;
35 }/* end halGetButtonStatus()*/
36 
uint8_t buttons
Number of buttons.
Definition: board.h:172
Header for button driver.
Data structure for button description.
Definition: board.h:97
Utility and convenience functions for STM32W108 microcontroller, common to both the full and minimal ...
#define PORTx_PIN(x, y)
Some registers and variables require indentifying GPIO by a single number instead of the port and pin...
Definition: micro-common.h:55
void halGpioSet(uint32_t gpio, boolean value)
Set/Clear single GPIO bit.
Definition: micro-common.c:63
Minimal Hal functions common across all microcontroller-specific files.
uint8_t halGetButtonStatus(HalBoardButton button)
Get button status.
Definition: button.c:25
const ButtonResourceType * buttons
Pointer to button resources.
Definition: board.h:137
void halInitButton(void)
Init buttons.
Definition: button.c:13
const BoardIOType * io
Board I/O description.
Definition: board.h:176
void halGpioConfig(uint32_t io, uint32_t config)
Configure an IO pin&#39;s operating mode.
Definition: micro-common.c:48