root/wiimote/wiimote_internal.h @ a339960844acef82f06e6c4ba82575fafc4e50ac

Revision a339960844acef82f06e6c4ba82575fafc4e50ac, 4.8 KB (checked in by dsmith <dsmith@…>, 6 years ago)

added wiimote_set_err

git-svn-id: http://abstrakraft.org/cwiid/svn/trunk@27 918edb2d-ff29-0410-9de2-eb38e7f22bc7

  • Property mode set to 100644
Line 
1/* Copyright (C) 2007 L. Donnie Smith <cwiid@abstrakraft.org>
2 *
3 *  This program is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  This program is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with this program; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 *  ChangeLog:
18 *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org>
19 *  * added wiimote parameter to wiimote_err prototype
20 *
21 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org>
22 *  * Initial ChangeLog
23 *  * type audit (stdint, const, char booleans)
24 */
25
26#ifndef WIIMOTE_INTERNAL_H
27#define WIIMOTE_INTERNAL_H
28
29#include <stdint.h>
30#include <pthread.h>
31#include "wiimote.h"
32
33/* Bluetooth magic numbers */
34#define BT_TRANS_MASK           0xF0
35#define BT_TRANS_HANDSHAKE      0x00
36#define BT_TRANS_SET_REPORT     0x50
37#define BT_TRANS_DATA           0xA0
38#define BT_TRANS_DATAC          0xB0
39
40#define BT_PARAM_MASK           0x0F
41/* HANDSHAKE params */
42#define BT_PARAM_SUCCESSFUL                                     0x00
43#define BT_PARAM_NOT_READY                                      0x01
44#define BT_PARAM_ERR_INVALID_REPORT_ID          0x02
45#define BT_PARAM_ERR_UNSUPPORTED_REQUEST        0x03
46#define BT_PARAM_ERR_INVALID_PARAMETER          0x04
47#define BT_PARAM_ERR_UNKNOWN                            0x0E
48#define BT_PARAM_ERR_FATAL                                      0x0F
49/* SET_REPORT, DATA, DATAC params */
50#define BT_PARAM_INPUT          0x01
51#define BT_PARAM_OUTPUT         0x02
52#define BT_PARAM_FEATURE        0x03
53
54/* Wiimote specific magic numbers */
55#define WIIMOTE_NAME "Nintendo RVL-CNT-01"
56#define WIIMOTE_CMP_LEN sizeof(WIIMOTE_NAME)
57#define WIIMOTE_CLASS_0 0x04
58#define WIIMOTE_CLASS_1 0x25
59#define WIIMOTE_CLASS_2 0x00
60
61/* Wiimote port/channel/PSMs */
62#define CTL_PSM 17
63#define INT_PSM 19
64
65/* Report numbers */
66#define RPT_LED_RUMBLE                  0x11
67#define RPT_RPT_MODE                    0x12
68#define RPT_IR_ENABLE1                  0x13
69#define RPT_SPEAKER_ENABLE              0x14
70#define RPT_STATUS_REQ                  0x15
71#define RPT_WRITE                               0x16
72#define RPT_READ_REQ                    0x17
73#define RPT_SPEAKER_DATA                0x18
74#define RPT_SPEAKER_MUTE                0x19
75#define RPT_IR_ENABLE2                  0x1A
76#define RPT_STATUS                              0x20
77#define RPT_READ_DATA                   0x21
78#define RPT_WRITE_ACK                   0x22
79#define RPT_BTN                                 0x30
80#define RPT_BTN_ACC                             0x31
81#define RPT_BTN_EXT8                    0x32
82#define RPT_BTN_ACC_IR12                0x33
83#define RPT_BTN_EXT19                   0x34
84#define RPT_BTN_ACC_EXT16               0x35
85#define RPT_BTN_IR10_EXT9               0x36
86#define RPT_BTN_ACC_IR10_EXT6   0x37
87#define RPT_EXT21                               0x3D
88#define RPT_BTN_ACC_IR36_1              0x3E
89#define RPT_BTN_ACC_IR36_2              0x3F
90
91/* Button Mask (masks unknown bits in button bytes) */
92#define BTN_MASK_0                      0x1F
93#define BTN_MASK_1                      0x9F
94#define NUNCHUK_BTN_MASK        0x03
95
96/* Extension Values */
97#define EXT_NONE        0x2E
98#define EXT_PARTIAL 0xFF
99#define EXT_NUNCHUK 0x00
100#define EXT_CLASSIC 0x01
101
102/* IR Enable blocks */
103#define MARCAN_IR_BLOCK_1       "\x00\x00\x00\x00\x00\x00\x90\x00\xC0"
104#define MARCAN_IR_BLOCK_2       "\x40\x00"
105#define CLIFF_IR_BLOCK_1        "\x02\x00\x00\x71\x01\x00\xAA\x00\x64"
106#define CLIFF_IR_BLOCK_2        "\x63\x03"
107
108/* Extension Decode */
109#define DECODE(a)       (((a ^ 0x17)+0x17)&0xFF)
110
111enum write_seq_type {
112        WRITE_SEQ_RPT,
113        WRITE_SEQ_MEM
114};
115
116/* send_report flags */
117#define SEND_RPT_NO_RUMBLE      0x01
118
119struct write_seq {
120        enum write_seq_type type;
121        uint32_t report_offset;
122        const void *data;
123        uint16_t len;
124        uint8_t flags;
125};
126
127#define SEQ_LEN(seq) (sizeof(seq)/sizeof(struct write_seq))
128
129enum rw_status {
130        RW_NONE,
131        RW_PENDING,
132        RW_READY,
133        RW_ERROR
134};
135
136struct mesg_array {
137        int count;
138        union wiimote_mesg *mesg[WIIMOTE_MAX_MESG_COUNT];
139};
140
141struct wiimote {
142        int id;
143        int ctl_socket;
144        int int_socket;
145        uint8_t led_rumble_state;
146        uint8_t rpt_mode_flags;
147        uint16_t buttons;
148        enum wiimote_ext_type extension;
149        wiimote_mesg_callback_t *mesg_callback;
150        pthread_t int_listen_thread;
151        pthread_t dispatch_thread;
152        struct queue *dispatch_queue;
153        pthread_mutex_t wiimote_mutex;
154        pthread_mutex_t rw_mutex;
155        pthread_cond_t rw_cond;
156        pthread_mutex_t rw_cond_mutex;
157        enum rw_status rw_status;
158        void *read_buf;
159        uint16_t read_len;
160        uint16_t read_received;
161};
162
163/* prototypes */
164void *int_listen(struct wiimote *wiimote);
165void *dispatch(struct wiimote *wiimote);
166
167int update_rpt_mode(struct wiimote *wiimote, int8_t flags);
168
169void wiimote_err(struct wiimote *wiimote, const char *str, ...);
170int verify_handshake(struct wiimote *wiimote);
171int send_report(struct wiimote *wiimote, uint8_t flags, uint8_t report,
172                size_t len, const void *data);
173int exec_write_seq(struct wiimote *wiimote, unsigned int len,
174                   struct write_seq *seq);
175void free_mesg_array(struct mesg_array *array);
176int wiimote_findfirst(bdaddr_t *bdaddr);
177
178#endif
179
Note: See TracBrowser for help on using the browser.