Skip to content

Commit

Permalink
Change .clang-format to the latest M5 one
Browse files Browse the repository at this point in the history
  • Loading branch information
GOB52 committed Sep 26, 2024
1 parent 950a9cc commit 09d831f
Show file tree
Hide file tree
Showing 20 changed files with 722 additions and 607 deletions.
5 changes: 2 additions & 3 deletions src/M5HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#define M5HAL_STATIC_MACRO_PATH_IMPL M5HAL_STATIC_MACRO_CONCAT(M5HAL_TARGET_PLATFORM_PATH, impl.inl)

#if M5HAL_TARGET_PLATFORM_NUMBER != 0
#include M5HAL_STATIC_MACRO_PATH_IMPL
#include M5HAL_STATIC_MACRO_PATH_IMPL
#endif

// Arduino環境の場合のみ、Arduino用の実装を用意
#if M5HAL_FRAMEWORK_HAS_ARDUINO
#include "./m5_hal/frameworks/arduino/impl.inl"
#include "./m5_hal/frameworks/arduino/impl.inl"
#endif

24 changes: 12 additions & 12 deletions src/M5HAL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@
#include "./m5_hal/bus/bus.hpp"
#include "./m5_hal/interface/gpio.hpp"

#define M5HAL_STATIC_MACRO_STRING(x) #x
#define M5HAL_STATIC_MACRO_CONCAT(x, y) M5HAL_STATIC_MACRO_STRING(x/y)
#define M5HAL_STATIC_MACRO_PATH_HEADER M5HAL_STATIC_MACRO_CONCAT(M5HAL_TARGET_PLATFORM_PATH, header.hpp)
#define M5HAL_STATIC_MACRO_STRING(x) #x
#define M5HAL_STATIC_MACRO_CONCAT(x, y) M5HAL_STATIC_MACRO_STRING(x / y)
#define M5HAL_STATIC_MACRO_PATH_HEADER M5HAL_STATIC_MACRO_CONCAT(M5HAL_TARGET_PLATFORM_PATH, header.hpp)

#if M5HAL_TARGET_PLATFORM_NUMBER != 0
#include M5HAL_STATIC_MACRO_PATH_HEADER
#include M5HAL_STATIC_MACRO_PATH_HEADER
#endif

#undef M5HAL_STATIC_MACRO_PATH_HEADER

// Arduinoフレームワークがある場合は準備
#if M5HAL_FRAMEWORK_HAS_ARDUINO
#include "./m5_hal/frameworks/arduino/header.hpp"
#include "./m5_hal/frameworks/arduino/header.hpp"

// 対象プラットフォームが特定されない場合は Arduino経由の実装を利用
#if 1 // M5HAL_TARGET_PLATFORM_NUMBER == 0
#if 1 // M5HAL_TARGET_PLATFORM_NUMBER == 0

namespace m5 {
namespace hal {
using namespace frameworks::arduino;
}
}
namespace m5 {
namespace hal {
using namespace frameworks::arduino;
}
} // namespace m5

#endif
#endif

#endif

Expand Down
138 changes: 93 additions & 45 deletions src/m5_hal/bus/bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,79 +24,113 @@ struct Accessor;
//-------------------------------------------------------------------------
// 通信バスの初期化に必要な条件を記述するため基底インターフェイス
struct BusConfig {
virtual ~BusConfig() = default;
virtual ~BusConfig() = default;
virtual types::bus_type_t getBusType(void) const = 0;
types::periph_t periph;
};

//-------------------------------------------------------------------------
// 実際の通信に必要な条件を記述するための基底インターフェイス
struct AccessConfig {
virtual ~AccessConfig() = default;
virtual ~AccessConfig() = default;
virtual types::bus_type_t getBusType(void) const = 0;
void (*callback_begin)(Accessor*) = nullptr; // 通信開始時時に呼び出すコールバック関数
void (*callback_end)(Accessor*) = nullptr; // 通信終了時に呼び出すコールバック関数
void (*callback_begin)(Accessor*) = nullptr; // 通信開始時時に呼び出すコールバック関数
void (*callback_end)(Accessor*) = nullptr; // 通信終了時に呼び出すコールバック関数
};

//-------------------------------------------------------------------------
// 特定の通信相手との各種通信条件を記述するため基底インターフェイス
struct Accessor : public interface::io::Output, public interface::io::Input
{
virtual ~Accessor(void) = default;
virtual types::bus_type_t getBusType(void) const = 0;
struct Accessor : public interface::io::Output, public interface::io::Input {
virtual ~Accessor(void) = default;
virtual types::bus_type_t getBusType(void) const = 0;
virtual const AccessConfig& getAccessConfig(void) const = 0;

Accessor(Bus& bus) : _bus { bus } {}
Bus& getBus(void) const { return _bus; };
Accessor(Bus& bus) : _bus{bus}
{
}
Bus& getBus(void) const
{
return _bus;
};
const BusConfig& getBusConfig(void) const;

virtual m5::stl::expected<void, m5::hal::error::error_t> startWrite(void) { return {}; }
virtual m5::stl::expected<void, m5::hal::error::error_t> startRead(void) { return {}; }
virtual m5::stl::expected<void, m5::hal::error::error_t> stop(void) { return {}; }
virtual m5::stl::expected<size_t, m5::hal::error::error_t> readLastNack(uint8_t* data, size_t len) { return readWithLastNackFlag(data, len, true); }
virtual m5::stl::expected<size_t, m5::hal::error::error_t> readWithLastNackFlag(uint8_t* data, size_t len, bool last_nack = false) { return read(data, len); }
virtual m5::stl::expected<void, m5::hal::error::error_t> startWrite(void)
{
return {};
}
virtual m5::stl::expected<void, m5::hal::error::error_t> startRead(void)
{
return {};
}
virtual m5::stl::expected<void, m5::hal::error::error_t> stop(void)
{
return {};
}
virtual m5::stl::expected<size_t, m5::hal::error::error_t> readLastNack(uint8_t* data, size_t len)
{
return readWithLastNackFlag(data, len, true);
}
virtual m5::stl::expected<size_t, m5::hal::error::error_t> readWithLastNackFlag(uint8_t* data, size_t len,
bool last_nack = false)
{
return read(data, len);
}

protected:
Bus& _bus;
};

template<typename TBusAccessInterface>
template <typename TBusAccessInterface>
struct DefaultBusExtension {
DefaultBusExtension(TBusAccessInterface&) {}
DefaultBusExtension(TBusAccessInterface&)
{
}
};

template<typename TBus, typename TBusAccessInterface, typename TExtension = DefaultBusExtension<TBusAccessInterface>>
template <typename TBus, typename TBusAccessInterface, typename TExtension = DefaultBusExtension<TBusAccessInterface>>
struct BusAccessor {
BusAccessor() = delete;
BusAccessor(TBus& bus, TBusAccessInterface& access) : _bus(bus), _access(access), _extension(access) {}
BusAccessor(const BusAccessor&) = delete;
BusAccessor(TBus& bus, TBusAccessInterface& access) : _bus(bus), _access(access), _extension(access)
{
}
BusAccessor(const BusAccessor&) = delete;
BusAccessor& operator=(const BusAccessor&) = delete;
BusAccessor(BusAccessor&& other) : _owner(other.owner), _bus(other.bus), _access(other.access), _extension(other.access) {
BusAccessor(BusAccessor&& other)
: _owner(other.owner), _bus(other.bus), _access(other.access), _extension(other.access)
{
other._owner = false;
}
void release() {
if( this->_owner ) {
void release()
{
if (this->_owner) {
this->_bus.release();
}
this->_owner = false;
}
BusAccessor& operator=(BusAccessor&& other) {
BusAccessor& operator=(BusAccessor&& other)
{
this->release();
this->_owner = other._owner;
this->_bus = other._bus;
this->_access = other._access;
this->_owner = other._owner;
this->_bus = other._bus;
this->_access = other._access;
this->_extension = TExtension(this->_access);
other._owner = false;
other._owner = false;
}
/*
void read() { this->_access.read(this->_bus);}
void write() { this->_access.write(this->_bus); }
void transmit() { this->_access.transmit(this->_bus); }
*/
TExtension& extension()
{
return this->_extension;
}
/*
void read() { this->_access.read(this->_bus);}
void write() { this->_access.write(this->_bus); }
void transmit() { this->_access.transmit(this->_bus); }
*/
TExtension& extension() { return this->_extension; }

~BusAccessor() {
~BusAccessor()
{
this->release();
}

protected:
bool _owner = true;
TBus& _bus;
Expand All @@ -108,22 +142,29 @@ struct BusAccessor {
// 通信バスの基底インターフェイス
struct Bus {
public:
virtual ~Bus() = default;
virtual ~Bus() = default;
virtual types::bus_type_t getBusType(void) const = 0;

// initとreleaseはユーザーは直接呼ばない。 createBus / releaseBus経由で使用する。

virtual const BusConfig& getConfig(void) const = 0;

// バスの初期化
virtual error::error_t init(const BusConfig& config) { return error::error_t::NOT_IMPLEMENTED; }
virtual error::error_t init(const BusConfig& config)
{
return error::error_t::NOT_IMPLEMENTED;
}
// バスの解放
virtual error::error_t release(void) { return error::error_t::NOT_IMPLEMENTED; }
virtual error::error_t release(void)
{
return error::error_t::NOT_IMPLEMENTED;
}

/// @note expectedは参照をサポートしていないのでポインタを含める形とした。
virtual m5::stl::expected<Accessor*, m5::hal::error::error_t> beginAccess(const AccessConfig& access_config) = 0;

virtual error::error_t endAccess(Accessor* Accessor) {
virtual error::error_t endAccess(Accessor* Accessor)
{
if (Accessor && _Accessor.get() == Accessor) {
_Accessor.reset(nullptr);
return error::error_t::OK;
Expand All @@ -132,18 +173,25 @@ struct Bus {
}

// 無条件でバスをロックしたい場合に使用する
virtual m5::stl::expected<void, error::error_t> lock(void) { return m5::stl::make_unexpected(error::error_t::NOT_IMPLEMENTED); }
virtual m5::stl::expected<void, error::error_t> unlock(void) { return m5::stl::make_unexpected(error::error_t::NOT_IMPLEMENTED); }
virtual m5::stl::expected<void, error::error_t> lock(void)
{
return m5::stl::make_unexpected(error::error_t::NOT_IMPLEMENTED);
}
virtual m5::stl::expected<void, error::error_t> unlock(void)
{
return m5::stl::make_unexpected(error::error_t::NOT_IMPLEMENTED);
}

protected:
std::unique_ptr<Accessor> _Accessor;
};

//-------------------------------------------------------------------------
// error::error_t Bus::beginAccess(const Accessor* Accessor) { return (Accessor->getBusType() != getBusType()) ? error::error_t::INVALID_ARGUMENT : error::error_t::OK; }
// error::error_t Bus::beginAccess(const Accessor* Accessor) { return (Accessor->getBusType() != getBusType()) ?
// error::error_t::INVALID_ARGUMENT : error::error_t::OK; }

} // namespace bus
} // namespace hal
} // namespace m5
} // namespace bus
} // namespace hal
} // namespace m5

#endif
6 changes: 3 additions & 3 deletions src/m5_hal/bus/bus.inl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ const BusConfig& Accessor::getBusConfig(void) const
return _bus.getConfig();
}

} // namespace bus
} // namespace hal
} // namespace m5
} // namespace bus
} // namespace hal
} // namespace m5
Loading

0 comments on commit 09d831f

Please sign in to comment.