Commit f8dd751e authored by Projects's avatar Projects

magnetometer & compass: Interrupt events are supported (*not tested yet*).

parent 7ea85f2b
......@@ -32,7 +32,7 @@
*/
enum event_type {
BUTTON_PRESSED,
SENSOR,
SENSOR_INT,
RTC_TICK
};
......@@ -46,6 +46,15 @@ enum button_name {
BUT_BR // bottom right
};
/**
* Sensor interrupts.
*/
enum sensor_type {
// LIGHT, // disabled for the time being
MAGNETOMETER,
ACCELEROMETER
};
/**
* Structure describing events received by applications.
*/
......@@ -56,6 +65,7 @@ struct event {
///> Data dependent on the event type
union {
enum button_name button;
enum sensor_type sensor;
} data;
};
......
......@@ -40,13 +40,45 @@ static portBASE_TYPE gpio_irq_dispatcher(uint32_t flags)
// Fill the event data
struct event evt;
evt.type = BUTTON_PRESSED;
switch(flags)
{
case 0x01: evt.data.button = BUT_TR; break;
case 0x40: evt.data.button = BUT_BL; break;
case 0x80: evt.data.button = BUT_TL; break;
case 0x0100: evt.data.button = BUT_BR; break;
// Buttons
case (1 << 0): // PA0
evt.type = BUTTON_PRESSED;
evt.data.button = BUT_TR;
break;
case (1 << 6): // PC6
evt.type = BUTTON_PRESSED;
evt.data.button = BUT_BL;
break;
case (1 << 7): // PC7
evt.type = BUTTON_PRESSED;
evt.data.button = BUT_TL;
break;
case (1 << 8): // PA8
evt.type = BUTTON_PRESSED;
evt.data.button = BUT_BR;
break;
// Sensors
// There is a conflict with the bottom-left button interrupt
// case (1 << 6): // PA6
// evt.type = SENSOR_INT;
// evt.data.sensor = LIGHT;
// break;
case (1 << 10): // PA10
evt.type = SENSOR_INT;
evt.data.sensor = MAGNETOMETER;
break;
case (1 << 5): // PD5
evt.type = SENSOR_INT;
evt.data.sensor = ACCELEROMETER;
break;
// Unexpected event, do not send it
default: return xHigherPriorityTaskWoken;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment