From 17ae35fb807cdb6077210a6ce832bceab3f37af6 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sun, 19 Nov 2023 01:31:38 +0000 Subject: [PATCH] Setup project structure --- .envrc | 1 + .gitignore | 3 ++ CMakeLists.txt | 5 +++ flake.lock | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 31 ++++++++++++++++++ prj.conf | 1 + src/main.c | 44 ++++++++++++++++++++++++++ 7 files changed, 170 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 prj.conf create mode 100644 src/main.c diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7bf4194 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.direnv/ +.cache/ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..be8ebaa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(blink) +target_sources(app PRIVATE src/main.c) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..16bbe4e --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "artemist-packages": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": [ + "utils" + ] + }, + "locked": { + "lastModified": 1699858083, + "narHash": "sha256-EXmVoYDYszdWlaxRzedQ3Q7ehbqIGfbe9EaHSBD4cgQ=", + "ref": "refs/heads/canon", + "rev": "453af715eebd7102131d2cc6846dd23d49f853ac", + "revCount": 12, + "type": "git", + "url": "https://git.mildlyfunctional.gay/artemist/packages.git" + }, + "original": { + "type": "git", + "url": "https://git.mildlyfunctional.gay/artemist/packages.git" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700108881, + "narHash": "sha256-+Lqybl8kj0+nD/IlAWPPG/RDTa47gff9nbei0u7BntE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7414e9ee0b3e9903c24d3379f577a417f0aae5f1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "artemist-packages": "artemist-packages", + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..430ae86 --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + artemist-packages = { + url = "git+https://git.mildlyfunctional.gay/artemist/packages.git"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.utils.follows = "utils"; + }; + }; + outputs = { self, nixpkgs, utils, artemist-packages }: + utils.lib.eachDefaultSystem (system: + let pkgs = import nixpkgs { inherit system; }; + in rec { + devShells.zephyr = + artemist-packages.devShells.${system}.zephyr.override { + toolchains = + with artemist-packages.packages.${system}.zephyr.toolchains; + [ xtensa-espressif_esp32_zephyr-elf ]; + modules = + with artemist-packages.packages.${system}.zephyr.modules; [ + mbedtls + hal_espressif + ]; + extraPackages = with pkgs; [ esptool ]; + }; + devShells.default = devShells.zephyr; + formatter = pkgs.nixfmt; + }); + +} diff --git a/prj.conf b/prj.conf new file mode 100644 index 0000000..91c3c15 --- /dev/null +++ b/prj.conf @@ -0,0 +1 @@ +CONFIG_GPIO=y diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a6d0954 --- /dev/null +++ b/src/main.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* 1000 msec = 1 sec */ +#define SLEEP_TIME_MS 1000 + +/* The devicetree node identifier for the "led0" alias. */ +#define LED0_NODE DT_ALIAS(led0) + +/* + * A build error on this line means your board is unsupported. + * See the sample documentation for information on how to fix this. + */ +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); + +int main(void) +{ + int ret; + + if (!gpio_is_ready_dt(&led)) { + return 0; + } + + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + return 0; + } + + while (1) { + ret = gpio_pin_toggle_dt(&led); + if (ret < 0) { + return 0; + } + k_msleep(SLEEP_TIME_MS); + } + return 0; +} +