// ----------------------------------------------------------------------------- /// @file MAX5715.h /// @brief File 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) 2015 Micro-Key bv // ----------------------------------------------------------------------------- /** * %MAX5715 implementation * \defgroup MAX5715 Package MAX5715 * \ingroup HAL * @{ */ #ifndef INC_MAX5715_H_ #define INC_MAX5715_H_ // ----------------------------------------------------------------------------- // Include files // ----------------------------------------------------------------------------- #include #include "DACDevice.h" #include "IODevice.h" #include "spi.h" // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- #define MAX5715_NUMBER_OF_DACS (4) #define MAX5715_RESOLUTION_IN_BITS (12) #define MAX5715_SPI_MAX_CLK_HZ (50000000) // SPI settings #define MAX5715_SPI_Direction (SPI_Direction_1Line_Tx) #define MAX5715_SPI_Mode (SPI_Mode_Master) #define MAX5715_SPI_DataSize (SPI_DataSize_8b) #define MAX5715_SPI_CPOL (SPI_CPOL_High) #define MAX5715_SPI_CPHA (SPI_CPHA_1Edge) #define MAX5715_SPI_NSS (SPI_NSS_Soft) #define MAX5715_SPI_NSS_INTERNAL (SPI_NSSInternalSoft_Reset) #define MAX5715_SPI_FirstBit (SPI_FirstBit_MSB) #define MAX5715_SPI_CRCPolynomial (7) #define MAX5715_SPI_RX_QUEUE (1) #define MAX5715_SPI_TX_QUEUE (32) #define MAX5715_SEL_DACA (0x1) #define MAX5715_SEL_DACB (0x2) #define MAX5715_SEL_DACC (0x4) #define MAX5715_SEL_DACD (0x8) #define MAX5715_CMD_CODEn (0x00) #define MAX5715_CMD_LOADn (0x10) #define MAX5715_CMD_CODEn_LOAD_ALL (0x20) #define MAX5715_CMD_CODEn_LOADn (0x30) #define MAX5715_CMD_POWER_NORMAL (0x40) #define MAX5715_CMD_POWER_PD1K (0x41) #define MAX5715_CMD_POWER_PD100K (0x42) #define MAX5715_CMD_POWER_HIGHZ (0x43) #define MAX5715_CMD_SW_CLEAR (0x50) #define MAX5715_CMD_SW_RESET (0x51) #define MAX5715_CMD_CONFIG_LATCH_ON (0x60) #define MAX5715_CMD_CONFIG_LATCH_OFF (0x61) #define MAX5715_CMD_REF_DAC_EXT (0x70) #define MAX5715_CMD_REF_DAC_2V5 (0x71) #define MAX5715_CMD_REF_DAC_2V0 (0x72) #define MAX5715_CMD_REF_DAC_4V0 (0x73) #define MAX5715_CMD_REF_ON_EXT (0x74) #define MAX5715_CMD_REF_ON_2V5 (0x75) #define MAX5715_CMD_REF_ON_2V0 (0x76) #define MAX5715_CMD_REF_ON_4V0 (0x77) #define MAX5715_CMD_CODE_ALL (0x80) #define MAX5715_CMD_LOAD_ALL (0x81) #define MAX5715_CMD_CODE_ALL_LOAD_ALL (0x82) #define MAX5715_writeCODEn(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn | (0x0F & (DAC))), DATA)) #define MAX5715_writeLOADn(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_LOADn | (0x0F & (DAC))), 0x0000)) #define MAX5715_writeCODEnLOADALL(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn_LOAD_ALL | (0x0F & (DAC))), DATA)) #define MAX5715_writeCODEnLOADn(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn_LOADn | (0x0F & (DAC))), DATA)) #define MAX5715_writePOWER_NORMAL(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_NORMAL), (0x00FF & ((DAC) << 4)))) #define MAX5715_writePOWER_PD1K(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_PD1K), (0x00FF & ((DAC) << 4)))) #define MAX5715_writePOWER_PD100K(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_PD100K), (0x00FF & ((DAC) << 4)))) #define MAX5715_writePOWER_HIGHZ(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_HIGHZ), (0x00FF & ((DAC) << 4)))) #define MAX5715_writeSW_CLEAR(self) (MAX5715_sendCommand(self, (MAX5715_CMD_SW_CLEAR), 0x0000)) #define MAX5715_writeSW_RESET(self) (MAX5715_sendCommand(self, (MAX5715_CMD_SW_RESET), 0x0000)) #define MAX5715_writeCONFIG_LATCH_ON(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_CONFIG_LATCH_ON), (0x00FF & ((DAC) << 4)))) #define MAX5715_writeCONFIG_LATCH_OFF(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_CONFIG_LATCH_OFF), (0x00FF & ((DAC) << 4)))) #define MAX5715_writeREF_DAC_EXT(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_EXT), 0x0000)) #define MAX5715_writeREF_DAC_2V5(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_2V5), 0x0000)) #define MAX5715_writeREF_DAC_2V0(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_2V0), 0x0000)) #define MAX5715_writeREF_DAC_4V0(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_4V0), 0x0000)) #define MAX5715_writeREF_ON_EXT(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_EXT), 0x0000)) #define MAX5715_writeREF_ON_2V5(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_2V5), 0x0000)) #define MAX5715_writeREF_ON_2V0(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_2V0), 0x0000)) #define MAX5715_writeREF_ON_4V0(self) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_4V0), 0x0000)) #define MAX5715_writeCODE_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODE_ALL), DATA)) #define MAX5715_writeLOAD_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_LOAD_ALL), 0x0000)) #define MAX5715_writeCODE_ALL_LOAD_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODE_ALL_LOAD_ALL), DATA)) // ----------------------------------------------------------------------------- // Type definitions. // ----------------------------------------------------------------------------- struct MAX5715; struct MAX5715_DAC { struct DACDevice dacDevice; struct MAX5715* parent; uint8_t id; uint16_t value; bool initialized; }; struct MAX5715 { const struct IODevice* device; struct MAX5715_DAC dac[MAX5715_NUMBER_OF_DACS]; bool initialized; }; // ----------------------------------------------------------------------------- // Function declarations // ----------------------------------------------------------------------------- /** ---------------------------------------------------------------------------- * MAX5715_construct * Constructs the MAX5715 instance into argument self. * * @param self The MAX5715 object to initialize * @param device The IODevice that should be used for * communication with the MAX5715 * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus MAX5715_construct(struct MAX5715* self, const struct IODevice* device); /** ---------------------------------------------------------------------------- * MAX5715_destruct * Destructs the MAX5715 instance in argument self * * @param self * * @return ErrorStatus SUCCESS if destruction was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern void MAX5715_destruct(struct MAX5715* self); /** ---------------------------------------------------------------------------- * MAX5715_getSpiParameters * Returns a filled-in struct SpiParameters with the MAX5715-specific parameters * * @param parameters SpiParameters struct to fill * * @return ErrorStatus SUCCESS if function was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus MAX5715_getSpiParameters(struct SpiParameters* parameters); /** ---------------------------------------------------------------------------- * MAX5715_sendCommand * Sends a command to MAX5715 instance in argument self with the command in * argument command * * @param self The MAX5715 instance * @param command The command to be sent * * @return ErrorStatus SUCCESS if function was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus MAX5715_sendCommand(const struct MAX5715* self, uint8_t command, uint16_t data); /** ---------------------------------------------------------------------------- * MAX5715Channel_construct * Constructor for one of the channels on the MAX5715 DAC * * @param self The channel object to initialize * @param parent The parent object that the channel belongs * to * @param id The channel number * * @return ErrorStatus SUCCESS if construction was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus MAX5715Channel_construct(struct MAX5715_DAC* self, struct MAX5715* parent, size_t id); /** ---------------------------------------------------------------------------- * MAX5715Channel_setValue * Sends value to the DAC channel in self * * @param self The DAC object * @param value Value to write * * @return ErrorStatus SUCCESS if setting value was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus MAX5715Channel_setValue(struct MAX5715_DAC* self, uint16_t value); #endif /* INC_MAX5715_H_ */ /** @} */