KallistiOS
2.0.0
Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
kernel
arch
dreamcast
include
dc
maple.h
Go to the documentation of this file.
1
/* KallistiOS 2.0.0
2
3
dc/maple.h
4
Copyright (C) 2002 Dan Potter
5
6
This new driver's design is based loosely on the LinuxDC maple
7
bus driver.
8
*/
9
10
/** \file dc/maple.h
11
\brief Maple Bus driver interface.
12
13
This file provides support for accessing the Maple bus on the Dreamcast.
14
Maple is the bus that all of your controllers and memory cards and the like
15
connect to, so this is one of those types of things that are quite important
16
to know how to use.
17
18
Each peripheral device registers their driver within this system, and can be
19
accessed through the functions here. Most of the drivers have their own
20
functionality that is implemented in their header files, as well.
21
22
\author Dan Potter
23
\author Lawrence Sebald
24
25
\see dc/maple/controller.h
26
\see dc/maple/dreameye.h
27
\see dc/maple/keyboard.h
28
\see dc/maple/mouse.h
29
\see dc/maple/purupuru.h
30
\see dc/maple/sip.h
31
\see dc/maple/vmu.h
32
*/
33
34
#ifndef __DC_MAPLE_H
35
#define __DC_MAPLE_H
36
37
#include <sys/cdefs.h>
38
__BEGIN_DECLS
39
40
#include <
arch/types.h
>
41
#include <sys/queue.h>
42
43
/** \brief Enable Maple DMA debugging.
44
45
Changing this to a 1 will add massive amounts of processing time to the
46
maple system in general, but it can help in verifying DMA errors. In
47
general, for most purposes this should stay disabled.
48
*/
49
#define MAPLE_DMA_DEBUG 0
50
51
/** \brief Enable Maple IRQ debugging.
52
53
Changing this to a 1 will turn on intra-interrupt debugging messages, which
54
may cause issues if you're using dcload rather than a raw serial debug
55
terminal. You probably will never have a good reason to enable this, so keep
56
it disabled for normal use.
57
*/
58
#define MAPLE_IRQ_DEBUG 0
59
60
/** \defgroup maple_regs Maple Bus register locations
61
62
These are various registers related to the Maple Bus. In general, you
63
probably won't ever need to mess with these directly.
64
65
@{
66
*/
67
#define MAPLE_BASE 0xa05f6c00
/**< \brief Maple register base */
68
#define MAPLE_DMAADDR (MAPLE_BASE+0x04)
/**< \brief DMA address register */
69
#define MAPLE_RESET2 (MAPLE_BASE+0x10)
/**< \brief Reset register #2 */
70
#define MAPLE_ENABLE (MAPLE_BASE+0x14)
/**< \brief Enable register */
71
#define MAPLE_STATE (MAPLE_BASE+0x18)
/**< \brief Status register */
72
#define MAPLE_SPEED (MAPLE_BASE+0x80)
/**< \brief Speed register */
73
#define MAPLE_RESET1 (MAPLE_BASE+0x8c)
/**< \brief Reset register #1 */
74
/** @} */
75
76
/** \defgroup maple_reg_values Values to write to Maple Bus registers
77
78
These are the values that are written to registers to get them to do their
79
thing.
80
81
@{
82
*/
83
#define MAPLE_RESET2_MAGIC 0
/**< \brief 2nd reset value */
84
#define MAPLE_ENABLE_ENABLED 1
/**< \brief Enable Maple */
85
#define MAPLE_ENABLE_DISABLED 0
/**< \brief Disable Maple */
86
#define MAPLE_STATE_IDLE 0
/**< \brief Idle state */
87
#define MAPLE_STATE_DMA 1
/**< \brief DMA in-progress */
88
#define MAPLE_SPEED_2MBPS 0
/**< \brief 2Mbps bus speed */
89
#define MAPLE_SPEED_TIMEOUT(n) ((n) << 16)
/**< \brief Bus timeout macro */
90
#define MAPLE_RESET1_MAGIC 0x6155404f
/**< \brief First reset value */
91
/** @} */
92
93
/** \defgroup maple_cmds Maple commands and responses
94
95
These are all either commands or responses to commands sent to or from Maple
96
in normal operation.
97
98
@{
99
*/
100
#define MAPLE_RESPONSE_FILEERR -5
/**< \brief File error */
101
#define MAPLE_RESPONSE_AGAIN -4
/**< \brief Try again later */
102
#define MAPLE_RESPONSE_BADCMD -3
/**< \brief Bad command sent */
103
#define MAPLE_RESPONSE_BADFUNC -2
/**< \brief Bad function code */
104
#define MAPLE_RESPONSE_NONE -1
/**< \brief No response */
105
#define MAPLE_COMMAND_DEVINFO 1
/**< \brief Device info request */
106
#define MAPLE_COMMAND_ALLINFO 2
/**< \brief All info request */
107
#define MAPLE_COMMAND_RESET 3
/**< \brief Reset device request */
108
#define MAPLE_COMMAND_KILL 4
/**< \brief Kill device request */
109
#define MAPLE_RESPONSE_DEVINFO 5
/**< \brief Device info response */
110
#define MAPLE_RESPONSE_ALLINFO 6
/**< \brief All info response */
111
#define MAPLE_RESPONSE_OK 7
/**< \brief Command completed ok */
112
#define MAPLE_RESPONSE_DATATRF 8
/**< \brief Data transfer */
113
#define MAPLE_COMMAND_GETCOND 9
/**< \brief Get condition request */
114
#define MAPLE_COMMAND_GETMINFO 10
/**< \brief Get memory information */
115
#define MAPLE_COMMAND_BREAD 11
/**< \brief Block read */
116
#define MAPLE_COMMAND_BWRITE 12
/**< \brief Block write */
117
#define MAPLE_COMMAND_BSYNC 13
/**< \brief Block sync */
118
#define MAPLE_COMMAND_SETCOND 14
/**< \brief Set condition request */
119
#define MAPLE_COMMAND_MICCONTROL 15
/**< \brief Microphone control */
120
#define MAPLE_COMMAND_CAMCONTROL 17
/**< \brief Camera control */
121
/** @} */
122
123
/** \defgroup maple_functions Maple device function codes
124
125
This is the list of maple device types (function codes). Each device must
126
have at least one function to actually do anything.
127
128
@{
129
*/
130
131
/* Function codes; most sources claim that these numbers are little
132
endian, and for all I know, they might be; but since it's a bitmask
133
it doesn't really make much different. We'll just reverse our constants
134
from the "big-endian" version. */
135
#define MAPLE_FUNC_PURUPURU 0x00010000
/**< \brief Jump pack */
136
#define MAPLE_FUNC_MOUSE 0x00020000
/**< \brief Mouse */
137
#define MAPLE_FUNC_CAMERA 0x00080000
/**< \brief Camera (Dreameye) */
138
#define MAPLE_FUNC_CONTROLLER 0x01000000
/**< \brief Controller */
139
#define MAPLE_FUNC_MEMCARD 0x02000000
/**< \brief Memory card */
140
#define MAPLE_FUNC_LCD 0x04000000
/**< \brief LCD screen */
141
#define MAPLE_FUNC_CLOCK 0x08000000
/**< \brief Clock */
142
#define MAPLE_FUNC_MICROPHONE 0x10000000
/**< \brief Microphone */
143
#define MAPLE_FUNC_ARGUN 0x20000000
/**< \brief AR gun? */
144
#define MAPLE_FUNC_KEYBOARD 0x40000000
/**< \brief Keyboard */
145
#define MAPLE_FUNC_LIGHTGUN 0x80000000
/**< \brief Lightgun */
146
/** @} */
147
148
/* \cond */
149
/* Pre-define list/queue types */
150
struct
maple_frame
;
151
TAILQ_HEAD(maple_frame_queue,
maple_frame
);
152
153
struct
maple_driver
;
154
LIST_HEAD
(maple_driver_list,
maple_driver
);
155
/* \endcond */
156
157
/** \brief Maple frame to be queued for transport.
158
159
Internal representation of a frame to be queued up for sending.
160
161
\headerfile dc/maple.h
162
*/
163
typedef
struct
maple_frame
{
164
/** \brief Send queue handle. NOT A FUNCTION! */
165
TAILQ_ENTRY
(
maple_frame
) frameq;
166
167
int
cmd
;
/**< \brief Command (see \ref maple_cmds) */
168
int
dst_port
;
/**< \brief Destination port */
169
int
dst_unit
;
/**< \brief Destination unit */
170
int
length
;
/**< \brief Data transfer length in 32-bit words */
171
volatile
int
state
;
/**< \brief Has this frame been sent / responded to? */
172
volatile
int
queued
;
/**< \brief Are we on the queue? */
173
174
void
*
send_buf
;
/**< \brief The data which will be sent (if any) */
175
uint8
*
recv_buf
;
/**< \brief Points into recv_buf_arr, but 32-byte aligned */
176
177
struct
maple_device
*
dev
;
/**< \brief Does this belong to a device? */
178
179
void (*
callback
)(
struct
maple_frame
*);
/**< \brief Response callback */
180
181
#if MAPLE_DMA_DEBUG
182
uint8
recv_buf_arr
[1024 + 1024 + 32];
/**< \brief Response receive area */
183
#else
184
uint8
recv_buf_arr
[1024 + 32];
/**< \brief Response receive area */
185
#endif
186
}
maple_frame_t
;
187
188
/** \defgroup maple_frame_states States that frames can be in
189
@{
190
*/
191
#define MAPLE_FRAME_VACANT 0
/**< \brief Ready to be used */
192
#define MAPLE_FRAME_UNSENT 1
/**< \brief Ready to be sent */
193
#define MAPLE_FRAME_SENT 2
/**< \brief Frame has been sent, but no response yet */
194
#define MAPLE_FRAME_RESPONDED 3
/**< \brief Frame has a response */
195
/** @} */
196
197
/** \brief Maple device info structure.
198
199
This structure is used by the hardware to deliver the response to the device
200
info request.
201
202
\headerfile dc/maple.h
203
*/
204
typedef
struct
maple_devinfo
{
205
uint32
functions
;
/**< \brief Function codes supported */
206
uint32
function_data
[3];
/**< \brief Additional data per function */
207
uint8
area_code
;
/**< \brief Region code */
208
uint8
connector_direction
;
/**< \brief ? */
209
char
product_name
[30];
/**< \brief Name of device */
210
char
product_license
[60];
/**< \brief License statement */
211
uint16
standby_power
;
/**< \brief Power consumption (standby) */
212
uint16
max_power
;
/**< \brief Power consumption (max) */
213
}
maple_devinfo_t
;
214
215
/** \brief Maple response frame structure.
216
217
This structure is used to deliver the actual response to a request placed.
218
The data field is where all the interesting stuff will be.
219
220
\headerfile dc/maple.h
221
*/
222
typedef
struct
maple_response
{
223
int8
response
;
/**< \brief Response */
224
uint8
dst_addr
;
/**< \brief Destination address */
225
uint8
src_addr
;
/**< \brief Source address */
226
uint8
data_len
;
/**< \brief Data length (in 32-bit words) */
227
uint8
data
[0];
/**< \brief Data (if any) */
228
}
maple_response_t
;
229
230
/** \brief One maple device.
231
232
Note that we duplicate the port/unit info which is normally somewhat
233
implicit so that we can pass around a pointer to a particular device struct.
234
235
\headerfile dc/maple.h
236
*/
237
typedef
struct
maple_device
{
238
/* Public */
239
int
valid
;
/**< \brief Is this a valid device? */
240
int
port
;
/**< \brief Maple bus port connected to */
241
int
unit
;
/**< \brief Unit number, off of the port */
242
maple_devinfo_t
info
;
/**< \brief Device info struct */
243
244
/* Private */
245
int
dev_mask
;
/**< \brief Device-present mask for unit 0's */
246
maple_frame_t
frame
;
/**< \brief One rx/tx frame */
247
struct
maple_driver
*
drv
;
/**< \brief Driver which handles this device */
248
249
volatile
int
status_valid
;
/**< \brief Have we got our first status update? */
250
uint8
status
[1024];
/**< \brief Status buffer (for pollable devices) */
251
}
maple_device_t
;
252
253
#define MAPLE_PORT_COUNT 4
/**< \brief Number of ports on the bus */
254
#define MAPLE_UNIT_COUNT 6
/**< \brief Max number of units per port */
255
256
/** \brief Internal representation of a Maple port.
257
258
each maple port can contain up to 6 devices, the first one of which is
259
always the port itself.
260
261
\headerfile dc/maple.h
262
*/
263
typedef
struct
maple_port
{
264
int
port
;
/**< \brief Port ID */
265
maple_device_t
units
[
MAPLE_UNIT_COUNT
];
/**< \brief Pointers to active units */
266
}
maple_port_t
;
267
268
/** \brief A maple device driver.
269
270
Anything which is added to this list is capable of handling one or more
271
maple device types. When a device of the given type is connected (includes
272
startup "connection"), the driver is invoked. This same process happens for
273
disconnection, response receipt, and on a periodic interval (for normal
274
updates).
275
276
\headerfile dc/maple.h
277
*/
278
typedef
struct
maple_driver
{
279
/** \brief Driver list handle. NOT A FUNCTION! */
280
LIST_ENTRY
(
maple_driver
) drv_list;
281
282
uint32
functions
;
/**< \brief One or more MAPLE_FUNCs ORed together */
283
const
char
*
name
;
/**< \brief The driver name */
284
285
/* Callbacks, to be filled in by the driver */
286
287
/** \brief Periodic polling callback.
288
289
This callback will be called to update the status of connected devices
290
periodically.
291
292
\param drv This structure for the driver.
293
*/
294
void (*
periodic
)(
struct
maple_driver
*drv);
295
296
/** \brief Device attached callback.
297
298
This callback will be called when a new device of this driver is
299
connected to the system.
300
301
\param drv This structure for the driver.
302
\param dev The device that was connected.
303
\return 0 on success, <0 on error.
304
*/
305
int (*
attach
)(
struct
maple_driver
*drv,
maple_device_t
*dev);
306
307
/** \brief Device detached callback.
308
309
This callback will be called when a device of this driver is disconnected
310
from the system.
311
312
\param drv This structure for the driver.
313
\param dev The device that was detached.
314
*/
315
void (*
detach
)(
struct
maple_driver
*drv,
maple_device_t
*dev);
316
}
maple_driver_t
;
317
318
/** \brief Maple state structure.
319
320
We put everything in here to keep from polluting the global namespace too
321
much.
322
323
\headerfile dc/maple.h
324
*/
325
typedef
struct
maple_state_str
{
326
/** \brief Maple device driver list. Do not manipulate directly! */
327
struct
maple_driver_list
driver_list
;
328
329
/** \brief Maple frame submission queue. Do not manipulate directly! */
330
struct
maple_frame_queue
frame_queue
;
331
332
/** \brief Maple device info structure */
333
maple_port_t
ports
[
MAPLE_PORT_COUNT
];
334
335
/** \brief DMA interrupt counter */
336
volatile
int
dma_cntr
;
337
338
/** \brief VBlank interrupt counter */
339
volatile
int
vbl_cntr
;
340
341
/** \brief DMA send buffer */
342
uint8
*
dma_buffer
;
343
344
/** \brief Is a DMA running now? */
345
volatile
int
dma_in_progress
;
346
347
/** \brief Next port that will be auto-detected */
348
int
detect_port_next
;
349
350
/** \brief Next unit which will be auto-detected */
351
int
detect_unit_next
;
352
353
/** \brief Did the detect wrap? */
354
volatile
int
detect_wrapped
;
355
356
/** \brief Our vblank handler handle */
357
int
vbl_handle
;
358
}
maple_state_t
;
359
360
/** \brief Maple DMA buffer size.
361
362
Increase if you do a _LOT_ of maple stuff on every periodic interrupt.
363
*/
364
#define MAPLE_DMA_SIZE 16384
365
366
/* Maple memory read/write functions; these are just hooks in case
367
we need to do something else later */
368
/** \brief Maple memory read macro. */
369
#define maple_read(A) ( *((vuint32*)(A)) )
370
371
/** \brief Maple memory write macro. */
372
#define maple_write(A, V) ( *((vuint32*)(A)) = (V) )
373
374
/* Return codes from maple access functions */
375
/** \defgroup maple_func_rvs Return values from Maple functions
376
@{
377
*/
378
#define MAPLE_EOK 0
/**< \brief No error */
379
#define MAPLE_EFAIL -1
/**< \brief Command failed */
380
#define MAPLE_EAGAIN -2
/**< \brief Try again later */
381
#define MAPLE_EINVALID -3
/**< \brief Invalid command */
382
#define MAPLE_ENOTSUPP -4
/**< \brief Command not suppoted by device */
383
#define MAPLE_ETIMEOUT -5
/**< \brief Command timed out */
384
/** @} */
385
386
/**************************************************************************/
387
/* maple_globals.c */
388
389
/** \brief Global state info.
390
391
Do not manipulate this state yourself, as it will likely break things if you
392
do so.
393
*/
394
extern
maple_state_t
maple_state
;
395
396
/**************************************************************************/
397
/* maple_utils.c */
398
399
/** \brief Enable the Maple bus.
400
401
This will be done for you autmatically at init time, and there's probably
402
not many reasons to be doing this during runtime.
403
*/
404
void
maple_bus_enable
();
405
406
/** \brief Disable the Maple bus.
407
408
There's really not many good reasons to be mucking with this at runtime.
409
*/
410
void
maple_bus_disable
();
411
412
/** \brief Start a Maple DMA.
413
414
This stuff will all be handled internally, so there's probably no reason to
415
be doing this yourself.
416
*/
417
void
maple_dma_start
();
418
419
/** \brief Stop a Maple DMA.
420
421
This stuff will all be handled internally, so there's probably no reason to
422
be doing this yourself.
423
*/
424
void
maple_dma_stop
();
425
426
/** \brief Is a Maple DMA in progress?
427
428
\return Non-zero if a DMA is in progress.
429
*/
430
int
maple_dma_in_progress
();
431
432
/** \brief Set the Maple DMA address.
433
434
Once again, you should not muck around with this in your programs.
435
*/
436
void
maple_dma_addr
(
void
*ptr);
437
438
/** \brief Return a "maple address" for a port, unit pair.
439
440
\param port The port to build the address for.
441
\param unit The unit to build the address for.
442
\return The Maple address of the pair.
443
*/
444
uint8
maple_addr
(
int
port,
int
unit);
445
446
/** \brief Decompose a "maple address" into a port, unit pair.
447
448
WARNING: This function will not work with multi-cast addresses!
449
450
\param addr The input address.
451
\param port Output space for the port of the address.
452
\param unit Output space for the unit of the address.
453
*/
454
void
maple_raddr
(
uint8
addr,
int
* port,
int
* unit);
455
456
/** \brief Return a string with the capabilities of a given function code.
457
458
This function is not re-entrant, and thus NOT THREAD SAFE.
459
460
\param functions The list of function codes.
461
\return A string containting the capabilities.
462
*/
463
const
char
*
maple_pcaps
(
uint32
functions);
464
465
/** \brief Return a string representing the maple response code.
466
467
\param response The response code returned from the function.
468
\return A string containing a textual respresentation of the
469
response code.
470
*/
471
const
char
*
maple_perror
(
int
response);
472
473
/** \brief Determine if a given device is valid.
474
\param p The port to check.
475
\param u The unit to check.
476
\return Non-zero if the device is valid.
477
*/
478
int
maple_dev_valid
(
int
p,
int
u);
479
480
#if MAPLE_DMA_DEBUG
481
/* Debugging help */
482
483
/** \brief Setup a sentinel for debugging DMA issues.
484
\param buffer The buffer to add the sentinel to.
485
\param bufsize The size of the data in the buffer.
486
*/
487
void
maple_sentinel_setup(
void
* buffer,
int
bufsize);
488
489
/** \brief Verify the presence of the sentine.
490
\param bufname A string to recognize the buffer by.
491
\param buffer The buffer to check.
492
\param bufsize The size of the buffer.
493
*/
494
void
maple_sentinel_verify(
const
char
* bufname,
void
* buffer,
int
bufsize);
495
#endif
496
497
/**************************************************************************/
498
/* maple_queue.c */
499
500
/** \brief Send all queued frames. */
501
void
maple_queue_flush
();
502
503
/** \brief Submit a frame for queueing.
504
505
This will generally be called inside the periodic interrupt; however, if you
506
need to do something asynchronously (e.g., VMU access) then it might cause
507
some problems. In this case, the function will automatically do locking by
508
disabling interrupts temporarily. In any case, the callback will be done
509
inside an IRQ context.
510
511
\param frame The frame to queue up.
512
\retval 0 On success.
513
\retval -1 If the frame is already queued.
514
*/
515
int
maple_queue_frame
(
maple_frame_t
*frame);
516
517
/** \brief Remove a used frame from the queue.
518
519
This will be done automatically when the frame is consumed.
520
521
\param frame The frame to remove from the queue.
522
\retval 0 On success.
523
\retval -1 If the frame is not queued.
524
*/
525
int
maple_queue_remove
(
maple_frame_t
*frame);
526
527
/** \brief Initialize a new frame to prepare it to be placed on the queue.
528
529
You should call this before you fill in the frame data.
530
531
\param frame The frame to initialize.
532
*/
533
void
maple_frame_init
(
maple_frame_t
*frame);
534
535
/** \brief Lock a frame so that someone else can't use it in the mean time.
536
\retval 0 On success.
537
\retval -1 If the frame is already locked.
538
*/
539
int
maple_frame_lock
(
maple_frame_t
*frame);
540
541
/** \brief Unlock a frame. */
542
void
maple_frame_unlock
(
maple_frame_t
*frame);
543
544
/**************************************************************************/
545
/* maple_driver.c */
546
547
/** \brief Register a maple device driver.
548
549
This should be done before calling maple_init().
550
551
\retval 0 On success (no error conditions defined).
552
*/
553
int
maple_driver_reg
(
maple_driver_t
*driver);
554
555
/** \brief Unregister a maple device driver.
556
\retval 0 On success (no error conditions defined).
557
*/
558
int
maple_driver_unreg
(
maple_driver_t
*driver);
559
560
/** \brief Attach a maple device to a driver, if possible.
561
\param det The detection frame.
562
\retval 0 On success.
563
\retval -1 If no driver is available.
564
*/
565
int
maple_driver_attach
(
maple_frame_t
*det);
566
567
/** \brief Detach an attached maple device.
568
\param p The port of the device to detach.
569
\param u The unit of the device to detach.
570
\retval 0 On success.
571
\retval -1 If the device wasn't valid.
572
*/
573
int
maple_driver_detach
(
int
p,
int
u);
574
575
/** \brief For each device which the given driver controls, call the callback.
576
\param drv The driver to loop through devices of.
577
\param callback The function to call. The parameter is the device
578
that it is being called on. It should return 0 on
579
success, and <0 on failure.
580
\retval 0 On success.
581
\retval -1 If any callbacks return <0.
582
*/
583
int
maple_driver_foreach
(
maple_driver_t
*drv,
int
(*callback)(
maple_device_t
*));
584
585
/**************************************************************************/
586
/* maple_irq.c */
587
588
/** \brief Called on every VBL (~60fps).
589
\param code The ASIC event code.
590
*/
591
void
maple_vbl_irq_hnd
(
uint32
code);
592
593
/** \brief Called after a Maple DMA send / receive pair completes.
594
\param code The ASIC event code.
595
*/
596
void
maple_dma_irq_hnd
(
uint32
code);
597
598
/**************************************************************************/
599
/* maple_enum.c */
600
601
/** \brief Return the number of connected devices.
602
\return The number of devices connected.
603
*/
604
int
maple_enum_count
();
605
606
/** \brief Get a raw device info struct for the given device.
607
\param p The port to look up.
608
\param u The unit to look up.
609
\return The device at that address, or NULL if no device is
610
there.
611
*/
612
maple_device_t
*
maple_enum_dev
(
int
p,
int
u);
613
614
/** \brief Get the Nth device of the requested type (where N is zero-indexed).
615
\param n The index to look up.
616
\param func The function code to look for.
617
\return The device found, if any. NULL otherwise.
618
*/
619
maple_device_t
*
maple_enum_type
(
int
n,
uint32
func);
620
621
/** \brief Return the Nth device that is of the requested type and supports the
622
list of capabilities given.
623
624
Note, this only currently makes sense for controllers, since some devices
625
don't necessarily use the function data in the same manner that controllers
626
do (and controllers are the only devices where we have a list of what all
627
the bits mean at the moment).
628
629
\param n The index to look up.
630
\param func The function code to look for.
631
\param cap Capabilities bits to look for.
632
\return The device found, if any. NULL otherwise.
633
*/
634
maple_device_t
*
maple_enum_type_ex
(
int
n,
uint32
func,
uint32
cap);
635
636
/** \brief Get the status struct for the requested maple device.
637
638
This function will wait until the status is valid before returning.
639
You should cast to the appropriate type you're expecting.
640
641
\param dev The device to look up.
642
\return The device's status.
643
*/
644
void
*
maple_dev_status
(
maple_device_t
*dev);
645
646
/**************************************************************************/
647
/* maple_init.c */
648
649
/** \brief Initialize Maple.
650
\return 0 on success, <0 on failure.
651
*/
652
int
maple_init
();
653
654
/** \brief Shutdown Maple. */
655
void
maple_shutdown
();
656
657
/** \brief Wait for the initial bus scan to complete. */
658
void
maple_wait_scan
();
659
660
/**************************************************************************/
661
/* Convienence macros */
662
663
/* A "foreach" loop to scan all maple devices of a given type. It is used
664
like this:
665
666
MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
667
if (st->buttons & CONT_START)
668
return -1;
669
MAPLE_FOREACH_END()
670
671
The peripheral index can be obtained with __i, and the raw device struct
672
with __dev. The code inside the loop is guaranteed to be inside a block
673
(i.e., { code })
674
*/
675
676
/** \brief Begin a foreach loop over Maple devices.
677
678
This macro (along with the MAPLE_FOREACH_END() one) implements a simple
679
foreach-style loop over the given type of devices. Essentially, it grabs the
680
status of the device, and leaves it to you to figure out what to do with it.
681
682
The most common use of this would be to look for input on any controller.
683
684
\param TYPE The function code of devices to look at.
685
\param VARTYPE The type to cast the return value of
686
maple_dev_status() to.
687
\param VAR The name of the result of maple_dev_status().
688
*/
689
#define MAPLE_FOREACH_BEGIN(TYPE, VARTYPE, VAR) \
690
do { \
691
maple_device_t * __dev; \
692
VARTYPE * VAR; \
693
int __i; \
694
\
695
__i = 0; \
696
while ( (__dev = maple_enum_type(__i, TYPE)) ) { \
697
VAR = (VARTYPE *)maple_dev_status(__dev); \
698
do {
699
700
/** \brief End a foreach loop over Maple devices.
701
702
Each MAPLE_FOREACH_BEGIN() must be paired with one of these after the loop
703
body.
704
*/
705
#define MAPLE_FOREACH_END() \
706
} while(0); \
707
__i++; \
708
} \
709
} while(0);
710
711
__END_DECLS
712
713
#endif
/* __DC_MAPLE_H */
Generated by
1.8.1.1