1 /*---------------------------------------------------------------------------*
2   Project:  HID lib open and close module for KPR 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.3.2.2  2009/10/14 10:04:01  iwai_yuma
15   Rool back into StackB.
16 
17   Revision 1.2  2007/10/18 18:44:45  henrch
18   - added copyrigth header and history
19   - added comments regarding memory usage
20   - use OSGetMEMArenaLo
21 
22   $NoKeywords: $
23  *---------------------------------------------------------------------------*/
24 #include <demo.h>
25 #include <revolution/hid.h>
26 #define printf OSReport
27 //////////////////////////////////////////////////////////////////////////////
28 volatile int __done;
29 //////////////////////////////////////////////////////////////////////////////
hid_setup_handler(HIDError he,u32 user)30 static void hid_setup_handler(HIDError he, u32 user)
31 {
32 #pragma unused(he)
33 
34     *(int*)user = 1;
35 }
36 
37 
38 //////////////////////////////////////////////////////////////////////////////
39 void hid_open_async(void);
hid_open_async(void)40 void hid_open_async(void)
41 {
42     // This demo does not have allocator and nothing is using the arena so we
43     // will just use the base of MEM2 address for the HID lib. USE AN ALLOCATOR
44     // FOR YOUR GMAE!!!
45     void *p_hid_mem = OSGetMEM2ArenaLo();
46 
47     __done = 0;
48 
49     printf("calling HIDOpenAsync()\n");
50 
51     HIDOpenAsync(p_hid_mem, hid_setup_handler, (u32)&__done);
52 
53     printf("wait for callback\n");
54 
55     // This should be in some initialization loop, perhaps when you fade in a
56     // screen and yo have to use a keyboard or other HID device for instance.
57     while (__done == 0)
58         ;
59 
60     printf("opened HID lib\n");
61 }
62 
63 
64 //////////////////////////////////////////////////////////////////////////////
65 void hid_close_async(void);
hid_close_async(void)66 void hid_close_async(void)
67 {
68     __done = 0;
69 
70     printf("calling HIDCloseAsync()\n");
71 
72     HIDCloseAsync(hid_setup_handler, (u32)&__done);
73 
74     printf("wait for callback\n");
75 
76     // This should be in some clean up loop, perhaps when you fade out a
77     // screen and you no longer need to use a keyboard or other HID device
78     // for instance.
79     while (__done == 0)
80         ;
81 
82     // If you allocated memory for the HID lib it can be freed after the HID
83     // lib is closed.
84 
85     printf("closed HID lib\n");
86 }