Skip to content

Commit 7ea2384

Browse files
authored
Merge pull request #2445 from IngHK/ch34x_fix2444
fix #2444 and other small things
2 parents 68cc708 + e63a2f5 commit 7ea2384

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/class/cdc/cdc_host.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ static inline bool ch34x_control_in(cdch_interface_t* p_cdc, uint8_t request, ui
13451345
complete_cb, user_data);
13461346
}
13471347

1348-
static bool ch34x_write_reg(cdch_interface_t* p_cdc, uint16_t reg, uint16_t reg_value, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
1348+
static inline bool ch34x_write_reg(cdch_interface_t* p_cdc, uint16_t reg, uint16_t reg_value, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
13491349
return ch34x_control_out(p_cdc, CH34X_REQ_WRITE_REG, reg, reg_value, complete_cb, user_data);
13501350
}
13511351

@@ -1358,7 +1358,7 @@ static bool ch34x_write_reg(cdch_interface_t* p_cdc, uint16_t reg, uint16_t reg_
13581358
static bool ch34x_write_reg_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate,
13591359
tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
13601360
uint16_t const div_ps = ch34x_get_divisor_prescaler(baudrate);
1361-
TU_VERIFY(div_ps != 0);
1361+
TU_VERIFY(div_ps);
13621362
TU_ASSERT(ch34x_write_reg(p_cdc, CH34X_REG16_DIVISOR_PRESCALER, div_ps,
13631363
complete_cb, user_data));
13641364
return true;
@@ -1379,7 +1379,7 @@ static bool ch34x_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, ui
13791379
p_cdc->requested_line_coding.data_bits = data_bits;
13801380

13811381
uint8_t const lcr = ch34x_get_lcr(stop_bits, parity, data_bits);
1382-
TU_VERIFY(lcr != 0);
1382+
TU_VERIFY(lcr);
13831383
TU_ASSERT (ch34x_control_out(p_cdc, CH34X_REQ_WRITE_REG, CH32X_REG16_LCR2_LCR, lcr,
13841384
complete_cb ? ch34x_control_complete : NULL, user_data));
13851385
return true;
@@ -1395,6 +1395,7 @@ static bool ch34x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate,
13951395
}
13961396

13971397
static void ch34x_set_line_coding_stage1_complete(tuh_xfer_t* xfer) {
1398+
// CH34x only has 1 interface and use wIndex as payload and not for bInterfaceNumber
13981399
uint8_t const itf_num = 0;
13991400
uint8_t const idx = tuh_cdc_itf_get_index(xfer->daddr, itf_num);
14001401
cdch_interface_t* p_cdc = get_itf(idx);
@@ -1443,7 +1444,7 @@ static bool ch34x_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t con
14431444

14441445
// update transfer result, user_data is expected to point to xfer_result_t
14451446
if (user_data) {
1446-
user_data = result;
1447+
*((xfer_result_t*) user_data) = result;
14471448
}
14481449
}
14491450

@@ -1513,8 +1514,7 @@ static void ch34x_process_config(tuh_xfer_t* xfer) {
15131514
uintptr_t const state = xfer->user_data;
15141515
uint8_t buffer[2]; // TODO remove
15151516
TU_ASSERT (p_cdc,);
1516-
1517-
// TODO check xfer->result
1517+
TU_ASSERT (xfer->result == XFER_RESULT_SUCCESS,);
15181518

15191519
switch (state) {
15201520
case CONFIG_CH34X_READ_VERSION:
@@ -1531,9 +1531,9 @@ static void ch34x_process_config(tuh_xfer_t* xfer) {
15311531
// init CH34x with line coding
15321532
cdc_line_coding_t const line_coding = CFG_TUH_CDC_LINE_CODING_ON_ENUM_CH34X;
15331533
uint16_t const div_ps = ch34x_get_divisor_prescaler(line_coding.bit_rate);
1534-
TU_ASSERT(div_ps != 0, );
1534+
TU_ASSERT(div_ps, );
15351535
uint8_t const lcr = ch34x_get_lcr(line_coding.stop_bits, line_coding.parity, line_coding.data_bits);
1536-
TU_ASSERT(lcr != 0, );
1536+
TU_ASSERT(lcr, );
15371537
TU_ASSERT (ch34x_control_out(p_cdc, CH34X_REQ_SERIAL_INIT, tu_u16(lcr, 0x9c), div_ps,
15381538
ch34x_process_config, CONFIG_CH34X_SPECIAL_REG_WRITE),);
15391539
break;
@@ -1573,7 +1573,7 @@ static uint16_t ch34x_get_divisor_prescaler(uint32_t baval) {
15731573
uint8_t b;
15741574
uint32_t c;
15751575

1576-
TU_VERIFY(baval != 0, 0);
1576+
TU_VERIFY(baval != 0 && baval <= 2000000, 0);
15771577
switch (baval) {
15781578
case 921600:
15791579
a = 0xf3;
@@ -1627,7 +1627,7 @@ static uint8_t ch34x_get_lcr(uint8_t stop_bits, uint8_t parity, uint8_t data_bit
16271627
break;
16281628

16291629
case CDC_LINE_CODING_PARITY_ODD:
1630-
lcr |= CH34X_LCR_ENABLE_PAR;
1630+
lcr |= CH34X_LCR_ENABLE_PAR;
16311631
break;
16321632

16331633
case CDC_LINE_CODING_PARITY_EVEN:

0 commit comments

Comments
 (0)