/*---------------------------------------------------------------------------* Project: Revolution Low-Level USB keyboard demo File: kbdLowLevel.c Copyright 2007 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: kbdLowLevel.c,v $ Revision 1.8 2007/10/08 18:44:55 henrch per API change Revision 1.7 2007/10/03 22:48:01 henrch changed to use new KBD / HID lib Revision 1.6 2007/07/13 23:37:18 carlmu Changed from TrySetLeds to KBDSetLedsRetry. Revision 1.5 2007/06/21 22:46:50 carlmu Updated for KBD 1.4 API (changed LED handling). Revision 1.4 2007/05/05 01:56:57 carlmu Changes for 0.8 API Revision 1.3 2007/04/10 18:34:05 carlmu Changed for compatibility with 0.4 API. Revision 1.2 2007/04/02 19:12:17 carlmu Set callback functions modified for new return value. Revision 1.1 2007/03/21 18:04:57 carlmu Initial version. $NoKeywords: $ *---------------------------------------------------------------------------*/ /* Example simple keyboard application to output the low-level API HID code and the high-level API unicode to the console. */ #include #include static u8 __kbd_mem[KBD_MEM_SIZE]; //----------------------------------------------------------------------------- #define KBD_CALL(_fn_call) \ if ((_fn_call) != KBD_SUCCESS) { \ OSReport ("KBD error: calling %s @ %s:%i\n", \ #_fn_call, __FILE__, __LINE__); \ } //----------------------------------------------------------------------------- static void kbdAppAttach (KBDDevEvent *kde) { OSReport ("kbd app: keyboard added on channel %d\n", kde->channel); // for demo purposes, enable NumLock on newly attached keyboard KBDSetModState(kde->channel, KBD_MS_NUM_LOCK); KBDSetLedsRetry(kde->channel, KBD_LED_NUM_LOCK); } static void kbdAppDetach (KBDDevEvent *kde) { OSReport ("kbd app: keyboard removed on channel %d\n", kde->channel); } static void kbdAppKeyEvent (KBDKeyEvent *kke) { if (KBD_KEY_MODE_REPEAT(kke->mode)) { return; } if (KBD_KEY_MODE_UP(kke->mode)) OSReport ("\t\t\thid code: 0x%02x ^ up (chan %d)\n", kke->hid, kke->channel); else OSReport ("hid code: 0x%02x v down (chan %d)\n", kke->hid, kke->channel); // check for CapsLock, NumLock, or ScrollLock (handle LEDs) if (kke->hid == KBD_HID_Caps_Lock || kke->hid == KBD_HID_Keypad_Num_Lock || kke->unicode == KBK_Scroll_Lock) { KBDModState ms; KBDLedState leds; // First compute the new LED state KBDGetModState(kke->channel, &ms); leds = (KBDLedState) (((ms & KBD_MS_NUM_LOCK) == KBD_MS_NUM_LOCK) * KBD_LED_NUM_LOCK | ((ms & KBD_MS_CAPS_LOCK) == KBD_MS_CAPS_LOCK) * KBD_LED_CAPS_LOCK | ((ms & KBD_MS_SCROLL_LOCK) == KBD_MS_SCROLL_LOCK) * KBD_LED_SCROLL_LOCK); KBDSetLedsRetry(kke->channel, leds); } } extern void hid_open_async(void); extern void hid_close_async(void); int main(void) { DEMOInit(NULL); hid_open_async(); OSReport("\n\n"); OSReport("************************************************\n"); OSReport("kbdLowLevel Low-level keyboard demo\n"); OSReport("************************************************\n"); OSReport("Attach a USB keyboard and press some keys.\n"); OSReport("\n"); KBD_CALL (KBDInit(&__kbd_mem, kbdAppAttach, kbdAppDetach, kbdAppKeyEvent)); // One of these MUST be called after calling KBDInit. // It's okay to call more than one. KBDInitRegionUS(); KBDInitRegionJP(); KBDInitRegionEU(); while(1) OSYieldThread(); hid_close_async(); OSShutdownSystem(); // Never reached return 0; }