|
@@ -11,43 +11,39 @@
|
|
|
namespace kbf::gpio {
|
|
|
static constexpr const char *TAG = "kbf::gpio";
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief GPIO / output
|
|
|
+ */
|
|
|
class Output {
|
|
|
public:
|
|
|
/**
|
|
|
- * Initialises GPIO pin by resetting it and setting it's direction to GPIO_MODE_OUTPUT.
|
|
|
+ * @brief Initialises GPIO pin by resetting it and setting it's direction to GPIO_MODE_OUTPUT.
|
|
|
*
|
|
|
* @param pin GPIO pin number
|
|
|
*/
|
|
|
explicit Output(int pin);
|
|
|
|
|
|
/**
|
|
|
- * GPIO pin number
|
|
|
+ * @brief GPIO pin number.
|
|
|
*/
|
|
|
const gpio_num_t pin;
|
|
|
|
|
|
/**
|
|
|
- * Sets pin output to HIGH.
|
|
|
+ * @brief Sets pin output to HIGH.
|
|
|
*/
|
|
|
void high() const;
|
|
|
|
|
|
/**
|
|
|
- * Sets pin output to LOW.
|
|
|
+ * @brief Sets pin output to LOW.
|
|
|
*/
|
|
|
void low() const;
|
|
|
|
|
|
/**
|
|
|
- * Checks the current state of the pin.
|
|
|
- *
|
|
|
- * @return true if pin is HIGH; false if pin is LOW
|
|
|
- */
|
|
|
- [[nodiscard]] bool isHigh() const;
|
|
|
-
|
|
|
- /**
|
|
|
- * Alternates between HIGH and LOW states, sleeping delay_ms milliseconds in between. Starts with HIGH.
|
|
|
+ * @brief Alternates between HIGH and LOW states, sleeping delay_ms milliseconds in between. Starts with HIGH.
|
|
|
*
|
|
|
* @note If the limit is negative (default), it will continue indefinitely.
|
|
|
*
|
|
|
- * @note This method uses kbf::sleep() which in turn uses vTaskDelay() from RTOS which is fine for
|
|
|
+ * @warning This method uses kbf::sleep() which in turn uses vTaskDelay() from RTOS which is fine for
|
|
|
* blinking an LED but is probably not good enough for high precision stuff.
|
|
|
*
|
|
|
* @param delay_ms delay in milliseconds
|
|
@@ -56,7 +52,7 @@ namespace kbf::gpio {
|
|
|
void startPulse(int delay_ms, int limit = -1);
|
|
|
|
|
|
/**
|
|
|
- * Stop pulse loop.
|
|
|
+ * @brief Stop pulse loop.
|
|
|
*
|
|
|
* @note Will ABORT if pulse loop not running
|
|
|
*/
|
|
@@ -68,12 +64,75 @@ namespace kbf::gpio {
|
|
|
int pulseLimit = 0;
|
|
|
|
|
|
/**
|
|
|
- * Callback for pulse task.
|
|
|
+ * @brief Callback for pulse task.
|
|
|
*
|
|
|
* @param arg Output instance
|
|
|
*/
|
|
|
static void pulseCallback(void *arg);
|
|
|
};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief GPIO / input
|
|
|
+ */
|
|
|
+ class Input {
|
|
|
+ public:
|
|
|
+ /**
|
|
|
+ * @brief Initialises GPIO pin by resetting it and setting it's direction to GPIO_MODE_OUTPUT.
|
|
|
+ *
|
|
|
+ * @param pin GPIO pin number
|
|
|
+ * @param userData custom data; useful in callbacks
|
|
|
+ */
|
|
|
+ explicit Input(int pin, void *userData = nullptr);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Removes interrupt handler.
|
|
|
+ */
|
|
|
+ ~Input();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief GPIO pin number
|
|
|
+ */
|
|
|
+ const gpio_num_t pin;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Custom data; useful in callbacks
|
|
|
+ */
|
|
|
+ void *const userData;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Returns the current state of the pin.
|
|
|
+ *
|
|
|
+ * @return true if pin is HIGH; false if LOW
|
|
|
+ */
|
|
|
+ [[nodiscard]] bool isHigh() const;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Returns the current state of the pin.
|
|
|
+ *
|
|
|
+ * @return true if pin is LOW; false if HIGH
|
|
|
+ */
|
|
|
+ [[nodiscard]] bool isLow() const;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Method to be called when the pin is pulled high.
|
|
|
+ *
|
|
|
+ * @param input gpio::Input instance
|
|
|
+ */
|
|
|
+ void (*onHigh)(Input &input) = nullptr;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Method to be called when the pin is pulled low.
|
|
|
+ *
|
|
|
+ * @param input gpio::Output instance
|
|
|
+ */
|
|
|
+ void (*onLow)(Input &input) = nullptr;
|
|
|
+
|
|
|
+ private:
|
|
|
+ /**
|
|
|
+ * @brief ISR handler. Calls onHigh() or onLow() if set.
|
|
|
+ */
|
|
|
+ static void interruptHandler(void *);
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
#endif //KBF_GPIO_H
|