LPT ECP/EPP support

Co-Authored-By: Miran Grča <oubattler@gmail.com>
This commit is contained in:
Jasmine Iwanek
2025-06-24 01:23:32 -04:00
parent 6a8eaf507c
commit 58aa261273
13 changed files with 1161 additions and 392 deletions

View File

@@ -1881,6 +1881,39 @@ write_data(uint8_t val, void *priv)
dev->data = val;
}
static void
autofeed(uint8_t val, void *priv)
{
escp_t *dev = (escp_t *) priv;
if (dev == NULL)
return;
dev->autofeed = ((val & 0x02) > 0);
}
static void
strobe(uint8_t old, uint8_t val, void *priv)
{
escp_t *dev = (escp_t *) priv;
if (dev == NULL)
return;
/* Data is strobed to the parallel printer on the falling edge of the
strobe bit. */
if (!(val & 0x01) && (old & 0x01)) {
/* Process incoming character. */
handle_char(dev, dev->data);
/* ACK it, will be read on next READ STATUS. */
dev->ack = 1;
timer_set_delay_u64(&dev->pulse_timer, ISACONST);
timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC);
}
}
static void
write_ctrl(uint8_t val, void *priv)
{
@@ -1919,14 +1952,6 @@ write_ctrl(uint8_t val, void *priv)
dev->autofeed = ((val & 0x02) > 0);
}
static uint8_t
read_data(void *priv)
{
const escp_t *dev = (escp_t *) priv;
return dev->data;
}
static uint8_t
read_ctrl(void *priv)
{
@@ -2058,13 +2083,16 @@ escp_close(void *priv)
}
const lpt_device_t lpt_prt_escp_device = {
.name = "Generic ESC/P Dot-Matrix Printer",
.internal_name = "dot_matrix",
.init = escp_init,
.close = escp_close,
.write_data = write_data,
.write_ctrl = write_ctrl,
.read_data = read_data,
.read_status = read_status,
.read_ctrl = read_ctrl
.name = "Generic ESC/P Dot-Matrix",
.internal_name = "dot_matrix",
.init = escp_init,
.close = escp_close,
.write_data = write_data,
.write_ctrl = write_ctrl,
.autofeed = autofeed,
.strobe = strobe,
.read_status = read_status,
.read_ctrl = read_ctrl,
.epp_write_data = NULL,
.epp_request_read = NULL
};

View File

@@ -319,6 +319,35 @@ process_data(ps_t *dev)
dev->buffer[dev->buffer_pos] = 0;
}
static void
ps_autofeed(uint8_t val, void *priv)
{
ps_t *dev = (ps_t *) priv;
if (dev == NULL)
return;
dev->autofeed = val & 0x02 ? true : false;
}
static void
ps_strobe(uint8_t old, uint8_t val, void *priv)
{
ps_t *dev = (ps_t *) priv;
if (dev == NULL)
return;
if (!(val & 0x01) && (old & 0x01)) {
process_data(dev);
dev->ack = true;
timer_set_delay_u64(&dev->pulse_timer, ISACONST);
timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC);
}
}
static void
ps_write_ctrl(uint8_t val, void *priv)
{
@@ -479,27 +508,33 @@ ps_close(void *priv)
}
const lpt_device_t lpt_prt_ps_device = {
.name = "Generic PostScript Printer",
.internal_name = "postscript",
.init = ps_init,
.close = ps_close,
.write_data = ps_write_data,
.write_ctrl = ps_write_ctrl,
.read_data = NULL,
.read_status = ps_read_status,
.read_ctrl = NULL
.name = "Generic PostScript Printer",
.internal_name = "postscript",
.init = ps_init,
.close = ps_close,
.write_data = ps_write_data,
.write_ctrl = ps_write_ctrl,
.autofeed = ps_autofeed,
.strobe = ps_strobe,
.read_status = ps_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL
};
#ifdef USE_PCL
const lpt_device_t lpt_prt_pcl_device = {
.name = "Generic PCL5e Printer",
.internal_name = "pcl",
.init = pcl_init,
.close = ps_close,
.write_data = ps_write_data,
.write_ctrl = ps_write_ctrl,
.read_data = NULL,
.read_status = ps_read_status,
.read_ctrl = NULL
.name = "Generic PCL5e Printer",
.internal_name = "pcl",
.init = pcl_init,
.close = ps_close,
.write_data = ps_write_data,
.write_ctrl = ps_write_ctrl,
.autofeed = ps_autofeed,
.strobe = ps_strobe,
.read_status = ps_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL
};
#endif

View File

@@ -367,6 +367,38 @@ write_data(uint8_t val, void *priv)
dev->data = val;
}
static void
autofeed(uint8_t val, void *priv)
{
prnt_t *dev = (prnt_t *) priv;
if (dev == NULL)
return;
/* set autofeed value */
dev->autofeed = val & 0x02 ? 1 : 0;
}
static void
strobe(uint8_t old, uint8_t val, void *priv)
{
prnt_t *dev = (prnt_t *) priv;
if (dev == NULL)
return;
if (!(val & 0x01) && (old & 0x01)) { /* STROBE */
/* Process incoming character. */
handle_char(dev);
/* ACK it, will be read on next READ STATUS. */
dev->ack = 1;
timer_set_delay_u64(&dev->pulse_timer, ISACONST);
timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC);
}
}
static void
write_ctrl(uint8_t val, void *priv)
{
@@ -465,13 +497,16 @@ prnt_close(void *priv)
}
const lpt_device_t lpt_prt_text_device = {
.name = "Generic Text Printer",
.internal_name = "text_prt",
.init = prnt_init,
.close = prnt_close,
.write_data = write_data,
.write_ctrl = write_ctrl,
.read_data = NULL,
.read_status = read_status,
.read_ctrl = NULL
.name = "Generic Text Printer",
.internal_name = "text_prt",
.init = prnt_init,
.close = prnt_close,
.write_data = write_data,
.write_ctrl = write_ctrl,
.autofeed = autofeed,
.strobe = strobe,
.read_status = read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL
};