update version to v2.0.5

This commit is contained in:
Artery-MCU
2022-05-23 20:00:00 +08:00
parent eab9bf65de
commit 6dc6595ed7
1034 changed files with 8706 additions and 2458 deletions

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file i2c_application.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief the driver library of the i2c peripheral
**************************************************************************
* Copyright notice & Disclaimer
@@ -278,7 +278,7 @@ i2c_status_type i2c_master_write_addr(i2c_handle_type *hi2c, uint16_t address, u
/* generate start condtion */
i2c_start_generate(hi2c->i2cx);
/* wait for the start falg to be set */
/* wait for the start flag to be set */
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_START;
@@ -296,7 +296,7 @@ i2c_status_type i2c_master_write_addr(i2c_handle_type *hi2c, uint16_t address, u
/* send slave 10-bit address header */
i2c_data_send(hi2c->i2cx, (uint8_t)((address & 0x0300) >> 7) | 0xF0);
/* wait for the addrh falg to be set */
/* wait for the addrh flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDRHF_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR10;
@@ -308,7 +308,7 @@ i2c_status_type i2c_master_write_addr(i2c_handle_type *hi2c, uint16_t address, u
i2c_data_send(hi2c->i2cx, (uint8_t)(address & 0x00FF));
}
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR;
@@ -334,7 +334,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
/* generate start condtion */
i2c_start_generate(hi2c->i2cx);
/* wait for the start falg to be set */
/* wait for the start flag to be set */
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_START;
@@ -352,7 +352,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
/* send slave 10-bit address header */
i2c_data_send(hi2c->i2cx, (uint8_t)((address & 0x0300) >> 7) | 0xF0);
/* wait for the addrh falg to be set */
/* wait for the addrh flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDRHF_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR10;
@@ -363,7 +363,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
/* send slave address */
i2c_data_send(hi2c->i2cx, (uint8_t)(address & 0x00FF));
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR;
@@ -377,7 +377,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
/* generate restart condtion */
i2c_start_generate(hi2c->i2cx);
/* wait for the start falg to be set */
/* wait for the start flag to be set */
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_START;
@@ -389,7 +389,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
i2c_data_send(hi2c->i2cx, (uint8_t)((address & 0x0300) >> 7) | 0xF1);
}
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR;
@@ -417,7 +417,7 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -440,7 +440,7 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin
while(size > 0)
{
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -454,7 +454,7 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin
size--;
}
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -485,7 +485,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -497,7 +497,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
/* enable ack */
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -511,7 +511,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
while(size > 0)
{
/* wait for the rdbf falg to be set */
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK)
{
/* disable ack */
@@ -525,7 +525,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
size--;
}
/* wait for the stop falg to be set */
/* wait for the stop flag to be set */
if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* disable ack */
@@ -560,7 +560,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -619,7 +619,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
/* 1 byte */
if(size == 1)
{
/* wait for the rdbf falg to be set */
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -635,7 +635,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
/* 2 bytes */
else if(size == 2)
{
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -658,7 +658,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
/* 3 last bytes */
else
{
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -674,7 +674,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
(*pdata++) = i2c_data_receive(hi2c->i2cx);
size--;
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -697,7 +697,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
}
else
{
/* wait for the rdbf falg to be set */
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -731,7 +731,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -743,7 +743,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
/* enable ack */
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -757,7 +757,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
if(hi2c->i2cx->oaddr1_bit.addr1mode == I2C_ADDRESS_MODE_10BIT)
{
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -772,7 +772,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
while(size > 0)
{
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* disable ack */
@@ -786,7 +786,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
size--;
}
/* wait for the ackfail falg to be set */
/* wait for the ackfail flag to be set */
if(i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_5;
@@ -822,7 +822,7 @@ i2c_status_type i2c_master_transmit_int(i2c_handle_type* hi2c, uint16_t address,
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -844,7 +844,7 @@ i2c_status_type i2c_master_transmit_int(i2c_handle_type* hi2c, uint16_t address,
i2c_addr_flag_clear(hi2c);
/* enable interrupt */
i2c_interrupt_enable(I2C1, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
return I2C_OK;
}
@@ -869,7 +869,7 @@ i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uin
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -881,7 +881,7 @@ i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uin
/* enable ack */
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_2;
@@ -891,7 +891,7 @@ i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uin
i2c_addr_flag_clear(hi2c);
/* enable interrupt */
i2c_interrupt_enable(I2C1, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
return I2C_OK;
}
@@ -917,7 +917,7 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address,
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -970,7 +970,7 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address,
}
/* enable interrupt */
i2c_interrupt_enable(I2C1, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
return I2C_OK;
}
@@ -995,7 +995,7 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1007,7 +1007,7 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
/* enable ack */
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_2;
@@ -1018,7 +1018,7 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
if(hi2c->i2cx->oaddr1_bit.addr1mode == I2C_ADDRESS_MODE_10BIT)
{
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -1032,7 +1032,7 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
}
/* enable interrupt */
i2c_interrupt_enable(I2C1, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
return I2C_OK;
}
@@ -1058,7 +1058,7 @@ i2c_status_type i2c_master_transmit_dma(i2c_handle_type* hi2c, uint16_t address,
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1111,7 +1111,7 @@ i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uin
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1129,7 +1129,7 @@ i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uin
/* configure the dma channel */
i2c_dma_config(hi2c, hi2c->dma_rx_channel, pdata, size);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -1168,7 +1168,7 @@ i2c_status_type i2c_master_receive_dma(i2c_handle_type* hi2c, uint16_t address,
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1244,7 +1244,7 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1263,7 +1263,7 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
i2c_dma_config(hi2c, hi2c->dma_tx_channel, pdata, size);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -1277,7 +1277,7 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the addr7 falg to be set */
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
@@ -1314,7 +1314,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1335,7 +1335,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1349,7 +1349,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
while(size > 0)
{
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1363,7 +1363,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
size--;
}
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1396,7 +1396,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1420,7 +1420,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1432,7 +1432,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
/* send memory address */
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1488,7 +1488,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
/* 1 byte */
if(size == 1)
{
/* wait for the rdbf falg to be set */
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1504,7 +1504,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
/* 2 bytes */
else if(size == 2)
{
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1527,7 +1527,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
/* 3 last bytes */
else
{
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1543,7 +1543,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
(*pdata++) = i2c_data_receive(hi2c->i2cx);
size--;
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1566,7 +1566,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
}
else
{
/* wait for the rdbf falg to be set */
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1606,7 +1606,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1627,7 +1627,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1639,7 +1639,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
/* send memory address */
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1649,7 +1649,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
}
/* enable interrupt */
i2c_interrupt_enable(I2C1, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
return I2C_OK;
}
@@ -1676,7 +1676,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1697,7 +1697,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1709,7 +1709,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
/* send memory address */
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1759,7 +1759,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
}
/* enable interrupt */
i2c_interrupt_enable(I2C1, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
return I2C_OK;
}
@@ -1786,7 +1786,7 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1813,7 +1813,7 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1825,7 +1825,7 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
/* send memory address */
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1862,7 +1862,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
hi2c->timeout = timeout;
hi2c->error_code = I2C_OK;
/* wait for the busy falg to be reset */
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
@@ -1892,7 +1892,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -1904,7 +1904,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
/* send memory address */
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe falg to be set */
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
@@ -2075,7 +2075,7 @@ void i2c_slave_tx_isr_int(i2c_handle_type* hi2c)
/* disable interrupt */
i2c_interrupt_enable(hi2c->i2cx, I2C_DATA_INT | I2C_EVT_INT | I2C_ERR_INT, FALSE);
/* wait for the ackfail falg to be set */
/* wait for the ackfail flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* clear ackfail flag */
@@ -2166,14 +2166,14 @@ void i2c_dma_tx_irq_handler(i2c_handle_type* hi2c)
switch(hi2c->mode)
{
case I2C_DMA_MA_TX:
/* wait for the tdc falg to be set */
/* wait for the tdc flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
break;
case I2C_DMA_SLA_TX:
/* wait for the ackfail falg to be set */
/* wait for the ackfail flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* clear ackfail flag */
@@ -2225,7 +2225,7 @@ void i2c_dma_rx_irq_handler(i2c_handle_type* hi2c)
}
break;
case I2C_DMA_SLA_RX:
/* wait for the stop falg to be set */
/* wait for the stop flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_STOPF_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* clear stop flag */

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file i2c_application.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief i2c application libray header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio class file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_conf.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio config
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_conf.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio config
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio class type
**************************************************************************
* Copyright notice & Disclaimer
@@ -830,6 +830,7 @@ static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
paudio_hid->g_txhid_buff[i_index] = report[i_index];
}
usbd_ept_send(pudev, USBD_AUHID_HID_IN_EPT, paudio_hid->g_txhid_buff, len);
break;
default:
break;
}

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio class file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file audio_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb audio descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc class file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc and keyboard class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc and keyboard class file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc and keyboard device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc and keyboard descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -0,0 +1,571 @@
/**
**************************************************************************
* @file cdc_msc_class.c
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc class type
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "usbd_core.h"
#include "cdc_msc_class.h"
#include "cdc_msc_desc.h"
/** @addtogroup AT32F413_middlewares_usbd_class
* @{
*/
/** @defgroup USB_cdc_msc_class
* @brief usb device class cdc msc demo
* @{
*/
/** @defgroup USB_cdc_msc_class_private_functions
* @{
*/
static usb_sts_type class_init_handler(void *udev);
static usb_sts_type class_clear_handler(void *udev);
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
static usb_sts_type class_ept0_tx_handler(void *udev);
static usb_sts_type class_ept0_rx_handler(void *udev);
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
static usb_sts_type class_sof_handler(void *udev);
static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
static usb_sts_type cdc_struct_init(cdc_msc_struct_type *pcdc);
extern void usb_usart_config( linecoding_type linecoding);
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup);
static usb_sts_type msc_class_setup_handler(void *udev, usb_setup_type *setup);
linecoding_type linecoding =
{
115200,
0,
0,
8
};
/* cdc data struct */
cdc_msc_struct_type cdc_msc_struct;
/* usb device class handler */
usbd_class_handler cdc_msc_class_handler =
{
class_init_handler,
class_clear_handler,
class_setup_handler,
class_ept0_tx_handler,
class_ept0_rx_handler,
class_in_handler,
class_out_handler,
class_sof_handler,
class_event_handler,
&cdc_msc_struct //cdc_struct
};
/**
* @brief initialize usb custom hid endpoint
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
static usb_sts_type class_init_handler(void *udev)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdcmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
/* init cdc struct */
cdc_struct_init(pcdcmsc);
/* open in endpoint */
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CDC_CMD_MAXPACKET_SIZE);
/* open in endpoint */
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_CDC_MSC_IN_MAXPACKET_SIZE);
/* open out endpoint */
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_CDC_MSC_OUT_MAXPACKET_SIZE);
/* set out endpoint to receive status */
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdcmsc->g_rx_buff, USBD_CDC_MSC_OUT_MAXPACKET_SIZE);
/* open in endpoint */
usbd_ept_open(pudev, USBD_MSC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_CDC_MSC_IN_MAXPACKET_SIZE);
/* open out endpoint */
usbd_ept_open(pudev, USBD_MSC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_CDC_MSC_OUT_MAXPACKET_SIZE);
bot_scsi_init(udev);
return status;
}
/**
* @brief clear endpoint or other state
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
static usb_sts_type class_clear_handler(void *udev)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
/* close in endpoint */
usbd_ept_close(pudev, USBD_CDC_INT_EPT);
/* close in endpoint */
usbd_ept_close(pudev, USBD_CDC_BULK_IN_EPT);
/* close out endpoint */
usbd_ept_close(pudev, USBD_CDC_BULK_OUT_EPT);
/* close in endpoint */
usbd_ept_close(pudev, USBD_MSC_BULK_IN_EPT);
/* close out endpoint */
usbd_ept_close(pudev, USBD_MSC_BULK_OUT_EPT);
return status;
}
/**
* @brief usb device class setup request handler
* @param udev: to the structure of usbd_core_type
* @param setup: setup packet
* @retval status of usb_sts_type
*/
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
switch(setup->bmRequestType & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_INTERFACE:
if(setup->wIndex == VCPMSC_MSC_INTERFACE)
{
msc_class_setup_handler(udev, setup);
}
else
{
cdc_class_setup_handler(pudev, setup);
}
break;
case USB_REQ_RECIPIENT_ENDPOINT:
if(setup->wIndex == (USBD_MSC_BULK_IN_EPT | USBD_MSC_BULK_OUT_EPT))
{
msc_class_setup_handler(udev, setup);
}
else
{
cdc_class_setup_handler(pudev, setup);
}
break;
}
return status;
}
/**
* @brief usb device class setup request handler
* @param udev: to the structure of usbd_core_type
* @param setup: setup packet
* @retval status of usb_sts_type
*/
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
{
/* class request */
case USB_REQ_TYPE_CLASS:
if(setup->wLength)
{
if(setup->bmRequestType & USB_REQ_DIR_DTH)
{
usb_vcp_cmd_process(udev, setup->bRequest, pcdc->g_cmd, setup->wLength);
usbd_ctrl_send(pudev, pcdc->g_cmd, setup->wLength);
}
else
{
pcdc->g_req = setup->bRequest;
pcdc->g_len = setup->wLength;
usbd_ctrl_recv(pudev, pcdc->g_cmd, pcdc->g_len);
}
}
break;
/* standard request */
case USB_REQ_TYPE_STANDARD:
switch(setup->bRequest)
{
case USB_STD_REQ_GET_DESCRIPTOR:
usbd_ctrl_unsupport(pudev);
break;
case USB_STD_REQ_GET_INTERFACE:
usbd_ctrl_send(pudev, (uint8_t *)&pcdc->alt_setting, 1);
break;
case USB_STD_REQ_SET_INTERFACE:
pcdc->alt_setting = setup->wValue;
break;
default:
break;
}
break;
default:
usbd_ctrl_unsupport(pudev);
break;
}
return status;
}
/**
* @brief usb device class setup request handler
* @param udev: to the structure of usbd_core_type
* @param setup: setup packet
* @retval status of usb_sts_type
*/
static usb_sts_type msc_class_setup_handler(void *udev, usb_setup_type *setup)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
{
/* class request */
case USB_REQ_TYPE_CLASS:
switch(setup->bRequest)
{
case MSC_REQ_GET_MAX_LUN:
usbd_ctrl_send(pudev, (uint8_t *)&cdc_msc_struct.max_lun, 1);
break;
case MSC_REQ_BO_RESET:
bot_scsi_reset(udev);
usbd_ctrl_send_status(pudev);
break;
default:
usbd_ctrl_unsupport(pudev);
break;
}
break;
/* standard request */
case USB_REQ_TYPE_STANDARD:
switch(setup->bRequest)
{
case USB_STD_REQ_GET_DESCRIPTOR:
usbd_ctrl_unsupport(pudev);
break;
case USB_STD_REQ_GET_INTERFACE:
usbd_ctrl_send(pudev, (uint8_t *)&pmsc->alt_setting, 1);
break;
case USB_STD_REQ_SET_INTERFACE:
pmsc->alt_setting = setup->wValue;
break;
case USB_STD_REQ_CLEAR_FEATURE:
usbd_ept_close(pudev, (uint8_t)setup->wIndex);
if((setup->wIndex & 0x80) == 0x80)
{
usbd_ept_open(pudev, (uint8_t)setup->wIndex, EPT_BULK_TYPE, USBD_CDC_MSC_IN_MAXPACKET_SIZE);
}
else
{
usbd_ept_open(pudev, (uint8_t)setup->wIndex, EPT_BULK_TYPE, USBD_CDC_MSC_OUT_MAXPACKET_SIZE);
}
bot_scsi_clear_feature(udev, setup->wIndex);
break;
default:
break;
}
break;
default:
usbd_ctrl_unsupport(pudev);
break;
}
return status;
}
/**
* @brief usb device endpoint 0 in status stage complete
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
static usb_sts_type class_ept0_tx_handler(void *udev)
{
usb_sts_type status = USB_OK;
/* ...user code... */
return status;
}
/**
* @brief usb device endpoint 0 out status stage complete
* @param udev: usb device core handler type
* @retval status of usb_sts_type
*/
static usb_sts_type class_ept0_rx_handler(void *udev)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
/* ...user code... */
if( pcdc->g_req == SET_LINE_CODING)
{
/* class process */
usb_vcp_cmd_process(udev, pcdc->g_req, pcdc->g_cmd, recv_len);
}
return status;
}
/**
* @brief usb device transmision complete handler
* @param udev: to the structure of usbd_core_type
* @param ept_num: endpoint number
* @retval status of usb_sts_type
*/
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdcmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
usb_sts_type status = USB_OK;
/* ...user code...
trans next packet data
*/
if((ept_num & 0x7F) == (USBD_CDC_BULK_IN_EPT & 0x7F))
{
pcdcmsc->g_tx_completed = 1;
}
if((ept_num & 0x7F) == (USBD_MSC_BULK_IN_EPT & 0x7F))
{
bot_scsi_datain_handler(udev, ept_num);
}
return status;
}
/**
* @brief usb device endpoint receive data
* @param udev: to the structure of usbd_core_type
* @param ept_num: endpoint number
* @retval status of usb_sts_type
*/
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdcmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if((ept_num & 0x7F) == (USBD_CDC_BULK_OUT_EPT & 0x7F))
{
/* get endpoint receive data length */
pcdcmsc->g_rxlen = usbd_get_recv_len(pudev, ept_num);
/*set recv flag*/
pcdcmsc->g_rx_completed = 1;
}
if((ept_num & 0x7F) == (USBD_MSC_BULK_OUT_EPT & 0x7F))
{
bot_scsi_dataout_handler(udev, ept_num);
}
return status;
}
/**
* @brief usb device sof handler
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
static usb_sts_type class_sof_handler(void *udev)
{
usb_sts_type status = USB_OK;
/* ...user code... */
return status;
}
/**
* @brief usb device event handler
* @param udev: to the structure of usbd_core_type
* @param event: usb device event
* @retval status of usb_sts_type
*/
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
{
usb_sts_type status = USB_OK;
switch(event)
{
case USBD_RESET_EVENT:
/* ...user code... */
break;
case USBD_SUSPEND_EVENT:
/* ...user code... */
break;
case USBD_WAKEUP_EVENT:
/* ...user code... */
break;
default:
break;
}
return status;
}
/**
* @brief usb device cdc init
* @param pcdc: to the structure of cdc_struct
* @retval status of usb_sts_type
*/
static usb_sts_type cdc_struct_init(cdc_msc_struct_type *pcdc)
{
pcdc->g_tx_completed = 1;
pcdc->g_rx_completed = 0;
pcdc->alt_setting = 0;
pcdc->linecoding.bitrate = linecoding.bitrate;
pcdc->linecoding.data = linecoding.data;
pcdc->linecoding.format = linecoding.format;
pcdc->linecoding.parity = linecoding.parity;
return USB_OK;
}
/**
* @brief usb device class rx data process
* @param udev: to the structure of usbd_core_type
* @param recv_data: receive buffer
* @retval receive data len
*/
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
{
uint16_t i_index = 0;
uint16_t tmp_len = 0;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if(pcdc->g_rx_completed == 0)
{
return 0;
}
pcdc->g_rx_completed = 0;
tmp_len = pcdc->g_rxlen;
for(i_index = 0; i_index < pcdc->g_rxlen; i_index ++)
{
recv_data[i_index] = pcdc->g_rx_buff[i_index];
}
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_MSC_OUT_MAXPACKET_SIZE);
return tmp_len;
}
/**
* @brief usb device class send data
* @param udev: to the structure of usbd_core_type
* @param send_data: send data buffer
* @param len: send length
* @retval error status
*/
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
{
error_status status = SUCCESS;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if(pcdc->g_tx_completed)
{
pcdc->g_tx_completed = 0;
usbd_ept_send(pudev, USBD_CDC_BULK_IN_EPT, send_data, len);
}
else
{
status = ERROR;
}
return status;
}
/**
* @brief usb device function
* @param udev: to the structure of usbd_core_type
* @param cmd: request number
* @param buff: request buffer
* @param len: buffer length
* @retval none
*/
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pcdc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
switch(cmd)
{
case SET_LINE_CODING:
pcdc->linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
pcdc->linecoding.format = buff[4];
pcdc->linecoding.parity = buff[5];
pcdc->linecoding.data = buff[6];
#ifdef USB_VIRTUAL_COMPORT
/* set hardware usart */
usb_usart_config(pcdc->linecoding);
#endif
break;
case GET_LINE_CODING:
buff[0] = (uint8_t)pcdc->linecoding.bitrate;
buff[1] = (uint8_t)(pcdc->linecoding.bitrate >> 8);
buff[2] = (uint8_t)(pcdc->linecoding.bitrate >> 16);
buff[3] = (uint8_t)(pcdc->linecoding.bitrate >> 24);
buff[4] = (uint8_t)(pcdc->linecoding.format);
buff[5] = (uint8_t)(pcdc->linecoding.parity);
buff[6] = (uint8_t)(pcdc->linecoding.data);
break;
default:
break;
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/

View File

@@ -0,0 +1,338 @@
/**
**************************************************************************
* @file cdc_msc_class.h
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc class file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __CDC_MSC_CLASS_H
#define __CDC_MSC_CLASS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "usb_std.h"
#include "usbd_core.h"
/** @addtogroup AT32F413_middlewares_usbd_class
* @{
*/
/** @addtogroup USB_cdc_msc_class
* @{
*/
/** @defgroup USB_cdc_class_definition
* @{
*/
/**
* @brief usb cdc use endpoint define
*/
#define USBD_CDC_INT_EPT 0x82
#define USBD_CDC_BULK_IN_EPT 0x83
#define USBD_CDC_BULK_OUT_EPT 0x02
#define USBD_MSC_BULK_IN_EPT 0x81
#define USBD_MSC_BULK_OUT_EPT 0x01
/**
* @brief usb cdc in and out max packet size define
*/
#define USBD_CDC_MSC_IN_MAXPACKET_SIZE 0x40
#define USBD_CDC_MSC_OUT_MAXPACKET_SIZE 0x40
#define USBD_CDC_CMD_MAXPACKET_SIZE 0x08
/**
* @}
*/
/** @defgroup USB_cdc_class_exported_types
* @{
*/
/** @defgroup USB_msc_bot_scsi_definition
* @{
*/
#define MSC_SUPPORT_MAX_LUN 1
#define MSC_MAX_DATA_BUF_LEN 4096
#define MSC_CMD_FORMAT_UNIT 0x04
#define MSC_CMD_INQUIRY 0x12
#define MSC_CMD_START_STOP 0x1B
#define MSC_CMD_MODE_SENSE6 0x1A
#define MSC_CMD_MODE_SENSE10 0x5A
#define MSC_CMD_ALLOW_MEDIUM_REMOVAL 0x1E
#define MSC_CMD_READ_10 0x28
#define MSC_CMD_READ_12 0xA8
#define MSC_CMD_READ_CAPACITY 0x25
#define MSC_CMD_READ_FORMAT_CAPACITY 0x23
#define MSC_CMD_REQUEST_SENSE 0x03
#define MSC_CMD_TEST_UNIT 0x00
#define MSC_CMD_VERIFY 0x2F
#define MSC_CMD_WRITE_10 0x2A
#define MSC_CMD_WRITE_12 0xAA
#define MSC_CMD_WRITE_VERIFY 0x2E
#define MSC_REQ_GET_MAX_LUN 0xFE /*!< get max lun */
#define MSC_REQ_BO_RESET 0xFF /*!< bulk only mass storage reset */
#define SET_LINE_CODING 0x20
#define GET_LINE_CODING 0x21
#define CBW_CMD_LENGTH 31
#define CBW_DCBWSIGNATURE 0x43425355
#define CBW_BMCBWFLAGS_DIR_OUT 0x00
#define CBW_BMCBWFLAGS_DIR_IN 0x80
#define CSW_CMD_LENGTH 13
#define CSW_DCSWSIGNATURE 0x53425355
#define CSW_BCSWSTATUS_PASS 0x00
#define CSW_BCSWSTATUS_FAILED 0x01
#define CSW_BCSWSTATUS_PHASE_ERR 0x02
#define MSC_STATE_MACHINE_CMD 0x00
#define MSC_STATE_MACHINE_DATA_IN 0x01
#define MSC_STATE_MACHINE_DATA_OUT 0x02
#define MSC_STATE_MACHINE_SEND_DATA 0x03
#define MSC_STATE_MACHINE_LAST_DATA 0x04
#define MSC_STATE_MACHINE_STATUS 0x05
#define MSC_STATE_MACHINE_FAILED 0x06
#define MSC_STATE_MACHINE_IDLE 0x07
#define MSC_BOT_STATE_IDLE 0x00
#define MSC_BOT_STATE_RECOVERY 0x01
#define MSC_BOT_STATE_ERROR 0x02
#define REQ_SENSE_STANDARD_DATA_LEN 0x12
#define SENSE_KEY_NO_SENSE 0x00
#define SENSE_KEY_RECOVERED_ERROR 0x01
#define SENSE_KEY_NOT_READY 0x02
#define SENSE_KEY_MEDIUM_ERROR 0x03
#define SENSE_KEY_HARDWARE_ERROR 0x04
#define SENSE_KEY_ILLEGAL_REQUEST 0x05
#define SENSE_KEY_UNIT_ATTENTION 0x06
#define SENSE_KEY_DATA_PROTECT 0x07
#define SENSE_KEY_BLANK_CHECK 0x08
#define SENSE_KEY_VENDERO_SPECIFIC 0x09
#define SENSE_KEY_ABORTED_COMMAND 0x0B
#define SENSE_KEY_VOLUME_OVERFLOW 0x0D
#define SENSE_KEY_MISCOMPARE 0x0E
#define INVALID_COMMAND 0x20
#define INVALID_FIELED_IN_COMMAND 0x24
#define PARAMETER_LIST_LENGTH_ERROR 0x1A
#define INVALID_FIELD_IN_PARAMETER_LIST 0x26
#define ADDRESS_OUT_OF_RANGE 0x21
#define MEDIUM_NOT_PRESENT 0x3A
#define MEDIUM_HAVE_CHANGED 0x28
#define SCSI_INQUIRY_DATA_LENGTH 36
/**
* @brief typical command block description
*/
typedef struct
{
uint8_t opcode;
uint8_t lun;
uint32_t address;
uint8_t reserved1;
uint32_t alloc_length;
uint16_t reserved2;
}cbd_typical_type;
/**
* @brief extended command block description
*/
typedef struct
{
uint8_t opcode;
uint8_t lun;
uint32_t address;
uint8_t reserved1;
uint32_t alloc_length;
uint16_t reserved2;
}cbd_extended_type;
/**
* @brief command block wrapper
*/
typedef struct
{
uint32_t dCBWSignature;
uint32_t dCBWTage;
uint32_t dCBWDataTransferLength;
uint8_t bmCBWFlags;
uint8_t bCBWLUN;
uint8_t bCBWCBLength;
uint8_t CBWCB[16];
}cbw_type;
/**
* @brief command block wrapper
*/
typedef struct
{
uint32_t dCSWSignature;
uint32_t dCSWTag;
uint32_t dCSWDataResidue;
uint32_t bCSWStatus;
}csw_type;
/**
* @brief request sense standard data
*/
typedef struct
{
uint8_t err_code;
uint8_t reserved1;
uint8_t sense_key;
uint32_t information;
uint8_t as_length;
uint32_t reserved2;
uint8_t asc;
uint8_t ascq;
uint32_t reserved3;
}sense_type;
typedef struct
{
uint8_t msc_state;
uint8_t bot_status;
uint32_t max_lun;
uint32_t blk_nbr[MSC_SUPPORT_MAX_LUN];
uint32_t blk_size[MSC_SUPPORT_MAX_LUN];
uint32_t blk_addr;
uint32_t blk_len;
uint32_t data_len;
uint8_t data[MSC_MAX_DATA_BUF_LEN];
uint32_t alt_setting;
cbw_type cbw_struct;
csw_type csw_struct;
}msc_type;
/**
* @brief usb cdc class struct
*/
typedef struct
{
//used for CDC
uint32_t alt_setting;
uint8_t g_rx_buff[USBD_CDC_MSC_OUT_MAXPACKET_SIZE];
uint8_t g_cmd[USBD_CDC_CMD_MAXPACKET_SIZE];
uint8_t g_req;
uint16_t g_len, g_rxlen;
__IO uint8_t g_tx_completed, g_rx_completed;
linecoding_type linecoding;
//used for MSC
uint8_t msc_state;
uint8_t bot_status;
uint32_t max_lun;
uint32_t blk_nbr[MSC_SUPPORT_MAX_LUN];
uint32_t blk_size[MSC_SUPPORT_MAX_LUN];
uint32_t blk_addr;
uint32_t blk_len;
uint32_t data_len;
uint8_t data[MSC_MAX_DATA_BUF_LEN];
cbw_type cbw_struct;
csw_type csw_struct;
}cdc_msc_struct_type; //cdc_struct_type;
/**
* @}
*/
/** @defgroup USB_cdc_msc_class_exported_functions
* @{
*/
extern usbd_class_handler cdc_msc_class_handler; //cdc_class_handler;
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data);
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
void bot_scsi_init(void *udev);
void bot_scsi_reset(void *udev);
void bot_scsi_datain_handler(void *pudev, uint8_t ept_num);
void bot_scsi_dataout_handler(void *pudev, uint8_t ept_num);
void bot_cbw_decode(void *udev);
void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len);
void bot_scsi_send_csw(void *udev, uint8_t status);
void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc);
usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset, uint32_t blk_count);
void bot_scsi_stall(void *udev);
usb_sts_type bot_scsi_cmd_process(void *udev);
usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun);
usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun);
usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun);
usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun);
usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun);
usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun);
usb_sts_type bot_scsi_read10(void *udev, uint8_t lun);
usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun);
usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun);
usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun);
usb_sts_type bot_scsi_verify(void *udev, uint8_t lun);
usb_sts_type bot_scsi_write10(void *udev, uint8_t lun);
void bot_scsi_clear_feature(void *udev, uint8_t ept_num);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,498 @@
/**
**************************************************************************
* @file cdc_msc_desc.c
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc device descriptor
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "stdio.h"
#include "usb_std.h"
#include "usbd_sdr.h"
#include "usbd_core.h"
#include "cdc_msc_desc.h"
/** @addtogroup AT32F413_middlewares_usbd_class
* @{
*/
/** @defgroup USB_cdc_msc_desc
* @brief usb device cdc msc descriptor
* @{
*/
/** @defgroup USB_cdc_msc_desc_private_functions
* @{
*/
#define USB_INTERFACE_ASSOCIATION_TYPE 0x0B
static usbd_desc_t *get_device_descriptor(void);
static usbd_desc_t *get_device_qualifier(void);
static usbd_desc_t *get_device_configuration(void);
static usbd_desc_t *get_device_other_speed(void);
static usbd_desc_t *get_device_lang_id(void);
static usbd_desc_t *get_device_manufacturer_string(void);
static usbd_desc_t *get_device_product_string(void);
static usbd_desc_t *get_device_serial_string(void);
static usbd_desc_t *get_device_interface_string(void);
static usbd_desc_t *get_device_config_string(void);
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len);
static void get_serial_num(void);
static uint8_t g_usbd_desc_buffer[256];
/**
* @brief device descriptor handler structure
*/
usbd_desc_handler cdc_msc_desc_handler =
{
get_device_descriptor,
get_device_qualifier,
get_device_configuration,
get_device_other_speed,
get_device_lang_id,
get_device_manufacturer_string,
get_device_product_string,
get_device_serial_string,
get_device_interface_string,
get_device_config_string,
};
/**
* @brief usb device standard descriptor
*/
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD static uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
{
USB_DEVICE_DESC_LEN, /* bLength */
USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */
0x00, /* bcdUSB */
0x02,
0xEF, /* bDeviceClass */
0x02, /* bDeviceSubClass */
0x01, /* bDeviceProtocol */
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
LBYTE(USBD_CDC_MSC_VENDOR_ID), /* idVendor */
HBYTE(USBD_CDC_MSC_VENDOR_ID), /* idVendor */
LBYTE(USBD_CDC_MSC_PRODUCT_ID), /* idProduct */
HBYTE(USBD_CDC_MSC_PRODUCT_ID), /* idProduct */
0x00, /* bcdDevice rel. 2.00 */
0x02,
USB_MFC_STRING, /* Index of manufacturer string */
USB_PRODUCT_STRING, /* Index of product string */
USB_SERIAL_STRING, /* Index of serial number string */
1 /* bNumConfigurations */
};
/**
* @brief usb configuration standard descriptor
*/
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CDC_MSC_CONFIG_DESC_SIZE] ALIGNED_TAIL =
{
USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */
USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */
LBYTE(USBD_CDC_MSC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
HBYTE(USBD_CDC_MSC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
0x03, /* bNumInterfaces: 3 interface */
0x01, /* bConfigurationValue: configuration value */
0x00, /* iConfiguration: index of string descriptor describing
the configuration */
0xC0, /* bmAttributes: self powered */
0x32, /* MaxPower 100 mA: this current is used for detecting vbus */
// IAD (Interface Association Descriptor) for MSC
0x08, /* bLength */
USB_INTERFACE_ASSOCIATION_TYPE, /* bDescriptorType */
0x00, /* bFirstInterface */
0x01, /* bInterfaceCount */
0x08, /* bFunctionClass */
0x06, /* bFunctionSubClass */
0x50, /* bFunctionProtocol */
0x00, /* iFunction (Index of string descriptor describing this function) */
// Configuration Descriptor for MSC
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
VCPMSC_MSC_INTERFACE, /* bInterfaceNumber: number of interface */
0x00, /* bAlternateSetting: alternate set */
0x02, /* bNumEndpoints: number of endpoints */
USB_CLASS_CODE_MSC, /* bInterfaceClass: msc class code */
0x06, /* bInterfaceSubClass: subclass code scsi */
0x50, /* bInterfaceProtocol: protocol code BBB */
0x00, /* iInterface: index of string descriptor */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_MSC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
LBYTE(USBD_CDC_MSC_IN_MAXPACKET_SIZE),
HBYTE(USBD_CDC_MSC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_MSC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
LBYTE(USBD_CDC_MSC_OUT_MAXPACKET_SIZE),
HBYTE(USBD_CDC_MSC_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
// IAD (Interface Association Descriptor) for CDC
0x08, /* bLength */
USB_INTERFACE_ASSOCIATION_TYPE, /* bDescriptorType */
0x01, /* bFirstInterface */
0x02, /* bInterfaceCount */
USB_CLASS_CODE_CDC, /* bFunctionClass */
0x02, /* bFunctionSubClass */
0x01, /* bFunctionProtocol */
0x00, /* iFunction (Index of string descriptor describing this function) */
// Configuration Descriptor for CDC
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
VCPMSC_CDC_INTERFACE, /* bInterfaceNumber: number of interface */
0x00, /* bAlternateSetting: alternate set */
0x01, /* bNumEndpoints: number of endpoints */
USB_CLASS_CODE_CDC, /* bInterfaceClass: CDC class code */
0x02, /* bInterfaceSubClass: subclass code, Abstract Control Model*/
0x01, /* bInterfaceProtocol: protocol code, AT Command */
0x00, /* iInterface: index of string descriptor */
0x05, /* bFunctionLength: size of this descriptor in bytes */
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/
LBYTE(CDC_BCD_NUM),
HBYTE(CDC_BCD_NUM), /* bcdCDC: USB class definitions for communications */
0x05, /* bFunctionLength: size of this descriptor in bytes */
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
USBD_CDC_SUBTYPE_CMF, /* bDescriptorSubtype: Call Management function descriptor subtype 0x01 */
0x00, /* bmCapabilities: 0x00*/
0x01, /* bDataInterface: interface number of data class interface optionally used for call management */
0x04, /* bFunctionLength: size of this descriptor in bytes */
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
USBD_CDC_SUBTYPE_ACM, /* bDescriptorSubtype: Abstract Control Management functional descriptor subtype 0x02 */
0x02, /* bmCapabilities: Support Set_Line_Coding and Get_Line_Coding 0x02 */
0x05, /* bFunctionLength: size of this descriptor in bytes */
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
USBD_CDC_SUBTYPE_UFD, /* bDescriptorSubtype: Union Function Descriptor subtype 0x06 */
0x00, /* bControlInterface: The interface number of the communications or data class interface 0x00 */
0x01, /* bSubordinateInterface0: interface number of first subordinate interface in the union */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
LBYTE(USBD_CDC_CMD_MAXPACKET_SIZE),
HBYTE(USBD_CDC_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
CDC_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
VCPMSC_CDC_DATA_INTERFACE, /* bInterfaceNumber: number of interface */
0x00, /* bAlternateSetting: alternate set */
0x02, /* bNumEndpoints: number of endpoints */
USB_CLASS_CODE_CDCDATA, /* bInterfaceClass: CDC-data class code */
0x00, /* bInterfaceSubClass: Data interface subclass code 0x00*/
0x00, /* bInterfaceProtocol: data class protocol code 0x00 */
0x00, /* iInterface: index of string descriptor */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
LBYTE(USBD_CDC_MSC_IN_MAXPACKET_SIZE),
HBYTE(USBD_CDC_MSC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
LBYTE(USBD_CDC_MSC_OUT_MAXPACKET_SIZE),
HBYTE(USBD_CDC_MSC_OUT_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
};
/**
* @brief usb string lang id
*/
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_CDC_SIZ_STRING_LANGID] ALIGNED_TAIL =
{
USBD_CDC_SIZ_STRING_LANGID,
USB_DESCIPTOR_TYPE_STRING,
0x09,
0x04,
};
/**
* @brief usb string serial
*/
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD static uint8_t g_string_serial[USBD_CDC_SIZ_STRING_SERIAL] ALIGNED_TAIL =
{
USBD_CDC_SIZ_STRING_SERIAL,
USB_DESCIPTOR_TYPE_STRING,
};
/* device descriptor */
static usbd_desc_t device_descriptor =
{
USB_DEVICE_DESC_LEN,
g_usbd_descriptor
};
/* config descriptor */
static usbd_desc_t config_descriptor =
{
USBD_CDC_MSC_CONFIG_DESC_SIZE,
g_usbd_configuration
};
/* langid descriptor */
static usbd_desc_t langid_descriptor =
{
USBD_CDC_SIZ_STRING_LANGID,
g_string_lang_id
};
/* serial descriptor */
static usbd_desc_t serial_descriptor =
{
USBD_CDC_SIZ_STRING_SERIAL,
g_string_serial
};
static usbd_desc_t vp_desc;
/**
* @brief standard usb unicode convert
* @param string: source string
* @param unicode_buf: unicode buffer
* @retval length
*/
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
{
uint16_t str_len = 0, id_pos = 2;
uint8_t *tmp_str = string;
while(*tmp_str != '\0')
{
str_len ++;
unicode_buf[id_pos ++] = *tmp_str ++;
unicode_buf[id_pos ++] = 0x00;
}
str_len = str_len * 2 + 2;
unicode_buf[0] = (uint8_t)str_len;
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
return str_len;
}
/**
* @brief usb int convert to unicode
* @param value: int value
* @param pbus: unicode buffer
* @param len: length
* @retval none
*/
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
{
uint8_t idx = 0;
for( idx = 0 ; idx < len ; idx ++)
{
if( ((value >> 28)) < 0xA )
{
pbuf[ 2 * idx] = (value >> 28) + '0';
}
else
{
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
}
value = value << 4;
pbuf[2 * idx + 1] = 0;
}
}
/**
* @brief usb get serial number
* @param none
* @retval none
*/
static void get_serial_num(void)
{
uint32_t serial0, serial1, serial2;
serial0 = *(uint32_t*)MCU_ID1;
serial1 = *(uint32_t*)MCU_ID2;
serial2 = *(uint32_t*)MCU_ID3;
serial0 += serial2;
if (serial0 != 0)
{
usbd_int_to_unicode (serial0, &g_string_serial[2] ,8);
usbd_int_to_unicode (serial1, &g_string_serial[18] ,4);
}
}
/**
* @brief get device descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_descriptor(void)
{
return &device_descriptor;
}
/**
* @brief get device qualifier
* @param none
* @retval usbd_desc
*/
static usbd_desc_t * get_device_qualifier(void)
{
return NULL;
}
/**
* @brief get config descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_configuration(void)
{
return &config_descriptor;
}
/**
* @brief get other speed descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_other_speed(void)
{
return NULL;
}
/**
* @brief get lang id descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_lang_id(void)
{
return &langid_descriptor;
}
/**
* @brief get manufacturer descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_manufacturer_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
/**
* @brief get product descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_product_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
/**
* @brief get serial descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_serial_string(void)
{
get_serial_num();
return &serial_descriptor;
}
/**
* @brief get interface descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_interface_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
/**
* @brief get device config descriptor
* @param none
* @retval usbd_desc
*/
static usbd_desc_t *get_device_config_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/

View File

@@ -0,0 +1,113 @@
/**
**************************************************************************
* @file cdc_msc_desc.h
* @version v2.0.5
* @date 2022-05-20
* @brief usb cdc descriptor header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __CDC_MSC_DESC_H
#define __CDC_MSC_DESC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "cdc_msc_class.h"
#include "usbd_core.h"
/** @addtogroup AT32F413_middlewares_usbd_class
* @{
*/
/** @addtogroup USB_cdc_msc_desc
* @{
*/
/** @defgroup USB_cdc_desc_definition
* @{
*/
/**
* @brief usb bcd number define
*/
#define CDC_BCD_NUM 0x0110
/**
* @brief usb vendor id and product id define
*/
#define USBD_CDC_MSC_VENDOR_ID 0x2E3C
#define USBD_CDC_MSC_PRODUCT_ID 0x5760
/**
* @brief usb descriptor size define
*/
#define USBD_CDC_MSC_CONFIG_DESC_SIZE 106
#define USBD_CDC_SIZ_STRING_LANGID 4
#define USBD_CDC_SIZ_STRING_SERIAL 0x1A
/**
* @brief usb string define(vendor, product configuration, interface)
*/
#define USBD_CDC_DESC_MANUFACTURER_STRING "Artery"
#define USBD_CDC_DESC_PRODUCT_STRING "AT32 Composite VCP and MSC "
#define USBD_CDC_DESC_CONFIGURATION_STRING "Composite VCP and MSC Config"
#define USBD_CDC_DESC_INTERFACE_STRING "Composite VCP and MSC Interface"
/**
* @brief usb endpoint interval define
*/
#define CDC_HID_BINTERVAL_TIME 0xFF
/**
* @brief usb interface define
*/
#define VCPMSC_MSC_INTERFACE 0x00
#define VCPMSC_CDC_INTERFACE 0x01
#define VCPMSC_CDC_DATA_INTERFACE 0x02
/**
* @brief usb mcu id address deine
*/
#define MCU_ID1 (0x1FFFF7E8)
#define MCU_ID2 (0x1FFFF7EC)
#define MCU_ID3 (0x1FFFF7F0)
/**
* @}
*/
extern usbd_desc_handler cdc_msc_desc_handler;
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,823 @@
/**
**************************************************************************
* @file msc_bot_scsi.c
* @version v2.0.5
* @date 2022-05-20
* @brief usb mass storage bulk-only transport and scsi command
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "cdc_msc_class.h"
#include "msc_diskio.h"
/** @addtogroup AT32F413_middlewares_usbd_class
* @{
*/
/** @defgroup USB_msc_bot_scsi
* @brief usb device class mass storage demo
* @{
*/
/** @defgroup USB_msc_bot_functions
* @{
*/
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t page00_inquiry_data[] ALIGNED_TAIL = {
0x00,
0x00,
0x00,
0x00,
0x00,
};
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD sense_type sense_data ALIGNED_TAIL =
{
0x70,
0x00,
SENSE_KEY_ILLEGAL_REQUEST,
0x00000000,
0x0A,
0x00000000,
0x20,
0x00,
0x00000000
};
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
{
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00
};
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
{
0x00,
0x06,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00
};
/**
* @brief initialize bulk-only transport and scsi
* @param udev: to the structure of usbd_core_type
* @retval none
*/
void bot_scsi_init(void *udev)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
pmsc->bot_status = MSC_BOT_STATE_IDLE;
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
pmsc->csw_struct.dCSWDataResidue = 0;
pmsc->csw_struct.dCSWSignature = 0;
pmsc->csw_struct.dCSWTag = CSW_BCSWSTATUS_PASS;
/* set out endpoint to receive status */
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
}
/**
* @brief reset bulk-only transport and scsi
* @param udev: to the structure of usbd_core_type
* @retval none
*/
void bot_scsi_reset(void *udev)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
pmsc->bot_status = MSC_BOT_STATE_RECOVERY;
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
/* set out endpoint to receive status */
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
}
/**
* @brief bulk-only transport data in handler
* @param udev: to the structure of usbd_core_type
* @param ept_num: endpoint number
* @retval none
*/
void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
switch(pmsc->msc_state)
{
case MSC_STATE_MACHINE_DATA_IN:
if(bot_scsi_cmd_process(udev) != USB_OK)
{
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_FAILED);
}
break;
case MSC_STATE_MACHINE_LAST_DATA:
case MSC_STATE_MACHINE_SEND_DATA:
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
break;
default:
break;
}
}
/**
* @brief bulk-only transport data out handler
* @param udev: to the structure of usbd_core_type
* @param ept_num: endpoint number
* @retval none
*/
void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
switch(pmsc->msc_state)
{
case MSC_STATE_MACHINE_IDLE:
bot_cbw_decode(udev);
break;
case MSC_STATE_MACHINE_DATA_OUT:
if(bot_scsi_cmd_process(udev) != USB_OK)
{
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_FAILED);
}
break;
}
}
/**
* @brief bulk-only cbw decode
* @param udev: to the structure of usbd_core_type
* @retval none
*/
void bot_cbw_decode(void *udev)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->csw_struct.dCSWTag = pmsc->cbw_struct.dCBWTage;
pmsc->csw_struct.dCSWDataResidue = pmsc->cbw_struct.dCBWDataTransferLength;
/* check param */
if((pmsc->cbw_struct.dCBWSignature != CBW_DCBWSIGNATURE) ||
(usbd_get_recv_len(pudev, USBD_MSC_BULK_OUT_EPT) != CBW_CMD_LENGTH)
|| (pmsc->cbw_struct.bCBWLUN > MSC_SUPPORT_MAX_LUN) ||
(pmsc->cbw_struct.bCBWCBLength < 1) || (pmsc->cbw_struct.bCBWCBLength > 16))
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
pmsc->bot_status = MSC_BOT_STATE_ERROR;
bot_scsi_stall(udev);
}
else
{
if(bot_scsi_cmd_process(udev) != USB_OK)
{
bot_scsi_stall(udev);
}
else if((pmsc->msc_state != MSC_STATE_MACHINE_DATA_IN) &&
(pmsc->msc_state != MSC_STATE_MACHINE_DATA_OUT) &&
(pmsc->msc_state != MSC_STATE_MACHINE_LAST_DATA))
{
if(pmsc->data_len == 0)
{
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
}
else if(pmsc->data_len > 0)
{
bot_scsi_send_data(udev, pmsc->data, pmsc->data_len);
}
}
}
}
/**
* @brief send bot data
* @param udev: to the structure of usbd_core_type
* @param buffer: data buffer
* @param len: data len
* @retval none
*/
void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint32_t data_len = MIN(len, pmsc->cbw_struct.dCBWDataTransferLength);
pmsc->csw_struct.dCSWDataResidue -= data_len;
pmsc->csw_struct.bCSWStatus = CSW_BCSWSTATUS_PASS;
pmsc->msc_state = MSC_STATE_MACHINE_SEND_DATA;
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
buffer, data_len);
}
/**
* @brief send command status
* @param udev: to the structure of usbd_core_type
* @param status: csw status
* @retval none
*/
void bot_scsi_send_csw(void *udev, uint8_t status)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->csw_struct.bCSWStatus = status;
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
(uint8_t *)&pmsc->csw_struct, CSW_CMD_LENGTH);
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
}
/**
* @brief send scsi sense code
* @param udev: to the structure of usbd_core_type
* @param sense_key: sense key
* @param asc: asc
* @retval none
*/
void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc)
{
sense_data.sense_key = sense_key;
sense_data.asc = asc;
}
/**
* @brief check address
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @param blk_offset: blk offset address
* @param blk_count: blk number
* @retval usb_sts_type
*/
usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset, uint32_t blk_count)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if((blk_offset + blk_count) > pmsc->blk_nbr[lun])
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
return USB_FAIL;
}
return USB_OK;
}
/**
* @brief bot endpoint stall
* @param udev: to the structure of usbd_core_type
* @retval none
*/
void bot_scsi_stall(void *udev)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if((pmsc->cbw_struct.dCBWDataTransferLength != 0) &&
(pmsc->cbw_struct.bmCBWFlags == 0) &&
pmsc->bot_status == MSC_BOT_STATE_IDLE)
{
usbd_set_stall(pudev, USBD_MSC_BULK_OUT_EPT);
}
usbd_set_stall(pudev, USBD_MSC_BULK_IN_EPT);
if(pmsc->bot_status == MSC_BOT_STATE_ERROR)
{
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
}
}
/**
* @brief bulk-only transport scsi command test unit
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if(pmsc->cbw_struct.dCBWDataTransferLength != 0)
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
return USB_FAIL;
}
pmsc->data_len = 0;
return status;
}
/**
* @brief bulk-only transport scsi command inquiry
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
{
uint8_t *pdata;
uint32_t trans_len = 0;
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if(pmsc->cbw_struct.CBWCB[1] & 0x01)
{
pdata = page00_inquiry_data;
trans_len = 5;
}
else
{
pdata = get_inquiry(lun);
if(pmsc->cbw_struct.dCBWDataTransferLength < SCSI_INQUIRY_DATA_LENGTH)
{
trans_len = pmsc->cbw_struct.dCBWDataTransferLength;
}
else
{
trans_len = SCSI_INQUIRY_DATA_LENGTH;
}
}
pmsc->data_len = trans_len;
while(trans_len)
{
trans_len --;
pmsc->data[trans_len] = pdata[trans_len];
}
return status;
}
/**
* @brief bulk-only transport scsi command start stop
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->data_len = 0;
return USB_OK;
}
/**
* @brief bulk-only transport scsi command meidum removal
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->data_len = 0;
return USB_OK;
}
/**
* @brief bulk-only transport scsi command mode sense6
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
{
uint8_t data_len = 8;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->data_len = 8;
while(data_len)
{
data_len --;
pmsc->data[data_len] = mode_sense6_data[data_len];
};
return USB_OK;
}
/**
* @brief bulk-only transport scsi command mode sense10
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
{
uint8_t data_len = 8;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
pmsc->data_len = 8;
while(data_len)
{
data_len --;
pmsc->data[data_len] = mode_sense10_data[data_len];
};
return USB_OK;
}
/**
* @brief bulk-only transport scsi command capacity
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint8_t *pdata = pmsc->data;
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
pdata[0] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
pdata[1] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
pdata[2] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
pdata[3] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
pdata[4] = (uint8_t)((pmsc->blk_size[lun]) >> 24);
pdata[5] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
pdata[6] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
pdata[7] = (uint8_t)((pmsc->blk_size[lun]));
pmsc->data_len = 8;
return USB_OK;
}
/**
* @brief bulk-only transport scsi command format capacity
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint8_t *pdata = pmsc->data;
pdata[0] = 0;
pdata[1] = 0;
pdata[2] = 0;
pdata[3] = 0x08;
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
pdata[4] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
pdata[5] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
pdata[6] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
pdata[7] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
pdata[8] = 0x02;
pdata[9] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
pdata[10] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
pdata[11] = (uint8_t)((pmsc->blk_size[lun]));
pmsc->data_len = 12;
return USB_OK;
}
/**
* @brief bulk-only transport scsi command request sense
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
{
uint32_t trans_len = 0x12;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint8_t *pdata = pmsc->data;
uint8_t *sdata = (uint8_t *)&sense_data;
while(trans_len)
{
trans_len --;
pdata[trans_len] = sdata[trans_len];
}
if(pmsc->cbw_struct.dCBWDataTransferLength < REQ_SENSE_STANDARD_DATA_LEN)
{
pmsc->data_len = pmsc->cbw_struct.dCBWDataTransferLength;
}
else
{
pmsc->data_len = REQ_SENSE_STANDARD_DATA_LEN;
}
return USB_OK;
}
/**
* @brief bulk-only transport scsi command verify
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
if((pmsc->cbw_struct.CBWCB[1] & 0x02) == 0x02)
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
return USB_FAIL;
}
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
pmsc->blk_len = cmd[7] << 8 | cmd[8];
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
{
return USB_FAIL;
}
pmsc->data_len = 0;
return USB_OK;
}
/**
* @brief bulk-only transport scsi command read10
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
uint32_t len;
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
{
if((pmsc->cbw_struct.bmCBWFlags & 0x80) != 0x80)
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
return USB_FAIL;
}
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
pmsc->blk_len = cmd[7] << 8 | cmd[8];
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
{
return USB_FAIL;
}
pmsc->blk_addr *= pmsc->blk_size[lun];
pmsc->blk_len *= pmsc->blk_size[lun];
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
return USB_FAIL;
}
pmsc->msc_state = MSC_STATE_MACHINE_DATA_IN;
}
pmsc->data_len = MSC_MAX_DATA_BUF_LEN;
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
if( msc_disk_read(lun, pmsc->blk_addr, pmsc->data, len) != USB_OK)
{
bot_scsi_sense_code(udev, SENSE_KEY_HARDWARE_ERROR, MEDIUM_NOT_PRESENT);
return USB_FAIL;
}
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT, pmsc->data, len);
pmsc->blk_addr += len;
pmsc->blk_len -= len;
pmsc->csw_struct.dCSWDataResidue -= len;
if(pmsc->blk_len == 0)
{
pmsc->msc_state = MSC_STATE_MACHINE_LAST_DATA;
}
return USB_OK;
}
/**
* @brief bulk-only transport scsi command write10
* @param udev: to the structure of usbd_core_type
* @param lun: logical units number
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
uint32_t len;
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
{
if((pmsc->cbw_struct.bmCBWFlags & 0x80) == 0x80)
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
return USB_FAIL;
}
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
pmsc->blk_len = cmd[7] << 8 | cmd[8];
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
{
return USB_FAIL;
}
pmsc->blk_addr *= pmsc->blk_size[lun];
pmsc->blk_len *= pmsc->blk_size[lun];
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
{
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
return USB_FAIL;
}
pmsc->msc_state = MSC_STATE_MACHINE_DATA_OUT;
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)pmsc->data, len);
}
else
{
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
if(msc_disk_write(lun, pmsc->blk_addr, pmsc->data, len) != USB_OK)
{
bot_scsi_sense_code(udev, SENSE_KEY_HARDWARE_ERROR, MEDIUM_NOT_PRESENT);
return USB_FAIL;
}
pmsc->blk_addr += len;
pmsc->blk_len -= len;
pmsc->csw_struct.dCSWDataResidue -= len;
if(pmsc->blk_len == 0)
{
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
}
else
{
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)pmsc->data, len);
}
}
return USB_OK;
}
/**
* @brief clear feature
* @param udev: to the structure of usbd_core_type
* @param etp_num: endpoint number
* @retval status of usb_sts_type
*/
void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
{
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
if(pmsc->bot_status == MSC_BOT_STATE_ERROR)
{
usbd_set_stall(pudev, USBD_MSC_BULK_IN_EPT);
pmsc->bot_status = MSC_BOT_STATE_IDLE;
}
else if(((ept_num & 0x80) == 0x80) && (pmsc->bot_status != MSC_BOT_STATE_RECOVERY))
{
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_FAILED);
}
}
/**
* @brief bulk-only transport scsi command process
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
usb_sts_type bot_scsi_cmd_process(void *udev)
{
usb_sts_type status = USB_FAIL;
usbd_core_type *pudev = (usbd_core_type *)udev;
cdc_msc_struct_type *pmsc = (cdc_msc_struct_type *)pudev->class_handler->pdata;
switch(pmsc->cbw_struct.CBWCB[0])
{
case MSC_CMD_INQUIRY:
status = bot_scsi_inquiry(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_START_STOP:
status = bot_scsi_start_stop(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_MODE_SENSE6:
status = bot_scsi_mode_sense6(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_MODE_SENSE10:
status = bot_scsi_mode_sense10(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_ALLOW_MEDIUM_REMOVAL:
status = bot_scsi_allow_medium_removal(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_READ_10:
status = bot_scsi_read10(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_READ_CAPACITY:
status = bot_scsi_capacity(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_REQUEST_SENSE:
status = bot_scsi_request_sense(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_TEST_UNIT:
status = bot_scsi_test_unit(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_VERIFY:
status = bot_scsi_verify(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_WRITE_10:
status = bot_scsi_write10(udev, pmsc->cbw_struct.bCBWLUN);
break;
case MSC_CMD_READ_FORMAT_CAPACITY:
status = bot_scsi_format_capacity(udev, pmsc->cbw_struct.bCBWLUN);
break;
default:
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
status = USB_FAIL;
break;
}
return status;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file custom_hid_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb custom hid class type
**************************************************************************
* Copyright notice & Disclaimer
@@ -381,6 +381,7 @@ static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
pcshid->g_txhid_buff[i_index] = report[i_index];
}
usbd_ept_send(pudev, USBD_CUSTOM_HID_IN_EPT, pcshid->g_txhid_buff, len);
break;
default:
break;
}

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file custom_hid_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb custom hid header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file custom_hid_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file custom_hid_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb custom hid descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file hid_iap_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid iap class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file hid_iap_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid iap header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file hid_iap_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file hid_iap_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file keyboard_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid keyboard class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file keyboard_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid keyboard header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file keyboard_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid keyboard device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file keyboard_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb keyboard descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file mouse_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid mouse class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file mouse_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid mouse header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file mouse_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb hid mouse device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file mouse_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb mouse descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file msc_bot_scsi.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb mass storage bulk-only transport and scsi command
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file msc_bot_scsi.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb mass storage bulk-only transport and scsi command header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file msc_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb msc class type
**************************************************************************
* Copyright notice & Disclaimer
@@ -127,7 +127,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
switch(setup->bRequest)
{
case MSC_REQ_GET_MAX_LUN:
usbd_ctrl_send(pudev, (uint8_t *)&msc_struct.max_lun, 1);
usbd_ctrl_send(pudev, (uint8_t *)&pmsc->max_lun, 1);
break;
case MSC_REQ_BO_RESET:
bot_scsi_reset(udev);

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file msc_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb msc class file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file msc_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb msc device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file msc_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb msc descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file printer_class.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb printer class type
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file printer_class.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb printer class file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file printer_desc.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb printer device descriptor
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file printer_desc.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb printer descriptor header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usb_std.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb standard header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usbd_core.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb device core header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usb_int.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usbd_sdr.h
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb standard request header file
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usbd_core.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb driver
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usbd_int.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb interrupt request
**************************************************************************
* Copyright notice & Disclaimer

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file usbd_sdr.c
* @version v2.0.4
* @date 2022-04-02
* @version v2.0.5
* @date 2022-05-20
* @brief usb standard device request
**************************************************************************
* Copyright notice & Disclaimer