Skip to content

Commit

Permalink
[examples] Add APA102 and SK6812 driver examples
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Aug 6, 2019
1 parent f579bcc commit 9fffd5d
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 4 deletions.
52 changes: 52 additions & 0 deletions examples/nucleo_f031k6/sk6812/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
* Copyright (c) 2017, Nick Sarten
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <modm/driver/pwm/sk6812w.hpp>
#include <modm/ui/led/tables.hpp>
#include <modm/processing/timer.hpp>

using namespace Board;

using Output = Board::D11;
modm::Sk6812w<SpiMaster1, Output, 8*8> leds;
modm::ShortPeriodicTimer tmr{33};

int
main()
{
Board::initialize();
LedD13::setOutput();
leds.initialize<Board::SystemClock>();

constexpr uint8_t max = 62;
uint8_t r=0, g=max/3, b=max/3*2;

while (true)
{
for (size_t ii=0; ii < leds.size; ii++)
{
leds.setColor(ii,
{modm::ui::table22_8_256[r*3/2],
modm::ui::table22_8_256[g*3/2],
modm::ui::table22_8_256[b*3/2]});
if (r++ >= max) r = 0;
if (g++ >= max) g = 0;
if (b++ >= max) b = 0;
}
leds.write();

while(not tmr.execute()) ;
LedD13::toggle();
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/nucleo_f031k6/sk6812/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:nucleo-f031k6</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f031k6/sk6812</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:sk6812</module>
<module>modm:platform:spi:1</module>
<module>modm:ui:led</module>
</modules>
</library>
8 changes: 4 additions & 4 deletions examples/nucleo_f411re/ws2812b/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<option name=":build:build.path">../../../build/nucleo_f411re/ws2812b</option>
</options>
<modules>
<module>:driver:ws2812</module>
<module>:platform:spi:1</module>
<module>:ui:led</module>
<module>:build:scons</module>
<module>modm:driver:ws2812</module>
<module>modm:platform:spi:1</module>
<module>modm:ui:led</module>
<module>modm:build:scons</module>
</modules>
</library>
50 changes: 50 additions & 0 deletions examples/nucleo_g071rb/apa102/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
* Copyright (c) 2017, Nick Sarten
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <modm/driver/pwm/apa102.hpp>
#include <modm/ui/led/tables.hpp>
#include <modm/processing/timer.hpp>

using namespace Board;

modm::Apa102<SpiMaster1, 8*8> leds;
modm::ShortPeriodicTimer tmr{33};

int
main()
{
Board::initialize();
SpiMaster1::connect<Board::D13::Sck, Board::D11::Mosi>();
SpiMaster1::initialize<Board::SystemClock, 8_MHz>();

constexpr uint8_t max = 62;
uint8_t r=0, g=max/3, b=max/3*2;

while (true)
{
for (size_t ii=0; ii < leds.size; ii++)
{
leds.setColor(ii, {r, g, b});
// {modm::ui::table22_8_256[r],
// modm::ui::table22_8_256[g],
// modm::ui::table22_8_256[b]});
if (r++ >= max) r = 0;
if (g++ >= max) g = 0;
if (b++ >= max) b = 0;
}
RF_CALL_BLOCKING(leds.write());

while(not tmr.execute()) ;
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/nucleo_g071rb/apa102/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/apa102</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:apa102</module>
<module>modm:platform:spi:1</module>
<module>modm:ui:led</module>
</modules>
</library>

0 comments on commit 9fffd5d

Please sign in to comment.