4 * main.c - main programm
6 * This file is released under the GNU General Public License. Refer
7 * to the COPYING file distributed with this package.
9 * (c) 2007 Carsten Presser cpresser AT fsing.uni-sb.de
12 /** I N C L U D E S **********************************************************/
16 #include "usb_compile_time_validation.h"
26 /** P R I V A T E P R O T O T Y P E S ***************************************/
29 /** V E C T O R R E M A P P I N G *******************************************/
30 extern void _startup (void); // See c018i.c in your C18 compiler dir
31 #pragma code _RESET_INTERRUPT_VECTOR = 0x000800
34 _asm goto _startup _endasm
38 /** C O D E ********************************************************/
45 mInitializeUSBDriver();
54 if (gg_ioflags & FLAG_I2C)
57 if (! (gg_ioflags & FLAG_KEY)) ReadClock();
59 gg_ioflags &= (FLAG_I2C ^ 255); // delete i2c-flag
63 // perhaps we need to power up?
64 if (((gg_ioflags & FLAG_IR) && (gg_ir == RC5_KEY_POWER)) || (gg_ioflags & FLAG_ALARM))
69 gg_ioflags |= FLAG_POWER;
70 // TODO: echo starting command??
71 gg_ioflags &= (FLAG_IR ^ 255);
75 // check for input, process it and send our answers...
76 if((usb_device_state >= CONFIGURED_STATE)&&(UCONbits.SUSPND!=1))
81 // if in managed mode...
82 if (gg_mode == MODE_MANAGED)
84 if((usb_device_state >= CONFIGURED_STATE)&&(UCONbits.SUSPND!=1))
86 // wooo wooo woooo. now zoidberg is the popular one!
87 if (gg_ioflags & FLAG_KEY)
89 comm_send_ir(RC5_FRONT_ADDRESS, gg_keys);
90 gg_ioflags &= (FLAG_KEY ^ 255);
92 if (gg_ioflags & FLAG_IR)
94 comm_send_ir(gg_ir_address, gg_ir);
95 gg_ioflags &= (FLAG_IR ^ 255);
100 gg_mode = MODE_UNMANAGED;
105 // we are NOT in usb-mode...
106 if (gg_ioflags & FLAG_KEY)
111 if (gg_pwm1dc <= 250) gg_pwm1dc += 5;
112 SetDCPWM1((int)gg_pwm1dc << 2);
116 if (gg_pwm1dc >= 5) gg_pwm1dc -= 5;
117 SetDCPWM1((int)gg_pwm1dc << 2);
123 gg_ioflags &= (FLAG_KEY ^ 255);
126 // always display some stuff...
127 if (gg_ioflags & FLAG_COUNTER)
131 /* lcd_WriteData(0x00); // byte1
132 lcd_WriteData(0x08); // byte2
133 lcd_WriteCommand(0x24); //set!
136 gg_ioflags &= (FLAG_COUNTER ^ 255);
141 } // end of main loop
152 USBCheckBusStatus(); // Must use polling method
153 if(UCFGbits.UTEYE!=1)
154 USBDriverService(); // Interrupt or polling method
156 #if defined(USB_USE_CDC)