Contiki 2.6

button.c

Go to the documentation of this file.
00001 /** @file /hal/micro/cortexm3/button.c
00002  * @brief button APIs
00003  *
00004  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved.        -->
00005  */
00006 
00007 #include PLATFORM_HEADER
00008 #include BOARD_HEADER
00009 #include "hal/micro/button.h"
00010 #include "hal/micro/micro-common.h"
00011 #include "hal/micro/cortexm3/micro-common.h"
00012 
00013 void halInitButton(void)
00014 {
00015   int8u i;
00016   /* Configure GPIO for BUTTONSs */
00017   ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
00018   for (i = 0; i < boardDescription->buttons; i++) {
00019     halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
00020     halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
00021   }
00022 }/* end halInitButton() */
00023 
00024 
00025 int8u halGetButtonStatus(HalBoardButton button)
00026 {
00027   int8u port = (button >> 3) & 0xf;
00028   int8u pin = button & 0x7;
00029 
00030   if (button != DUMMY_BUTTON)
00031   {
00032     return (BUTTON_INPUT_GPIO(port) & (1 << pin)) ? BUTTON_RELEASED : BUTTON_PRESSED;
00033   }
00034   return BUTTON_UNKNOWN;
00035 }/* end halGetButtonStatus()*/
00036