Skip to content

Commit

Permalink
Updated to esp-idf 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LeandroTE committed Aug 17, 2023
1 parent 68bc1e4 commit 6fd9119
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 45 deletions.
3 changes: 2 additions & 1 deletion components/spidriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FILE(GLOB SOURCES *.c)
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS ".")
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS "."
PRIV_REQUIRES driver)
2 changes: 2 additions & 0 deletions components/spidriver/spi_master_lobo.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Main driver's function is 'spi_lobo_transfer_data()'
#include "driver/gpio.h"
#include "spi_master_lobo.h"
#include "driver/periph_ctrl.h"
#include "soc/gpio_periph.h"
#include "rom/gpio.h"

static spi_lobo_host_t *spihost[3] = {NULL};

Expand Down
3 changes: 2 additions & 1 deletion components/tft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FILE(GLOB SOURCES *.c)
idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS "."
REQUIRES spidriver)
REQUIRES spidriver
PRIV_REQUIRES driver)
5 changes: 5 additions & 0 deletions components/tft/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ config TFT_PREDEFINED_DISPLAY_TYPE
default 3 if TFT_PREDEFINED_DISPLAY_TYPE3
default 4 if TFT_PREDEFINED_DISPLAY_TYPE4
default 5 if TFT_PREDEFINED_DISPLAY_TYPE5
default 6 if TFT_PREDEFINED_DISPLAY_TYPE6


choice
prompt "Select predefined display configuration"
Expand All @@ -27,6 +29,9 @@ config TFT_PREDEFINED_DISPLAY_TYPE
bool "M5Stack TFT Display"
config TFT_PREDEFINED_DISPLAY_TYPE5
bool "TTGO T-DISPLAY (ST7789V)"
config TFT_PREDEFINED_DISPLAY_TYPE6
bool "TTGO T-WRISTBAND (ST7735)"

endchoice

if TFT_PREDEFINED_DISPLAY_TYPE0
Expand Down
32 changes: 16 additions & 16 deletions components/tft/tft.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,8 @@ void TFT_drawStar(int cx, int cy, int diameter, color_t color, bool fill, float

// ================ Font and string functions ==================================

//--------------------------------------------------------
static int load_file_font(const char * fontfile, int info)
//-------------------------------------------------------
static int load_file_font(const char *fontfile, int info)
{
int err = 0;
char err_msg[256] = {'\0'};
Expand Down Expand Up @@ -1142,8 +1142,8 @@ static int load_file_font(const char * fontfile, int info)
return err;
}

//------------------------------------------------
int compile_font_file(char *fontfile, uint8_t dbg)
//------------------------------------------------------
int compile_font_file(const char *fontfile, uint8_t dbg)
{
int err = 0;
char err_msg[128] = {'\0'};
Expand Down Expand Up @@ -1768,16 +1768,16 @@ static int _7seg_height()

// Returns the string width in pixels.
// Useful for positions strings on the screen.
//===============================
int TFT_getStringWidth(char* str)
//=====================================
int TFT_getStringWidth(const char *str)
{
int strWidth = 0;

if (tft_cfont.bitmap == 2) strWidth = ((_7seg_width()+2) * strlen(str)) - 2; // 7-segment font
else if (tft_cfont.x_size != 0) strWidth = strlen(str) * tft_cfont.x_size; // fixed width font
else {
// calculate the width of the string of proportional characters
char* tempStrptr = str;
const char *tempStrptr = str;
while (*tempStrptr != 0) {
if (getCharPtr(*tempStrptr++)) {
strWidth += (((fontChar.width > fontChar.xDelta) ? fontChar.width : fontChar.xDelta) + 1);
Expand All @@ -1788,8 +1788,8 @@ int TFT_getStringWidth(char* str)
return strWidth;
}

//===============================================
void TFT_clearStringRect(int x, int y, char *str)
//=====================================================
void TFT_clearStringRect(int x, int y, const char *str)
{
int w = TFT_getStringWidth(str);
int h = TFT_getfontheight();
Expand Down Expand Up @@ -1919,8 +1919,8 @@ static void _draw7seg(int16_t x, int16_t y, int8_t num, int16_t w, int16_t l, co
}
//==============================================================================

//======================================
void TFT_print(char *st, int x, int y) {
//============================================
void TFT_print(const char *st, int x, int y) {
int stl, i, tmpw, tmph, fh;
uint8_t ch;

Expand Down Expand Up @@ -2363,7 +2363,7 @@ static UINT tjd_output (
}
else {
wait_trans_finish(1);
printf("Data size error: %d jpg: (%d,%d,%d,%d) disp: (%d,%d,%d,%d)\r\n", len, left,top,right,bottom, dleft,dtop,dright,dbottom);
printf("Data size error: %lu jpg: (%d,%d,%d,%d) disp: (%d,%d,%d,%d)\r\n", (long unsigned)len, left,top,right,bottom, dleft,dtop,dright,dbottom);
return 0; // stop decompression
}

Expand All @@ -2372,8 +2372,8 @@ static UINT tjd_output (

// tft.jpgimage(X, Y, scale, file_name, buf, size]
// X & Y can be < 0 !
//==================================================================================
void TFT_jpg_image(int x, int y, uint8_t scale, char *fname, uint8_t *buf, int size)
//========================================================================================
void TFT_jpg_image(int x, int y, uint8_t scale, const char *fname, uint8_t *buf, int size)
{
JPGIODEV dev;
struct stat sb;
Expand Down Expand Up @@ -2469,8 +2469,8 @@ void TFT_jpg_image(int x, int y, uint8_t scale, char *fname, uint8_t *buf, int s
}


//====================================================================================
int TFT_bmp_image(int x, int y, uint8_t scale, char *fname, uint8_t *imgbuf, int size)
//==========================================================================================
int TFT_bmp_image(int x, int y, uint8_t scale, const char *fname, uint8_t *imgbuf, int size)
{
FILE *fhndl = NULL;
struct stat sb;
Expand Down
27 changes: 14 additions & 13 deletions components/tft/tft.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ void TFT_setFont(uint8_t font, const char *font_file);
* height: pointer to returned font height
*/
//-------------------------------------------
int TFT_getfontsize(int *width, int* height);
int TFT_getfontsize(int *width, int *height);


/*
Expand Down Expand Up @@ -484,11 +484,11 @@ int TFT_getfontheight();
* LASTY, continues from last Y position; offset can be used: LASTY+n
*
*/
//-------------------------------------
void TFT_print(char *st, int x, int y);
//-------------------------------------------
void TFT_print(const char *st, int x, int y);

/*
* Set atributes for 7 segment vector font
* Set attributes for 7 segment vector font
* == 7 segment font must be the current font to this function to have effect ==
*
* Params:
Expand Down Expand Up @@ -579,14 +579,15 @@ int TFT_compare_colors(color_t c1, color_t c2);
* returns the string width in pixels.
* Useful for positions strings on the screen.
*/
//--------------------------------
int TFT_getStringWidth(char* str);
//--------------------------------------
int TFT_getStringWidth(const char *str);


/*
* Fills the rectangle occupied by string with current background color
*/
void TFT_clearStringRect(int x, int y, char *str);
//------------------------------------------------------
void TFT_clearStringRect(int x, int y, const char *str);

/*
* Converts the components of a color, as specified by the HSB model,
Expand Down Expand Up @@ -622,8 +623,8 @@ color_t HSBtoRGB(float _hue, float _sat, float _brightness);
* size: size of the memory buffer from which the image will be read; used if fname=NULL & buf!=NULL
*
*/
//-----------------------------------------------------------------------------------
void TFT_jpg_image(int x, int y, uint8_t scale, char *fname, uint8_t *buf, int size);
//-----------------------------------------------------------------------------------------
void TFT_jpg_image(int x, int y, uint8_t scale, const char *fname, uint8_t *buf, int size);

/*
* Decodes and displays BMP image
Expand All @@ -639,8 +640,8 @@ void TFT_jpg_image(int x, int y, uint8_t scale, char *fname, uint8_t *buf, int s
* size: size of the memory buffer from which the image will be read; used if fname=NULL & imgbuf!=NULL
*
*/
//-------------------------------------------------------------------------------------
int TFT_bmp_image(int x, int y, uint8_t scale, char *fname, uint8_t *imgbuf, int size);
//-------------------------------------------------------------------------------------------
int TFT_bmp_image(int x, int y, uint8_t scale, const char *fname, uint8_t *imgbuf, int size);

/*
* Get the touch panel coordinates.
Expand Down Expand Up @@ -673,8 +674,8 @@ int TFT_read_touch(int *x, int* y, uint8_t raw);
* err no on error
*
*/
//------------------------------------------------
int compile_font_file(char *fontfile, uint8_t dbg);
//-------------------------------------------------------
int compile_font_file(const char *fontfile, uint8_t dbg);

/*
* Get all font's characters to buffer
Expand Down
11 changes: 6 additions & 5 deletions components/tft/tftspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "freertos/task.h"
#include "soc/spi_reg.h"
#include "driver/gpio.h"
#include "rom/gpio.h"


// ====================================================
Expand Down Expand Up @@ -601,14 +602,14 @@ uint32_t stmpe610_getID()
void stmpe610_Init()
{
stmpe610_write_reg(STMPE610_REG_SYS_CTRL1, 0x02); // Software chip reset
vTaskDelay(10 / portTICK_RATE_MS);
vTaskDelay(10 / portTICK_PERIOD_MS);

stmpe610_write_reg(STMPE610_REG_SYS_CTRL2, 0x04); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on

stmpe610_write_reg(STMPE610_REG_INT_EN, 0x00); // Don't Interrupt on INT pin

stmpe610_write_reg(STMPE610_REG_ADC_CTRL1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce
vTaskDelay(2 / portTICK_RATE_MS);
vTaskDelay(2 / portTICK_PERIOD_MS);
stmpe610_write_reg(STMPE610_REG_ADC_CTRL2, 0x01); // ADC speed 3.25MHz
stmpe610_write_reg(STMPE610_REG_GPIO_AF, 0x00); // GPIO alternate function - OFF
stmpe610_write_reg(STMPE610_REG_TSC_CFG, 0xE3); // Averaging 8, touch detect delay 1ms, panel driver settling time 1ms
Expand Down Expand Up @@ -756,7 +757,7 @@ static void commandList(spi_lobo_device_handle_t spi, const uint8_t *addr) {
if(ms) {
ms = *addr++; // Read post-command delay time (ms)
if(ms == 255) ms = 500; // If 255, delay for 500 ms
vTaskDelay(ms / portTICK_RATE_MS);
vTaskDelay(ms / portTICK_PERIOD_MS);
}
}
}
Expand Down Expand Up @@ -897,9 +898,9 @@ void TFT_display_init()
#if PIN_NUM_RST
//Reset the display
gpio_set_level(PIN_NUM_RST, 0);
vTaskDelay(20 / portTICK_RATE_MS);
vTaskDelay(20 / portTICK_PERIOD_MS);
gpio_set_level(PIN_NUM_RST, 1);
vTaskDelay(150 / portTICK_RATE_MS);
vTaskDelay(150 / portTICK_PERIOD_MS);
#endif

ret = disp_select();
Expand Down
34 changes: 33 additions & 1 deletion components/tft/tftspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef _TFTSPI_H_
#define _TFTSPI_H_

#include "tftspi.h"
#include "spi_master_lobo.h"
#include "sdkconfig.h"
#include "stmpe610.h"
Expand Down Expand Up @@ -188,6 +187,39 @@
#define PIN_BCKL_OFF 0 // GPIO value for backlight OFF
//END TTGO T_DISPLAY

#elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 6
//CONFIG FOR TTGO T-WRISTBAND
#define DEFAULT_DISP_TYPE DISP_TYPE_ST7735R
#define DEFAULT_TFT_DISPLAY_WIDTH 80
#define DEFAULT_TFT_DISPLAY_HEIGHT 160

//Need to be defined together so they can be swapped for x;y when rotating
#define TFT_STATIC_WIDTH_OFFSET 26
#define TFT_STATIC_HEIGHT_OFFSET 1

#define DISP_COLOR_BITS_24 0x66
#define DEFAULT_GAMMA_CURVE 0
#define DEFAULT_SPI_CLOCK 27000000
#define TFT_INVERT_ROTATION 0
#define TFT_INVERT_ROTATION1 1
#define TFT_RGB_BGR 0x00
//To be used by user application for initialization
#define TFT_START_COLORS_INVERTED

#define USE_TOUCH TOUCH_TYPE_NONE

#define PIN_NUM_MISO 0 // SPI MISO
#define PIN_NUM_MOSI 19 // SPI MOSI
#define PIN_NUM_CLK 18 // SPI CLOCK pin
#define PIN_NUM_CS 5 // Display CS pin
#define PIN_NUM_DC 23 // Display command/data pin
#define PIN_NUM_TCS 0 // Touch screen CS pin

#define PIN_NUM_RST 26 // GPIO used for RESET control
#define PIN_NUM_BCKL 27 // GPIO used for backlight control
#define PIN_BCKL_ON 1 // GPIO value for backlight ON
#define PIN_BCKL_OFF 0 // GPIO value for backlight OFF
//END TTGO T_DISPLAY
#else

// Configuration for other boards, set the correct values for the display used
Expand Down
6 changes: 3 additions & 3 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void rx_task(void *arg) {
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
uint8_t *data = (uint8_t *)malloc(RX_BUF_SIZE + 1);
while (1) {
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 50 / portTICK_RATE_MS);
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 50 / portTICK_PERIOD_MS);

if (rxBytes > 0) {
for (i = 0; i < rxBytes; i++) {
Expand Down Expand Up @@ -189,7 +189,7 @@ static void display_task(void *arg) {
displayData.pwm_duty[2] = motor_data[M2_CH].pwm_duty; // Update display variable for 3° line
displayData.pwm_duty[3] = motor_data[M3_CH].pwm_duty; // Update display variable for 4° line
update_disp(&displayData);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

Expand Down Expand Up @@ -234,7 +234,7 @@ void app_main() {
// ==== Application configuration ====
lidarBeginStateMachine(&lidarStateMachine); // Initialize Lidar state machinne

vTaskDelay(500 / portTICK_RATE_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
printf("\r\n==============================\r\n");
printf("iOmni, LEANDRO 06/2020\r\n");
printf("==============================\r\n\n");
Expand Down
2 changes: 2 additions & 0 deletions main/rest_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "esp_vfs.h"
#include <fcntl.h>
#include <string.h>
#include <esp_chip_info.h>
#include <esp_random.h>

static const char *REST_TAG = "esp-rest";
#define REST_CHECK(a, str, goto_tag, ...) \
Expand Down
10 changes: 5 additions & 5 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void tft_init() {
ret = spi_lobo_device_deselect(spi);
assert(ret == ESP_OK);

printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(spi));
//printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(spi));
printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(spi) ? "true" : "false");

// ==== Initialize the Display ====
Expand All @@ -126,11 +126,11 @@ void tft_init() {

// ==== Detect maximum read speed ====
tft_max_rdclock = find_rd_speed();
printf("SPI: Max rd speed = %u\r\n", tft_max_rdclock);
//printf("SPI: Max rd speed = %u\r\n", tft_max_rdclock);

// ==== Set SPI clock used for display operations ====
spi_lobo_set_speed(spi, DEFAULT_SPI_CLOCK);
printf("SPI: Changed speed to %u\r\n", spi_lobo_get_speed(spi));
//printf("SPI: Changed speed to %u\r\n", spi_lobo_get_speed(spi));

tft_bg = TFT_BLACK;
tft_font_rotate = 0;
Expand Down Expand Up @@ -200,8 +200,8 @@ void set_PWM_duty(float duty, int channel) {
*
**********************************************************************************************************************/
void GPIO_Init(gpio_config_t io_conf) {
io_conf.intr_type = GPIO_PIN_INTR_DISABLE; // disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_POSEDGE; // interrupt of rising edge
io_conf.intr_type = GPIO_INTR_DISABLE; // disable interrupt
io_conf.intr_type = GPIO_INTR_POSEDGE; // interrupt of rising edge
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL; // bit mask of the pins, use GPIO35/0 here
io_conf.mode = GPIO_MODE_INPUT; // set as input mode
io_conf.pull_up_en = 1; // enable pull-up mode
Expand Down

0 comments on commit 6fd9119

Please sign in to comment.