Skip to content

Commit 836a530

Browse files
committed
Issue #992 - Apply proposed patch
1 parent 184039f commit 836a530

File tree

16 files changed

+302
-50
lines changed

16 files changed

+302
-50
lines changed

src/boards/B-L072Z-LRWAN1/i2c-board.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,25 @@ void I2cSetAddrSize( I2c_t *obj, I2cAddrSize addrSize )
106106
I2cInternalAddrSize = addrSize;
107107
}
108108

109-
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
109+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
110+
{
111+
uint8_t status = FAIL;
112+
113+
status = ( HAL_I2C_Master_Transmit( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
114+
115+
return status;
116+
}
117+
118+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
119+
{
120+
uint8_t status = FAIL;
121+
122+
status = ( HAL_I2C_Master_Receive( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
123+
124+
return status;
125+
}
126+
127+
uint8_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
110128
{
111129
uint8_t status = FAIL;
112130
uint16_t memAddSize = 0;
@@ -124,7 +142,7 @@ uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_
124142
return status;
125143
}
126144

127-
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
145+
uint8_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
128146
{
129147
uint8_t status = FAIL;
130148
uint16_t memAddSize = 0;

src/boards/NAMote72/i2c-board.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,25 @@ void I2cSetAddrSize( I2c_t *obj, I2cAddrSize addrSize )
105105
I2cInternalAddrSize = addrSize;
106106
}
107107

108-
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
108+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
109+
{
110+
uint8_t status = FAIL;
111+
112+
status = ( HAL_I2C_Master_Transmit( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
113+
114+
return status;
115+
}
116+
117+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
118+
{
119+
uint8_t status = FAIL;
120+
121+
status = ( HAL_I2C_Master_Receive( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
122+
123+
return status;
124+
}
125+
126+
uint8_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
109127
{
110128
uint8_t status = FAIL;
111129
uint16_t memAddSize = 0;
@@ -123,7 +141,7 @@ uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_
123141
return status;
124142
}
125143

126-
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
144+
uint8_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
127145
{
128146
uint8_t status = FAIL;
129147
uint16_t memAddSize = 0;

src/boards/NucleoL073/i2c-board.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,25 @@ void I2cSetAddrSize( I2c_t *obj, I2cAddrSize addrSize )
106106
I2cInternalAddrSize = addrSize;
107107
}
108108

109-
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
109+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
110+
{
111+
uint8_t status = FAIL;
112+
113+
status = ( HAL_I2C_Master_Transmit( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
114+
115+
return status;
116+
}
117+
118+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
119+
{
120+
uint8_t status = FAIL;
121+
122+
status = ( HAL_I2C_Master_Receive( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
123+
124+
return status;
125+
}
126+
127+
uint8_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
110128
{
111129
uint8_t status = FAIL;
112130
uint16_t memAddSize = 0;
@@ -124,7 +142,7 @@ uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_
124142
return status;
125143
}
126144

127-
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
145+
uint8_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
128146
{
129147
uint8_t status = FAIL;
130148
uint16_t memAddSize = 0;

src/boards/NucleoL152/i2c-board.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,25 @@ void I2cSetAddrSize( I2c_t *obj, I2cAddrSize addrSize )
105105
I2cInternalAddrSize = addrSize;
106106
}
107107

108-
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
108+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
109+
{
110+
uint8_t status = FAIL;
111+
112+
status = ( HAL_I2C_Master_Transmit( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
113+
114+
return status;
115+
}
116+
117+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
118+
{
119+
uint8_t status = FAIL;
120+
121+
status = ( HAL_I2C_Master_Receive( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
122+
123+
return status;
124+
}
125+
126+
uint8_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
109127
{
110128
uint8_t status = FAIL;
111129
uint16_t memAddSize = 0;
@@ -123,7 +141,7 @@ uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_
123141
return status;
124142
}
125143

126-
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
144+
uint8_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
127145
{
128146
uint8_t status = FAIL;
129147
uint16_t memAddSize = 0;

src/boards/NucleoL476/i2c-board.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,25 @@ void I2cSetAddrSize( I2c_t *obj, I2cAddrSize addrSize )
105105
I2cInternalAddrSize = addrSize;
106106
}
107107

108-
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
108+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
109+
{
110+
uint8_t status = FAIL;
111+
112+
status = ( HAL_I2C_Master_Transmit( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
113+
114+
return status;
115+
}
116+
117+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
118+
{
119+
uint8_t status = FAIL;
120+
121+
status = ( HAL_I2C_Master_Receive( &I2cHandle, deviceAddr, buffer, size, 2000 ) == HAL_OK ) ? SUCCESS : FAIL;
122+
123+
return status;
124+
}
125+
126+
uint8_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
109127
{
110128
uint8_t status = FAIL;
111129
uint16_t memAddSize = 0;
@@ -123,7 +141,7 @@ uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_
123141
return status;
124142
}
125143

126-
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
144+
uint8_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size )
127145
{
128146
uint8_t status = FAIL;
129147
uint16_t memAddSize = 0;

src/boards/SAMR34/i2c-board.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void I2cMcuFormat( I2c_t* obj, I2cMode mode, I2cDutyCycle dutyCycle, bool I2cAck
7373
return;
7474
}
7575

76-
uint8_t I2cMcuWriteBuffer( I2c_t* obj, uint8_t deviceAddr, uint16_t addr, uint8_t* buffer, uint16_t size )
76+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
7777
{
7878
i2c_m_sync_set_slaveaddr( &I2C_INSTANCE, deviceAddr, I2C_M_SEVEN );
7979
if( io_write( &I2C_INSTANCE.io, buffer, size ) == size )
@@ -86,7 +86,7 @@ uint8_t I2cMcuWriteBuffer( I2c_t* obj, uint8_t deviceAddr, uint16_t addr, uint8_
8686
}
8787
}
8888

89-
uint8_t I2cMcuReadBuffer( I2c_t* obj, uint8_t deviceAddr, uint16_t addr, uint8_t* buffer, uint16_t size )
89+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size )
9090
{
9191
i2c_m_sync_set_slaveaddr( &I2C_INSTANCE, deviceAddr, I2C_M_SEVEN );
9292
if( io_read( &I2C_INSTANCE.io, buffer, size ) == size )
@@ -97,4 +97,30 @@ uint8_t I2cMcuReadBuffer( I2c_t* obj, uint8_t deviceAddr, uint16_t addr, uint8_t
9797
{
9898
return 0; // something went wrong
9999
}
100+
}
101+
102+
uint8_t I2cMcuWriteMemBuffer( I2c_t* obj, uint8_t deviceAddr, uint16_t addr, uint8_t* buffer, uint16_t size )
103+
{
104+
i2c_m_sync_set_slaveaddr( &I2C_INSTANCE, deviceAddr, I2C_M_SEVEN );
105+
if( i2c_m_sync_cmd_write( &I2C_INSTANCE, addr, buffer, size ) == size )
106+
{
107+
return 1; // ok
108+
}
109+
else
110+
{
111+
return 0; // something went wrong
112+
}
113+
}
114+
115+
uint8_t I2cMcuReadMemBuffer( I2c_t* obj, uint8_t deviceAddr, uint16_t addr, uint8_t* buffer, uint16_t size )
116+
{
117+
i2c_m_sync_set_slaveaddr( &I2C_INSTANCE, deviceAddr, I2C_M_SEVEN );
118+
if( i2c_m_sync_cmd_read( &I2C_INSTANCE, addr, buffer, size ) == size )
119+
{
120+
return 1; // ok
121+
}
122+
else
123+
{
124+
return 0; // something went wrong
125+
}
100126
}

src/boards/i2c-board.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,42 @@ void I2cMcuResetBus( I2c_t *obj );
109109
*
110110
* \param [IN] obj I2C object
111111
* \param [IN] deviceAddr device address
112-
* \param [IN] addr data address
113112
* \param [IN] buffer data buffer to write
114113
* \param [IN] size number of data bytes to write
115114
*/
116-
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size );
115+
uint8_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size );
117116

118117
/*!
119118
* \brief Read data buffer from the I2C device
120119
*
121120
* \param [IN] obj I2C object
122121
* \param [IN] deviceAddr device address
122+
* \param [IN] buffer data buffer to read
123+
* \param [IN] size number of data bytes to read
124+
*/
125+
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size );
126+
127+
/*!
128+
* \brief Write data buffer starting at addr to the I2C device
129+
*
130+
* \param [IN] obj I2C object
131+
* \param [IN] deviceAddr device address
132+
* \param [IN] addr data address
133+
* \param [IN] buffer data buffer to write
134+
* \param [IN] size number of data bytes to write
135+
*/
136+
uint8_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size );
137+
138+
/*!
139+
* \brief Read data buffer starting at addr from the I2C device
140+
*
141+
* \param [IN] obj I2C object
142+
* \param [IN] deviceAddr device address
123143
* \param [IN] addr data address
124144
* \param [IN] buffer data buffer to read
125145
* \param [IN] size number of data bytes to read
126146
*/
127-
uint8_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size );
147+
uint8_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size );
128148

129149
/*!
130150
* \brief Waits until the given device is in standby mode

src/peripherals/atecc608a-tnglora-se/atecc608a-tnglora-se-hal.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength)
151151

152152
txdata[0] = 0x3;
153153
txlength++;
154-
if (I2cMcuWriteBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, 0, txdata, (size_t)txlength) == 1)
154+
if (I2cMcuWriteBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, txdata, (size_t)txlength) == 1)
155155
{
156156
return ATCA_SUCCESS;
157157
}
@@ -179,7 +179,7 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength
179179
int retries = iface->mIfaceCFG->rx_retries;
180180
while (--retries > 0 && r != 1)
181181
{
182-
r = I2cMcuReadBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, 0, lengthPackage, 1);
182+
r = I2cMcuReadBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, lengthPackage, 1);
183183
}
184184

185185
if (r != 1)
@@ -202,7 +202,7 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength
202202
retries = iface->mIfaceCFG->rx_retries;
203203
while (--retries > 0 && r != 1)
204204
{
205-
r = I2cMcuReadBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, 0, rxdata + 1, bytesToRead);
205+
r = I2cMcuReadBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, rxdata + 1, bytesToRead);
206206
}
207207

208208
if (r != 1)
@@ -234,7 +234,7 @@ ATCA_STATUS hal_i2c_wake(ATCAIface iface)
234234
{
235235
// 2. Send NULL buffer to address 0x0 (NACK)
236236
uint8_t emptybuff[1] = {0};
237-
int r = I2cMcuWriteBuffer((I2c_t *)NULL, 0x00, 0, emptybuff, (size_t)0);
237+
int r = I2cMcuWriteBuffer((I2c_t *)NULL, 0x00, emptybuff, (size_t)0);
238238

239239
// 3. Wait for wake_delay
240240
atca_delay_us(iface->mIfaceCFG->wake_delay);
@@ -246,7 +246,7 @@ ATCA_STATUS hal_i2c_wake(ATCAIface iface)
246246
int retries = iface->mIfaceCFG->rx_retries;
247247
while (--retries > 0 && r != 1)
248248
{
249-
r = I2cMcuReadBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, 0, rx_buffer, 4);
249+
r = I2cMcuReadBuffer((I2c_t *)NULL, iface->mIfaceCFG->atcai2c.slave_address, rx_buffer, 4);
250250
}
251251

252252
// 5. Set frequency back to requested one
@@ -272,7 +272,7 @@ ATCA_STATUS hal_i2c_wake(ATCAIface iface)
272272
ATCA_STATUS hal_i2c_idle(ATCAIface iface)
273273
{
274274
uint8_t buffer[1] = { 0x2 }; // idle word address value
275-
I2cMcuWriteBuffer((I2c_t*)NULL, iface->mIfaceCFG->atcai2c.slave_address,0, buffer, (size_t)1);
275+
I2cMcuWriteBuffer((I2c_t*)NULL, iface->mIfaceCFG->atcai2c.slave_address, buffer, (size_t)1);
276276
return ATCA_SUCCESS;
277277
}
278278

@@ -284,7 +284,7 @@ ATCA_STATUS hal_i2c_idle(ATCAIface iface)
284284
ATCA_STATUS hal_i2c_sleep(ATCAIface iface)
285285
{
286286
uint8_t buffer[1] = { 0x1 }; // sleep word address value
287-
I2cMcuWriteBuffer((I2c_t*)NULL, iface->mIfaceCFG->atcai2c.slave_address,0, buffer, (size_t)1);
287+
I2cMcuWriteBuffer((I2c_t*)NULL, iface->mIfaceCFG->atcai2c.slave_address, buffer, (size_t)1);
288288
return ATCA_SUCCESS;
289289
}
290290

src/peripherals/mag3110.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ uint8_t MAG3110Write( uint8_t addr, uint8_t data )
6767

6868
uint8_t MAG3110WriteBuffer( uint8_t addr, uint8_t *data, uint8_t size )
6969
{
70-
return I2cWriteBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
70+
return I2cWriteMemBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
7171
}
7272

7373
uint8_t MAG3110Read( uint8_t addr, uint8_t *data )
@@ -77,7 +77,7 @@ uint8_t MAG3110Read( uint8_t addr, uint8_t *data )
7777

7878
uint8_t MAG3110ReadBuffer( uint8_t addr, uint8_t *data, uint8_t size )
7979
{
80-
return I2cReadBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
80+
return I2cReadMemBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
8181
}
8282

8383
void MAG3110SetDeviceAddr( uint8_t addr )

src/peripherals/mma8451.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ uint8_t MMA8451Write( uint8_t addr, uint8_t data )
125125

126126
uint8_t MMA8451WriteBuffer( uint8_t addr, uint8_t *data, uint8_t size )
127127
{
128-
return I2cWriteBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
128+
return I2cWriteMemBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
129129
}
130130

131131
uint8_t MMA8451Read( uint8_t addr, uint8_t *data )
@@ -135,7 +135,7 @@ uint8_t MMA8451Read( uint8_t addr, uint8_t *data )
135135

136136
uint8_t MMA8451ReadBuffer( uint8_t addr, uint8_t *data, uint8_t size )
137137
{
138-
return I2cReadBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
138+
return I2cReadMemBuffer( &I2c, I2cDeviceAddr << 1, addr, data, size );
139139
}
140140

141141
void MMA8451SetDeviceAddr( uint8_t addr )

0 commit comments

Comments
 (0)