ARMEBS4  revision-26.06.2015
stm32_mcp4552.c
Go to the documentation of this file.
1 /**
2  * \file heivs/stm32_mcp4552.c
3  *
4  * \author marc dot pignat at hevs dot ch
5  */
6 
7 #include "heivs/stm32_mcp4552.h"
8 
9 status_e mcp4552_set(const struct mcp4552_t *dev, uint32_t value)
10 {
11  status_e status;
12 
13  const uint8_t cmd[] =
14  {
15  /* The write command */
16  0x00 | ((value >> 8) & 0x3),
17  value & 0xff,
18  };
19 
20  status = bus_init(dev->bus);
21  if (status != NO_ERROR)
22  {
23  return status;
24  }
25 
26  status = bus_get(dev->bus);
27  if (status != NO_ERROR)
28  {
29  return status;
30  }
31 
32  status = bus_write(dev->bus, dev->i2c_address, cmd, ARRAY_SIZE(cmd));
33  if (status != NO_ERROR)
34  {
35  return status;
36  }
37 
38  status = bus_release(dev->bus);
39  if (status != NO_ERROR)
40  {
41  return status;
42  }
43 
44  return status;
45 }
status_e bus_release(const struct heivs_bus_t *bus)
Release exclusive access to the bus.
Definition: bus.c:149
status_e bus_write(const struct heivs_bus_t *bus, uint32_t address, const void *data, size_t len)
Write data to the bus.
Definition: bus.c:243
Driver for mcp4552 digital potentiometer.
status_e bus_init(const struct heivs_bus_t *bus)
initialize the bus
Definition: bus.c:59
status_e bus_get(const struct heivs_bus_t *bus)
Get exclusive access to the bus.
Definition: bus.c:134
status_e
Known errors.
Definition: error.h:21
#define ARRAY_SIZE(x)
Number of elements in the array.
Definition: utils.h:19
No error.
Definition: error.h:28