Hardware Abstraction Layer for FreeRTOS
mcp320x.h
Go to the documentation of this file.
1 #ifndef MCP320X_H_
2 #define MCP320X_H_
3 
4 #include <adc.h>
5 #define ADC_PRV
6 #include <adc_prv.h>
7 #include <spi.h>
8 #include <FreeRTOS.h>
9 #include <task.h>
10 extern const struct adc_ops mcp320x_adc_ops;
11 struct adc_mcp320x_controller {
12  struct hal gen;
13  struct adc_mcp320x *channels[16];
14  struct spi_slave *slave;
15 
16 };
17 struct adc_mcp320x {
18  struct adc_generic gen;
19  struct adc_mcp320x_controller *adcc;
20  uint32_t bits;
21  uint32_t ticks;
22  uint32_t channelID;
23  bool running;
24  OS_DEFINE_TASK(task, 500);
25  bool (*callback)(struct adc *adc, uint32_t channel, int32_t value, void *data);
26  void *data;
27 };
28 
29 #define ADD_MCP320X_CHANNEL(ID, _channelID) \
30  struct adc_mcp320x mcp320x_##ID##_##_channelID = { \
31  ADC_INIT_DEV(mcp320x) \
32  HAL_NAME("TI MCP320x " #ID "Channel " #_channelID) \
33  .adcc = &mcp320x_##ID, \
34  .channelID = _channelID, \
35  };\
36  ADC_ADDDEV(mcp320x, mcp320x_##ID##_##_channelID)
37 
39 void *mcp320x_controller_init(uint32_t index);
40 int32_t mcp320x_connect(void *ac, struct spi *spi, uint8_t cs, uint16_t gpio, uint32_t baudrate);
41 
42 #define ADD_MCP320X(ID) \
43  extern struct adc_mcp320x_controller mcp320x_##ID;\
44  ADD_MCP320X_CHANNEL(ID, 0); \
45  ADD_MCP320X_CHANNEL(ID, 1); \
46  ADD_MCP320X_CHANNEL(ID, 2); \
47  ADD_MCP320X_CHANNEL(ID, 3); \
48  ADD_MCP320X_CHANNEL(ID, 4); \
49  ADD_MCP320X_CHANNEL(ID, 5); \
50  ADD_MCP320X_CHANNEL(ID, 6); \
51  ADD_MCP320X_CHANNEL(ID, 7); \
52  ADD_MCP320X_CHANNEL(ID, 8); \
53  ADD_MCP320X_CHANNEL(ID, 9); \
54  ADD_MCP320X_CHANNEL(ID, 10); \
55  ADD_MCP320X_CHANNEL(ID, 11); \
56  ADD_MCP320X_CHANNEL(ID, 12); \
57  ADD_MCP320X_CHANNEL(ID, 13); \
58  ADD_MCP320X_CHANNEL(ID, 14); \
59  ADD_MCP320X_CHANNEL(ID, 15); \
60  struct adc_mcp320x_controller mcp320x_##ID = { \
61  HAL_NAME("TI MCP320x " #ID) \
62  .channels = { \
63  &mcp320x_##ID##_0, \
64  &mcp320x_##ID##_1, \
65  &mcp320x_##ID##_2, \
66  &mcp320x_##ID##_3, \
67  &mcp320x_##ID##_4, \
68  &mcp320x_##ID##_5, \
69  &mcp320x_##ID##_6, \
70  &mcp320x_##ID##_7, \
71  &mcp320x_##ID##_8, \
72  &mcp320x_##ID##_9, \
73  &mcp320x_##ID##_10, \
74  &mcp320x_##ID##_11, \
75  &mcp320x_##ID##_12, \
76  &mcp320x_##ID##_13, \
77  &mcp320x_##ID##_14, \
78  &mcp320x_##ID##_15, \
79  }, \
80  }; \
81  HAL_ADDDEV(hal, mcp320x, mcp320x_##ID)
82 
83 #define MCP320X_ID(ID) HAL_GET_ID(hal, mcp320x, mcp320x_##ID)
84 #define MCP320X_ID_CHANNEL(ID, _channelID) HAL_GET_ID(adc, mcp320x, mcp320x_##ID##_##_channelID)
85 #endif
86 
mcp320x_connect
int32_t mcp320x_connect(void *ac, struct spi *spi, uint8_t cs, uint16_t gpio, uint32_t baudrate)
mcp320x_controller_init
void * mcp320x_controller_init(uint32_t index)
spi.h
adc.h
hal
Definition: hal.h:48
adc_prv.h
OS_DEFINE_TASK
#define OS_DEFINE_TASK(name, stackSize)
Definition: os.h:52
adc_generic
Definition: adc.h:45