File indexing completed on 2025-05-11 08:24:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
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
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
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
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
0110
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
0121
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
0131
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 }