small refactor

This commit is contained in:
rick 2024-05-13 19:58:39 +02:00
parent ab12c27261
commit 87044eca91
Signed by: Rick
GPG key ID: A2E7B6CA577C8F07

View file

@ -21,52 +21,36 @@
#define MY_MODE SPI_MODE3
#define MY_BYTE MSBFIRST
enum type_t { CMD = LOW, DATA = HIGH };
SPIClass *hspi = NULL;
camera_fb_t *fb = NULL;
camera_config_t my_cam_config;
int16_t screen[240];
int16_t tmp[240];
byte test_tmp[480];
uint16_t screen[240];
uint16_t tmp[240];
void send_cmd(SPIClass *spi, byte datas) {
digitalWrite(DC, LOW);
void send_to_screen(SPIClass *spi, byte data, type_t type) {
digitalWrite(DC, type);
digitalWrite(CS, LOW);
spi->beginTransaction(SPISettings(SPI_HZ, MY_BYTE, MY_MODE));
spi->transfer(datas);
spi->transfer(data);
spi->endTransaction();
digitalWrite(CS, HIGH);
}
void send_data(SPIClass *spi, byte datas) {
void send_buffer(SPIClass *spi, uint16_t *data, int size) {
digitalWrite(DC, HIGH);
digitalWrite(CS, LOW);
spi->beginTransaction(SPISettings(SPI_HZ, MY_BYTE, MY_MODE));
spi->transfer(datas);
spi->endTransaction();
digitalWrite(CS, HIGH);
}
void send_buffer(SPIClass *spi, int16_t *datas, int size) {
digitalWrite(DC, HIGH);
digitalWrite(CS, LOW);
spi->beginTransaction(SPISettings(SPI_HZ, MY_BYTE, MY_MODE));
spi->transfer(datas, size);
spi->endTransaction();
digitalWrite(CS, HIGH);
}
void send_buffer_tmp(SPIClass *spi, uint8_t *datas, int size) {
digitalWrite(DC, HIGH);
digitalWrite(CS, LOW);
spi->beginTransaction(SPISettings(SPI_HZ, MY_BYTE, MY_MODE));
spi->transfer(datas, size);
spi->transfer(data, size);
spi->endTransaction();
digitalWrite(CS, HIGH);
}
void setup() {
Serial.begin(9600);
Serial.setDebugOutput(true);
Serial.setDebugOutput(true);
hspi = new SPIClass(HSPI);
hspi->begin();
@ -82,113 +66,113 @@ void setup() {
digitalWrite(RST, HIGH);
delay(20);
send_cmd(hspi, 0xEF);
send_cmd(hspi, 0xEB);
send_data(hspi, 0x14);
send_cmd(hspi, 0xFE);
send_cmd(hspi, 0xEF);
send_cmd(hspi, 0xEB);
send_data(hspi, 0x14);
send_to_screen(hspi, 0xEF, CMD);
send_to_screen(hspi, 0xEB, CMD);
send_to_screen(hspi, 0x14, DATA);
send_to_screen(hspi, 0xFE, CMD);
send_to_screen(hspi, 0xEF, CMD);
send_to_screen(hspi, 0xEB, CMD);
send_to_screen(hspi, 0x14, DATA);
send_cmd(hspi, 0x84);
send_data(hspi, 0x40);
send_cmd(hspi, 0x85);
send_data(hspi, 0xFF);
send_cmd(hspi, 0x86);
send_data(hspi, 0xFF);
send_cmd(hspi, 0x87);
send_data(hspi, 0xFF);
send_cmd(hspi, 0x88);
send_data(hspi, 0x0A);
send_cmd(hspi, 0x89);
send_data(hspi, 0x21);
send_cmd(hspi, 0x8A);
send_data(hspi, 0x00);
send_cmd(hspi, 0x8B);
send_data(hspi, 0x80);
send_cmd(hspi, 0x8C);
send_data(hspi, 0x01);
send_cmd(hspi, 0x8D);
send_data(hspi, 0x01);
send_cmd(hspi, 0x8E);
send_data(hspi, 0xFF);
send_cmd(hspi, 0x8F);
send_data(hspi, 0xFF);
send_cmd(hspi, 0xB6);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_cmd(hspi, 0x36);
send_data(hspi, 0x08);
//send_data(hspi, 0x48);
send_to_screen(hspi, 0x84, CMD);
send_to_screen(hspi, 0x40, DATA);
send_to_screen(hspi, 0x85, CMD);
send_to_screen(hspi, 0xFF, DATA);
send_to_screen(hspi, 0x86, CMD);
send_to_screen(hspi, 0xFF, DATA);
send_to_screen(hspi, 0x87, CMD);
send_to_screen(hspi, 0xFF, DATA);
send_to_screen(hspi, 0x88, CMD);
send_to_screen(hspi, 0x0A, DATA);
send_to_screen(hspi, 0x89, CMD);
send_to_screen(hspi, 0x21, DATA);
send_to_screen(hspi, 0x8A, CMD);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x8B, CMD);
send_to_screen(hspi, 0x80, DATA);
send_to_screen(hspi, 0x8C, CMD);
send_to_screen(hspi, 0x01, DATA);
send_to_screen(hspi, 0x8D, CMD);
send_to_screen(hspi, 0x01, DATA);
send_to_screen(hspi, 0x8E, CMD);
send_to_screen(hspi, 0xFF, DATA);
send_to_screen(hspi, 0x8F, CMD);
send_to_screen(hspi, 0xFF, DATA);
send_to_screen(hspi, 0xB6, CMD);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x36, CMD);
send_to_screen(hspi, 0x08, DATA);
//send_to_screen(hspi, 0x48, DATA);
send_cmd(hspi, 0x3A);
send_data(hspi, 0x05);
//send_data(hspi, 0x66);
//send_data(hspi, 0x60);
send_to_screen(hspi, 0x3A, CMD);
send_to_screen(hspi, 0x05, DATA);
//send_to_screen(hspi, 0x66, DATA);
//send_to_screen(hspi, 0x60, DATA);
send_cmd(hspi, 0x90);
send_data(hspi, 0x08);
send_data(hspi, 0x08);
send_data(hspi, 0x08);
send_data(hspi, 0x08);
send_cmd(hspi, 0xBD);
send_data(hspi, 0x06);
send_cmd(hspi, 0xBC);
send_data(hspi, 0x00);
send_cmd(hspi, 0xFF);
send_data(hspi, 0x60);
send_data(hspi, 0x01);
send_data(hspi, 0x04);
send_cmd(hspi, 0xC3);
send_data(hspi, 0x13);
send_cmd(hspi, 0xC4);
send_data(hspi, 0x13);
send_cmd(hspi, 0xC9);
send_data(hspi, 0x22);
send_cmd(hspi, 0xBE);
send_data(hspi, 0x11);
send_cmd(hspi, 0xE1);
send_data(hspi, 0x10);
send_data(hspi, 0x0E);
send_cmd(hspi, 0xDF);
send_data(hspi, 0x21);
send_data(hspi, 0x0C);
send_data(hspi, 0x02);
send_cmd(hspi, 0xF0);
send_data(hspi, 0x45);
send_data(hspi, 0x09);
send_data(hspi, 0x08);
send_data(hspi, 0x08);
send_data(hspi, 0x26);
send_data(hspi, 0x2A);
send_cmd(hspi, 0xF1);
send_data(hspi, 0x43);
send_data(hspi, 0x70);
send_data(hspi, 0x72);
send_data(hspi, 0x36);
send_data(hspi, 0x37);
send_data(hspi, 0x6F);
send_cmd(hspi, 0xF2);
send_data(hspi, 0x45);
send_data(hspi, 0x09);
send_data(hspi, 0x08);
send_data(hspi, 0x08);
send_data(hspi, 0x26);
send_data(hspi, 0x2A);
send_cmd(hspi, 0xF3);
send_data(hspi, 0x43);
send_data(hspi, 0x70);
send_data(hspi, 0x72);
send_data(hspi, 0x36);
send_data(hspi, 0x37);
send_data(hspi, 0x6F);
send_cmd(hspi, 0xED);
send_data(hspi, 0x1B);
send_data(hspi, 0x0B);
send_cmd(hspi, 0xAE);
send_data(hspi, 0x77);
send_cmd(hspi, 0xCD);
send_data(hspi, 0x63);
send_to_screen(hspi, 0x90, CMD);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0xBD, CMD);
send_to_screen(hspi, 0x06, DATA);
send_to_screen(hspi, 0xBC, CMD);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0xFF, CMD);
send_to_screen(hspi, 0x60, DATA);
send_to_screen(hspi, 0x01, DATA);
send_to_screen(hspi, 0x04, DATA);
send_to_screen(hspi, 0xC3, CMD);
send_to_screen(hspi, 0x13, DATA);
send_to_screen(hspi, 0xC4, CMD);
send_to_screen(hspi, 0x13, DATA);
send_to_screen(hspi, 0xC9, CMD);
send_to_screen(hspi, 0x22, DATA);
send_to_screen(hspi, 0xBE, CMD);
send_to_screen(hspi, 0x11, DATA);
send_to_screen(hspi, 0xE1, CMD);
send_to_screen(hspi, 0x10, DATA);
send_to_screen(hspi, 0x0E, DATA);
send_to_screen(hspi, 0xDF, CMD);
send_to_screen(hspi, 0x21, DATA);
send_to_screen(hspi, 0x0C, DATA);
send_to_screen(hspi, 0x02, DATA);
send_to_screen(hspi, 0xF0, CMD);
send_to_screen(hspi, 0x45, DATA);
send_to_screen(hspi, 0x09, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x26, DATA);
send_to_screen(hspi, 0x2A, DATA);
send_to_screen(hspi, 0xF1, CMD);
send_to_screen(hspi, 0x43, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x72, DATA);
send_to_screen(hspi, 0x36, DATA);
send_to_screen(hspi, 0x37, DATA);
send_to_screen(hspi, 0x6F, DATA);
send_to_screen(hspi, 0xF2, CMD);
send_to_screen(hspi, 0x45, DATA);
send_to_screen(hspi, 0x09, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x08, DATA);
send_to_screen(hspi, 0x26, DATA);
send_to_screen(hspi, 0x2A, DATA);
send_to_screen(hspi, 0xF3, CMD);
send_to_screen(hspi, 0x43, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x72, DATA);
send_to_screen(hspi, 0x36, DATA);
send_to_screen(hspi, 0x37, DATA);
send_to_screen(hspi, 0x6F, DATA);
send_to_screen(hspi, 0xED, CMD);
send_to_screen(hspi, 0x1B, DATA);
send_to_screen(hspi, 0x0B, DATA);
send_to_screen(hspi, 0xAE, CMD);
send_to_screen(hspi, 0x77, DATA);
send_to_screen(hspi, 0xCD, CMD);
send_to_screen(hspi, 0x63, DATA);
/*
send_(hspi, 0x70,COMMAND);
send_(hspi, 0x07,PARAM);
@ -201,93 +185,93 @@ void setup() {
send_(hspi, 0x08,PARAM);
send_(hspi, 0x03,PARAM);
*/
send_cmd(hspi, 0xE8);
send_data(hspi, 0x34);
send_cmd(hspi, 0x62);
send_data(hspi, 0x18);
send_data(hspi, 0x0D);
send_data(hspi, 0x71);
send_data(hspi, 0xED);
send_data(hspi, 0x70);
send_data(hspi, 0x70);
send_data(hspi, 0x18);
send_data(hspi, 0x0F);
send_data(hspi, 0x71);
send_data(hspi, 0xEF);
send_data(hspi, 0x70);
send_data(hspi, 0x70);
send_cmd(hspi, 0x63);
send_data(hspi, 0x18);
send_data(hspi, 0x11);
send_data(hspi, 0x71);
send_data(hspi, 0xF1);
send_data(hspi, 0x70);
send_data(hspi, 0x70);
send_data(hspi, 0x18);
send_data(hspi, 0x13);
send_data(hspi, 0x71);
send_data(hspi, 0xF3);
send_data(hspi, 0x70);
send_data(hspi, 0x70);
send_cmd(hspi, 0x64);
send_data(hspi, 0x28);
send_data(hspi, 0x29);
send_data(hspi, 0xF1);
send_data(hspi, 0x01);
send_data(hspi, 0xF1);
send_data(hspi, 0x00);
send_data(hspi, 0x07);
send_cmd(hspi, 0x66);
send_data(hspi, 0x3C);
send_data(hspi, 0x00);
send_data(hspi, 0xCD);
send_data(hspi, 0x67);
send_data(hspi, 0x45);
send_data(hspi, 0x45);
send_data(hspi, 0x10);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_cmd(hspi, 0x67);
send_data(hspi, 0x00);
send_data(hspi, 0x3C);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0x01);
send_data(hspi, 0x54);
send_data(hspi, 0x10);
send_data(hspi, 0x32);
send_data(hspi, 0x98);
send_cmd(hspi, 0x74);
send_data(hspi, 0x10);
send_data(hspi, 0x85);
send_data(hspi, 0x80);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0x4E);
send_data(hspi, 0x00);
send_cmd(hspi, 0x98);
send_data(hspi, 0x3E);
send_data(hspi, 0x07);
send_cmd(hspi, 0x35);
send_cmd(hspi, 0x21);
send_cmd(hspi, 0x11);
send_to_screen(hspi, 0xE8, CMD);
send_to_screen(hspi, 0x34, DATA);
send_to_screen(hspi, 0x62, CMD);
send_to_screen(hspi, 0x18, DATA);
send_to_screen(hspi, 0x0D, DATA);
send_to_screen(hspi, 0x71, DATA);
send_to_screen(hspi, 0xED, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x18, DATA);
send_to_screen(hspi, 0x0F, DATA);
send_to_screen(hspi, 0x71, DATA);
send_to_screen(hspi, 0xEF, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x63, CMD);
send_to_screen(hspi, 0x18, DATA);
send_to_screen(hspi, 0x11, DATA);
send_to_screen(hspi, 0x71, DATA);
send_to_screen(hspi, 0xF1, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x18, DATA);
send_to_screen(hspi, 0x13, DATA);
send_to_screen(hspi, 0x71, DATA);
send_to_screen(hspi, 0xF3, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x70, DATA);
send_to_screen(hspi, 0x64, CMD);
send_to_screen(hspi, 0x28, DATA);
send_to_screen(hspi, 0x29, DATA);
send_to_screen(hspi, 0xF1, DATA);
send_to_screen(hspi, 0x01, DATA);
send_to_screen(hspi, 0xF1, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x07, DATA);
send_to_screen(hspi, 0x66, CMD);
send_to_screen(hspi, 0x3C, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0xCD, DATA);
send_to_screen(hspi, 0x67, DATA);
send_to_screen(hspi, 0x45, DATA);
send_to_screen(hspi, 0x45, DATA);
send_to_screen(hspi, 0x10, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x67, CMD);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x3C, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x01, DATA);
send_to_screen(hspi, 0x54, DATA);
send_to_screen(hspi, 0x10, DATA);
send_to_screen(hspi, 0x32, DATA);
send_to_screen(hspi, 0x98, DATA);
send_to_screen(hspi, 0x74, CMD);
send_to_screen(hspi, 0x10, DATA);
send_to_screen(hspi, 0x85, DATA);
send_to_screen(hspi, 0x80, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x4E, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x98, CMD);
send_to_screen(hspi, 0x3E, DATA);
send_to_screen(hspi, 0x07, DATA);
send_to_screen(hspi, 0x35, CMD);
send_to_screen(hspi, 0x21, CMD);
send_to_screen(hspi, 0x11, CMD);
delay(150);
send_cmd(hspi, 0x29);
send_to_screen(hspi, 0x29, CMD);
delay(150);
send_cmd(hspi, 0x2A);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0xEF);
send_cmd(hspi, 0x2B);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0x00);
send_data(hspi, 0xEF);
send_to_screen(hspi, 0x2A, CMD);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0xEF, DATA);
send_to_screen(hspi, 0x2B, CMD);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0x00, DATA);
send_to_screen(hspi, 0xEF, DATA);
my_cam_config.ledc_channel = LEDC_CHANNEL_0;
my_cam_config.ledc_timer = LEDC_TIMER_0;
@ -323,7 +307,6 @@ void setup() {
}
sensor_t *my_sensor = esp_camera_sensor_get();
/*
my_sensor->set_whitebal(my_sensor, 0);
my_sensor->set_awb_gain(my_sensor, 0);
my_sensor->set_exposure_ctrl(my_sensor, 0);
@ -333,7 +316,6 @@ void setup() {
my_sensor->set_lenc(my_sensor, 0);
my_sensor->set_dcw(my_sensor, 0);
my_sensor->set_special_effect(my_sensor, 4);
*/
Serial.print("===== fin !! =====");
@ -341,7 +323,7 @@ void setup() {
screen[i] = 0x0000;
}
send_cmd(hspi, 0x2C);
send_to_screen(hspi, 0x2C, CMD);
for (int i= 0; i<240; i++)
{
memcpy(tmp, screen, 240 * 2);
@ -350,34 +332,17 @@ void setup() {
}
void loop() {
/*
for(int i = 0; i < 240; i++) {
screen[i] = 0xFC00;
//screen[i] = 0x00;
//screen[i] = 0x0F;
//screen[i] = 0x07E0;
//screen[i] = 0xFFFF;
}
send_cmd(hspi, 0x2C);
for (int i= 0; i<240; i++)
{
memcpy(tmp, screen, 240 * 2);
send_buffer(hspi, tmp, 240 * 2);
}
*/
camera_fb_t *fb = esp_camera_fb_get();
fb = esp_camera_fb_get();
// TODO check si tout est bon
send_cmd(hspi, 0x2C);
send_to_screen(hspi, 0x2C, CMD);
for (int i= 0; i<240; i++)
{
memcpy(test_tmp, (fb->buf + i * 240 * 2), 240 * 2);
send_buffer_tmp(hspi, test_tmp, 240 * 2);
memcpy(tmp, (fb->buf + (i * 240 * 2)), 240 * 2);
send_buffer(hspi, tmp, 240 * 2);
}
esp_camera_fb_return(fb);
delay(10);
delay(5);
}