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