Skip to content

Commit ba2e707

Browse files
author
Wu Han
committed
Use #ifde for compatibility
1 parent 1a17a71 commit ba2e707

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

port/i2c_soft_init.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,110 @@
11
#include "i2c_soft_init.h"
22

3+
#ifdef SOC_STM32F1
4+
#include <stm32f10x.h>
5+
#endif
6+
37
void stm32_set_sda(void *data, rt_int32_t state)
48
{
9+
// examples for STM32F103x
10+
#ifdef SOC_STM32F1
511
if(state == 1)
612
GPIO_SetBits(I2C1_GPIO , I2C1_GPIO_SDA); //GPIOB->BSRRL = I2C1_GPIO_SDA
713
// rt_pin_write(I2C1_GPIO_SDA,PIN_HIGH);
814
else if(state == 0)
915
GPIO_ResetBits(I2C1_GPIO , I2C1_GPIO_SDA); //GPIOB->BSRRH = I2C1_GPIO_SDA
1016
// rt_pin_write(I2C1_GPIO_SDA,PIN_LOW);
17+
#endif
1118
}
1219

1320
void stm32_set_scl(void *data, rt_int32_t state)
1421
{
22+
// examples for STM32F103x
23+
#ifdef SOC_STM32F1
1524
if(state == 1)
1625
GPIO_SetBits(I2C1_GPIO , I2C1_GPIO_SCL); //GPIOB->BSRRL = I2C1_GPIO_SCL
1726
// rt_pin_write(I2C1_GPIO_SCL,PIN_HIGH);
1827
else if(state == 0)
1928
GPIO_ResetBits(I2C1_GPIO , I2C1_GPIO_SCL); //GPIOB->BSRRH = I2C1_GPIO_SCL
2029
// rt_pin_write(I2C1_GPIO_SCL,PIN_LOW);
30+
#endif
2131
}
2232

2333
rt_int32_t stm32_get_sda(void *data)
2434
{
35+
// examples for STM32F103x
36+
#ifdef SOC_STM32F1
2537
return (rt_int32_t)GPIO_ReadInputDataBit(I2C1_GPIO , I2C1_GPIO_SDA);//return(GPIOB->IDR & I2C1_GPIO_SDA)
26-
// return rt_pin_read(I2C1_GPIO_SDA);
38+
#endif
39+
// return rt_pin_read(I2C1_GPIO_SDA);
2740
}
2841

2942
rt_int32_t stm32_get_scl(void *data)
3043
{
44+
// examples for STM32F103x
45+
#ifdef SOC_STM32F1
3146
return (rt_int32_t)GPIO_ReadInputDataBit(I2C1_GPIO , I2C1_GPIO_SCL);//return(GPIOB->IDR & I2C1_GPIO_SCL)
32-
// return rt_pin_read(I2C1_GPIO_SCL);
47+
#endif
48+
// return rt_pin_read(I2C1_GPIO_SCL);
3349
}
3450

3551
void stm32_udelay(rt_uint32_t us)
3652
{
53+
// examples for STM32F103x
54+
#ifdef SOC_STM32F1
3755
rt_uint32_t delta;
3856
/* sysTick->LOAD=21000, RT_TICK_PER_SECOND=1000 */
3957
us = us * (SysTick->LOAD/(1000000/RT_TICK_PER_SECOND));
4058
delta = SysTick->VAL;
4159
/* delay us */
4260
while (delta - SysTick->VAL< us);
61+
#endif
4362
}
4463

4564
void stm32_mdelay(rt_uint32_t ms)
4665
{
47-
stm32_udelay(ms * 1000);
66+
// examples for STM32F103x
67+
#ifdef SOC_STM32F1
68+
stm32_udelay(ms * 1000);
69+
#endif
4870
}
4971

5072
static const struct rt_i2c_bit_ops stm32_i2c_bit_ops =
5173
{
74+
// examples for STM32F103x
75+
#ifdef SOC_STM32F1
5276
(void*)0xaa, //no use in set_sda,set_scl,get_sda,get_scl
5377
stm32_set_sda,
5478
stm32_set_scl,
5579
stm32_get_sda,
5680
stm32_get_scl,
5781
stm32_udelay,
58-
20,
82+
20,
83+
#endif
5984
};
6085

6186
static void RCC_Configuration(void)
6287
{
88+
// examples for STM32F103x
89+
#ifdef SOC_STM32F1
6390
RCC->APB2ENR|=1<<4;
6491
RCC_APB2PeriphClockCmd( RCC_I2C, ENABLE );
92+
#endif
6593
}
6694

6795

6896
static void GPIO_Configuration(void)
6997
{
70-
98+
// examples for STM32F103x
99+
#ifdef SOC_STM32F1
71100
GPIO_InitTypeDef GPIO_InitStructure;
72101
GPIO_InitStructure.GPIO_Pin = I2C1_GPIO_SDA | I2C1_GPIO_SCL;
73102
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_OD ;
74103
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
75104

76105
GPIO_Init(I2C1_GPIO, &GPIO_InitStructure);
77-
106+
#endif
107+
78108
// rt_pin_mode(I2C1_GPIO_SDA, PIN_MODE_OUTPUT_OD);
79109
// rt_pin_mode(I2C1_GPIO_SCL, PIN_MODE_OUTPUT_OD);
80110

port/i2c_soft_init.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef __I2C_SOFT_INIT_H__
22
#define __I2C_SOFT_INIT_H__
33

4-
#include <stm32f10x.h>
54
#include <rtthread.h>
65
#include <rtdevice.h>
76
#include <drivers/i2c-bit-ops.h>

0 commit comments

Comments
 (0)