00001
00092 #include "stdio.h"
00093 #include "board.h"
00094 #include "print_funcs.h"
00095 #include "gpio.h"
00096 #include "pm.h"
00097 #include "intc.h"
00098 #include "lis3l06al.h"
00099 #if __GNUC__
00100 # include "nlao_cpu.h"
00101 # include "nlao_usart.h"
00102 #endif
00103
00106
00107 #define ACC_TRIG_X0 (int) ( ACC_ZERO_X - SIN15 * ACC_1G )
00108 #define ACC_TRIG_X1 (int) ( ACC_ZERO_X + SIN15 * ACC_1G )
00109 #define ACC_TRIG_Y0 (int) ( ACC_ZERO_Y - SIN15 * ACC_1G )
00110 #define ACC_TRIG_Y1 (int) ( ACC_ZERO_Y + SIN15 * ACC_1G )
00111 #define ACC_TRIG_Z_TOP (int) ( ACC_ZERO_Z - SIN75 * ACC_1G )
00112 #define ACC_TRIG_Z_BOT (int) ( ACC_ZERO_Z + SIN60 * ACC_1G )
00114
00115
00117 void print_mouse()
00118 {
00119 print_dbg("HEX Value for Channel x : 0x");
00120 print_dbg_hex(acc_get_m_x());
00121 if ( is_acc_left() ) { print_dbg(" < 0x") ; print_dbg_hex(ACC_TRIG_X0) ; print_dbg(" ... left") ; }
00122 else if ( is_acc_right() ) { print_dbg(" > 0x") ; print_dbg_hex(ACC_TRIG_X1) ; print_dbg(" ... right") ; }
00123 else { print_dbg(" = 0x") ; print_dbg_hex(ACC_ZERO_X) ; }
00124 print_dbg("\r\n");
00125 print_dbg("HEX Value for Channel y : 0x");
00126 print_dbg_hex(acc_get_m_y());
00127 if ( is_acc_up() ) { print_dbg(" < 0x") ; print_dbg_hex(ACC_TRIG_Y0) ; print_dbg(" ... up") ; }
00128 else if ( is_acc_down() ) { print_dbg(" > 0x") ; print_dbg_hex(ACC_TRIG_Y1) ; print_dbg(" ... down") ; }
00129 else { print_dbg(" = 0x") ; print_dbg_hex(ACC_ZERO_Y) ; }
00130 print_dbg("\r\n");
00131 print_dbg("HEX Value for Channel z : 0x");
00132 print_dbg_hex(acc_get_m_z());
00133 if ( is_acc_topdown() ) { print_dbg(" ... TOPDOWN") ; }
00134 if ( is_acc_meuh(1) ) { print_dbg(" ... MEUH !!") ; }
00135 print_dbg("\r\n\r\n");
00136 }
00137
00138
00141 void print_angles()
00142 {
00143 signed int res;
00144 static xyz_t angle ;
00145
00146
00147
00148 if( 0!=(res=is_acc_abs_angle_x(60)) ) angle.x = 60;
00149 else if( 0!=(res=is_acc_abs_angle_x(30)) ) angle.x = 30;
00150 else angle.x = 0 ;
00151
00152 if ( angle.x > 0 )
00153 {
00154 if( res>0 ) print_dbg("LEFT ") ;
00155 else if( res<0 ) print_dbg("RIGHT ") ;
00156
00157 print_dbg_ulong(angle.x) ;
00158 print_dbg("\r\n") ;
00159 }
00160
00161 if( 0!=(res=is_acc_abs_angle_y(60)) ) angle.y = 60;
00162 else if( 0!=(res=is_acc_abs_angle_y(30)) ) angle.y = 30;
00163 else angle.y = 0 ;
00164
00165 if ( angle.y > 0 )
00166 {
00167 if( res>0 ) print_dbg("DOWN ") ;
00168 else if( res<0 ) print_dbg("UP ") ;
00169
00170 print_dbg_ulong(angle.y) ;
00171 print_dbg("\r\n") ;
00172 }
00173 }
00174
00175
00176
00180 void print_move()
00181 {
00182 volatile U32 i;
00183 print_dbg("... T I L T !!!") ;
00184 print_dbg("\r\n");
00185 for ( i=0 ; i < 1000000 ; i++);
00186 }
00187
00188
00189
00190 volatile char meuh_en = 0 ;
00191 volatile char meuh_stop = 1 ;
00192
00193
00194
00195 #ifndef FREERTOS_USED
00196
00197 # if __GNUC__
00198
00210 int _init_startup(void)
00211 {
00212
00213 extern void _evba;
00214
00215
00216 Set_system_register(AVR32_EVBA, (int)&_evba);
00217
00218
00219 Enable_global_exception();
00220
00221
00222 INTC_init_interrupts();
00223
00224
00225 init_dbg_rs232(FOSC0);
00226
00227
00228 set_cpu_hz(FOSC0);
00229
00230
00231 set_usart_base( ( void * ) DBG_USART );
00232
00233
00234 return 1;
00235 }
00236
00237 # elif __ICCAVR32__
00238
00242 int __low_level_init(void)
00243 {
00244
00245 Enable_global_exception();
00246
00247
00248 INTC_init_interrupts();
00249
00250
00251 init_dbg_rs232(FOSC0);
00252
00253
00254 extern volatile avr32_usart_t *volatile stdio_usart_base;
00255 stdio_usart_base = DBG_USART;
00256
00257
00258 return 1;
00259 }
00260 # endif
00261 #endif
00262
00266 int main(void)
00267 {
00268 volatile unsigned long i;
00269
00270
00271 pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00272
00273 acc_init();
00274
00275
00276 for (;;)
00277 {
00278
00279 for ( i=0 ; i < 50000 ; i++);
00280
00281
00282 print_dbg("\x1B[2J\x1B[H\r\n\r\nAccelerometer Example\r\n\r\n");
00283
00284
00285 acc_update();
00286
00287
00288
00289 if ( is_acc_slow() )
00290 {
00291 print_mouse() ;
00292 print_angles() ;
00293 }
00294 else
00295 print_move() ;
00296
00297
00298
00299
00300 meuh_en = is_acc_meuh( meuh_stop ) ;
00301 }
00302 }