Skip to content

Commit

Permalink
feat(gpio): add a constructor to GPIOInput that fully configures a GPIO
Browse files Browse the repository at this point in the history
The new constructor takes gpio number, pull mode and driver strength as parameters.
This constructor by used in GPIOIntr constructor.
  • Loading branch information
SoucheSouche committed Oct 3, 2022
1 parent ac75cad commit e71b50c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/gpio_intr_cxx/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace std::placeholders;
class IntHdlr {
public:
IntHdlr(const GPIONum gpio_num, const GPIOPullMode mode, const GPIODriveStrength strength, const GPIOIntrType type):
gpio_intr(gpio_num, type, mode, strength, "name", std::bind(&IntHdlr::callback, this, _1)),
gpio_intr(gpio_num, mode, strength, type, "name", std::bind(&IntHdlr::callback, this, _1)),
counter(0),
missed_counter(0)
{
Expand Down
7 changes: 7 additions & 0 deletions gpio_cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ GPIOInput::GPIOInput(GPIONum num) : GPIOBase(num)
GPIO_CHECK_THROW(gpio_set_direction(gpio_num.get_value<gpio_num_t>(), GPIO_MODE_INPUT));
}

GPIOInput::GPIOInput(const GPIONum num, const GPIOPullMode mode, const GPIODriveStrength strength)
: GPIOInput(num)
{
set_pull_mode(mode);
set_drive_strength(strength);
}

GPIOLevel GPIOInput::get_level() const noexcept
{
int level = gpio_get_level(gpio_num.get_value<gpio_num_t>());
Expand Down
6 changes: 2 additions & 4 deletions gpio_intr_cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ void stop_service(void)
}

GPIOIntr::GPIOIntr(const GPIONum gpio_number,
const GPIOIntrType type,
const GPIOPullMode mode,
const GPIODriveStrength strength,
const GPIOIntrType type,
std::string cb_name,
interrupt_callback_t cb):
GPIOInput(gpio_number)
GPIOInput(gpio_number, mode, strength)
{
set_pull_mode(mode);
set_drive_strength(strength);
set_type(type);
add_callback(cb_name, cb);
}
Expand Down
9 changes: 9 additions & 0 deletions include/gpio_cxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ class GPIOInput : public GPIOBase {
*/
GPIOInput(GPIONum num);

/**
* @brief Constructs and fully configure a GPIO as input
*
* @param num GPIO pin number of the GPIO to be configured.
* @param mode The pull mode to configure on the GPIO
* @param strength The internal pull resistor strength to setup on the GPIO
*/
GPIOInput(const GPIONum num, const GPIOPullMode mode, const GPIODriveStrength strength);

/**
* @brief Read the current level of the GPIO.
*
Expand Down
5 changes: 2 additions & 3 deletions include/gpio_intr_cxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ class GPIOIntr: public GPIOInput {
* @param cb_name
* @param cb
*/
GPIOIntr(const GPIONum gpio_number, const GPIOIntrType type,
const GPIOPullMode mode, const GPIODriveStrength strength,
std::string cb_name, interrupt_callback_t cb);
GPIOIntr(const GPIONum gpio_number, const GPIOPullMode mode, const GPIODriveStrength strength,
const GPIOIntrType type, std::string cb_name, interrupt_callback_t cb);

/**
* @brief Set the interrupt type on the GPIO input
Expand Down

0 comments on commit e71b50c

Please sign in to comment.