local M = {} M.defaults = { ncs_root = vim.fn.expand("~/ncs"), toolchains_root = vim.fn.expand("~/ncs/toolchains"), ncs_version = nil, toolchain_dir = nil, board = nil, build_dir = "build", conf_file = "prj.conf", sysbuild = true, overlays = {}, extra_cmake = {}, keys = { build = "nb", pristine = "np", flash = "nf", flash_erase = "nE", flash_recover = "nR", device_recover = "nD", kconfig = "nk", memory = "nm", config = "nc", build_config = "nB", monitor = "nt", }, } M.options = {} function M.setup(opts) local o = vim.tbl_deep_extend("force", {}, M.defaults, opts or {}) local detect = require("hego.detect") if not o.ncs_version then o.ncs_version = detect.ncs_version(o.ncs_root) end if not o.toolchain_dir then local tc = detect.toolchain(o.toolchains_root) o.toolchain_dir = tc and tc.dir or nil end if not o.board then o.board = detect.board(o.build_dir) end M.options = o require("hego.keymaps").setup(o) require("hego.commands").setup(o) return o end function M.build(pristine) return require("hego.west").build(M.options, pristine) end --- mode: nil/"flash" | "erase" | "recover" function M.flash(mode) return require("hego.flash").run(M.options, mode) end function M.device_recover() return require("hego.flash").device_recover(M.options) end function M.kconfig() return require("hego.targets").run(M.options, "menuconfig", "hego://menuconfig") end function M.memory_report() return require("hego.targets").memory(M.options) end function M.monitor() return require("hego.monitor").run(M.options) end function M.edit_config() local Config = require("hego.config") if vim.fn.filereadable(Config.path) == 0 then Config.save({ version = 1, configs = { default = Config.seed(M.options) }, }) vim.notify("[hego] creado " .. Config.path .. " (sembrado desde tus opts)", vim.log.levels.INFO) end vim.cmd.edit(vim.fn.fnamemodify(Config.path, ":p")) end function M.build_from_config(pristine) local Config = require("hego.config") local data = Config.load() local names = vim.tbl_keys(data.configs) if #names == 0 then vim.notify("[hego] no hay configs en " .. Config.path .. " (usa nc)", vim.log.levels.WARN) return end table.sort(names) vim.ui.select(names, { prompt = "Construir con configuración", format_item = function(n) return n end, }, function(choice) if not choice then return end require("hego.west").build(M.options, pristine, Config.normalize(data.configs[choice])) end) end return M