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