summaryrefslogtreecommitdiff
path: root/bsp/stm32
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2023-06-27 18:07:57 -0400
committerMan, Jianting (Meco) <[email protected]>2023-06-28 22:08:14 -0400
commit34bc78331c7116aeeb70512dd8d297b7dc88f8d5 (patch)
tree5b8a7d22fefb5d816fccc89bd0493e55bd9721c4 /bsp/stm32
parent4cbc1893bd1f5e19a09fde573c4d1f46c8e5d561 (diff)
[stm32][i2c] replace stm32_udelay as rt_hw_us_delay
Diffstat (limited to 'bsp/stm32')
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_soft_i2c.c42
1 files changed, 4 insertions, 38 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_soft_i2c.c b/bsp/stm32/libraries/HAL_Drivers/drv_soft_i2c.c
index b722b01ed2..545c16d980 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_soft_i2c.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_soft_i2c.c
@@ -6,9 +6,9 @@
* Change Logs:
* Date Author Notes
* 2018-11-08 balanceTWK first version
+ * 2023-06-27 Meco Man replace stm32_udelay as rt_hw_us_delay
*/
-#include <board.h>
#include "drv_soft_i2c.h"
#include "drv_config.h"
@@ -116,40 +116,6 @@ static rt_int32_t stm32_get_scl(void *data)
struct stm32_soft_i2c_config* cfg = (struct stm32_soft_i2c_config*)data;
return rt_pin_read(cfg->scl);
}
-/**
- * The time delay function.
- *
- * @param microseconds.
- */
-static void stm32_udelay(rt_uint32_t us)
-{
- rt_uint32_t ticks;
- rt_uint32_t told, tnow, tcnt = 0;
- rt_uint32_t reload = SysTick->LOAD;
-
- ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
- told = SysTick->VAL;
- while (1)
- {
- tnow = SysTick->VAL;
- if (tnow != told)
- {
- if (tnow < told)
- {
- tcnt += told - tnow;
- }
- else
- {
- tcnt += reload - tnow + told;
- }
- told = tnow;
- if (tcnt >= ticks)
- {
- break;
- }
- }
- }
-}
static const struct rt_i2c_bit_ops stm32_bit_ops_default =
{
@@ -158,7 +124,7 @@ static const struct rt_i2c_bit_ops stm32_bit_ops_default =
.set_scl = stm32_set_scl,
.get_sda = stm32_get_sda,
.get_scl = stm32_get_scl,
- .udelay = stm32_udelay,
+ .udelay = rt_hw_us_delay,
.delay_us = 1,
.timeout = 100
};
@@ -179,9 +145,9 @@ static rt_err_t stm32_i2c_bus_unlock(const struct stm32_soft_i2c_config *cfg)
while (i++ < 9)
{
rt_pin_write(cfg->scl, PIN_HIGH);
- stm32_udelay(100);
+ rt_hw_us_delay(100);
rt_pin_write(cfg->scl, PIN_LOW);
- stm32_udelay(100);
+ rt_hw_us_delay(100);
}
}
if (PIN_LOW == rt_pin_read(cfg->sda))