70#define MAPLE_DMA_DEBUG 0
80#define MAPLE_IRQ_DEBUG 0
91#define MAPLE_BASE 0xa05f6c00
92#define MAPLE_DMA_ADDR (MAPLE_BASE+0x04)
93#define MAPLE_DMA_TSEL (MAPLE_BASE+0x10)
94#define MAPLE_ENABLE (MAPLE_BASE+0x14)
95#define MAPLE_STATE (MAPLE_BASE+0x18)
96#define MAPLE_SPEED (MAPLE_BASE+0x80)
97#define MAPLE_DMA_PROT (MAPLE_BASE+0x8c)
109#define MAPLE_DMA_TSEL_SOFTWARE 0
110#define MAPLE_DMA_TSEL_VBLANK 1
111#define MAPLE_ENABLE_ENABLED 1
112#define MAPLE_ENABLE_DISABLED 0
113#define MAPLE_STATE_IDLE 0
114#define MAPLE_STATE_DMA 1
115#define MAPLE_SPEED_1MBPS 0x0100
116#define MAPLE_SPEED_2MBPS 0x0000
117#define MAPLE_SPEED_4MBPS 0x0200
118#define MAPLE_SPEED_8MBPS 0x0300
119#define MAPLE_SPEED_TIMEOUT(n) ((n) << 16)
121#define MAPLE_DMA_PROT_MAGIC 0x61550000
134#define MAPLE_RESPONSE_FILEERR -5
135#define MAPLE_RESPONSE_AGAIN -4
136#define MAPLE_RESPONSE_BADCMD -3
137#define MAPLE_RESPONSE_BADFUNC -2
138#define MAPLE_RESPONSE_NONE -1
139#define MAPLE_COMMAND_DEVINFO 1
140#define MAPLE_COMMAND_ALLINFO 2
141#define MAPLE_COMMAND_RESET 3
142#define MAPLE_COMMAND_KILL 4
143#define MAPLE_RESPONSE_DEVINFO 5
144#define MAPLE_RESPONSE_ALLINFO 6
145#define MAPLE_RESPONSE_OK 7
146#define MAPLE_RESPONSE_DATATRF 8
147#define MAPLE_COMMAND_GETCOND 9
148#define MAPLE_COMMAND_GETMINFO 10
149#define MAPLE_COMMAND_BREAD 11
150#define MAPLE_COMMAND_BWRITE 12
151#define MAPLE_COMMAND_BSYNC 13
152#define MAPLE_COMMAND_SETCOND 14
153#define MAPLE_COMMAND_MICCONTROL 15
154#define MAPLE_COMMAND_CAMCONTROL 17
171#define MAPLE_FUNC_PURUPURU 0x00010000
172#define MAPLE_FUNC_MOUSE 0x00020000
173#define MAPLE_FUNC_CAMERA 0x00080000
174#define MAPLE_FUNC_CONTROLLER 0x01000000
175#define MAPLE_FUNC_MEMCARD 0x02000000
176#define MAPLE_FUNC_LCD 0x04000000
177#define MAPLE_FUNC_CLOCK 0x08000000
178#define MAPLE_FUNC_MICROPHONE 0x10000000
179#define MAPLE_FUNC_ARGUN 0x20000000
180#define MAPLE_FUNC_KEYBOARD 0x40000000
181#define MAPLE_FUNC_LIGHTGUN 0x80000000
182#define MAPLE_FUNC_MIE 0x00000001
183#define MAPLE_FUNC_ANY 0xffffffff
192LIST_HEAD(maple_driver_list, maple_driver);
194struct maple_state_str;
204typedef struct maple_frame {
220 void (*callback)(
struct maple_state_str *,
struct maple_frame *);
223 uint8_t recv_buf_arr[1024 + 1024 + 32];
225 uint8_t recv_buf_arr[1024 + 32];
234#define MAPLE_FRAME_VACANT 0
235#define MAPLE_FRAME_UNSENT 1
236#define MAPLE_FRAME_SENT 2
237#define MAPLE_FRAME_RESPONDED 3
250typedef struct maple_devinfo {
252 uint32_t function_data[3];
255 char product_name[30] __attribute__ ((nonstring));
256 char product_license[60] __attribute__ ((nonstring));
269typedef struct maple_response {
279#define MAPLE_DEV_VALID_TIMEOUT 30
290typedef struct maple_device {
307#define MAPLE_PORT_COUNT 4
308#define MAPLE_UNIT_COUNT 6
318typedef struct maple_port {
335#define maple_attach_callback_t __depr("Use the type maple_user_callback_t rather than maple_attach_callback_t.") maple_user_callback_t
336#define maple_detach_callback_t __depr("Use the type maple_user_callback_t rather than maple_detach_callback_t.") maple_user_callback_t
350typedef struct maple_driver {
368 void (*periodic)(
struct maple_driver *drv);
428typedef struct maple_state_str {
430 struct maple_driver_list driver_list;
433 struct maple_frame_queue frame_queue;
477#define MAPLE_DMA_SIZE 16384
484#define maple_read(A) ( *((volatile uint32_t*)(A)) )
489#define maple_write(A, V) ( *((volatile uint32_t*)(A)) = (V) )
497#define MAPLE_EFAIL -1
498#define MAPLE_EAGAIN -2
499#define MAPLE_EINVALID -3
500#define MAPLE_ENOTSUPP -4
501#define MAPLE_ETIMEOUT -5
946#define MAPLE_FOREACH_BEGIN(TYPE, VARTYPE, VAR) \
948 maple_device_t *__dev; \
952 while( (__dev = maple_enum_type(__i, TYPE)) ) { \
953 VAR = (VARTYPE *)maple_dev_status(__dev); \
962#define MAPLE_FOREACH_END() \
static struct @89 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(uint32_t functions, maple_user_callback_t cb, void *user_data)
Set an automatic maple detach callback.
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.
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_user_callback_t)(maple_device_t *dev, void *user_data)
Maple user callback type.
Definition maple.h:331
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_frame_trylock(maple_frame_t *frame)
Try to lock a frame so that someone else can't use it in the mean time.
void maple_attach_callback(uint32_t functions, maple_user_callback_t cb, void *user_data)
Set an automatic maple attach callback.
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_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 TAILQ_HEAD(http_state_list, http_state)
Definition httpd.c:24
#define MAPLE_PORT_COUNT
Number of ports on the bus.
Definition maple.h:307
#define MAPLE_UNIT_COUNT
Max number of units per port.
Definition maple.h:308
int y
Definition example.c:183
static char buffer[256]
Definition porthelper.c:11
One maple device.
Definition maple.h:290
void * status
Status buffer (for pollable devices)
Definition maple.h:304
int unit
Unit number, off of the port.
Definition maple.h:294
uint8_t dev_mask
Device-present mask for unit 0's.
Definition maple.h:302
maple_devinfo_t info
Device info struct.
Definition maple.h:295
uint8_t valid
Is this a valid device? 0 for no.
Definition maple.h:292
maple_frame_t frame
One rx/tx frame.
Definition maple.h:298
uint8_t probe_mask
Mask of sub-devices left to probe.
Definition maple.h:301
int port
Maple bus port connected to.
Definition maple.h:293
struct maple_driver * drv
Driver which handles this device.
Definition maple.h:299
Maple device info structure.
Definition maple.h:250
uint32_t functions
Function codes supported.
Definition maple.h:251
uint8_t area_code
Region code.
Definition maple.h:253
uint16_t max_power
Power consumption (max)
Definition maple.h:258
uint8_t connector_direction
0: UP (most controllers), 1: DOWN (lightgun, microphones)
Definition maple.h:254
uint16_t standby_power
Power consumption (standby)
Definition maple.h:257
A maple device driver.
Definition maple.h:350
maple_user_callback_t user_detach
User-specified device detached callback.
Definition maple.h:411
LIST_ENTRY(maple_driver) drv_list
Driver list handle.
const char * name
The driver name.
Definition maple.h:355
uint32_t functions
One or more MAPLE_FUNCs ORed together.
Definition maple.h:354
size_t status_size
The size of the status buffer.
Definition maple.h:357
void * user_detach_data
User-specified device detached callback data.
Definition maple.h:417
void * user_attach_data
User-specified device attached callback data.
Definition maple.h:403
maple_user_callback_t user_attach
User-specified device attached callback.
Definition maple.h:397
Maple frame to be queued for transport.
Definition maple.h:204
uint8_t * recv_buf
Points into recv_buf_arr, but 32-byte aligned.
Definition maple.h:216
uint32_t * send_buf
The data which will be sent (if any)
Definition maple.h:215
volatile int queued
Are we on the queue?
Definition maple.h:213
int cmd
Command (see Commands and Responses)
Definition maple.h:208
int dst_port
Destination port.
Definition maple.h:209
struct maple_device * dev
Does this belong to a device?
Definition maple.h:218
int dst_unit
Destination unit.
Definition maple.h:210
TAILQ_ENTRY(maple_frame) frameq
Send queue handle.
int length
Data transfer length in 32-bit words.
Definition maple.h:211
volatile int state
Has this frame been sent / responded to?
Definition maple.h:212
Internal representation of a Maple port.
Definition maple.h:318
int port
Port ID.
Definition maple.h:319
Maple response frame structure.
Definition maple.h:269
uint8_t data_len
Data length (in 32-bit words)
Definition maple.h:273
int8_t response
Response.
Definition maple.h:270
uint8_t dst_addr
Destination address.
Definition maple.h:271
uint8_t src_addr
Source address.
Definition maple.h:272
Maple state structure.
Definition maple.h:428
volatile int dma_in_progress
Is a DMA running now?
Definition maple.h:448
uint8_t port0_mie
Port A is MIE (skip autodetect on port 0).
Definition maple.h:457
int vbl_handle
Our vblank handler handle.
Definition maple.h:460
volatile int dma_cntr
DMA interrupt counter.
Definition maple.h:439
volatile int vbl_cntr
VBlank interrupt counter.
Definition maple.h:442
int gun_x
The horizontal position of the lightgun signal.
Definition maple.h:466
volatile uint8_t scan_ready_mask
Mask of ports that completed the initial scan.
Definition maple.h:454
int gun_y
The vertical position of the lightgun signal.
Definition maple.h:469
uint8_t detect_port_next
Next port that will be auto-detected.
Definition maple.h:451
uint8_t * dma_buffer
DMA send buffer.
Definition maple.h:445
int gun_port
The port to read for lightgun status, if any.
Definition maple.h:463