Skip to content

Commit 26eb283

Browse files
fdcavalcantixiaoxiang781216
authored andcommitted
boards/risc-v: fix config for SPI and I2C drivers
Replaces CONFIG_I2C_DRIVER with CONFIG_I2C for proper build requirements. Same for SPI. Also changes some logging to syslog. Signed-off-by: Filipe Cavalcanti <[email protected]>
1 parent 0ce9e82 commit 26eb283

File tree

23 files changed

+146
-113
lines changed

23 files changed

+146
-113
lines changed

boards/risc-v/esp32c3/common/include/esp_board_i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C"
6363
*
6464
****************************************************************************/
6565

66-
#ifdef CONFIG_I2C_DRIVER
66+
#ifdef CONFIG_I2C
6767
int board_i2c_init(void);
6868
#endif
6969

boards/risc-v/esp32c3/common/include/esp_board_spidev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern "C"
6767
*
6868
****************************************************************************/
6969

70-
#ifdef CONFIG_SPI_DRIVER
70+
#ifdef CONFIG_SPI
7171
int board_spidev_initialize(int bus);
7272
#endif
7373

boards/risc-v/esp32c3/common/src/Make.defs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ ifeq ($(CONFIG_ESPRESSIF_SPI),y)
3838
CSRCS += esp_board_spi.c
3939
endif
4040

41-
ifeq ($(CONFIG_SPI_DRIVER),y)
41+
ifeq ($(CONFIG_SPI),y)
4242
CSRCS += esp_board_spidev.c
4343
endif
4444

45-
ifeq ($(CONFIG_SPI_SLAVE_DRIVER),y)
45+
ifeq ($(CONFIG_SPI_SLAVE),y)
4646
CSRCS += esp_board_spislavedev.c
4747
endif
4848

49-
ifeq ($(CONFIG_I2C_DRIVER),y)
49+
ifeq ($(CONFIG_I2C),y)
5050
CSRCS += esp_board_i2c.c
5151
endif
5252

boards/risc-v/esp32c3/common/src/esp_board_i2c.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <nuttx/config.h>
2828

29-
#include <debug.h>
29+
#include <syslog.h>
3030
#include <errno.h>
3131
#include <sys/types.h>
3232

@@ -59,20 +59,22 @@
5959
static int i2c_bitbang_driver_init(int bus)
6060
{
6161
struct i2c_master_s *i2c;
62-
int ret;
62+
int ret = OK;
6363

6464
i2c = esp_i2cbus_bitbang_initialize();
6565
if (i2c == NULL)
6666
{
67-
i2cerr("Failed to get I2C%d interface\n", bus);
67+
syslog(LOG_ERR, "Failed to get I2C%d interface\n", bus);
6868
return -ENODEV;
6969
}
7070

71+
#ifdef CONFIG_I2C_DRIVER
7172
ret = i2c_register(i2c, bus);
7273
if (ret < 0)
7374
{
74-
i2cerr("Failed to register I2C%d driver: %d\n", bus, ret);
75+
syslog(LOG_ERR, "Failed to register I2C%d driver: %d\n", bus, ret);
7576
}
77+
#endif
7678

7779
return ret;
7880
}
@@ -82,21 +84,23 @@ static int i2c_bitbang_driver_init(int bus)
8284
static int i2c_driver_init(int bus)
8385
{
8486
struct i2c_master_s *i2c;
85-
int ret;
87+
int ret = OK;
8688

8789
i2c = esp_i2cbus_initialize(bus);
8890
if (i2c == NULL)
8991
{
90-
i2cerr("Failed to get I2C%d interface\n", bus);
92+
syslog(LOG_ERR, "Failed to get I2C%d interface\n", bus);
9193
return -ENODEV;
9294
}
9395

96+
#ifdef CONFIG_I2C_DRIVER
9497
ret = i2c_register(i2c, bus);
9598
if (ret < 0)
9699
{
97-
i2cerr("Failed to register I2C%d driver: %d\n", bus, ret);
100+
syslog(LOG_ERR, "Failed to register I2C%d driver: %d\n", bus, ret);
98101
esp_i2cbus_uninitialize(i2c);
99102
}
103+
#endif
100104

101105
return ret;
102106
}
@@ -106,21 +110,23 @@ static int i2c_driver_init(int bus)
106110
static int i2c_slave_driver_init(int bus, int addr)
107111
{
108112
struct i2c_slave_s *i2c;
109-
int ret;
113+
int ret = OK;
110114

111115
i2c = esp_i2cbus_slave_initialize(bus, addr);
112116
if (i2c == NULL)
113117
{
114-
i2cerr("Failed to get I2C%d interface\n", bus);
118+
syslog(LOG_ERR, "Failed to get I2C%d interface\n", bus);
115119
return -ENODEV;
116120
}
117121

122+
#ifdef CONFIG_I2C_DRIVER
118123
ret = i2c_slave_register(i2c, bus, addr, I2C0_SLAVE_NBITS);
119124
if (ret < 0)
120125
{
121-
i2cerr("Failed to register I2C%d driver: %d\n", bus, ret);
126+
syslog(LOG_ERR, "Failed to register I2C%d driver: %d\n", bus, ret);
122127
esp_i2cbus_slave_uninitialize(i2c);
123128
}
129+
#endif
124130

125131
return ret;
126132
}

boards/risc-v/esp32c3/common/src/esp_board_spidev.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <nuttx/config.h>
2828

2929
#include <stdio.h>
30-
#include <debug.h>
30+
#include <syslog.h>
3131
#include <errno.h>
3232

3333
#include <nuttx/spi/spi_transfer.h>
@@ -63,10 +63,8 @@
6363
#ifdef CONFIG_ESPRESSIF_SPI_BITBANG
6464
static int spi_bitbang_driver_init(int port)
6565
{
66-
int ret;
6766
struct spi_dev_s *spi;
68-
69-
syslog(LOG_INFO, "Initializing /dev/spi%d...\n", port);
67+
int ret = OK;
7068

7169
/* Initialize SPI device */
7270

@@ -78,12 +76,16 @@ static int spi_bitbang_driver_init(int port)
7876
return -ENODEV;
7977
}
8078

79+
#ifdef CONFIG_SPI_DRIVER
80+
syslog(LOG_INFO, "Initializing /dev/spi%d...\n", port);
81+
8182
ret = spi_register(spi, port);
8283
if (ret < 0)
8384
{
8485
syslog(LOG_ERR, "Failed to register /dev/spi%d: %d\n", port, ret);
8586
esp_spi_bitbang_uninitialize(spi);
8687
}
88+
#endif
8789

8890
return ret;
8991
}
@@ -110,8 +112,6 @@ static int spi_driver_init(int port)
110112
int ret = OK;
111113
struct spi_dev_s *spi;
112114

113-
syslog(LOG_INFO, "Initializing /dev/spi%d...\n", port);
114-
115115
/* Initialize SPI device */
116116

117117
spi = esp_spibus_initialize(port);
@@ -122,12 +122,16 @@ static int spi_driver_init(int port)
122122
return -ENODEV;
123123
}
124124

125+
#ifdef CONFIG_SPI_DRIVER
126+
syslog(LOG_INFO, "Initializing /dev/spi%d...\n", port);
127+
125128
ret = spi_register(spi, port);
126129
if (ret < 0)
127130
{
128131
syslog(LOG_ERR, "Failed to register /dev/spi%d: %d\n", port, ret);
129132
esp_spibus_uninitialize(spi);
130133
}
134+
#endif
131135

132136
return ret;
133137
}
@@ -184,7 +188,7 @@ int board_spidev_initialize(int port)
184188

185189
default:
186190
{
187-
wderr("ERROR: unsupported SPI %d\n", port);
191+
syslog(LOG_ERR, "ERROR: unsupported SPI %d\n", port);
188192
return ERROR;
189193
}
190194
}

boards/risc-v/esp32c3/common/src/esp_board_spislavedev.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <nuttx/config.h>
2828

2929
#include <stdio.h>
30-
#include <debug.h>
30+
#include <syslog.h>
3131
#include <errno.h>
3232

3333
#include <nuttx/spi/slave.h>
@@ -57,28 +57,29 @@
5757

5858
int board_spislavedev_initialize(int bus)
5959
{
60-
int ret;
61-
6260
struct spi_slave_ctrlr_s *ctrlr;
63-
64-
spiinfo("Initializing /dev/spislv%d...\n", bus);
61+
int ret = OK;
6562

6663
/* Initialize SPI Slave controller device */
6764

6865
ctrlr = esp_spislave_ctrlr_initialize(bus);
6966
if (ctrlr == NULL)
7067
{
71-
spierr("Failed to initialize SPI%d as slave.\n", bus);
68+
syslog(LOG_ERR, "Failed to initialize SPI%d as slave.\n", bus);
7269
return -ENODEV;
7370
}
7471

72+
#ifdef CONFIG_SPI_SLAVE_DRIVER
73+
syslog(LOG_INFO, "Initializing /dev/spislv%d...\n", bus);
74+
7575
ret = spi_slave_register(ctrlr, bus);
7676
if (ret < 0)
7777
{
78-
spierr("Failed to register /dev/spislv%d: %d\n", bus, ret);
78+
syslog(LOG_ERR, "Failed to register /dev/spislv%d: %d\n", bus, ret);
7979

8080
esp_spislave_ctrlr_uninitialize(ctrlr);
8181
}
82+
#endif
8283

8384
return ret;
8485
}

boards/risc-v/esp32c3/esp32c3-generic/src/esp32c3_bringup.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
# include "esp_ble.h"
106106
#endif
107107

108-
#ifdef CONFIG_SPI_SLAVE_DRIVER
108+
#ifdef CONFIG_SPI_SLAVE
109109
# include "espressif/esp_spi.h"
110110
# include "esp_board_spislavedev.h"
111111
#endif
@@ -229,7 +229,7 @@ int esp_bringup(void)
229229
#endif
230230
#endif
231231

232-
#if defined(CONFIG_ESPRESSIF_SPI) && defined(CONFIG_SPI_DRIVER)
232+
#ifdef CONFIG_ESPRESSIF_SPI
233233
# ifdef CONFIG_ESPRESSIF_SPI2
234234
ret = board_spidev_initialize(ESPRESSIF_SPI2);
235235
if (ret < 0)
@@ -245,7 +245,7 @@ int esp_bringup(void)
245245
syslog(LOG_ERR, "ERROR: Failed to init spidev 3: %d\n", ret);
246246
}
247247
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
248-
#endif /* CONFIG_ESPRESSIF_SPI && CONFIG_SPI_DRIVER*/
248+
#endif /* CONFIG_ESPRESSIF_SPI */
249249

250250
#ifdef CONFIG_ESPRESSIF_SPIFLASH
251251
ret = board_spiflash_init();
@@ -298,7 +298,7 @@ int esp_bringup(void)
298298
}
299299
#endif
300300

301-
#if defined(CONFIG_SPI_SLAVE_DRIVER) && defined(CONFIG_ESPRESSIF_SPI2)
301+
#if defined(CONFIG_SPI_SLAVE) && defined(CONFIG_ESPRESSIF_SPI2)
302302
ret = board_spislavedev_initialize(ESPRESSIF_SPI2);
303303
if (ret < 0)
304304
{
@@ -339,7 +339,7 @@ int esp_bringup(void)
339339
}
340340
#endif
341341

342-
#if defined(CONFIG_I2C_DRIVER)
342+
#if defined(CONFIG_I2C)
343343
/* Configure I2C peripheral interfaces */
344344

345345
ret = board_i2c_init();

boards/risc-v/esp32c6/common/include/esp_board_i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C"
6363
*
6464
****************************************************************************/
6565

66-
#ifdef CONFIG_I2C_DRIVER
66+
#ifdef CONFIG_I2C
6767
int board_i2c_init(void);
6868
#endif
6969

boards/risc-v/esp32c6/common/include/esp_board_spidev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern "C"
6767
*
6868
****************************************************************************/
6969

70-
#ifdef CONFIG_SPI_DRIVER
70+
#ifdef CONFIG_SPI
7171
int board_spidev_initialize(int bus);
7272
#endif
7373

boards/risc-v/esp32c6/common/src/Make.defs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ ifeq ($(CONFIG_ESPRESSIF_SPI),y)
3838
CSRCS += esp_board_spi.c
3939
endif
4040

41-
ifeq ($(CONFIG_SPI_DRIVER),y)
41+
ifeq ($(CONFIG_SPI),y)
4242
CSRCS += esp_board_spidev.c
4343
endif
4444

45-
ifeq ($(CONFIG_SPI_SLAVE_DRIVER),y)
45+
ifeq ($(CONFIG_SPI_SLAVE),y)
4646
CSRCS += esp_board_spislavedev.c
4747
endif
4848

49-
ifeq ($(CONFIG_I2C_DRIVER),y)
49+
ifeq ($(CONFIG_I2C),y)
5050
CSRCS += esp_board_i2c.c
5151
endif
5252

0 commit comments

Comments
 (0)