You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					112 lines
				
				2.4 KiB
			
		
		
			
		
	
	
					112 lines
				
				2.4 KiB
			|   
											12 years ago
										 | #include <avr/io.h>
 | ||
|  | #include <avr/power.h>
 | ||
|  | #include <avr/wdt.h>
 | ||
|  | #include "lufa.h"
 | ||
|  | #include "print.h"
 | ||
|  | #include "sendchar.h"
 | ||
|   
											12 years ago
										 | #include "rn42.h"
 | ||
|   
											11 years ago
										 | #include "rn42_task.h"
 | ||
|   
											12 years ago
										 | #include "serial.h"
 | ||
|  | #include "keyboard.h"
 | ||
|  | #include "keycode.h"
 | ||
|  | #include "action.h"
 | ||
|  | #include "action_util.h"
 | ||
|  | #include "wait.h"
 | ||
|   
											11 years ago
										 | #include "suart.h"
 | ||
|   
											11 years ago
										 | #include "suspend.h"
 | ||
|   
											12 years ago
										 | 
 | ||
|   
											11 years ago
										 | static int8_t sendchar_func(uint8_t c) | ||
|  | { | ||
|  |     xmit(c);        // SUART
 | ||
|   
											11 years ago
										 |     sendchar(c);    // LUFA
 | ||
|   
											11 years ago
										 |     return 0; | ||
|   
											11 years ago
										 | } | ||
|  | 
 | ||
|   
											12 years ago
										 | static void SetupHardware(void) | ||
|  | { | ||
|  |     /* Disable watchdog if enabled by bootloader/fuses */ | ||
|  |     MCUSR &= ~(1 << WDRF); | ||
|  |     wdt_disable(); | ||
|  | 
 | ||
|  |     /* Disable clock division */ | ||
|  |     clock_prescale_set(clock_div_1); | ||
|  | 
 | ||
|  |     // Leonardo needs. Without this USB device is not recognized.
 | ||
|  |     USB_Disable(); | ||
|  | 
 | ||
|  |     USB_Init(); | ||
|  | 
 | ||
|  |     // for Console_Task
 | ||
|  |     USB_Device_EnableSOFEvents(); | ||
|   
											11 years ago
										 |     print_set_sendchar(sendchar_func); | ||
|  | 
 | ||
|  |     // SUART PD0:output, PD1:input
 | ||
|  |     DDRD |= (1<<0); | ||
|  |     PORTD |= (1<<0); | ||
|  |     DDRD &= ~(1<<1); | ||
|  |     PORTD |= (1<<1); | ||
|   
											12 years ago
										 | } | ||
|  | 
 | ||
|  | int main(void)  __attribute__ ((weak)); | ||
|  | int main(void) | ||
|  | { | ||
|  |     SetupHardware(); | ||
|  |     sei(); | ||
|  | 
 | ||
|   
											12 years ago
										 |     /* wait for USB startup to get ready for debug output */ | ||
|  |     uint8_t timeout = 255;  // timeout when USB is not available(Bluetooth)
 | ||
|  |     while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) { | ||
|  |         wait_ms(4); | ||
|   
											12 years ago
										 | #if defined(INTERRUPT_CONTROL_ENDPOINT)
 | ||
|  |         ; | ||
|  | #else
 | ||
|  |         USB_USBTask(); | ||
|  | #endif
 | ||
|  |     } | ||
|   
											11 years ago
										 |     print("\nUSB init\n"); | ||
|   
											12 years ago
										 | 
 | ||
|   
											12 years ago
										 |     rn42_init(); | ||
|   
											11 years ago
										 |     rn42_task_init(); | ||
|   
											12 years ago
										 |     print("RN-42 init\n"); | ||
|  | 
 | ||
|   
											12 years ago
										 |     /* init modules */ | ||
|  |     keyboard_init(); | ||
|   
											12 years ago
										 | 
 | ||
|   
											11 years ago
										 |     if (!rn42_rts()) { | ||
|   
											12 years ago
										 |         host_set_driver(&rn42_driver); | ||
|  |     } else { | ||
|  |         host_set_driver(&lufa_driver); | ||
|  |     } | ||
|  | 
 | ||
|   
											12 years ago
										 | #ifdef SLEEP_LED_ENABLE
 | ||
|  |     sleep_led_init(); | ||
|  | #endif
 | ||
|  | 
 | ||
|   
											11 years ago
										 |     print("Keyboard start\n"); | ||
|   
											12 years ago
										 |     while (1) { | ||
|   
											11 years ago
										 |         while (rn42_rts() && // RN42 is off
 | ||
|  |                 USB_DeviceState == DEVICE_STATE_Suspended) { | ||
|   
											11 years ago
										 |             print("[s]"); | ||
|   
											11 years ago
										 |             matrix_power_down(); | ||
|  |             suspend_power_down(); | ||
|  |             suspend_power_down(); | ||
|  |             suspend_power_down(); | ||
|  |             suspend_power_down(); | ||
|  |             suspend_power_down(); | ||
|  |             suspend_power_down(); | ||
|   
											11 years ago
										 |             suspend_power_down(); | ||
|   
											12 years ago
										 |             if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { | ||
|  |                     USB_Device_SendRemoteWakeup(); | ||
|  |             } | ||
|  |         } | ||
|  | 
 | ||
|  |         keyboard_task(); | ||
|  | 
 | ||
|  | #if !defined(INTERRUPT_CONTROL_ENDPOINT)
 | ||
|  |         USB_USBTask(); | ||
|  | #endif
 | ||
|   
											12 years ago
										 | 
 | ||
|   
											11 years ago
										 |         rn42_task(); | ||
|   
											12 years ago
										 |     } | ||
|  | } |