adjust indentation

This commit is contained in:
Emil Lerch 2023-04-29 17:21:21 -07:00
parent 797141a2cd
commit 4d36e6fc07
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 182 additions and 187 deletions

View File

@ -70,100 +70,100 @@
/*!< global descriptor */ /*!< global descriptor */
static const uint8_t cdc_descriptor[] = { static const uint8_t cdc_descriptor[] = {
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01), USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x04, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER), USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x04, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
/* ^ - Number of interfaces. We need a seperate in and out channel for each virtual */ /* ^ - Number of interfaces. We need a seperate in and out channel for each virtual */
/* So for each /dev/ttyACMx, add 2 to this number */ /* So for each /dev/ttyACMx, add 2 to this number */
/* */ /* */
/* The last paramater is the string index for this interface. Linux does not */ /* The last paramater is the string index for this interface. Linux does not */
/* seem to report that anywhere, but maybe Windows does? */ /* seem to report that anywhere, but maybe Windows does? */
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, 0x02), CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, 0x02),
CDC_ACM_DESCRIPTOR_INIT(0x02, CDC_INT_DBG_EP, CDC_OUT_DBG_EP, CDC_IN_DBG_EP, 0x02), CDC_ACM_DESCRIPTOR_INIT(0x02, CDC_INT_DBG_EP, CDC_OUT_DBG_EP, CDC_IN_DBG_EP, 0x02),
/////////////////////////////////////// ///////////////////////////////////////
/// string0 descriptor /// string0 descriptor
/////////////////////////////////////// ///////////////////////////////////////
USB_LANGID_INIT(USBD_LANGID_STRING), USB_LANGID_INIT(USBD_LANGID_STRING),
/////////////////////////////////////// ///////////////////////////////////////
/// string1 descriptor /// string1 descriptor
/////////////////////////////////////// ///////////////////////////////////////
0x16, /* bLength */ 0x16, /* bLength */
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
'E', 0x00, /* wcChar0 */ 'E', 0x00, /* wcChar0 */
'm', 0x00, /* wcChar1 */ 'm', 0x00, /* wcChar1 */
'i', 0x00, /* wcChar2 */ 'i', 0x00, /* wcChar2 */
'l', 0x00, /* wcChar3 */ 'l', 0x00, /* wcChar3 */
' ', 0x00, /* wcChar4 */ ' ', 0x00, /* wcChar4 */
'L', 0x00, /* wcChar5 */ 'L', 0x00, /* wcChar5 */
'e', 0x00, /* wcChar6 */ 'e', 0x00, /* wcChar6 */
'r', 0x00, /* wcChar7 */ 'r', 0x00, /* wcChar7 */
'c', 0x00, /* wcChar8 */ 'c', 0x00, /* wcChar8 */
'h', 0x00, /* wcChar9 */ 'h', 0x00, /* wcChar9 */
/////////////////////////////////////// ///////////////////////////////////////
/// string2 descriptor /// string2 descriptor
/////////////////////////////////////// ///////////////////////////////////////
0x22, /* bLength */ 0x22, /* bLength */
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
'B', 0x00, /* wcChar0 */ 'B', 0x00, /* wcChar0 */
'L', 0x00, /* wcChar1 */ 'L', 0x00, /* wcChar1 */
'6', 0x00, /* wcChar2 */ '6', 0x00, /* wcChar2 */
'1', 0x00, /* wcChar3 */ '1', 0x00, /* wcChar3 */
'6', 0x00, /* wcChar4 */ '6', 0x00, /* wcChar4 */
' ', 0x00, /* wcChar5 */ ' ', 0x00, /* wcChar5 */
'B', 0x00, /* wcChar6 */ 'B', 0x00, /* wcChar6 */
'a', 0x00, /* wcChar7 */ 'a', 0x00, /* wcChar7 */
'r', 0x00, /* wcChar8 */ 'r', 0x00, /* wcChar8 */
'e', 0x00, /* wcChar9 */ 'e', 0x00, /* wcChar9 */
' ', 0x00, /* wcChar10 */ ' ', 0x00, /* wcChar10 */
'M', 0x00, /* wcChar11 */ 'M', 0x00, /* wcChar11 */
'e', 0x00, /* wcChar12 */ 'e', 0x00, /* wcChar12 */
't', 0x00, /* wcChar13 */ 't', 0x00, /* wcChar13 */
'a', 0x00, /* wcChar14 */ 'a', 0x00, /* wcChar14 */
'l', 0x00, /* wcChar15 */ 'l', 0x00, /* wcChar15 */
/////////////////////////////////////// ///////////////////////////////////////
/// string3 descriptor /// string3 descriptor
/////////////////////////////////////// ///////////////////////////////////////
0x16, /* bLength */ 0x16, /* bLength */
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
'2', 0x00, /* wcChar0 */ '2', 0x00, /* wcChar0 */
'0', 0x00, /* wcChar1 */ '0', 0x00, /* wcChar1 */
'2', 0x00, /* wcChar2 */ '2', 0x00, /* wcChar2 */
'3', 0x00, /* wcChar3 */ '3', 0x00, /* wcChar3 */
'-', 0x00, /* wcChar4 */ '-', 0x00, /* wcChar4 */
'0', 0x00, /* wcChar5 */ '0', 0x00, /* wcChar5 */
'4', 0x00, /* wcChar6 */ '4', 0x00, /* wcChar6 */
'-', 0x00, /* wcChar7 */ '-', 0x00, /* wcChar7 */
'1', 0x00, /* wcChar8 */ '1', 0x00, /* wcChar8 */
'9', 0x00, /* wcChar9 */ '9', 0x00, /* wcChar9 */
/////////////////////////////////////// ///////////////////////////////////////
/// string4 descriptor /// string4 descriptor
/////////////////////////////////////// ///////////////////////////////////////
0x14, /* bLength */ 0x14, /* bLength */
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
'D', 0x00, /* wcChar0 */ 'D', 0x00, /* wcChar0 */
'E', 0x00, /* wcChar1 */ 'E', 0x00, /* wcChar1 */
'B', 0x00, /* wcChar2 */ 'B', 0x00, /* wcChar2 */
'U', 0x00, /* wcChar3 */ 'U', 0x00, /* wcChar3 */
'G', 0x00, /* wcChar4 */ 'G', 0x00, /* wcChar4 */
' ', 0x00, /* wcChar5 */ ' ', 0x00, /* wcChar5 */
'L', 0x00, /* wcChar6 */ 'L', 0x00, /* wcChar6 */
'O', 0x00, /* wcChar7 */ 'O', 0x00, /* wcChar7 */
'G', 0x00, /* wcChar8 */ 'G', 0x00, /* wcChar8 */
#ifdef CONFIG_USB_HS #ifdef CONFIG_USB_HS
/////////////////////////////////////// ///////////////////////////////////////
/// device qualifier descriptor /// device qualifier descriptor
/////////////////////////////////////// ///////////////////////////////////////
0x0a, 0x0a,
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER, USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
0x00, 0x00,
0x02, 0x02,
0x02, 0x02,
0x02, 0x02,
0x01, 0x01,
0x40, 0x40,
0x01, 0x01,
0x00, 0x00,
#endif #endif
0x00 0x00
}; };
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048]; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048];
@ -187,61 +187,59 @@ volatile uint32_t debug_val32_2 = 0;
void usbd_configure_done_callback(void) void usbd_configure_done_callback(void)
{ {
/* setup first out ep read transfer */ /* setup first out ep read transfer */
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048); usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
usbd_ep_start_read(CDC_OUT_DBG_EP, read_buffer, 2048); usbd_ep_start_read(CDC_OUT_DBG_EP, read_buffer, 2048);
} }
void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes) void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes)
{ {
//4, 5 (shouldn't we be getting endpoint 2 here?) debug_val_1 = ep; debug_val32_1 = nbytes;
debug_val_1 = ep; debug_val32_1 = nbytes; USB_LOG_RAW("actual out len:%d\r\n", nbytes);
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
/* setup next out ep read transfer */ /* setup next out ep read transfer */
usbd_ep_start_read(ep, read_buffer, 2048); usbd_ep_start_read(ep, read_buffer, 2048);
} }
void usbd_cdc_acm_bulk_in(uint8_t ep, uint32_t nbytes) void usbd_cdc_acm_bulk_in(uint8_t ep, uint32_t nbytes)
{ {
//129, 14 (129=0x81=CDC_IN_EP) debug_val_2 = ep; debug_val32_2 = nbytes;
debug_val_2 = ep; debug_val32_2 = nbytes; USB_LOG_RAW("actual in len:%d\r\n", nbytes);
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) { if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
/* send zlp */ /* send zlp */
usbd_ep_start_write(ep, NULL, 0); usbd_ep_start_write(ep, NULL, 0);
} else { } else {
if (ep == CDC_IN_EP) { if (ep == CDC_IN_EP) {
ep_tx_busy_flag = false; ep_tx_busy_flag = false;
}else{ }else{
ep_dbg_tx_busy_flag = false; ep_dbg_tx_busy_flag = false;
}
} }
}
} }
/*!< endpoint call back */ /*!< endpoint call back */
struct usbd_endpoint cdc_out_ep = { struct usbd_endpoint cdc_out_ep = {
.ep_addr = CDC_OUT_EP, .ep_addr = CDC_OUT_EP,
.ep_cb = usbd_cdc_acm_bulk_out .ep_cb = usbd_cdc_acm_bulk_out
}; };
struct usbd_endpoint cdc_in_ep = { struct usbd_endpoint cdc_in_ep = {
.ep_addr = CDC_IN_EP, .ep_addr = CDC_IN_EP,
.ep_cb = usbd_cdc_acm_bulk_in .ep_cb = usbd_cdc_acm_bulk_in
}; };
struct usbd_interface intf0; struct usbd_interface intf0;
struct usbd_interface intf1; struct usbd_interface intf1;
struct usbd_endpoint cdc_out_dbg_ep = { struct usbd_endpoint cdc_out_dbg_ep = {
.ep_addr = CDC_OUT_DBG_EP, .ep_addr = CDC_OUT_DBG_EP,
.ep_cb = usbd_cdc_acm_bulk_out .ep_cb = usbd_cdc_acm_bulk_out
}; };
struct usbd_endpoint cdc_in_dbg_ep = { struct usbd_endpoint cdc_in_dbg_ep = {
.ep_addr = CDC_IN_DBG_EP, .ep_addr = CDC_IN_DBG_EP,
.ep_cb = usbd_cdc_acm_bulk_in .ep_cb = usbd_cdc_acm_bulk_in
}; };
struct usbd_interface intf2; struct usbd_interface intf2;
@ -250,22 +248,22 @@ struct usbd_interface intf3;
/* function ------------------------------------------------------------------*/ /* function ------------------------------------------------------------------*/
void cdc_acm_init(void) void cdc_acm_init(void)
{ {
usbd_desc_register(cdc_descriptor); usbd_desc_register(cdc_descriptor);
/* Add primary comms channel */ /* Add primary comms channel */
usbd_add_interface(usbd_cdc_acm_init_intf(&intf0)); usbd_add_interface(usbd_cdc_acm_init_intf(&intf0));
usbd_add_interface(usbd_cdc_acm_init_intf(&intf1)); usbd_add_interface(usbd_cdc_acm_init_intf(&intf1));
usbd_add_endpoint(&cdc_out_ep); usbd_add_endpoint(&cdc_out_ep);
usbd_add_endpoint(&cdc_in_ep); usbd_add_endpoint(&cdc_in_ep);
/* Add debug log comms channel */ /* Add debug log comms channel */
usbd_add_interface(usbd_cdc_acm_init_intf(&intf2)); usbd_add_interface(usbd_cdc_acm_init_intf(&intf2));
usbd_add_interface(usbd_cdc_acm_init_intf(&intf3)); usbd_add_interface(usbd_cdc_acm_init_intf(&intf3));
usbd_add_endpoint(&cdc_out_dbg_ep); usbd_add_endpoint(&cdc_out_dbg_ep);
usbd_add_endpoint(&cdc_in_dbg_ep); usbd_add_endpoint(&cdc_in_dbg_ep);
usbd_initialize(); usbd_initialize();
} }
volatile uint8_t dtr_enable = 0; volatile uint8_t dtr_enable = 0;
@ -277,30 +275,30 @@ volatile uint8_t dtr_debug_enable = 0;
*/ */
void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr) void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr)
{ {
/* Based on above init, intf = 0 is normal, intf = 2 is debug */ /* Based on above init, intf = 0 is normal, intf = 2 is debug */
if (dtr) { if (dtr) {
if (intf == 0) { if (intf == 0) {
dtr_enable = 1; dtr_enable = 1;
} else {
dtr_debug_enable = 1;
}
} else { } else {
if (intf == 0) { dtr_debug_enable = 1;
dtr_enable = 0;
} else {
dtr_debug_enable = 0;
}
} }
} else {
if (intf == 0) {
dtr_enable = 0;
} else {
dtr_debug_enable = 0;
}
}
} }
void cdc_acm_data_send_with_dtr(const uint8_t *data, uint32_t data_len ) void cdc_acm_data_send_with_dtr(const uint8_t *data, uint32_t data_len )
{ {
if (dtr_enable) { if (dtr_enable) {
ep_tx_busy_flag = true; ep_tx_busy_flag = true;
usbd_ep_start_write(CDC_IN_EP, data, data_len); usbd_ep_start_write(CDC_IN_EP, data, data_len);
while (ep_tx_busy_flag) { while (ep_tx_busy_flag) {
}
} }
}
} }
void cdc_acm_log_with_dtr(const uint8_t *data, uint32_t data_len ) void cdc_acm_log_with_dtr(const uint8_t *data, uint32_t data_len )
@ -315,31 +313,28 @@ void cdc_acm_log_with_dtr(const uint8_t *data, uint32_t data_len )
uint32_t out_inx = 0; uint32_t out_inx = 0;
void log(const char *data){ void log(const char *data){
/* memcpy(&write_buffer[0], data, strlen(data)); */ int len = snprintf(
/* write_buffer[9] = 0x30 + debug_val_1; */ (char *)&write_buffer[0],
/* write_buffer[20] = 0x30 + debug_val_2; */ 2048,
int len = snprintf( "%d\r\ndebug u8 val 1: %d, debug val u8 2: %d\r\ndebug 32 val 1: %d, debug 32 val 2: %d\r\nsending to debug...\r\n",
(char *)&write_buffer[0], out_inx++,
2048, debug_val_1,
"%d\r\ndebug u8 val 1: %d, debug val u8 2: %d\r\ndebug 32 val 1: %d, debug 32 val 2: %d\r\nsending to debug...\r\n", debug_val_2,
out_inx++, debug_val32_1,
debug_val_1, debug_val32_2
debug_val_2, );
debug_val32_1, cdc_acm_data_send_with_dtr(&write_buffer[0], len);
debug_val32_2
);
cdc_acm_data_send_with_dtr(&write_buffer[0], len);
int dbg_len = snprintf( int dbg_len = snprintf(
(char *)&debug_buffer[0], (char *)&debug_buffer[0],
2048, 2048,
"%d\r\ndebug u8 val 1: %d, debug val u8 2: %d\r\ndebug 32 val 1: %d, debug 32 val 2: %d\r\n(debug log)\r\n", "%d\r\ndebug u8 val 1: %d, debug val u8 2: %d\r\ndebug 32 val 1: %d, debug 32 val 2: %d\r\n(debug log)\r\n",
out_inx, out_inx,
debug_val_1, debug_val_1,
debug_val_2, debug_val_2,
debug_val32_1, debug_val32_1,
debug_val32_2 debug_val32_2
); );
cdc_acm_log_with_dtr(&debug_buffer[0], dbg_len); cdc_acm_log_with_dtr(&debug_buffer[0], dbg_len);
} }

26
main.c
View File

@ -15,21 +15,21 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer_main[2048];
int main(void) int main(void)
{ {
board_init(); board_init();
uint32_t data_len = buffer_init("Hello world!\r\n"); uint32_t data_len = buffer_init("Hello world!\r\n");
uint32_t inx = 0; uint32_t inx = 0;
cdc_acm_init(); cdc_acm_init();
log("Initialized"); log("Initialized");
while (1) { while (1) {
if (inx++ >= 2000){ if (inx++ >= 2000){
cdc_acm_data_send_with_dtr(write_buffer_main, data_len); cdc_acm_data_send_with_dtr(write_buffer_main, data_len);
log("dtr_enabled_true_callbacks: . Write\r\n"); log("dtr_enabled_true_callbacks: . Write\r\n");
/* cdc_acm_log_with_dtr(write_buffer_main, data_len); */ /* cdc_acm_log_with_dtr(write_buffer_main, data_len); */
inx = 0; inx = 0;
}
bflb_mtimer_delay_ms(1);
} }
bflb_mtimer_delay_ms(1);
}
} }
uint32_t buffer_init(char *data) { uint32_t buffer_init(char *data) {