49 lines
1019 B
C++
49 lines
1019 B
C++
#include "GPIO_drv.hpp"
|
|
#include <algorithm>
|
|
#include "esp_log.h"
|
|
|
|
bool GPIO_drv::isr_service_installed = false;
|
|
|
|
GPIO_drv::GPIO_drv()
|
|
: clbk_ptr(nullptr)
|
|
{
|
|
}
|
|
|
|
GPIO_drv::~GPIO_drv()
|
|
{
|
|
}
|
|
|
|
void GPIO_drv::init(gpio_num_t but, gpio_mode_t mode, gpio_pullup_t pu, gpio_pulldown_t pd)
|
|
{
|
|
button = but;
|
|
gpio_config_t io_conf;
|
|
io_conf.intr_type = GPIO_INTR_DISABLE;
|
|
io_conf.mode = mode;
|
|
io_conf.pin_bit_mask = (1ULL << button);
|
|
io_conf.pull_down_en = pd;
|
|
io_conf.pull_up_en = pu;
|
|
gpio_config(&io_conf);
|
|
}
|
|
|
|
void GPIO_drv::enableINT(gpio_int_type_t type, Callback ptr)
|
|
{
|
|
gpio_set_intr_type(button, type);
|
|
if (!isr_service_installed)
|
|
{
|
|
gpio_install_isr_service(0);
|
|
isr_service_installed = true;
|
|
}
|
|
gpio_isr_handler_add(button, ptr, (void*)button);
|
|
gpio_intr_enable(button);
|
|
}
|
|
|
|
void GPIO_drv::setLvl(Lvl lvl)
|
|
{
|
|
gpio_set_level(button, static_cast<std::uint32_t>(lvl));
|
|
}
|
|
|
|
Lvl GPIO_drv::getLvl()
|
|
{
|
|
return static_cast<Lvl>(gpio_get_level(button));
|
|
}
|