rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
board.c File Reference

Board bring-up for the 7-inch ESP32-P4 display board: touch I2C bus, backlight PWM and the GT911 reset. More...

#include "board.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#include "esp_check.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

Data Structures

struct  [struct].s_board

Macros

#define BL_DUTY_MAX   ((1u << BOARD_BL_DUTY_BITS) - 1u)
 The largest LEDC duty at BOARD_BL_DUTY_BITS.

Functions

static esp_err_t backlight_init (void)
 Set up the backlight's LEDC timer and channel, dark.
esp_err_t board_init (void)
 Bring up the touch I2C bus and the backlight PWM, the backlight at 0% (dark).
i2c_master_bus_handle_t board_i2c_bus (void)
 The touch bus: the GT911 and, in a build with it, the touch injector.
esp_err_t board_backlight_percent (int percent)
 Set the backlight brightness.
esp_err_t board_backlight (bool on)
 Backlight at 100% or 0%.
esp_err_t board_touch_reset_sequence (void)
 Run the GT911 reset on BOARD_TOUCH_PIN_RST: low 20ms, high, then 60ms before the first read. Does nothing with GPIO_NUM_NC. INT is not wired to the SoC, so the address the GT911 takes is its own choice; gt911_new() probes 0x5D, then 0x14.

Variables

static const char * TAG = "board"
static struct  s_board
 The board's state, set once by board_init().

Detailed Description

Board bring-up for the 7-inch ESP32-P4 display board: touch I2C bus, backlight PWM and the GT911 reset.

SPDX-License-Identifier: MIT

Function Documentation

◆ backlight_init()

esp_err_t backlight_init ( void )
static

Set up the backlight's LEDC timer and channel, dark.

LEDC low-speed mode, inverted output: duty 0 holds GPIO32 high, the dimmest state, from the moment the channel exists. Before that the pin is undriven and the converter's own resistors set the brightest state (from the schematic, not measured).

Returns
ESP_OK, or the LEDC error.

◆ board_backlight()

esp_err_t board_backlight ( bool on)

Backlight at 100% or 0%.

Parameters
ontrue for 100%, false for 0% (dark).
Returns
As board_backlight_percent().

◆ board_backlight_percent()

esp_err_t board_backlight_percent ( int percent)

Set the backlight brightness.

Parameters
percent0 to 100%; values outside are clamped.
Returns
ESP_OK, ESP_ERR_INVALID_STATE before board_init(), or the LEDC error.

◆ board_i2c_bus()

i2c_master_bus_handle_t board_i2c_bus ( void )

The touch bus: the GT911 and, in a build with it, the touch injector.

Returns
The bus handle, or NULL before board_init() succeeded.

◆ board_init()

esp_err_t board_init ( void )

Bring up the touch I2C bus and the backlight PWM, the backlight at 0% (dark).

Safe to call repeatedly: a second call returns at once.

Returns
ESP_OK, or the error of the bus or LEDC call that failed.

◆ board_touch_reset_sequence()

esp_err_t board_touch_reset_sequence ( void )

Run the GT911 reset on BOARD_TOUCH_PIN_RST: low 20ms, high, then 60ms before the first read. Does nothing with GPIO_NUM_NC. INT is not wired to the SoC, so the address the GT911 takes is its own choice; gt911_new() probes 0x5D, then 0x14.

Returns
ESP_OK, the board_init() error, or the GPIO error.