-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How backlight works on t-deck plus? #61
Comments
T-Deck/examples/UnitTest/UnitTest.ino Line 278 in c43766f
|
Thanks for the reply, I have 2 more questions: does #define BOARD_BL_PIN 42
void setBrightness(uint8_t value)
{
gpio_set_direction(BOARD_BL_PIN, GPIO_MODE_OUTPUT);
static uint8_t level = 0;
static uint8_t steps = 16;
if (value == 0) {
gpio_set_level(BOARD_BL_PIN, 0);
vTaskDelay(3 / portTICK_PERIOD_MS);
level = 0;
return;
}
if (level == 0) {
gpio_set_level(BOARD_BL_PIN, 1);
level = steps;
delayMicroseconds(30);
}
int from = steps - level;
int to = steps - value;
int num = (steps + to - from) % steps;
for (int i = 0; i < num; i++) {
gpio_set_level(BOARD_BL_PIN, 0);
gpio_set_level(BOARD_BL_PIN, 1);
}
level = value;
}
#define NOP() asm volatile ("nop")
unsigned long IRAM_ATTR micros()
{
return (unsigned long) (esp_timer_get_time());
}
void IRAM_ATTR delayMicroseconds(uint32_t us)
{
uint32_t m = micros();
if(us){
uint32_t e = (m + us);
if(m > e){ //overflow
while(micros() > e){
NOP();
}
}
while(micros() < e){
NOP();
}
}
} am I missing anything? |
Plus and non-Plus are the same, only the shell and screen are different I tested it and there was no problem at all #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include <rom/ets_sys.h>
#define BOARD_BL_PIN 42
#define BOARD_POWERON 10
void setBrightness(uint8_t value)
{
static uint8_t level = 0;
static uint8_t steps = 16;
if (value == 0)
{
gpio_set_level((gpio_num_t)BOARD_BL_PIN, 0);
vTaskDelay(pdMS_TO_TICKS(3));
level = 0;
return;
}
if (level == 0)
{
gpio_set_level((gpio_num_t)BOARD_BL_PIN, 1);
level = steps;
ets_delay_us(30);
}
int from = steps - level;
int to = steps - value;
int num = (steps + to - from) % steps;
for (int i = 0; i < num; i++)
{
gpio_set_level((gpio_num_t)BOARD_BL_PIN, 0);
gpio_set_level((gpio_num_t)BOARD_BL_PIN, 1);
}
level = value;
}
void app_main(void)
{
gpio_config_t config;
memset(&config, 0, sizeof(config));
config.pin_bit_mask = 1ULL << BOARD_POWERON;
config.mode = GPIO_MODE_OUTPUT;
config.pull_up_en = GPIO_PULLUP_DISABLE;
config.pull_down_en = GPIO_PULLDOWN_DISABLE;
config.intr_type = GPIO_INTR_DISABLE;
ESP_ERROR_CHECK(gpio_config(&config));
gpio_set_level((gpio_num_t)BOARD_POWERON, 1);
gpio_config_t bl_pin;
memset(&bl_pin, 0, sizeof(bl_pin));
bl_pin.pin_bit_mask = 1ULL << BOARD_BL_PIN;
bl_pin.mode = GPIO_MODE_OUTPUT;
bl_pin.pull_up_en = GPIO_PULLUP_DISABLE;
bl_pin.pull_down_en = GPIO_PULLDOWN_DISABLE;
bl_pin.intr_type = GPIO_INTR_DISABLE;
ESP_ERROR_CHECK(gpio_config(&bl_pin));
uint8_t level = 0;
while (1)
{
setBrightness(level++);
level %= 16;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
} |
Now it works, but there is something that I don't understand yet: how gpio 10 is involved here? |
T-Deck/examples/UnitTest/UnitTest.ino Line 832 in c43766f
|
Display backlight (gpio 42) is working on regular t-deck using LEDC PWM , but same code doesn't work with the Plus model.
How backlight can be enabled with esp-idf APIs? Should I use any specific PWM frequency or duty cycle?
The text was updated successfully, but these errors were encountered: