arduino-esp32/variants/esp32s3usbotg/variant.cpp
Lucas Saavedra Vaz da5c6ab9ae
Refactor repository with pre-commit hooks (#9515)
* Add Config

* Add Cache and remove pre-commit action

* [pre-commit.ci lite] apply automatic fixes

* Remove freeze

* Fix

* Update action

* Use latest stable Python 3 version

* Improve caching

* Improve cache tag

* Improve bot message

* fix(typos): Fix typos

* fix(typos): Fix more typos

* refactor(udp_server): Convert script from Python 2 to 3

* Fix whitespace

* Clang-format fixes

* Prettier fixes

* Black formatting

* Manual fixes

* Line endings

* Fix flake and make Vale manual

* Fix flake and reformat

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
2024-04-15 19:40:56 +03:00

52 lines
1.3 KiB
C++

#include "Arduino.h"
void usbHostPower(UsbHostPower_t mode) {
static UsbHostPower_t m = USB_HOST_POWER_OFF;
if (m == mode) {
return;
}
if (mode == USB_HOST_POWER_OFF) {
digitalWrite(LIMIT_EN, LOW);
if (m == USB_HOST_POWER_VBUS) {
digitalWrite(DEV_VBUS_EN, LOW);
} else if (m == USB_HOST_POWER_BAT) {
digitalWrite(BOOST_EN, LOW);
}
} else if (mode == USB_HOST_POWER_VBUS) {
if (m == USB_HOST_POWER_BAT) {
digitalWrite(BOOST_EN, LOW);
}
digitalWrite(DEV_VBUS_EN, HIGH);
} else if (mode == USB_HOST_POWER_BAT) {
if (m == USB_HOST_POWER_VBUS) {
digitalWrite(DEV_VBUS_EN, LOW);
}
digitalWrite(BOOST_EN, HIGH);
}
if (mode != USB_HOST_POWER_OFF) {
digitalWrite(LIMIT_EN, HIGH);
}
m = mode;
}
void usbHostEnable(bool enable) {
digitalWrite(USB_HOST_EN, enable);
}
extern "C" void initVariant(void) {
// Route USB to Device Side
pinMode(BOOST_EN, OUTPUT);
digitalWrite(BOOST_EN, LOW);
pinMode(LIMIT_EN, OUTPUT);
digitalWrite(LIMIT_EN, LOW);
pinMode(DEV_VBUS_EN, OUTPUT);
digitalWrite(DEV_VBUS_EN, LOW);
pinMode(USB_HOST_EN, OUTPUT);
digitalWrite(USB_HOST_EN, LOW);
// Turn Off LCD
pinMode(LCD_RST, OUTPUT);
digitalWrite(LCD_RST, LOW);
pinMode(LCD_BL, OUTPUT);
digitalWrite(LCD_BL, LOW);
}