mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-05-16 10:15:32 +01:00
applied platformio structure
This commit is contained in:
128
lib/display/core/ifaces/default_if_i2c.c
Normal file
128
lib/display/core/ifaces/default_if_i2c.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Copyright (c) 2017-2018 Tara Keeling
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <driver/i2c.h>
|
||||
#include <driver/gpio.h>
|
||||
#include "gds.h"
|
||||
#include "gds_err.h"
|
||||
#include "gds_private.h"
|
||||
#include "gds_default_if.h"
|
||||
|
||||
static int I2CPortNumber;
|
||||
static int I2CWait;
|
||||
|
||||
static const int GDS_I2C_COMMAND_MODE = 0x80;
|
||||
static const int GDS_I2C_DATA_MODE = 0x40;
|
||||
|
||||
static bool I2CDefaultWriteBytes( int Address, bool IsCommand, const uint8_t* Data, size_t DataLength );
|
||||
static bool I2CDefaultWriteCommand( struct GDS_Device* Device, uint8_t Command );
|
||||
static bool I2CDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength );
|
||||
|
||||
/*
|
||||
* Initializes the i2c master with the parameters specified
|
||||
* in the component configuration in sdkconfig.h.
|
||||
*
|
||||
* Returns true on successful init of the i2c bus.
|
||||
*/
|
||||
bool GDS_I2CInit( int PortNumber, int SDA, int SCL, int Speed ) {
|
||||
I2CPortNumber = PortNumber;
|
||||
|
||||
I2CWait = pdMS_TO_TICKS( Speed ? (250 * 250000) / Speed : 250 );
|
||||
|
||||
if (SDA != -1 && SCL != -1) {
|
||||
i2c_config_t Config = { 0 };
|
||||
|
||||
Config.mode = I2C_MODE_MASTER;
|
||||
Config.sda_io_num = SDA;
|
||||
Config.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
||||
Config.scl_io_num = SCL;
|
||||
Config.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
||||
Config.master.clk_speed = Speed ? Speed : 400000;
|
||||
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_param_config( I2CPortNumber, &Config ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_driver_install( I2CPortNumber, Config.mode, 0, 0, 0 ), return false );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attaches a display to the I2C bus using default communication functions.
|
||||
*
|
||||
* Params:
|
||||
* Device: Pointer to your GDS_Device object
|
||||
* Width: Width of display
|
||||
* Height: Height of display
|
||||
* I2CAddress: Address of your display
|
||||
* RSTPin: Optional GPIO pin to use for hardware reset, if none pass -1 for this parameter.
|
||||
*
|
||||
* Returns true on successful init of display.
|
||||
*/
|
||||
bool GDS_I2CAttachDevice( struct GDS_Device* Device, int Width, int Height, int I2CAddress, int RSTPin, int BacklightPin ) {
|
||||
NullCheck( Device, return false );
|
||||
|
||||
Device->WriteCommand = I2CDefaultWriteCommand;
|
||||
Device->WriteData = I2CDefaultWriteData;
|
||||
Device->Address = I2CAddress;
|
||||
Device->RSTPin = RSTPin;
|
||||
Device->Backlight.Pin = BacklightPin;
|
||||
Device->IF = GDS_IF_I2C;
|
||||
Device->Width = Device->TextWidth = Width;
|
||||
Device->Height = Height;
|
||||
|
||||
if ( RSTPin >= 0 ) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( RSTPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( RSTPin, 1 ), return false );
|
||||
GDS_Reset( Device );
|
||||
}
|
||||
|
||||
return GDS_Init( Device );
|
||||
}
|
||||
|
||||
static bool I2CDefaultWriteBytes( int Address, bool IsCommand, const uint8_t* Data, size_t DataLength ) {
|
||||
i2c_cmd_handle_t* CommandHandle = NULL;
|
||||
static uint8_t ModeByte = 0;
|
||||
|
||||
NullCheck( Data, return false );
|
||||
|
||||
if ( ( CommandHandle = i2c_cmd_link_create( ) ) != NULL ) {
|
||||
ModeByte = ( IsCommand == true ) ? GDS_I2C_COMMAND_MODE: GDS_I2C_DATA_MODE;
|
||||
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_master_start( CommandHandle ), goto error );
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_master_write_byte( CommandHandle, ( Address << 1 ) | I2C_MASTER_WRITE, true ), goto error );
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_master_write_byte( CommandHandle, ModeByte, true ), goto error );
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_master_write( CommandHandle, ( uint8_t* ) Data, DataLength, true ), goto error );
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_master_stop( CommandHandle ), goto error );
|
||||
|
||||
ESP_ERROR_CHECK_NONFATAL( i2c_master_cmd_begin( I2CPortNumber, CommandHandle, I2CWait ), goto error );
|
||||
i2c_cmd_link_delete( CommandHandle );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
if (CommandHandle) i2c_cmd_link_delete( CommandHandle );
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool I2CDefaultWriteCommand( struct GDS_Device* Device, uint8_t Command ) {
|
||||
uint8_t CommandByte = ( uint8_t ) Command;
|
||||
|
||||
NullCheck( Device, return false );
|
||||
return I2CDefaultWriteBytes( Device->Address, true, ( const uint8_t* ) &CommandByte, 1 );
|
||||
}
|
||||
|
||||
static bool I2CDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength ) {
|
||||
NullCheck( Device, return false );
|
||||
NullCheck( Data, return false );
|
||||
|
||||
return I2CDefaultWriteBytes( Device->Address, false, Data, DataLength );
|
||||
}
|
||||
161
lib/display/core/ifaces/default_if_qspi.c
Normal file
161
lib/display/core/ifaces/default_if_qspi.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* QSPI Interface for Guition JC4827W543C ILI9488 Display
|
||||
* Supports ESP32-S3 QSPI peripheral
|
||||
*
|
||||
* (c) Guition Support 2026
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <driver/spi_master.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <freertos/task.h>
|
||||
#include "gds.h"
|
||||
#include "gds_err.h"
|
||||
#include "gds_private.h"
|
||||
#include "gds_default_if.h"
|
||||
|
||||
static const int GDS_QSPI_Command_Mode = 0;
|
||||
static const int GDS_QSPI_Data_Mode = 1;
|
||||
|
||||
static spi_host_device_t QSPIHost;
|
||||
static int DCPin;
|
||||
|
||||
static bool QSPIDefaultWriteBytes( spi_device_handle_t QSPIHandle, int WriteMode, const uint8_t* Data, size_t DataLength );
|
||||
static bool QSPIDefaultWriteCommand( struct GDS_Device* Device, uint8_t Command );
|
||||
static bool QSPIDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength );
|
||||
|
||||
bool GDS_QSPIInit( int QSPI, int DC ) {
|
||||
QSPIHost = QSPI;
|
||||
DCPin = DC;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GDS_QSPIAttachDevice( struct GDS_Device* Device, int Width, int Height, int CSPin, int RSTPin, int BackLightPin, int Speed, int Mode ) {
|
||||
spi_device_interface_config_t QSPIDeviceConfig = { };
|
||||
spi_device_handle_t QSPIDevice;
|
||||
|
||||
NullCheck( Device, return false );
|
||||
|
||||
if (CSPin >= 0) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( CSPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( CSPin, 0 ), return false );
|
||||
}
|
||||
|
||||
QSPIDeviceConfig.clock_speed_hz = Speed > 0 ? Speed : SPI_MASTER_FREQ_20M;
|
||||
QSPIDeviceConfig.spics_io_num = CSPin;
|
||||
QSPIDeviceConfig.queue_size = 4;
|
||||
QSPIDeviceConfig.mode = Mode;
|
||||
QSPIDeviceConfig.flags = SPI_DEVICE_HALFDUPLEX;
|
||||
QSPIDeviceConfig.duty_cycle_pos = 128; // 50% duty cycle
|
||||
|
||||
// QSPI specific configuration for ESP32-S3
|
||||
QSPIDeviceConfig.command_bits = 8;
|
||||
QSPIDeviceConfig.address_bits = 24;
|
||||
QSPIDeviceConfig.address_len = 3;
|
||||
|
||||
if( spi_bus_add_device( QSPIHost, &QSPIDeviceConfig, &QSPIDevice ) != ESP_OK ) {
|
||||
GDS_LOG_ERROR( "Failed to add QSPI device to host" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( DCPin >= 0 ) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( DCPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( DCPin, 1 ), return false );
|
||||
}
|
||||
|
||||
if( RSTPin >= 0 ) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( RSTPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( RSTPin, 1 ), return false );
|
||||
}
|
||||
|
||||
if( BackLightPin >= 0 ) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( BackLightPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( BackLightPin, 1 ), return false );
|
||||
}
|
||||
|
||||
Device->WriteCommand = QSPIDefaultWriteCommand;
|
||||
Device->WriteData = QSPIDefaultWriteData;
|
||||
Device->DeviceHandle = QSPIDevice;
|
||||
|
||||
// Hardware reset if pin is available
|
||||
if( RSTPin >= 0 ) {
|
||||
gpio_set_level( RSTPin, 0 );
|
||||
vTaskDelay( pdMS_TO_TICKS( 10 ) );
|
||||
gpio_set_level( RSTPin, 1 );
|
||||
vTaskDelay( pdMS_TO_TICKS( 120 ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool QSPIDefaultWriteCommand( struct GDS_Device* Device, uint8_t Command ) {
|
||||
return QSPIDefaultWriteBytes( Device->DeviceHandle, GDS_QSPI_Command_Mode, &Command, 1 );
|
||||
}
|
||||
|
||||
static bool QSPIDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength ) {
|
||||
if( DCPin >= 0 ) {
|
||||
gpio_set_level( DCPin, 1 );
|
||||
}
|
||||
|
||||
bool Result = QSPIDefaultWriteBytes( Device->DeviceHandle, GDS_QSPI_Data_Mode, Data, DataLength );
|
||||
|
||||
if( DCPin >= 0 ) {
|
||||
gpio_set_level( DCPin, 0 );
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
static bool QSPIDefaultWriteBytes( spi_device_handle_t QSPIHandle, int WriteMode, const uint8_t* Data, size_t DataLength ) {
|
||||
spi_transaction_ext_t SPITransaction = { };
|
||||
SPITransaction.base.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR | SPI_TRANS_VARIABLE_DUMMY;
|
||||
SPITransaction.base.cmd = 0;
|
||||
SPITransaction.base.addr = 0;
|
||||
SPITransaction.base.length = DataLength * 8;
|
||||
SPITransaction.base.tx_buffer = Data;
|
||||
SPITransaction.base.rx_buffer = NULL;
|
||||
SPITransaction.command_bits = 8;
|
||||
SPITransaction.address_bits = 0;
|
||||
SPITransaction.dummy_bits = 0;
|
||||
|
||||
if( WriteMode == GDS_QSPI_Command_Mode ) {
|
||||
SPITransaction.command_bits = 8;
|
||||
SPITransaction.base.cmd = Data[0];
|
||||
SPITransaction.base.length = 0;
|
||||
SPITransaction.base.tx_buffer = NULL;
|
||||
}
|
||||
|
||||
if( spi_device_transmit( QSPIHandle, (spi_transaction_t*) &SPITransaction ) != ESP_OK ) {
|
||||
GDS_LOG_ERROR( "QSPI transaction failed" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GDS_QSPIBusInit( int MOSIPin, int MISOPin, int CLKPin, int Host ) {
|
||||
spi_bus_config_t BusConfig = { };
|
||||
|
||||
NullCheck( Host >= SPI2_HOST && Host <= SPI3_HOST, return false );
|
||||
|
||||
// QSPI pin configuration for ESP32-S3
|
||||
BusConfig.mosi_io_num = MOSIPin;
|
||||
BusConfig.miso_io_num = MISOPin;
|
||||
BusConfig.sclk_io_num = CLKPin;
|
||||
BusConfig.quadwp_io_num = -1; // Not used for ILI9488
|
||||
BusConfig.quadhd_io_num = -1; // Not used for ILI9488
|
||||
BusConfig.max_transfer_sz = 65536;
|
||||
BusConfig.flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_NATIVE_PINS;
|
||||
|
||||
if( spi_bus_initialize( Host, &BusConfig, DMA_CH_AUTO ) != ESP_OK ) {
|
||||
GDS_LOG_ERROR( "Failed to initialize QSPI bus" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
119
lib/display/core/ifaces/default_if_spi.c
Normal file
119
lib/display/core/ifaces/default_if_spi.c
Normal file
@@ -0,0 +1,119 @@
|
||||
|
||||
/**
|
||||
* Copyright (c) 2017-2018 Tara Keeling
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <driver/spi_master.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <freertos/task.h>
|
||||
#include "gds.h"
|
||||
#include "gds_err.h"
|
||||
#include "gds_private.h"
|
||||
#include "gds_default_if.h"
|
||||
|
||||
static const int GDS_SPI_Command_Mode = 0;
|
||||
static const int GDS_SPI_Data_Mode = 1;
|
||||
|
||||
static spi_host_device_t SPIHost;
|
||||
static int DCPin;
|
||||
|
||||
static bool SPIDefaultWriteBytes( spi_device_handle_t SPIHandle, int WriteMode, const uint8_t* Data, size_t DataLength );
|
||||
static bool SPIDefaultWriteCommand( struct GDS_Device* Device, uint8_t Command );
|
||||
static bool SPIDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength );
|
||||
|
||||
bool GDS_SPIInit( int SPI, int DC ) {
|
||||
SPIHost = SPI;
|
||||
DCPin = DC;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GDS_SPIAttachDevice( struct GDS_Device* Device, int Width, int Height, int CSPin, int RSTPin, int BackLightPin, int Speed, int Mode ) {
|
||||
spi_device_interface_config_t SPIDeviceConfig = { };
|
||||
spi_device_handle_t SPIDevice;
|
||||
|
||||
NullCheck( Device, return false );
|
||||
|
||||
if (CSPin >= 0) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( CSPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( CSPin, 0 ), return false );
|
||||
}
|
||||
|
||||
SPIDeviceConfig.clock_speed_hz = Speed > 0 ? Speed : SPI_MASTER_FREQ_8M;
|
||||
SPIDeviceConfig.spics_io_num = CSPin;
|
||||
SPIDeviceConfig.queue_size = 1;
|
||||
SPIDeviceConfig.mode = Mode;
|
||||
SPIDeviceConfig.flags = SPI_DEVICE_NO_DUMMY;
|
||||
if (Device->SPIParams) Device->SPIParams(SPIDeviceConfig.clock_speed_hz, &SPIDeviceConfig.mode,
|
||||
&SPIDeviceConfig.cs_ena_pretrans, &SPIDeviceConfig.cs_ena_posttrans);
|
||||
|
||||
ESP_ERROR_CHECK_NONFATAL( spi_bus_add_device( SPIHost, &SPIDeviceConfig, &SPIDevice ), return false );
|
||||
|
||||
Device->WriteCommand = SPIDefaultWriteCommand;
|
||||
Device->WriteData = SPIDefaultWriteData;
|
||||
Device->SPIHandle = SPIDevice;
|
||||
Device->RSTPin = RSTPin;
|
||||
Device->CSPin = CSPin;
|
||||
Device->Backlight.Pin = BackLightPin;
|
||||
Device->IF = GDS_IF_SPI;
|
||||
Device->Width = Device->TextWidth = Width;
|
||||
Device->Height = Height;
|
||||
|
||||
if ( RSTPin >= 0 ) {
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_direction( RSTPin, GPIO_MODE_OUTPUT ), return false );
|
||||
ESP_ERROR_CHECK_NONFATAL( gpio_set_level( RSTPin, 0 ), return false );
|
||||
GDS_Reset( Device );
|
||||
}
|
||||
|
||||
return GDS_Init( Device );
|
||||
}
|
||||
|
||||
static bool SPIDefaultWriteBytes( spi_device_handle_t SPIHandle, int WriteMode, const uint8_t* Data, size_t DataLength ) {
|
||||
spi_transaction_t SPITransaction = { };
|
||||
|
||||
NullCheck( SPIHandle, return false );
|
||||
NullCheck( Data, return false );
|
||||
|
||||
if ( DataLength > 0 ) {
|
||||
gpio_set_level( DCPin, WriteMode );
|
||||
|
||||
SPITransaction.length = DataLength * 8;
|
||||
|
||||
if (DataLength <= 4) {
|
||||
SPITransaction.flags = SPI_TRANS_USE_TXDATA;
|
||||
SPITransaction.tx_data[0] = *Data++; SPITransaction.tx_data[1] = *Data++;
|
||||
SPITransaction.tx_data[2] = *Data++; SPITransaction.tx_data[3] = *Data;
|
||||
} else {
|
||||
SPITransaction.tx_buffer = Data;
|
||||
}
|
||||
|
||||
// only do polling as we don't have contention on SPI (otherwise DMA for transfers > 16 bytes)
|
||||
ESP_ERROR_CHECK_NONFATAL( spi_device_polling_transmit(SPIHandle, &SPITransaction), return false );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SPIDefaultWriteCommand( struct GDS_Device* Device, uint8_t Command ) {
|
||||
static uint8_t CommandByte = 0;
|
||||
|
||||
NullCheck( Device, return false );
|
||||
NullCheck( Device->SPIHandle, return false );
|
||||
|
||||
CommandByte = Command;
|
||||
|
||||
return SPIDefaultWriteBytes( Device->SPIHandle, GDS_SPI_Command_Mode, &CommandByte, 1 );
|
||||
}
|
||||
|
||||
static bool SPIDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength ) {
|
||||
NullCheck( Device, return false );
|
||||
NullCheck( Device->SPIHandle, return false );
|
||||
|
||||
return SPIDefaultWriteBytes( Device->SPIHandle, GDS_SPI_Data_Mode, Data, DataLength );
|
||||
}
|
||||
Reference in New Issue
Block a user