Skip to content

Commit a23310b

Browse files
authored
Add implementation for I2C Slave (#2824)
***NO_CI***
1 parent 659b6ea commit a23310b

15 files changed

+451
-22
lines changed

CMake/Modules/FindNF_NativeAssemblies.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option(API_System.Device.Adc "option for System.Devic
2323
option(API_System.Device.Dac "option for System.Device.Dac API")
2424
option(API_System.Device.Gpio "option for System.Device.Gpio API")
2525
option(API_System.Device.I2c "option for System.Device.I2c API")
26+
option(API_System.Device.I2c.Slave "option for System.Device.I2c.Slave API")
2627
option(API_System.Device.I2s "option for System.Device.I2s API")
2728
option(API_System.Device.Pwm "option for System.Device.Pwm API")
2829
option(API_System.IO.Ports "option for System.IO.Ports API")
@@ -339,6 +340,12 @@ if(API_System.Device.I2c)
339340
PerformSettingsForApiEntry("System.Device.I2c")
340341
endif()
341342

343+
# System.Device.I2c.Slave
344+
if(API_System.Device.I2c.Slave)
345+
##### API name here (doted name)
346+
PerformSettingsForApiEntry("System.Device.I2c.Slave")
347+
endif()
348+
342349
# System.Device.I2s
343350
if(API_System.Device.I2s)
344351
##### API name here (doted name)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) .NET Foundation and Contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
# native code directory
7+
set(BASE_PATH_FOR_THIS_MODULE ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/System.Device.I2c.Slave)
8+
9+
10+
# set include directories
11+
list(APPEND System.Device.I2c.Slave_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core)
12+
list(APPEND System.Device.I2c.Slave_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include)
13+
list(APPEND System.Device.I2c.Slave_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include)
14+
list(APPEND System.Device.I2c.Slave_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include)
15+
list(APPEND System.Device.I2c.Slave_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE})
16+
list(APPEND System.Device.I2c.Slave_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/System.Device.I2c.Slave)
17+
18+
# source files
19+
set(System.Device.I2c.Slave_SRCS
20+
21+
sys_dev_i2c_slave_native.cpp
22+
23+
24+
sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice.cpp
25+
)
26+
27+
foreach(SRC_FILE ${System.Device.I2c.Slave_SRCS})
28+
29+
set(System.Device.I2c.Slave_SRC_FILE SRC_FILE-NOTFOUND)
30+
31+
find_file(System.Device.I2c.Slave_SRC_FILE ${SRC_FILE}
32+
PATHS
33+
${BASE_PATH_FOR_THIS_MODULE}
34+
${TARGET_BASE_LOCATION}
35+
${PROJECT_SOURCE_DIR}/src/System.Device.I2c.Slave
36+
37+
CMAKE_FIND_ROOT_PATH_BOTH
38+
)
39+
40+
if (BUILD_VERBOSE)
41+
message("${SRC_FILE} >> ${System.Device.I2c.Slave_SRC_FILE}")
42+
endif()
43+
44+
list(APPEND System.Device.I2c.Slave_SOURCES ${System.Device.I2c.Slave_SRC_FILE})
45+
46+
endforeach()
47+
48+
include(FindPackageHandleStandardArgs)
49+
50+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(System.Device.I2c.Slave DEFAULT_MSG System.Device.I2c.Slave_INCLUDE_DIRS System.Device.I2c.Slave_SOURCES)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
#include "sys_dev_i2c_slave_native.h"
7+
8+
// clang-format off
9+
10+
static const CLR_RT_MethodHandler method_lookup[] =
11+
{
12+
NULL,
13+
NULL,
14+
NULL,
15+
NULL,
16+
NULL,
17+
NULL,
18+
NULL,
19+
NULL,
20+
NULL,
21+
NULL,
22+
Library_sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice::NativeInit___VOID,
23+
Library_sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice::NativeDispose___VOID,
24+
Library_sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice::NativeTransmit___I4__SystemSpanByte__SystemSpanByte__I4,
25+
};
26+
27+
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_I2c_Slave =
28+
{
29+
"System.Device.I2c.Slave",
30+
0x4238164B,
31+
method_lookup,
32+
{ 1, 0, 0, 0 }
33+
};
34+
35+
// clang-format on
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
#ifndef SYS_DEV_I2C_SLAVE_NATIVE_H
7+
#define SYS_DEV_I2C_SLAVE_NATIVE_H
8+
9+
#include <nanoCLR_Interop.h>
10+
#include <nanoCLR_Runtime.h>
11+
#include <nanoPackStruct.h>
12+
#include <corlib_native.h>
13+
14+
struct Library_sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice
15+
{
16+
static const int FIELD___busId = 1;
17+
static const int FIELD___deviceAddress = 2;
18+
static const int FIELD___disposed = 3;
19+
static const int FIELD___syncLock = 4;
20+
static const int FIELD___buffer = 5;
21+
22+
NANOCLR_NATIVE_DECLARE(NativeInit___VOID);
23+
NANOCLR_NATIVE_DECLARE(NativeDispose___VOID);
24+
NANOCLR_NATIVE_DECLARE(NativeTransmit___I4__SystemSpanByte__SystemSpanByte__I4);
25+
26+
//--//
27+
};
28+
29+
extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_I2c_Slave;
30+
31+
#endif // SYS_DEV_I2C_SLAVE_NATIVE_H
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
// I2C slave TX buffer size
7+
#define I2C_SLAVE_TX_BUF_LEN 16
8+
// I2C slave RX buffer size
9+
#define I2C_SLAVE_RX_BUF_LEN 16
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
// I2C slave TX buffer size
7+
#define I2C_SLAVE_TX_BUF_LEN 16
8+
// I2C slave RX buffer size
9+
#define I2C_SLAVE_RX_BUF_LEN 16
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
// I2C slave TX buffer size
7+
#define I2C_SLAVE_TX_BUF_LEN 16
8+
// I2C slave RX buffer size
9+
#define I2C_SLAVE_RX_BUF_LEN 16
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
// I2C slave TX buffer size
7+
#define I2C_SLAVE_TX_BUF_LEN 16
8+
// I2C slave RX buffer size
9+
#define I2C_SLAVE_RX_BUF_LEN 16
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
#ifndef TARGET_HAL_I2C_H
7+
#define TARGET_HAL_I2C_H
8+
9+
#include <target_platform.h>
10+
#include <esp32_idf.h>
11+
#include <nanoHAL_v2.h>
12+
#include <soc/rtc_cntl_reg.h>
13+
14+
extern uint8_t Esp_I2C_Initialised_Flag[I2C_NUM_MAX];
15+
16+
void Esp32_I2c_UnitializeAll();
17+
18+
#endif // TARGET_HAL_I2C_H

targets/ESP32/_nanoCLR/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ list(APPEND TARGET_ESP32_IDF_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetH
3030
# append nanoHAL
3131
list(APPEND TARGET_ESP32_IDF_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetRandom.cpp)
3232

33+
list(APPEND TARGET_ESP32_IDF_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetPAL_I2c.cpp)
34+
3335
# make var global
3436
set(TARGET_ESP32_IDF_NANOCLR_SOURCES ${TARGET_ESP32_IDF_NANOCLR_SOURCES} CACHE INTERNAL "make global")
3537

0 commit comments

Comments
 (0)