@@ -104,14 +104,27 @@ Original Source:
104
104
#endif
105
105
106
106
#if defined (SOC_GDMA_SUPPORTED) // for C3/S3
107
- #include < soc/gdma_reg.h>
108
- #include < soc/gdma_struct.h>
109
- // S3とC3で同じレジスタに異なる定義名がついているため、ここで統一;
110
- #if !defined (DMA_OUT_PERI_SEL_CH0_REG)
111
- #define DMA_OUT_PERI_SEL_CH0_REG GDMA_OUT_PERI_SEL_CH0_REG
107
+ #if __has_include(<soc/gdma_reg.h>)
108
+ #include < soc/gdma_reg.h>
109
+ #elif __has_include(<soc/axi_dma_reg.h>) // ESP32P4
110
+ #include < soc/axi_dma_reg.h>
112
111
#endif
113
- #if !defined (DMA_IN_PERI_SEL_CH0_REG)
114
- #define DMA_IN_PERI_SEL_CH0_REG GDMA_IN_PERI_SEL_CH0_REG
112
+ #if __has_include(<soc/gdma_struct.h>)
113
+ #include < soc/gdma_struct.h>
114
+ #elif __has_include(<soc/axi_dma_struct.h>) // ESP32P4
115
+ #include < soc/axi_dma_struct.h>
116
+ #endif
117
+ // レジスタに異なる定義名がついているため、ここで統一;
118
+ #if defined AXI_DMA_OUT_PERI_SEL_CH0_REG
119
+ #define DMA_OUT_PERI_SEL_CH0_REG AXI_DMA_OUT_PERI_SEL_CH0_REG
120
+ #define DMA_IN_PERI_SEL_CH0_REG AXI_DMA_IN_PERI_SEL_CH0_REG
121
+ #else
122
+ #if !defined (DMA_OUT_PERI_SEL_CH0_REG)
123
+ #define DMA_OUT_PERI_SEL_CH0_REG GDMA_OUT_PERI_SEL_CH0_REG
124
+ #define DMA_IN_PERI_SEL_CH0_REG GDMA_IN_PERI_SEL_CH0_REG
125
+ #define DMA_PERI_OUT_SEL_CH0_M GDMA_PERI_OUT_SEL_CH0_M
126
+ #define DMA_PERI_IN_SEL_CH0_M GDMA_PERI_IN_SEL_CH0_M
127
+ #endif
115
128
#endif
116
129
117
130
#if !defined (SOC_GDMA_PAIRS_PER_GROUP_MAX)
@@ -129,7 +142,7 @@ namespace lgfx
129
142
130
143
static int search_pin_number (int peripheral_sig)
131
144
{
132
- #if defined (CONFIG_IDF_TARGET_ESP32C6)
145
+ #if defined (CONFIG_IDF_TARGET_ESP32C6) || defined (CONFIG_IDF_TARGET_ESP32P4)
133
146
uint32_t result = GPIO.func_in_sel_cfg [peripheral_sig].in_sel ;
134
147
#else
135
148
uint32_t result = GPIO.func_in_sel_cfg [peripheral_sig].func_sel ;
@@ -144,7 +157,11 @@ namespace lgfx
144
157
if (conf.freq_mhz >= 80 ){
145
158
return 80 * 1000000 ;
146
159
}
147
- return (conf.source_freq_mhz * 1000000 ) / conf.div ;
160
+ #if defined ( CONFIG_IDF_TARGET_ESP32P4 )
161
+ return (conf.source_freq_mhz * 1000000 ) / conf.div .integer ;
162
+ #else
163
+ return (conf.source_freq_mhz * 1000000 ) / conf.div ;
164
+ #endif
148
165
}
149
166
150
167
uint32_t FreqToClockDiv (uint32_t fapb, uint32_t hz)
@@ -225,8 +242,13 @@ namespace lgfx
225
242
// GDMAペリフェラルレジスタの配列を順に調べてペリフェラル番号が一致するDMAチャンネルを特定する;
226
243
for (int i = 0 ; i < SOC_GDMA_PAIRS_PER_GROUP_MAX; ++i)
227
244
{
228
- // ESP_LOGD("DBG","GDMA.channel:%d peri_sel:%d", i, GDMA.channel[i].out.peri_sel.sel);
229
- if ((*reg (DMA_OUT_PERI_SEL_CH0_REG + i * sizeof (GDMA.channel [0 ])) & 0x3F ) == peripheral_select)
245
+ #if defined AXI_DMA_OUT_PERI_SEL_CH0_REG
246
+ bool hit = (*reg (DMA_OUT_PERI_SEL_CH0_REG + i * sizeof (AXI_DMA.out [0 ])) & AXI_DMA_PERI_OUT_SEL_CH0_M) == peripheral_select;
247
+ #else
248
+ // ESP_LOGD("DBG","GDMA.channel:%d peri_sel:%d", i, GDMA.channel[i].out.peri_sel.sel);
249
+ bool hit = (*reg (DMA_OUT_PERI_SEL_CH0_REG + i * sizeof (GDMA.channel [0 ])) & DMA_PERI_OUT_SEL_CH0_M) == peripheral_select;
250
+ #endif
251
+ if (hit)
230
252
{
231
253
// ESP_LOGD("DBG","GDMA.channel:%d hit", i);
232
254
return i;
@@ -246,8 +268,13 @@ namespace lgfx
246
268
// GDMAペリフェラルレジスタの配列を順に調べてペリフェラル番号が一致するDMAチャンネルを特定する;
247
269
for (int i = 0 ; i < SOC_GDMA_PAIRS_PER_GROUP_MAX; ++i)
248
270
{
249
- // ESP_LOGD("DBG","GDMA.channel:%d peri_sel:%d", i, GDMA.channel[i].out.peri_sel.sel);
250
- if ((*reg (DMA_IN_PERI_SEL_CH0_REG + i * sizeof (GDMA.channel [0 ])) & 0x3F ) == peripheral_select)
271
+ #if defined AXI_DMA_OUT_PERI_SEL_CH0_REG
272
+ bool hit = (*reg (DMA_IN_PERI_SEL_CH0_REG + i * sizeof (AXI_DMA.in [0 ])) & AXI_DMA_PERI_IN_SEL_CH0_M) == peripheral_select;
273
+ #else
274
+ // ESP_LOGD("DBG","GDMA.channel:%d peri_sel:%d", i, GDMA.channel[i].out.peri_sel.sel);
275
+ bool hit = (*reg (DMA_IN_PERI_SEL_CH0_REG + i * sizeof (GDMA.channel [0 ])) & DMA_PERI_IN_SEL_CH0_M) == peripheral_select;
276
+ #endif
277
+ if (hit)
251
278
{
252
279
// ESP_LOGD("DBG","GDMA.channel:%d hit", i);
253
280
return i;
@@ -286,9 +313,8 @@ namespace lgfx
286
313
(volatile uint32_t *)GPIO_ENABLE1_W1TS_REG,
287
314
#endif
288
315
};
289
- // / pin番号が32未満かどうかで分岐する。 bit0は OUTPUT enか否かで切替。
290
- auto gpio_en_reg = gpio_en_regs[((pin >> 5 ) << 1 ) + (mode == pin_mode_t ::output ? 1 : 0 )];
291
- *gpio_en_reg = 1u << (pin & 31 );
316
+ // / pin番号が32未満かどうかで分岐する。 bit0は OUTPUT en。
317
+ // auto gpio_en_reg = gpio_en_regs[((pin >> 5) << 1) + (mode == pin_mode_t::output ? 1 : 0)];
292
318
293
319
auto io_mux_reg = (volatile uint32_t *)(GPIO_PIN_MUX_REG[pin]);
294
320
auto io_mux_val = *io_mux_reg; // & ~(FUN_PU_M | FUN_PD_M | SLP_PU_M | SLP_PD_M | MCU_SEL_M);
@@ -321,9 +347,15 @@ namespace lgfx
321
347
322
348
*io_mux_reg = io_mux_val;
323
349
324
- GPIO.pin [pin].pad_driver = 0 ; // 1 = OpenDrain / 0 = normal output
350
+ GPIO.pin [pin].pad_driver = (mode == pin_mode_t ::output) ? 0 : 1 ; // 1 = OpenDrain / 0 = normal output
351
+ if (mode != pin_mode_t ::output) {
352
+ gpio_hi (pin);
353
+ }
354
+ auto gpio_en_reg = gpio_en_regs[((pin >> 5 ) << 1 ) + 1 ];
355
+ *gpio_en_reg = 1u << (pin & 31 );
356
+
325
357
326
- #if defined (CONFIG_IDF_TARGET_ESP32C6)
358
+ #if defined (CONFIG_IDF_TARGET_ESP32C6) || defined (CONFIG_IDF_TARGET_ESP32P4)
327
359
GPIO.func_out_sel_cfg [pin].out_sel = SIG_GPIO_OUT_IDX;
328
360
#else
329
361
GPIO.func_out_sel_cfg [pin].func_sel = SIG_GPIO_OUT_IDX;
@@ -357,8 +389,14 @@ namespace lgfx
357
389
358
390
size_t func_num = ((_gpio_func_out_reg >> GPIO_FUNC0_OUT_SEL_S) & GPIO_FUNC0_OUT_SEL_V);
359
391
if (func_num < sizeof (GPIO.func_in_sel_cfg ) / sizeof (GPIO.func_in_sel_cfg [0 ])) {
392
+ #if defined ( GPIO_FUNC0_IN_SEL_CFG_REG )
360
393
_gpio_func_in_reg = *reinterpret_cast <uint32_t *>(GPIO_FUNC0_IN_SEL_CFG_REG + (func_num * 4 ));
361
- if (func_num == ((_gpio_func_in_reg >> GPIO_FUNC0_IN_SEL_S) & GPIO_FUNC0_IN_SEL_V)) {
394
+ bool hit = func_num == ((_gpio_func_in_reg >> GPIO_FUNC0_IN_SEL_S) & GPIO_FUNC0_IN_SEL_V);
395
+ #else
396
+ _gpio_func_in_reg = *reinterpret_cast <uint32_t *>(GPIO_FUNC1_IN_SEL_CFG_REG + ((func_num - 1 ) * 4 ));
397
+ bool hit = func_num == ((_gpio_func_in_reg >> GPIO_FUNC1_IN_SEL_S) & GPIO_FUNC1_IN_SEL_V);
398
+ #endif
399
+ if (hit) {
362
400
_in_func_num = func_num;
363
401
// ESP_LOGD("DEBUG","backup pin:%d : func_num:%d", pin_num, _in_func_num);
364
402
}
@@ -437,6 +475,7 @@ namespace lgfx
437
475
while (cmd_list[0 ] != command_end)
438
476
{
439
477
auto cmd = (command_t )cmd_list[0 ];
478
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
440
479
bool res = command (cmd, cmd_list[1 ]);
441
480
if (cmd == command_read) {
442
481
result = (result << 1 ) + res;
@@ -737,7 +776,7 @@ namespace lgfx
737
776
}
738
777
static volatile uint32_t * getFifoAddr (int num)
739
778
{
740
- #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
779
+ #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
741
780
return &(getDev (num)->data .val );
742
781
#else
743
782
return &(getDev (num)->fifo_data .val );
@@ -787,7 +826,7 @@ namespace lgfx
787
826
void save_reg (i2c_dev_t * dev)
788
827
{
789
828
auto reg = (volatile uint32_t *)dev;
790
- #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
829
+ #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
791
830
auto fifo_reg = (volatile uint32_t *)(&dev->data );
792
831
#else
793
832
auto fifo_reg = (volatile uint32_t *)(&dev->fifo_data );
@@ -802,7 +841,7 @@ namespace lgfx
802
841
void load_reg (i2c_dev_t * dev)
803
842
{
804
843
auto reg = (volatile uint32_t *)dev;
805
- #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
844
+ #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
806
845
auto fifo_reg = (volatile uint32_t *)(&dev->data );
807
846
#else
808
847
auto fifo_reg = (volatile uint32_t *)(&dev->fifo_data );
@@ -853,7 +892,7 @@ namespace lgfx
853
892
{
854
893
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
855
894
return dev->sr .rx_fifo_cnt ;
856
- #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
895
+ #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
857
896
return dev->sr .rxfifo_cnt ;
858
897
#else
859
898
return dev->status_reg .rx_fifo_cnt ;
@@ -959,7 +998,7 @@ namespace lgfx
959
998
uint32_t us;
960
999
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
961
1000
uint32_t us_limit = (dev->scl_high_period .period + dev->scl_low_period .period + 16 ) * (1 + dev->sr .tx_fifo_cnt );
962
- #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1001
+ #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
963
1002
uint32_t us_limit = (dev->scl_high_period .scl_high_period + dev->scl_low_period .scl_low_period + 16 ) * (1 + dev->sr .txfifo_cnt );
964
1003
#else
965
1004
uint32_t us_limit = (dev->scl_high_period .period + dev->scl_low_period .period + 16 ) * (1 + dev->status_reg .tx_fifo_cnt );
@@ -976,7 +1015,7 @@ namespace lgfx
976
1015
dev->int_clr .val = int_raw.val ;
977
1016
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
978
1017
if (!int_raw.end_detect || int_raw.ack_err )
979
- #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1018
+ #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
980
1019
if (!int_raw.end_detect_int_raw || int_raw.nack_int_raw )
981
1020
#else
982
1021
if (!int_raw.end_detect || int_raw.nack )
@@ -990,7 +1029,7 @@ namespace lgfx
990
1029
991
1030
if (flg_stop || res.has_error ())
992
1031
{
993
- #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1032
+ #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
994
1033
if (i2c_context[i2c_port].state == i2c_context_t ::state_read || !int_raw.end_detect_int_raw )
995
1034
#else
996
1035
if (i2c_context[i2c_port].state == i2c_context_t ::state_read || !int_raw.end_detect )
@@ -1011,7 +1050,7 @@ namespace lgfx
1011
1050
while (!(dev->int_raw .val & intmask_) && ((millis () - ms) < 14 ));
1012
1051
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
1013
1052
if (res.has_value () && dev->int_raw .ack_err )
1014
- #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1053
+ #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
1015
1054
if (res.has_value () && dev->int_raw .nack_int_raw )
1016
1055
#else
1017
1056
if (res.has_value () && dev->int_raw .nack )
@@ -1211,7 +1250,11 @@ namespace lgfx
1211
1250
uint32_t src_clock = 80 * 1000 * 1000 ;
1212
1251
if (cpu_freq_conf.freq_mhz < 80 )
1213
1252
{
1253
+ #if defined ( CONFIG_IDF_TARGET_ESP32P4 )
1254
+ src_clock = (cpu_freq_conf.source_freq_mhz * 1000000 ) / cpu_freq_conf.div .integer ;
1255
+ #else
1214
1256
src_clock = (cpu_freq_conf.source_freq_mhz * 1000000 ) / cpu_freq_conf.div ;
1257
+ #endif
1215
1258
}
1216
1259
// ESP_LOGI("LGFX", "i2c::restart : port:%d / addr:%02x / freq:%d / rw:%d", i2c_port, i2c_addr, freq, read);
1217
1260
// ESP_LOGI("LGFX", "cpu_freq_conf.div :%d", cpu_freq_conf.div);
@@ -1236,7 +1279,9 @@ namespace lgfx
1236
1279
uint32_t val = (cycle > 64 ) ? (I2C_SCL_FILTER_EN | I2C_SDA_FILTER_EN) : 0 ;
1237
1280
dev->filter_cfg .val = val;
1238
1281
uint32_t scl_high_offset = ( val ? 8 : 7 );
1282
+ #if !defined ( CONFIG_IDF_TARGET_ESP32P4 )
1239
1283
dev->clk_conf .sclk_sel = 0 ;
1284
+ #endif
1240
1285
#else
1241
1286
dev->scl_filter_cfg .en = cycle > 64 ;
1242
1287
dev->scl_filter_cfg .thres = 0 ;
@@ -1265,7 +1310,7 @@ namespace lgfx
1265
1310
cycle = (1 <<10 )-1 ;
1266
1311
}
1267
1312
1268
- #if defined (CONFIG_IDF_TARGET_ESP32S3) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1313
+ #if defined (CONFIG_IDF_TARGET_ESP32S3) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
1269
1314
auto wait_high = scl_high_period >> 2 ;
1270
1315
dev->scl_high_period .scl_high_period = scl_high_period - wait_high;
1271
1316
dev->scl_high_period .scl_wait_high_period = wait_high;
@@ -1315,7 +1360,7 @@ namespace lgfx
1315
1360
auto dev = getDev (i2c_port);
1316
1361
i2c_context[i2c_port].lock ();
1317
1362
1318
- #if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1363
+ #if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
1319
1364
if (dev->sr .bus_busy )
1320
1365
#else
1321
1366
if (dev->status_reg .bus_busy )
@@ -1327,7 +1372,7 @@ namespace lgfx
1327
1372
{
1328
1373
taskYIELD ();
1329
1374
}
1330
- #if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1375
+ #if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
1331
1376
while (dev->sr .bus_busy && micros () - ms < 128 );
1332
1377
#else
1333
1378
while (dev->status_reg .bus_busy && micros () - ms < 128 );
@@ -1344,7 +1389,7 @@ namespace lgfx
1344
1389
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
1345
1390
dev->timeout .time_out_value = 31 ;
1346
1391
dev->timeout .time_out_en = 1 ;
1347
- #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1392
+ #elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
1348
1393
dev->to .time_out_value = 31 ;
1349
1394
dev->to .time_out_en = 1 ;
1350
1395
#else
@@ -1434,7 +1479,7 @@ namespace lgfx
1434
1479
auto dev = getDev (i2c_port);
1435
1480
1436
1481
size_t len = 0 ;
1437
- #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
1482
+ #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 ) || defined ( CONFIG_IDF_TARGET_ESP32P4 )
1438
1483
uint32_t us_limit = ((dev->scl_high_period .scl_high_period + dev->scl_high_period .scl_wait_high_period + dev->scl_low_period .scl_low_period ) << 1 );
1439
1484
#elif defined ( CONFIG_IDF_TARGET_ESP32C3 )
1440
1485
uint32_t us_limit = ((dev->scl_high_period .period + dev->scl_low_period .period ) << 1 );
@@ -1560,6 +1605,15 @@ namespace lgfx
1560
1605
i2c_temporary_switcher_t::i2c_temporary_switcher_t (int i2c_port, int pin_sda, int pin_scl)
1561
1606
: _i2c_port { i2c_port }
1562
1607
{
1608
+ #if defined ( I2C0_SDA_PAD_IN_IDX )
1609
+ #define I2CEXT0_SDA_IN_IDX I2C0_SDA_PAD_IN_IDX
1610
+ #define I2CEXT0_SCL_IN_IDX I2C0_SCL_PAD_IN_IDX
1611
+ #if defined ( I2C1_SDA_PAD_IN_IDX )
1612
+ #define I2CEXT1_SDA_IN_IDX I2C1_SDA_PAD_IN_IDX
1613
+ #define I2CEXT1_SCL_IN_IDX I2C1_SCL_PAD_IN_IDX
1614
+ #endif
1615
+ #endif
1616
+
1563
1617
int peri_sig_sda = I2CEXT0_SDA_IN_IDX;
1564
1618
int peri_sig_scl = I2CEXT0_SCL_IN_IDX;
1565
1619
#if defined (I2CEXT1_SDA_IN_IDX)
0 commit comments