Skip to content

Update more stuff to fprime v4.0.0a1 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 31 additions & 49 deletions Arduino/Drv/AnalogDriver/AnalogDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,36 @@
// ======================================================================

#include <Arduino/Drv/AnalogDriver/AnalogDriver.hpp>
#include <FpConfig.hpp>
#include <FprimeArduino.hpp>

namespace Arduino
{

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

AnalogDriver ::
AnalogDriver(
const char *const compName) : AnalogDriverComponentBase(compName), m_pin(-1)
{
}

AnalogDriver ::
~AnalogDriver()
{
}

bool AnalogDriver ::open(NATIVE_INT_TYPE pin, GpioDirection direction)
{
m_pin = pin;
pinMode(m_pin, (direction == IN) ? Arduino::DEF_INPUT : Arduino::DEF_OUTPUT);
return true;
}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

Fw::Success AnalogDriver ::
readAnalog_handler(
const NATIVE_INT_TYPE portNum,
U16 &val)
{
val = analogRead(m_pin);
return Fw::Success::SUCCESS;
}

Fw::Success AnalogDriver ::
setAnalog_handler(
const NATIVE_INT_TYPE portNum,
U8 val)
{
analogWrite(m_pin, val);
return Fw::Success::SUCCESS;
}

} // end namespace Arduino
namespace Arduino {

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

AnalogDriver ::AnalogDriver(const char* const compName) : AnalogDriverComponentBase(compName), m_pin(-1) {}

AnalogDriver ::~AnalogDriver() {}

bool AnalogDriver ::open(FwIndexType pin, GpioDirection direction) {
m_pin = pin;
pinMode(m_pin, (direction == IN) ? Arduino::DEF_INPUT : Arduino::DEF_OUTPUT);
return true;
}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

Fw::Success AnalogDriver ::readAnalog_handler(const FwIndexType portNum, U16& val) {
val = analogRead(m_pin);
return Fw::Success::SUCCESS;
}

Fw::Success AnalogDriver ::setAnalog_handler(const FwIndexType portNum, U8 val) {
analogWrite(m_pin, val);
return Fw::Success::SUCCESS;
}

} // end namespace Arduino
79 changes: 35 additions & 44 deletions Arduino/Drv/AnalogDriver/AnalogDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,48 @@

#include "Arduino/Drv/AnalogDriver/AnalogDriverComponentAc.hpp"

namespace Arduino
{

class AnalogDriver : public AnalogDriverComponentBase
{

public:
//! configure GPIO
enum GpioDirection
{
IN, //!< input
OUT, //!< output
};
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

//! Construct object AnalogDriver
//!
AnalogDriver(
const char *const compName /*!< The component name*/
);
namespace Arduino {

class AnalogDriver : public AnalogDriverComponentBase {
public:
//! configure GPIO
enum GpioDirection {
IN, //!< input
OUT, //!< output
};
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

//! Destroy object AnalogDriver
//!
~AnalogDriver();
//! Construct object AnalogDriver
//!
AnalogDriver(const char* const compName /*!< The component name*/
);

bool open(NATIVE_INT_TYPE pin, GpioDirection direction);
//! Destroy object AnalogDriver
//!
~AnalogDriver();

PRIVATE :
bool open(FwIndexType pin, GpioDirection direction);

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
private:
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

//! Handler implementation for readAnalog
//!
Fw::Success
readAnalog_handler(
const NATIVE_INT_TYPE portNum, /*!< The port number*/
U16 &val);
//! Handler implementation for readAnalog
//!
Fw::Success readAnalog_handler(const FwIndexType portNum, /*!< The port number*/
U16& val);

//! Handler implementation for setAnalog
//!
Fw::Success setAnalog_handler(
const NATIVE_INT_TYPE portNum, /*!< The port number*/
U8 val);
//! Handler implementation for setAnalog
//!
Fw::Success setAnalog_handler(const FwIndexType portNum, /*!< The port number*/
U8 val);

PlatformIntType m_pin;
};
PlatformIntType m_pin;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are soon getting rid of PlatformIntType. Should replace this with int

};

} // end namespace Arduino
} // end namespace Arduino

#endif
7 changes: 3 additions & 4 deletions Arduino/Drv/HardwareRateDriver/HardwareRateDriverTeensy.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include <FpConfig.hpp>
#include <IntervalTimer.h>
#include <Arduino/Drv/HardwareRateDriver/HardwareRateDriver.hpp>
#include <FprimeArduino.hpp>
#include <IntervalTimer.h>
#include <Fw/Logger/Logger.hpp>

namespace Arduino {
IntervalTimer s_itimer;

void HardwareRateDriver::start() {
U32 microseconds = m_interval * 1000;
(void) s_itimer.begin(HardwareRateDriver::s_timerISR, microseconds);
(void)s_itimer.begin(HardwareRateDriver::s_timerISR, microseconds);
Fw::Logger::log("Starting base rate group clock with period of %" PRIu32 " microseconds\n", microseconds);
}

Expand All @@ -21,4 +20,4 @@ void HardwareRateDriver::s_timerISR() {
s_timer(s_driver);
}

};
}; // namespace Arduino
55 changes: 15 additions & 40 deletions Arduino/Drv/I2cDriver/I2cDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,35 @@
// \brief cpp file for I2cDriver component implementation class
// ======================================================================


#include <Arduino/Drv/I2cDriver/I2cDriver.hpp>
#include <FpConfig.hpp>
#include "Fw/Types/Assert.hpp"

namespace Arduino {

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

I2cDriver ::
I2cDriver(
const char *const compName
) : I2cDriverComponentBase(compName),
m_port_pointer(static_cast<POINTER_CAST>(NULL))
{

}
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

I2cDriver ::
~I2cDriver()
{
I2cDriver ::I2cDriver(const char* const compName) : I2cDriverComponentBase(compName), m_port_pointer(nullptr) {}

}
I2cDriver ::~I2cDriver() {}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

Drv::I2cStatus I2cDriver ::
read_handler(
const NATIVE_INT_TYPE portNum,
U32 addr,
Fw::Buffer &serBuffer
)
{
Drv::I2cStatus I2cDriver ::read_handler(const FwIndexType portNum, U32 addr, Fw::Buffer& serBuffer) {
// Ensure buffer is not a nullptr
FW_ASSERT(serBuffer.getData());

return read_data(addr, serBuffer);
}

Drv::I2cStatus I2cDriver ::
write_handler(
const NATIVE_INT_TYPE portNum,
U32 addr,
Fw::Buffer &serBuffer
)
{
}

Drv::I2cStatus I2cDriver ::write_handler(const FwIndexType portNum, U32 addr, Fw::Buffer& serBuffer) {
// Ensure buffer is not a nullptr
FW_ASSERT(serBuffer.getData());

return write_data(addr, serBuffer);
}
}

} // end namespace Arduino
} // end namespace Arduino
22 changes: 9 additions & 13 deletions Arduino/Drv/I2cDriver/I2cDriverArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@
// \brief cpp file for I2cDriver component implementation class
// ======================================================================


#include <Arduino/Drv/I2cDriver/I2cDriver.hpp>
#include <FpConfig.hpp>
#include "Fw/Types/Assert.hpp"

namespace Arduino {

void I2cDriver::open(TwoWire *wire) {
void I2cDriver::open(TwoWire* wire) {
FW_ASSERT(wire != nullptr);
m_port_pointer = wire;
wire->begin();
}
}

void I2cDriver::close() {
void I2cDriver::close() {
FW_ASSERT(m_port_pointer != 0);
TwoWire* wire_ptr = reinterpret_cast<TwoWire*>(m_port_pointer);
wire_ptr->end();
}
}

Drv::I2cStatus I2cDriver::read_data(U32 addr, Fw::Buffer& fwBuffer)
{
Drv::I2cStatus I2cDriver::read_data(U32 addr, Fw::Buffer& fwBuffer) {
TwoWire* wire_ptr = reinterpret_cast<TwoWire*>(m_port_pointer);

wire_ptr->requestFrom(static_cast<U8>(addr), fwBuffer.getSize());
Expand All @@ -39,10 +36,9 @@ namespace Arduino {
fwBuffer.setSize(count);

return Drv::I2cStatus::I2C_OK;
}
}

Drv::I2cStatus I2cDriver::write_data(U32 addr, Fw::Buffer& fwBuffer)
{
Drv::I2cStatus I2cDriver::write_data(U32 addr, Fw::Buffer& fwBuffer) {
FW_ASSERT(m_port_pointer != 0);
TwoWire* wire_ptr = reinterpret_cast<TwoWire*>(m_port_pointer);

Expand All @@ -51,6 +47,6 @@ namespace Arduino {
wire_ptr->endTransmission();

return Drv::I2cStatus::I2C_OK;
}
}

} // end namespace Arduino
} // end namespace Arduino
11 changes: 5 additions & 6 deletions Arduino/Drv/I2cNodeDriver/I2cNodeDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// ======================================================================

#include "Arduino/Drv/I2cNodeDriver/I2cNodeDriver.hpp"
#include "FpConfig.hpp"
#include "Fw/Types/Assert.hpp"

namespace Arduino {
Expand All @@ -19,9 +18,9 @@ I2cNodeDriver ::I2cNodeDriver(const char* const compName) : I2cNodeDriverCompone

I2cNodeDriver ::~I2cNodeDriver() {}

void I2cNodeDriver ::configure(const U16 address, TwoWire &wire) {
void I2cNodeDriver ::configure(const U16 address, TwoWire& wire) {
FW_ASSERT(this->m_wire == nullptr);
FW_ASSERT(I2cNodeDriver::s_component == nullptr); // Cannot run multiple I2cNodes at once
FW_ASSERT(I2cNodeDriver::s_component == nullptr); // Cannot run multiple I2cNodes at once
this->m_wire = &wire;
I2cNodeDriver ::s_component = this;
this->m_wire->begin(address);
Expand All @@ -31,14 +30,14 @@ void I2cNodeDriver ::configure(const U16 address, TwoWire &wire) {

void I2cNodeDriver ::write(int size) {
FW_ASSERT(this->m_wire != nullptr);
FW_ASSERT(this->m_wire->available() >= size); // If size was reported available, then at least that size must be
FW_ASSERT(this->m_wire->available() >= size); // If size was reported available, then at least that size must be
this->m_wire->readBytes(this->m_buffer, size);
Fw::Buffer writeData(this->m_buffer, size);
this->write_out(0, this->m_address, writeData);
}

void I2cNodeDriver ::writeCallback(int size) {
FW_ASSERT(I2cNodeDriver::s_component != nullptr); // To reach this statement, this variable must be set
FW_ASSERT(I2cNodeDriver::s_component != nullptr); // To reach this statement, this variable must be set
I2cNodeDriver::s_component->write(size);
}

Expand All @@ -50,7 +49,7 @@ void I2cNodeDriver ::read() {
}

void I2cNodeDriver ::readCallback() {
FW_ASSERT(I2cNodeDriver::s_component != nullptr); // To reach this statement, this variable must be set
FW_ASSERT(I2cNodeDriver::s_component != nullptr); // To reach this statement, this variable must be set
I2cNodeDriver::s_component->read();
}

Expand Down
14 changes: 14 additions & 0 deletions Arduino/Drv/Ip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding files
# MOD_DEPS: (optional) module dependencies
#
####
restrict_platforms(ArduinoFw)

set(SOURCE_FILES

)

register_fprime_module()
Loading