1
0
Fork 0

Align ChibiOS I2C defs with other drivers (#14399)

* Align ChibiOS I2C defs with other drivers

* Update keyboards/xelus/valor_frl_tkl/config.h

Co-authored-by: Ryan <fauxpark@gmail.com>

Co-authored-by: Ryan <fauxpark@gmail.com>
This commit is contained in:
Joel Challis 2021-09-12 15:41:33 +01:00 committed by GitHub
parent bb841087bb
commit 0fa217a5b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 64 additions and 95 deletions

View file

@ -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.

View file

@ -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 の種類に依存します。

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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);
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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).

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 B9
#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1

View file

@ -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
}
}

View file

@ -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