Fixed button-sensor for launchpad
This commit is contained in:
parent
d312dd9ebb
commit
f3a030b0a4
@ -47,7 +47,7 @@ endif
|
||||
# root path. Note that the returned path is encased in angular brackets, <...>,
|
||||
# and is therefore extracted with sed.
|
||||
SDK_DEVICE_DIR := $(shell echo "DeviceFamily_constructPath(dummy)" \
|
||||
| arm-none-eabi-gcc -x c -E -DDeviceFamily_$(DEVICE_FAMILY) -include $(DEVICE_FAMILY_H) - \
|
||||
| arm-none-eabi-cpp -x c -E -DDeviceFamily_$(DEVICE_FAMILY) -include $(DEVICE_FAMILY_H) - \
|
||||
| tail -1 \
|
||||
| sed -E 's:<(.+)/dummy>:\1:')
|
||||
|
||||
|
@ -45,18 +45,22 @@
|
||||
#define BUTTON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Contiki API */
|
||||
#include <lib/sensors.h>
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Board specific button sensors */
|
||||
#include "button-sensor-arch.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR "Button"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR_VALUE_STATE 0
|
||||
#define BUTTON_SENSOR_VALUE_DURATION 1
|
||||
typedef enum {
|
||||
BUTTON_SENSOR_TYPE_STATE,
|
||||
BUTTON_SENSOR_TYPE_DURATION
|
||||
} button_sensor_type_t;
|
||||
|
||||
#define BUTTON_SENSOR_VALUE_RELEASED 0
|
||||
#define BUTTON_SENSOR_VALUE_PRESSED 1
|
||||
typedef enum {
|
||||
BUTTON_SENSOR_VALUE_RELEASED,
|
||||
BUTTON_SENSOR_VALUE_PRESSED
|
||||
} button_sensor_value_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -59,14 +59,10 @@
|
||||
* Override button symbols from dev/button-sensor.h, for the examples that
|
||||
* include it
|
||||
*/
|
||||
#define button_left_sensor btn1_sensor
|
||||
#define button_right_sensor btn2_sensor
|
||||
#define button_sensor button_left_sensor
|
||||
#define button_sensor2 button_right_sensor
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Platform-specific define to signify sensor reading failure */
|
||||
/* TODO: remove */
|
||||
#define CC26XX_SENSOR_READING_ERROR 0x80000000
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Include CPU-related configuration */
|
||||
#include "cc13xx-cc26xx-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "button-sensor.h"
|
||||
#include "button-sensor-arch.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* LaunchPad has 2 buttons: BTN1 and BTN2 */
|
||||
/* Map the GPIO defines from the Board file */
|
||||
@ -96,9 +95,9 @@ button_press_cb(PIN_Handle handle, PIN_Id pin_id)
|
||||
|
||||
switch (pin_id) {
|
||||
case BTN1_PIN: btn_timer = &btn1_timer;
|
||||
btn_sensor = &btn1_sensor; break;
|
||||
btn_sensor = &button_left_sensor; break;
|
||||
case BTN2_PIN: btn_timer = &btn2_timer;
|
||||
btn_sensor = &btn2_sensor; break;
|
||||
btn_sensor = &button_right_sensor; break;
|
||||
default: return; /* No matching PIN */
|
||||
}
|
||||
|
||||
@ -121,14 +120,18 @@ button_press_cb(PIN_Handle handle, PIN_Id pin_id)
|
||||
static int
|
||||
button_value(int type, uint8_t pin, BtnTimer *btn_timer)
|
||||
{
|
||||
if (type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
switch (type) {
|
||||
case BUTTON_SENSOR_TYPE_STATE:
|
||||
return (PIN_getInputValue(pin) == 0)
|
||||
? BUTTON_SENSOR_VALUE_PRESSED
|
||||
: BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if (type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
|
||||
case BUTTON_SENSOR_TYPE_DURATION:
|
||||
return (int)btn_timer->duration;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
@ -212,7 +215,7 @@ btn2_status(int type)
|
||||
return button_status(type, BTN2_PIN);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(btn1_sensor, BUTTON_SENSOR, btn1_value, btn1_config, btn1_status);
|
||||
SENSORS_SENSOR(btn2_sensor, BUTTON_SENSOR, btn2_value, btn2_config, btn2_status);
|
||||
SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, btn1_value, btn1_config, btn1_status);
|
||||
SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, btn2_value, btn2_config, btn2_status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
@ -45,10 +45,10 @@
|
||||
#define BUTTON_SENSOR_ARCH_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Contiki API */
|
||||
#include <lib/sensors.h>
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor btn1_sensor;
|
||||
extern const struct sensors_sensor btn2_sensor;
|
||||
extern const struct sensors_sensor button_left_sensor;
|
||||
extern const struct sensors_sensor button_right_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_ARCH_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -43,8 +43,8 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Exports a global symbol to be used by the sensor API */
|
||||
SENSORS(
|
||||
&btn1_sensor,
|
||||
&btn2_sensor,
|
||||
&button_left_sensor,
|
||||
&button_right_sensor,
|
||||
NULL
|
||||
);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -79,7 +79,6 @@
|
||||
/* Arch driver implementations */
|
||||
#include "uart0-arch.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
//#include "gpio-interrupt.h"
|
||||
#include "ieee-addr.h"
|
||||
#include "dev/rf-common.h"
|
||||
#include "lib/random.h"
|
||||
@ -94,8 +93,11 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned short g_nodeId = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Board specific initialization */
|
||||
void board_init(void);
|
||||
/*
|
||||
* Board-specific initialization function.
|
||||
* This function is defined in the file <BOARD>_fxns.c
|
||||
*/
|
||||
extern void Board_initHook(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
fade(unsigned char l)
|
||||
@ -138,17 +140,20 @@ platform_init_stage_one(void)
|
||||
{
|
||||
DRIVERLIB_ASSERT_CURR_RELEASE();
|
||||
|
||||
// TODO: TEMPORARY WHILE DEVELOP. REMOVE
|
||||
HWREG(CPU_SCS_BASE + CPU_SCS_O_ACTLR) = CPU_SCS_ACTLR_DISDEFWBUF;
|
||||
|
||||
// Enable flash cache
|
||||
VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
|
||||
// Configure round robin arbitration and prefetching
|
||||
VIMSConfigure(VIMS_BASE, true, true);
|
||||
|
||||
// Board_initGeneral() will call Power_init()
|
||||
// Board_initGeneral() will call PIN_init(BoardGpioInitTable)
|
||||
Board_initGeneral();
|
||||
Power_init();
|
||||
|
||||
if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) {
|
||||
/* Error with PIN_init */
|
||||
while (1);
|
||||
}
|
||||
|
||||
/* Perform board-specific initialization */
|
||||
Board_initHook();
|
||||
|
||||
// Contiki drivers init
|
||||
leds_init();
|
||||
|
Loading…
Reference in New Issue
Block a user