Commit 0bb54a12 authored by Projects's avatar Projects

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

parent 6b742351
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
*/ */
enum event_type { enum event_type {
BUTTON_PRESSED, BUTTON_PRESSED,
SENSOR, SENSOR_INT,
RTC_TICK RTC_TICK
}; };
...@@ -46,6 +46,15 @@ enum button_name { ...@@ -46,6 +46,15 @@ enum button_name {
BUT_BR // bottom right BUT_BR // bottom right
}; };
/**
* Sensor interrupts.
*/
enum sensor_type {
// LIGHT, // disabled for the time being
MAGNETOMETER,
ACCELEROMETER
};
/** /**
* Structure describing events received by applications. * Structure describing events received by applications.
*/ */
...@@ -56,6 +65,7 @@ struct event { ...@@ -56,6 +65,7 @@ struct event {
///> Data dependent on the event type ///> Data dependent on the event type
union { union {
enum button_name button; enum button_name button;
enum sensor_type sensor;
} data; } data;
}; };
......
...@@ -40,13 +40,45 @@ static portBASE_TYPE gpio_irq_dispatcher(uint32_t flags) ...@@ -40,13 +40,45 @@ static portBASE_TYPE gpio_irq_dispatcher(uint32_t flags)
// Fill the event data // Fill the event data
struct event evt; struct event evt;
evt.type = BUTTON_PRESSED;
switch(flags) switch(flags)
{ {
case 0x01: evt.data.button = BUT_TR; break; // Buttons
case 0x40: evt.data.button = BUT_BL; break; case (1 << 0): // PA0
case 0x80: evt.data.button = BUT_TL; break; evt.type = BUTTON_PRESSED;
case 0x0100: evt.data.button = BUT_BR; break; 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 // Unexpected event, do not send it
default: return xHigherPriorityTaskWoken; 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