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
94 lines
2.6 KiB
C++
94 lines
2.6 KiB
C++
#ifndef HAL_ARDUINO_H
|
|
#define HAL_ARDUINO_H
|
|
|
|
/*
|
|
* Real hardware implementation of the HAL.
|
|
*
|
|
* This file includes Arduino.h and Wire.h, so it can only be compiled
|
|
* by avr-gcc (via arduino-cli). It is included by .ino files only.
|
|
*
|
|
* Every method is a trivial passthrough to the real Arduino function.
|
|
* The point is not to add logic here -- it is to keep Arduino.h out
|
|
* of your application code so that code can compile on the host.
|
|
*/
|
|
|
|
#include <Arduino.h>
|
|
#include <Wire.h>
|
|
#include <hal.h>
|
|
|
|
class ArduinoHal : public Hal {
|
|
public:
|
|
// -- GPIO ---------------------------------------------------------------
|
|
void pinMode(uint8_t pin, uint8_t mode) override {
|
|
::pinMode(pin, mode);
|
|
}
|
|
void digitalWrite(uint8_t pin, uint8_t value) override {
|
|
::digitalWrite(pin, value);
|
|
}
|
|
uint8_t digitalRead(uint8_t pin) override {
|
|
return ::digitalRead(pin);
|
|
}
|
|
int analogRead(uint8_t pin) override {
|
|
return ::analogRead(pin);
|
|
}
|
|
void analogWrite(uint8_t pin, int value) override {
|
|
::analogWrite(pin, value);
|
|
}
|
|
|
|
// -- Timing -------------------------------------------------------------
|
|
unsigned long millis() override {
|
|
return ::millis();
|
|
}
|
|
unsigned long micros() override {
|
|
return ::micros();
|
|
}
|
|
void delay(unsigned long ms) override {
|
|
::delay(ms);
|
|
}
|
|
void delayMicroseconds(unsigned long us) override {
|
|
::delayMicroseconds(us);
|
|
}
|
|
|
|
// -- Serial -------------------------------------------------------------
|
|
void serialBegin(unsigned long baud) override {
|
|
Serial.begin(baud);
|
|
}
|
|
void serialPrint(const char* msg) override {
|
|
Serial.print(msg);
|
|
}
|
|
void serialPrintln(const char* msg) override {
|
|
Serial.println(msg);
|
|
}
|
|
int serialAvailable() override {
|
|
return Serial.available();
|
|
}
|
|
int serialRead() override {
|
|
return Serial.read();
|
|
}
|
|
|
|
// -- I2C ----------------------------------------------------------------
|
|
void i2cBegin() override {
|
|
Wire.begin();
|
|
}
|
|
void i2cBeginTransmission(uint8_t addr) override {
|
|
Wire.beginTransmission(addr);
|
|
}
|
|
size_t i2cWrite(uint8_t data) override {
|
|
return Wire.write(data);
|
|
}
|
|
uint8_t i2cEndTransmission() override {
|
|
return Wire.endTransmission();
|
|
}
|
|
uint8_t i2cRequestFrom(uint8_t addr, uint8_t count) override {
|
|
return Wire.requestFrom(addr, count);
|
|
}
|
|
int i2cAvailable() override {
|
|
return Wire.available();
|
|
}
|
|
int i2cRead() override {
|
|
return Wire.read();
|
|
}
|
|
};
|
|
|
|
#endif // HAL_ARDUINO_H
|