Make use of C++ standard library

This commit is contained in:
BlackMark 2022-05-29 16:14:42 +02:00
parent 85346f258f
commit 8bf3d1a874
3 changed files with 19 additions and 13 deletions

View File

@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
#include "../io/io.hpp"
namespace spi {
@ -44,8 +46,8 @@ struct HardwareConfig {
static constexpr auto PULLUP = pullup;
};
template <io::P sckPin, io::P misoPin, io::P mosiPin, io::P ssPin, uint32_t freq = 100'000, Mode mode = Mode::MODE_0,
BitOrder bitOrder = BitOrder::MSB_FIRST, uint8_t bits = 8, bool pullup = false>
template <io::P sckPin, io::P misoPin, io::P mosiPin, io::P ssPin, std::uint32_t freq = 100'000,
Mode mode = Mode::MODE_0, BitOrder bitOrder = BitOrder::MSB_FIRST, std::uint8_t bits = 8, bool pullup = false>
struct SoftwareConfig {
static constexpr auto SCK_PIN = sckPin;
static constexpr auto MISO_PIN = misoPin;

View File

@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
#include "../io/io.hpp"
namespace spi {
@ -9,7 +11,7 @@ namespace spi {
template <class Cfg>
class Hardware {
public:
using word_t = uint8_t;
using word_t = std::uint8_t;
static void init()
{
@ -58,7 +60,7 @@ class Hardware {
static void setClockDiv()
{
uint8_t ui8ClockDiv = static_cast<uint8_t>(Cfg::FREQ);
std::uint8_t ui8ClockDiv = static_cast<std::uint8_t>(Cfg::FREQ);
if (ui8ClockDiv & 1) {
SPCR = SPCR | (1 << SPR0);

View File

@ -2,12 +2,14 @@
#include "../clock.hpp"
#include <stdint.h>
#include <type_traits>
#include <utility>
#include <cstdint>
#include <avr/interrupt.h>
#include "../io/io.hpp"
#include "../util/type.hpp"
#include "../util/util.hpp"
namespace spi {
@ -27,10 +29,10 @@ class Software {
public:
static_assert(Cfg::BITS >= 1 && Cfg::BITS <= 64, "Word size must be in range [1-64]");
// clang-format off
using word_t = util::conditional_t<Cfg::BITS <= 8, uint8_t,
util::conditional_t<Cfg::BITS <= 16, uint16_t,
util::conditional_t<Cfg::BITS <= 32, uint32_t,
uint64_t>>>;
using word_t = std::conditional_t<Cfg::BITS <= 8, std::uint8_t,
std::conditional_t<Cfg::BITS <= 16, std::uint16_t,
std::conditional_t<Cfg::BITS <= 32, std::uint32_t,
std::uint64_t>>>;
// clang-format on
static void init()
@ -76,7 +78,7 @@ class Software {
_delay_us(DELAY_US);
}
},
util::make_index_sequence<Cfg::BITS>{});
std::make_index_sequence<Cfg::BITS>{});
enableInterrupts(oldInterruptState);
@ -96,14 +98,14 @@ class Software {
static constexpr auto DELAY_US = calcClockDelay();
static inline uint8_t disableInterrupts()
static inline std::uint8_t disableInterrupts()
{
const auto oldInterruptState = SREG;
cli();
return oldInterruptState;
}
static inline void enableInterrupts(const uint8_t oldInterruptState)
static inline void enableInterrupts(const std::uint8_t oldInterruptState)
{
SREG = oldInterruptState;
}