|
| 1 | +#include "devices/Display.h" |
| 2 | +#include "devices/SdCard.h" |
| 3 | + |
| 4 | +#include <Tactility/hal/Configuration.h> |
| 5 | + |
| 6 | +using namespace tt::hal; |
| 7 | + |
| 8 | +static const auto LOGGER = tt::Logger("Tab5"); |
| 9 | + |
| 10 | +static DeviceVector createDevices() { |
| 11 | + return { |
| 12 | + createDisplay(), |
| 13 | + createSdCard(), |
| 14 | + }; |
| 15 | +} |
| 16 | + |
| 17 | +static bool initBoot() { |
| 18 | + /* |
| 19 | + PI4IOE5V6408-1 (0x43) |
| 20 | + - Bit 0: RF internal/external switch |
| 21 | + - Bit 1: Speaker enable |
| 22 | + - Bit 2: External 5V bus enable |
| 23 | + - Bit 3: / |
| 24 | + - Bit 4: LCD reset |
| 25 | + - Bit 5: Touch reset |
| 26 | + - Bit 6: Camera reset |
| 27 | + - Bit 7: Headphone detect |
| 28 | +
|
| 29 | + PI4IOE5V6408-2 (0x44) |
| 30 | + - Bit 0: C6 WLAN enable |
| 31 | + - Bit 1: / |
| 32 | + - Bit 2: / |
| 33 | + - Bit 3: USB-A 5V enable |
| 34 | + - Bit 4: Device power: PWROFF_PLUSE |
| 35 | + - Bit 5: IP2326: nCHG_QC_EN |
| 36 | + - Bit 6: IP2326: CHG_STAT_LED |
| 37 | + - Bit 7: IP2326: CHG_EN |
| 38 | + */ |
| 39 | + |
| 40 | + // Init byte arrays adapted from https://github.com/m5stack/M5GFX/blob/03565ccc96cb0b73c8b157f5ec3fbde439b034ad/src/M5GFX.cpp |
| 41 | + static constexpr uint8_t reg_data_io1_1[] = { |
| 42 | + 0x03, 0b01111111, // PI4IO_REG_IO_DIR |
| 43 | + 0x05, 0b01000110, // PI4IO_REG_OUT_SET (bit4=LCD Reset, bit5=GT911 TouchReset -> LOW) |
| 44 | + 0x07, 0b00000000, // PI4IO_REG_OUT_H_IM |
| 45 | + 0x0D, 0b01111111, // PI4IO_REG_PULL_SEL |
| 46 | + 0x0B, 0b01111111, // PI4IO_REG_PULL_EN |
| 47 | + }; |
| 48 | + |
| 49 | + static constexpr uint8_t reg_data_io1_2[] = { |
| 50 | + 0x05, 0b01110110, // PI4IO_REG_OUT_SET (bit4=LCD Reset, bit5=GT911 TouchReset -> HIGH) |
| 51 | + }; |
| 52 | + |
| 53 | + static constexpr uint8_t reg_data_io2[] = { |
| 54 | + 0x03, 0b10111001, // PI4IO_REG_IO_DIR |
| 55 | + 0x07, 0b00000110, // PI4IO_REG_OUT_H_IM |
| 56 | + 0x0D, 0b10111001, // PI4IO_REG_PULL_SEL |
| 57 | + 0x0B, 0b11111001, // PI4IO_REG_PULL_EN |
| 58 | + 0x09, 0b01000000, // PI4IO_REG_IN_DEF_STA |
| 59 | + 0x11, 0b10111111, // PI4IO_REG_INT_MASK |
| 60 | + 0x05, 0b10001001, // PI4IO_REG_OUT_SET (enable WiFi, USB-A 5V and CHG_EN) |
| 61 | + }; |
| 62 | + |
| 63 | + constexpr auto IO_EXPANDER1_ADDRESS = 0x43; |
| 64 | + if (!i2c::masterWriteRegisterArray(I2C_NUM_0, IO_EXPANDER1_ADDRESS, reg_data_io1_1, sizeof(reg_data_io1_1))) { |
| 65 | + LOGGER.error("IO expander 1 init failed in phase 1"); |
| 66 | + return false; |
| 67 | + } |
| 68 | + |
| 69 | + constexpr auto IO_EXPANDER2_ADDRESS = 0x44; |
| 70 | + if (!i2c::masterWriteRegisterArray(I2C_NUM_0, IO_EXPANDER2_ADDRESS, reg_data_io2, sizeof(reg_data_io2))) { |
| 71 | + LOGGER.error("IO expander 2 init failed"); |
| 72 | + return false; |
| 73 | + } |
| 74 | + |
| 75 | + // The M5Stack code applies this, but it's not known why |
| 76 | + // TODO: Remove and test it extensively |
| 77 | + tt::kernel::delayTicks(10); |
| 78 | + |
| 79 | + if (!i2c::masterWriteRegisterArray(I2C_NUM_0, IO_EXPANDER1_ADDRESS, reg_data_io1_2, sizeof(reg_data_io1_2))) { |
| 80 | + LOGGER.error("IO expander 1 init failed in phase 2"); |
| 81 | + return false; |
| 82 | + } |
| 83 | + |
| 84 | + return true; |
| 85 | +} |
| 86 | + |
| 87 | +extern const Configuration hardwareConfiguration = { |
| 88 | + .initBoot = initBoot, |
| 89 | + .createDevices = createDevices, |
| 90 | + .i2c = { |
| 91 | + i2c::Configuration { |
| 92 | + .name = "Internal", |
| 93 | + .port = I2C_NUM_0, |
| 94 | + .initMode = i2c::InitMode::ByTactility, |
| 95 | + .isMutable = false, |
| 96 | + .config = (i2c_config_t) { |
| 97 | + .mode = I2C_MODE_MASTER, |
| 98 | + .sda_io_num = GPIO_NUM_31, |
| 99 | + .scl_io_num = GPIO_NUM_32, |
| 100 | + .sda_pullup_en = true, |
| 101 | + .scl_pullup_en = true, |
| 102 | + .master = { |
| 103 | + .clk_speed = 400000 |
| 104 | + }, |
| 105 | + .clk_flags = 0 |
| 106 | + } |
| 107 | + }, |
| 108 | + i2c::Configuration { |
| 109 | + .name = "Port A", |
| 110 | + .port = I2C_NUM_1, |
| 111 | + .initMode = i2c::InitMode::ByTactility, |
| 112 | + .isMutable = false, |
| 113 | + .config = (i2c_config_t) { |
| 114 | + .mode = I2C_MODE_MASTER, |
| 115 | + .sda_io_num = GPIO_NUM_53, |
| 116 | + .scl_io_num = GPIO_NUM_54, |
| 117 | + .sda_pullup_en = true, |
| 118 | + .scl_pullup_en = true, |
| 119 | + .master = { |
| 120 | + .clk_speed = 400000 |
| 121 | + }, |
| 122 | + .clk_flags = 0 |
| 123 | + } |
| 124 | + } |
| 125 | + }, |
| 126 | + .spi = { |
| 127 | + // SDCard |
| 128 | + spi::Configuration { |
| 129 | + .device = SPI3_HOST, |
| 130 | + .dma = SPI_DMA_CH_AUTO, |
| 131 | + .config = { |
| 132 | + .mosi_io_num = GPIO_NUM_44, |
| 133 | + .miso_io_num = GPIO_NUM_39, |
| 134 | + .sclk_io_num = GPIO_NUM_43, |
| 135 | + .quadwp_io_num = GPIO_NUM_NC, |
| 136 | + .quadhd_io_num = GPIO_NUM_NC, |
| 137 | + .data4_io_num = GPIO_NUM_NC, |
| 138 | + .data5_io_num = GPIO_NUM_NC, |
| 139 | + .data6_io_num = GPIO_NUM_NC, |
| 140 | + .data7_io_num = GPIO_NUM_NC, |
| 141 | + .data_io_default_level = false, |
| 142 | + .max_transfer_sz = 0, |
| 143 | + .flags = 0, |
| 144 | + .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, |
| 145 | + .intr_flags = 0 |
| 146 | + }, |
| 147 | + .initMode = spi::InitMode::ByTactility, |
| 148 | + .isMutable = false, |
| 149 | + .lock = nullptr |
| 150 | + } |
| 151 | + } |
| 152 | +}; |
0 commit comments