00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00052 #include <stdio.h>
00053 #include <io.h>
00054
00055 #include <cfg/arch.h>
00056 #include <cfg/dev.h>
00057 #include <dev/board.h>
00058 #include <sys/timer.h>
00059 #include <sys/event.h>
00060 #include <sys/thread.h>
00061
00062 #include <dev/gpio.h>
00063
00064 #include <dev/keys.h>
00065 #include <dev/led.h>
00066
00067
00068 HANDLE led1, led2, led3, led4;
00069
00070 HANDLE keyUp, keyDn, keyLt, keyRt, keyMi;
00071
00072 HANDLE keyT1w, keyT2w;
00073
00082 THREAD( Key1Thread, arg)
00083 {
00084 NutThreadSetPriority(60);
00085 for(;;) {
00086 NutEventWait( &keyT1w, NUT_WAIT_INFINITE);
00087 if( NutGetKeyState( keyMi) & KEY_PENDING) {
00088 printf("KEY ENTER pressed\n");
00089 NutSetLed( led2, LED_OFF, 0, 0);
00090 NutSetLed( led3, LED_OFF, 0, 0);
00091 NutSetLed( led4, LED_OFF, 0, 0);
00092 }
00093 if( NutGetKeyState( keyDn) & KEY_PENDING) {
00094 printf("\nKEY DOWN pressed\n");
00095 NutSetLed( led2, LED_BLINK, 100, 900);
00096 NutSetLed( led3, LED_BLINK, 500, 500);
00097 NutSetLed( led4, LED_BLINK, 900, 100);
00098 }
00099 }
00100 }
00101
00110 THREAD( Key2Thread, arg)
00111 {
00112 NutThreadSetPriority(60);
00113 for(;;) {
00114 NutEventWait( &keyT2w, NUT_WAIT_INFINITE);
00115 if( NutGetKeyState( keyLt) & KEY_PENDING) {
00116 printf("\nKEY LEFT pressed\n");
00117 NutSetLed( led2, LED_ON, 200, 0);
00118 NutSetLed( led4, LED_OFF, 0, 0);
00119 }
00120 if( NutGetKeyState( keyRt) & KEY_PENDING) {
00121 printf("\nKEY RIGHT pressed\n");
00122 NutSetLed( led2, LED_OFF, 0, 0);
00123 NutSetLed( led4, LED_ON, 200, 0);
00124 }
00125 if( NutGetKeyState( keyUp) & KEY_PENDING) {
00126 printf("\nKEY UP pressed\n");
00127 NutSetLed( led3, LED_FLIP, 0, 0);
00128 }
00129 }
00130 }
00131
00132
00133
00134
00135
00136 int main(void)
00137 {
00138 u_long baud = 115200;
00139
00140
00141
00142
00143 NutRegisterDevice(&DEV_DEBUG, 0, 0);
00144 freopen(DEV_DEBUG_NAME, "w", stdout);
00145 _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00146
00147 puts("\n*** LED and key Test ***\n");
00148
00149
00150 NutRegisterLed( &led1, NUTGPIO_PORTB, 19);
00151 NutSetLed( led1, LED_BLINK, 100, 900);
00152
00153
00154 NutRegisterLed( &led2, NUTGPIO_PORTB, 20);
00155 NutSetLed( led2, LED_ON, 200, 0);
00156
00157
00158 NutRegisterLed( &led3, NUTGPIO_PORTB, 21);
00159 NutSetLed( led3, LED_ON, 200, 0);
00160
00161
00162 NutRegisterLed( &led4, NUTGPIO_PORTB, 22);
00163 NutSetLed( led4, LED_ON, 200, 0);
00164
00165
00166
00167
00168
00169
00170
00171 NutRegisterKey( &keyMi, &keyT1w, NUTGPIO_PORTA, 25, KEY_ACTION_SHORT, 1000);
00172 NutRegisterKey( &keyDn, &keyT1w, NUTGPIO_PORTA, 22, KEY_ACTION_HOLD, 2000);
00173
00174
00175
00176
00177
00178 NutRegisterKey( &keyLt, &keyT2w, NUTGPIO_PORTA, 23, KEY_ACTION_UP, 0);
00179 NutRegisterKey( &keyRt, &keyT2w, NUTGPIO_PORTA, 24, KEY_ACTION_DOWN, 0);
00180 NutRegisterKey( &keyUp, &keyT2w, NUTGPIO_PORTA, 21, KEY_ACTION_DOWN, 0);
00181
00182
00183 NutThreadCreate("k1", Key1Thread, NULL, 256);
00184 NutThreadCreate("k2", Key2Thread, NULL, 256);
00185
00186
00187
00188
00189 for (;;) {
00190 putchar('.');
00191 NutSleep(2000);
00192 }
00193 return 0;
00194 }