diff --git a/samples/spi_controller/CMakeLists.txt b/samples/spi_controller/CMakeLists.txt new file mode 100644 index 00000000..824634e5 --- /dev/null +++ b/samples/spi_controller/CMakeLists.txt @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(spi_controller) + +target_sources(app PRIVATE src/app.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/spi_controller/README.rst b/samples/spi_controller/README.rst new file mode 100644 index 00000000..8d2aad33 --- /dev/null +++ b/samples/spi_controller/README.rst @@ -0,0 +1,9 @@ +.. _spi_controller: + +SPI Controller +############### + +Overview +******** + +A simple sample that sends incrementing byte to SPI peripheral. diff --git a/samples/spi_controller/prj.conf b/samples/spi_controller/prj.conf new file mode 100644 index 00000000..661fb228 --- /dev/null +++ b/samples/spi_controller/prj.conf @@ -0,0 +1,6 @@ +CONFIG_CPLUSPLUS=y +CONFIG_ARDUINO_API=y +CONFIG_SPI=y +CONFIG_LOG=y +CONFIG_LOG_OUTPUT=y +CONFIG_LOG_MODE_IMMEDIATE=y diff --git a/samples/spi_controller/src/app.cpp b/samples/spi_controller/src/app.cpp new file mode 100644 index 00000000..d0306512 --- /dev/null +++ b/samples/spi_controller/src/app.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Ayush Singh + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "SPI.h" +#include + +#define CHIPSELECT 3 + +static uint8_t data = 0; + +void setup() { + SPI.begin(); + pinMode(CHIPSELECT, OUTPUT); + digitalWrite(CHIPSELECT, HIGH); +} + +void loop() { + SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); + digitalWrite(CHIPSELECT, LOW); + SPI.transfer(data++); + digitalWrite(CHIPSELECT, HIGH); + SPI.endTransaction(); + delay(1000); +}