|
14 | 14 | #include <soc/gpio_reg.h> |
15 | 15 |
|
16 | 16 | #include "lgfx/v1/panel/Panel_ILI9342.hpp" |
| 17 | +#include "lgfx/v1/panel/Panel_SSD1306.hpp" |
17 | 18 | #include "lgfx/v1/panel/Panel_ST7735.hpp" |
18 | 19 | #include "lgfx/v1/panel/Panel_ST7789.hpp" |
19 | 20 | #include "lgfx/v1/panel/Panel_GC9A01.hpp" |
@@ -2058,142 +2059,205 @@ The usage of each pin is as follows. |
2058 | 2059 | std::uint32_t pkg_ver = m5gfx::get_pkg_ver(); |
2059 | 2060 | ESP_LOGD(LIBRARY_NAME, "pkg_ver : %02x", (int)pkg_ver); |
2060 | 2061 |
|
2061 | | - if (board == 0 || board == board_t::board_M5NanoC6) |
2062 | | - { |
2063 | | - } |
2064 | | - |
2065 | | - if (board == 0 || board == board_t::board_ArduinoNessoN1) |
2066 | | - { |
2067 | | - gpio::pin_backup_t backup_pins[] = |
2068 | | - { GPIO_NUM_8 |
2069 | | - , GPIO_NUM_10 |
2070 | | - , GPIO_NUM_16 |
2071 | | - , GPIO_NUM_17 |
2072 | | - , GPIO_NUM_20 |
2073 | | - , GPIO_NUM_21 |
2074 | | - , GPIO_NUM_22 |
2075 | | - }; |
2076 | | - auto result = lgfx::gpio::command( |
2077 | | - (const uint8_t[]) { |
2078 | | - lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_8, |
2079 | | - lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_10, |
2080 | | - lgfx::gpio::command_read , GPIO_NUM_8, |
2081 | | - lgfx::gpio::command_read , GPIO_NUM_10, |
2082 | | - lgfx::gpio::command_end |
2083 | | - } |
2084 | | - ); |
2085 | | - |
2086 | | - if (result == 0x03) { |
2087 | | - // PI4IO E0 |
2088 | | - // P0 BTN1 |
2089 | | - // P1 BTN2 |
2090 | | - // P2-P5 NC |
2091 | | - // P5 LNA Enable |
2092 | | - // P6 RF Switch |
2093 | | - // P7 LoRa Reset |
2094 | | - static constexpr const uint8_t reg_data_io1[] = { |
2095 | | - 0x03, 0b11100000, 0, // PI4IO_REG_IO_DIR |
2096 | | - 0x05, 0b10000000, 0, // PI4IO_REG_OUT_SET |
2097 | | - 0x07, 0b00011100, 0, // PI4IO_REG_OUT_H_IM |
2098 | | - 0x0D, 0b11000011, 0, // PI4IO_REG_PULL_SEL |
2099 | | - 0x0B, 0b11000011, 0, // PI4IO_REG_PULL_EN |
2100 | | - 0x09, 0b00000011, 0, // PI4IO_REG_IN_DEF_STA |
2101 | | - 0x11, 0b11111100, 0, // PI4IO_REG_INT_MASK |
2102 | | - 0xFF,0xFF,0xFF, |
2103 | | - }; |
2104 | | - // PI4IO E1 |
2105 | | - // P0 Power OFF system |
2106 | | - // P1 LCD_RST |
2107 | | - // P2 EXT_PWR_EN |
2108 | | - // P3 NC |
2109 | | - // P4 NC |
2110 | | - // P5 VIN_DET |
2111 | | - // P6 LCD_BL |
2112 | | - // P7 SYS_LEDG Low-level light |
2113 | | - static constexpr const uint8_t reg_data_io2[] = { |
2114 | | - 0x03, 0b11000111, 0, // PI4IO_REG_IO_DIR |
2115 | | - 0x07, 0b00011000, 0, // PI4IO_REG_OUT_H_IM |
2116 | | - 0x05, 0b00000000, 0, // PI4IO_REG_OUT_SET |
2117 | | - 0x0D, 0b10000000, 0, // PI4IO_REG_PULL_SEL |
2118 | | - 0x0B, 0b11111111, 0, // PI4IO_REG_PULL_EN |
2119 | | - 0x05, 0b10000010, 0, // PI4IO_REG_OUT_SET |
2120 | | - 0xFF,0xFF,0xFF, |
| 2062 | + if (pkg_ver == 1) |
| 2063 | + { // ESP32C6FH4(QFN32) : NanoC6 |
| 2064 | + if (board == 0 || board == board_t::board_M5NanoC6) |
| 2065 | + { |
| 2066 | + } |
| 2067 | + } else |
| 2068 | + if (pkg_ver == 0) |
| 2069 | + { // ESP32C6(QFN40) : NessoN1, UnitC6L |
| 2070 | + if (board == 0 || board == board_t::board_ArduinoNessoN1 || board == board_t::board_M5UnitC6L) |
| 2071 | + { |
| 2072 | + gpio::pin_backup_t backup_pins[] = |
| 2073 | + { GPIO_NUM_8 |
| 2074 | + , GPIO_NUM_10 |
| 2075 | + , GPIO_NUM_16 |
| 2076 | + , GPIO_NUM_17 |
| 2077 | + , GPIO_NUM_18 |
| 2078 | + , GPIO_NUM_20 |
| 2079 | + , GPIO_NUM_21 |
| 2080 | + , GPIO_NUM_22 |
2121 | 2081 | }; |
2122 | | - lgfx::i2c::init(i2c_port, GPIO_NUM_10, GPIO_NUM_8); |
2123 | | - i2c_write_register8_array(i2c_port, pi4io2_i2c_addr, reg_data_io2, 100000); |
2124 | | - i2c_write_register8_array(i2c_port, pi4io1_i2c_addr, reg_data_io1, 100000); |
2125 | | - |
2126 | | - bus_cfg.pin_mosi = GPIO_NUM_21; |
2127 | | - bus_cfg.pin_miso = GPIO_NUM_22; |
2128 | | - bus_cfg.pin_sclk = GPIO_NUM_20; |
2129 | | - bus_cfg.pin_dc = GPIO_NUM_16; |
2130 | | - bus_cfg.spi_mode = 0; |
2131 | | - bus_cfg.spi_3wire = true; |
2132 | | - bus_spi->config(bus_cfg); |
2133 | | - bus_spi->init(); |
| 2082 | + /* |
| 2083 | + | | NessoN1 | UnitC6L | |
| 2084 | + |:--:+:-------:+:-------:| |
| 2085 | + | G8 | SYS_SCL | SYS_SCL | |
| 2086 | + | G10| SYS_SDA | SYS_SDA | |
| 2087 | + | G18| GND | NC | |
| 2088 | + */ |
| 2089 | + auto result = lgfx::gpio::command( |
| 2090 | + (const uint8_t[]) { |
| 2091 | + lgfx::gpio::command_mode_input_pullup , GPIO_NUM_18, |
| 2092 | + lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_8, |
| 2093 | + lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_10, |
| 2094 | + lgfx::gpio::command_read , GPIO_NUM_18, |
| 2095 | + lgfx::gpio::command_read , GPIO_NUM_8, |
| 2096 | + lgfx::gpio::command_read , GPIO_NUM_10, |
| 2097 | + lgfx::gpio::command_end |
| 2098 | + } |
| 2099 | + ); |
| 2100 | + // 3 == NessoN1 / 7 == UnitC6L |
| 2101 | + // ESP_LOGE("debug", "\n\nN1/C6L detect %02x\n\n\n", (int)result); |
| 2102 | + if (result == 0x07) |
| 2103 | + { // UnitC6L ? |
| 2104 | + lgfx::i2c::init(i2c_port, GPIO_NUM_10, GPIO_NUM_8); |
| 2105 | + |
| 2106 | + _pin_reset(GPIO_NUM_6, use_reset); // LCD RST |
| 2107 | + bus_cfg.pin_mosi = GPIO_NUM_21; |
| 2108 | + bus_cfg.pin_miso = GPIO_NUM_22; // NC |
| 2109 | + bus_cfg.pin_sclk = GPIO_NUM_20; |
| 2110 | + bus_cfg.pin_dc = GPIO_NUM_18; |
| 2111 | + bus_cfg.spi_mode = 0; |
| 2112 | + bus_cfg.spi_3wire = true; |
| 2113 | + bus_spi->config(bus_cfg); |
| 2114 | + bus_spi->init(); |
2134 | 2115 |
|
2135 | | - id = _read_panel_id(bus_spi, GPIO_NUM_17); |
2136 | | - // check panel (ST7789) |
2137 | | - if ((id & 0xFB) == 0x81) // 0x81 or 0x85 |
2138 | | - { |
2139 | | - board = board_t::board_ArduinoNessoN1; |
2140 | | - ESP_LOGI(LIBRARY_NAME, "[Autodetect] board_ArduinoNessoN1"); |
| 2116 | + // id = _read_panel_id(bus_spi, GPIO_NUM_6); |
| 2117 | + // if (id == 0x??) // check panel (SSD1306) |
| 2118 | + { |
| 2119 | + board = board_t::board_M5UnitC6L; |
| 2120 | + ESP_LOGI(LIBRARY_NAME, "[Autodetect] board_M5UnitC6L"); |
2141 | 2121 |
|
| 2122 | + bus_spi->release(); |
| 2123 | + bus_cfg.freq_write = 40000000; |
| 2124 | + bus_cfg.freq_read = 10000000; |
| 2125 | + bus_spi->config(bus_cfg); |
| 2126 | + bus_spi->init(); |
| 2127 | + auto p = new Panel_SSD1306(); |
| 2128 | + p->bus(bus_spi); |
| 2129 | + { |
| 2130 | + _panel_last.reset(p); |
| 2131 | + auto cfg = p->config(); |
| 2132 | + cfg.pin_cs = GPIO_NUM_6; // OLED CS |
| 2133 | + cfg.pin_rst = GPIO_NUM_15; // OLED RST |
| 2134 | + cfg.panel_width = 64; |
| 2135 | + cfg.panel_height = 48; |
| 2136 | + cfg.offset_x = 32; |
| 2137 | + cfg.offset_y = 0; |
| 2138 | + cfg.offset_rotation = 0; |
| 2139 | + cfg.readable = true; |
| 2140 | + cfg.bus_shared = false; |
| 2141 | + p->config(cfg); |
| 2142 | + p->setRotation(0); |
| 2143 | + } |
| 2144 | + goto init_clear; |
| 2145 | + } |
2142 | 2146 | bus_spi->release(); |
2143 | | - bus_cfg.freq_write = 40000000; |
2144 | | - bus_cfg.freq_read = 16000000; |
| 2147 | + } else |
| 2148 | + if (result == 0x03) |
| 2149 | + { // NessoN1 ? |
| 2150 | + lgfx::i2c::init(i2c_port, GPIO_NUM_10, GPIO_NUM_8); |
| 2151 | + // PI4IO E0 |
| 2152 | + // P0 BTN1 |
| 2153 | + // P1 BTN2 |
| 2154 | + // P2-P5 NC |
| 2155 | + // P5 LNA Enable |
| 2156 | + // P6 RF Switch |
| 2157 | + // P7 LoRa Reset |
| 2158 | + static constexpr const uint8_t reg_data_io1[] = { |
| 2159 | + 0x03, 0b11100000, 0, // PI4IO_REG_IO_DIR |
| 2160 | + 0x05, 0b10000000, 0, // PI4IO_REG_OUT_SET |
| 2161 | + 0x07, 0b00011100, 0, // PI4IO_REG_OUT_H_IM |
| 2162 | + 0x0D, 0b11000011, 0, // PI4IO_REG_PULL_SEL |
| 2163 | + 0x0B, 0b11000011, 0, // PI4IO_REG_PULL_EN |
| 2164 | + 0x09, 0b00000011, 0, // PI4IO_REG_IN_DEF_STA |
| 2165 | + 0x11, 0b11111100, 0, // PI4IO_REG_INT_MASK |
| 2166 | + 0xFF,0xFF,0xFF, |
| 2167 | + }; |
| 2168 | + // PI4IO E1 |
| 2169 | + // P0 Power OFF system |
| 2170 | + // P1 LCD_RST |
| 2171 | + // P2 EXT_PWR_EN |
| 2172 | + // P3 NC |
| 2173 | + // P4 NC |
| 2174 | + // P5 VIN_DET |
| 2175 | + // P6 LCD_BL |
| 2176 | + // P7 SYS_LEDG Low-level light |
| 2177 | + static constexpr const uint8_t reg_data_io2[] = { |
| 2178 | + 0x03, 0b11000111, 0, // PI4IO_REG_IO_DIR |
| 2179 | + 0x07, 0b00011000, 0, // PI4IO_REG_OUT_H_IM |
| 2180 | + 0x05, 0b00000000, 0, // PI4IO_REG_OUT_SET |
| 2181 | + 0x0D, 0b10000000, 0, // PI4IO_REG_PULL_SEL |
| 2182 | + 0x0B, 0b11111111, 0, // PI4IO_REG_PULL_EN |
| 2183 | + 0x05, 0b10000010, 0, // PI4IO_REG_OUT_SET |
| 2184 | + 0xFF,0xFF,0xFF, |
| 2185 | + }; |
| 2186 | + i2c_write_register8_array(i2c_port, pi4io2_i2c_addr, reg_data_io2, 100000); |
| 2187 | + i2c_write_register8_array(i2c_port, pi4io1_i2c_addr, reg_data_io1, 100000); |
| 2188 | + |
| 2189 | + bus_cfg.pin_mosi = GPIO_NUM_21; |
| 2190 | + bus_cfg.pin_miso = GPIO_NUM_22; |
| 2191 | + bus_cfg.pin_sclk = GPIO_NUM_20; |
| 2192 | + bus_cfg.pin_dc = GPIO_NUM_16; |
| 2193 | + bus_cfg.spi_mode = 0; |
| 2194 | + bus_cfg.spi_3wire = true; |
2145 | 2195 | bus_spi->config(bus_cfg); |
2146 | 2196 | bus_spi->init(); |
2147 | | - auto p = new Panel_ST7789(); |
2148 | | - p->bus(bus_spi); |
2149 | | - { |
2150 | | - _panel_last.reset(p); |
2151 | | - auto cfg = p->config(); |
2152 | | - cfg.pin_cs = GPIO_NUM_17; // LCD CS |
2153 | | - cfg.pin_rst = -1; |
2154 | | - cfg.panel_width = 135; |
2155 | | - cfg.panel_height = 240; |
2156 | | - cfg.offset_x = 52; |
2157 | | - cfg.offset_y = 40; |
2158 | | - cfg.offset_rotation = 0; |
2159 | | - cfg.readable = true; |
2160 | | - cfg.invert = true; |
2161 | | - cfg.bus_shared = true; |
2162 | | - p->config(cfg); |
2163 | | - p->setRotation(0); |
2164 | | - } |
2165 | 2197 |
|
| 2198 | + id = _read_panel_id(bus_spi, GPIO_NUM_17); |
| 2199 | + // check panel (ST7789) |
| 2200 | + if ((id & 0xFB) == 0x81) // 0x81 or 0x85 |
2166 | 2201 | { |
2167 | | - auto t = new m5gfx::Touch_FT5x06(); |
2168 | | - if (t) { |
2169 | | - _touch_last.reset(t); |
2170 | | - auto cfg = t->config(); |
| 2202 | + board = board_t::board_ArduinoNessoN1; |
| 2203 | + ESP_LOGI(LIBRARY_NAME, "[Autodetect] board_ArduinoNessoN1"); |
2171 | 2204 |
|
2172 | | - cfg.x_min = 0; |
2173 | | - cfg.x_max = 134; |
2174 | | - cfg.y_min = 0; |
2175 | | - cfg.y_max = 239; |
2176 | | - cfg.bus_shared = true; |
2177 | | - cfg.offset_rotation = 0; |
2178 | | - |
2179 | | - cfg.i2c_port = I2C_NUM_0; |
2180 | | - cfg.i2c_addr = 0x38; |
| 2205 | + bus_spi->release(); |
| 2206 | + bus_cfg.freq_write = 40000000; |
| 2207 | + bus_cfg.freq_read = 16000000; |
| 2208 | + bus_spi->config(bus_cfg); |
| 2209 | + bus_spi->init(); |
| 2210 | + auto p = new Panel_ST7789(); |
| 2211 | + p->bus(bus_spi); |
| 2212 | + { |
| 2213 | + _panel_last.reset(p); |
| 2214 | + auto cfg = p->config(); |
| 2215 | + cfg.pin_cs = GPIO_NUM_17; // LCD CS |
2181 | 2216 | cfg.pin_rst = -1; |
2182 | | - cfg.pin_int = GPIO_NUM_3; |
2183 | | - cfg.pin_sda = GPIO_NUM_10; |
2184 | | - cfg.pin_scl = GPIO_NUM_8; |
2185 | | - cfg.freq = 400000; |
| 2217 | + cfg.panel_width = 135; |
| 2218 | + cfg.panel_height = 240; |
| 2219 | + cfg.offset_x = 52; |
| 2220 | + cfg.offset_y = 40; |
| 2221 | + cfg.offset_rotation = 0; |
| 2222 | + cfg.readable = true; |
| 2223 | + cfg.invert = true; |
| 2224 | + cfg.bus_shared = true; |
| 2225 | + p->config(cfg); |
| 2226 | + p->setRotation(0); |
| 2227 | + } |
2186 | 2228 |
|
2187 | | - t->config(cfg); |
2188 | | - p->touch(t); |
| 2229 | + { |
| 2230 | + auto t = new m5gfx::Touch_FT5x06(); |
| 2231 | + if (t) { |
| 2232 | + _touch_last.reset(t); |
| 2233 | + auto cfg = t->config(); |
| 2234 | + |
| 2235 | + cfg.x_min = 0; |
| 2236 | + cfg.x_max = 134; |
| 2237 | + cfg.y_min = 0; |
| 2238 | + cfg.y_max = 239; |
| 2239 | + cfg.bus_shared = true; |
| 2240 | + cfg.offset_rotation = 0; |
| 2241 | + |
| 2242 | + cfg.i2c_port = I2C_NUM_0; |
| 2243 | + cfg.i2c_addr = 0x38; |
| 2244 | + cfg.pin_rst = -1; |
| 2245 | + cfg.pin_int = GPIO_NUM_3; |
| 2246 | + cfg.pin_sda = GPIO_NUM_10; |
| 2247 | + cfg.pin_scl = GPIO_NUM_8; |
| 2248 | + cfg.freq = 400000; |
| 2249 | + |
| 2250 | + t->config(cfg); |
| 2251 | + p->touch(t); |
| 2252 | + } |
2189 | 2253 | } |
| 2254 | + _set_backlight(new Light_ArduinoNessoN1()); |
| 2255 | + goto init_clear; |
2190 | 2256 | } |
2191 | | - _set_backlight(new Light_ArduinoNessoN1()); |
2192 | | - goto init_clear; |
| 2257 | + bus_spi->release(); |
2193 | 2258 | } |
2194 | | - bus_spi->release(); |
| 2259 | + for (auto &bup : backup_pins) { bup.restore(); } |
2195 | 2260 | } |
2196 | | - for (auto &bup : backup_pins) { bup.restore(); } |
2197 | 2261 | } |
2198 | 2262 |
|
2199 | 2263 | #endif |
|
0 commit comments