diff --git a/include/sta/devices/arduino/bus/i2c.hpp b/include/sta/devices/arduino/bus/i2c.hpp new file mode 100644 index 0000000..ff9a4e9 --- /dev/null +++ b/include/sta/devices/arduino/bus/i2c.hpp @@ -0,0 +1,36 @@ +#ifndef STA_CORE_ARDUINO_I2C_HPP +#define STA_CORE_ARDUINO_I2C_HPP + +#include +#ifdef STA_PLATFORM_ARDUINO + +#include +#include + +namespace sta +{ + class ArduinoI2C : public I2C + { + public: + ArduinoI2C(Mutex * mutex=nullptr, uint16_t address); + + void transfer16(uint16_t value) override; + void transfer(const uint8_t * buffer, size_t size) override; + void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override; + void receive(uint8_t * buffer, size_t size) override; + void fill(uint8_t value, size_t count) override; + + void acquire(); + void release(); + }; + + class ArduinoI2CDevice : public I2CDevice + { + public: + ArduinoI2CDevice(I2C * intf, int address, bool master=false, bool blocking=true); + }; +} // namespace sta + +#endif // STA_PLATFORM_ARDUINO + +#endif // STA_CORE_ARDUINO_I2C_HPP \ No newline at end of file diff --git a/include/sta/devices/arduino/bus/spi.hpp b/include/sta/devices/arduino/bus/spi.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/sta/devices/arduino/delay.hpp b/include/sta/devices/arduino/delay.hpp new file mode 100644 index 0000000..bcc6ebb --- /dev/null +++ b/include/sta/devices/arduino/delay.hpp @@ -0,0 +1,28 @@ +#ifndef STA_CORE_ARDUINO_DELAY_HPP +#define STA_CORE_ARDUINO_DELAY_HPP + +// Only enable module on Arduino platform +#include + +#if defined(STA_PLATFORM_ARDUINO) || defined(DOXYGEN) + +namespace sta +{ + /** + * @brief Millisecond delay. + * + * @param ms Milliseconds + */ + void delayMs(uint32_t ms); + + /** + * @brief Microsecond delay. + * + * @param us Microseconds + */ + void delayUs(uint32_t us); +} // namespace sta + +#endif // STA_PLATFORM_ARDUINO + +#endif // STA_CORE_ARDUINO_DELAY_HPP \ No newline at end of file diff --git a/include/sta/devices/arduino/gpio_pin.hpp b/include/sta/devices/arduino/gpio_pin.hpp new file mode 100644 index 0000000..dd03289 --- /dev/null +++ b/include/sta/devices/arduino/gpio_pin.hpp @@ -0,0 +1,44 @@ +/** + * @file + * @brief Wrapper for Arduino GPIO pins. + */ +#ifndef STA_CORE_ARDUINO_GPIO_PIN_HPP +#define STA_CORE_ARDUINO_GPIO_PIN_HPP + +// Only enable module on Arduino platform w/ HAL GPIO module enabled +#include + +#if defined(STA_PLATFORM_ARDUINO) || defined(DOXYGEN) + +#include +#include + +namespace sta +{ + class ArduinoGpioPin : public GpioPin + { + public: + /** + * @param port GPIO port + * @param pin Pin index + */ + ArduinoGpioPin(uint16_t pin); + + void setState(GpioPinState state) override; + + GpioPinState getState() override; + + /** + * @brief Get pin index for pin. + * + * @return Pin index + */ + uint16_t getPin() const; + private: + uint16_t pin_; /**< GPIO pin */ + }; +} // namespace sta + +#endif // STA_ARDUINO_GPIO_ENABLED + +#endif // STA_CORE_ARDUINO_GPIO_PIN_HPP \ No newline at end of file diff --git a/include/sta/devices/arduino/hal.hpp b/include/sta/devices/arduino/hal.hpp new file mode 100644 index 0000000..1693555 --- /dev/null +++ b/include/sta/devices/arduino/hal.hpp @@ -0,0 +1,8 @@ +#ifndef STA_CORE_ARDUINO_HAL_HPP +#define STA_CORE_ARDUINO_HAL_HPP + +#include +#include +#include + +#endif // STA_CORE_ARDUINO_HAL_HPP \ No newline at end of file diff --git a/include/sta/devices/arduino/mcu/common.hpp b/include/sta/devices/arduino/mcu/common.hpp new file mode 100644 index 0000000..3a79c10 --- /dev/null +++ b/include/sta/devices/arduino/mcu/common.hpp @@ -0,0 +1,7 @@ +#ifndef STA_CORE_ARDUINO_MCU_COMMON_HPP +#define STA_CORE_ARDUINO_MCU_COMMON_HPP + +// Enable Arduino platform +#define STA_PLATFORM_ARDUINO + +#endif // STA_CORE_ARDUINO_MCU_COMMON_HPP \ No newline at end of file diff --git a/include/sta/devices/arduino/mcu/uno_r3.hpp b/include/sta/devices/arduino/mcu/uno_r3.hpp new file mode 100644 index 0000000..a367296 --- /dev/null +++ b/include/sta/devices/arduino/mcu/uno_r3.hpp @@ -0,0 +1,6 @@ +#ifndef STA_CORE_ARDUINO_MCU_UNO_R3_HPP +#define STA_CORE_ARDUINO_MCU_UNO_R3_HPP + +#include + +#endif // STA_CORE_ARDUINO_MCU_UNO_R3_HPPs \ No newline at end of file diff --git a/include/sta/devices/arduino/not_implemented.hpp b/include/sta/devices/arduino/not_implemented.hpp deleted file mode 100644 index 5c8d8b3..0000000 --- a/include/sta/devices/arduino/not_implemented.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef STA_CORE_ARDUINO_NOT_IMPLEMENTED_HPP -#define STA_CORE_ARDUINO_NOT_IMPLEMENTED_HPP - - -/** - * @defgroup sta_core_arduino Arduino - * @ingroup sta_core_platforms - * @brief Modules implemented for the Arduino platform. - */ - - -#endif // STA_CORE_ARDUINO_NOT_IMPLEMENTED_HPP \ No newline at end of file diff --git a/src/devices/arduino/bus/i2c.cpp b/src/devices/arduino/bus/i2c.cpp new file mode 100644 index 0000000..c52503a --- /dev/null +++ b/src/devices/arduino/bus/i2c.cpp @@ -0,0 +1,68 @@ +#include + +#ifdef STA_PLATFORM_ARDUINO + +#include + + +namespace sta +{ + ArduinoI2C::ArduinoI2C(Mutex * mutex, uint16_t address) + : I2C{mutex} + { + Wire.begin(address); + } + + void ArduinoI2C::transfer16(uint16_t value) + { + Wire.write(value); + } + + void ArduinoI2C::transfer(const uint8_t * buffer, size_t size) + { + Wire.write(buffer, size); + } + + void ArduinoI2C::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) + { + // NOT REALLY A THING HERE, IS IT? + } + + void ArduinoI2C::receive(uint8_t * buffer, size_t size) + { + + } + + void ArduinoI2C::fill(uint8_t value, size_t count) + { + // Initialize a buffer of size count and fill it with the value. + uint8_t *buffer = new uint8_t[count]; + memset(buffer, value, count); + + Serial.write(buffer, count); + + delete [] buffer; + } + + void ArduinoI2C::acquire() + { + I2C::acquire(); + + Wire.beginTransmission(address_); + } + + void ArduinoI2C::release() + { + Wire.endTransmission(); + + I2C::release(); + } + + ArduinoI2CDevice::ArduinoI2CDevice(I2C * intf, int address, bool master, bool blocking) + : I2CDevice{intf, address, master, blocking} + { + + } +} // namespace sta + +#endif // STA_PLATFORM_ARDUINO \ No newline at end of file diff --git a/src/devices/arduino/bus/spi.cpp b/src/devices/arduino/bus/spi.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/devices/arduino/delay.cpp b/src/devices/arduino/delay.cpp new file mode 100644 index 0000000..b3a39f1 --- /dev/null +++ b/src/devices/arduino/delay.cpp @@ -0,0 +1,20 @@ +#include + +#ifdef STA_PLATFORM_ARDUINO + +#include + +namespace sta +{ + void delayMs(uint32_t ms) + { + delay(ms); + } + + void delayUs(uint32_t us) + { + delayMicroseconds(us); + } +} // namespace sta + +#endif // STA_PLATFORM_ARDUINO \ No newline at end of file diff --git a/src/devices/arduino/gpio_pin.cpp b/src/devices/arduino/gpio_pin.cpp new file mode 100644 index 0000000..1d3b232 --- /dev/null +++ b/src/devices/arduino/gpio_pin.cpp @@ -0,0 +1,28 @@ +#include + +#ifdef STA_PLATFORM_ARDUINO + +#include + +namespace sta +{ + ArduinoGpioPin::ArduinoGpioPin(uint16_t pin) : pin_{pin} { } + + void ArduinoGpioPin::setState(GpioPinState state) + { + digitalWrite(pin_, (state == GpioPinState::GPIO_LOW) ? LOW : HIGH); + } + + GpioPinState ArduinoGpioPin::getState() + { + return digitalRead(pin_) == HIGH ? GpioPinState::GPIO_HIGH : GpioPinState::GPIO_LOW; + } + + uint16_t ArduinoGpioPin::getPin() const + { + return pin_; + } + +} // namespace sta + +#endif // STA_PLATFORM_ARDUINO \ No newline at end of file diff --git a/src/devices/raspi/bus/i2c/i2c.cpp b/src/devices/raspi/bus/i2c.cpp similarity index 100% rename from src/devices/raspi/bus/i2c/i2c.cpp rename to src/devices/raspi/bus/i2c.cpp diff --git a/src/devices/raspi/bus/spi/spi.cpp b/src/devices/raspi/bus/spi.cpp similarity index 100% rename from src/devices/raspi/bus/spi/spi.cpp rename to src/devices/raspi/bus/spi.cpp diff --git a/src/devices/stm32/spi.cpp b/src/devices/stm32/bus/spi.cpp similarity index 100% rename from src/devices/stm32/spi.cpp rename to src/devices/stm32/bus/spi.cpp