Skip to content

Commit 523fbeb

Browse files
committed
adding missing headers
1 parent 96022f2 commit 523fbeb

9 files changed

+4375
-0
lines changed

inc/usb_host_generic.h

Lines changed: 669 additions & 0 deletions
Large diffs are not rendered by default.

inc/usb_host_midi.h

Lines changed: 558 additions & 0 deletions
Large diffs are not rendered by default.

inc/usb_host_printer.h

Lines changed: 2187 additions & 0 deletions
Large diffs are not rendered by default.

inc/usb_host_printer_esc_pos.h

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
// DOM-IGNORE-BEGIN
2+
/*******************************************************************************
3+
Copyright 2015 Microchip Technology Inc. (www.microchip.com)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
To request to license the code under the MLA license (www.microchip.com/mla_license),
18+
please contact [email protected]
19+
*******************************************************************************/
20+
//DOM-IGNORE-END
21+
22+
23+
// *****************************************************************************
24+
// *****************************************************************************
25+
// Section: Constants
26+
// *****************************************************************************
27+
// *****************************************************************************
28+
29+
// This is the string that the printer language support determination
30+
// routine will look for to determine if the printer supports this
31+
// printer language. This string is case sensive. See the function
32+
// USBHostPrinterLanguageESCPOSIsSupported() for more information
33+
// about using or changing this string. Dynamic language determination
34+
// is not recommended when using POS printers.
35+
#define LANGUAGE_ID_STRING_ESCPOS "ESC"
36+
// These are the support flags that are set for this language.
37+
#define LANGUAGE_SUPPORT_FLAGS_ESCPOS USB_PRINTER_FUNCTION_SUPPORT_POS
38+
39+
40+
/****************************************************************************
41+
Function:
42+
uint8_t USBHostPrinterLanguageESCPOS( uint8_t address,
43+
USB_PRINTER_COMMAND command, USB_DATA_POINTER data, uint32_t size, uint8_t transferFlags )
44+
45+
Summary:
46+
This function executes printer commands for an ESC/POS printer.
47+
48+
Description:
49+
This function executes printer commands for an ESC/POS printer. When
50+
the application issues a printer command, the printer client driver
51+
determines what language to use to communicate with the printer, and
52+
transfers the command to that language support routine. As much as
53+
possible, commands are designed to produce the same output regardless
54+
of what printer language is used.
55+
56+
Not all printer commands support data from both RAM and ROM. Unless
57+
otherwise noted, the data pointer is assumed to point to RAM, regardless of
58+
the value of transferFlags. Refer to the specific command to see if ROM
59+
data is supported.
60+
61+
Preconditions:
62+
None
63+
64+
Parameters:
65+
uint8_t address - Device's address on the bus
66+
USB_PRINTER_COMMAND command - Command to execute. See the enumeration
67+
USB_PRINTER_COMMAND for the list of
68+
valid commands and their requirements.
69+
USB_DATA_POINTER data - Pointer to the required data. Note that
70+
the caller must set transferFlags
71+
appropriately to indicate if the pointer is
72+
a RAM pointer or a ROM pointer.
73+
uint32_t size - Size of the data. For some commands, this
74+
parameter is used to hold the data itself.
75+
uint8_t transferFlags - Flags that indicate details about the
76+
transfer operation. Refer to these flags
77+
* USB_PRINTER_TRANSFER_COPY_DATA
78+
* USB_PRINTER_TRANSFER_STATIC_DATA
79+
* USB_PRINTER_TRANSFER_NOTIFY
80+
* USB_PRINTER_TRANSFER_FROM_ROM
81+
* USB_PRINTER_TRANSFER_FROM_RAM
82+
83+
Return Values:
84+
USB_PRINTER_SUCCESS - The command was executed successfully.
85+
USB_PRINTER_UNKNOWN_DEVICE - A printer with the indicated address is not
86+
attached
87+
USB_PRINTER_TOO_MANY_DEVICES - The printer status array does not have
88+
space for another printer.
89+
USB_PRINTER_OUT_OF_MEMORY - Not enough available heap space to
90+
execute the command.
91+
other - See possible return codes from the
92+
function USBHostPrinterWrite().
93+
94+
Remarks:
95+
When developing new commands, keep in mind that the function
96+
USBHostPrinterCommandReady() will be used before calling this function to
97+
see if there is space available in the output transfer queue.
98+
USBHostPrinterCommandReady() will routine true if a single space is
99+
available in the output queue. Therefore, each command can generate only
100+
one output transfer.
101+
102+
Multiple printer languages may be used in a single application. The USB
103+
Embedded Host Printer Client Driver will call the routine required for the
104+
attached device.
105+
***************************************************************************/
106+
107+
uint8_t USBHostPrinterLanguageESCPOS( uint8_t address,
108+
USB_PRINTER_COMMAND command, USB_DATA_POINTER data, uint32_t size, uint8_t transferFlags );
109+
110+
111+
/****************************************************************************
112+
Function:
113+
bool USBHostPrinterLanguageESCPOSIsSupported( char *deviceID,
114+
USB_PRINTER_FUNCTION_SUPPORT *support )
115+
116+
Description:
117+
This function determines if the printer with the given device ID string
118+
supports the ESC/POS printer language.
119+
120+
Preconditions:
121+
None
122+
123+
Parameters:
124+
char *deviceID - Pointer to the "COMMAND SET:" portion of the device ID
125+
string of the attached printer.
126+
USB_PRINTER_FUNCTION_SUPPORT *support - Pointer to returned information
127+
about what types of functions this printer supports.
128+
129+
Return Values:
130+
true - The printer supports ESC/POS.
131+
false - The printer does not support ESC/POS.
132+
133+
Remarks:
134+
The caller must first locate the "COMMAND SET:" section of the device ID
135+
string. To ensure that only the "COMMAND SET:" section of the device ID
136+
string is checked, the ";" at the end of the section should be temporarily
137+
replaced with a NULL. Otherwise, this function may find the printer
138+
language string in the comments or other section, and incorrectly indicate
139+
that the printer supports the language.
140+
141+
Device ID strings are case sensitive.
142+
143+
See the file header comments for this file (usb_host_printer_esc_pos.h)
144+
for cautions regarding dynamic printer language selection with POS
145+
printers.
146+
***************************************************************************/
147+
148+
bool USBHostPrinterLanguageESCPOSIsSupported( char *deviceID,
149+
USB_PRINTER_FUNCTION_SUPPORT *support );
150+
151+
152+
/****************************************************************************
153+
Function:
154+
USB_DATA_POINTER USBHostPrinterPOSImageDataFormat( USB_DATA_POINTER image,
155+
uint8_t imageLocation, uint16_t imageHeight, uint16_t imageWidth, uint16_t *currentRow,
156+
uint8_t uint8_tDepth, uint8_t *imageData )
157+
158+
Summary:
159+
This function formats data for a bitmapped image into the format required
160+
for sending to a POS printer.
161+
162+
Description:
163+
This function formats data for a bitmapped image into the format required
164+
for sending to a POS printer. Bitmapped images are stored one row of pixels
165+
at a time. Suppose we have an image with vertical black bars, eight pixels
166+
wide and eight pixels deep. The image would appear as the following pixels,
167+
where 0 indicates a black dot and 1 indicates a white dot:
168+
<code>
169+
0 1 0 1 0 1 0 1
170+
0 1 0 1 0 1 0 1
171+
0 1 0 1 0 1 0 1
172+
0 1 0 1 0 1 0 1
173+
0 1 0 1 0 1 0 1
174+
0 1 0 1 0 1 0 1
175+
0 1 0 1 0 1 0 1
176+
0 1 0 1 0 1 0 1
177+
</code>
178+
The stored bitmap of the data would contain the data uint8_ts, where each uint8_t
179+
is one row of data:
180+
<code>
181+
0x55 0x55 0x55 0x55 0x55 0x55 0x55 0x55
182+
</code>
183+
When printing to a full sheet printer, eight separate
184+
USB_PRINTER_IMAGE_DATA_HEADER / USB_PRINTER_IMAGE_DATA command combinations
185+
are required to print this image.
186+
187+
POS printers, however, require image data formated either 8 dots or 24 dots
188+
deep, depending on the desired (and supported) vertical print density. For
189+
a POS printer performing an 8-dot vertical density print, the data needs to
190+
be in this format:
191+
<code>
192+
0x00 0xFF 0x00 0xFF 0x00 0xFF 0x00 0xFF
193+
</code>
194+
When printing to a POS printer, only one
195+
USB_PRINTER_IMAGE_DATA_HEADER / USB_PRINTER_IMAGE_DATA command combination
196+
is required to print this image.
197+
198+
This function supports 8-dot and 24-dot vertical densities by specifying
199+
the uint8_tDepth parameter as either 1 (8-dot) or 3 (24-dot).
200+
201+
Precondition:
202+
None
203+
204+
Parameters:
205+
USB_DATA_POINTER image Pointer to the image bitmap data.
206+
uint8_t imageLocation Location of the image bitmap data. Valid values
207+
are USB_PRINTER_TRANSFER_FROM_ROM and
208+
USB_PRINTER_TRANSFER_FROM_RAM.
209+
uint16_t imageHeight Height of the image in pixels.
210+
uint16_t imageWidth Width of the image in pixels.
211+
uint16_t *currentRow The current pixel row. Upon return, this value is
212+
updated to the next pixel row to print.
213+
uint8_t uint8_tDepth The uint8_t depth of the print. Valid values are 1
214+
(8-dot vertical density) and 3 (24-dot vertical
215+
density).
216+
uint8_t *imageData Pointer to a RAM data buffer that will receive the
217+
manipulated data to send to the printer.
218+
219+
Returns:
220+
The function returns a pointer to the next uint8_t of image data.
221+
222+
Example:
223+
The following example code will send a complete bitmapped image to a POS
224+
printer.
225+
<code>
226+
uint16_t currentRow;
227+
uint8_t depthuint8_ts;
228+
uint8_t *imageDataPOS;
229+
USB_PRINTER_IMAGE_INFO imageInfo;
230+
uint8_t returnCode;
231+
#if defined (__C30__) || defined __XC16__
232+
uint8_t __prog__ *ptr;
233+
ptr = (uint8_t __prog__ *)logoMCHP.address;
234+
#elif defined (__PIC32MX__)
235+
const uint8_t *ptr;
236+
ptr = (const uint8_t *)logoMCHP.address;
237+
#endif
238+
239+
imageInfo.densityVertical = 24; // 24-dot density
240+
imageInfo.densityHorizontal = 2; // Double density
241+
242+
// Extract the image height and width
243+
imageInfo.width = ((uint16_t)ptr[5] << 8) + ptr[4];
244+
imageInfo.height = ((uint16_t)ptr[3] << 8) + ptr[2];
245+
246+
depthuint8_ts = imageInfo.densityVertical / 8;
247+
imageDataPOS = (uint8_t *)malloc( imageInfo.width *
248+
depthuint8_ts );
249+
250+
if (imageDataPOS == NULL)
251+
{
252+
// Error - not enough heap space
253+
}
254+
255+
USBHostPrinterCommandWithReadyWait( &returnCode,
256+
printerInfo.deviceAddress, USB_PRINTER_IMAGE_START,
257+
USB_DATA_POINTER_RAM(&imageInfo),
258+
sizeof(USB_PRINTER_IMAGE_INFO ),
259+
0 );
260+
261+
ptr += 10; // skip the header info
262+
263+
currentRow = 0;
264+
while (currentRow < imageInfo.height)
265+
{
266+
USBHostPrinterCommandWithReadyWait( &returnCode,
267+
printerInfo.deviceAddress,
268+
USB_PRINTER_IMAGE_DATA_HEADER, USB_NULL,
269+
imageInfo.width, 0 );
270+
271+
ptr = USBHostPrinterPOSImageDataFormat(
272+
USB_DATA_POINTER_ROM(ptr),
273+
USB_PRINTER_TRANSFER_FROM_ROM, imageInfo.height,
274+
imageInfo.width, &currentRow, depthuint8_ts,
275+
imageDataPOS ).pointerROM;
276+
277+
USBHostPrinterCommandWithReadyWait( &returnCode,
278+
printerInfo.deviceAddress, USB_PRINTER_IMAGE_DATA,
279+
USB_DATA_POINTER_RAM(imageDataPOS), imageInfo.width,
280+
USB_PRINTER_TRANSFER_COPY_DATA);
281+
}
282+
283+
free( imageDataPOS );
284+
285+
USBHostPrinterCommandWithReadyWait( &returnCode,
286+
printerInfo.deviceAddress, USB_PRINTER_IMAGE_STOP,
287+
USB_NULL, 0, 0 );
288+
</code>
289+
290+
Remarks:
291+
This routine currently does not support 36-dot density printing. Since
292+
the output for 36-dot vertical density is identical to 24-dot vertical
293+
density, 24-dot vertical density should be used instead.
294+
295+
This routine does not yet support reading from external memory.
296+
***************************************************************************/
297+
298+
USB_DATA_POINTER USBHostPrinterPOSImageDataFormat( USB_DATA_POINTER image,
299+
uint8_t imageLocation, uint16_t imageHeight, uint16_t imageWidth, uint16_t *currentRow,
300+
uint8_t uint8_tDepth, uint8_t *imageData );
301+

0 commit comments

Comments
 (0)