diff options
| author | supperthomas <[email protected]> | 2021-02-15 14:21:41 +0800 |
|---|---|---|
| committer | supperthomas <[email protected]> | 2021-02-15 14:21:41 +0800 |
| commit | c0f83308111fd714ee7cbb273577df27efac5eb1 (patch) | |
| tree | 9d3f979feadd15ffcaeaff1a2958c690034ae118 /bsp/maxim/libraries | |
| parent | 3e6b866956813ab6a04fa5045103ca13d4980c46 (diff) | |
fix the sample code
Diffstat (limited to 'bsp/maxim/libraries')
| -rw-r--r-- | bsp/maxim/libraries/HAL_Drivers/drv_spi.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/bsp/maxim/libraries/HAL_Drivers/drv_spi.c b/bsp/maxim/libraries/HAL_Drivers/drv_spi.c index 45ac50b3c4..96a01354bb 100644 --- a/bsp/maxim/libraries/HAL_Drivers/drv_spi.c +++ b/bsp/maxim/libraries/HAL_Drivers/drv_spi.c @@ -178,6 +178,22 @@ static void spi_sample(int argc, char *argv[]) struct rt_spi_device *spi_dev; char name[RT_NAME_MAX]; + + spi_dev = (struct rt_spi_device *)rt_device_find(SPI_DEVICE_NAME); + if (RT_NULL == spi_dev) + { + rt_hw_spi_device_attach(SPI_DEVICE_BUS, SPI_DEVICE_NAME, PIN_0); + spi_dev = (struct rt_spi_device *)rt_device_find(SPI_DEVICE_NAME); + } + + struct rt_spi_configuration spi_cfg = + { + .mode = 0, + .data_width = 8, + .max_hz = 1000000, + }; + rt_spi_configure(spi_dev, &spi_cfg); + rt_kprintf("\n************** SPI Loopback Demo ****************\n"); rt_kprintf("This example configures the SPI to send data between the MISO (P0.4) and\n"); rt_kprintf("MOSI (P0.5) pins. Connect these two pins together. \n"); @@ -211,21 +227,3 @@ static void spi_sample(int argc, char *argv[]) } } MSH_CMD_EXPORT(spi_sample, spi sample); - -static int rt_hw_spi_sample_init(void) -{ - - struct rt_spi_device *spi_dev; - rt_hw_spi_device_attach(SPI_DEVICE_BUS, SPI_DEVICE_NAME, PIN_0); - spi_dev = (struct rt_spi_device *)rt_device_find(SPI_DEVICE_NAME); - struct rt_spi_configuration spi_cfg = - { - .mode = 0, - .data_width = 8, - .max_hz = 1000000, - }; - rt_spi_configure(spi_dev, &spi_cfg); - - return RT_EOK; -} -INIT_COMPONENT_EXPORT(rt_hw_spi_sample_init);
\ No newline at end of file |
