/*-
* Copyright (c) 2019 Michael Lorenz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* State info, per mouse instance.
*/
struct ktm_softc {
device_t sc_dev;
struct adb_device *sc_adbdev;
struct adb_bus_accessops *sc_ops;
uint8_t sc_us; /* cmd to watch for */
device_t sc_wsmousedev;
/* buffers */
uint8_t sc_config[8];
int sc_left;
int sc_right;
int sc_poll;
int sc_msg_len;
kcondvar_t sc_event;
kmutex_t sc_interlock;
uint8_t sc_buffer[16];
};
/*
* byte 0
- 0x80 enables EMP output
- 0x08 seems to map both buttons together
- 0x04 enables the 2nd button
- initialized to 0x20 on power up, no idea what that does
* byte 2 - 0x40 on powerup, seems to do nothing
* byte 3 - 0x01 on powerup, seems to do nothing
* byte 4 programs a delay for button presses, apparently in 1/100 seconds
* byte 5 and 6 init to 0xff
* byte 7 is a simple XOR checksum, writes will only stick if it's valid
as in, b[7] = (b[0] ^ b[1] ^ ... ^ b[6]) ^ 0xff
*/
/* this seems to be the most reasonable default */
uint8_t data[8] = { 0xa5, 0x0e, 0, 0, 1, 0xff, 0xff, 0 };
memcpy(sc->sc_config, data, sizeof(data));
sc->sc_left = 1;
sc->sc_right = 3;
ktm_buttons(sc);
#ifdef KTM_DEBUG
int addr = sc->sc_adbdev->current_addr;
{
int i;
ktm_send_sync(sc, ADBTALK(addr, 2), 0, NULL);
printf("reg *");
for (i = 0; i < sc->sc_msg_len; i++)
printf(" %02x", sc->sc_buffer[i]);
printf("\n");
}
#endif
ktm_write_config(sc);
#ifdef KTM_DEBUG
int i, reg;
for (reg = 1; reg < 4; reg++) {
ktm_send_sync(sc, ADBTALK(addr, reg), 0, NULL);
printf("reg %d", reg);
for (i = 0; i < sc->sc_msg_len; i++)
printf(" %02x", sc->sc_buffer[i]);
printf("\n");
}
#endif
ret = sysctl_createv(NULL, 0, NULL, &me,
CTLFLAG_READWRITE,
CTLTYPE_NODE, device_xname(sc->sc_dev), NULL,
NULL, 0, NULL, 0,
CTL_MACHDEP, CTL_CREATE, CTL_EOL);