Вт сен 26, 2017 19:46:56
Чт май 31, 2018 13:12:04
Вт июн 05, 2018 14:27:18
Пт июн 29, 2018 08:58:18
Пт авг 28, 2020 10:23:42
Пн мар 18, 2024 22:27:04
enum class Cmd : std::int8_t {
eNOP = LCD_CMD_NOP, //0x00 This command is empty command
eSWRESET = LCD_CMD_SWRESET, //0x01 Software reset registers (the built-in frame buffer is not affected)
eRDDID = LCD_CMD_RDDID, //0x04 Read 24-bit display ID
eRDDST = LCD_CMD_RDDST, //0x09 Read display status
eRDDPM = LCD_CMD_RDDPM, //0x0A Read display power mode
eRDD_MADCTL = LCD_CMD_RDD_MADCTL, //0x0B Read display MADCTL
eRDD_COLMOD = LCD_CMD_RDD_COLMOD, //0x0C Read display pixel format
eRDDIM = LCD_CMD_RDDIM, //0x0D Read display image mode
eRDDSM = LCD_CMD_RDDSM, //0x0E Read display signal mode
eRDDSR = LCD_CMD_RDDSR, //0x0F Read display self-diagnostic result
eSLPIN = LCD_CMD_SLPIN, //0x10 Go into sleep mode (DC/DC, oscillator, scanning stopped, but memory keeps content)
eSLPOUT = LCD_CMD_SLPOUT, //0x11 Exit sleep mode
ePTLON = LCD_CMD_PTLON, //0x12 Turns on partial display mode
eNORON = LCD_CMD_NORON, //0x13 Turns on normal display mode
eINVOFF = LCD_CMD_INVOFF, //0x20 Recover from display inversion mode
eINVON = LCD_CMD_INVON, //0x21 Go into display inversion mode
eGAMSET = LCD_CMD_GAMSET, //0x26 Select Gamma curve for current display
eDISPOFF = LCD_CMD_DISPOFF, //0x28 Display off (disable frame buffer output)
eDISPON = LCD_CMD_DISPON, //0x29 Display on (enable frame buffer output)
eCASET = LCD_CMD_CASET, //0x2A Set column address
eRASET = LCD_CMD_RASET, //0x2B Set row address
eRAMWR = LCD_CMD_RAMWR, //0x2C Write frame memory
eRAMRD = LCD_CMD_RAMRD, //0x2E Read frame memory
ePTLAR = LCD_CMD_PTLAR, //0x30 Define the partial area
eVSCRDEF = LCD_CMD_VSCRDEF, //0x33 Vertical scrolling definition
eTEOFF = LCD_CMD_TEOFF, //0x34 Turns off tearing effect
eTEON = LCD_CMD_TEON, //0x35 Turns on tearing effect
eMADCTL = LCD_CMD_MADCTL, //0x36 Memory data access control
eVSCSAD = LCD_CMD_VSCSAD, //0x37 Vertical scroll start address
eIDMOFF = LCD_CMD_IDMOFF, //0x38 Recover from IDLE mode
eIDMON = LCD_CMD_IDMON, //0x39 Fall into IDLE mode (8 color depth is displayed)
eCOLMOD = LCD_CMD_COLMOD, //0x3A Defines the format of RGB picture data
eRAMWRC = LCD_CMD_RAMWRC, //0x3C Memory write continue
eRAMRDC = LCD_CMD_RAMRDC, //0x3E Memory read continue
eSTE = LCD_CMD_STE, //0x44 Set tear scan line, tearing effect output signal when display module reaches line N
eGDCAN = LCD_CMD_GDCAN, //0x45 Get scan line
eWRDISBV = LCD_CMD_WRDISBV, //0x51 Write display brightness
eRDDISBV = LCD_CMD_RDDISBV //0x52 Read display brightness value
};
enum class MadCtlBits : std::int16_t {
eMH = LCD_CMD_MH_BIT, // Display data latch order, 0: refresh left to right, 1: refresh right to left
eBGR = LCD_CMD_BGR_BIT, // RGB/BGR order, 0: RGB, 1: BGR
eML = LCD_CMD_ML_BIT, // Line address order, 0: refresh top to bottom, 1: refresh bottom to top
eMV = LCD_CMD_MV_BIT, // Row/Column order, 0: normal mode, 1: reverse mode
eMX = LCD_CMD_MX_BIT, // Column address order, 0: left to right, 1: right to left
eMY = LCD_CMD_MY_BIT, // Row address order, 0: top to bottom, 1: bottom to top
};
enum class ColorMode : std::int8_t {
e8BIT = 2,
e12BIT = 3,
e16BIT = 5,
e24BIT = 7,
};
struct alignas( 32 ) Status {
std::uint8_t ST24 : 1;
std::uint8_t MH : 1;
std::uint8_t RGB : 1;
std::uint8_t ML : 1;
std::uint8_t MV : 1;
std::uint8_t MX : 1;
std::uint8_t MY : 1;
std::uint8_t BOTSON : 1;
std::uint8_t NORON : 1;
std::uint8_t SLOUT : 1;
std::uint8_t PTLON : 1;
std::uint8_t IDMON : 1;
std::uint8_t IFPF : 3;
std::uint8_t ST23 : 1;
std::uint8_t GCS2 : 1;
std::uint8_t TEON : 1;
std::uint8_t DISON : 1;
std::uint8_t ST11 : 1;
std::uint8_t ST12 : 1;
std::uint8_t INVON : 1;
std::uint8_t ST14 : 1;
std::uint8_t VSSON : 1;
std::uint8_t ST0 : 1;
std::uint8_t DEON : 1;
std::uint8_t PCKON : 1;
std::uint8_t VSON : 1;
std::uint8_t HSON : 1;
std::uint8_t TELOM : 1;
std::uint8_t GCS0 : 1;
std::uint8_t GCS1 : 1;
};
using Id = union {
struct {
uint8_t ID1;
uint8_t ID2;
uint8_t ID3;
};
uint8_t ID[ 3 ];
};
static Status readStatus() {
constexpr auto rawSize = sizeof( Status );
std::array< std::uint8_t, rawSize > statusRaw {};
Driver::send_command( std::to_underlying( Cmd::eRDDST ) );
Driver::bus::read_raw( statusRaw.begin(), rawSize );
std::cout << "Status size is " << rawSize << " : ";
std::cout << ( int ) *statusRaw.data() << std::endl;
return reinterpret_cast< Status & >( statusRaw );
}
static Id readId() {
Id id {};
Driver::send_command( std::to_underlying( Cmd::eRDDID ) );
Driver::bus::read_raw( id.ID, 3 );
return id;
}
static void init() {
std::cout << "Initialize\n";
auto initStatus = Driver::initialize();
std::cout << "Initialize is " << initStatus << std::endl;
LcdCom::Status status;
std::cout << "SW reset\n";
Driver::send_command( std::to_underlying( LcdCommon::Cmd::eSWRESET ) );
delay( 50 );
do {
status = LcdCom::readStatus();
delay( 50 );
} while ( !status.NORON );
const auto id = LcdCom::readId();
const std::int32_t idRes = ( static_cast< std::int32_t >( id.ID1 ) << 16 ) |
( static_cast< std::int32_t >( id.ID2 ) << 8 ) |
( static_cast< std::int32_t >( id.ID3 ) );
std::cout << "Display id is: " << std::hex << idRes << std::endl;
}
regSet( 0x11, 0x0014 );
Вт мар 19, 2024 22:22:25
Ср мар 20, 2024 07:09:12
template < LcdDriveType DriverType > class Lcd {
public:
using Driver = DriverType;
struct alignas( 32 ) Status {
std::uint8_t ST24 : 1;
std::uint8_t MH : 1;
std::uint8_t RGB : 1;
std::uint8_t ML : 1;
std::uint8_t MV : 1;
std::uint8_t MX : 1;
std::uint8_t MY : 1;
std::uint8_t BOTSON : 1;
std::uint8_t NORON : 1;
std::uint8_t SLOUT : 1;
std::uint8_t PTLON : 1;
std::uint8_t IDMON : 1;
std::uint8_t IFPF : 3;
std::uint8_t ST23 : 1;
std::uint8_t GCS2 : 1;
std::uint8_t TEON : 1;
std::uint8_t DISON : 1;
std::uint8_t ST11 : 1;
std::uint8_t ST12 : 1;
std::uint8_t INVON : 1;
std::uint8_t ST14 : 1;
std::uint8_t VSSON : 1;
std::uint8_t ST0 : 1;
std::uint8_t DEON : 1;
std::uint8_t PCKON : 1;
std::uint8_t VSON : 1;
std::uint8_t HSON : 1;
std::uint8_t TELOM : 1;
std::uint8_t GCS0 : 1;
std::uint8_t GCS1 : 1;
};
using Id = union {
struct {
uint8_t ID1;
uint8_t ID2;
uint8_t ID3;
};
uint8_t ID[ 3 ];
};
static void reset() { Driver::send_command( std::to_underlying( LcdCommon::Cmd::eSWRESET ) ); }
static Status readStatus() {
constexpr auto rawSize = sizeof( Status );
std::array< std::uint8_t, rawSize > statusRaw {};
Driver::send_command( std::to_underlying( Cmd::eRDDST ) );
Driver::bus::read_raw( statusRaw.begin(), rawSize );
std::cout << "Status size is " << rawSize << " : ";
std::cout << ( int ) *statusRaw.data() << std::endl;
return reinterpret_cast< Status & >( statusRaw );
}
static Id readId() {
Id id {};
Driver::send_command( std::to_underlying( Cmd::eRDDID ) );
Driver::bus::read_raw( id.ID, 3 );
return id;
}
static void setRamArea( Math::Rect rect ) {
Driver::send_command( std::to_underlying( Cmd::eCASET ) );
Driver::send_data8( rect.offset.x );
Driver::send_data8( rect.extent.width );
Driver::send_command( std::to_underlying( Cmd::eRASET ) );
Driver::send_data8( rect.offset.y );
Driver::send_data8( rect.extent.height );
}
static void setAddressMode( uint8_t mx, uint8_t my, uint8_t mv, uint8_t ml, uint8_t bgr, uint8_t mh ) {
Driver::send_command( std::to_underlying( Cmd::eMADCTL ) );
Driver::send_data8( ( ( mx ? 1 : 0 ) << 7 ) | ( ( my ? 1 : 0 ) << 6 ) | ( ( mv ? 1 : 0 ) << 5 ) |
( ( ml ? 1 : 0 ) << 4 ) | ( ( bgr ? 1 : 0 ) << 3 ) | ( ( ml ? 1 : 0 ) << 2 ) );
}
static void sleepin() {
Driver::send_command( std::to_underlying( Cmd::eSLPIN ) );
std::cout << "LCD sleep on\n";
}
static void sleepout() {
Driver::send_command( std::to_underlying( Cmd::eSLPOUT ) );
std::cout << "LCD sleep off\n";
}
static void enable() {
Driver::send_command( std::to_underlying( Cmd::eDISPON ) );
std::cout << "LCD enabled\n";
}
static void disable() {
Driver::send_command( std::to_underlying( Cmd::eDISPOFF ) );
std::cout << "LCD disabled\n";
}
static void writeRamStartContinue() { Driver::send_command( std::to_underlying( Cmd::eRAMWRC ) ); }
static void writeRamStart() { Driver::send_command( std::to_underlying( Cmd::eRAMWR ) ); }
static void setColorMode( ColorMode mode ) {
Driver::send_command( std::to_underlying( Cmd::eCOLMOD ) );
Driver::send_data8( std::to_underlying( mode ) );
}
static void regSet( Cmd cmd, std::uint16_t data ) {
Driver::send_command( std::to_underlying( cmd ) );
Driver::send_data16( data );
}
static void regSet( std::uint8_t cmd, std::uint16_t data ) {
Driver::send_command( cmd );
Driver::send_data16( data );
}
};
static void Lcd::init() {
std::cout << "Initialize\n";
auto initStatus = Driver::initialize();
std::cout << "Initialize is " << initStatus << std::endl;
LcdCom::Status status;
delay( 100 );
std::cout << "SW reset\n";
Driver::send_command( std::to_underlying( LcdCommon::Cmd::eSWRESET ) );
delay( 500 );
do {
status = LcdCom::readStatus();
delay( 100 );
} while ( !status.NORON );
const auto id = LcdCom::readId();
const std::int32_t idRes = ( static_cast< std::int32_t >( id.ID1 ) << 16 ) |
( static_cast< std::int32_t >( id.ID2 ) << 8 ) |
( static_cast< std::int32_t >( id.ID3 ) );
std::cout << "Display id is: " << std::hex << idRes << std::endl;
LcdCom::sleepout();
delay( 100 );
}
void setup() {
init();
Lcd::init();
Lcd::LcdCom::setColorMode( Lcd::ColorMode::e8BIT );
std::cout << "Test pint 1\n";
delay( 100 );
Lcd::LcdCom::setRamArea( Math::Rect { { 0, 0 }, { Lcd::width - 1, Lcd::height - 1 } } );
std::cout << "Test pint 2\n";
delay( 100 );
Lcd::LcdCom::setAddressMode( 0, 0, 0, 0, 0, 0 );
std::cout << "Test pint 3\n";
delay( 100 );
Lcd::LcdCom::enable();
std::cout << "Test pint 4\n";
delay( 100 );
Lcd::LcdCom::writeRamStart();
delay( 100 );
while ( 1 ) {
for ( int y = 0; y < 58; ++y ) {
for ( int x = 0; x < 132; ++x ) {
Lcd::sendRgb24( 0xFF0000 );
}
}
for ( int y = 58; y < 58 + 58; ++y ) {
for ( int x = 0; x < 132; ++x ) {
Lcd::sendRgb24( 0x00FF00 );
}
}
for ( int y = 58 + 58; y < 176; ++y ) {
for ( int x = 0; x < 132; ++x ) {
Lcd::sendRgb24( 0x0000FF );
}
}
}
}
Status size is 32 : 9
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
Initialize
Initialize is 1
SW reset
Status size is 32 : 151587081
Display id is: 40404
LCD sleep off
Test pint 1
Test pint 2
Test pint 3
LCD enabled
Test pint 4
Ср мар 20, 2024 22:24:23