blob: 0549a1569e89d024fa353343104774e984369d16 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 N Conrad
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27
28#ifndef CLASS_USBTMC_USBTMC_DEVICE_H_
29#define CLASS_USBTMC_USBTMC_DEVICE_H_
30
31#include "usbtmc.h"
32
33// Enable 488 mode by default
34#if !defined(CFG_TUD_USBTMC_ENABLE_488)
35#define CFG_TUD_USBTMC_ENABLE_488 (1)
36#endif
37
38// USB spec says that full-speed must be 8,16,32, or 64.
39// However, this driver implementation requires it to be >=32
40#define USBTMCD_MAX_PACKET_SIZE (64u)
41
42/***********************************************
43 * Functions to be implemeted by the class implementation
44 */
45
46// In order to proceed, app must call call tud_usbtmc_start_bus_read(rhport) during or soon after:
47// * tud_usbtmc_open_cb
48// * tud_usbtmc_msg_data_cb
49// * tud_usbtmc_msgBulkIn_complete_cb
50// * tud_usbtmc_msg_trigger_cb
51// * (successful) tud_usbtmc_check_abort_bulk_out_cb
52// * (successful) tud_usbtmc_check_abort_bulk_in_cb
53// * (successful) tud_usmtmc_bulkOut_clearFeature_cb
54
55#if (CFG_TUD_USBTMC_ENABLE_488)
56usbtmc_response_capabilities_488_t const * tud_usbtmc_get_capabilities_cb(void);
57#else
58usbtmc_response_capabilities_t const * tud_usbtmc_get_capabilities_cb(void);
59#endif
60
61void tud_usbtmc_open_cb(uint8_t interface_id);
62
63bool tud_usbtmc_msgBulkOut_start_cb(usbtmc_msg_request_dev_dep_out const * msgHeader);
64// transfer_complete does not imply that a message is complete.
65bool tud_usbtmc_msg_data_cb( void *data, size_t len, bool transfer_complete);
66void tud_usbtmc_bulkOut_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer
67
68bool tud_usbtmc_msgBulkIn_request_cb(usbtmc_msg_request_dev_dep_in const * request);
69bool tud_usbtmc_msgBulkIn_complete_cb(void);
70void tud_usbtmc_bulkIn_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer
71
72bool tud_usbtmc_initiate_abort_bulk_in_cb(uint8_t *tmcResult);
73bool tud_usbtmc_initiate_abort_bulk_out_cb(uint8_t *tmcResult);
74bool tud_usbtmc_initiate_clear_cb(uint8_t *tmcResult);
75
76bool tud_usbtmc_check_abort_bulk_in_cb(usbtmc_check_abort_bulk_rsp_t *rsp);
77bool tud_usbtmc_check_abort_bulk_out_cb(usbtmc_check_abort_bulk_rsp_t *rsp);
78bool tud_usbtmc_check_clear_cb(usbtmc_get_clear_status_rsp_t *rsp);
79
80// Indicator pulse should be 0.5 to 1.0 seconds long
81TU_ATTR_WEAK bool tud_usbtmc_indicator_pulse_cb(tusb_control_request_t const * msg, uint8_t *tmcResult);
82
83#if (CFG_TUD_USBTMC_ENABLE_488)
84uint8_t tud_usbtmc_get_stb_cb(uint8_t *tmcResult);
85TU_ATTR_WEAK bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg);
86//TU_ATTR_WEAK bool tud_usbtmc_app_go_to_local_cb();
87#endif
88
89/*******************************************
90 * Called from app
91 *
92 * We keep a reference to the buffer, so it MUST not change until the app is
93 * notified that the transfer is complete.
94 ******************************************/
95
96bool tud_usbtmc_transmit_dev_msg_data(
97 const void * data, size_t len,
98 bool endOfMessage, bool usingTermChar);
99
100bool tud_usbtmc_start_bus_read(void);
101
102
103/* "callbacks" from USB device core */
104
105uint16_t usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
106void usbtmcd_reset_cb(uint8_t rhport);
107bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
108bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
109void usbtmcd_init_cb(void);
110
111/************************************************************
112 * USBTMC Descriptor Templates
113 *************************************************************/
114
115
116#endif /* CLASS_USBTMC_USBTMC_DEVICE_H_ */