Je viens de réussir a afficher le background avec une couleur voulu, seulement, je suis obligé de passer par la fonction Gcmd pour que l'écran fonctionne, seulement l'affichage est très lent (environ 2-3 secondes pour afficher tous les pixel sur l'écran)
J'ai repris la librairie existante pour garder (en suivant l'appel a la fonction background (color))
le code:
#include <SPI.h> // Pour la communication via le port SPI
#define DELAY 0x80
PROGMEM const static unsigned char
Gcmd[] = { // Initialization commands for 7735B screens
19, // 18 commands in list:
0x01, DELAY, // 1: Software reset, no args, w/delay
50, // 50 ms delay
0x11 , DELAY, // 2: Out of sleep mode, no args, w/delay
100, // 255 = 500 ms delay
0x26 , 1, // 3: Set default gamma
0x04, // 16-bit color
0xb1, 2, // 4: Frame Rate
0x0b,
0x14,
0xc0, 2, // 5: VRH1[4:0] & VC[2:0]
0x08,
0x00,
0xc1, 1, // 6: BT[2:0]
0x05,
0xc5, 2, // 7: VMH[6:0] & VML[6:0]
0x41,
0x30,
0xc7, 1, // 8: LCD Driving control
0xc1,
0xEC, 1, // 9: Set pumping color freq
0x1b,
0x3a , 1 + DELAY, // 10: Set color format
0x55, // 16-bit color
100,
0x2a, 4, // 11: Set Column Address
0x00,
0x00,
0x00,
0x7f,
0x2b, 4, // 12: Set Page Address
0x00,
0x00,
0x00,
0x9f,
0x36, 1, // 12+1: Set Scanning Direction
0xc8,
0xb7, 1, // 14: Set Source Output Direciton
0x00,
0xf2, 1, // 15: Enable Gamma bit
0x00,
0xe0, 15 + DELAY, // 16: magic
0x28, 0x24, 0x22, 0x31,
0x2b, 0x0e, 0x53, 0xa5,
0x42, 0x16, 0x18, 0x12,
0x1a, 0x14, 0x03,
50,
0xe1, 15 + DELAY, // 17: more magic
0x17, 0x1b, 0x1d, 0x0e,
0x14, 0x11, 0x2c, 0xa5,
0x3d, 0x09, 0x27, 0x2d,
0x25, 0x2b, 0x3c,
50,
0x13 , DELAY, // 17: Normal display on, no args, w/delay
10, // 10 ms delay
0x29 , DELAY, // 18: Main screen turn on, no args, w/delay
255
}; // 255 = 500 ms delay
const int CS = 7;
const int DC = 6;
const int RST = 5;
void setAddrTFT (uint8_t x0 , uint8_t y0, uint8_t x1, uint8_t y1) {
// Localiser le pixel:
writecmd (0x2A);
writedata (0x00);
writedata (x0);
writedata (0x00);
writedata (x1);
writecmd (0x2B);
writedata (0x00);
writedata (y0);
writedata (0x00);
writedata (y1);
writecmd (0x2C);
}
void writecmd (uint8_t c) {
SPI.beginTransaction(SPISettings(4000000L, MSBFIRST, SPI_MODE0));
digitalWrite(DC, LOW);
digitalWrite(CS, LOW);
SPI.transfer(c);
digitalWrite(CS, LOW);
SPI.endTransaction();
}
void writedata (uint8_t c) {
SPI.beginTransaction(SPISettings(4000000L, MSBFIRST, SPI_MODE0));
digitalWrite(DC, HIGH);
digitalWrite(CS, LOW);
SPI.transfer(c);
digitalWrite(CS, LOW);
SPI.endTransaction();
}
void drawPixel (uint16_t x , uint16_t y , uint16_t color) {
//Serial.print("..drawpixel..");
if ((x < 0) || (x >= 128) || (y < 0) || (y >= 160));
setAddrTFT (x, y, x + 10 , y + 10);
SPI.beginTransaction(SPISettings(4000000L, MSBFIRST, SPI_MODE0));
digitalWrite(DC, HIGH);
digitalWrite(CS, LOW);
SPI.transfer(color >> 8);
SPI.transfer(color);
digitalWrite(CS, LOW);
SPI.endTransaction();
}
void drawLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
for (; y0 <= y1 ; y0++) {
drawPixel (x0, y0, color);
}
}
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
{
drawLine(x, y, x, y + h - 1, color);
}
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
for (int16_t i = x; i < x + w; i++) {
drawFastVLine(i, y, h, color);
}
}
void background (uint16_t color) {
fillRect(0, 0, 120, 150, color);
}
uint16_t newColor(uint8_t r, uint8_t g, uint8_t b)
{
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}
void background(uint8_t red, uint8_t green, uint8_t blue)
{
background(newColor(red, green, blue));
}
void commandList(const uint8_t *addr) {
uint8_t numCommands, numArgs;
uint16_t ms;
numCommands = pgm_read_byte(addr++); // Number of commands to follow
while (numCommands--) { // For each command...
writecmd(pgm_read_byte(addr++)); // Read, issue command
numArgs = pgm_read_byte(addr++); // Number of args to follow
ms = numArgs & DELAY; // If hibit set, delay follows args
numArgs &= ~DELAY; // Mask out delay bit
while (numArgs--) { // For each argument...
writedata(pgm_read_byte(addr++)); // Read, issue argument
}
if (ms) {
ms = pgm_read_byte(addr++); // Read post-command delay time (ms)
if (ms == 255) ms = 500; // If 255, delay for 500 ms
delay(ms);
}
}
}
void setup() {
Serial.begin(9600);
pinMode(CS, OUTPUT);
pinMode(DC, OUTPUT);
pinMode(RST, OUTPUT);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz (half speed)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
digitalWrite(CS, LOW);
digitalWrite(RST, HIGH); //Reset
delay(500);
digitalWrite(RST, LOW);
delay(500);
digitalWrite(RST, HIGH);
delay(500);
commandList(Gcmd);
/* writecmd(0x01); // COMMANDE POUR ACTIVER L ECRAN MAIS NE FONCTIONNE PAS
delay(50);
writecmd(0x11);
delay(500);
writecmd(0x13);
delay(10);
writecmd(0x29);
delay(500);*/
// SPI.beginTransaction(SPISettings(4000000L, MSBFIRST, SPI_MODE0));
//background (0, 25, 0); //bleu
fillRect(0, 0, 128, 160, 0xf0f0);
fillRect(0, 0, 128, 160, 0xFFFF);
// SPI.endTransaction();
Serial.println("..FINISH");
}
void loop() {
// put your main code here, to run repeatedly:
}
J'aimerai initialiser le strick minimum pour que l'écran m'affiche mes pixels, a une vitesse raisonnable, Je vais essayer d'enlever le maximum dans Gcmd