Exemplo n.º 1
0
static int lp_probe(int offset)
{
	int base, size;
	unsigned int testvalue;

	base = LP_B(offset);
	if (base == 0) 
		return -1;		/* de-configured by command line */
	if (LP_IRQ(offset) > 15) 
		return -1;		/* bogus interrupt value */
	size = (base == 0x3bc)? 3 : 8;
	if (check_region(base, size) < 0)
		return -1;
	/* write to port & read back to check */
	outb_p(LP_DUMMY, base);
	udelay(LP_DELAY);
	testvalue = inb_p(base);
	if (testvalue == LP_DUMMY) {
		LP_F(offset) |= LP_EXIST;
		lp_reset(offset);
		printk(KERN_INFO "lp%d at 0x%04x, ", offset, base);
		request_region(base, size, "lp");
		if (LP_IRQ(offset))
			printk("(irq = %d)\n", LP_IRQ(offset));
		else
			printk("(polling)\n");
		return 1;
	} else
		return 0;
}
Exemplo n.º 2
0
//int ptt_(int *unused, int *ntx, int *iptt)
int ptt_(int nport, int ntx, int *iptt, int *nopen)
{
  static int state=0;
  char *p;
  char ptt_port[]="/dev/ttyUSB0";
  fflush(stdout);

  // In the very unlikely event of a NULL pointer, just return.
  if (ptt_port == NULL) {
    *iptt = ntx;
    return (0);
  }
  switch (state) {
  case STATE_PORT_CLOSED:
 
  // Remove trailing ' '
    if ((p = strchr(ptt_port, ' ')) != NULL)
      *p = '\0';

  //  If all that is left is a '\0' then also just return
    if (*ptt_port == '\0') {
      *iptt = ntx;
      return(0);
    }
    if ((fd = open(ptt_port, O_RDWR|O_NONBLOCK)) < 0) {
	fprintf(stderr, "Can't open %s.\n", ptt_port);
	return (1);
    }
    if (dev_is_parport(fd)) {
      state = STATE_PORT_OPEN_PARALLEL;
      lp_reset(fd);
      ptt_parallel(fd, ntx, iptt);
    } else {
      state = STATE_PORT_OPEN_SERIAL;
      ptt_serial(fd, &ntx, iptt);
    }
    break;

  case STATE_PORT_OPEN_PARALLEL:
    ptt_parallel(fd, ntx, iptt);
    break;

  case STATE_PORT_OPEN_SERIAL:
    ptt_serial(fd, &ntx, iptt);
    break;

  default:
    close(fd);
    fd = -1;
    state = STATE_PORT_CLOSED;
    break;
  }
  *iptt=ntx;
  return(0);
}
Exemplo n.º 3
0
/* release ppdev and close port */
int
lp_free (int fd)
{
#ifdef HAVE_LINUX_PPDEV_H
	lp_reset (fd);

	/* Disable CW & PTT - /STROBE bit (pin 1) */
	parport_control (fd, PARPORT_CONTROL_STROBE, 0);

	ioctl (fd, PPRELEASE);
#endif
#ifdef HAVE_DEV_PPBUS_PPI_H
	/* Disable CW & PTT - /STROBE bit (pin 1) */
	parport_control (fd, STROBE, 0);
#endif
	close (fd);
	return(0);
}
Exemplo n.º 4
0
Arquivo: lp.c Projeto: lithoxs/elks
static size_t lp_write(struct inode *inode, struct file *file, char *buf, int count)
{
    register char *chrsp;

#if 0

    /* initialize printer */
    lp_reset(MINOR(inode->i_rdev));

#endif

    chrsp = 0;
    while (((int)chrsp) < count) {
	if (!lp_char_polled((int)get_user_char((void *)(buf++)),
			    MINOR(inode->i_rdev)))
	    break;
	chrsp++;
    }
    return (size_t)chrsp;
}
Exemplo n.º 5
0
/* Initialise a parallel port, given open fd */
int
lp_init (int fd)
{
#ifdef HAVE_LINUX_PPDEV_H
	int mode;
#endif

#ifdef HAVE_LINUX_PPDEV_H
	mode = PARPORT_MODE_PCSPP;

	if (ioctl (fd, PPSETMODE, &mode) == -1)
	{
		fprintf(stderr, "Setting parallel port mode");
		close (fd);
		return(-1);
	}

	if (ioctl (fd, PPEXCL, NULL) == -1)
	{
		fprintf(stderr, "Parallel port is already in use.\n");
		close (fd);
		return(-1);
	}
	if (ioctl (fd, PPCLAIM, NULL) == -1)
	{
		fprintf(stderr, "Claiming parallel port.\n");
		fprintf(stderr, "HINT: did you unload the lp kernel module?");
		close (fd);
		return(-1);
	}

	/* Enable CW & PTT - /STROBE bit (pin 1) */
	parport_control (fd, PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE);
#endif
#ifdef HAVE_DEV_PPBUS_PPI_H
	parport_control (fd, STROBE, STROBE);
#endif
	lp_reset (fd);
	return(0);
}
Exemplo n.º 6
0
static int lp_ioctl(struct inode *inode, struct file *file,
		    unsigned int cmd, unsigned long arg)
{
	unsigned int minor = MINOR(inode->i_rdev);
	int retval = 0;

#ifdef LP_DEBUG
	printk(KERN_DEBUG "lp%d ioctl, cmd: 0x%x, arg: 0x%x\n", minor, cmd, arg);
#endif
	if (minor >= LP_NO)
		return -ENODEV;
	if ((LP_F(minor) & LP_EXIST) == 0)
		return -ENODEV;
	switch ( cmd ) {
		case LPTIME:
			LP_TIME(minor) = arg * HZ/100;
			break;
		case LPCHAR:
			LP_CHAR(minor) = arg;
			break;
		case LPABORT:
			if (arg)
				LP_F(minor) |= LP_ABORT;
			else
				LP_F(minor) &= ~LP_ABORT;
			break;
		case LPABORTOPEN:
			if (arg)
				LP_F(minor) |= LP_ABORTOPEN;
			else
				LP_F(minor) &= ~LP_ABORTOPEN;
			break;
		case LPCAREFUL:
			if (arg)
				LP_F(minor) |= LP_CAREFUL;
			else
				LP_F(minor) &= ~LP_CAREFUL;
			break;
		case LPWAIT:
			LP_WAIT(minor) = arg;
			break;
		case LPSETIRQ: {
			int oldirq;
			int newirq = arg;
			struct lp_struct *lp = &lp_table[minor];

			if (!suser())
				return -EPERM;

			oldirq = LP_IRQ(minor);

			/* Allocate buffer now if we are going to need it */
			if (!oldirq && newirq) {
				lp->lp_buffer = (char *) kmalloc(LP_BUFFER_SIZE, GFP_KERNEL);
				if (!lp->lp_buffer)
					return -ENOMEM;
			}

			if (oldirq) {
				free_irq(oldirq, NULL);
			}
			if (newirq) {
				/* Install new irq */
				if ((retval = request_irq(newirq, lp_interrupt, SA_INTERRUPT, "printer", NULL))) {
					if (oldirq) {
						/* restore old irq */
						request_irq(oldirq, lp_interrupt, SA_INTERRUPT, "printer", NULL);
					} else {
						/* We don't need the buffer */
						kfree_s(lp->lp_buffer, LP_BUFFER_SIZE);
						lp->lp_buffer = NULL;
					}
					return retval;
				}
			}
			if (oldirq && !newirq) {
				/* We don't need the buffer */
				kfree_s(lp->lp_buffer, LP_BUFFER_SIZE);
				lp->lp_buffer = NULL;
			}
			LP_IRQ(minor) = newirq;
			lp_reset(minor);
			break;
		}
		case LPGETIRQ:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
			    sizeof(int));
		    	if (retval)
		    		return retval;
			memcpy_tofs((int *) arg, &LP_IRQ(minor), sizeof(int));
			break;
		case LPGETSTATUS:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
			    sizeof(int));
		    	if (retval)
		    		return retval;
			else {
				int status = LP_S(minor);
				memcpy_tofs((int *) arg, &status, sizeof(int));
			}
			break;
		case LPRESET:
			lp_reset(minor);
			break;
		case LPGETSTATS:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
			    sizeof(struct lp_stats));
		    	if (retval)
		    		return retval;
			else {
				memcpy_tofs((int *) arg, &LP_STAT(minor), sizeof(struct lp_stats));
				if (suser())
					memset(&LP_STAT(minor), 0, sizeof(struct lp_stats));
			}
			break;
 		case LPGETFLAGS:
 			retval = verify_area(VERIFY_WRITE, (void *) arg,
 			    sizeof(int));
 		    	if (retval)
 		    		return retval;
 			else {
 				int status = LP_F(minor);
				memcpy_tofs((int *) arg, &status, sizeof(int));
			}
			break;
		default:
			retval = -EINVAL;
	}
	return retval;
}
Exemplo n.º 7
0
t_stat lp_settype (UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{
lp_model = val;
lp_reset (&lp_dev);
return SCPE_OK;
}
Exemplo n.º 8
0
int reset_handler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
{
	lp_reset(lp);
	return 0;
}
Exemplo n.º 9
0
struct launchpad* lp_register()
{
    struct launchpad *lp;
    
    //build the struct
    lp = malloc(sizeof(struct launchpad));
    if (lp == NULL) {
	fprintf(stderr,"Unable to allocate memory\n");
	return NULL;
    }
    
    //initialize usb
    if(libusb_init(NULL)!=0){
	fprintf(stderr,"Unable to initialize usb\n");
	return NULL;
    } else {
        printf("usb initialized\n");
    }
    
    //find the device
    lp->device = libusb_open_device_with_vid_pid(NULL, ID_VENDOR, ID_PRODUCT);
    if (lp->device == NULL) {
	fprintf(stderr,"Unable to find the launchpad\n");
 	return NULL;
    } else {
        printf("launchpad found\n");
    }
    
    //claim the device
    if(libusb_claim_interface(lp->device, 0) != 0) {
	fprintf(stderr,"Unable to claim the launchpad\n");
	return NULL;
    } else {
	printf("launchpad claimed\n");
    }
  
    //allocate input buffer
    lp->rdata = malloc(sizeof(unsigned char)*MAX_PACKET_SIZE);
    
    if (lp->rdata == NULL) {
	fprintf(stderr,"could not allocate input buffer\n");
	return NULL;
    }
    
    //allocate output buffer
    lp->tdata = malloc(sizeof(unsigned char)*MAX_PACKET_SIZE);
  
    if (lp->tdata == NULL) {
	fprintf(stderr,"could not allocate output buffer\n");
	return NULL;
    }
        
    // initialize the protocol's state
    lp->event[0] = NOTE;
    lp->parse_at = 0;
    lp->received = 0;

    // reset launchpad
    lp_reset(lp);
    
    return lp;
}