KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ltc2631.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : ltc2631.c
11  * Created : 21 jan. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 
16 #include "drv/i2c/ltc2631.h"
17 #include "errorcode.h"
18 
19 #define _LTC2631_OPER_WRITE 0x00
20 #define _LTC2631_OPER_UPDATE 0x10
21 #define _LTC2631_OPER_WRITE_UPDATE 0x30
22 #define _LTC2631_OPER_POWER_DOWN 0x40
23 #define _LTC2631_OPER_REF_INTERNAL 0x60
24 #define _LTC2631_OPER_REF_EXTERNAL 0x70
25 
26 bool ltc2631Write(I2C_Device * dev, uint8_t addr, uint16_t value, bool update)
27 {
28  uint8_t out[3];
29 
30  out[0] = update ? _LTC2631_OPER_WRITE_UPDATE : _LTC2631_OPER_WRITE;
31  out[1] = 0xff & (value >> 8);
32  out[2] = 0xff & value;
33 
34  return i2cWrite(dev, addr, out, sizeof(out));
35 }
36 
37 bool ltc2631Operation(I2C_Device * dev, uint8_t addr, LTC2631Oper oper)
38 {
39  uint8_t out[3];
40  out[1] = out[2] = 0;
41 
42  switch (oper)
43  {
44  case ltc2631OperPowerDown: out[0] = _LTC2631_OPER_POWER_DOWN; break;
45  case ltc2631OperUpdate: out[0] = _LTC2631_OPER_UPDATE; break;
46  case ltc2631OperSelExtRef: out[0] = _LTC2631_OPER_REF_EXTERNAL; break;
47  case ltc2631OperSelIntRef: out[0] = _LTC2631_OPER_REF_INTERNAL; break;
48  default:
49  return errSet(ERROR(E_INVARGUMENT));
50  }
51 
52  return i2cWrite(dev, addr, out, sizeof(out));
53 }
54 
bool i2cWrite(I2C_Device *dev, i2cAddr addr, uint8_t *bytes, int len)
Writes to the I2C device.
Definition: i2c.c:219
bool ltc2631Write(I2C_Device *dev, uint8_t addr, uint16_t value, bool update)
Sets the DAC value on the input register.
Definition: ltc2631.c:26
Driver of the LTC2631 DAC as found on the power board.
Select external reference.
Definition: ltc2631.h:35
bool ltc2631Operation(I2C_Device *dev, uint8_t addr, LTC2631Oper oper)
Executes a DAC operation.
Definition: ltc2631.c:37
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
Power down the LTC2631.
Definition: ltc2631.h:33
#define E_INVARGUMENT
Generic error: invalid argument.
Definition: errorcode.h:112
LTC2631Oper
Definition: ltc2631.h:31
This module is responsible for distributing error codes.
Select internal reference.
Definition: ltc2631.h:34
Adjust output voltage with value in input buffer.
Definition: ltc2631.h:32
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).