Anvil v1.0.0 -- Arduino build tool with HAL and test scaffolding

Single-binary CLI that scaffolds testable Arduino projects, compiles,
uploads, and monitors serial output. Templates embed a hardware
abstraction layer, Google Mock infrastructure, and CMake-based host
tests so application logic can be verified without hardware.

Commands: new, doctor, setup, devices, build, upload, monitor
39 Rust tests (21 unit, 18 integration)
Cross-platform: Linux and Windows
This commit is contained in:
Eric Ratliff
2026-02-15 11:16:17 -06:00
commit 3298844399
41 changed files with 4866 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
#ifndef HAL_H
#define HAL_H
#include <stdint.h>
// Pin modes (match Arduino constants)
#ifndef INPUT
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#endif
#ifndef LOW
#define LOW 0x0
#define HIGH 0x1
#endif
// LED_BUILTIN for host builds
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
/*
* Hardware Abstraction Layer
*
* Abstract interface over GPIO, timing, serial, and I2C. Sketch logic
* depends on this interface only -- never on Arduino.h directly.
*
* Two implementations:
* hal_arduino.h -- real hardware (included by .ino files)
* mock_hal.h -- Google Mock (included by test files)
*/
class Hal {
public:
virtual ~Hal() = default;
// -- GPIO ---------------------------------------------------------------
virtual void pinMode(uint8_t pin, uint8_t mode) = 0;
virtual void digitalWrite(uint8_t pin, uint8_t value) = 0;
virtual uint8_t digitalRead(uint8_t pin) = 0;
virtual int analogRead(uint8_t pin) = 0;
virtual void analogWrite(uint8_t pin, int value) = 0;
// -- Timing -------------------------------------------------------------
virtual unsigned long millis() = 0;
virtual unsigned long micros() = 0;
virtual void delay(unsigned long ms) = 0;
virtual void delayMicroseconds(unsigned long us) = 0;
// -- Serial -------------------------------------------------------------
virtual void serialBegin(unsigned long baud) = 0;
virtual void serialPrint(const char* msg) = 0;
virtual void serialPrintln(const char* msg) = 0;
virtual int serialAvailable() = 0;
virtual int serialRead() = 0;
// -- I2C ----------------------------------------------------------------
virtual void i2cBegin() = 0;
virtual void i2cBeginTransmission(uint8_t addr) = 0;
virtual size_t i2cWrite(uint8_t data) = 0;
virtual uint8_t i2cEndTransmission() = 0;
virtual uint8_t i2cRequestFrom(uint8_t addr, uint8_t count) = 0;
virtual int i2cAvailable() = 0;
virtual int i2cRead() = 0;
};
#endif // HAL_H