mn_pin.hpp
Go to the documentation of this file.
1 
19 #ifndef MINLIB_65db7f3d_c57e_4420_884f_350c78711f41_H_
20 #define MINLIB_65db7f3d_c57e_4420_884f_350c78711f41_H_
21 
22 #include "mn_config.hpp"
23 
24 #include <freertos/FreeRTOS.h>
25 #include <freertos/task.h>
26 #include <driver/gpio.h>
27 #include <sdkconfig.h>
28 
29 #include <stdio.h>
30 
31 namespace mn {
32  enum class pin_direction {
33  Disable = GPIO_MODE_DISABLE,
34  Input = GPIO_MODE_INPUT,
35  Output = GPIO_MODE_OUTPUT,
36  InOut = GPIO_MODE_INPUT_OUTPUT;
37  };
38 
39  template <int TPin>
40  class basic_hardware_pin { };
41 
42 
43 
44  template <int TPin, bool TLevel = false, pin_direction TDirection = pin_direction::Output>
46  public:
48  gpio_pad_select_gpio(TPin);
49  gpio_set_level(TPin, TLevel ? 1 : 0);
50  gpio_set_direction(TPin, TDirection);
51  }
52  void set(bool on) {
53  gpio_set_level(TPin, on ? 1 : 0);
54  }
55  void reset() {
56  gpio_reset_pin(TPin);
57  }
58  bool get() {
59  return gpio_get_level(TPin) == 1;
60  }
61  void set_direction(pin_direction& direction) {
62  gpio_set_direction(TPin, direction);
63  }
64 
65 
66  };
67 
68  template <int TPin, bool TLevel = false, pin_direction TDirection = pin_direction::Output>
69  using esp32_digital_pin = basic_esp32_hardware_pin<TPin>;
70 
71 
72 
73 
74 }
75 
76 
77 #endif
Definition: mn_pin.hpp:45
basic_esp32_hardware_pin()
Definition: mn_pin.hpp:47
bool get()
Definition: mn_pin.hpp:58
void reset()
Definition: mn_pin.hpp:55
void set(bool on)
Definition: mn_pin.hpp:52
void set_direction(pin_direction &direction)
Definition: mn_pin.hpp:61
Definition: mn_pin.hpp:40
Definition: mn_allocator_typetraits.hpp:25
pin_direction
Definition: mn_pin.hpp:32
basic_esp32_hardware_pin< TPin > esp32_digital_pin
Definition: mn_pin.hpp:69