This module is USB Peripheral Printer Device Class Driver (PPRN). It implements the USB PPRN Interface.
Refer to USB (r_usb_basic) for the common API (r_usb_basic) to be called from the application.
Overview
The r_usb_pprn module combines with the r_usb_basic module to provide a USB Peripheral Printer Device Class (PPRN) driver. The PPRN driver conforms to the USB Printer Device class specifications and implements communication with a printer host.
Features
The r_usb_pprn module has the following functions:
- Data transfer to and from a USB host
- Response to the printer class requests
- Response to function references from the printer host
- Note
- This driver is not guaranteed to provide USB printer operation in all scenarios. The developer must verify correct operation when connected to the targeted USB hosts.
Configuration
Build Time Configurations for r_usb_pprn
The following build time configurations are defined in fsp_cfg/r_usb_pprn_cfg.h:
Configuration | Options | Default | Description |
Bulk In Pipe |
-
USB PIPE1
-
USB PIPE2
-
USB PIPE3
-
USB PIPE4
-
USB PIPE5
| USB PIPE4 | Select the USB pipe to use for bulk in transfer. |
Bulk Out Pipe |
-
USB PIPE1
-
USB PIPE2
-
USB PIPE3
-
USB PIPE4
-
USB PIPE5
| USB PIPE5 | Select the USB pipe to use for bulk out transfer. |
Configurations for Connectivity > USB PPRN (r_usb_pprn)
This module can be added to the Stacks tab via New Stack > Connectivity > USB PPRN (r_usb_pprn).
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_pprn0 | Module name. |
Clock Configuration
Refer to the USB (r_usb_basic) module.
Pin Configuration
Refer to the USB (r_usb_basic) module.
Usage Notes
Class Requests (Host to Peripheral)
This driver notifies the application when receiving the following class requests:
Request | Code | Description |
GET_DEVICE_ID | 0x00 | Get IEEE 1284 Device ID String |
GET_PORT_STATUS | 0x01 | Get Printer's Status |
SOFT_RESET | 0x02 | Flushes all buffers and resets the Bulk OUT and Bulk IN pipes |
The data format of supported class requests is described below:
bmRequestType | bRequest | wValue | wIndex | wLength | Data |
0xA1 | GET_DEVICE_ID (0x00) | Config Index | Interface
Alternate Setting | Maximum
Length | 1284 Device ID
String |
0xA1 | GET_PORT_STATUS (0x01) | 0 | Interface | 1 | Printer Status |
0x21 | SOFT_RESET (0x02) | 0 | Interface | 0 | None |
Limitations
- This driver does not support USB Low-speed mode.
- This driver does not support simultaneous operation with USB Host device class.
- Please ignore the suspend or resume event occurs when attaching or detaching the USB cable.
USB PPRN Example
This is a minimal example for implementing PPRN in bare metal and FreeRTOS application.
#define DEMO_PROTOCOL (1U)
#define VALUE_5BH (0x5BU)
static uint8_t g_port_status = PORT_STATUS_BENIGN;
static uint8_t g_printer_device_id[] =
{
0x00,
VALUE_5BH,
'M',
'F',
'G',
':',
'G',
'e',
'n',
'e',
'r',
'i',
'c',
';',
'M',
'D',
'L',
':',
'G',
'e',
'n',
'e',
'r',
'i',
'c',
'_',
'/',
'_',
'T',
'e',
'x',
't',
'_',
'O',
'n',
'l',
'y',
';',
'C',
'M',
'D',
':',
'1',
'2',
'8',
'4',
'.',
'4',
';',
'C',
'L',
'S',
':',
'P',
'R',
'I',
'N',
'T',
'E',
'R',
';',
'D',
'E',
'S',
':',
'G',
'e',
'n',
'e',
'r',
'i',
'c',
' ',
't',
'e',
'x',
't',
' ',
'o',
'n',
'l',
'y',
' ',
'p',
'r',
'i',
'n',
't',
'e',
'r',
';'
};
void usb_pprn_example(void);
#if (BSP_CFG_RTOS == 2)
void usb_apl_callback (usb_event_info_t * p_api_event, usb_hdl_t cur_task,
usb_onoff_t usb_state)
{
(void) usb_state;
(void) cur_task;
xQueueSend(g_apl_mbx_hdl, (const void *) &p_api_event, (TickType_t) (0));
}
#endif
void usb_pprn_example (void)
{
usb_event_info_t event_info;
usb_info_t info;
#if (BSP_CFG_RTOS == 2)
usb_event_info_t * p_mess;
#endif
g_usb_on_usb.
open(&g_basic0_ctrl, &g_basic0_cfg);
memset(&event_info, 0, sizeof(usb_event_info_t));
while (1)
{
#if (BSP_CFG_RTOS == 2)
xQueueReceive(g_apl_mbx_hdl, (void *) &p_mess, portMAX_DELAY);
event_info = *p_mess;
event = event_info.event;
#else
g_usb_on_usb.
eventGet(&event_info, &event);
#endif
switch (event)
{
break;
#if DEMO_PROTOCOL > 1
#endif
break;
#if DEMO_PROTOCOL > 1
#else
#endif
break;
{
}
{
}
{
}
else
{
}
break;
break;
default:
break;
}
}
}
Descriptors
A template for PPRN descriptors can be found in ra/fsp/src/r_usb_pprn folder. Be sure to replace the vendor ID with your own.