chegewara / EspTinyUSB

ESP32S2 native USB library. Implemented few common classes, like MIDI, CDC, HID or DFU (update).
MIT License
473 stars 70 forks source link

ACM Host: get the hex values in CDC_DATA_IN #120

Open padaszewski opened 1 year ago

padaszewski commented 1 year ago

Hello,

I'm using the acm host example. I've managed to establish the communication between the host (ESP32 S3) and device, but I'm not retriving the expected output from the device.

Some logs:

[744950][I][acm.ino:118] loop(): Send sth
[744950][I][acm.ino:29] acm_events(): CDC_DATA_OUT
[744967][I][acm.ino:20] acm_events(): CDC_DATA_IN, 5
---here should be the cdc_data_in output printed ---

[744950][I][acm.ino:118] loop(): Send sth else
[744950][I][acm.ino:29] acm_events(): CDC_DATA_OUT
[744967][I][acm.ino:20] acm_events(): CDC_DATA_IN, 67
---here should be the cdc_data_in output printed again ---

I'm expecting to retrive a array of hex values, like 00 01 00 0a ..., but I'm unable to perform the mapping. This needs probably to be done here: (Btw what is the cf-Argument in the setLineCoding function?)

void acm_events(int event, void *data, size_t len)
{
  switch (event)
  {
    case CDC_CTRL_SET_CONTROL_LINE_STATE:
      log_i("CDC_CTRL_SET_CONTROL_LINE_STATE");
      device->setLineCoding(9600, 0, 0, 8);
      break;

    case CDC_DATA_IN:
      {
        log_i("CDC_DATA_IN, %d", len);
        device->INDATA();
        //here Im trying to find a solution
        uint8_t *buf = (uint8_t *)data;
        printf("%x", *buf);
        //buf[len] = 0;
        //printf("%x", (uint8_t *)data);
        break;
      }
    case CDC_DATA_OUT:
      log_i("CDC_DATA_OUT");
      break;

    case CDC_CTRL_SET_LINE_CODING:
      log_i("CDC_CTRL_SET_LINE_CODING");
      break;
  }
}

Actually after each CDC_DATA_OUT I should retrive a CDC_DATA_IN response, but this is not the case. Can it be this function again?

Greets!