stm32f1/usb_cables.h

79 lines
3.5 KiB
C

/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** USB cable definitions and utilities
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2019
*/
/* USB pin definition */
struct usb_pin_t {
const char* name; /*< pin name */
uint32_t port; /*< on which MCU port is this pin connected */
uint16_t pin; /*< on which MCU pin is this pin connected */
};
/** USB connector definition */
struct usb_connector_t {
const char* name; /*< connector name (A, B, mini-B, micro-B, C, ...) */
bool host; /*< if on host or device side */
uint8_t pins_nb; /*< number of pins */
const struct usb_pin_t* pins; /*< all connector pins */
};
/** USB cable definition */
struct usb_cable_t {
const char* name; /*< cable name */
uint8_t connectors_nb; /*< number of connectors */
const struct usb_connector_t* connectors; /*< list of connectors this cables uses */
uint8_t pin_pairs_nb; /* number of connected pin pairs */
const struct usb_pin_t (*pin_pairs)[2]; /*< list of connected pin pairs (order does not matter) */
};
/** USB connectors definitions */
extern const struct usb_connector_t usb_connectors[8];
/** USB cables definitions */
extern const struct usb_cable_t usb_cables[2];
/** set every pin of connector to input floating
* @param[in] connector connector on which to set the pins floating
*/
void usb_cables_pins_float(const struct usb_connector_t* connector);
/** set every pin to the connectors to input floating
* @param[in] connectors list on connectors on which to set the pins floating
* @param[in] connectors_nb numbers of connectors
*/
void usb_cables_connectors_float(const struct usb_connector_t* connectors, uint8_t connectors_nb);
/** check connector for connections between pins of this connector
* @param[in] connector connector to check
*/
void usb_cables_check_intra(const struct usb_connector_t* connector);
/** check connectors for connections between pins of the connectors
* @param[in] connectors connectors to check
* @param[in] connectors_nb numbers of connectors
* @note connection between pin on the same connector are not checked
*/
void usb_cables_check_inter(const struct usb_connector_t* connectors, uint8_t connectors_nb);
/** check USB cable connections
* @param[in] usb_cable USB cable to check
* @param[out] defined number of pin pairs that are connected according to definition
* @param[out] undefined number of pin pairs that are connected but not according to definition
* @param[out] disconnected number of pin pairs that are not connected but should according to definition
* @param[out] error number of pin pairs that are have an issue (can't be put high and low, or are unidirectional)
* @return if the connections of the cable correspond to the definition
* @note each pair is checked in both directions
*/
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected, uint8_t* error);