application: add USB-C ressitor using FUSB302 to in Cplug action
This commit is contained in:
parent
93af648943
commit
4d8f1d537a
|
@ -48,6 +48,7 @@
|
|||
#include "usb_cables.h" // USB cables definition
|
||||
#include "lcd_hd44780.h" // LCD utilities
|
||||
#include "oled_text.h" // OLED utilities to display text
|
||||
#include "usb_fusb302.h" // USB-C controller utilities
|
||||
|
||||
/** watchdog period in ms */
|
||||
#define WATCHDOG_PERIOD 10000
|
||||
|
@ -74,6 +75,9 @@ volatile bool rtc_internal_tick_flag = false; /**< flag set when internal RTC ti
|
|||
/** activity timeout before switching off (in RTC ticks) */
|
||||
#define SHUTDOWN_TIMEOUT (60 * RTC_TICKS_SECOND)
|
||||
|
||||
/** if a FUSB302 USB-C controller is present */
|
||||
static bool present_fusb302 = false;
|
||||
|
||||
// ====================
|
||||
// = common functions =
|
||||
// ====================
|
||||
|
@ -1340,6 +1344,36 @@ static void command_cplug(void* argument)
|
|||
if (cc1 || cc2) {
|
||||
puts("> this cable is to be connected to a source on the other end (A plug)\n");
|
||||
}
|
||||
// find out if a resistor is present using USB-C controller
|
||||
if (present_fusb302 && USB_CONNECTOR_C_DEVICE == connectors[connector_id]) { // HW v1 (modified for a v2 prototype) has only a FUSB302 on the C device port
|
||||
// ground pins need to be pulled low for the resistor test to work
|
||||
usb_cables_pins_float(); // start with all floating to remove interferences
|
||||
for (uint8_t i = 0; i < connector->pins_nb; i++) {
|
||||
if (connector->pins[i] >= LENGTH(usb_pins)) {
|
||||
continue;
|
||||
}
|
||||
const struct usb_pin_t pin = usb_pins[connector->pins[i]];
|
||||
if (USB_PIN_TYPE_GROUND != pin.type) {
|
||||
continue;
|
||||
}
|
||||
gpio_clear(pin.port, pin.pin);
|
||||
gpio_set_mode(pin.port, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, pin.pin);
|
||||
}
|
||||
// figure out resistors on CC lines
|
||||
for (uint8_t cc = 1; cc < 3; cc++) {
|
||||
const char* r_values[] = {"short to ground", "Ra", "Rd", "Rp", "open"};
|
||||
int16_t r = usb_fusb302_r(cc);
|
||||
printf("- CC%u resistor: ", cc);
|
||||
if (r < 0 || r >= (int16_t)LENGTH(r_values)) {
|
||||
printf("error=%d", r);
|
||||
} else {
|
||||
puts(r_values[r]);
|
||||
}
|
||||
putc('\n');
|
||||
}
|
||||
// put ground back to floating
|
||||
usb_cables_pins_float(); // not the most efficient way, but time is not critical
|
||||
}
|
||||
}
|
||||
|
||||
// test interconnection
|
||||
|
@ -1719,6 +1753,16 @@ void main(void)
|
|||
oled_text_clear();
|
||||
oled_text_update();
|
||||
|
||||
// setup FUSB302 to remove all connections to CC pins (Rd enabled by default, also when unpowered)
|
||||
// HW v1 has not been designed with a FUSB302 USB-C controller
|
||||
// a FUSB302 has been added to it to test it in preparation of the v2
|
||||
// since there wes no free pin to control its power, the LCD LED pin has been reused
|
||||
lcd_hd44780_set_led(false); // provide power to the USB-C controller
|
||||
present_fusb302 = (0 == usb_fusb302_setup());
|
||||
if (!present_fusb302) {
|
||||
lcd_hd44780_set_led(true);
|
||||
}
|
||||
|
||||
// setup USB connectors
|
||||
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0); // only use SWD and reuse JTAG pins
|
||||
rcc_periph_clock_enable(RCC_GPIOA); // enable clock to all GPIO port domains since we use them all
|
||||
|
|
Loading…
Reference in New Issue