/* Send an ADB retransmit (Talk, appended to the request queue) */
static void macii_retransmit(int device)
{
	static int in_retransmit = 0;
	static struct adb_request rt;
	unsigned long flags;
	
	if (in_retransmit) printk("macii_retransmit: double retransmit!\n");

	in_retransmit++;

	adb_request(&rt, NULL, ADBREQ_REPLY|ADBREQ_NOSEND, 1,
		    ADB_READREG(device, 0));

	save_flags(flags);
	cli();

	if (current_req != NULL) {
		last_req->next = &rt;
		last_req = &rt;
	} else {
		current_req = &rt;
		last_req = &rt;
	}

	if (macii_state == idle) macii_start();

	restore_flags(flags);
	in_retransmit--;
}
/* Send an ADB poll (Talk Register 0 command, tagged on the front of the request queue) */
static void macii_queue_poll(void)
{
	static int device = 0;
	static int in_poll=0;
	static struct adb_request req;
	unsigned long flags;
	
	if (in_poll) printk("macii_queue_poll: double poll!\n");

	in_poll++;
	if (++device > 15) device = 1;

	adb_request(&req, NULL, ADBREQ_REPLY|ADBREQ_NOSEND, 1,
		    ADB_READREG(device, 0));

	save_flags(flags);
	cli();

	req.next = current_req;
	current_req = &req;

	restore_flags(flags);
	macii_start();
	in_poll--;
}
Esempio n. 3
0
static int
mouse_read_reg( adb_device_t *ad, int reg, unsigned char *retbuf )
{
	struct mouse_status *ms = (struct mouse_status*)ad->usr;
	int len=0, dx, dy;
	mouse_byte_t *mb;

	retbuf[0] = ADB_PACKET;
	retbuf[1] = 0x40;	/* experimentally */
	retbuf[2] = ADB_READREG( ad->id, reg );

	/* printm("mouse_read_reg\n"); */
	switch( reg ){
	case 0: /* mouse data */
		if( !ms->dirty ) {
			ad->service_req = 0;
			/* No package is returned if no mouse event is queued */
			break;
		}
		
		dx = ms->dx;
		dy = ms->dy;
		if( dx > 63 )
			dx = 63;
		else if (dx < -64 ) 
			dx = -64;
		if( dy > 63 ) 
			dy = 63;
		else if (dy < -64 ) 
			dy = -64;
		mb = (mouse_byte_t*)&retbuf[3];
		mb->delta = dy;
		mb->button = (ms->buttons & kButton1)? 1 : 0;
		(++mb)->delta = dx;
		mb->button = (ms->buttons & kButton2)? 1 : 0;
		ms->dx -= dx;
		ms->dy -= dy;

		len = 5;
		if( !ms->dx && !ms->dy ) {
			ms->dirty = ad->service_req = 0;
		}
		break;
	default:
		printm("mouse_read_reg, unexpected regster %d\n", reg );
		retbuf[3] = 0;
		len = 4;
		break;
	}
	return len;
}
Esempio n. 4
0
/* Try to change handler to new_id. Will return 1 if successful. */
static int try_handler_change(int address, int new_id)
{
	struct adb_request req;

	if (adb_handler[address].handler_id == new_id)
	    return 1;
	adb_request(&req, NULL, ADBREQ_SYNC, 3,
	    ADB_WRITEREG(address, 3), address | 0x20, new_id);
	adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
	    ADB_READREG(address, 3));
	if (req.reply_len < 2)
	    return 0;
	if (req.reply[2] != new_id)
	    return 0;
	adb_handler[address].handler_id = req.reply[2];

	return 1;
}
Esempio n. 5
0
static int
kbd_read_reg( adb_device_t *ad, int reg, unsigned char *retbuf )
{
	struct kbd_status *ks = (struct kbd_status*)ad->usr;
	int i, len;

	len = 0;
	retbuf[0] = ADB_PACKET;
	retbuf[1] = 0x40;	/* experimentally */
	retbuf[2] = ADB_READREG( ad->id, reg );


	/* printm("kbd_read_reg\n"); */

	switch( reg ){
	case 0: /* key data */
		retbuf[3] = retbuf[4] = 0xff;
		for(i=3; i<=4; i++ )
			if( ks->buf_bot != ks->buf_top ) {
				retbuf[i] = ks->buf[ ks->buf_bot++ ];
				ks->buf_bot &= KEY_BUF_MASK;
			}
		if( ks->buf_bot == ks->buf_top )
			ad->service_req = 0;
		if( retbuf[3] != 0xff )
			len = 5;
		/* No package should be returned if no key event is queued */
		break;
	case 2: /* XXX: Here we should reply led + modifier status */
		retbuf[3] = 0xff;
		retbuf[4] = 0xff;
		len = 5;
		break;		
	default:
		printm("KBD: kbd_read_reg, unexpected regster %d\n", reg );
		len = 3;
		break;
	}
	return len;
}