Hardware Abstraction Layer for FreeRTOS
adc.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2016
5  */
6 #ifndef ADC_H_
7 #define ADC_H_
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include <system.h>
11 #include <FreeRTOS.h>
12 #include <semphr.h>
13 #include <hal.h>
27 struct adc;
28 #ifdef CONFIG_ADC_MULTI
29 
32 struct adc_ops {
33  struct adc *(*adc_init)(uint32_t index, uint8_t bits, uint32_t hz);
34  int32_t (*adc_deinit)(struct adc *adc);
35  int32_t (*adc_get)(struct adc *adc, TickType_t waittime);
36  int32_t (*adc_getISR)(struct adc *adc);
37  int32_t (*adc_setCallback)(struct adc *adc, bool (*callback)(struct adc *adc, uint32_t channel, int32_t value, void *data), void *data);
38  int32_t (*adc_start)(struct adc *adc);
39  int32_t (*adc_stop)(struct adc *adc);
40 };
41 #endif
42 
45 struct adc_generic {
50  bool init;
51 #ifdef CONFIG_INSTANCE_NAME
52 
55  const char *name;
56 #endif
57 #ifdef CONFIG_ADC_THREAD_SAVE
58 
62 #endif
63 #ifdef CONFIG_ADC_MULTI
64 
67  const struct adc_ops *ops;
68 #endif
69 };
70 #ifndef CONFIG_ADC_MULTI
71 
78 struct adc *adc_init(uint32_t index, uint8_t bits, uint32_t hz);
84 int32_t adc_deinit(struct adc *adc);
91 int32_t adc_get(struct adc *adc, TickType_t waittime);
97 int32_t adc_getISR(struct adc *adc);
105 int32_t adc_setCallback(struct adc *adc, bool (*callback)(struct adc *adc, uint32_t channel, int32_t value, void *data), void *data);
111 int32_t adc_start(struct adc *adc);
117 int32_t adc_stop(struct adc *adc);
118 #else
119 inline struct adc *adc_init(uint32_t index, uint8_t bits, uint32_t hz) {
121  struct adc_generic *a = (struct adc_generic *) HAL_GET_DEV(adc, index);
122  if (a == NULL) {
123  return NULL;
124  }
125  return a->ops->adc_init(index, bits, hz);
126 }
127 inline int32_t adc_deinit(struct adc *adc) {
128  struct adc_generic *a = (struct adc_generic *) adc;
129  return a->ops->adc_deinit(adc);
130 }
131 inline int32_t adc_get(struct adc *adc, TickType_t waittime) {
132  struct adc_generic *a = (struct adc_generic *) adc;
133  return a->ops->adc_get(adc, waittime);
134 }
135 inline int32_t adc_getISR(struct adc *adc) {
136  struct adc_generic *a = (struct adc_generic *) adc;
137  return a->ops->adc_getISR(adc);
138 }
139 inline int32_t adc_setCallback(struct adc *adc, bool (*callback)(struct adc *adc, uint32_t channel, int32_t value, void *data), void *data) {
140  struct adc_generic *a = (struct adc_generic *) adc;
141  return a->ops->adc_setCallback(adc, callback, data);
142 }
143 inline int32_t adc_start(struct adc *adc) {
144  struct adc_generic *a = (struct adc_generic *) adc;
145  return a->ops->adc_start(adc);
146 }
147 inline int32_t adc_stop(struct adc *adc) {
148  struct adc_generic *a = (struct adc_generic *) adc;
149  return a->ops->adc_stop(adc);
150 }
151 #endif
152 
153 #endif
OS_DEFINE_MUTEX_RECURSIVE
#define OS_DEFINE_MUTEX_RECURSIVE(name)
Definition: os.h:59
hal.h
adc_setCallback
int32_t adc_setCallback(struct adc *adc, bool(*callback)(struct adc *adc, uint32_t channel, int32_t value, void *data), void *data)
adc_generic::init
bool init
Definition: adc.h:50
adc_deinit
int32_t adc_deinit(struct adc *adc)
HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY(gns)
Definition: hal.h:149
adc_start
int32_t adc_start(struct adc *adc)
HAL_GET_DEV
#define HAL_GET_DEV(gns, index)
Definition: hal.h:182
system.h
adc_get
int32_t adc_get(struct adc *adc, TickType_t waittime)
adc_generic
Definition: adc.h:45
adc_stop
int32_t adc_stop(struct adc *adc)
adc_init
struct adc * adc_init(uint32_t index, uint8_t bits, uint32_t hz)
adc_getISR
int32_t adc_getISR(struct adc *adc)