wip
This commit is contained in:
parent
5fa3d89af8
commit
6f07f008c2
@ -21,12 +21,15 @@ class SerialUSBHost {
|
||||
|
||||
public:
|
||||
SerialUSBHost() = delete;
|
||||
static void init();
|
||||
static void init(uint32_t baudrate, uint8_t stop_bits, uint8_t parity, uint8_t dataBits);
|
||||
|
||||
static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx);
|
||||
static bool handle_rx(const uint8_t *data, size_t data_len, void *arg);
|
||||
|
||||
static void takeSem();//XXX
|
||||
|
||||
static cdc_acm_host_device_config_t* getDevConfig();
|
||||
static cdc_acm_line_coding_t* getLineCoding();
|
||||
private:
|
||||
/**
|
||||
* @brief USB Host library handling task
|
||||
|
@ -3,6 +3,19 @@
|
||||
|
||||
static SemaphoreHandle_t device_disconnected_sem;//XXX
|
||||
|
||||
|
||||
static cdc_acm_host_device_config_t dev_config = {
|
||||
.connection_timeout_ms = 5000, // 5 seconds, enough time to plug the device in or experiment with timeout
|
||||
.out_buffer_size = 512,
|
||||
.in_buffer_size = 512,
|
||||
.event_cb = SerialUSBHost::handle_event,
|
||||
.data_cb = SerialUSBHost::handle_rx,
|
||||
.user_arg = NULL,
|
||||
};
|
||||
|
||||
static cdc_acm_line_coding_t line_coding;
|
||||
|
||||
|
||||
static const char *TAG = "VCP example";
|
||||
|
||||
/**
|
||||
@ -19,6 +32,7 @@ static const char *TAG = "VCP example";
|
||||
*/
|
||||
bool SerialUSBHost::handle_rx(const uint8_t *data, size_t data_len, void *arg)
|
||||
{
|
||||
//ESP_LOGI("USB_HANDLE", "Recivend data !!");
|
||||
printf("%.*s", data_len, data);
|
||||
return true;
|
||||
}
|
||||
@ -65,7 +79,7 @@ void SerialUSBHost::usb_lib_task(void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void SerialUSBHost::init() {
|
||||
void SerialUSBHost::init(uint32_t baudrate, uint8_t stop_bits, uint8_t parity, uint8_t dataBits) {
|
||||
const String TAG = "SerialUSBHost_constructor";
|
||||
device_disconnected_sem = xSemaphoreCreateBinary();
|
||||
assert(device_disconnected_sem);
|
||||
@ -91,9 +105,21 @@ void SerialUSBHost::init() {
|
||||
esp_usb::VCP::register_driver<esp_usb::CP210x>();
|
||||
esp_usb::VCP::register_driver<esp_usb::CH34x>();
|
||||
|
||||
|
||||
line_coding.dwDTERate = baudrate;
|
||||
line_coding.bCharFormat = stop_bits;
|
||||
line_coding.bParityType = parity;
|
||||
line_coding.bDataBits = dataBits;
|
||||
}
|
||||
|
||||
|
||||
void SerialUSBHost::takeSem(){//XXX
|
||||
void SerialUSBHost::takeSem() {//XXX
|
||||
xSemaphoreTake(device_disconnected_sem, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
cdc_acm_host_device_config_t* SerialUSBHost::getDevConfig() {
|
||||
return &dev_config;
|
||||
}
|
||||
|
||||
cdc_acm_line_coding_t* SerialUSBHost::getLineCoding() {
|
||||
return &line_coding;
|
||||
}
|
||||
|
21
src/main.cpp
21
src/main.cpp
@ -18,23 +18,15 @@ static const char *TAG = "VCP example";
|
||||
|
||||
|
||||
void setup() {
|
||||
SerialUSBHost::init();
|
||||
SerialUSBHost::init(EXAMPLE_BAUDRATE, EXAMPLE_STOP_BITS, EXAMPLE_PARITY, EXAMPLE_DATA_BITS);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
const cdc_acm_host_device_config_t dev_config = {
|
||||
.connection_timeout_ms = 5000, // 5 seconds, enough time to plug the device in or experiment with timeout
|
||||
.out_buffer_size = 512,
|
||||
.in_buffer_size = 512,
|
||||
.event_cb = SerialUSBHost::handle_event,
|
||||
.data_cb = SerialUSBHost::handle_rx,
|
||||
.user_arg = NULL,
|
||||
};
|
||||
|
||||
// You don't need to know the device's VID and PID. Just plug in any device and the VCP service will load correct (already registered) driver for the device
|
||||
ESP_LOGI(TAG, "Opening any VCP device...");
|
||||
auto vcp = std::unique_ptr<CdcAcmDevice>(VCP::open(&dev_config));
|
||||
auto vcp = std::unique_ptr<CdcAcmDevice>(VCP::open(SerialUSBHost::getDevConfig()));
|
||||
|
||||
if (vcp == nullptr) {
|
||||
ESP_LOGI(TAG, "Failed to open VCP device");
|
||||
@ -44,13 +36,8 @@ void loop() {
|
||||
vTaskDelay(10);
|
||||
|
||||
ESP_LOGI(TAG, "Setting up line coding");
|
||||
cdc_acm_line_coding_t line_coding = {
|
||||
.dwDTERate = EXAMPLE_BAUDRATE,
|
||||
.bCharFormat = EXAMPLE_STOP_BITS,
|
||||
.bParityType = EXAMPLE_PARITY,
|
||||
.bDataBits = EXAMPLE_DATA_BITS,
|
||||
};
|
||||
ESP_ERROR_CHECK(vcp->line_coding_set(&line_coding));
|
||||
|
||||
ESP_ERROR_CHECK(vcp->line_coding_set(SerialUSBHost::getLineCoding()));
|
||||
|
||||
/*
|
||||
Now the USB-to-UART converter is configured and receiving data.
|
||||
|
Loading…
x
Reference in New Issue
Block a user