adb.h 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * QEMU ADB emulation shared definitions and prototypes
 *
 * Copyright (c) 2004-2007 Fabrice Bellard
 * Copyright (c) 2007 Jocelyn Mayer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

26 27
#ifndef ADB_H
#define ADB_H
28

29
#include "hw/qdev-core.h"
30
#include "qom/object.h"
A
Andreas Färber 已提交
31

32 33 34 35
#define MAX_ADB_DEVICES 16

#define ADB_MAX_OUT_LEN 16

A
Andreas Färber 已提交
36
typedef struct ADBBusState ADBBusState;
37 38 39 40 41
typedef struct ADBDevice ADBDevice;

/* buf = NULL means polling */
typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
                              const uint8_t *buf, int len);
A
Andreas Färber 已提交
42

43 44
typedef bool ADBDeviceHasData(ADBDevice *d);

A
Andreas Färber 已提交
45
#define TYPE_ADB_DEVICE "adb-device"
46
OBJECT_DECLARE_TYPE(ADBDevice, ADBDeviceClass, ADB_DEVICE)
47 48

struct ADBDevice {
A
Andreas Färber 已提交
49 50 51 52
    /*< private >*/
    DeviceState parent_obj;
    /*< public >*/

53 54 55 56
    int devaddr;
    int handler;
};

A
Andreas Färber 已提交
57

58
struct ADBDeviceClass {
A
Andreas Färber 已提交
59 60 61 62 63
    /*< private >*/
    DeviceClass parent_class;
    /*< public >*/

    ADBDeviceRequest *devreq;
64
    ADBDeviceHasData *devhasdata;
65
};
A
Andreas Färber 已提交
66

A
Andreas Färber 已提交
67
#define TYPE_ADB_BUS "apple-desktop-bus"
E
Eduardo Habkost 已提交
68 69
DECLARE_INSTANCE_CHECKER(ADBBusState, ADB_BUS,
                         TYPE_ADB_BUS)
A
Andreas Färber 已提交
70

71 72 73
#define ADB_STATUS_BUSTIMEOUT  0x1
#define ADB_STATUS_POLLREPLY   0x2

A
Andreas Färber 已提交
74 75 76 77 78
struct ADBBusState {
    /*< private >*/
    BusState parent_obj;
    /*< public >*/

A
Andreas Färber 已提交
79
    ADBDevice *devices[MAX_ADB_DEVICES];
80
    uint16_t pending;
81 82
    int nb_devices;
    int poll_index;
83
    uint8_t status;
84 85 86

    QEMUTimer *autopoll_timer;
    bool autopoll_enabled;
87
    bool autopoll_blocked;
88 89 90 91
    uint8_t autopoll_rate_ms;
    uint16_t autopoll_mask;
    void (*autopoll_cb)(void *opaque);
    void *autopoll_cb_opaque;
A
Andreas Färber 已提交
92
};
93 94 95

int adb_request(ADBBusState *s, uint8_t *buf_out,
                const uint8_t *buf, int len);
96
int adb_poll(ADBBusState *s, uint8_t *buf_out, uint16_t poll_mask);
97

98 99 100
void adb_autopoll_block(ADBBusState *s);
void adb_autopoll_unblock(ADBBusState *s);

101 102 103 104 105 106
void adb_set_autopoll_enabled(ADBBusState *s, bool enabled);
void adb_set_autopoll_rate_ms(ADBBusState *s, int rate_ms);
void adb_set_autopoll_mask(ADBBusState *s, uint16_t mask);
void adb_register_autopoll_callback(ADBBusState *s, void (*cb)(void *opaque),
                                    void *opaque);

A
Andreas Färber 已提交
107 108
#define TYPE_ADB_KEYBOARD "adb-keyboard"
#define TYPE_ADB_MOUSE "adb-mouse"
109

110
#endif /* ADB_H */