Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:18

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup libmisc_mouse Serial Mouse Driver
0007  *
0008  * @brief Serial Mouse Driver
0009  */
0010 
0011 /*
0012  *  COPYRIGHT (c) 1989-2011.
0013  *  On-Line Applications Research Corporation (OAR).
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <stdio.h>
0038 #include <stdlib.h>
0039 #include <sys/types.h>
0040 #include <sys/stat.h>
0041 #include <fcntl.h>
0042 
0043 #include <rtems/bspIo.h>
0044 #include <rtems/libio.h>
0045 #include <termios.h>
0046 #include <rtems/termiostypes.h>
0047 #include <rtems/mouse_parser.h>
0048 #include <rtems/serial_mouse.h>
0049 
0050 int         serial_mouse_fd = -1;
0051 const char *serial_mouse_device;
0052 const char *serial_mouse_type;
0053 
0054 static int serial_mouse_l_rint(int c, struct rtems_termios_tty *tp)
0055 {
0056   unsigned char buf = c;
0057 
0058   /* call mouse_parser( void *ptr, char *buffer, int size ) */
0059   mouse_parser_enqueue( &buf, 1 );
0060   return 0;
0061 }
0062 
0063 static struct rtems_termios_linesw serial_mouse_linesw = {
0064   .l_open = NULL,
0065   .l_close = NULL,
0066   .l_read  = NULL,
0067   .l_write = NULL,
0068   .l_rint  = serial_mouse_l_rint,
0069   .l_start = NULL,
0070   .l_ioctl = NULL,
0071   .l_modem = NULL
0072 };
0073 
0074 
0075 /*
0076  *  Serial Mouse - device driver INITIALIZE entry point.
0077  */
0078 rtems_device_driver serial_mouse_initialize(
0079   rtems_device_major_number  major,
0080   rtems_device_minor_number  minor,
0081   void                      *arg
0082 )
0083 {
0084   bsp_get_serial_mouse_device(
0085     &serial_mouse_device,
0086     &serial_mouse_type
0087   );
0088 
0089   (void) rtems_io_register_name( "/dev/mouse", major, 0 );
0090 
0091   rtems_termios_linesw[ 6 ] = serial_mouse_linesw;
0092 
0093   return RTEMS_SUCCESSFUL;
0094 }
0095 
0096 /*
0097  * serial_mouse - device driver OPEN entry point
0098  */
0099 rtems_device_driver serial_mouse_open(
0100   rtems_device_major_number  major,
0101   rtems_device_minor_number  minor,
0102   void                      *args
0103 )
0104 {
0105   struct termios  termios_attr;
0106   int             status;
0107   int             disc = 6;
0108 
0109   /* XXX open(2) the configured /dev/comX */
0110   /* XXX save the file descriptor */
0111   serial_mouse_fd = open( serial_mouse_device, O_RDONLY );
0112   if ( serial_mouse_fd == -1 ) {
0113    printk(
0114      "Error opening serial_mouse device on %s\n",
0115      serial_mouse_device
0116    );
0117    return RTEMS_IO_ERROR;
0118   }
0119 
0120   /* 1200-8-N-1, without hardware flow control */
0121   /* BSP_uart_init( BSP_UART_PORT, 1200, CHR_8_BITS, 0, 0, 0 ); */
0122   status = tcgetattr(serial_mouse_fd, &termios_attr );
0123   if (status != 0) {
0124     printk("Error getting mouse attributes\n");
0125     return RTEMS_IO_ERROR;
0126   }
0127   termios_attr.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
0128   termios_attr.c_iflag &= ~(IXON|IXANY|IXOFF);
0129   /*
0130   termios_attr.c_cc[VMIN] = itask_VMIN;
0131   termios_attr.c_cc[VTIME] = itask_VTIME;
0132   */
0133   termios_attr.c_cflag |= B1200;
0134   termios_attr.c_cflag |= CS8;
0135   status = tcsetattr( serial_mouse_fd, TCSANOW, &termios_attr );
0136   if (status != 0) {
0137     printk("Error setting mouse attributes\n");
0138     return RTEMS_IO_ERROR;
0139   }
0140 
0141   status = ioctl(serial_mouse_fd, TIOCSETD, &disc);
0142   if (status != 0) {
0143     printk("Error setting mouse attributes\n");
0144     return RTEMS_IO_ERROR;
0145   }
0146 
0147   sleep(5);
0148   return RTEMS_SUCCESSFUL;
0149 }
0150 
0151 rtems_device_driver serial_mouse_close(
0152   rtems_device_major_number  major,
0153   rtems_device_minor_number  minor,
0154   void                      *arg
0155 )
0156 {
0157   close( serial_mouse_fd );
0158 
0159   return RTEMS_SUCCESSFUL;
0160 }
0161 
0162 rtems_device_driver serial_mouse_read(
0163   rtems_device_major_number  major,
0164   rtems_device_minor_number  minor,
0165   void                      *arg
0166 )
0167 {
0168   return RTEMS_SUCCESSFUL;
0169 }
0170 
0171 
0172 rtems_device_driver serial_mouse_write(
0173   rtems_device_major_number  major,
0174   rtems_device_minor_number  minor,
0175   void                      *arg
0176 )
0177 {
0178   return RTEMS_SUCCESSFUL;
0179 }
0180 
0181 
0182 rtems_device_driver serial_mouse_control(
0183   rtems_device_major_number  major,
0184   rtems_device_minor_number  minor,
0185   void                      *arg
0186 )
0187 {
0188   rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t *)arg;
0189 
0190   switch( args->command ) {
0191 
0192     case MW_UID_REGISTER_DEVICE:
0193       printk( "SerialMouse: reg=%s\n", (const char*) args->buffer );
0194       mouse_parser_initialize( serial_mouse_type );
0195       break;
0196 
0197     case MW_UID_UNREGISTER_DEVICE:
0198       break;
0199 
0200     default:
0201       args->ioctl_return = ioctl(serial_mouse_fd, args->command, args->buffer );
0202       if ( !args->ioctl_return )
0203         return RTEMS_SUCCESSFUL;
0204       return RTEMS_IO_ERROR;
0205   }
0206   args->ioctl_return = 0;
0207   return RTEMS_SUCCESSFUL;
0208 }