{"id":49309686,"url":"https://github.com/roottool0/advanced-avr-templates","last_synced_at":"2026-04-26T12:01:33.369Z","repository":{"id":353802112,"uuid":"1220784937","full_name":"RootTool0/Advanced-AVR-Templates","owner":"RootTool0","description":"Header-only C++17 framework for AVR microcontrollers - zero-cost abstractions, no RAM overhead, no virtual functions, no exceptions","archived":false,"fork":false,"pushed_at":"2026-04-25T17:16:23.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-25T17:29:25.958Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RootTool0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-25T10:27:35.000Z","updated_at":"2026-04-25T17:16:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/RootTool0/Advanced-AVR-Templates","commit_stats":null,"previous_names":["roottool0/advanced-avr-templates"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/RootTool0/Advanced-AVR-Templates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RootTool0%2FAdvanced-AVR-Templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RootTool0%2FAdvanced-AVR-Templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RootTool0%2FAdvanced-AVR-Templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RootTool0%2FAdvanced-AVR-Templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RootTool0","download_url":"https://codeload.github.com/RootTool0/Advanced-AVR-Templates/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RootTool0%2FAdvanced-AVR-Templates/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32296259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-26T12:01:32.030Z","updated_at":"2026-04-26T12:01:33.357Z","avatar_url":"https://github.com/RootTool0.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advanced AVR Templates\n\n[![C++17](https://img.shields.io/badge/C%2B%2B-17-blue.svg)]()\n[![AVR](https://img.shields.io/badge/AVR-ATmega%2C%20ATtiny-orange)]()\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n\n**[EN]** | **[[RU]](README_RU.md)**\n\n**Header-only C++17 framework for AVR microcontrollers**\n\n---\n\n## About\n\nI noticed that in every new AVR project, I kept copying the same code: pin setup, delays, EEPROM handling, display drivers. Instead of doing this for the tenth time, I put all the accumulated code into a single **header-only** library\n\nThe focus is on **readable** and **type-safe** code that compiles into the same **optimal assembly** as **plain C**\n\nNo virtual functions, no RTTI, no exceptions - only **static polymorphism via templates** and **aggressive inlining**\n\n---\n\n## Features\n\n| Module                    | File                     | Template/Struct                                                    | Description                                                |\n|---------------------------|--------------------------|--------------------------------------------------------------------|------------------------------------------------------------|\n| **Delays**                | `Delay.h`                | `FDelay`                                                           | Compile-time delay in clocks / microseconds / milliseconds |\n| **Digital pins**          | `GPIO/Pin.h`             | `TPin\u003cuint8 InPin\u003e`                                                | Digital pin operations (Arduino-style mapping)             |\n| **Buttons**               | `GPIO/PinButton.h`       | `TPinButton\u003cuint8 InPin\u003e`                                          | Button polling with pull-up + state flags                  |\n| **PWM**                   | `GPIO/PinPWM.h`          | `TPinPWM\u003cuint8 InPin, bool bInverted\u003e`                             | Hardware timer PWM                                         |\n| **Serial**                | `Communication/Serial.h` | `FSerial`                                                          | UART with compile-time baud rate                           |\n| **I2C**                   | `Communication/TWI.h`    | `FTWI`                                                             | TWI (Two-Wire Interface)                                   |\n| **EEPROM**                | `Memory/EEPROM.h`        | `FEEPROM`                                                          | Read / Write                                               |\n| **PROGMEM**               | `Memory/PROGMEM.h`       | `FPROGMEM`                                                         | Flash data access                                          |\n| **LED matrix**            | `Display/MAX7219.h`      | `TMAX7219\u003cuint8 InDIO, uint8 InCS, uint8 InCLK, uint8 InSize = 1\u003e` | MAX7219 driver                                             |\n| **OLED**                  | `Display/OLED.h`         | `TOLEDtemplate\u003cuint8 InAddress = 0x3C\u003e`                            | SSD1306 driver                                             |\n\n---\n\n## Quick Example\n\n```cpp\n#include \"AAT/GPIO/Pin.h\"\n#include \"AAT/Delay.h\"\n\nusing MyLedPin = TPin\u003c13\u003e;\n\nint main()\n{\n    MyLedPin::InitializeAsOutput();\n    \n    while(true)\n    {\n        MyLedPin::Toggle();\n        FDelay::Milliseconds\u003c1000\u003e();\n    }\n}\n```\n\n**Comparison with Arduino Blink _(ATmega328P)_:**\n\n|                      | **Arduino** | **AAT**       |\n|----------------------|-------------|---------------|\n| Flash (.text)        | 924 bytes   | **139 bytes** |\n| RAM (.bss)           | 9 bytes     | **0 bytes**   |\n| RAM (.data)          | 0 bytes     | **0 bytes**   |\n| **Total size**       | 933 bytes   | **139 bytes** |\n\n**Flash is 6.6x smaller, and RAM usage is zero.**\n\n---\n\n## Project Template\n\nThe repository also includes a `Project Template` folder - a ready-to-use structure for new projects.\n\n### How to use\n\n1. Copy the `Project Template` folder to a new name\n2. (If needed) edit `CMakeLists.txt` - set MCU type, frequency, port, etc.\n3. Run `Build.bat`\n\n**What `Build.bat` does:**\n- Copies `AAT` from `Include/` into the project folder\n- Runs **CMake** with preset parameters\n- Creates a `.sln` project in the `Build` folder\n- Generates `Upload.bat` via **CMake** for flashing the MCU\n- **Self-destructs** (deletes itself)\n\nAfter the build, write your code and run `Upload.bat` to flash the MCU\n\n_(`Build.bat` runs only once - this prevents accidentally overwriting your changes. Use **CMake** directly for subsequent builds!)_\n\n### Manual setup (without the template)\n\n1. Copy the `AAT` folder from `Include/` into your project\n2. Compile with these flags:\n   ```\n   -std=c++17 -fno-exceptions -fno-rtti -Os\n   ```\n\n### Notes\n\nFor IDEs that don't support **AVR-specific extensions**, the macro `__IDE__` is provided\n\nIt substitutes AVR-specific constructs with neutral stubs - without affecting real compilation (the macro is **not defined** in production builds)\n\n**AAT/Core/Aliases.h**\n```cpp\n#ifdef __IDE__\n\n// Dirty hack to stop the IDE from complaining about AVR-specific constructs\n#define F_CPU 0\n#define __extension__\n#define __volatile__\n#define __DOXYGEN__\n#define __AVR_ATmega328__\n\n#endif\n```\n\nThis doesn't affect the final binary - it's just a way to preserve syntax highlighting, autocompletion, and a clean error log in the IDE\n\n---\n\n## Why **Advanced AVR Templates** instead of **Arduino**?\n\n**Arduino** is fine for prototyping, but its digital pins, `delay()`, `Serial`, etc., come with significant overhead *(bounds checking, indirect calls)*\n\n**Advanced AVR Templates** provides the same convenient interface but with **zero-cost abstractions** - the compiler **aggressively inlines everything**, **generates direct `SBI`/`CBI` instructions**, and **evaluates all constants at compile time**\n\n---\n\n## Finally\n\n**Advanced AVR Templates** was built for **harsh conditions** - when **every byte of RAM is precious**, and **indirect calls**, **stack overflow**, and **memory corruption** become critical problems\n\nIt all started with a project on an MCU with **1 KB of RAM**. The problem is that the **stack grows downward** (or upward - depends on the architecture), and static variables live nearby. Free memory is squeezed between them\n\nWith just one deeply nested call, the stack starts overwriting those variables - or variables overwrite the stack\n\nStandard Arduino approaches (functions calling functions, temporary local variables, function pointers) only make things worse: indirect calls = more return addresses on the stack = deeper nesting = higher risk of memory corruption\n\nI had to write my own ~~bicycle~~ library _(yes, I reinvented the wheel)_\n\n### Core principles\n\n- **Minimal RAM** - ideally 0 bytes\n- **Minimal indirect calls** - no virtual functions, no function pointers\n- **Minimal stack depth** - to stay away from static data\n- **Everything possible at compile time** - templates, `constexpr`, `if constexpr`, `static_assert`\n\nYes, templates and aggressive inlining **increase Flash** usage. But usually **Flash is much larger**, while **RAM is not**. So:\n\n\u003e **\"Heavy at compile time - light at runtime\"**\n\u003e\n\u003e *(c) RootTool*\n\n---\n\n## License\n\nThis project is distributed under the MIT License - Do what you want. For more information, see the [LICENSE](LICENSE) file\n\n---\n\n## Feedback\n\nIf you have questions, suggestions, or bugs, you can contact me:\n\n- **Telegram (channel/blog)**: [RootTool Blog](https://t.me/RootToolBlog)\n- **Telegram (DM)**: [@RootTool28](https://t.me/RootTool28)\n- **Discord**: `.roottool` (or `RootTool#5776`)\n- **YouTube**: [RootTool](https://www.youtube.com/@RTEdits0)\n\n_(please do not contact me without reason)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froottool0%2Fadvanced-avr-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froottool0%2Fadvanced-avr-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froottool0%2Fadvanced-avr-templates/lists"}