RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
RBControl_serialPWM.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <freertos/FreeRTOS.h>
4 
5 #include <driver/i2s.h>
6 #include <i2s_parallel.h>
7 
8 #include <initializer_list>
9 #include <vector>
10 
11 namespace rb {
12 
13 class SerialPWM {
14 public:
15  typedef int value_type;
16 
17  SerialPWM(const int channels,
18  const std::initializer_list<int> data_pins,
19  const int latch_pin,
20  const int clock_pin,
21  const int test_pin = -1,
22  const int frequency = 20000,
23  const int i2s = 1);
24 
25  ~SerialPWM();
26 
27  value_type& operator[](size_t index);
28 
29  void update();
30 
31  static int resolution();
32 
33 private:
34  SerialPWM(const SerialPWM&) = delete;
35 
36  static volatile void* i2snum2struct(const int num);
37 
38  static constexpr int sc_buffers = 2;
39  static constexpr int sc_resolution = 100;
40  const int c_channels;
41  const int c_bytes;
42  volatile void* m_i2s; // m_i2s is actually i2s_dev_t*, but this is an anonymous struct in the Espressif header i2s_struct.h and that causes a compilation error
43  i2s_parallel_buffer_desc_t* m_buffer_descriptors[sc_buffers];
44  uint8_t* m_buffer[sc_buffers][sc_resolution];
45  int m_active_buffer;
46  std::vector<value_type> m_pwm;
47 };
48 
49 } // namespace rb
Definition: RBControl_serialPWM.hpp:13
value_type & operator[](size_t index)
Definition: RBControl_serialPWM.cpp:99
static int resolution()
Definition: RBControl_serialPWM.cpp:115
int value_type
Definition: RBControl_serialPWM.hpp:15
SerialPWM(const int channels, const std::initializer_list< int > data_pins, const int latch_pin, const int clock_pin, const int test_pin=-1, const int frequency=20000, const int i2s=1)
Definition: RBControl_serialPWM.cpp:22
void update()
Definition: RBControl_serialPWM.cpp:101
~SerialPWM()
Definition: RBControl_serialPWM.cpp:87
The base namespace. Contains some logging functions, too.
Definition: half_duplex_uart.cpp:53