osd-contiki/cpu/stm32w108/hal/micro/cortexm3/button.c

37 lines
1 KiB
C
Raw Permalink Normal View History

2010-10-25 11:03:38 +02:00
/** @file /hal/micro/cortexm3/button.c
* @brief button APIs
*
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
*/
#include PLATFORM_HEADER
#include BOARD_HEADER
#include "hal/micro/button.h"
#include "hal/micro/micro-common.h"
#include "hal/micro/cortexm3/micro-common.h"
void halInitButton(void)
{
uint8_t i;
2011-03-21 13:11:52 +01:00
/* Configure GPIO for BUTTONSs */
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
for (i = 0; i < boardDescription->buttons; i++) {
halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
}
2010-10-25 11:03:38 +02:00
}/* end halInitButton() */
uint8_t halGetButtonStatus(HalBoardButton button)
2010-10-25 11:03:38 +02:00
{
uint8_t port = (button >> 3) & 0xf;
uint8_t pin = button & 0x7;
2011-03-21 13:11:52 +01:00
if (button != DUMMY_BUTTON)
{
return (BUTTON_INPUT_GPIO(port) & (1 << pin)) ? BUTTON_RELEASED : BUTTON_PRESSED;
}
return BUTTON_UNKNOWN;
2010-10-25 11:03:38 +02:00
}/* end halGetButtonStatus()*/