/* ################################################################################ # Example program using libieee1284 to operate a MDE8255-1 LPT device # # Created by: Travis Sidelinger <travis@ilive4code.net> # # Version History: # 2005Oct24 : removed the ieee1284 negotiate line # 2005Oct22 : initial release # # Notes: This program does not work, and I can't figure out why # # Copyright: # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################################################ */ #include <stdio.h> #include <string.h> #include <ieee1284.h> #include <unistd.h> #include <errno.h> #define PORTNUM 0 #define DELAY 1000 extern int errno; /**************************** Function Declarations ***************************/ void list_capabilities(int cap); /************************************ Main ************************************/ int main () { /* Variables */ struct parport_list pl; struct parport *port; unsigned int cap; int errcode = 0; printf("Finding the port\n"); ieee1284_find_ports(&pl, 0); if(errcode != E1284_OK) { printf("Failed to find any ports.\n"); switch(errcode) { case E1284_NOMEM : printf("There is not enough memory.\n"); break; case E1284_NOTIMPL : printf("One or more of the supplied flags is not supported in this implementation.\n"); break; } } else { port = pl.portv[PORTNUM]; /* open the port */ printf("Opening the port\n"); errcode = ieee1284_open(port, F1284_EXCL, &cap); if(errcode != E1284_OK) { printf ("Failed to open port: %s\n", port->name); switch(errcode) { case E1284_INIT : printf("There was a problem during port initialization. This could be because another driver has opened the port exclusively, or some other reason.\n"); break; case E1284_NOMEM : printf("There is not enough memory.\n"); break; case E1284_NOTAVAIL : printf("One or more of the supplied flags is not supported by this type of port.\n"); break; case E1284_INVALIDPORT : printf("The port parameter is invalid (for instance, the port may already be open).\n"); break; case E1284_SYS : perror("There was a problem at the operating system level\n"); errcode = errno; break; } } else { list_capabilities(cap); /* Check port capacities */ errcode = 0; if((cap&CAP1284_RAW) == 0) { printf("The port does not support raw mode: %d\n", cap); errcode = CAP1284_RAW; } if((cap&CAP1284_BYTE) == 0) { printf("The port does not support byte mode: %d\n", cap); errcode = CAP1284_BYTE; } if(errcode == 0) { printf ("Port info: %s %#lx %d\n", port->name, port->base_addr, cap); /* claim access to the ports */ errcode = ieee1284_claim(port); if(errcode != E1284_OK) { printf ("Failed to claim the port: %s\n", port->name); switch(errcode) { case E1284_NOMEM : printf("There is not enough memory.\n"); break; case E1284_INVALIDPORT : printf("The port parameter is invalid (for instance, it might not have been opened yet).\n"); break; case E1284_SYS : perror("There was a problem at the operating system level\n"); errcode = errno; break; } } else { /* do some data I/O */ printf("Configuring the MDE device\n"); ieee1284_write_data (port, 0x80); usleep(DELAY); ieee1284_write_control(port, 0x0F); usleep(DELAY); ieee1284_write_control(port, 0x07); usleep(DELAY); ieee1284_write_control(port, 0x0F); usleep(DELAY); printf("Sending data\n"); ieee1284_write_data (port, 0xFF); usleep(DELAY); ieee1284_write_control(port, 0x0E); usleep(DELAY); ieee1284_write_control(port, 0x06); usleep(DELAY); ieee1284_write_control(port, 0x0E); usleep(DELAY); //data = ieee1284_read_data(port); //printf("Data read from parallel port: %d\n", data); //errcode = ieee1284_clear_irq (port, NULL); ieee1284_release(port); } /* Close the ports */ ieee1284_close(port); } } } /* safely deallocate a port list */ ieee1284_free_ports(&pl); return(errcode); } /********************************* Functions **********************************/ /* Description: This function prints the supported modes */ void list_capabilities(int cap) { printf("Supported modes: "); if((cap&CAP1284_RAW)) printf("RAW "); if((cap&CAP1284_NIBBLE)) printf("NIBBLE "); if((cap&CAP1284_BYTE)) printf("BYTE "); if((cap&CAP1284_COMPAT)) printf("COMPAT "); if((cap&CAP1284_ECP)) printf("ECP "); if((cap&CAP1284_ECPRLE)) printf("ECPRLE "); if((cap&CAP1284_ECPSWE)) printf("ECPSWE "); if((cap&CAP1284_BECP)) printf("BECP "); if((cap&CAP1284_EPP)) printf("EPP "); if((cap&CAP1284_EPPSWE)) printf("EPPSWE "); if((cap&CAP1284_IRQ)) printf("IRQ "); if((cap&CAP1284_DMA)) printf("DMA "); printf("\n"); return; }