Skip to content

Commit 04f940d

Browse files
authored
Merge pull request #3324 from LMESTM/dev_i2c_common_code
Dev i2c common code
2 parents 1636671 + 29b32b8 commit 04f940d

File tree

68 files changed

+4708
-6335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4708
-6335
lines changed

features/unsupported/tests/mbed/i2c_master_slave_asynch/main.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ I2C master(PB_9, PB_8);
3232
I2C master(D14, D15); // I2C_SDA, I2C_SCL
3333
#endif
3434

35-
#if defined (TARGET_NUCLEO_F429ZI) || \
35+
#if defined (TARGET_NUCLEO_F072RB) || \
36+
defined (TARGET_NUCLEO_F030R8) || \
37+
defined (TARGET_NUCLEO_F103RB) || \
38+
defined (TARGET_NUCLEO_F207ZG) || \
39+
defined (TARGET_NUCLEO_F446ZE) || \
40+
defined (TARGET_NUCLEO_F429ZI) || \
3641
defined (TARGET_DISCO_F429ZI) || \
37-
defined (TARGET_NUCLEO_F446ZE)
42+
defined (TARGET_NUCLEO_F767ZI) || \
43+
defined (TARGET_NUCLEO_L053R8) || \
44+
defined (TARGET_NUCLEO_L152RE) || \
45+
defined (TARGET_NUCLEO_L476RG)
3846
I2CSlave slave(PB_11, PB_10);
39-
47+
#elif defined(TARGET_NUCLEO_F303RE)
48+
I2CSlave slave(D2, D8);
4049
#else
4150
I2CSlave slave(D3, D6);
42-
4351
#endif
4452

4553
volatile int why;
@@ -95,7 +103,8 @@ int main()
95103

96104
while (!master_complete) {
97105
if(slave.receive() == I2CSlave::ReadAddressed) {
98-
slave.write(buf_slave, SIZE);
106+
if(slave.write(buf_slave, SIZE))
107+
notify_completion(false);
99108
}
100109
}
101110
if (why != I2C_EVENT_TRANSFER_COMPLETE) {

targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ struct dac_s {
6666
uint32_t channel;
6767
};
6868

69-
struct i2c_s {
70-
I2CName i2c;
71-
};
72-
7369
#include "common_objects.h"
7470
#include "gpio_object.h"
7571

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ struct analogin_s {
6060
uint32_t channel;
6161
};
6262

63-
struct i2c_s {
64-
I2CName i2c;
65-
};
66-
6763
#include "common_objects.h"
6864
#include "gpio_object.h"
6965

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ struct analogin_s {
6060
uint32_t channel;
6161
};
6262

63-
struct i2c_s {
64-
I2CName i2c;
65-
};
66-
6763
#include "common_objects.h"
6864
#include "gpio_object.h"
6965

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ struct analogin_s {
6060
uint32_t channel;
6161
};
6262

63-
struct i2c_s {
64-
I2CName i2c;
65-
};
66-
6763
struct can_s {
6864
CANName can;
6965
int index;

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ struct analogin_s {
6060
uint32_t channel;
6161
};
6262

63-
struct i2c_s {
64-
I2CName i2c;
65-
};
66-
6763
#include "common_objects.h"
6864
#include "gpio_object.h"
6965

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ struct dac_s {
6666
uint32_t channel;
6767
};
6868

69-
struct i2c_s {
70-
I2CName i2c;
71-
};
72-
7369
struct can_s {
7470
CANName can;
7571
int index;

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ struct dac_s {
6666
uint32_t channel;
6767
};
6868

69-
struct i2c_s {
70-
I2CName i2c;
71-
};
72-
7369
struct can_s {
7470
CANName can;
7571
int index;

targets/TARGET_STM/TARGET_STM32F0/common_objects.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ struct serial_s {
8282
#endif
8383
};
8484

85+
struct i2c_s {
86+
/* The 1st 2 members I2CName i2c
87+
* and I2C_HandleTypeDef handle should
88+
* be kept as the first members of this struct
89+
* to ensure i2c_get_obj to work as expected
90+
*/
91+
I2CName i2c;
92+
I2C_HandleTypeDef handle;
93+
uint8_t index;
94+
int hz;
95+
PinName sda;
96+
PinName scl;
97+
IRQn_Type event_i2cIRQ;
98+
IRQn_Type error_i2cIRQ;
99+
uint32_t XferOperation;
100+
volatile uint8_t event;
101+
#if DEVICE_I2CSLAVE
102+
uint8_t slave;
103+
volatile uint8_t pending_slave_tx_master_rx;
104+
volatile uint8_t pending_slave_rx_maxter_tx;
105+
#endif
106+
#if DEVICE_I2C_ASYNCH
107+
uint32_t address;
108+
uint8_t stop;
109+
uint8_t available_events;
110+
#endif
111+
};
112+
85113
#include "gpio_object.h"
86114

87115
#ifdef __cplusplus

targets/TARGET_STM/TARGET_STM32F0/device/stm32f0xx_hal_i2c.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25852585
/* Prepare transfer parameters */
25862586
hi2c->pBuffPtr = pData;
25872587
hi2c->XferCount = Size;
2588-
hi2c->XferOptions = XferOptions;
2588+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
25892589
hi2c->XferISR = I2C_Master_ISR_IT;
25902590

25912591
/* If size > MAX_NBYTE_SIZE, use reload mode */
@@ -2598,15 +2598,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25982598
{
25992599
hi2c->XferSize = hi2c->XferCount;
26002600
xfermode = hi2c->XferOptions;
2601-
2602-
/* If transfer direction not change, do not generate Restart Condition */
2603-
/* Mean Previous state is same as current state */
2604-
if(hi2c->PreviousState == I2C_STATE_SLAVE_BUSY_TX)
2605-
{
2606-
xferrequest = I2C_NO_STARTSTOP;
2607-
}
26082601
}
2609-
26102602

26112603
/* Send Slave Address and set NBYTES to write */
26122604
I2C_TransferConfig(hi2c, DevAddress, hi2c->XferSize, xfermode, xferrequest);
@@ -2659,7 +2651,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26592651
/* Prepare transfer parameters */
26602652
hi2c->pBuffPtr = pData;
26612653
hi2c->XferCount = Size;
2662-
hi2c->XferOptions = XferOptions;
2654+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
26632655
hi2c->XferISR = I2C_Master_ISR_IT;
26642656

26652657
/* If hi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
@@ -2672,13 +2664,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26722664
{
26732665
hi2c->XferSize = hi2c->XferCount;
26742666
xfermode = hi2c->XferOptions;
2675-
2676-
/* If transfer direction not change, do not generate Restart Condition */
2677-
/* Mean Previous state is same as current state */
2678-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_RX)
2679-
{
2680-
xferrequest = I2C_NO_STARTSTOP;
2681-
}
26822667
}
26832668

26842669
/* Send Slave Address and set NBYTES to read */

0 commit comments

Comments
 (0)