Driver improvements (#226)
- Created driver subprojects: `FT5x06`, `FT6x36`, `CST816S`. - Refactored existing projects to use new drivers. - Improve `PwmBacklight` driver: expose frequency, channel id and timer id - Update `build-and-release-all.sh` for recent board addition
This commit is contained in:
committed by
GitHub
parent
6e8fbae62b
commit
933bc5fb97
@@ -1,6 +1,6 @@
|
||||
#include "PwmBacklight.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#define TAG "pwm_backlight"
|
||||
|
||||
@@ -8,16 +8,20 @@ namespace driver::pwmbacklight {
|
||||
|
||||
static bool isBacklightInitialized = false;
|
||||
static gpio_num_t backlightPin = GPIO_NUM_NC;
|
||||
static ledc_timer_t backlightTimer;
|
||||
static ledc_channel_t backlightChannel;
|
||||
|
||||
bool init(gpio_num_t pin) {
|
||||
bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) {
|
||||
backlightPin = pin;
|
||||
backlightTimer = timer;
|
||||
backlightChannel = channel;
|
||||
|
||||
TT_LOG_I(TAG, "Init");
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = LEDC_TIMER_8_BIT,
|
||||
.timer_num = LEDC_TIMER_0,
|
||||
.freq_hz = 4000,
|
||||
.timer_num = backlightTimer,
|
||||
.freq_hz = frequencyHz,
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
.deconfigure = false
|
||||
};
|
||||
@@ -30,9 +34,9 @@ bool init(gpio_num_t pin) {
|
||||
ledc_channel_config_t ledc_channel = {
|
||||
.gpio_num = backlightPin,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = LEDC_CHANNEL_0,
|
||||
.channel = backlightChannel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.timer_sel = backlightTimer,
|
||||
.duty = 0,
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
@@ -55,8 +59,8 @@ bool setBacklightDuty(uint8_t duty) {
|
||||
TT_LOG_E(TAG, "Not initialized");
|
||||
return false;
|
||||
}
|
||||
return ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, duty) == ESP_OK &&
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0) == ESP_OK;
|
||||
return ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK &&
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, backlightChannel) == ESP_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
namespace driver::pwmbacklight {
|
||||
|
||||
bool init(gpio_num_t pin);
|
||||
bool init(gpio_num_t pin, uint32_t frequencyHz = 40000, ledc_timer_t timer = LEDC_TIMER_0, ledc_channel_t channel = LEDC_CHANNEL_0);
|
||||
|
||||
void setBacklightDuty(uint8_t duty);
|
||||
bool setBacklightDuty(uint8_t duty);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user