Skip to content

Commit ac5b1bc

Browse files
committed
esp32/machine_i2c: Factor default pin macros to header file.
So the implementation of I2CTarget can use them. Signed-off-by: Damien George <[email protected]>
1 parent 79d182d commit ac5b1bc

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

ports/esp32/machine_i2c.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,13 @@
2828
#include "py/mphal.h"
2929
#include "py/mperrno.h"
3030
#include "extmod/modmachine.h"
31+
#include "machine_i2c.h"
3132

3233
#include "driver/i2c.h"
3334
#include "hal/i2c_ll.h"
3435

3536
#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C
3637

37-
#ifndef MICROPY_HW_I2C0_SCL
38-
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
39-
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_9)
40-
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_8)
41-
#else
42-
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_18)
43-
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_19)
44-
#endif
45-
#endif
46-
47-
#ifndef MICROPY_HW_I2C1_SCL
48-
#if CONFIG_IDF_TARGET_ESP32
49-
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_25)
50-
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_26)
51-
#else
52-
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_9)
53-
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_8)
54-
#endif
55-
#endif
56-
5738
#if SOC_I2C_SUPPORT_XTAL
5839
#if CONFIG_XTAL_FREQ > 0
5940
#define I2C_SCLK_FREQ (CONFIG_XTAL_FREQ * 1000000)

ports/esp32/machine_i2c.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
/*
3+
* This file is part of the MicroPython project, http://micropython.org/
4+
*
5+
* The MIT License (MIT)
6+
*
7+
* Copyright (c) 2019-2025 Damien P. George
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
#ifndef MICROPY_INCLUDED_ESP32_MACHINE_I2C_H
28+
#define MICROPY_INCLUDED_ESP32_MACHINE_I2C_H
29+
30+
// Configure default I2C0 pins.
31+
#ifndef MICROPY_HW_I2C0_SCL
32+
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
33+
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_9)
34+
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_8)
35+
#else
36+
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_18)
37+
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_19)
38+
#endif
39+
#endif
40+
41+
// Configure default I2C1 pins.
42+
#ifndef MICROPY_HW_I2C1_SCL
43+
#if CONFIG_IDF_TARGET_ESP32
44+
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_25)
45+
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_26)
46+
#else
47+
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_9)
48+
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_8)
49+
#endif
50+
#endif
51+
52+
#endif // MICROPY_INCLUDED_ESP32_MACHINE_I2C_H

0 commit comments

Comments
 (0)