Contiki 2.5
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  int8u 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 int8u halGetButtonStatus(HalBoardButton button)
26 {
27  int8u port = (button >> 3) & 0xf;
28  int8u 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