1 /*
2 * Copyright (c) 2025 Nordic Semiconductor ASA
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #include <zephyr/kernel.h>
7 #include <zephyr/logging/log.h>
8 #include <zephyr/drivers/spi.h>
9 #include <zephyr/drivers/gpio.h>
10
11 #define SPI_MODE (SPI_OP_MODE_MASTER | SPI_WORD_SET(8))
12 static const struct spi_dt_spec spim = SPI_DT_SPEC_GET(DT_NODELABEL(spim_dt), SPI_MODE, 0);
13
14 static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led), gpios);
15
16 LOG_MODULE_REGISTER(spi_wakeup);
17
main(void)18 int main(void)
19 {
20 bool status;
21 static char tx_buffer[] = CONFIG_BOARD_QUALIFIERS;
22 struct spi_buf tx_spi_bufs = {.buf = tx_buffer, .len = sizeof(tx_buffer)};
23 struct spi_buf_set tx_spi_buf_set = {.buffers = &tx_spi_bufs, .count = 1};
24
25 LOG_INF("Hello world from %s", CONFIG_BOARD_TARGET);
26
27 status = gpio_is_ready_dt(&led);
28 __ASSERT(status, "Error: GPIO Device not ready");
29
30 status = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
31 __ASSERT(status == 0, "Could not configure led GPIO");
32
33 status = spi_is_ready_dt(&spim);
34 __ASSERT(status, "Error: SPI device is not ready");
35
36 while (1) {
37 LOG_INF("SPIM: going to sleep for 1.5s...");
38 gpio_pin_set_dt(&led, 0);
39 k_msleep(1500);
40 gpio_pin_set_dt(&led, 1);
41 LOG_INF("SPIM: will be active for 500ms before transfer");
42 k_busy_wait(500000);
43 LOG_INF("SPIM: transferring the CONFIG_BOARD_QUALIFIERS: '%s'", tx_buffer);
44 spi_write_dt(&spim, &tx_spi_buf_set);
45 }
46
47 return 0;
48 }
49