first commit
This commit is contained in:
commit
e5d9e78985
2 changed files with 386 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
PSRAM !!
|
||||
|
||||
ESP32 - OV2640 - GC9A01A
|
383
firmware/firmware.ino
Normal file
383
firmware/firmware.ino
Normal file
|
@ -0,0 +1,383 @@
|
|||
/* caméra : https://github.com/espressif/esp32-camera
|
||||
* écran : https://github.com/sbcshop/Round-LCD-HAT/blob/main/lib/GC9A01A%20Datasheet.pdf
|
||||
* https://esp32.com/viewtopic.php?t=14376
|
||||
*/
|
||||
|
||||
// TODO refactor / cleanup
|
||||
|
||||
#include <SPI.h>
|
||||
#include "esp_camera.h"
|
||||
|
||||
#define BOARD_ESP32CAM_AITHINKER
|
||||
#define CAMERA_MODEL_AI_THINKER
|
||||
|
||||
#define RST 2
|
||||
#define DC 12
|
||||
#define CS 15
|
||||
#define CLK 14
|
||||
#define MOSI 13
|
||||
|
||||
#define SPI_HZ 62500000
|
||||
#define MY_MODE SPI_MODE3
|
||||
#define MY_BYTE MSBFIRST
|
||||
|
||||
SPIClass *hspi = NULL;
|
||||
camera_config_t my_cam_config;
|
||||
|
||||
int16_t screen[240];
|
||||
int16_t tmp[240];
|
||||
byte test_tmp[480];
|
||||
|
||||
void send_cmd(SPIClass *spi, byte datas) {
|
||||
digitalWrite(DC, LOW);
|
||||
digitalWrite(CS, LOW);
|
||||
spi->beginTransaction(SPISettings(SPI_HZ, MY_BYTE, MY_MODE));
|
||||
spi->transfer(datas);
|
||||
spi->endTransaction();
|
||||
digitalWrite(CS, HIGH);
|
||||
}
|
||||
|
||||
void send_data(SPIClass *spi, byte datas) {
|
||||
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->endTransaction();
|
||||
digitalWrite(CS, HIGH);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
hspi = new SPIClass(HSPI);
|
||||
hspi->begin();
|
||||
|
||||
pinMode(hspi->pinSS(), OUTPUT);
|
||||
pinMode(RST, OUTPUT);
|
||||
pinMode(DC, OUTPUT);
|
||||
|
||||
digitalWrite(RST, HIGH);
|
||||
delay(10);
|
||||
digitalWrite(RST, LOW);
|
||||
delay(10);
|
||||
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_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_cmd(hspi, 0x3A);
|
||||
send_data(hspi, 0x05);
|
||||
//send_data(hspi, 0x66);
|
||||
//send_data(hspi, 0x60);
|
||||
|
||||
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_(hspi, 0x70,COMMAND);
|
||||
send_(hspi, 0x07,PARAM);
|
||||
send_(hspi, 0x07,PARAM);
|
||||
send_(hspi, 0x04,PARAM);
|
||||
send_(hspi, 0x0E,PARAM);
|
||||
send_(hspi, 0x0F,PARAM);
|
||||
send_(hspi, 0x09,PARAM);
|
||||
send_(hspi, 0x07,PARAM);
|
||||
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);
|
||||
|
||||
delay(150);
|
||||
send_cmd(hspi, 0x29);
|
||||
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);
|
||||
|
||||
my_cam_config.ledc_channel = LEDC_CHANNEL_0;
|
||||
my_cam_config.ledc_timer = LEDC_TIMER_0;
|
||||
my_cam_config.pin_d0 = 5;
|
||||
my_cam_config.pin_d1 = 18;
|
||||
my_cam_config.pin_d2 = 19;
|
||||
my_cam_config.pin_d3 = 21;
|
||||
my_cam_config.pin_d4 = 36;
|
||||
my_cam_config.pin_d5 = 39;
|
||||
my_cam_config.pin_d6 = 34;
|
||||
my_cam_config.pin_d7 = 35;
|
||||
my_cam_config.pin_xclk = 0;
|
||||
my_cam_config.pin_pclk = 22;
|
||||
my_cam_config.pin_vsync = 25;
|
||||
my_cam_config.pin_href = 23;
|
||||
my_cam_config.pin_sccb_sda = 26;
|
||||
my_cam_config.pin_sccb_scl = 27;
|
||||
my_cam_config.pin_pwdn = 32;
|
||||
//my_cam_config.xclk_freq_hz = 12000000;
|
||||
my_cam_config.xclk_freq_hz = 20000000;
|
||||
my_cam_config.pin_reset = -1;
|
||||
my_cam_config.pixel_format = PIXFORMAT_RGB565;
|
||||
my_cam_config.frame_size = FRAMESIZE_240X240;
|
||||
//my_cam_config.jpeg_quality = 40;
|
||||
my_cam_config.fb_count = 4;
|
||||
my_cam_config.grab_mode = CAMERA_GRAB_LATEST;
|
||||
|
||||
esp_err_t err = esp_camera_init(&my_cam_config);
|
||||
if (err != ESP_OK) {
|
||||
Serial.printf("Camera init failed with error 0x%x", err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
my_sensor->set_gain_ctrl(my_sensor, 0);
|
||||
my_sensor->set_wpc(my_sensor, 0);
|
||||
my_sensor->set_raw_gma(my_sensor, 0);
|
||||
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 !! =====");
|
||||
|
||||
for(int i = 0; i < 240; i++) {
|
||||
screen[i] = 0x0000;
|
||||
}
|
||||
|
||||
send_cmd(hspi, 0x2C);
|
||||
for (int i= 0; i<240; i++)
|
||||
{
|
||||
memcpy(tmp, screen, 240 * 2);
|
||||
send_buffer(hspi, screen, 240 * 2);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
// TODO check si tout est bon
|
||||
|
||||
send_cmd(hspi, 0x2C);
|
||||
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);
|
||||
}
|
||||
|
||||
esp_camera_fb_return(fb);
|
||||
|
||||
delay(10);
|
||||
}
|
Loading…
Reference in a new issue