Skip to content

Commit 00328e0

Browse files
committed
Fixes to array and initializer_list.
WIP: Timer, fixed point and servo.
1 parent d19e4fe commit 00328e0

File tree

6 files changed

+114
-37
lines changed

6 files changed

+114
-37
lines changed

src/arduino_etl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ struct PinLow_t {};
1212
struct PinHigh_t {};
1313

1414
namespace {
15-
PinLow_t Low;
16-
PinHigh_t High;
15+
static constexpr PinLow_t Low;
16+
static constexpr PinHigh_t High;
1717
}
1818

1919
// digitalWrite overloads

src/array

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ namespace std {
5757
T* data () noexcept { return _m_elements; }
5858
constexpr const T* data () const noexcept { return _m_elements; }
5959

60-
private:
61-
T _m_elements[N];
60+
typedef T __Type[N];
61+
__Type _m_elements;
6262
};
6363

6464
// Partial specialization for Zero-sized array

src/hal/timer.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//----------------------------------------------------------------------------------------------------------------------
2+
// Timer peripherals
3+
//----------------------------------------------------------------------------------------------------------------------
4+
#pragma once
5+
6+
namespace etl::hal {
7+
8+
template<
9+
class Tcnt_,
10+
class OcrA, class OcrB,
11+
class TccrA, class TccrB, class TccrC,
12+
class Tifr, class Timsk>
13+
struct Timer
14+
{
15+
//
16+
};
17+
18+
} // namespace etl::hal

src/initializer_list

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,63 @@
22
// Initializer list
33
//----------------------------------------------------------------------------------------------------------------------
44
#pragma once
5-
#ifndef _INITIALIZER_LIST_
6-
#define _INITIALIZER_LIST_
7-
8-
namespace std {
9-
10-
template<class E> class initializer_list {
11-
public: // Nested types
12-
using value_type = E;
13-
using reference = const E&;
14-
using const_reference = const E&;
15-
using size_type = size_t;
16-
using iterator = const E*;
17-
using const_iterator = const E*;
18-
19-
public: // Interface
20-
constexpr initializer_list() noexcept;
21-
constexpr size_t size() const noexcept { return _end - _start; } ///< number of elements
22-
constexpr const E* begin() const noexcept { return _start; } ///< first element
23-
constexpr const E* end() const noexcept { return _end; } ///< one past the last element
24-
25-
private:
26-
E* _start = nullptr;
27-
E* _end = nullptr;
28-
}; // Initializer list range access
29-
template<class E> constexpr const E* begin(initializer_list<E> il) noexcept {
30-
return il.begin();
31-
}
32-
template<class E> constexpr const E* end(initializer_list<E> il) noexcept {
33-
return il.end();
34-
}
35-
}
36-
37-
#endif // _INITIALIZER_LIST_
5+
6+
namespace std
7+
{
8+
/// initializer_list
9+
template<class _E>
10+
class initializer_list
11+
{
12+
public:
13+
typedef _E value_type;
14+
typedef const _E& reference;
15+
typedef const _E& const_reference;
16+
typedef size_t size_type;
17+
typedef const _E* iterator;
18+
typedef const _E* const_iterator;
19+
20+
private:
21+
iterator _M_array;
22+
size_type _M_len;
23+
24+
// The compiler can call a private constructor.
25+
constexpr initializer_list(const_iterator __a, size_type __l)
26+
: _M_array(__a), _M_len(__l) { }
27+
28+
public:
29+
constexpr initializer_list() noexcept
30+
: _M_array(0), _M_len(0) { }
31+
32+
// Number of elements.
33+
constexpr size_type
34+
size() const noexcept { return _M_len; }
35+
36+
// First element.
37+
constexpr const_iterator
38+
begin() const noexcept { return _M_array; }
39+
40+
// One past the last element.
41+
constexpr const_iterator
42+
end() const noexcept { return begin() + size(); }
43+
};
44+
45+
/**
46+
* @brief Return an iterator pointing to the first element of
47+
* the initializer_list.
48+
* @param __ils Initializer list.
49+
*/
50+
template<class _Tp>
51+
constexpr const _Tp*
52+
begin(initializer_list<_Tp> __ils) noexcept
53+
{ return __ils.begin(); }
54+
55+
/**
56+
* @brief Return an iterator pointing to one past the last element
57+
* of the initializer_list.
58+
* @param __ils Initializer list.
59+
*/
60+
template<class _Tp>
61+
constexpr const _Tp*
62+
end(initializer_list<_Tp> __ils) noexcept
63+
{ return __ils.end(); }
64+
}

src/math/fixedPoint.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//----------------------------------------------------------------------------------
2+
// Fixed point arithmetic
3+
//----------------------------------------------------------------------------------
4+
#pragma once
5+
6+
#include <cstddef>
7+
8+
namespace etl::math {
9+
10+
template<size_t integerSize_, size_t fractionalSize_>
11+
struct UnsignedFixedPointNumber
12+
{
13+
UnsignedFixedPointNumber() = default;
14+
};
15+
16+
} // namespace etl::math

src/output/servo.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//----------------------------------------------------------------------------------------------------------------------
2+
// Analog servos
3+
//----------------------------------------------------------------------------------------------------------------------
4+
#pragma once
5+
#include <hal/gpio_pin.h>
6+
7+
namespace etl::output {
8+
9+
template<class Timer, class OutputPin_>
10+
struct PWMServo
11+
{
12+
void setPosition(Radianls) const;
13+
void setPosition(Degrees) const;
14+
};
15+
16+
} // namespace etl::output

0 commit comments

Comments
 (0)