Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Babyseat_NewFirmware_copy_sean by
Diff: src/adi_sense_1000.c
- Revision:
- 17:fd5ab3d27b15
- Parent:
- 16:e4f2689363bb
diff -r e4f2689363bb -r fd5ab3d27b15 src/adi_sense_1000.c --- a/src/adi_sense_1000.c Tue Dec 05 19:08:53 2017 +0000 +++ b/src/adi_sense_1000.c Fri Dec 15 22:41:44 2017 +0000 @@ -726,6 +726,7 @@ adi_sense_GpioClose(pCtx->hGpio); adi_sense_SpiClose(pCtx->hSpi); + adi_sense_LogClose(); return ADI_SENSE_SUCCESS; } @@ -1750,6 +1751,65 @@ return ADI_SENSE_SUCCESS; } +static ADI_SENSE_RESULT adi_sense_SetDigitalSensorFormat( + ADI_SENSE_DEVICE_HANDLE hDevice, + ADI_SENSE_1000_CHANNEL_ID eChannelId, + ADI_SENSE_1000_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat) +{ + ADI_ADISENSE_CORE_Digital_Sensor_Config_t sensorConfigReg; + + sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn); + + if (pDataFormat->coding != ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_NONE) + { + if (pDataFormat->frameLength == 0) + { + ADI_SENSE_LOG_ERROR("Invalid frame length specified for digital sensor data format"); + return ADI_SENSE_INVALID_PARAM; + } + if (pDataFormat->numDataBits == 0) + { + ADI_SENSE_LOG_ERROR("Invalid frame length specified for digital sensor data format"); + return ADI_SENSE_INVALID_PARAM; + } + + CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_READ_BYTES, + pDataFormat->frameLength - 1); + CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_DATA_BITS, + pDataFormat->numDataBits - 1); + CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_BIT_OFFSET, + pDataFormat->bitOffset); + + sensorConfigReg.Digital_Sensor_Read_Bytes = pDataFormat->frameLength - 1; + sensorConfigReg.Digital_Sensor_Data_Bits = pDataFormat->numDataBits - 1; + sensorConfigReg.Digital_Sensor_Bit_Offset = pDataFormat->bitOffset; + sensorConfigReg.Digital_Sensor_LeftAligned = pDataFormat->leftJustified ? 1 : 0; + sensorConfigReg.Digital_Sensor_LittleEndian = pDataFormat->littleEndian ? 1 : 0; + + switch (pDataFormat->coding) + { + case ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_UNIPOLAR: + sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_UNIPOLAR; + break; + case ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_TWOS_COMPLEMENT: + sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_TWOS_COMPL; + break; + case ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_OFFSET_BINARY: + sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_OFFSET_BINARY; + break; + default: + ADI_SENSE_LOG_ERROR("Invalid coding specified for digital sensor data format"); + return ADI_SENSE_INVALID_PARAM; + } + } + + WRITE_REG_U16(hDevice, sensorConfigReg.VALUE16, + CORE_DIGITAL_SENSOR_CONFIGn(eChannelId)); + + + return ADI_SENSE_SUCCESS; +} + static ADI_SENSE_RESULT adi_sense_SetChannelI2cSensorType( ADI_SENSE_DEVICE_HANDLE hDevice, ADI_SENSE_1000_CHANNEL_ID eChannelId, @@ -1769,7 +1829,6 @@ sensorTypeReg.Sensor_Type = ADISENSE_CORE_SENSOR_TYPE_SENSOR_I2C_HUMIDITY_SENSIRION_SHT3X; break; default: - /* TODO - add support for custom I2C sensors */ ADI_SENSE_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); return ADI_SENSE_INVALID_PARAM; } @@ -1825,6 +1884,15 @@ return eRet; } + eRet = adi_sense_SetDigitalSensorFormat(hDevice, eChannelId, + &pI2cChannelConfig->dataFormat); + if (eRet != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to set I2C sensor data format for channel %d", + eChannelId); + return eRet; + } + return ADI_SENSE_SUCCESS; } @@ -1847,7 +1915,6 @@ sensorTypeReg.Sensor_Type = ADISENSE_CORE_SENSOR_TYPE_SENSOR_SPI_ACCELEROMETER_1; break; default: - /* TODO - add support for custom SPI sensors */ ADI_SENSE_LOG_ERROR("Unsupported SPI sensor type %d specified", sensorType); return ADI_SENSE_INVALID_PARAM; } @@ -1883,6 +1950,15 @@ return eRet; } + eRet = adi_sense_SetDigitalSensorFormat(hDevice, eChannelId, + &pSpiChannelConfig->dataFormat); + if (eRet != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to set SPI sensor data format for channel %d", + eChannelId); + return eRet; + } + return ADI_SENSE_SUCCESS; }