@@ -1510,10 +1510,11 @@ static void ch34x_process_config(tuh_xfer_t* xfer) {
15101510 uint8_t const idx = tuh_cdc_itf_get_index (xfer -> daddr , itf_num );
15111511 cdch_interface_t * p_cdc = get_itf (idx );
15121512 uintptr_t const state = xfer -> user_data ;
1513- cdc_line_coding_t const line_coding = CFG_TUH_CDC_LINE_CODING_ON_ENUM_CH34X ;
15141513 uint8_t buffer [2 ]; // TODO remove
15151514 TU_ASSERT (p_cdc ,);
15161515
1516+ // TODO check xfer->result
1517+
15171518 switch (state ) {
15181519 case CONFIG_CH34X_READ_VERSION :
15191520 TU_LOG_DRV ("[%u] CDCh CH34x attempt to read Chip Version\r\n" , p_cdc -> daddr );
@@ -1527,20 +1528,28 @@ static void ch34x_process_config(tuh_xfer_t* xfer) {
15271528 // only versions >= 0x30 are tested, below 0x30 seems having other programming, see drivers from WCH vendor, Linux kernel and FreeBSD
15281529 TU_ASSERT (version >= 0x30 ,);
15291530
1531+ #ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
1532+ cdc_line_coding_t const line_coding = CFG_TUH_CDC_LINE_CODING_ON_ENUM ;
1533+ uint8_t const lcr = ch34x_get_lcr (line_coding .stop_bits , line_coding .parity , line_coding .data_bits );
1534+ uint16_t const first_arg = tu_u16 (lcr , 0x9c );
15301535 uint16_t const div_ps = ch34x_get_divisor_prescaler (line_coding .bit_rate );
15311536 TU_ASSERT (div_ps != 0 , );
1532-
1533- uint8_t const lcr = ch34x_get_lcr (line_coding .stop_bits , line_coding .parity , line_coding .data_bits );
1537+ #else
1538+ uint16_t const first_arg = 0 ;
1539+ uint16_t const div_ps = 0 ;
1540+ #endif
15341541
15351542 // Init CH34x with line coding
1536- TU_ASSERT (ch34x_control_out (p_cdc , CH34X_REQ_SERIAL_INIT , tu_u16 ( lcr , 0x9c ) , div_ps ,
1543+ TU_ASSERT (ch34x_control_out (p_cdc , CH34X_REQ_SERIAL_INIT , first_arg , div_ps ,
15371544 ch34x_process_config , CONFIG_CH34X_SPECIAL_REG_WRITE ),);
15381545 break ;
15391546 }
15401547
15411548 case CONFIG_CH34X_SPECIAL_REG_WRITE :
15421549 // do special reg write, purpose unknown, overtaken from WCH driver
1543- p_cdc -> line_coding = line_coding ;
1550+ #ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
1551+ p_cdc -> line_coding = ((cdc_line_coding_t ) CFG_TUH_CDC_LINE_CODING_ON_ENUM );
1552+ #endif
15441553 TU_ASSERT (ch34x_write_reg (p_cdc , 0x0f2c , 0x0007 , ch34x_process_config , CONFIG_CH34X_FLOW_CONTROL ),);
15451554 break ;
15461555
0 commit comments