Firmware SDK
twr_module_power.c
1 #include <twr_module_power.h>
2 #include <twr_scheduler.h>
3 #include <twr_gpio.h>
4 #include <twr_ws2812b.h>
5 
6 #define TWR_MODULE_POWER_PIN_RELAY TWR_GPIO_P0
7 
8 static uint32_t _twr_module_power_led_strip_dma_buffer_rgbw_144[144 * 4 * 2];
9 static uint32_t _twr_module_power_led_strip_dma_buffer_rgb_150[150 * 3 * 2];
10 
11 const twr_led_strip_buffer_t twr_module_power_led_strip_buffer_rgbw_144 =
12 {
13  .type = TWR_LED_STRIP_TYPE_RGBW,
14  .count = 144,
15  .buffer = _twr_module_power_led_strip_dma_buffer_rgbw_144
16 };
17 
18 const twr_led_strip_buffer_t twr_module_power_led_strip_buffer_rgb_150 =
19 {
20  .type = TWR_LED_STRIP_TYPE_RGB,
21  .count = 150,
22  .buffer = _twr_module_power_led_strip_dma_buffer_rgb_150
23 };
24 
25 #if LED_STRIP_SWAP_RG == 0
26 
27 const twr_led_strip_driver_t twr_module_power_led_strip_driver =
28 {
29  .init = twr_ws2812b_init,
30  .write = twr_ws2812b_write,
31  .set_pixel = twr_ws2812b_set_pixel_from_uint32,
32  .set_pixel_rgbw = twr_ws2812b_set_pixel_from_rgb,
33  .is_ready = twr_ws2812b_is_ready
34 };
35 
36 #else
37 
38 const twr_led_strip_driver_t twr_module_power_led_strip_driver =
39 {
40  .init = twr_ws2812b_init,
41  .write = twr_ws2812b_write,
42  .set_pixel = twr_ws2812b_set_pixel_from_uint32_swap_rg,
43  .set_pixel_rgbw = twr_ws2812b_set_pixel_from_rgb_swap_rg,
44  .is_ready = twr_ws2812b_is_ready
45 };
46 
47 #endif
48 
49 static struct
50 {
51  struct
52  {
53  bool on;
54 
55  } relay;
56 
57 } _twr_module_power;
58 
60 {
61  memset(&_twr_module_power, 0, sizeof(_twr_module_power));
62 
63  twr_gpio_init(TWR_MODULE_POWER_PIN_RELAY);
64  twr_gpio_set_mode(TWR_MODULE_POWER_PIN_RELAY, TWR_GPIO_MODE_OUTPUT);
65 }
66 
68 {
69  _twr_module_power.relay.on = state;
70 
71  twr_gpio_set_output(TWR_MODULE_POWER_PIN_RELAY, _twr_module_power.relay.on ? 1 : 0);
72 }
73 
75 {
76  return _twr_module_power.relay.on;
77 }
78 
80 {
81  return &twr_module_power_led_strip_driver;
82 }
void twr_gpio_set_mode(twr_gpio_channel_t channel, twr_gpio_mode_t mode)
Set mode of operation for GPIO channel.
Definition: twr_gpio.c:367
GPIO channel operates as output.
Definition: twr_gpio.h:108
const twr_led_strip_driver_t * twr_module_power_get_led_strip_driver(void)
Set relay state.
void twr_module_power_init(void)
Initialize power module.
void twr_gpio_init(twr_gpio_channel_t channel)
Initialize GPIO channel.
Definition: twr_gpio.c:325
void twr_gpio_set_output(twr_gpio_channel_t channel, int state)
Set output state for GPIO channel.
Definition: twr_gpio.c:471
void twr_module_power_relay_set_state(bool state)
Set relay state.
bool twr_module_power_relay_get_state(void)
Set relay state.