aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports
diff options
context:
space:
mode:
authorFabio Utzig <utzig@utzig.org>2019-07-27 16:15:21 -0300
committerGitHub <noreply@github.com>2019-07-27 16:15:21 -0300
commit62161f8106b99a705d0f7ce59c4e4f3e9249aad5 (patch)
tree99f39594a929a32401ba58872805fb0047d0a9ae /os/hal/ports
parent9abc320aa536698bfe04a158a282ea3cf7daea90 (diff)
parentb5332141f06b23c5708adba6b356746e54be665e (diff)
downloadChibiOS-Contrib-62161f8106b99a705d0f7ce59c4e4f3e9249aad5.tar.gz
ChibiOS-Contrib-62161f8106b99a705d0f7ce59c4e4f3e9249aad5.tar.bz2
ChibiOS-Contrib-62161f8106b99a705d0f7ce59c4e4f3e9249aad5.zip
Merge pull request #192 from fabio-d/nrf-i2c-pullup
NRF51/NRF52: Added support for internal I2C pull-ups
Diffstat (limited to 'os/hal/ports')
-rw-r--r--os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.c24
-rw-r--r--os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.h4
-rw-r--r--os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.c24
-rw-r--r--os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.h4
4 files changed, 32 insertions, 24 deletions
diff --git a/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.c b/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.c
index 957c0be..7d5a26d 100644
--- a/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.c
+++ b/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.c
@@ -38,17 +38,17 @@
#define I2C_INPUT(p) do { IOPORT1->DIRCLR = (1UL << (p)); } while(0) /*!< Configures I2C pin as input */
#define I2C_OUTPUT(p) do { IOPORT1->DIRSET = (1UL << (p)); } while(0) /*!< Configures I2C pin as output */
-#define I2C_PIN_CNF \
+#define I2C_PIN_CNF(internal_pullup) \
((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
| (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) \
+ | (((internal_pullup) ? GPIO_PIN_CNF_PULL_Pullup : GPIO_PIN_CNF_PULL_Disabled) << GPIO_PIN_CNF_PULL_Pos) \
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos))
-#define I2C_PIN_CNF_CLR \
+#define I2C_PIN_CNF_CLR(internal_pullup) \
((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
| (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) \
+ | (((internal_pullup) ? GPIO_PIN_CNF_PULL_Pullup : GPIO_PIN_CNF_PULL_Disabled) << GPIO_PIN_CNF_PULL_Pos) \
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))
@@ -97,14 +97,14 @@ static void i2c_clear_bus(I2CDriver *i2cp) {
const I2CConfig *cfg = i2cp->config;
uint8_t i;
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF(cfg->sda_pullup);
I2C_HIGH(cfg->sda_pad);
I2C_HIGH(cfg->scl_pad);
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR(cfg->sda_pullup);
nrf_delay_us(4);
@@ -233,8 +233,8 @@ void i2c_lld_start(I2CDriver *i2cp) {
i2c_clear_bus(i2cp);
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF(cfg->sda_pullup);
i2c->SHORTS = 0;
@@ -300,8 +300,8 @@ void i2c_lld_stop(I2CDriver *i2cp) {
i2c->ENABLE = TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos;
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR(cfg->sda_pullup);
}
}
diff --git a/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.h b/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.h
index fb88a5e..a73efc7 100644
--- a/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.h
+++ b/os/hal/ports/NRF5/LLD/TWIMv1/hal_i2c_lld.h
@@ -113,6 +113,10 @@ typedef struct {
uint8_t scl_pad;
/* @brief Pad number for SDA */
uint8_t sda_pad;
+ /* @brief Whether to use the internal pull-up for SCL */
+ bool scl_pullup;
+ /* @brief Whether to use the internal pull-up for SDA */
+ bool sda_pullup;
} I2CConfig;
diff --git a/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.c b/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.c
index 9f75906..a9391dd 100644
--- a/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.c
+++ b/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.c
@@ -38,17 +38,17 @@
#define I2C_INPUT(p) do { IOPORT1->DIRCLR = (1UL << (p)); } while(0) /*!< Configures I2C pin as input */
#define I2C_OUTPUT(p) do { IOPORT1->DIRSET = (1UL << (p)); } while(0) /*!< Configures I2C pin as output */
-#define I2C_PIN_CNF \
+#define I2C_PIN_CNF(internal_pullup) \
((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
| (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) \
+ | (((internal_pullup) ? GPIO_PIN_CNF_PULL_Pullup : GPIO_PIN_CNF_PULL_Disabled) << GPIO_PIN_CNF_PULL_Pos) \
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos))
-#define I2C_PIN_CNF_CLR \
+#define I2C_PIN_CNF_CLR(internal_pullup) \
((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
| (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) \
+ | (((internal_pullup) ? GPIO_PIN_CNF_PULL_Pullup : GPIO_PIN_CNF_PULL_Disabled) << GPIO_PIN_CNF_PULL_Pos) \
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))
@@ -102,14 +102,14 @@ static void i2c_clear_bus(I2CDriver *i2cp)
const I2CConfig *cfg = i2cp->config;
int i;
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF(cfg->sda_pullup);
I2C_HIGH(cfg->sda_pad);
I2C_HIGH(cfg->scl_pad);
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR(cfg->sda_pullup);
nrf_delay_us(4);
@@ -290,8 +290,8 @@ void i2c_lld_start(I2CDriver *i2cp) {
i2c_clear_bus(i2cp);
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF(cfg->sda_pullup);
i2c->EVENTS_RXDREADY = 0;
i2c->EVENTS_TXDSENT = 0;
@@ -351,8 +351,8 @@ void i2c_lld_stop(I2CDriver *i2cp) {
nvicDisableVector(I2C_IRQ_NUM);
- IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR;
- IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR;
+ IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR(cfg->scl_pullup);
+ IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR(cfg->sda_pullup);
}
}
diff --git a/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.h b/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.h
index 7a4050b..f126983 100644
--- a/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.h
+++ b/os/hal/ports/NRF5/LLD/TWIv1/hal_i2c_lld.h
@@ -121,6 +121,10 @@ typedef struct {
uint8_t scl_pad;
/* @brief Pad number for SDA */
uint8_t sda_pad;
+ /* @brief Whether to use the internal pull-up for SCL */
+ bool scl_pullup;
+ /* @brief Whether to use the internal pull-up for SDA */
+ bool sda_pullup;
} I2CConfig;