This data structure (i2c_slave_driver_api ) is supposed to be in the i2c_slave.h header but I can't find any i2c_slave hearder
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/
fffff
#include <zephyr/kernel.h>
//#include <zephyr/drivers/i2c_slave.h> // Use i2c_slave.h for the slave API
#include <zephyr/device.h>
#include <zephyr/drivers/i2c.h>
#include <stdio.h>
// ...
#include <zephyr/kernel.h>
#include <zephyr/drivers/i2c_slave.h> // <-- UNCOMMENT THIS LINE
#include <zephyr/device.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/sys/util.h> // <-- ADD this for MIN()
#include <string.h> // <-- ADD this for memcpy()
#include <stdio.h>
// ...
#define I2C_SLAVE_DEVICE_NAME "I2C_1" // Matches the label in your overlay
// Buffer to simulate the slave's internal "register" space
static uint8_t slave_data[16];
static const struct device *i2c_slave_dev;
// --- I2C Slave Protocol Handler ---
static int i2c_slave_write_received(const struct device *dev, const uint8_t *buf, uint32_t len)
{
// The master is writing data to us.
// In a "register model," the first byte is usually the register address.
// We'll just print all incoming data for simplicity.
printk("SLAVE: Received %d bytes: ", len);
for (uint32_t i = 0; i < len; i++) {
printk("0x%02X ", buf[i]);
}
printk("\n");
// Copy data (excluding the register address if applicable) to slave_data
if (len > 0) {
memcpy(slave_data, buf, MIN(len, sizeof(slave_data)));
}
return 0; // Return 0 to allow the write
}
static int i2c_slave_read_requested(const struct device *dev, uint8_t *buf, uint32_t *len)
{
// The master is requesting data from us.
// Load the output buffer with simulated register content.
uint32_t tx_len = MIN(*len, sizeof(slave_data));
memcpy(buf, slave_data, tx_len);
*len = tx_len;
printk("SLAVE: Sending %d bytes to Master.\n", tx_len);
return 0; // Return 0 to allow the read
}
static void i2c_slave_stop(const struct device *dev)
{
// Transfer complete (STOP condition received)
// No action needed for this simple example.
}
static const struct i2c_slave_driver_api slave_api = {
.write_received = i2c_slave_write_received,
.read_request = i2c_slave_read_requested,
.stop = i2c_slave_stop,
};
// --- Main Application ---
void main(void)
{
printk("*** Booting I2C Slave Application ***\n");
i2c_slave_dev = device_get_binding(I2C_SLAVE_DEVICE_NAME);
if (!i2c_slave_dev) {
printk("Error: Device binding failed for %s.\n", I2C_SLAVE_DEVICE_NAME);
return;
}
// Initialize slave_data with a pattern for the master to read
for (int i = 0; i < sizeof(slave_data); i++) {
slave_data[i] = 0x80 + i;
}
int ret = i2c_slave_register(i2c_slave_dev, &slave_api);
if (ret != 0) {
printk("Error registering I2C slave driver: %d\n", ret);
return;
}
printk("I2C Slave Registered at 0x%02X. Waiting for Master...\n", 0x42);
// Slave thread enters an endless sleep loop.
// All communication is handled by the interrupt-driven driver callbacks.
while (1) {
k_sleep(K_SECONDS(5));
}
}
* Executing task: nRF Connect: Generate config ubx_evknorab12_nrf5340_cpuapp for c:\aram\tmp\ARAM-I2C-SLAVE
Building ARAM-I2C-SLAVE
west build --build-dir c:/aram/tmp/ARAM-I2C-SLAVE/build c:/aram/tmp/ARAM-I2C-SLAVE --pristine --board ubx_evknorab12_nrf5340_cpuapp -- -DNCS_TOOLCHAIN_VERSION="NONE" -DCONF_FILE="prj.conf" -DEXTRA_DTC_OVERLAY_FILE=aram00.overlay
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: C:/aram/tmp/ARAM-I2C-SLAVE
-- CMake version: 3.21.0
-- Found Python3: C:/ncs/toolchains/cf2149caf2/opt/bin/python.exe (found suitable version "3.9.13", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: C:/ncs/v2.6.0/zephyr/.cache
-- Zephyr version: 3.5.99 (C:/ncs/v2.6.0/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: ubx_evknorab12_nrf5340_cpuapp
-- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
-- Found Dtc: C:/ncs/toolchains/cf2149caf2/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found BOARD.dts: C:/ncs/v2.6.0/zephyr/boards/arm/ubx_evknorab12_nrf5340/ubx_evknorab12_nrf5340_cpuapp.dts
-- Found devicetree overlay: aram00.overlay
-- Generated zephyr.dts: C:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/dts.cmake
Parsing C:/ncs/v2.6.0/zephyr/Kconfig
Loaded configuration 'C:/ncs/v2.6.0/zephyr/boards/arm/ubx_evknorab12_nrf5340/ubx_evknorab12_nrf5340_cpuapp_defconfig'
Merged configuration 'C:/aram/tmp/ARAM-I2C-SLAVE/prj.conf'
Configuration saved to 'C:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/.config'
Kconfig header saved to 'C:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
CMake Warning at C:/ncs/v2.6.0/zephyr/CMakeLists.txt:1957 (message):
__ASSERT() statements are globally ENABLED
-- Configuring done
-- Generating done
-- Build files have been written to: C:/aram/tmp/ARAM-I2C-SLAVE/build
←[92m-- west build: building application
[2/138] Generating include/generated/version.h
-- Zephyr version: 3.5.99 (C:/ncs/v2.6.0/zephyr), build: v3.5.99-ncs1
[39/138] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj
C:\ncs\toolchains\cf2149caf2\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DPICOLIBC_LONG_LONG_PRINTF_SCANF -D_FORTIFY_
SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.6.0/zephyr/include -IC:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/include/generated -IC:/ncs/v2.6
.0/zephyr/soc/arm/nordic_nrf/nrf53 -IC:/ncs/v2.6.0/zephyr/soc/common/nordic_nrf/. -IC:/ncs/v2.6.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.6.0/nrf/include -IC:/ncs/v2.6.0/nrf/tests/include -IC:/
ncs/v2.6.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.6.0/zephyr/modules/cmsis/. -IC:/ncs/v2.6.0/modules/hal/nordic/nrfx -IC:/ncs/v2.6.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.6.0/m
odules/hal/nordic/nrfx/mdk -IC:/ncs/v2.6.0/zephyr/modules/hal_nordic/nrfx/. -isystem C:/ncs/v2.6.0/zephyr/lib/libc/common/include -isystem C:/ncs/v2.6.0/nrfxlib/crypto/nrf_cc312_platform/include -fno-
strict-aliasing -Os -imacros C:/aram/tmp/ARAM-I2C-SLAVE/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb
-mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.6.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -W
all -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-un
wind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/aram/tmp/ARAM-I2C-SLAVE=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.6.0/zephyr=Z
EPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.6.0=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.
obj.d -o CMakeFiles/app.dir/src/main.c.obj -c C:/aram/tmp/ARAM-I2C-SLAVE/src/main.c
C:/aram/tmp/ARAM-I2C-SLAVE/src/main.c:17:10: fatal error: zephyr/drivers/i2c_slave.h: No such file or directory
17 | #include <zephyr/drivers/i2c_slave.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[52/138] Building C object zephyr/soc/soc/arm/nordic_nrf/CMakeFiles/soc__arm__nordic_nrf.dir/nrf53/soc.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\cf2149caf2\opt\bin\cmake.EXE' --build 'c:\aram\tmp\ARAM-I2C-SLAVE\build'
* The terminal process terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.

