/* * data_buffer.c * * Created on: 20-Jun-2023 * Author: vivek */ #include #include #include "descriptor_fifo.h" int descriptor_fifo_write(uint32_t descriptor_data_size, uint32_t* descrtiptor_data) { if(descriptor_data_size == 0x00) { return -2; } for(uint32_t i=0;i<(descriptor_data_size);i++) { if(ltcusb_fifo_write(DESC_FIFO_ADDR_RV, descrtiptor_data[i]) != 0) { return -1; } } return 0; } static int ascii2unicode(uint8_t* ascii_str, uint32_t ascii_str_len, uint8_t* unicode_str, uint32_t* unicode_str_len) { *unicode_str_len = (ascii_str_len << 1); for(uint32_t i=0;i<*unicode_str_len;i++) { unicode_str[i] = (i&0x1)?0:(uint8_t)ascii_str[i/2]; } return 0; } int create_string_descriptor(uint8_t* str, uint32_t str_len, uint32_t* str_desc, uint32_t* str_desc_len) { const uint32_t unicode_max_len = 252; uint8_t unicode_str[unicode_max_len]; memset(unicode_str,0x00,unicode_max_len); if(str_len > unicode_max_len/2) { return -1; } ascii2unicode(str, str_len, unicode_str, str_desc_len); *str_desc_len += 2; /**@todo descriptor type with enum or macro.*/ *str_desc = (uint32_t)*str_desc_len | (uint32_t)(0x03 << 8); memcpy((uint8_t*)str_desc+2, unicode_str, *str_desc_len-2); if(*str_desc_len%4) { *str_desc_len = (*str_desc_len >> 2); ++*str_desc_len; } else { *str_desc_len = (*str_desc_len >> 2); } return 0; }