50 #include <dev/button-sensor.h>
56 #define button_read PORTDbits.RD5
58 const struct sensors_sensor button_sensor;
60 static struct timer debouncetimer;
62 static int status(
int type);
64 static uint8_t sensor_status = 0;
66 ISR(_CHANGE_NOTICE_VECTOR)
68 ENERGEST_ON(ENERGEST_TYPE_IRQ);
72 sensors_changed(&button_sensor);
75 IFS1CLR = _IFS1_CNIF_MASK;
78 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
85 sensors_changed(&button_sensor);
95 configure(
int type,
int value)
100 if(!status(SENSORS_ACTIVE)) {
103 TRISDbits.TRISD5 = 1;
106 CNCONSET = 1 << _CNCON_ON_POSITION | 1 << _CNCON_SIDL_POSITION;
107 CNEN = 1 << _CNEN_CNEN14_POSITION;
108 CNPUE = 1 << _CNPUE_CNPUE14_POSITION;
110 IEC1CLR = _IEC1_CNIE_MASK;
111 IFS1CLR = _IFS1_CNIF_MASK;
113 IPC6CLR = _IPC6_CNIP_MASK;
114 IPC6SET = 6 << _IPC6_CNIP_POSITION;
116 IEC1SET = 1 << _IEC1_CNIE_POSITION;
132 return sensor_status;
135 SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, configure, status);
INTERRUPT interface for PIC32MX (pic32mx795f512l)
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
int timer_expired(struct timer *t)
Check if a timer has expired.
#define CLOCK_SECOND
A second, measured in system clock time.