CDC: mount\unmount led notifications.
This commit is contained in:
parent
2dd0c4d2e3
commit
9a46514def
|
@ -6,6 +6,7 @@ set(SOURCES
|
|||
"led.c"
|
||||
"uart.c"
|
||||
"i2c.c"
|
||||
"delay.c"
|
||||
)
|
||||
|
||||
set(INCLUDES
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include "delay.h"
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
void delay(uint32_t ms) {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#include <stdint.h>
|
||||
|
||||
void delay(uint32_t ms);
|
|
@ -46,8 +46,9 @@ void app_main(void) {
|
|||
led_set_blue(255);
|
||||
|
||||
usb_cdc_init();
|
||||
// nvs_init();
|
||||
// wifi_init();
|
||||
|
||||
nvs_init();
|
||||
wifi_init();
|
||||
|
||||
pins_init();
|
||||
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
#include <tusb_cdc_acm.h>
|
||||
#include <sdkconfig.h>
|
||||
#include "usb-cdc.h"
|
||||
#include "led.h"
|
||||
#include "delay.h"
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#define USB_DN_PIN (19)
|
||||
#define USB_DP_PIN (20)
|
||||
|
||||
static const char* TAG = "usb-cdc";
|
||||
static uint8_t buffer_rx[CONFIG_USB_CDC_RX_BUFSIZE + 1];
|
||||
|
@ -112,13 +118,53 @@ void usb_cdc_line_coding_changed_callback(int itf, cdcacm_event_t* event) {
|
|||
//--------------------------------------------------------------------+
|
||||
// Device callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// It seems like a reliable way is to rely on tud_mount_cb on connect and tud_suspend_cb on disconnect
|
||||
void tud_mount_cb(void) {
|
||||
ESP_LOGI(TAG, "Mount");
|
||||
|
||||
if(!furi_hal_vcp.connected) {
|
||||
led_set_blue(255);
|
||||
delay(10);
|
||||
led_set_blue(0);
|
||||
}
|
||||
|
||||
furi_hal_vcp.connected = true;
|
||||
}
|
||||
|
||||
void tud_umount_cb(void) {
|
||||
ESP_LOGI(TAG, "Unmount");
|
||||
|
||||
if(furi_hal_vcp.connected) {
|
||||
led_set_blue(255);
|
||||
delay(10);
|
||||
led_set_blue(0);
|
||||
}
|
||||
|
||||
furi_hal_vcp.connected = false;
|
||||
}
|
||||
|
||||
void tud_resume_cb(void) {
|
||||
ESP_LOGI(TAG, "Resume");
|
||||
|
||||
if(furi_hal_vcp.connected) {
|
||||
led_set_blue(255);
|
||||
delay(10);
|
||||
led_set_blue(0);
|
||||
}
|
||||
|
||||
furi_hal_vcp.connected = true;
|
||||
}
|
||||
|
||||
void tud_suspend_cb(bool remote_wakeup_en) {
|
||||
ESP_LOGI(TAG, "Suspend");
|
||||
|
||||
if(furi_hal_vcp.connected) {
|
||||
led_set_blue(255);
|
||||
delay(10);
|
||||
led_set_blue(0);
|
||||
}
|
||||
|
||||
furi_hal_vcp.connected = false;
|
||||
}
|
||||
|
||||
|
@ -128,7 +174,27 @@ void usb_cdc_init(void) {
|
|||
furi_hal_vcp.rx_stream_full = false;
|
||||
|
||||
ESP_LOGI(TAG, "USB initialization");
|
||||
tinyusb_config_t tusb_cfg = {};
|
||||
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_OUTPUT_OD;
|
||||
io_conf.pin_bit_mask = ((1 << USB_DN_PIN) | (1 << USB_DP_PIN));
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
|
||||
gpio_set_level(USB_DN_PIN, 0);
|
||||
gpio_set_level(USB_DP_PIN, 0);
|
||||
delay(100);
|
||||
gpio_set_level(USB_DN_PIN, 1);
|
||||
gpio_set_level(USB_DP_PIN, 1);
|
||||
|
||||
tinyusb_config_t tusb_cfg = {
|
||||
.descriptor = NULL, //Uses default descriptor specified in Menuconfig
|
||||
.string_descriptor = NULL, //Uses default string specified in Menuconfig
|
||||
.external_phy = false,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
|
||||
|
||||
tinyusb_config_cdcacm_t amc_cfg = {
|
||||
|
|
|
@ -1039,7 +1039,7 @@ CONFIG_USB_DESC_USE_DEFAULT_PID=y
|
|||
CONFIG_USB_DESC_BCDDEVICE=0x0100
|
||||
CONFIG_USB_DESC_MANUFACTURER_STRING="Espressif Systems"
|
||||
CONFIG_USB_DESC_PRODUCT_STRING="Espressif Device"
|
||||
CONFIG_USB_DESC_SERIAL_STRING="123456"
|
||||
CONFIG_USB_DESC_SERIAL_STRING="blackmagic-esp32-s2"
|
||||
CONFIG_USB_DESC_CDC_STRING="Espressif CDC Device"
|
||||
# end of Descriptor configuration
|
||||
|
||||
|
|
Loading…
Reference in New Issue