]> git.karo-electronics.de Git - oswald.git/blobdiff - metawatch/mw_main.c
Make accelerometer work, interrup driven tilt change mode
[oswald.git] / metawatch / mw_main.c
index 89b014ebe748be909e475509957392796cf23304..4f8ee90b01e77ea6930ad91601becdbbdabee447 100644 (file)
@@ -10,6 +10,7 @@
 #include "mw_bt.h"
 #include "mw_adc.h"
 #include "mw_bt.h"
+#include "mw_acc.h"
 #include "bt_hci.h"
 #include "bt_l2cap.h"
 
@@ -18,7 +19,7 @@
 
 #include "bluetooth_init_cc256x.h"
 
-unsigned int _event_src = 0;
+uint16_t _event_src = 0;
 
 
 static void set16mhz(void)
@@ -111,7 +112,7 @@ static void setup_pins(void)
        DISABLE_LCD_LED();              // frontlight
        CONFIG_DEBUG_PINS();
        CONFIG_ACCELEROMETER_PINS();
-       // DISABLE_ACCELEROMETER_POWER(); // there is no accel. power switching!
+       DISABLE_ACCELEROMETER_POWER(); // starts from config 5 and later
 
        HARDWARE_CFG_SENSE_INIT();
 
@@ -324,7 +325,19 @@ static void handle_uart_rx_event(void)
 
        if (debug_uart_rx_char(&c)) {
                debug_uart_tx_char(c);
-               if (c == 'b') {
+               if (c == 'a') {
+                       debug_uart_tx("\nenabling ACC\n");
+                       mw_acc_enable();
+               } else if (c == 'A') {
+                       debug_uart_tx("\ndisabling ACC\n");
+                       mw_acc_disable();
+               } else if (c == 'r') {
+                       int16_t x,y,z;
+                       debug_uart_tx("\nread ACC: ");
+                       mw_acc_read(&x, &y, &z);
+                       snprintf(tstr, 64, "x:%d y:%d z:%d\n", x,y,z);
+                       debug_uart_tx(tstr);
+               } else if (c == 'b') {
                        debug_uart_tx("\nenabling BT\n");
                        mw_enable_bt();
                } else if (c == 'B') {
@@ -484,6 +497,9 @@ uint8_t handle_event(void)
                } else if (_event_src & TIMER_100MS_EVENT) {
                        _event_src &= ~TIMER_100MS_EVENT;
                        oswald_centisecond_tick();
+               } else if (_event_src & ACCEL_EVENT) {
+                       _event_src &= ~ACCEL_EVENT;
+                       mw_acc_handle_irq();
                } else {
 #if defined MW_DEVBOARD_V2
                        snprintf(tstr, 64, "unhandled event in 0x%04x\n", _event_src);
@@ -504,6 +520,26 @@ __interrupt void BUTTON_ISR (void)
        LPM3_EXIT;
 }
 
+#pragma vector=PORT1_VECTOR
+__interrupt void PORT1_GPIO_ISR (void)
+{
+       if (P1IFG & BT_IO_CTS) {
+               P1IFG &= ~BT_IO_CTS;
+
+               debug_uart_tx("BT CTS irq\n");
+               bt_hci_ehcill_wake();
+
+               LPM3_EXIT;
+       };
+       if (P1IFG & ACCELEROMETER_INT_PIN) {
+               P1IFG &= ~ACCELEROMETER_INT_PIN;
+               // debug_uart_tx("ACC irq\n");
+               _event_src |= ACCEL_EVENT;
+               LPM3_EXIT;
+       }
+}
+
+
 #if 0
 #pragma vector=NOVECTOR
 __interrupt void UNEXP_ISR (void)