Skip to content

Commit

Permalink
✨ Ad inert drivers from -soft (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
kammce authored Nov 10, 2024
1 parent 9d8b782 commit 370e32d
Show file tree
Hide file tree
Showing 40 changed files with 1,283 additions and 118 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ cmake_minimum_required(VERSION 3.15)
project(libhal-util LANGUAGES CXX)

set(TEST_SOURCES_LIST
tests/inert_drivers/inert_accelerometer.test.cpp
tests/inert_drivers/inert_adc.test.cpp
tests/inert_drivers/inert_dac.test.cpp
tests/inert_drivers/inert_distance_sensor.test.cpp
tests/inert_drivers/inert_gyroscope.test.cpp
tests/inert_drivers/inert_input_pin.test.cpp
tests/inert_drivers/inert_interrupt_pin.test.cpp
tests/inert_drivers/inert_magnetometer.test.cpp
tests/inert_drivers/inert_motor.test.cpp
tests/inert_drivers/inert_pwm.test.cpp
tests/inert_drivers/inert_output_pin.test.cpp
tests/inert_drivers/inert_rotation_sensor.test.cpp
tests/inert_drivers/inert_steady_clock.test.cpp
tests/inert_drivers/inert_temperature_sensor.test.cpp
tests/inert_drivers/inert_timer.test.cpp
tests/as_bytes.test.cpp
tests/can.test.cpp
tests/bit.test.cpp
Expand Down
4 changes: 2 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def validate(self):
def build_requirements(self):
self.tool_requires("cmake/3.27.1")
self.tool_requires("libhal-cmake-util/[^4.1.0]")
self.test_requires("boost-ext-ut/1.1.9")
self.test_requires("boost-ext-ut/2.1.0")

def requirements(self):
self.requires("libhal/[^4.4.0]", transitive_headers=True)
self.requires("libhal/[^4.7.0]", transitive_headers=True)

def layout(self):
cmake_layout(self)
Expand Down
4 changes: 2 additions & 2 deletions include/libhal-util/atomic_spin_lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <libhal/lock.hpp>
#include <libhal/steady_clock.hpp>

namespace hal::soft {
namespace hal {
/**
* @brief Atomic spin lock that implements hal::pollable_lock
*
Expand Down Expand Up @@ -86,4 +86,4 @@ class timed_atomic_spin_lock : public hal::timed_lock
hal::steady_clock* m_steady_clock;
atomic_spin_lock m_atomic_spin_lock;
};
} // namespace hal::soft
} // namespace hal
7 changes: 0 additions & 7 deletions include/libhal-util/bit_bang_i2c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,3 @@ class bit_bang_i2c : public i2c
float m_duty_cycle;
};
} // namespace hal

namespace hal {
// This is here for backwards compatibility.
// We made a mistake on the first review and accidentally put bit_bang_i2c in
// the hal namespace.
using hal::soft::bit_bang_i2c;
} // namespace hal
4 changes: 2 additions & 2 deletions include/libhal-util/bit_bang_spi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <libhal/spi.hpp>
#include <libhal/steady_clock.hpp>

namespace hal::soft {
namespace hal {
/**
* @brief A bit bang implementation for spi.
*
Expand Down Expand Up @@ -124,4 +124,4 @@ class bit_bang_spi : public spi
delay_mode m_delay_mode;
};

} // namespace hal::soft
} // namespace hal
58 changes: 0 additions & 58 deletions include/libhal-util/i2c_minimum_speed.hpp

This file was deleted.

45 changes: 45 additions & 0 deletions include/libhal-util/inert_drivers/inert_accelerometer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <libhal/accelerometer.hpp>

namespace hal {
/**
* @brief Inert implementation of acceleration sensing hardware
*
*/
class inert_accelerometer : public hal::accelerometer
{
public:
/**
* @brief Create inert_accelerometer object
*
* @param p_values - what will be returned from the read function.
*/
constexpr inert_accelerometer(read_t p_values)
: m_values(p_values)
{
}

private:
read_t driver_read()
{
return m_values;
}

read_t m_values;
};
} // namespace hal
48 changes: 48 additions & 0 deletions include/libhal-util/inert_drivers/inert_adc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <libhal/adc.hpp>

#include <algorithm>

namespace hal {
/**
* @brief Inert implementation of Analog to Digital Converter (ADC) hardware
*
*/
class inert_adc : public hal::adc
{
public:
/**
* @brief Create inert_adc object
*
* @param p_result - What will be returned from inert_adc's read function,
* clamped to -1.0f to 1.0f.
*/
constexpr inert_adc(float p_result)
: m_result(std::clamp(p_result, -1.0f, 1.0f))
{
}

private:
float driver_read()
{
return m_result;
}

float m_result;
};
} // namespace hal
39 changes: 39 additions & 0 deletions include/libhal-util/inert_drivers/inert_dac.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <libhal/dac.hpp>

namespace hal {
/**
* @brief Inert implementation of Digital to Analog Converter (DAC) hardware
*
*/
class inert_dac : public hal::dac
{
public:
/**
* @brief Create inert_dac object
*/
constexpr inert_dac()
{
}

private:
void driver_write(float)
{
}
};
} // namespace hal
45 changes: 45 additions & 0 deletions include/libhal-util/inert_drivers/inert_distance_sensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <libhal/distance_sensor.hpp>

namespace hal {
/**
* @brief Inert implementation of linear distance hardware
*
*/
class inert_distance_sensor : public hal::distance_sensor
{
public:
/**
* @brief Create inert_distance_sensor object
*
* @param p_result - what will be returned from the read function.
*/
constexpr inert_distance_sensor(hal::meters p_result)
: m_result(p_result)
{
}

private:
hal::meters driver_read()
{
return m_result;
}

hal::meters m_result;
};
} // namespace hal
45 changes: 45 additions & 0 deletions include/libhal-util/inert_drivers/inert_gyroscope.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <libhal/gyroscope.hpp>

namespace hal {
/**
* @brief Inert implementation of angular velocity sensing hardware
*
*/
class inert_gyroscope : public hal::gyroscope
{
public:
/**
* @brief Create inert_gyroscope object
*
* @param p_result - what will be returned from the read function.
*/
constexpr inert_gyroscope(read_t p_result)
: m_result(p_result)
{
}

private:
read_t driver_read()
{
return m_result;
}

read_t m_result;
};
} // namespace hal
Loading

0 comments on commit 370e32d

Please sign in to comment.