Vybhav Kadaba
/
EV-PRO-MW1001_Development_code_cleanup2
Code clean up, removed unwanted enums and configurations
Diff: src/admw_1001.c
- Revision:
- 54:31921ad29828
- Parent:
- 53:644c5f6300da
- Child:
- 55:215da406282b
--- a/src/admw_1001.c Wed Feb 19 09:09:59 2020 +0000 +++ b/src/admw_1001.c Wed Feb 19 10:08:13 2020 +0000 @@ -2341,95 +2341,7 @@ return ADMW_SUCCESS; } -ADMW_RESULT admw1001_SetLutData( - ADMW_DEVICE_HANDLE const hDevice, - ADMW1001_LUT * const pLutData) -{ - ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; - ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; - unsigned actualLength = 0; - - if (pLutData->header.signature != ADMW_LUT_SIGNATURE) { - ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", - ADMW_LUT_SIGNATURE, pLutHeader->signature); - return ADMW_INVALID_SIGNATURE; - } - if ((pLutData->tables->descriptor.geometry!= ADMW1001_LUT_GEOMETRY_NES_1D) && - (pLutData->tables->data.lut1dNes.nElements > MAX_LUT_NUM_ENTRIES)) { - return ADMW_INVALID_PARAM; - } - for (unsigned i = 0; i < pLutHeader->numTables; i++) { - ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; - ADMW1001_LUT_TABLE_DATA *pData = &pLutTable->data; - unsigned short calculatedCrc; - - switch (pDesc->geometry) { - case ADMW1001_LUT_GEOMETRY_COEFFS: - switch (pDesc->equation) { - case ADMW1001_LUT_EQUATION_POLYN: - case ADMW1001_LUT_EQUATION_POLYNEXP: - case ADMW1001_LUT_EQUATION_QUADRATIC: - case ADMW1001_LUT_EQUATION_STEINHART: - case ADMW1001_LUT_EQUATION_LOGARITHMIC: - case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: - break; - default: - ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", - pDesc->equation, i); - return ADMW_INVALID_PARAM; - } - break; - case ADMW1001_LUT_GEOMETRY_NES_1D: - break; - default: - ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", - pDesc->geometry, i); - return ADMW_INVALID_PARAM; - } - - switch (pDesc->dataType) { - case ADMW1001_LUT_DATA_TYPE_FLOAT32: - case ADMW1001_LUT_DATA_TYPE_FLOAT64: - break; - default: - ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", - pDesc->dataType, i); - return ADMW_INVALID_PARAM; - } - - calculatedCrc = admw_crc16_ccitt(pData, pDesc->length); - if (calculatedCrc != pDesc->crc16) { - ADMW_LOG_ERROR("CRC validation failed on LUT table %u (expected 0x%04X, actual 0x%04X)", - i, pDesc->crc16, calculatedCrc); - return ADMW_CRC_ERROR; - } - - actualLength += sizeof(*pDesc) + pDesc->length; - - /* Move to the next look-up table */ - pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); - } - - if (actualLength != pLutHeader->totalLength) { - ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", - pLutHeader->totalLength, actualLength); - return ADMW_WRONG_SIZE; - } - - if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) { - ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", - ADMW_LUT_MAX_SIZE); - return ADMW_WRONG_SIZE; - } - - /* Write the LUT data to the device */ - unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength; - WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET); - WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA); - - return ADMW_SUCCESS; -} ADMW_RESULT admw1001_SetLutDataRaw( ADMW_DEVICE_HANDLE const hDevice, ADMW1001_LUT_RAW * const pLutData) @@ -2517,3 +2429,102 @@ return ADMW_SUCCESS; } +ADMW_RESULT admw1001_SetLutData( + ADMW_DEVICE_HANDLE const hDevice, + ADMW1001_LUT * const pLutData) +{ + ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; + ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; + + unsigned actualLength = 0; + + if (pLutData->header.signature != ADMW_LUT_SIGNATURE) + { + ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", + ADMW_LUT_SIGNATURE, pLutHeader->signature); + return ADMW_INVALID_SIGNATURE; + } + if ((pLutData->tables->descriptor.geometry!= ADMW1001_LUT_GEOMETRY_NES_1D) && + (pLutData->tables->data.lut1dNes.nElements > MAX_LUT_NUM_ENTRIES)) + { + return ADMW_INVALID_PARAM; + } + + for (unsigned i = 0; i < pLutHeader->numTables; i++) + { + ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; + ADMW1001_LUT_TABLE_DATA *pData = &pLutTable->data; + unsigned short calculatedCrc; + + switch (pDesc->geometry) + { + case ADMW1001_LUT_GEOMETRY_COEFFS: + switch (pDesc->equation) + { + case ADMW1001_LUT_EQUATION_POLYN: + case ADMW1001_LUT_EQUATION_POLYNEXP: + case ADMW1001_LUT_EQUATION_QUADRATIC: + case ADMW1001_LUT_EQUATION_STEINHART: + case ADMW1001_LUT_EQUATION_LOGARITHMIC: + case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: + break; + default: + ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", + pDesc->equation, i); + return ADMW_INVALID_PARAM; + } + break; + case ADMW1001_LUT_GEOMETRY_NES_1D: + break; + default: + ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", + pDesc->geometry, i); + return ADMW_INVALID_PARAM; + } + + switch (pDesc->dataType) + { + case ADMW1001_LUT_DATA_TYPE_FLOAT32: + case ADMW1001_LUT_DATA_TYPE_FLOAT64: + break; + default: + ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", + pDesc->dataType, i); + return ADMW_INVALID_PARAM; + } + + calculatedCrc = admw_crc16_ccitt(pData, pDesc->length); + if (calculatedCrc != pDesc->crc16) + { + ADMW_LOG_ERROR("CRC validation failed on LUT table %u (expected 0x%04X, actual 0x%04X)", + i, pDesc->crc16, calculatedCrc); + return ADMW_CRC_ERROR; + } + + actualLength += sizeof(*pDesc) + pDesc->length; + + /* Move to the next look-up table */ + pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); + } + + if (actualLength != pLutHeader->totalLength) + { + ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", + pLutHeader->totalLength, actualLength); + return ADMW_WRONG_SIZE; + } + + if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) + { + ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", + ADMW_LUT_MAX_SIZE); + return ADMW_WRONG_SIZE; + } + + /* Write the LUT data to the device */ + unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength; + WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET); + WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA); + + return ADMW_SUCCESS; +} \ No newline at end of file