{"action":"created","issue":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9086","repository_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr","labels_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9086/labels{/name}","comments_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9086/comments","events_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9086/events","html_url":"https://github.com/zephyrproject-rtos/zephyr/pull/9086","id":343902459,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAzNDIzMDE0","number":9086,"title":"[RFC] [DNM] drivers: nrf: Driver instantiation proposal","user":{"login":"nordic-krch","id":16899589,"node_id":"MDQ6VXNlcjE2ODk5NTg5","avatar_url":"https://avatars3.githubusercontent.com/u/16899589?v=4","gravatar_id":"","url":"https://api.github.com/users/nordic-krch","html_url":"https://github.com/nordic-krch","followers_url":"https://api.github.com/users/nordic-krch/followers","following_url":"https://api.github.com/users/nordic-krch/following{/other_user}","gists_url":"https://api.github.com/users/nordic-krch/gists{/gist_id}","starred_url":"https://api.github.com/users/nordic-krch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nordic-krch/subscriptions","organizations_url":"https://api.github.com/users/nordic-krch/orgs","repos_url":"https://api.github.com/users/nordic-krch/repos","events_url":"https://api.github.com/users/nordic-krch/events{/privacy}","received_events_url":"https://api.github.com/users/nordic-krch/received_events","type":"User","site_admin":false},"labels":[{"id":807706246,"node_id":"MDU6TGFiZWw4MDc3MDYyNDY=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/DNM","name":"DNM","color":"b60205","default":false},{"id":724796876,"node_id":"MDU6TGFiZWw3MjQ3OTY4NzY=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/RFC","name":"RFC","color":"d8af5d","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-07-24T06:33:31Z","updated_at":"2018-07-27T13:00:59Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/pulls/9086","html_url":"https://github.com/zephyrproject-rtos/zephyr/pull/9086","diff_url":"https://github.com/zephyrproject-rtos/zephyr/pull/9086.diff","patch_url":"https://github.com/zephyrproject-rtos/zephyr/pull/9086.patch"},"body":"There is ongoing discussion (and PR #8561) about code generation for driver instantiation. Here is a proposal how to do that using C preprocessor only. It is using macros already present in zephyr (UTIL_REPEAT and modified version of _LOG_EVAL).\r\n\r\nIf main goal of codegen is to allow dynamic/flexible instances generation then this macros seem to solve the problem without introducing external tools.\r\n\r\nConcept is utilizing 2 preprocessor 'tricks':\r\n- optional code creation based on a test result _EVAL(_test, _code_iftrue, _code_iffalse) which is used to create particular instance e.g. _EVAL(CONFIG_INSTANCE_##i##_ENABLED, (instance code), ())\r\n- macro which which repeats call to another macro for requested number of times (with index as first parameter).\r\n\r\nSigned-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>"},"comment":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/comments/408411599","html_url":"https://github.com/zephyrproject-rtos/zephyr/pull/9086#issuecomment-408411599","issue_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9086","id":408411599,"node_id":"MDEyOklzc3VlQ29tbWVudDQwODQxMTU5OQ==","user":{"login":"b0661","id":5486823,"node_id":"MDQ6VXNlcjU0ODY4MjM=","avatar_url":"https://avatars0.githubusercontent.com/u/5486823?v=4","gravatar_id":"","url":"https://api.github.com/users/b0661","html_url":"https://github.com/b0661","followers_url":"https://api.github.com/users/b0661/followers","following_url":"https://api.github.com/users/b0661/following{/other_user}","gists_url":"https://api.github.com/users/b0661/gists{/gist_id}","starred_url":"https://api.github.com/users/b0661/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b0661/subscriptions","organizations_url":"https://api.github.com/users/b0661/orgs","repos_url":"https://api.github.com/users/b0661/repos","events_url":"https://api.github.com/users/b0661/events{/privacy}","received_events_url":"https://api.github.com/users/b0661/received_events","type":"User","site_admin":false},"created_at":"2018-07-27T13:00:59Z","updated_at":"2018-07-27T13:00:59Z","author_association":"COLLABORATOR","body":"@nordic-krch below you find a working example from the latest version of codegen #6762.\r\n\r\nIt creates device instances for STM32 SPI devices. Device instantiation is controlled by the CONFIG_SPIx Kconfig vars and the device tree status \"activated\". All config data is retrieved from the device tree. All values in the device_info template are replaced by the current device instance device tree property values. In my view this is easy to understand, use and maintain. I welcome suggestions for improvements.\r\n\r\n```\r\n/**\r\n * @code{.codegen}\r\n * codegen.import_module('devicedeclare')\r\n *\r\n * device_configs = ['CONFIG_SPI_{}'.format(x) for x in range(1, 4)]\r\n * driver_names = ['SPI_{}'.format(x) for x in range(1, 4)]\r\n * device_inits = 'spi_stm32_init'\r\n * device_levels = 'POST_KERNEL'\r\n * device_prios = 'CONFIG_SPI_INIT_PRIORITY'\r\n * device_api = 'spi_stm32_driver_api'\r\n * device_info = \\\r\n * \"\"\"\r\n * #if CONFIG_SPI_STM32_INTERRUPT\r\n * DEVICE_DECLARE(${device-name});\r\n * static void ${device-config-irq}(struct device *dev)\r\n * {\r\n *         IRQ_CONNECT(${interrupts/0/irq}, ${interrupts/0/priority}, \\\\\r\n *                     spi_stm32_isr, \\\\\r\n *                     DEVICE_GET(${device-name}), 0);\r\n *         irq_enable(${interrupts/0/irq});\r\n * }\r\n * #endif\r\n * static const struct spi_stm32_config ${device-config-info} = {\r\n *         .spi = (SPI_TypeDef *)${reg/0/address/0},\r\n *         .pclken.bus = ${clocks/0/bus},\r\n *         .pclken.enr = ${clocks/0/bits},\r\n * #if CONFIG_SPI_STM32_INTERRUPT\r\n *         .config_irq = ${device-config-irq},\r\n * #endif\r\n * };\r\n * static struct spi_stm32_data ${device-data} = {\r\n *         SPI_CONTEXT_INIT_LOCK(${device-data}, ctx),\r\n *         SPI_CONTEXT_INIT_SYNC(${device-data}, ctx),\r\n * };\r\n * \"\"\"\r\n *\r\n * devicedeclare.device_declare_multi( \\\r\n *     device_configs,\r\n *     driver_names,\r\n *     device_inits,\r\n *     device_levels,\r\n *     device_prios,\r\n *     device_api,\r\n *     device_info)\r\n * @endcode{.codegen}\r\n */\r\n/** @code{.codeins}@endcode */\r\n```"}}
{"actor":{"display_login":"b0661"}}