-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUSBClass.h
92 lines (79 loc) · 2.78 KB
/
USBClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @file USBControllerClass.h
* @author Leonardo Cavagnis
* @brief Header file for the USB Controller of the Portenta Machine Control.
*
* This library provides a class to manage the USB functionality of the Portenta Machine Control.
* It enables or disables the power of the USB Host (USBA) and provides methods to check the fault status.
*/
#ifndef __USB_CONTROLLER_CLASS_H
#define __USB_CONTROLLER_CLASS_H
/* Includes -------------------------------------------------------------------*/
#include <Arduino.h>
#include <mbed.h>
#include "pins_mc.h"
/* Class ----------------------------------------------------------------------*/
/**
* @class USBClass
* @brief Class for managing the USB functionality of the Portenta Machine Control.
*
* This class allows enabling or disabling the power of the USB Host (USBA) and checking for any fault status.
*/
class USBClass {
public:
/**
* @brief Construct a USBClass object.
*
* This constructor initializes a USBClass object with the specified pin assignments for power control and fault status.
*
* @param power_pin The pin number for controlling the power to the USBA VBUS.
* @param usbflag_pin The pin number for reading the fault status of the USBA VBUS.
*/
USBClass(PinName power_pin = MC_USB_PWR_PIN, PinName usbflag_pin = MC_USB_FLAG_PIN);
/**
* @brief Destruct the USBClass object.
*
* This destructor releases any resources used by the USBClass object.
*/
~USBClass();
/**
* @brief Begin the USB functionality.
*
* This method initializes the USB functionality by enabling power to the USBA VBUS.
*
* @return true If the initialization is successful, false otherwise.
*/
bool begin();
/**
* @brief End the USB functionality.
*
* This method disables power to the USBA VBUS and releases any resources used by the USBClass object.
*/
void end();
/**
* @brief Get the fault status of the USBA VBUS.
*
* This method reads the fault status of the USBA VBUS to check for overcurrent, overtemperature,
* or reverse-voltage conditions.
*
* @return true if there is a fault, false if everything is okay.
*/
bool getFaultStatus();
private:
PinName _power; // Pin for controlling the power to the USBA VBUS
PinName _usbflag; // Pin for reading the fault status of the USBA VBUS
/**
* @brief Enable power to the USBA VBUS.
*
* This private method is used to enable power to the USBA VBUS.
*/
void _enable();
/**
* @brief Disable power to the USBA VBUS.
*
* This private method is used to disable power to the USBA VBUS.
*/
void _disable();
};
extern USBClass MachineControl_USBController;
#endif /* __USB_CONTROLLER_CLASS_H */