-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add example for LP503x led driver for Nucleo F042
- Loading branch information
1 parent
30c95fd
commit 6e5ebf4
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2020, Christopher Durand | ||
* | ||
* 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/lp503x.hpp> | ||
|
||
using namespace Board; | ||
|
||
/* | ||
* Example to demonstrate LP503x driver | ||
* It assumes an LP5036 is connected to the following pins: | ||
* A10 SDA | ||
* A11 SCL | ||
* A7 Enable | ||
*/ | ||
|
||
using I2cSda = GpioA10; | ||
using I2cScl = GpioA11; | ||
using LedEnable = GpioA7; | ||
|
||
constexpr uint8_t i2cAddress = 0b011'0000; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
LedEnable::setOutput(); | ||
|
||
MODM_LOG_INFO << "LP5036 demo" << modm::endl; | ||
|
||
I2cMaster1::connect<I2cSda::Sda, I2cScl::Scl>(); | ||
I2cMaster1::initialize<SystemClock, 400_kBd>(); | ||
|
||
modm::Lp5036<I2cMaster1> leds{i2cAddress}; | ||
LedEnable::set(); | ||
|
||
// Initialize and enable chip | ||
RF_CALL_BLOCKING(leds.initialize()); | ||
RF_CALL_BLOCKING(leds.enable()); | ||
|
||
// Turn on all leds with increasing brightness | ||
for(uint8_t channel = 0; channel < 36; ++channel) { | ||
const uint8_t brightness = (channel + 1) * 7; | ||
RF_CALL_BLOCKING(leds.setChannelBrightness(channel, brightness)); | ||
} | ||
|
||
modm::delayMilliseconds(1000); | ||
|
||
// Configure outputs 0-5 (rgb led 0-1) in bank mode | ||
using LedBankMode = modm::lp503x::LedBankMode; | ||
const auto bankLeds = LedBankMode::Led0 | LedBankMode::Led1; | ||
RF_CALL_BLOCKING(leds.setBankModeEnabled(bankLeds)); | ||
|
||
// Set bank leds to full brightness | ||
RF_CALL_BLOCKING(leds.setBankABrightness(255)); | ||
RF_CALL_BLOCKING(leds.setBankBBrightness(255)); | ||
RF_CALL_BLOCKING(leds.setBankCBrightness(255)); | ||
|
||
// Blink leds in bank mode | ||
while(true) { | ||
RF_CALL_BLOCKING(leds.setBankBrightness(255)); | ||
modm::delayMilliseconds(500); | ||
RF_CALL_BLOCKING(leds.setBankBrightness(0)); | ||
modm::delayMilliseconds(500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<library> | ||
<extends>modm:nucleo-f042k6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_f042k6/lp503x</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:driver:lp503x</module> | ||
<module>modm:platform:i2c:1</module> | ||
</modules> | ||
</library> |