1 /*---------------------------------------------------------------------------*
2 Project: HID lib open and close module for KBD demo
3 File: hid_open_close.c
4
5 Copyright (C)1998-2007 Nintendo All Rights Reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: hid_open_close.c,v $
14 Revision 1.2 2007/10/18 18:44:29 henrch
15 - added copyrigth header and history
16 - added comments regarding memory usage
17 - use OSGetMEMArenaLo
18
19 $NoKeywords: $
20 *---------------------------------------------------------------------------*/
21 #include <demo.h>
22 #include <revolution/hid.h>
23 #define printf OSReport
24 //////////////////////////////////////////////////////////////////////////////
25 volatile int __done;
26 //////////////////////////////////////////////////////////////////////////////
hid_setup_handler(HIDError he,u32 user)27 static void hid_setup_handler(HIDError he, u32 user)
28 {
29 #pragma unused(he)
30
31 *(int*)user = 1;
32 }
33
34
35 //////////////////////////////////////////////////////////////////////////////
36 void hid_open_async(void);
hid_open_async(void)37 void hid_open_async(void)
38 {
39 // This demo does not have allocator and nothing is using the arena so we
40 // will just use the base of MEM2 address for the HID lib. USE AN ALLOCATOR
41 // FOR YOUR GMAE!!!
42 void *p_hid_mem = OSGetMEM2ArenaLo();
43
44 __done = 0;
45
46 printf("calling HIDOpenAsync()\n");
47
48 HIDOpenAsync(p_hid_mem, hid_setup_handler, (u32)&__done);
49
50 printf("wait for callback\n");
51
52 // This should be in some initialization loop, perhaps when you fade in a
53 // screen and yo have to use a keyboard or other HID device for instance.
54 while (__done == 0)
55 ;
56
57 printf("opened HID lib\n");
58 }
59
60
61 //////////////////////////////////////////////////////////////////////////////
62 void hid_close_async(void);
hid_close_async(void)63 void hid_close_async(void)
64 {
65 __done = 0;
66
67 printf("calling HIDCloseAsync()\n");
68
69 HIDCloseAsync(hid_setup_handler, (u32)&__done);
70
71 printf("wait for callback\n");
72
73 // This should be in some clean up loop, perhaps when you fade out a
74 // screen and you no longer need to use a keyboard or other HID device
75 // for instance.
76 while (__done == 0)
77 ;
78
79 // If you allocated memory for the HID lib it can be freed after the HID
80 // lib is closed.
81
82 printf("closed HID lib\n");
83 }