RA Flexible Software Package Documentation  Release v5.2.0

 
USB PPRN (r_usb_pprn)

This module is USB Peripheral Printer Device Class Driver (PPRN). It implements the USB PPRN Interface.

Functions

Refer to USB (r_usb_basic) for the common API (r_usb_basic) to be called from the application.

Detailed Description

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:

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:

ConfigurationOptionsDefaultDescription
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).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_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

USB PPRN Example

This is a minimal example for implementing PPRN in bare metal and FreeRTOS application.

/******************************************************************************
* Macro definitions
******************************************************************************/
/* Define device framework. */
#define DEMO_PROTOCOL (1U) /* 1-Uni-dir, 2-Bi-dir */
#define VALUE_5BH (0x5BU)
/******************************************************************************
* Private global variables and functions
******************************************************************************/
static uint8_t g_port_status = PORT_STATUS_BENIGN;
/* Device printer device ID. */
static uint8_t g_printer_device_id[] =
{
0x00, /* data length */
VALUE_5BH,
'M', /* manufacturer (case sensitive) */
'F',
'G',
':',
'G',
'e',
'n',
'e',
'r',
'i',
'c',
';',
'M', /* model (case sensitive) */
'D',
'L',
':',
'G',
'e',
'n',
'e',
'r',
'i',
'c',
'_',
'/',
'_',
'T',
'e',
'x',
't',
'_',
'O',
'n',
'l',
'y',
';',
'C', /* PDL command set */
'M',
'D',
':',
'1',
'2',
'8',
'4',
'.',
'4',
';',
'C', /* class */
'L',
'S',
':',
'P',
'R',
'I',
'N',
'T',
'E',
'R',
';',
'D', /* description */
'E',
'S',
':',
'G',
'e',
'n',
'e',
'r',
'i',
'c',
' ',
't',
'e',
'x',
't',
' ',
'o',
'n',
'l',
'y',
' ',
'p',
'r',
'i',
'n',
't',
'e',
'r',
';'
};
/******************************************************************************
* Exported global functions (to be accessed by other files)
******************************************************************************/
void usb_pprn_example(void);
usb_instance_ctrl_t g_basic0_ctrl;
#if (BSP_CFG_RTOS == 2)
/******************************************************************************
* Function Name : usb_apl_callback
* Description : Callback function for Application program
* Arguments : usb_event_info_t *p_api_event : Control structure for USB API.
* : usb_hdl_t cur_task : Task Handle
* : uint8_t usb_state : USB_ON(USB_STATUS_REQUEST) / USB_OFF
* Return value : none
******************************************************************************/
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));
} /* End of function usb_apl_callback */
#endif /* (BSP_CFG_RTOS == 2) */
/******************************************************************************
* Function Name : usb_pprn_example
* Description : Peripheral Printer Class(PRN) application main process
* Arguments : none
* Return value : none
******************************************************************************/
void usb_pprn_example (void)
{
usb_event_info_t event_info;
usb_status_t event;
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);
while (1)
{
#if (BSP_CFG_RTOS == 2) /* FreeRTOS */
xQueueReceive(g_apl_mbx_hdl, (void *) &p_mess, portMAX_DELAY);
event_info = *p_mess;
event = event_info.event;
#else /* (BSP_CFG_RTOS == 2) */
/* Get USB event data */
g_usb_on_usb.eventGet(&event_info, &event);
#endif
/* Handle the received event (if any) */
switch (event)
{
/* Initialization complete; get data from host */
g_usb_on_usb.read(&g_basic0_ctrl, g_buf, DATA_LEN, USB_CLASS_PPRN);
break;
#if DEMO_PROTOCOL > 1
g_usb_on_usb.read(&g_basic0_ctrl, g_buf, DATA_LEN, USB_CLASS_PPRN);
#endif
break;
#if DEMO_PROTOCOL > 1
/* Loop back to Host */
g_usb_on_usb.write(&g_basic0_ctrl, g_buf, event_info.data_size, USB_CLASS_PPRN);
#else
g_usb_on_usb.read(&g_basic0_ctrl, g_buf, DATA_LEN, USB_CLASS_PPRN);
#endif
break;
case USB_STATUS_REQUEST: /* Receive Class Request */
if (USB_PPRN_GET_DEVICE_ID == (event_info.setup.request_type & USB_BREQUEST))
{
R_USB_InfoGet(&g_basic0_ctrl, &info, event_info.device_address);
R_USB_PeriControlDataSet(&g_basic0_ctrl, g_printer_device_id, PRINTER_DEVICE_ID_LENGTH);
}
else if (USB_PRPN_GET_PORT_STATUS == (event_info.setup.request_type & USB_BREQUEST))
{
R_USB_InfoGet(&g_basic0_ctrl, &info, event_info.device_address);
R_USB_PeriControlDataSet(&g_basic0_ctrl, &g_port_status, 1);
}
else if (USB_PPRN_SOFT_RESET == (event_info.setup.request_type & USB_BREQUEST))
{
R_USB_InfoGet(&g_basic0_ctrl, &info, event_info.device_address);
/* [To do] Transport Abort */
g_usb_on_usb.stop(&g_basic0_ctrl, USB_TRANSFER_READ, USB_CLASS_PPRN);
}
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.