// ----------------------------------------------------------------------------- /// @file DAConverter.c /// @brief Description // ----------------------------------------------------------------------------- // Micro-Key bv // Industrieweg 28, 9804 TG Noordhorn // Postbus 92, 9800 AB Zuidhorn // The Netherlands // Tel: +31 594 503020 // Fax: +31 594 505825 // Email: support@microkey.nl // Web: www.microkey.nl // ----------------------------------------------------------------------------- /// $Revision$ /// $Author$ /// $Date$ // (c) 2017 Micro-Key bv // ----------------------------------------------------------------------------- /// @file DAConverter.c /// @ingroup {group_name} // ----------------------------------------------------------------------------- // Include files // ----------------------------------------------------------------------------- #include "DAConverter.h" #include "Voltage.h" #include "Logger.h" // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // Type definitions // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // File-scope variables // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // Function declarations // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // Function definitions // ----------------------------------------------------------------------------- ErrorStatus DAConverter_construct(struct DAConverter* self, int minVoltage, int maxVoltage, struct DACDevice* dacDevice) { ErrorStatus returnValue = SUCCESS; if (!self->initialized) { self->minVoltage = minVoltage; self->maxVoltage = maxVoltage; self->dacDevice = dacDevice; self->initialized = true; } else { returnValue = ERROR; } return returnValue; } void DAConverter_destruct(struct DAConverter* self) { self->initialized = false; } ErrorStatus DAConverter_setOutputVoltage(const struct DAConverter* self, int voltage) { ErrorStatus returnValue = SUCCESS; if (returnValue == SUCCESS) { if (self->initialized) { uint32_t dacValue; dacValue = Voltage_calculateDeviceValue(voltage, self->dacDevice->resolutionInBits, self->minVoltage, self->maxVoltage); DACDevice_write(self->dacDevice, dacValue); } } else { returnValue = ERROR; } return returnValue; } uint32_t DAConverter_getCurrentValue(const struct DAConverter* self) { uint32_t returnValue = 0; if (self->initialized) { returnValue = Voltage_calculateVoltage(DACDevice_getCurrentValue(self->dacDevice), self->dacDevice->resolutionInBits, self->minVoltage, self->maxVoltage); } return returnValue; }