Hardware Abstraction Layer for FreeRTOS
tlc5947.h
Go to the documentation of this file.
1 #ifndef TLC5947
2 #define TLC5947
3 #include <stdint.h>
4 #include <spi.h>
5 #include <pwm.h>
6 #include <gpio.h>
7 
21 #define PWM_PRV
22 #include <pwm_prv.h>
23 #define GPIO_PRV
24 #include <gpio_prv.h>
25 
26 struct tlc5947;
27 
28 struct tlc5947_gpio {
29  struct gpio_generic gen;
30  struct tlc5947 *tlc;
31 };
32 
33 struct tlc5947_gpioPin {
34  struct gpio_pin_generic gen;
35  struct tlc5947_pwm *pwm;
36 };
37 
38 struct tlc5947_pwm {
39  struct pwm_generic gen;
40  int16_t val;
41  struct tlc5947_gpioPin pin;
42  struct tlc5947 *tlc;
43  int32_t us;
44 };
45 
46 struct tlc5947 {
47  struct hal gen;
48  struct spi_slave *slave;
49  struct gpio_pin *black;
50  struct tlc5947_pwm *pins[24];
51  struct tlc5947_gpio *gpio;
52 };
53 extern const struct pwm_ops tlc5947_pwm_ops;
54 extern const struct gpio_ops tlc5947_gpio_ops;
55 #define TLC5947_PWM_ADDDEV(id, i) \
56  struct tlc5947_pwm tlc5947_##id##_pwm_##i = { \
57  PWM_INIT_DEV(tlc5947) \
58  .val = 0,\
59  .pin = { \
60  .gen.gpio = (struct gpio_generic *) &tlc5947_##id##_gpio, \
61  .pwm = &tlc5947_##id##_pwm_##i, \
62  }, \
63  .tlc = &tlc5947_##id, \
64  .us = 1000, \
65  }; \
66  PWM_ADDDEV(tlc5947, tlc5947_##id##_pwm_##i)
67 
69 int32_t tlc5947_init(int32_t index, struct spi *spi, uint32_t cs, uint32_t spi_gpio, struct gpio *gpio, uint32_t black);
70 int32_t tlc5947_deinit(int32_t index);
71 
72 #define TLC5947_ADDDEV(id) \
73  extern struct tlc5947 tlc5947_##id; \
74  struct tlc5947_gpio tlc5947_##id##_gpio = { \
75  GPIO_INIT_DEV(tlc5947) \
76  HAL_NAME("TLC5947 " #id " GPIO") \
77  .tlc = &tlc5947_##id, \
78  }; \
79  TLC5947_PWM_ADDDEV(id, 0); \
80  TLC5947_PWM_ADDDEV(id, 1); \
81  TLC5947_PWM_ADDDEV(id, 2); \
82  TLC5947_PWM_ADDDEV(id, 3); \
83  TLC5947_PWM_ADDDEV(id, 4); \
84  TLC5947_PWM_ADDDEV(id, 5); \
85  TLC5947_PWM_ADDDEV(id, 6); \
86  TLC5947_PWM_ADDDEV(id, 7); \
87  TLC5947_PWM_ADDDEV(id, 8); \
88  TLC5947_PWM_ADDDEV(id, 9); \
89  TLC5947_PWM_ADDDEV(id, 10); \
90  TLC5947_PWM_ADDDEV(id, 11); \
91  TLC5947_PWM_ADDDEV(id, 12); \
92  TLC5947_PWM_ADDDEV(id, 13); \
93  TLC5947_PWM_ADDDEV(id, 14); \
94  TLC5947_PWM_ADDDEV(id, 15); \
95  TLC5947_PWM_ADDDEV(id, 16); \
96  TLC5947_PWM_ADDDEV(id, 17); \
97  TLC5947_PWM_ADDDEV(id, 18); \
98  TLC5947_PWM_ADDDEV(id, 19); \
99  TLC5947_PWM_ADDDEV(id, 20); \
100  TLC5947_PWM_ADDDEV(id, 21); \
101  TLC5947_PWM_ADDDEV(id, 22); \
102  TLC5947_PWM_ADDDEV(id, 23); \
103  GPIO_ADDDEV(tlc5947, tlc5947_##id##_gpio); \
104  struct tlc5947 tlc5947_##id = { \
105  HAL_NAME("TLC5947 " #id) \
106  .slave = NULL, \
107  .black = NULL, \
108  .gpio = &tlc5947_##id##_gpio,\
109  .pins = { \
110  &tlc5947_##id##_pwm_0, \
111  &tlc5947_##id##_pwm_1, \
112  &tlc5947_##id##_pwm_2, \
113  &tlc5947_##id##_pwm_3, \
114  &tlc5947_##id##_pwm_4, \
115  &tlc5947_##id##_pwm_5, \
116  &tlc5947_##id##_pwm_6, \
117  &tlc5947_##id##_pwm_7, \
118  &tlc5947_##id##_pwm_8, \
119  &tlc5947_##id##_pwm_9, \
120  &tlc5947_##id##_pwm_10, \
121  &tlc5947_##id##_pwm_11, \
122  &tlc5947_##id##_pwm_12, \
123  &tlc5947_##id##_pwm_13, \
124  &tlc5947_##id##_pwm_14, \
125  &tlc5947_##id##_pwm_15, \
126  &tlc5947_##id##_pwm_16, \
127  &tlc5947_##id##_pwm_17, \
128  &tlc5947_##id##_pwm_18, \
129  &tlc5947_##id##_pwm_19, \
130  &tlc5947_##id##_pwm_20, \
131  &tlc5947_##id##_pwm_21, \
132  &tlc5947_##id##_pwm_22, \
133  &tlc5947_##id##_pwm_23, \
134  },\
135  }; \
136  HAL_ADDDEV(hal, tlc5947, tlc5947_##id)
137 
138 #define TLC5947_ID(id) HAL_GET_ID(hal, tlc5947, tlc5947_##id)
139 #define TLC5947_GPIO_ID(id) HAL_GET_ID(gpio, tlc5947, tlc5947_##id##_gpio)
140 #define TLC5947_PWM_ID(id, channelID) HAL_GET_ID(pwm, tlc5947, tlc5947_##id##_pwm_##channelID)
141 
142 #endif
gpio_pin_generic
Definition: gpio.h:129
pwm_generic
Definition: pwm.h:45
spi.h
pwm_prv.h
hal
Definition: hal.h:48
gpio_generic
Definition: gpio.h:107
gpio_prv.h
tlc5947_init
int32_t tlc5947_init(int32_t index, struct spi *spi, uint32_t cs, uint32_t spi_gpio, struct gpio *gpio, uint32_t black)
tlc5947_deinit
int32_t tlc5947_deinit(int32_t index)
gpio.h
pwm.h