Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
76782f2c
Unverified
Commit
76782f2c
authored
Nov 13, 2023
by
Me No Dev
Committed by
GitHub
Nov 13, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fully guard I2C Slave in preparation for C2 support (#8882)
parent
82e5fe8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
4 deletions
+31
-4
libraries/Wire/examples/WireSlave/.skip.esp32c2
libraries/Wire/examples/WireSlave/.skip.esp32c2
+0
-0
libraries/Wire/src/Wire.cpp
libraries/Wire/src/Wire.cpp
+24
-3
libraries/Wire/src/Wire.h
libraries/Wire/src/Wire.h
+7
-1
No files found.
libraries/Wire/examples/WireSlave/.skip.esp32c2
0 → 100644
View file @
76782f2c
libraries/Wire/src/Wire.cpp
View file @
76782f2c
...
...
@@ -32,7 +32,9 @@ extern "C" {
}
#include "esp32-hal-i2c.h"
#if SOC_I2C_SUPPORT_SLAVE
#include "esp32-hal-i2c-slave.h"
#endif
/* SOC_I2C_SUPPORT_SLAVE */
#include "Wire.h"
#include "Arduino.h"
...
...
@@ -53,9 +55,11 @@ TwoWire::TwoWire(uint8_t bus_num)
,
nonStopTask
(
NULL
)
,
lock
(
NULL
)
#endif
#if SOC_I2C_SUPPORT_SLAVE
,
is_slave
(
false
)
,
user_onRequest
(
NULL
)
,
user_onReceive
(
NULL
)
#endif
/* SOC_I2C_SUPPORT_SLAVE */
{}
TwoWire
::~
TwoWire
()
...
...
@@ -297,10 +301,12 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
return
false
;
}
#endif
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
log_e
(
"Bus already started in Slave Mode."
);
goto
end
;
}
#endif
/* SOC_I2C_SUPPORT_SLAVE */
if
(
i2cIsInit
(
num
)){
log_w
(
"Bus already started in Master Mode."
);
started
=
true
;
...
...
@@ -337,12 +343,15 @@ bool TwoWire::end()
return
false
;
}
#endif
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
err
=
i2cSlaveDeinit
(
num
);
if
(
err
==
ESP_OK
){
is_slave
=
false
;
}
}
else
if
(
i2cIsInit
(
num
)){
}
else
#endif
/* SOC_I2C_SUPPORT_SLAVE */
if
(
i2cIsInit
(
num
)){
err
=
i2cDeinit
(
num
);
}
freeWireBuffer
();
...
...
@@ -363,9 +372,12 @@ uint32_t TwoWire::getClock()
log_e
(
"could not acquire lock"
);
}
else
{
#endif
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
log_e
(
"Bus is in Slave Mode"
);
}
else
{
}
else
#endif
/* SOC_I2C_SUPPORT_SLAVE */
{
i2cGetClock
(
num
,
&
frequency
);
}
#if !CONFIG_DISABLE_HAL_LOCKS
...
...
@@ -386,10 +398,13 @@ bool TwoWire::setClock(uint32_t frequency)
return
false
;
}
#endif
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
log_e
(
"Bus is in Slave Mode"
);
err
=
ESP_FAIL
;
}
else
{
}
else
#endif
/* SOC_I2C_SUPPORT_SLAVE */
{
err
=
i2cSetClock
(
num
,
frequency
);
}
#if !CONFIG_DISABLE_HAL_LOCKS
...
...
@@ -411,10 +426,12 @@ uint16_t TwoWire::getTimeOut()
void
TwoWire
::
beginTransmission
(
uint16_t
address
)
{
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
log_e
(
"Bus is in Slave Mode"
);
return
;
}
#endif
/* SOC_I2C_SUPPORT_SLAVE */
#if !CONFIG_DISABLE_HAL_LOCKS
if
(
nonStop
&&
nonStopTask
==
xTaskGetCurrentTaskHandle
()){
log_e
(
"Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing..."
);
...
...
@@ -444,10 +461,12 @@ endTransmission() returns:
*/
uint8_t
TwoWire
::
endTransmission
(
bool
sendStop
)
{
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
log_e
(
"Bus is in Slave Mode"
);
return
4
;
}
#endif
/* SOC_I2C_SUPPORT_SLAVE */
if
(
txBuffer
==
NULL
){
log_e
(
"NULL TX buffer pointer"
);
return
4
;
...
...
@@ -477,10 +496,12 @@ uint8_t TwoWire::endTransmission(bool sendStop)
size_t
TwoWire
::
requestFrom
(
uint16_t
address
,
size_t
size
,
bool
sendStop
)
{
#if SOC_I2C_SUPPORT_SLAVE
if
(
is_slave
){
log_e
(
"Bus is in Slave Mode"
);
return
0
;
}
#endif
/* SOC_I2C_SUPPORT_SLAVE */
if
(
rxBuffer
==
NULL
||
txBuffer
==
NULL
){
log_e
(
"NULL buffer pointer"
);
return
0
;
...
...
libraries/Wire/src/Wire.h
View file @
76782f2c
...
...
@@ -45,8 +45,10 @@
#ifndef I2C_BUFFER_LENGTH
#define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t)
#endif
#if SOC_I2C_SUPPORT_SLAVE
typedef
void
(
*
user_onRequest
)(
void
);
typedef
void
(
*
user_onReceive
)(
uint8_t
*
,
int
);
#endif
/* SOC_I2C_SUPPORT_SLAVE */
class
TwoWire
:
public
Stream
{
...
...
@@ -71,8 +73,8 @@ protected:
SemaphoreHandle_t
lock
;
#endif
private:
bool
is_slave
;
#if SOC_I2C_SUPPORT_SLAVE
bool
is_slave
;
void
(
*
user_onRequest
)(
void
);
void
(
*
user_onReceive
)(
int
);
static
void
onRequestService
(
uint8_t
,
void
*
);
...
...
@@ -90,12 +92,15 @@ public:
bool
setPins
(
int
sda
,
int
scl
);
bool
begin
(
int
sda
,
int
scl
,
uint32_t
frequency
=
0
);
// returns true, if successful init of i2c bus
#if SOC_I2C_SUPPORT_SLAVE
bool
begin
(
uint8_t
slaveAddr
,
int
sda
,
int
scl
,
uint32_t
frequency
);
#endif
/* SOC_I2C_SUPPORT_SLAVE */
// Explicit Overload for Arduino MainStream API compatibility
inline
bool
begin
()
{
return
begin
(
-
1
,
-
1
,
static_cast
<
uint32_t
>
(
0
));
}
#if SOC_I2C_SUPPORT_SLAVE
inline
bool
begin
(
uint8_t
addr
)
{
return
begin
(
addr
,
-
1
,
-
1
,
0
);
...
...
@@ -104,6 +109,7 @@ public:
{
return
begin
(
static_cast
<
uint8_t
>
(
addr
),
-
1
,
-
1
,
0
);
}
#endif
/* SOC_I2C_SUPPORT_SLAVE */
bool
end
();
size_t
setBufferSize
(
size_t
bSize
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment