Skip to content

Commit 6897160

Browse files
committed
concept
1 parent baf3c83 commit 6897160

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

src/modm/architecture/interface/spi.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919

2020
namespace modm
2121
{
22+
namespace spi
23+
{
24+
25+
template<class Spi>
26+
concept Support_DataSize_Bit16 = requires
27+
{ Spi::DataSize::Bit16; };
28+
29+
template<class Spi>
30+
concept Support_DataSize_Bit32 = requires
31+
{ Spi::DataSize::Bit32; };
32+
33+
} // namespace spi
2234

2335
/// @ingroup modm_architecture_spi
2436
struct Spi
@@ -43,6 +55,7 @@ struct Spi
4355
MsbFirst = 0b0,
4456
LsbFirst = 0b1,
4557
};
58+
4659
};
4760

4861
} // namespace modm

src/modm/driver/display/ili9341_spi.hpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313

1414
#include <modm/architecture/interface/spi_device.hpp>
1515

16-
// TODO Prototype
17-
template<class Spi>
18-
concept SupportsBit16 = requires() {
19-
Spi::setDataSize(Spi::DataSize::Bit16);
20-
};
21-
2216
namespace modm
2317
{
2418

@@ -41,7 +35,7 @@ class Ili9341SPIInterface: public ili9341, public modm::SpiDevice<SPI>
4135
__attribute__((noinline)) void
4236
writeCommand(Command command)
4337
{
44-
if constexpr ( SupportsBit16<SPI> )
38+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
4539
SPI::setDataSize(SPI::DataSize::Bit8);
4640
Dc::reset(); // enable command
4741
SPI::transferBlocking(i(command));
@@ -50,7 +44,7 @@ class Ili9341SPIInterface: public ili9341, public modm::SpiDevice<SPI>
5044
__attribute__((noinline)) void
5145
writeCommand(Command command, uint8_t const *args, std::size_t length)
5246
{
53-
if constexpr ( SupportsBit16<SPI> )
47+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
5448
SPI::setDataSize(SPI::DataSize::Bit8);
5549
Dc::reset(); // enable command
5650
SPI::transferBlocking(i(command));
@@ -63,39 +57,39 @@ class Ili9341SPIInterface: public ili9341, public modm::SpiDevice<SPI>
6357
void
6458
writeData(uint8_t const *data, std::size_t length)
6559
{
66-
if constexpr ( SupportsBit16<SPI> )
60+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
6761
SPI::setDataSize(SPI::DataSize::Bit8);
6862
SPI::transferBlocking(data, nullptr, length);
6963
}
7064

7165
void
7266
writeData(color::Rgb565 rgb565)
7367
{
74-
if constexpr ( SupportsBit16<SPI> )
68+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
7569
SPI::setDataSize(SPI::DataSize::Bit16);
7670
SPI::transferBlocking(rgb565.color);
7771
}
7872

7973
void
8074
writeDataRepeat(color::Rgb565 rgb565, std::size_t repeat)
8175
{
82-
if constexpr ( SupportsBit16<SPI> )
76+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
8377
SPI::setDataSize(SPI::DataSize::Bit16);
8478
SPI::transferBlocking16(rgb565.color, repeat);
8579
}
8680

8781
void
8882
writeData(color::Rgb565 const *data, std::size_t length)
8983
{
90-
if constexpr ( SupportsBit16<SPI> )
84+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
9185
SPI::setDataSize(SPI::DataSize::Bit16);
9286
SPI::transferBlocking16(reinterpret_cast<const uint16_t*>(data), nullptr, length);
9387
}
9488

9589
void
9690
writeCommandValue8(Command command, uint8_t value)
9791
{
98-
if constexpr ( SupportsBit16<SPI> )
92+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
9993
SPI::setDataSize(SPI::DataSize::Bit8);
10094
writeCommand(command, &value, 1);
10195
}
@@ -105,7 +99,7 @@ class Ili9341SPIInterface: public ili9341, public modm::SpiDevice<SPI>
10599
{
106100
uint8_t b[4];
107101

108-
if constexpr ( SupportsBit16<SPI> )
102+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
109103
SPI::setDataSize(SPI::DataSize::Bit8);
110104
Dc::reset();
111105
SPI::transferBlocking(i(command) << 1);
@@ -115,7 +109,7 @@ class Ili9341SPIInterface: public ili9341, public modm::SpiDevice<SPI>
115109
uint8_t
116110
readData(Command command)
117111
{
118-
if constexpr ( SupportsBit16<SPI> )
112+
if constexpr ( spi::Support_DataSize_Bit16<SPI> )
119113
SPI::setDataSize(SPI::DataSize::Bit8);
120114
writeCommand(command);
121115
return SPI::transferBlocking(0);

src/modm/platform/spi/at90_tiny_mega/spi.hpp.in

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
1010
*/
1111
// ----------------------------------------------------------------------------
12-
13-
#ifndef MODM_AVR_SPI_HPP
14-
#define MODM_AVR_SPI_HPP
12+
#pragma once
1513

1614
#include <avr/io.h>
1715

@@ -51,10 +49,7 @@
5149
%% endif
5250
/// @endcond
5351

54-
namespace modm
55-
{
56-
57-
namespace platform
52+
namespace modm::platform
5853
{
5954

6055
/// @ingroup modm_platform_spi
@@ -87,8 +82,4 @@ struct Spi
8782
typedef Value<State_t, 2> Type_t;
8883
};
8984

90-
} // namespace platform
91-
92-
} // namespace modm
93-
94-
#endif // MODM_AVR_SPI_HPP
85+
} // namespace modm::platform

0 commit comments

Comments
 (0)