Working prop-mode

This commit is contained in:
Edvard Pettersen 2018-06-15 16:37:51 +02:00
parent f9fcbd6a77
commit f6b016c5d4
13 changed files with 593 additions and 543 deletions

View File

@ -56,12 +56,10 @@
#define CC2650_FAST_RADIO_STARTUP (MAC_CONF_WITH_TSCH)
#endif
#ifdef RF_CHANNEL
#define RF_CORE_CONF_CHANNEL RF_CHANNEL
#endif
#ifndef RF_CORE_CONF_CHANNEL
#define RF_CORE_CONF_CHANNEL 25
#ifdef RF_CORE_CONF_CHANNEL
#define RF_CHANNEL RF_CORE_CONF_CHANNEL
#else
#define RF_CHANNEL 25
#endif
/* Number of Prop Mode RX buffers */
@ -70,54 +68,59 @@
#endif
/* Configure Radio mode, i.e. prop or ieee */
/*----- CC13xx Device Line --------------------------------------------------*/
/* CC13xx supports both IEEE and Prop mode, depending on which device */
/* CC26xx only supports IEEE mode */
#if defined(DEVICE_LINE_CC13XX)
/* Default mode should be prop for prop-only devices (CC1310, CC1312);
/* Default mode should be prop for prop-only devices (CC1310, CC1312R);
* Else, IEEE mode is default. */
# ifndef CC13XX_CONF_PROP_MODE
# if (SUPPORTS_IEEE_MODE == 0)
# define CC13XX_CONF_PROP_MODE 1
# else
# define CC13XX_CONF_PROP_MODE 0
# endif
# endif
# if (CC13XX_CONF_PROP_MODE == 1) && (SUPPORTS_PROP_MODE == 1)
/*----- CC13xx Prop Mode ----------------------------------------------------*/
# define NETSTACK_CONF_RADIO prop_mode_driver
# define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400)
# define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME \
(RTIMER_SECOND / 1000)
# define CSMA_CONF_SEND_SOFT_ACK 1
# elif (CC13XX_CONF_PROP_MODE == 0) && (SUPPORTS_IEEE_MODE == 1)
/*----- CC13xx IEEE Mode ----------------------------------------------------*/
# define NETSTACK_CONF_RADIO ieee_mode_driver
# define CSMA_CONF_SEND_SOFT_ACK 0
# ifndef CC13XX_CONF_PROP_MODE
# if (SUPPORTS_IEEE_MODE == 0)
# define CC13XX_CONF_PROP_MODE 1
# else
# error "Invalid radio mode configuration of CC13xx device"
# endif /* (CC13XX_CONF_PROP_MODE == 1) && (SUPPORTS_PROP_MODE == 1) */
# define CC13XX_CONF_PROP_MODE 0
# endif
# endif
# if (CC13XX_CONF_PROP_MODE == 1) && (SUPPORTS_PROP_MODE == 1)
/*----- CC13xx Prop Mode ----------------------------------------------------*/
# define NETSTACK_CONF_RADIO prop_mode_driver
# define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 300)
# define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000)
# define CSMA_CONF_SEND_SOFT_ACK 1
# elif (CC13XX_CONF_PROP_MODE == 0) && (SUPPORTS_IEEE_MODE == 1)
/*----- CC13xx IEEE Mode ----------------------------------------------------*/
# define NETSTACK_CONF_RADIO ieee_mode_driver
# define CSMA_CONF_SEND_SOFT_ACK 0
# else
/*----- CC13xx Non-supported Mode -------------------------------------------*/
# error "Invalid radio mode configuration of CC13xx device"
# endif /* (CC13XX_CONF_PROP_MODE == 1) && (SUPPORTS_PROP_MODE == 1) */
/*----- CC26xx Device Line --------------------------------------------------*/
/* CC26xx only supports IEEE mode */
#elif defined(DEVICE_LINE_CC26XX)
# if (SUPPORTS_IEEE_MODE == 1)
# if (SUPPORTS_IEEE_MODE == 1)
/*----- CC26xx IEEE Mode ----------------------------------------------------*/
# define NETSTACK_CONF_RADIO ieee_mode_driver
# define NETSTACK_CONF_RADIO ieee_mode_driver
# define CSMA_CONF_SEND_SOFT_ACK 0
# define CSMA_CONF_SEND_SOFT_ACK 0
# else
# error "IEEE mode only supported by CC26xx devices"
# endif /* (SUPPORTS_IEEE_MODE == 1) */
# else
/*----- CC26xx Non-supported Mode -------------------------------------------*/
# error "IEEE mode only supported by CC26xx devices"
# endif /* (SUPPORTS_IEEE_MODE == 1) */
/*----- Unsupported device line ---------------------------------------------*/
#else
# error "Unsupported Device Line defined"
# error "Unsupported Device Line defined"
#endif /* defined(DEVICE_LINE_CC13xx) */
#define NETSTACK_RADIO_MAX_PAYLOAD_LEN 125

View File

@ -39,25 +39,18 @@
#include <contiki.h>
#include <dev/watchdog.h>
#include <sys/process.h>
#include <sys/energest.h>
#include <net/netstack.h>
#include <net/packetbuf.h>
#include <net/mac/mac.h>
/*---------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
/*---------------------------------------------------------------------------*/
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "RF"
#define LOG_LEVEL LOG_LEVEL_DBG
/*---------------------------------------------------------------------------*/
PROCESS(RF_coreProcess, "SimpleLink RF process");
PROCESS(rf_process, "SimpleLink RF Process");
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(RF_coreProcess, ev, data)
PROCESS_THREAD(rf_process, ev, data)
{
int len;

View File

@ -43,34 +43,12 @@
#ifndef RF_COMMON_H_
#define RF_COMMON_H_
/*---------------------------------------------------------------------------*/
/* Contiki API */
#include <sys/rtimer.h>
#include <dev/radio.h>
/*---------------------------------------------------------------------------*/
/* Standard library */
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#ifdef RF_CORE_CONF_CHANNEL
# define RF_CORE_CHANNEL RF_CORE_CONF_CHANNEL
#else
# define RF_CORE_CHANNEL 25
#endif
/*---------------------------------------------------------------------------*/
typedef enum {
CMD_RESULT_ERROR = 0,
CMD_RESULT_OK = 1,
} CmdResult;
} cmd_result_t;
/*---------------------------------------------------------------------------*/
typedef struct {
radio_value_t dbm;
uint16_t power; ///< Value for the .txPower field
} RF_TxPower;
#define TX_POWER_UNKNOWN 0xFFFF
/*---------------------------------------------------------------------------*/
#define RSSI_UNKNOWN -128
/*---------------------------------------------------------------------------*/
PROCESS_NAME(RF_coreProcess);
PROCESS_NAME(rf_process);
/*---------------------------------------------------------------------------*/
#endif /* RF_COMMON_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -121,7 +121,7 @@
#ifdef IEEE_MODE_CONF_CHANNEL
# define IEEE_MODE_CHANNEL IEEE_MODE_CONF_CHANNEL
#else
# define IEEE_MODE_CHANNEL RF_CORE_CHANNEL
# define IEEE_MODE_CHANNEL RF_CHANNEL
#endif
/* Configuration for TX power table */
@ -301,10 +301,7 @@ static void
rx_cb(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
{
if (e & RF_EventRxOk) {
process_poll(&RF_coreProcess);
}
if (e & RF_EventRxBufFull) {
process_poll(&rf_process);
}
}
/*---------------------------------------------------------------------------*/
@ -343,7 +340,7 @@ init_data_queue(void)
static void
init_rf_params(void)
{
cmd_rx.channel = RF_CORE_CHANNEL;
cmd_rx.channel = IEEE_MODE_CHANNEL;
cmd_rx.pRxQ = &g_rxDataQueue;
cmd_rx.pOutput = &g_rxStats;
@ -555,7 +552,7 @@ init(void)
ctimer_set(&g_ratOverflowTimer, RAT_OVERFLOW_PERIOD_SECONDS * CLOCK_SECOND / 2,
rat_overflow_cb, NULL);
process_start(&RF_coreProcess, NULL);
process_start(&rf_process, NULL);
return CMD_RESULT_OK;
}
@ -812,23 +809,25 @@ pending_packet(void)
const rfc_dataEntry_t *const pStartEntry = (rfc_dataEntry_t *)g_rxDataQueue.pCurrEntry;
volatile const rfc_dataEntry_t *pCurrEntry = pStartEntry;
int rv = 0;
// Check all RX buffers and check their statuses, stopping when looping the circular buffer
int bIsPending = 0;
do {
const uint8_t status = pCurrEntry->status;
if ((status == DATA_ENTRY_FINISHED) ||
(status == DATA_ENTRY_BUSY)) {
bIsPending = 1;
if (!g_bPollMode) {
process_poll(&RF_coreProcess);
}
rv += 1;
}
pCurrEntry = (rfc_dataEntry_t *)pCurrEntry->pNextEntry;
} while (pCurrEntry != pStartEntry);
if ((rv > 0) && !g_bPollMode) {
process_poll(&rf_process);
}
// If we didn't find an entry at status finished or busy, no frames are pending
return bIsPending;
return rv;
}
/*---------------------------------------------------------------------------*/
static int
@ -909,7 +908,7 @@ get_value(radio_param_t param, radio_value_t *value)
case RADIO_PARAM_TXPOWER:
*value = get_tx_power();
return (*value == TX_POWER_UNKNOWN)
return (*value == RF_TxPowerTable_INVALID_DBM)
? RADIO_RESULT_ERROR
: RADIO_RESULT_OK;

File diff suppressed because it is too large Load Diff

View File

@ -97,7 +97,7 @@ RF_TxPowerTable_Entry rf_prop_tx_power_table[RF_PROP_TX_POWER_TABLE_SIZE+1] =
};
/*---------------------------------------------------------------------------*/
// Overrides for CMD_PROP_RADIO_DIV_SETUP
uint32_t p_prop_overrides[] CC_ALIGN(4) =
uint32_t rf_prop_overrides[] CC_ALIGN(4) =
{
// override_use_patch_prop_genfsk.xml
MCE_RFE_OVERRIDE(0,4,0,1,0,0), // PHY: Use MCE ROM bank 4, RFE RAM patch
@ -137,15 +137,15 @@ uint32_t p_prop_overrides[] CC_ALIGN(4) =
// Proprietary Mode Radio Setup Command for All Frequency Bands
rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup =
{
.commandNo = 0x3807,
.status = 0x0000,
.commandNo = CMD_PROP_RADIO_DIV_SETUP,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = 0x0,
.startTrigger.bEnaCmd = 0x0,
.startTrigger.triggerNo = 0x0,
.startTrigger.pastTrig = 0x0,
.condition.rule = 0x1,
.condition.rule = COND_NEVER,
.condition.nSkip = 0x0,
.modulation.modType = 0x1,
.modulation.deviation = 0x64,
@ -164,7 +164,7 @@ rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup =
.config.analogCfgMode = 0x0,
.config.bNoFsPowerUp = 0x0,
.txPower = 0xAB3F,
.pRegOverride = pPropOverrides,
.pRegOverride = rf_prop_overrides,
.centerFreq = 0x0364,
.intFreq = 0x8000,
.loDivider = 0x05,
@ -174,15 +174,15 @@ rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup =
// Frequency Synthesizer Programming Command
rfc_CMD_FS_t rf_cmd_prop_fs =
{
.commandNo = 0x0803,
.status = 0x0000,
.commandNo = CMD_FS,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = 0x0,
.startTrigger.bEnaCmd = 0x0,
.startTrigger.triggerNo = 0x0,
.startTrigger.pastTrig = 0x0,
.condition.rule = 0x1,
.condition.rule = COND_NEVER,
.condition.nSkip = 0x0,
.frequency = 0x0364,
.fractFreq = 0x0000,
@ -199,14 +199,14 @@ rfc_CMD_FS_t rf_cmd_prop_fs =
rfc_CMD_PROP_TX_ADV_t rf_cmd_prop_tx_adv =
{
.commandNo = CMD_PROP_TX_ADV,
.status = 0x0000,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = 0x2,
.startTrigger.bEnaCmd = 0x0,
.startTrigger.triggerNo = 0x0,
.startTrigger.pastTrig = 0x1,
.condition.rule = 0x1,
.condition.rule = COND_NEVER,
.condition.nSkip = 0x0,
.pktConf.bFsOff = 0x0,
.pktConf.bUseCrc = 0x1,

View File

@ -52,7 +52,7 @@ extern rfc_CMD_PROP_TX_ADV_t rf_cmd_prop_tx_adv;
extern rfc_CMD_PROP_RX_ADV_t rf_cmd_prop_rx_adv;
/*---------------------------------------------------------------------------*/
// RF Core API Overrides
extern uint32_t p_prop_overrides[];
extern uint32_t rf_prop_overrides[];
/*---------------------------------------------------------------------------*/
#endif /* PROP_SETTINGS_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -109,7 +109,7 @@ uint32_t rf_ieee_overrides[] CC_ALIGN(4) =
rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup =
{
.commandNo = CMD_RADIO_SETUP,
.status = 0x0000,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = TRIG_NOW,
@ -133,7 +133,7 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup =
rfc_CMD_FS_t rf_cmd_ieee_fs =
{
.commandNo = CMD_FS,
.status = 0x0000,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = TRIG_NOW,
@ -142,8 +142,8 @@ rfc_CMD_FS_t rf_cmd_ieee_fs =
.startTrigger.pastTrig = 0x0,
.condition.rule = COND_NEVER,
.condition.nSkip = 0x0,
.frequency = 0x0965,
.fractFreq = 0x0000,
.frequency = 0x0965, /* set by driver */
.fractFreq = 0x0000, /* set by driver */
.synthConf.bTxMode = 0x1,
.synthConf.refFreq = 0x0,
.__dummy0 = 0x00,
@ -156,8 +156,8 @@ rfc_CMD_FS_t rf_cmd_ieee_fs =
// IEEE 802.15.4 Transmit Command
rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx =
{
.commandNo = CMD_IEEE_RX,
.status = 0x0000,
.commandNo = CMD_IEEE_TX,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = TRIG_NOW,
@ -178,25 +178,25 @@ rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx =
// IEEE 802.15.4 Receive Command
rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx =
{
.commandNo = 0x2801,
.status = 0x0000,
.commandNo = CMD_IEEE_RX,
.status = IDLE,
.pNextOp = 0,
.startTime = 0x00000000,
.startTrigger.triggerType = 0x0,
.startTrigger.triggerType = TRIG_NOW,
.startTrigger.bEnaCmd = 0x0,
.startTrigger.triggerNo = 0x0,
.startTrigger.pastTrig = 0x0,
.condition.rule = 0x1,
.condition.rule = COND_NEVER,
.condition.nSkip = 0x0,
.channel = 0x00,
.rxConfig.bAutoFlushCrc = 0x0,
.channel = 0x00, /* set by driver */
.rxConfig.bAutoFlushCrc = 0x1,
.rxConfig.bAutoFlushIgn = 0x0,
.rxConfig.bIncludePhyHdr = 0x0,
.rxConfig.bIncludeCrc = 0x0,
.rxConfig.bIncludeCrc = 0x1,
.rxConfig.bAppendRssi = 0x1,
.rxConfig.bAppendCorrCrc = 0x1,
.rxConfig.bAppendSrcInd = 0x0,
.rxConfig.bAppendTimestamp = 0x0,
.rxConfig.bAppendTimestamp = 0x1,
.pRxQ = 0, /* set by driver */
.pOutput = 0, /* set by driver */
.frameFiltOpt.frameFiltEn = 0x0, /* set by driver */

View File

@ -34,8 +34,8 @@
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h
#include DeviceFamily_constructPath(driverlib/rf_ieee_mailbox.h))
#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h)
#include DeviceFamily_constructPath(driverlib/rf_ieee_mailbox.h)
#include <ti/drivers/rf/RF.h>
/*---------------------------------------------------------------------------*/

View File

@ -59,8 +59,8 @@
* Override button symbols from dev/button-sensor.h, for the examples that
* include it
*/
#define btn1_sensor button_left_sensor
#define btn2_sensor button_right_sensor
#define button_left_sensor btn1_sensor
#define button_right_sensor btn2_sensor
/** @} */
/*---------------------------------------------------------------------------*/
/* Platform-specific define to signify sensor reading failure */

View File

@ -41,23 +41,24 @@
#include <lib/sensors.h>
/*---------------------------------------------------------------------------*/
#include <Board.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/Power.h>
/*---------------------------------------------------------------------------*/
#include <stdint.h>
#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 */
#define BTN1_GPIO Board_GPIO_BTN1
#define BTN2_GPIO Board_GPIO_BTN2
#define BTN1_PIN Board_PIN_BTN1
#define BTN2_PIN Board_PIN_BTN2
/*---------------------------------------------------------------------------*/
#ifdef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
# define BUTTON_SENSOR_ENABLE_SHUTDOWN BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
#else
# define BUTTON_SENSOR_ENABLE_SHUTDOWN 1
# define BUTTON_SENSOR_ENABLE_SHUTDOWN 0
#endif
/*---------------------------------------------------------------------------*/
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 5)
@ -68,56 +69,92 @@ typedef struct {
clock_time_t duration;
} BtnTimer;
/*---------------------------------------------------------------------------*/
static BtnTimer g_btn1Timer;
static BtnTimer g_btn2Timer;
static BtnTimer btn1_timer;
static BtnTimer btn2_timer;
/*---------------------------------------------------------------------------*/
static const PIN_Config btn_pin_table[] = {
BTN1_PIN | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
BTN2_PIN | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
PIN_TERMINATE
};
static PIN_State pin_state;
static PIN_Handle pin_handle;
/*---------------------------------------------------------------------------*/
static void
button_press_cb(uint8_t index, BtnTimer *btnTimer, const struct sensors_sensor *btnSensor)
button_press_cb(PIN_Handle handle, PIN_Id pin_id)
{
if (!timer_expired(&btnTimer->debounce)) {
#ifdef BUTTON_SENSOR_ENABLE_SHUTDOWN
if (pin_id == BTN2_PIN) {
Power_shutdown(Power_ENTERING_SHUTDOWN, 0);
return;
}
#endif
BtnTimer *btn_timer = NULL;
const struct sensors_sensor *btn_sensor = NULL;
switch (pin_id) {
case BTN1_PIN: btn_timer = &btn1_timer;
btn_sensor = &btn1_sensor; break;
case BTN2_PIN: btn_timer = &btn2_timer;
btn_sensor = &btn2_sensor; break;
default: return; /* No matching PIN */
}
if (!timer_expired(&btn_timer->debounce)) {
return;
}
timer_set(&btnTimer->debounce, DEBOUNCE_DURATION);
timer_set(&btn_timer->debounce, DEBOUNCE_DURATION);
// Start press duration counter on press (falling), notify on release (rising)
if (GPIO_read(index) == 0) {
btnTimer->start = clock_time();
btnTimer->duration = 0;
if (PIN_getInputValue(pin_id) == 0) {
btn_timer->start = clock_time();
btn_timer->duration = 0;
} else {
btnTimer->duration = clock_time() - btnTimer->start;
sensors_changed(btnSensor);
btn_timer->duration = clock_time() - btn_timer->start;
sensors_changed(btn_sensor);
}
}
/*---------------------------------------------------------------------------*/
static int
button_value(int type, uint8_t index, BtnTimer *btnTimer)
button_value(int type, uint8_t pin, BtnTimer *btn_timer)
{
if (type == BUTTON_SENSOR_VALUE_STATE) {
return (GPIO_read(index) == 0)
return (PIN_getInputValue(pin) == 0)
? BUTTON_SENSOR_VALUE_PRESSED
: BUTTON_SENSOR_VALUE_RELEASED;
} else if (type == BUTTON_SENSOR_VALUE_DURATION) {
return (int)btnTimer->duration;
return (int)btn_timer->duration;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
button_config(int type, int value, uint8_t index, GPIO_CallbackFxn callback)
button_config(int type, int value, uint8_t pin)
{
switch (type) {
case SENSORS_HW_INIT:
GPIO_clearInt(index);
GPIO_setCallback(index, callback);
// Open PIN handle
if (pin_handle) {
return 1;
}
pin_handle = PIN_open(&pin_state, btn_pin_table);
if (!pin_handle) {
return 0;
}
// Register button callback function
PIN_registerIntCb(pin_handle, button_press_cb);
break;
case SENSORS_ACTIVE:
if (value) {
GPIO_clearInt(index);
GPIO_enableInt(index);
// Enable interrupts on both edges
PIN_setInterrupt(pin_handle, pin | PIN_IRQ_BOTHEDGES);
} else {
GPIO_disableInt(index);
// Disable pin interrupts
PIN_setInterrupt(pin_handle, pin | PIN_IRQ_DIS);
}
break;
}
@ -126,70 +163,53 @@ button_config(int type, int value, uint8_t index, GPIO_CallbackFxn callback)
}
/*---------------------------------------------------------------------------*/
static int
button_status(int type, uint8_t index)
button_status(int type, uint8_t pin)
{
switch(type) {
case SENSORS_ACTIVE: /* fallthrough */
case SENSORS_READY: {
GPIO_PinConfig pinCfg = 0;
GPIO_getConfig(index, &pinCfg);
return (pinCfg & GPIO_CFG_IN_INT_NONE) == 0;
PIN_Config pin_cfg = PIN_getConfig(pin);
return (pin_cfg & PIN_BM_IRQ) == PIN_IRQ_DIS;
}
default: break;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void
btn1_press_cb(unsigned char unusued)
{
button_press_cb(BTN1_GPIO, &g_btn1Timer, &btn1_sensor);
}
/*---------------------------------------------------------------------------*/
static int
btn1_value(int type)
{
return button_value(type, BTN1_GPIO, &g_btn1Timer);
return button_value(type, BTN1_PIN, &btn1_timer);
}
/*---------------------------------------------------------------------------*/
static int
btn1_config(int type, int value)
{
return button_config(type, value, BTN1_GPIO, btn1_press_cb);
return button_config(type, value, BTN1_PIN);
}
/*---------------------------------------------------------------------------*/
static int
btn1_status(int type)
{
return button_status(type, BTN1_GPIO);
}
/*---------------------------------------------------------------------------*/
static void
btn2_press_cb(unsigned char unusued)
{
if (BUTTON_SENSOR_ENABLE_SHUTDOWN) {
Power_shutdown(Power_ENTERING_SHUTDOWN, 0);
return;
}
button_press_cb(BTN2_GPIO, &g_btn2Timer, &btn2_sensor);
return button_status(type, BTN1_PIN);
}
/*---------------------------------------------------------------------------*/
static int
btn2_value(int type)
{
return button_value(type, BTN2_GPIO, &g_btn2Timer);
return button_value(type, BTN2_PIN, &btn2_timer);
}
/*---------------------------------------------------------------------------*/
static int
btn2_config(int type, int value)
{
return button_config(type, value, BTN2_GPIO, btn2_press_cb);
return button_config(type, value, BTN2_PIN);
}
/*---------------------------------------------------------------------------*/
static int
btn2_status(int type)
{
return button_status(type, BTN1_GPIO);
return button_status(type, BTN2_PIN);
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(btn1_sensor, BUTTON_SENSOR, btn1_value, btn1_config, btn1_status);

View File

@ -43,12 +43,8 @@
/*---------------------------------------------------------------------------*/
/* Exports a global symbol to be used by the sensor API */
SENSORS(
#ifdef BUTTON_SENSOR_ARCH_BTN1
&button_sensor,
#endif
#ifdef BUTTON_SENSOR_ARCH_BTN2
&button_sensor2,
#endif
&btn1_sensor,
&btn2_sensor,
NULL
);
/*---------------------------------------------------------------------------*/

View File

@ -145,6 +145,10 @@
#define ABS(n) (((n) < 0) ? -(n) : (n))
#endif
#ifndef CLAMP
#define CLAMP(v, vmin, vmax) (MAX(MIN(v, vmax), vmin))
#endif
#define CC_CONCAT2(s1, s2) s1##s2
/**