|
60 | 60 | # include <nuttx/leds/userled.h> |
61 | 61 | #endif |
62 | 62 |
|
| 63 | +#ifdef CONFIG_SENSORS_AS5047D |
| 64 | +#include <nuttx/sensors/as5047d.h> |
| 65 | +#endif |
| 66 | + |
63 | 67 | #include "stm32_romfs.h" |
64 | 68 | #include "nucleo-f446re.h" |
65 | 69 |
|
|
84 | 88 | int stm32_bringup(void) |
85 | 89 | { |
86 | 90 | int ret = OK; |
| 91 | +#if defined(CONFIG_SENSORS_QENCODER) && defined(CONFIG_SENSORS_AS5047D) |
| 92 | + FAR struct spi_dev_s *spi; |
| 93 | + FAR struct qe_lowerhalf_s *lower; |
| 94 | +#endif |
87 | 95 |
|
88 | 96 | #ifdef CONFIG_FS_PROCFS |
89 | 97 | /* Mount the procfs file system */ |
@@ -197,16 +205,45 @@ int stm32_bringup(void) |
197 | 205 | #endif |
198 | 206 |
|
199 | 207 | #ifdef CONFIG_SENSORS_QENCODER |
200 | | - /* Initialize and register the qencoder driver */ |
| 208 | +#ifdef CONFIG_SENSORS_AS5047D |
| 209 | + /* Initialize and register the AS5047D qencoder driver */ |
| 210 | + |
| 211 | + spi = stm32_spibus_initialize(3); |
| 212 | + if (spi == NULL) |
| 213 | + { |
| 214 | + syslog(LOG_ERR, "ERROR: Failed to initialize SPI3 for AS5047D\n"); |
| 215 | + return -ENODEV; |
| 216 | + } |
| 217 | + |
| 218 | +#ifdef GPIO_SPI3_CS_USER |
| 219 | + stm32_configgpio(GPIO_SPI3_CS_USER); |
| 220 | +#endif |
| 221 | + |
| 222 | + lower = as5047d_initialize(spi, SPIDEV_USER(0)); |
| 223 | + if (lower == NULL) |
| 224 | + { |
| 225 | + syslog(LOG_ERR, "ERROR: as5047d_initialize() failed\n"); |
| 226 | + return -ENODEV; |
| 227 | + } |
| 228 | + |
| 229 | + ret = qe_register("/dev/qe0", lower); |
| 230 | + if (ret < 0) |
| 231 | + { |
| 232 | + syslog(LOG_ERR, "ERROR: qe_register(/dev/qe0) failed: %d\n", ret); |
| 233 | + return ret; |
| 234 | + } |
| 235 | +#else |
| 236 | + /* Initialize and register the STM32 timer qencoder driver */ |
201 | 237 |
|
202 | 238 | ret = board_qencoder_initialize(0, CONFIG_NUCLEO_F446RE_QETIMER); |
203 | 239 | if (ret != OK) |
204 | 240 | { |
205 | 241 | syslog(LOG_ERR, |
206 | | - "ERROR: Failed to register the qencoder: %d\n", |
| 242 | + "ERROR: Failed to register timer qencoder: %d\n", |
207 | 243 | ret); |
208 | 244 | return ret; |
209 | 245 | } |
| 246 | +# endif |
210 | 247 | #endif |
211 | 248 |
|
212 | 249 | #ifdef CONFIG_SENSORS_HALL3PHASE |
|
0 commit comments