Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align ChibiOS I2C defs with other drivers #14399

Merged
merged 2 commits into from
Sep 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Align ChibiOS I2C defs with other drivers
  • Loading branch information
zvecr committed Sep 12, 2021
commit 1e329ee6a2dc13cba1c067bc8e0275fe2b59936b
17 changes: 7 additions & 10 deletions docs/i2c_driver.md
Original file line number Diff line number Diff line change
@@ -62,16 +62,13 @@ Then, modify your board's `mcuconf.h` to enable the peripheral you've chosen, fo

Configuration-wise, you'll need to set up the peripheral as per your MCU's datasheet -- the defaults match the pins for a Proton-C, i.e. STM32F303.

|`config.h` Overrride |Description |Default|
|------------------------|-------------------------------------------------------------------------------------------|-------|
|`I2C_DRIVER` |I2C peripheral to use - I2C1 -> `I2CD1`, I2C2 -> `I2CD2` etc. |`I2CD1`|
|`I2C1_BANK` (deprecated)|The bank of pins (`GPIOA`, `GPIOB`, `GPIOC`), superseded by `I2C1_SCL_BANK`/`I2C1_SDA_BANK`|`GPIOB`|
|`I2C1_SCL_BANK` |The bank of pins (`GPIOA`, `GPIOB`, `GPIOC`) to use for SCL |`GPIOB`|
|`I2C1_SCL` |The pin number for SCL (0-15) |`6` |
|`I2C1_SCL_PAL_MODE` |The alternate function mode for SCL |`4` |
|`I2C1_SDA_BANK` |The bank of pins (`GPIOA`, `GPIOB`, `GPIOC`) to use for SDA |`GPIOB`|
|`I2C1_SDA` |The pin number for SDA (0-15) |`7` |
|`I2C1_SDA_PAL_MODE` |The alternate function mode for SDA |`4` |
|`config.h` Overrride |Description |Default|
|------------------------|--------------------------------------------------------------|-------|
|`I2C_DRIVER` |I2C peripheral to use - I2C1 -> `I2CD1`, I2C2 -> `I2CD2` etc. |`I2CD1`|
|`I2C1_SCL_PIN` |The pin definition for SCL |`B6` |
|`I2C1_SCL_PAL_MODE` |The alternate function mode for SCL |`4` |
|`I2C1_SDA_PIN` |The pin definition for SDA |`B7` |
|`I2C1_SDA_PAL_MODE` |The alternate function mode for SDA |`4` |

The following configuration values depend on the specific MCU in use.

11 changes: 4 additions & 7 deletions docs/ja/i2c_driver.md
Original file line number Diff line number Diff line change
@@ -79,13 +79,10 @@ ARM MCU 用の設定はしばしば非常に複雑です。これは、多くの

STM32 MCU では、使用するハードウェアドライバにより、さまざまなピンを I2C ピンとして設定できます。標準では `B6`, `B7` ピンが I2C 用のピンです。 I2C 用のピンを設定するために次の定義が使えます:

| 変数 | 説明 | 既定値 |
|-----------------------|--------------------------------------------------------------------------------------------------|---------|
| `I2C1_SCL_BANK` | SCL に使うピンのバンク (`GPIOA`, `GPIOB`, `GPIOC`) | `GPIOB` |
| `I2C1_SDA_BANK` | SDA に使うピンのバンク (`GPIOA`, `GPIOB`, `GPIOC`) | `GPIOB` |
| `I2C1_SCL` | SCL のピン番号 (0-15) | `6` |
| `I2C1_SDA` | SDA のピン番号 (0-15) | `7` |
| `I2C1_BANK`(非推奨) | 使用するピンのバンク (`GPIOA`, `GPIOB`, `GPIOC`)。後継は `I2C1_SCL_BANK`, `I2C1_SDA_BANK` です。 | `GPIOB` |
| 変数 | 説明 | 既定値 |
|-----------------------|-------------------------------------------------------------------------------------------|---------|
| `I2C1_SCL_PIN` | SCL のピン番号 | `B6` |
| `I2C1_SDA_PIN` | SDA のピン番号 | `B7` |

ChibiOS I2C ドライバの設定項目は STM32 MCU の種類に依存します。

4 changes: 2 additions & 2 deletions keyboards/aeboards/constellation/rev2/config.h
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@
#define LOCKING_RESYNC_ENABLE

// I2C setup
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_SCL_PAL_MODE 4
#define I2C1_SDA_PAL_MODE 4
#define I2C1_TIMINGR_PRESC 0U
4 changes: 2 additions & 2 deletions keyboards/aeboards/ext65/rev2/config.h
Original file line number Diff line number Diff line change
@@ -56,8 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define WS2812_EXTERNAL_PULLUP

// I2C OLED defines
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9

#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1
5 changes: 2 additions & 3 deletions keyboards/cannonkeys/satisfaction75/config.h
Original file line number Diff line number Diff line change
@@ -53,9 +53,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

// I2C config
#define I2C_DRIVER I2CD1
#define I2C1_SCL_BANK GPIOB
#define I2C1_SCL 6
#define I2C1_SDA 7
#define I2C1_SCL_PIN B6
#define I2C1_SDA_PIN B7
#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1
#define I2C1_TIMINGR_PRESC 0x00U
4 changes: 2 additions & 2 deletions keyboards/clueboard/66_hotswap/gen1/config.h
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@
// 0b1110101 AD <-> SCL
// 0b1110110 AD <-> SDA
#define LED_DRIVER_ADDR_1 0b1110100
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9

#define LED_DRIVER_COUNT 1
#define DRIVER_LED_TOTAL 71
4 changes: 2 additions & 2 deletions keyboards/dekunukem/duckypad/config.h
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#endif

#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9

#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1
5 changes: 2 additions & 3 deletions keyboards/ergodox_infinity/config.h
Original file line number Diff line number Diff line change
@@ -83,9 +83,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define I2C1_CLOCK_SPEED 400000
#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_BANK GPIOB
#define I2C1_SCL 0
#define I2C1_SDA 1
#define I2C1_SCL_PIN B0
#define I2C1_SDA_PIN B1

#ifdef ST7565_ENABLE
/* LCD driver */
4 changes: 2 additions & 2 deletions keyboards/ez_maker/directpins/teensy_32/config.h
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#pragma once

// i2c_master defines
#define I2C1_SCL 0 // A2 on pinout = B0
#define I2C1_SDA 1 // A3 on pinout = B1
#define I2C1_SCL_PIN B0 // A2 on pinout = B0
#define I2C1_SDA_PIN B1 // A3 on pinout = B1
#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
4 changes: 2 additions & 2 deletions keyboards/ez_maker/directpins/teensy_lc/config.h
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#pragma once

// i2c_master defines
#define I2C1_SCL 0 // A2 on pinout = B0
#define I2C1_SDA 1 // A3 on pinout = B1
#define I2C1_SCL_PIN B0 // A2 on pinout = B0
#define I2C1_SDA_PIN B1 // A3 on pinout = B1
#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
6 changes: 2 additions & 4 deletions keyboards/ferris/0_2/config.h
Original file line number Diff line number Diff line change
@@ -67,10 +67,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* i2c settings */

#define I2C_DRIVER I2CD2
#define I2C1_SCL_BANK GPIOB
#define I2C1_SCL 10
#define I2C1_SDA_BANK GPIOB
#define I2C1_SDA 11
#define I2C1_SCL_PIN B10
#define I2C1_SDA_PIN B11
#define I2C1_TIMINGR_PRESC 2U
#define I2C1_TIMINGR_SCLDEL 1U
#define I2C1_TIMINGR_SDADEL 0U
5 changes: 0 additions & 5 deletions keyboards/ferris/0_2/matrix.c
Original file line number Diff line number Diff line change
@@ -59,11 +59,6 @@ extern i2c_status_t mcp23017_status;
bool i2c_initialized = 0;
i2c_status_t mcp23017_status = I2C_ADDR;

#define I2C2_SCL_BANK GPIOB
#define I2C2_SCL 10
#define I2C2_SDA_BANK GPIOB
#define I2C2_SDA 11

uint8_t init_mcp23017(void) {
print("init mcp23017\n");
mcp23017_status = I2C_ADDR;
2 changes: 1 addition & 1 deletion keyboards/handwired/onekey/blackpill_f401/blackpill_f401.c
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#include QMK_KEYBOARD_H

void board_init(void) {
// B9 is configured as I2C1_SDA in the board file; that function must be
// B9 is configured as I2C1_SDA_PIN in the board file; that function must be
// disabled before using B7 as I2C1_SDA.
setPinInputHigh(B9);
}
4 changes: 2 additions & 2 deletions keyboards/handwired/onekey/teensy_32/config.h
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
#define UNUSED_PINS

// i2c_master defines
#define I2C1_SCL 0 // A2 on pinout = B0
#define I2C1_SDA 1 // A3 on pinout = B1
#define I2C1_SCL_PIN B0 // A2 on pinout = B0
#define I2C1_SDA_PIN B1 // A3 on pinout = B1
#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
4 changes: 2 additions & 2 deletions keyboards/handwired/onekey/teensy_lc/config.h
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
#define UNUSED_PINS

// i2c_master defines
#define I2C1_SCL 0 // A2 on pinout = B0
#define I2C1_SDA 1 // A3 on pinout = B1
#define I2C1_SCL_PIN B0 // A2 on pinout = B0
#define I2C1_SDA_PIN B1 // A3 on pinout = B1
#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
6 changes: 2 additions & 4 deletions keyboards/handwired/tractyl_manuform/5x6_right/f411/config.h
Original file line number Diff line number Diff line change
@@ -71,10 +71,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* i2c config for oleds */
#define I2C_DRIVER I2CD1
#define I2C1_SCL_BANK GPIOB
#define I2C1_SDA_BANK GPIOB
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_SCL_PAL_MODE 4
#define I2C1_SDA_PAL_MODE 4
#define I2C1_CLOCK_SPEED 400000
4 changes: 2 additions & 2 deletions keyboards/matrix/m20add/config.h
Original file line number Diff line number Diff line change
@@ -82,8 +82,8 @@
#define DEBOUNCE 5

// i2c setting
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_CLOCK_SPEED 400000
#define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2

8 changes: 4 additions & 4 deletions keyboards/matrix/m20add/m20add.c
Original file line number Diff line number Diff line change
@@ -64,12 +64,12 @@ void i2c_init(void)
}

// Try releasing special pins for a short time
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
palSetLineMode(I2C1_SCL_PIN, PAL_MODE_INPUT);
palSetLineMode(I2C1_SDA_PIN, PAL_MODE_INPUT);

chThdSleepMilliseconds(10);
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
palSetLineMode(I2C1_SCL_PIN, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
palSetLineMode(I2C1_SDA_PIN, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
}

#define REBOOT_MAGIC 0x41544B42
4 changes: 2 additions & 2 deletions keyboards/matrix/noah/config.h
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@
#define DEBOUNCE 5

// i2c setting
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_CLOCK_SPEED 400000
#define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2
#define PAL_MODE_STM32_ALTERNATE_OPENDRAIN (PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN)
5 changes: 2 additions & 3 deletions keyboards/whitefox/config.h
Original file line number Diff line number Diff line change
@@ -72,9 +72,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define I2C1_CLOCK_SPEED 400000
#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
#define I2C1_BANK GPIOB
#define I2C1_SCL 0
#define I2C1_SDA 1
#define I2C1_SCL_PIN B0
#define I2C1_SDA_PIN B1

/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
* This is useful for the Windows task manager shortcut (ctrl+shift+esc).
4 changes: 2 additions & 2 deletions keyboards/xelus/kangaroo/config.h
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@
#define LOCKING_RESYNC_ENABLE

// I2C OLED defines
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9

#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1
4 changes: 2 additions & 2 deletions keyboards/xelus/pachi/rgb/config.h
Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@
#define LOCKING_RESYNC_ENABLE

// I2C setup
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_SCL_PAL_MODE 4
#define I2C1_SDA_PAL_MODE 4
#define I2C1_TIMINGR_PRESC 0U
4 changes: 2 additions & 2 deletions keyboards/xelus/valor/rev2/config.h
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@
#define LOCKING_RESYNC_ENABLE

// I2C setup
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_SCL_PAL_MODE 4
#define I2C1_SDA_PAL_MODE 4
#define I2C1_TIMINGR_PRESC 0U
4 changes: 2 additions & 2 deletions keyboards/xelus/valor_frl_tkl/config.h
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@
#define LOCKING_RESYNC_ENABLE

// I2C OLED defines
#define I2C1_SCL 8
#define I2C1_SDA 9
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B 9
zvecr marked this conversation as resolved.
Show resolved Hide resolved

#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1
12 changes: 6 additions & 6 deletions platforms/chibios/drivers/i2c_master.c
Original file line number Diff line number Diff line change
@@ -63,16 +63,16 @@ __attribute__((weak)) void i2c_init(void) {
is_initialised = true;

// Try releasing special pins for a short time
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
palSetLineMode(I2C1_SCL_PIN, PAL_MODE_INPUT);
palSetLineMode(I2C1_SDA_PIN, PAL_MODE_INPUT);

chThdSleepMilliseconds(10);
#if defined(USE_GPIOV1)
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, I2C1_SCL_PAL_MODE);
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, I2C1_SDA_PAL_MODE);
palSetLineMode(I2C1_SCL_PIN, I2C1_SCL_PAL_MODE);
palSetLineMode(I2C1_SDA_PIN, I2C1_SDA_PAL_MODE);
#else
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
palSetLineMode(I2C1_SCL_PIN, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
palSetLineMode(I2C1_SDA_PIN, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
#endif
}
}
21 changes: 4 additions & 17 deletions platforms/chibios/drivers/i2c_master.h
Original file line number Diff line number Diff line change
@@ -27,24 +27,11 @@
#include <ch.h>
#include <hal.h>

#ifdef I2C1_BANK
# define I2C1_SCL_BANK I2C1_BANK
# define I2C1_SDA_BANK I2C1_BANK
#ifndef I2C1_SCL_PIN
# define I2C1_SCL_PIN B6
#endif

#ifndef I2C1_SCL_BANK
# define I2C1_SCL_BANK GPIOB
#endif

#ifndef I2C1_SDA_BANK
# define I2C1_SDA_BANK GPIOB
#endif

#ifndef I2C1_SCL
# define I2C1_SCL 6
#endif
#ifndef I2C1_SDA
# define I2C1_SDA 7
#ifndef I2C1_SDA_PIN
# define I2C1_SDA_PIN B7
#endif

#ifdef USE_I2CV1