@@ -325,6 +325,7 @@ namespace m5gfx
325325 static constexpr int32_t i2c_freq = 400000 ;
326326 static constexpr int_fast16_t aw9523_i2c_addr = 0x58 ; // AW9523B
327327 static constexpr int_fast16_t axp_i2c_addr = 0x34 ; // AXP2101
328+ static constexpr int_fast16_t gc0308_i2c_addr = 0x21 ; // GC0308
328329 static constexpr int_fast16_t i2c_port = I2C_NUM_1;
329330 static constexpr int_fast16_t i2c_sda = GPIO_NUM_12;
330331 static constexpr int_fast16_t i2c_scl = GPIO_NUM_11;
@@ -424,6 +425,26 @@ namespace m5gfx
424425 }
425426 };
426427
428+ struct Light_M5StackAtomS3R : public lgfx ::ILight
429+ {
430+ bool init (uint8_t brightness) override
431+ {
432+ lgfx::i2c::init (i2c_port, GPIO_NUM_45, GPIO_NUM_0);
433+ lgfx::i2c::writeRegister8 (i2c_port, 48 , 0x00 , 0b01000000 , 0 , i2c_freq);
434+ lgfx::delay (1 );
435+ lgfx::i2c::writeRegister8 (i2c_port, 48 , 0x08 , 0b00000001 , 0 , i2c_freq);
436+ lgfx::i2c::writeRegister8 (i2c_port, 48 , 0x70 , 0b00000000 , 0 , i2c_freq);
437+
438+ setBrightness (brightness);
439+ return true ;
440+ }
441+
442+ void setBrightness (uint8_t brightness) override
443+ {
444+ lgfx::i2c::writeRegister8 (i2c_port, 48 , 0x0e , brightness, 0 , i2c_freq);
445+ }
446+ };
447+
427448#endif
428449
429450 __attribute__ ((unused))
@@ -1183,7 +1204,8 @@ namespace m5gfx
11831204 m5gfx::i2c::writeRegister8 (i2c_port, aw9523_i2c_addr, 0x12 , 0b11111111 ); // LEDMODE_P0
11841205 m5gfx::i2c::writeRegister8 (i2c_port, aw9523_i2c_addr, 0x13 , 0b11111111 ); // LEDMODE_P1
11851206 m5gfx::i2c::writeRegister8 (i2c_port, axp_i2c_addr, 0x90 , 0xBF ); // LDOS ON/OFF control 0
1186- m5gfx::i2c::writeRegister8 (i2c_port, axp_i2c_addr, 0x95 , 0x28 ); // ALDO3 set to 3.3v // for TF card slot
1207+ m5gfx::i2c::writeRegister8 (i2c_port, axp_i2c_addr, 0x94 , 33 - 5 ); // ALDO3 set to 3.3v // for GC0308 Camera
1208+ m5gfx::i2c::writeRegister8 (i2c_port, axp_i2c_addr, 0x95 , 33 - 5 ); // ALDO4 set to 3.3v // for TF card slot
11871209
11881210 bus_cfg.pin_mosi = GPIO_NUM_37;
11891211 bus_cfg.pin_miso = GPIO_NUM_35;
@@ -1199,31 +1221,14 @@ namespace m5gfx
11991221 id = _read_panel_id (bus_spi, GPIO_NUM_3);
12001222 if ((id & 0xFF ) == 0xE3 )
12011223 { // check panel (ILI9342)
1202- gpio::pin_backup_t backup_pins[] = { GPIO_NUM_38, GPIO_NUM_45, GPIO_NUM_46 };
1203- auto result = lgfx::gpio::command (
1204- (const uint8_t []) {
1205- lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_38, // CoreS3 = CAM_HREF
1206- lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_45, // CoreS3 = CAM_PCLK
1207- lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_46, // CoreS3 = CAM_VSYNC
1208- lgfx::gpio::command_mode_input_pullup , GPIO_NUM_38,
1209- lgfx::gpio::command_read , GPIO_NUM_38,
1210- lgfx::gpio::command_mode_input_pullup , GPIO_NUM_45,
1211- lgfx::gpio::command_read , GPIO_NUM_45,
1212- lgfx::gpio::command_mode_input_pullup , GPIO_NUM_46,
1213- lgfx::gpio::command_read , GPIO_NUM_46,
1214- lgfx::gpio::command_end
1215- }
1216- );
1217- for (auto &bup : backup_pins) { bup.restore (); }
1218-
1219- // In "CoreS3", even if GPIO38,45,46 are set to Input_pullup, LOW is output.
1220- // This characteristic can be used to distinguish between the two models.
12211224 board = board_t ::board_M5StackCoreS3;
1222- if (result == 0b111 ) {
1225+ // Camera GC0308 check (not found == M5StackCoreS3SE)
1226+ auto chk_gc = lgfx::i2c::readRegister8 (i2c_port, gc0308_i2c_addr, 0x00 , i2c_freq);
1227+ if (chk_gc .has_value () && chk_gc .value () == 0x9b ) {
1228+ ESP_LOGW (LIBRARY_NAME, " [Autodetect] board_M5StackCoreS3" );
1229+ } else {
12231230 board = board_M5StackCoreS3SE;
12241231 ESP_LOGW (LIBRARY_NAME, " [Autodetect] board_M5StackCoreS3SE" );
1225- } else {
1226- ESP_LOGW (LIBRARY_NAME, " [Autodetect] board_M5StackCoreS3" );
12271232 }
12281233 bus_cfg.freq_write = 40000000 ;
12291234 bus_cfg.freq_read = 16000000 ;
@@ -1250,11 +1255,55 @@ namespace m5gfx
12501255 lgfx::i2c::release (i2c_port);
12511256 }
12521257
1258+ if (board == 0 || board == board_t ::board_M5AtomS3R)
1259+ {
1260+ _pin_reset (GPIO_NUM_48, use_reset); // LCD RST
1261+ bus_cfg.pin_mosi = GPIO_NUM_21;
1262+ bus_cfg.pin_miso = (gpio_num_t )-1 ; // GPIO_NUM_NC;
1263+ bus_cfg.pin_sclk = GPIO_NUM_15;
1264+ bus_cfg.pin_dc = GPIO_NUM_42;
1265+ bus_cfg.spi_mode = 0 ;
1266+ bus_cfg.spi_3wire = true ;
1267+ bus_spi->config (bus_cfg);
1268+ bus_spi->init ();
1269+ id = _read_panel_id (bus_spi, GPIO_NUM_14);
1270+ if ((id & 0xFFFFFF ) == 0x079100 )
1271+ { // check panel (GC9107)
1272+ board = board_t ::board_M5AtomS3R;
1273+ ESP_LOGW (LIBRARY_NAME, " [Autodetect] board_M5AtomS3R" );
1274+ bus_spi->release ();
1275+ bus_cfg.spi_host = SPI3_HOST;
1276+ bus_cfg.freq_write = 40000000 ;
1277+ bus_cfg.freq_read = 16000000 ;
1278+ bus_spi->config (bus_cfg);
1279+ bus_spi->init ();
1280+ auto p = new Panel_GC9107 ();
1281+ p->bus (bus_spi);
1282+ {
1283+ auto cfg = p->config ();
1284+ cfg.pin_cs = GPIO_NUM_14;
1285+ cfg.pin_rst = GPIO_NUM_48;
1286+ cfg.panel_width = 128 ;
1287+ cfg.panel_height = 128 ;
1288+ cfg.offset_y = 32 ;
1289+ cfg.readable = false ;
1290+ cfg.bus_shared = false ;
1291+ p->config (cfg);
1292+ }
1293+ _panel_last.reset (p);
1294+ _set_backlight (new Light_M5StackAtomS3R ());
1295+
1296+ goto init_clear;
1297+ }
1298+ lgfx::pinMode (GPIO_NUM_48, lgfx::pin_mode_t ::input); // LCD RST
1299+ bus_spi->release ();
1300+ }
1301+
12531302 if (board == 0 || board == board_t ::board_M5AtomS3)
12541303 {
12551304 _pin_reset (GPIO_NUM_34, use_reset); // LCD RST
12561305 bus_cfg.pin_mosi = GPIO_NUM_21;
1257- bus_cfg.pin_miso = GPIO_NUM_13 ;
1306+ bus_cfg.pin_miso = ( gpio_num_t )- 1 ; // GPIO_NUM_NC ;
12581307 bus_cfg.pin_sclk = GPIO_NUM_17;
12591308 bus_cfg.pin_dc = GPIO_NUM_33;
12601309 bus_cfg.spi_mode = 0 ;
@@ -1586,6 +1635,7 @@ namespace m5gfx
15861635 case board_M5Tough: title = " M5Tough" ; break ;
15871636 case board_M5Station: title = " M5Station" ; break ;
15881637 case board_M5AtomS3: title = " M5AtomS3" ; break ;
1638+ case board_M5AtomS3R: title = " M5AtomS3R" ; break ;
15891639 case board_M5Dial: title = " M5Dial" ; break ;
15901640 case board_M5Cardputer: title = " M5Cardputer" ; break ;
15911641 case board_M5DinMeter: title = " M5DinMeter" ; break ;
@@ -1597,6 +1647,7 @@ namespace m5gfx
15971647
15981648 switch (board) {
15991649 case board_M5AtomS3:
1650+ case board_M5AtomS3R:
16001651 w = 128 ;
16011652 h = 128 ;
16021653 break ;
0 commit comments