59#define MAPLE_DMA_DEBUG 0
69#define MAPLE_IRQ_DEBUG 0
80#define MAPLE_BASE 0xa05f6c00
81#define MAPLE_DMAADDR (MAPLE_BASE+0x04)
82#define MAPLE_RESET2 (MAPLE_BASE+0x10)
83#define MAPLE_ENABLE (MAPLE_BASE+0x14)
84#define MAPLE_STATE (MAPLE_BASE+0x18)
85#define MAPLE_SPEED (MAPLE_BASE+0x80)
86#define MAPLE_RESET1 (MAPLE_BASE+0x8c)
98#define MAPLE_RESET2_MAGIC 0
99#define MAPLE_ENABLE_ENABLED 1
100#define MAPLE_ENABLE_DISABLED 0
101#define MAPLE_STATE_IDLE 0
102#define MAPLE_STATE_DMA 1
103#define MAPLE_SPEED_2MBPS 0
104#define MAPLE_SPEED_TIMEOUT(n) ((n) << 16)
106#ifndef _arch_sub_naomi
107#define MAPLE_RESET1_MAGIC 0x6155404f
109#define MAPLE_RESET1_MAGIC 0x6155405f
123#define MAPLE_RESPONSE_FILEERR -5
124#define MAPLE_RESPONSE_AGAIN -4
125#define MAPLE_RESPONSE_BADCMD -3
126#define MAPLE_RESPONSE_BADFUNC -2
127#define MAPLE_RESPONSE_NONE -1
128#define MAPLE_COMMAND_DEVINFO 1
129#define MAPLE_COMMAND_ALLINFO 2
130#define MAPLE_COMMAND_RESET 3
131#define MAPLE_COMMAND_KILL 4
132#define MAPLE_RESPONSE_DEVINFO 5
133#define MAPLE_RESPONSE_ALLINFO 6
134#define MAPLE_RESPONSE_OK 7
135#define MAPLE_RESPONSE_DATATRF 8
136#define MAPLE_COMMAND_GETCOND 9
137#define MAPLE_COMMAND_GETMINFO 10
138#define MAPLE_COMMAND_BREAD 11
139#define MAPLE_COMMAND_BWRITE 12
140#define MAPLE_COMMAND_BSYNC 13
141#define MAPLE_COMMAND_SETCOND 14
142#define MAPLE_COMMAND_MICCONTROL 15
143#define MAPLE_COMMAND_CAMCONTROL 17
160#define MAPLE_FUNC_PURUPURU 0x00010000
161#define MAPLE_FUNC_MOUSE 0x00020000
162#define MAPLE_FUNC_CAMERA 0x00080000
163#define MAPLE_FUNC_CONTROLLER 0x01000000
164#define MAPLE_FUNC_MEMCARD 0x02000000
165#define MAPLE_FUNC_LCD 0x04000000
166#define MAPLE_FUNC_CLOCK 0x08000000
167#define MAPLE_FUNC_MICROPHONE 0x10000000
168#define MAPLE_FUNC_ARGUN 0x20000000
169#define MAPLE_FUNC_KEYBOARD 0x40000000
170#define MAPLE_FUNC_LIGHTGUN 0x80000000
179LIST_HEAD(maple_driver_list, maple_driver);
181struct maple_state_str;
191typedef struct maple_frame {
207 void (*callback)(
struct maple_state_str *,
struct maple_frame *);
210 uint8_t recv_buf_arr[1024 + 1024 + 32];
212 uint8_t recv_buf_arr[1024 + 32];
221#define MAPLE_FRAME_VACANT 0
222#define MAPLE_FRAME_UNSENT 1
223#define MAPLE_FRAME_SENT 2
224#define MAPLE_FRAME_RESPONDED 3
237typedef struct maple_devinfo {
239 uint32_t function_data[3];
242 char product_name[30] __attribute__ ((nonstring));
243 char product_license[60] __attribute__ ((nonstring));
256typedef struct maple_response {
272typedef struct maple_device {
291#define MAPLE_PORT_COUNT 4
292#define MAPLE_UNIT_COUNT 6
302typedef struct maple_port {
318typedef struct maple_driver {
336 void (*periodic)(
struct maple_driver *drv);
390typedef struct maple_state_str {
392 struct maple_driver_list driver_list;
395 struct maple_frame_queue frame_queue;
436#define MAPLE_DMA_SIZE 16384
443#define maple_read(A) ( *((volatile uint32_t*)(A)) )
448#define maple_write(A, V) ( *((volatile uint32_t*)(A)) = (V) )
456#define MAPLE_EFAIL -1
457#define MAPLE_EAGAIN -2
458#define MAPLE_EINVALID -3
459#define MAPLE_ENOTSUPP -4
460#define MAPLE_ETIMEOUT -5
913#define MAPLE_FOREACH_BEGIN(TYPE, VARTYPE, VAR) \
915 maple_device_t * __dev; \
920 while( (__dev = maple_enum_type(__i, TYPE)) ) { \
921 VAR = (VARTYPE *)maple_dev_status(__dev); \
930#define MAPLE_FOREACH_END() \
static struct @69 data[BARRIER_COUNT]
Various common macros used throughout the codebase.
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:776
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.
maple_device_t * maple_enum_type(int n, uint32_t func)
Get the Nth device of the requested type (where N is zero-indexed).
int maple_driver_detach(int p, int u)
Detach an attached maple device.
uint8_t maple_addr(int port, int unit)
Return a "maple address" for a port, unit pair.
void maple_detach_callback(uint32_t functions, maple_detach_callback_t cb)
Set an automatic maple detach callback.
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.
void maple_attach_callback(uint32_t functions, maple_attach_callback_t cb)
Set an automatic maple attach callback.
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_frame_trylock(maple_frame_t *frame)
Try to 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.
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_sentinel_setup(void *buffer, int bufsize)
Setup a sentinel for debugging DMA issues.
maple_device_t * maple_enum_type_ex(int n, uint32_t func, uint32_t cap)
Return the Nth device that is of the requested type and supports the list of capabilities given.
void(* maple_attach_callback_t)(maple_device_t *dev)
Maple attach callback type.
Definition maple.h:755
void maple_vbl_irq_hnd(uint32_t code, void *data)
Called on every VBL (~60fps).
void maple_sentinel_verify(const char *bufname, void *buffer, int bufsize)
Verify the presence of the sentine.
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.
const char * maple_pcaps(uint32_t functions)
Return a string with the capabilities of a given function code.
void maple_dma_stop(void)
Stop a Maple DMA.
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_dma_irq_hnd(uint32_t code, void *data)
Called after a Maple DMA send / receive pair completes.
void maple_raddr(uint8_t addr, int *port, int *unit)
Decompose a "maple address" into a port, unit pair.
int maple_dma_in_progress(void)
Is a Maple DMA in progress?
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.
typedef TAILQ_HEAD(http_state_list, http_state)
Definition httpd.c:24
#define MAPLE_PORT_COUNT
Number of ports on the bus.
Definition maple.h:291
#define MAPLE_UNIT_COUNT
Max number of units per port.
Definition maple.h:292
static char buffer[256]
Definition porthelper.c:11
static GLint y
Definition scissor.c:38
static GLint x
Definition scissor.c:38
__noinline void func(void)
Definition stacktrace.c:13
One maple device.
Definition maple.h:272
void * status
Status buffer (for pollable devices)
Definition maple.h:288
int unit
Unit number, off of the port.
Definition maple.h:276
uint8_t dev_mask
Device-present mask for unit 0's.
Definition maple.h:284
maple_devinfo_t info
Device info struct.
Definition maple.h:277
maple_frame_t frame
One rx/tx frame.
Definition maple.h:280
uint8_t probe_mask
Mask of sub-devices left to probe.
Definition maple.h:283
volatile uint8_t status_valid
Have we got our first status update?
Definition maple.h:286
int port
Maple bus port connected to.
Definition maple.h:275
bool valid
Is this a valid device?
Definition maple.h:274
struct maple_driver * drv
Driver which handles this device.
Definition maple.h:281
Maple device info structure.
Definition maple.h:237
uint32_t functions
Function codes supported.
Definition maple.h:238
uint8_t area_code
Region code.
Definition maple.h:240
uint16_t max_power
Power consumption (max)
Definition maple.h:245
uint8_t connector_direction
0: UP (most controllers), 1: DOWN (lightgun, microphones)
Definition maple.h:241
uint16_t standby_power
Power consumption (standby)
Definition maple.h:244
A maple device driver.
Definition maple.h:318
LIST_ENTRY(maple_driver) drv_list
Driver list handle.
const char * name
The driver name.
Definition maple.h:323
uint32_t functions
One or more MAPLE_FUNCs ORed together.
Definition maple.h:322
size_t status_size
The size of the status buffer.
Definition maple.h:325
Maple frame to be queued for transport.
Definition maple.h:191
uint8_t * recv_buf
Points into recv_buf_arr, but 32-byte aligned.
Definition maple.h:203
uint32_t * send_buf
The data which will be sent (if any)
Definition maple.h:202
volatile int queued
Are we on the queue?
Definition maple.h:200
int cmd
Command (see Commands and Responses)
Definition maple.h:195
int dst_port
Destination port.
Definition maple.h:196
struct maple_device * dev
Does this belong to a device?
Definition maple.h:205
int dst_unit
Destination unit.
Definition maple.h:197
TAILQ_ENTRY(maple_frame) frameq
Send queue handle.
int length
Data transfer length in 32-bit words.
Definition maple.h:198
volatile int state
Has this frame been sent / responded to?
Definition maple.h:199
Internal representation of a Maple port.
Definition maple.h:302
int port
Port ID.
Definition maple.h:303
Maple response frame structure.
Definition maple.h:256
uint8_t data_len
Data length (in 32-bit words)
Definition maple.h:260
int8_t response
Response.
Definition maple.h:257
uint8_t dst_addr
Destination address.
Definition maple.h:258
uint8_t src_addr
Source address.
Definition maple.h:259
Maple state structure.
Definition maple.h:390
volatile int dma_in_progress
Is a DMA running now?
Definition maple.h:410
int vbl_handle
Our vblank handler handle.
Definition maple.h:419
volatile int dma_cntr
DMA interrupt counter.
Definition maple.h:401
volatile int vbl_cntr
VBlank interrupt counter.
Definition maple.h:404
int gun_x
The horizontal position of the lightgun signal.
Definition maple.h:425
volatile uint8_t scan_ready_mask
Mask of ports that completed the initial scan.
Definition maple.h:416
int gun_y
The vertical position of the lightgun signal.
Definition maple.h:428
uint8_t detect_port_next
Next port that will be auto-detected.
Definition maple.h:413
uint8_t * dma_buffer
DMA send buffer.
Definition maple.h:407
int gun_port
The port to read for lightgun status, if any.
Definition maple.h:422