Further tinkering with LPT
This commit is contained in:
parent
94097ace40
commit
50c871600d
|
@ -508,47 +508,74 @@ short cli_test_lpt(short screen, int argc, const char * argv[]) {
|
|||
|
||||
sprintf(message, "Test parallel port:\nF1: DATA=00 F2: DATA=FF F3: STRB=1 F4: STRB=0\n");
|
||||
sys_chan_write(screen, message, strlen(message));
|
||||
sprintf(message, "F5: INIT=1 F6: INIT=0 F7: SEL=1 F8: SEL=0\nESC: Quit");
|
||||
sprintf(message, "F5: INIT=1 F6: INIT=0 F7: SEL=1 F8: SEL=0\nESC: Quit\n");
|
||||
sys_chan_write(screen, message, strlen(message));
|
||||
|
||||
unsigned char ctrl = 0;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
|
||||
while (1) {
|
||||
scancode = sys_kbd_scancode();
|
||||
switch (scancode) {
|
||||
case 0x3B: /* F1 */
|
||||
print(0, "DATA = 0x00\n");
|
||||
*LPT_DATA_PORT = 0;
|
||||
break;
|
||||
|
||||
case 0x3C: /* F2 */
|
||||
*LPT_DATA_PORT = 0xff;
|
||||
print(0, "DATA = 'A'\n");
|
||||
*LPT_DATA_PORT = 'A';
|
||||
break;
|
||||
|
||||
case 0x3D: /* F3 */
|
||||
*LPT_CTRL_PORT = LPT_CTRL_STROBE;
|
||||
ctrl |= LPT_CTRL_STROBE;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
sprintf(message, "STROBE = TRUE [%02X]\n", ctrl);
|
||||
print(0, message);
|
||||
break;
|
||||
|
||||
case 0x3E: /* F4 */
|
||||
*LPT_CTRL_PORT = 0;
|
||||
ctrl &= ~LPT_CTRL_STROBE;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
sprintf(message, "STROBE = FALSE [%02X]\n", ctrl);
|
||||
print(0, message);
|
||||
break;
|
||||
|
||||
case 0x3F: /* F5 */
|
||||
*LPT_CTRL_PORT = 0;
|
||||
ctrl |= LPT_CTRL_INIT;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
sprintf(message, "INIT = TRUE [%02X]\n", ctrl);
|
||||
print(0, message);
|
||||
break;
|
||||
|
||||
case 0x40: /* F6 */
|
||||
*LPT_CTRL_PORT = LPT_CTRL_INIT;
|
||||
ctrl &= ~LPT_CTRL_INIT;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
sprintf(message, "INIT = FALSE [%02X]\n", ctrl);
|
||||
print(0, message);
|
||||
break;
|
||||
|
||||
case 0x41: /* F7 */
|
||||
*LPT_CTRL_PORT = LPT_CTRL_SELECT;
|
||||
ctrl |= LPT_CTRL_SELECT;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
sprintf(message, "SELECT = TRUE [%02X]\n", ctrl);
|
||||
print(0, message);
|
||||
break;
|
||||
|
||||
case 0x42: /* F8 */
|
||||
*LPT_CTRL_PORT = 0;
|
||||
ctrl &= ~LPT_CTRL_SELECT;
|
||||
*LPT_CTRL_PORT = ctrl;
|
||||
sprintf(message, "SELECT = FALSE [%02X]\n", ctrl);
|
||||
print(0, message);
|
||||
break;
|
||||
|
||||
case 0x1B: /* ESC */
|
||||
case 0x01: /* ESC */
|
||||
return 0;
|
||||
|
||||
case 0x02: /* 1 */
|
||||
*LPT_DATA_PORT = '\r';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -559,7 +586,7 @@ short cli_test_lpt(short screen, int argc, const char * argv[]) {
|
|||
|
||||
short cmd_test_print(short screen, int argc, const char * argv[]) {
|
||||
#if MODEL == MODEL_FOENIX_A2560K
|
||||
const char * test_pattern = "0123456789ABCDEFGHIJKLMNOPQRTSUVWZXYZ\r\n";
|
||||
const char * test_pattern = "0123456789ABCDEFGHIJKLMNOPQRTSUVWZXYZ\n\r";
|
||||
|
||||
char message[80];
|
||||
unsigned short scancode = 0;
|
||||
|
@ -573,8 +600,8 @@ short cmd_test_print(short screen, int argc, const char * argv[]) {
|
|||
sys_chan_write(screen, message, strlen(message));
|
||||
|
||||
while (scancode != 0x01) {
|
||||
scancode = sys_kbd_scancode();
|
||||
lpt_write(0, test_pattern, strlen(test_pattern));
|
||||
scancode = sys_kbd_scancode();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
|
|
@ -29,19 +29,18 @@
|
|||
|
||||
#define LPT_INIT_ON 0x08 /* Start the printer initialization process */
|
||||
#define LPT_INIT_OFF 0x0C /* Stop the printer initialization process */
|
||||
#define LPT_STROBE_ON 0x0F /* Strobe the printer */
|
||||
#define LPT_STROBE_OFF 0x0E /* Drop the strobe to the printer */
|
||||
#define LPT_STROBE_ON 0x0D /* Strobe the printer */
|
||||
#define LPT_STROBE_OFF 0x0C /* Drop the strobe to the printer */
|
||||
|
||||
short lpt_delay() {
|
||||
int i;
|
||||
short x;
|
||||
for (i = 0, x = 0; i < 10; i++) {
|
||||
x++;
|
||||
}
|
||||
return x;
|
||||
/**
|
||||
* Wait a little bit...
|
||||
*/
|
||||
void lpt_delay() {
|
||||
long target_jiffies = sys_time_jiffies() + 1;
|
||||
while (target_jiffies > sys_time_jiffies()) ;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Install the LPT driver
|
||||
*/
|
||||
short lpt_install() {
|
||||
|
@ -53,43 +52,10 @@ void lpt_initialize() {
|
|||
|
||||
/* Set the outputs to start the initialization process */
|
||||
*LPT_CTRL_PORT = LPT_INIT_ON;
|
||||
|
||||
/* Wait 50 micro seconds */
|
||||
lpt_delay();
|
||||
|
||||
/* Set the outputs to stop the initialization process */
|
||||
*LPT_CTRL_PORT = LPT_INIT_OFF;
|
||||
|
||||
lpt_delay();
|
||||
}
|
||||
|
||||
short lpt_wait_busy() {
|
||||
unsigned char stat = 0;
|
||||
do {
|
||||
stat = *LPT_STAT_PORT;
|
||||
if ((stat & LPT_STAT_ERROR) == 0) {
|
||||
// There was an error...
|
||||
DEBUG("LPT: lpt_wait_busy error");
|
||||
return -1;
|
||||
} else if (stat & LPT_STAT_PO) {
|
||||
// Out of paper
|
||||
DEBUG("LPT: lpt_wait_busy out of paper");
|
||||
return -1;
|
||||
}
|
||||
} while ((stat & LPT_STAT_BUSY) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
short lpt_wait_ack() {
|
||||
unsigned char stat = 0;
|
||||
short counter = 0;
|
||||
|
||||
do {
|
||||
stat = *LPT_STAT_PORT;
|
||||
} while ((counter++ < 32000) && ((stat & LPT_STAT_ACK) != 0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -100,25 +66,25 @@ short lpt_write_b(p_channel chan, unsigned char b) {
|
|||
/* TODO: convert it to interrupt driven */
|
||||
|
||||
/* Wait until the printer is not busy */
|
||||
if (lpt_wait_busy()) {
|
||||
// If we got an error, return an error
|
||||
DEBUG("LPT: Error writing");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*LPT_DATA_PORT = b; /* Send the byte */
|
||||
*LPT_CTRL_PORT = LPT_STROBE_ON; /* Strobe the interface */
|
||||
|
||||
while ((*LPT_STAT_PORT & LPT_STAT_BUSY) == 0) {
|
||||
lpt_delay();
|
||||
|
||||
/* Wait for the printer to acknowledge */
|
||||
if (lpt_wait_ack()) {
|
||||
// If we got an error, return an error
|
||||
*LPT_CTRL_PORT = LPT_STROBE_OFF; /* Drop the strobe */
|
||||
return -1;
|
||||
}
|
||||
|
||||
*LPT_CTRL_PORT = LPT_STROBE_OFF; /* Drop the strobe */
|
||||
/* Send the byte */
|
||||
if (b == 0x1b) { b = 'E'}
|
||||
*LPT_DATA_PORT = b;
|
||||
sys_chan_write_b(0, b);
|
||||
|
||||
/* Strobe the interface */
|
||||
//unsigned char ctrl = *LPT_CTRL_PORT;
|
||||
*LPT_CTRL_PORT = LPT_STROBE_ON;
|
||||
lpt_delay();
|
||||
*LPT_CTRL_PORT = LPT_STROBE_OFF;
|
||||
|
||||
/* Wait until the printer is not busy */
|
||||
while ((*LPT_STAT_PORT & LPT_STAT_BUSY) == 0) {
|
||||
lpt_delay();
|
||||
}
|
||||
|
||||
return 0; /* Return success */
|
||||
}
|
||||
|
|
5253
src/foenixmcp.s68
5253
src/foenixmcp.s68
File diff suppressed because it is too large
Load diff
12350
src/mapfile
12350
src/mapfile
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue