drivers: i2c: Add I2C driver support for Renesas RA8 devices
Add implemetation of I2C driver use IIC Master for Renesas RA8 devices Signed-off-by: Ha Nguyen <ha.nguyen.fz@bp.renesas.com> Signed-off-by: Thao Luong <thao.luong.uw@renesas.com> Signed-off-by: Duy Phuong Hoang. Nguyen <duy.nguyen.xa@renesas.com>
This commit is contained in:
parent
3a895ecea8
commit
8bcfbf4d80
14 changed files with 734 additions and 15 deletions
22
tests/drivers/i2c/i2c_api/Kconfig
Normal file
22
tests/drivers/i2c/i2c_api/Kconfig
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Copyright (c) 2024 Renesas Electronics Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
mainmenu "I2C API Test"
|
||||
|
||||
source "Kconfig.zephyr"
|
||||
|
||||
choice
|
||||
prompt "Select GY271 Sensor Type"
|
||||
default SENSOR_GY271_HMC
|
||||
|
||||
config SENSOR_GY271_HMC
|
||||
bool "Use gy271 HMC type sensor"
|
||||
help
|
||||
Use to enable the use of gy271 HMC sensor
|
||||
|
||||
config SENSOR_GY271_QMC
|
||||
bool "Use gy271 QMC type sensor"
|
||||
help
|
||||
Use to enable the use of gy271 QMC sensor
|
||||
|
||||
endchoice
|
1
tests/drivers/i2c/i2c_api/boards/ek_ra8m1.conf
Normal file
1
tests/drivers/i2c/i2c_api/boards/ek_ra8m1.conf
Normal file
|
@ -0,0 +1 @@
|
|||
CONFIG_SENSOR_GY271_QMC=y
|
10
tests/drivers/i2c/i2c_api/boards/ek_ra8m1.overlay
Normal file
10
tests/drivers/i2c/i2c_api/boards/ek_ra8m1.overlay
Normal file
|
@ -0,0 +1,10 @@
|
|||
/ {
|
||||
aliases {
|
||||
i2c-0 = &iic1;
|
||||
gy271 = &iic1;
|
||||
};
|
||||
};
|
||||
|
||||
&iic1 {
|
||||
status = "okay";
|
||||
};
|
|
@ -17,17 +17,28 @@
|
|||
#include <zephyr/ztest.h>
|
||||
|
||||
#if DT_NODE_HAS_STATUS(DT_ALIAS(i2c_0), okay)
|
||||
#define I2C_DEV_NODE DT_ALIAS(i2c_0)
|
||||
#define I2C_DEV_NODE DT_ALIAS(i2c_0)
|
||||
#elif DT_NODE_HAS_STATUS(DT_ALIAS(i2c_1), okay)
|
||||
#define I2C_DEV_NODE DT_ALIAS(i2c_1)
|
||||
#define I2C_DEV_NODE DT_ALIAS(i2c_1)
|
||||
#elif DT_NODE_HAS_STATUS(DT_ALIAS(i2c_2), okay)
|
||||
#define I2C_DEV_NODE DT_ALIAS(i2c_2)
|
||||
#define I2C_DEV_NODE DT_ALIAS(i2c_2)
|
||||
#else
|
||||
#error "Please set the correct I2C device"
|
||||
#endif
|
||||
|
||||
uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_STANDARD) | I2C_MODE_CONTROLLER;
|
||||
|
||||
#define GY271_HMC_ADDR (0x1E)
|
||||
#define GY271_QMC_ADDR (0x0D)
|
||||
|
||||
#if defined(CONFIG_SENSOR_GY271_QMC)
|
||||
#define GY271_ADDR GY271_QMC_ADDR
|
||||
#elif defined(CONFIG_SENSOR_GY271_HMC)
|
||||
#define GY271_ADDR GY271_HMC_ADDR
|
||||
#else
|
||||
#error "No sensor type defined"
|
||||
#endif
|
||||
|
||||
static int test_gy271(void)
|
||||
{
|
||||
unsigned char datas[6];
|
||||
|
@ -55,26 +66,42 @@ static int test_gy271(void)
|
|||
return TC_FAIL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SENSOR_GY271_QMC
|
||||
datas[0] = 0x09;
|
||||
datas[1] = 0x01;
|
||||
|
||||
if (i2c_write(i2c_dev, datas, 2, GY271_ADDR)) {
|
||||
TC_PRINT("Fail to configure sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
#else /* GY271 HMC */
|
||||
datas[0] = 0x01;
|
||||
datas[1] = 0x20;
|
||||
|
||||
/* 3. verify i2c_write() */
|
||||
if (i2c_write(i2c_dev, datas, 2, 0x1E)) {
|
||||
if (i2c_write(i2c_dev, datas, 2, GY271_ADDR)) {
|
||||
TC_PRINT("Fail to configure sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
datas[0] = 0x02;
|
||||
datas[1] = 0x00;
|
||||
if (i2c_write(i2c_dev, datas, 2, 0x1E)) {
|
||||
if (i2c_write(i2c_dev, datas, 2, GY271_ADDR)) {
|
||||
TC_PRINT("Fail to configure sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
k_sleep(K_MSEC(1));
|
||||
|
||||
#ifdef CONFIG_SENSOR_GY271_QMC
|
||||
/* Sensor data bits start from 0x00 to 0x05 */
|
||||
datas[0] = 0x00;
|
||||
#else /* GY271 HMC */
|
||||
datas[0] = 0x03;
|
||||
if (i2c_write(i2c_dev, datas, 1, 0x1E)) {
|
||||
#endif
|
||||
|
||||
if (i2c_write(i2c_dev, datas, 1, GY271_ADDR)) {
|
||||
TC_PRINT("Fail to write to sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
@ -82,14 +109,13 @@ static int test_gy271(void)
|
|||
(void)memset(datas, 0, sizeof(datas));
|
||||
|
||||
/* 4. verify i2c_read() */
|
||||
if (i2c_read(i2c_dev, datas, 6, 0x1E)) {
|
||||
if (i2c_read(i2c_dev, datas, 6, GY271_ADDR)) {
|
||||
TC_PRINT("Fail to fetch sample from sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
TC_PRINT("axis raw data: %d %d %d %d %d %d\n",
|
||||
datas[0], datas[1], datas[2],
|
||||
datas[3], datas[4], datas[5]);
|
||||
TC_PRINT("axis raw data: %d %d %d %d %d %d\n", datas[0], datas[1], datas[2], datas[3],
|
||||
datas[4], datas[5]);
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
|
@ -121,13 +147,21 @@ static int test_burst_gy271(void)
|
|||
return TC_FAIL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SENSOR_GY271_QMC
|
||||
datas[0] = 0x09;
|
||||
datas[1] = 0x01;
|
||||
|
||||
if (i2c_burst_write(i2c_dev, GY271_ADDR, 0x00, datas, 2)) {
|
||||
TC_PRINT("Fail to configure sensor GY271 QMC\n");
|
||||
}
|
||||
#else
|
||||
datas[0] = 0x01;
|
||||
datas[1] = 0x20;
|
||||
datas[2] = 0x02;
|
||||
datas[3] = 0x00;
|
||||
|
||||
/* 3. verify i2c_burst_write() */
|
||||
if (i2c_burst_write(i2c_dev, 0x1E, 0x00, datas, 4)) {
|
||||
if (i2c_burst_write(i2c_dev, GY271_ADDR, 0x00, datas, 4)) {
|
||||
TC_PRINT("Fail to write to sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
@ -135,16 +169,22 @@ static int test_burst_gy271(void)
|
|||
k_sleep(K_MSEC(1));
|
||||
|
||||
(void)memset(datas, 0, sizeof(datas));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSOR_GY271_QMC
|
||||
/* Sensor data bits start from 0x00 to 0x05 */
|
||||
int start_bit = 0x00;
|
||||
#else /* GY271 HMC */
|
||||
int start_bit = 0x03;
|
||||
#endif
|
||||
/* 4. verify i2c_burst_read() */
|
||||
if (i2c_burst_read(i2c_dev, 0x1E, 0x03, datas, 6)) {
|
||||
if (i2c_burst_read(i2c_dev, GY271_ADDR, start_bit, datas, 6)) {
|
||||
TC_PRINT("Fail to fetch sample from sensor GY271\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
TC_PRINT("axis raw data: %d %d %d %d %d %d\n",
|
||||
datas[0], datas[1], datas[2],
|
||||
datas[3], datas[4], datas[5]);
|
||||
TC_PRINT("axis raw data: %d %d %d %d %d %d\n", datas[0], datas[1], datas[2], datas[3],
|
||||
datas[4], datas[5]);
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue