Hardware Abstraction Layer for FreeRTOS
dac.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: David Brandt <david@wakka.de>
4  * Date: 2021
5  */
6 #ifndef DAC_H_
7 #define DAC_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 dac;
28 #ifdef CONFIG_DAC_MULTI
29 
32 struct dac_ops {
33  struct dac *(*dac_init)(uint32_t index, uint8_t bits);
34  int32_t (*dac_deinit)(struct dac *dac);
35  int32_t (*dac_set)(struct dac *dac, uint32_t data, TickType_t waittime);
36  int32_t (*dac_setISR)(struct dac *dac, uint32_t data);
37 };
38 #endif
39 
42 struct dac_generic {
47  bool init;
48 #ifdef CONFIG_INSTANCE_NAME
49 
52  const char *name;
53 #endif
54 #ifdef CONFIG_DAC_THREAD_SAVE
55 
59 #endif
60 #ifdef CONFIG_DAC_MULTI
61 
64  const struct dac_ops *ops;
65 #endif
66 };
67 #ifndef CONFIG_DAC_MULTI
68 
74 struct dac *dac_init(uint32_t index, uint8_t bits);
80 int32_t dac_deinit(struct dac *dac);
87 int32_t dac_set(struct dac *dac, uint32_t data, TickType_t waittime);
93 int32_t dac_setISR(struct dac *dac, uint32_t data);
94 #else
95 inline struct dac *dac_init(uint32_t index, uint8_t bits) {
97  struct dac_generic *a = (struct dac_generic *) HAL_GET_DEV(dac, index);
98  if (a == NULL) {
99  return NULL;
100  }
101  return a->ops->dac_init(index, bits);
102 }
103 inline int32_t dac_deinit(struct dac *dac) {
104  struct dac_generic *a = (struct dac_generic *) dac;
105  return a->ops->dac_deinit(dac);
106 }
107 inline int32_t dac_set(struct dac *dac, uint32_t data, TickType_t waittime) {
108  struct dac_generic *a = (struct dac_generic *) dac;
109  return a->ops->dac_set(dac, data, waittime);
110 }
111 inline int32_t dac_setISR(struct dac *dac, uint32_t data) {
112  struct dac_generic *a = (struct dac_generic *) dac;
113  return a->ops->dac_setISR(dac, data);
114 }
115 #endif
116 
117 #endif
dac_init
struct dac * dac_init(uint32_t index, uint8_t bits)
dac_set
int32_t dac_set(struct dac *dac, uint32_t data, TickType_t waittime)
OS_DEFINE_MUTEX_RECURSIVE
#define OS_DEFINE_MUTEX_RECURSIVE(name)
Definition: os.h:59
hal.h
HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY(gns)
Definition: hal.h:149
dac_generic::init
bool init
Definition: dac.h:47
HAL_GET_DEV
#define HAL_GET_DEV(gns, index)
Definition: hal.h:182
dac_setISR
int32_t dac_setISR(struct dac *dac, uint32_t data)
dac_deinit
int32_t dac_deinit(struct dac *dac)
dac_generic
Definition: dac.h:42
system.h