Skip to content

variant: WB: add STM32WB5MM-DK #1441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
library: add RGB LED TLC59731
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed Jul 9, 2021
commit 2eeb79e52c29c6d58b6b23fd068dd9651473c31b
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
RGB_LED_TLC59731

This example code is in the public domain.

Blink one RGB LED with different default colors:
RGB_LED_TLC59731::OFF
RGB_LED_TLC59731::RED
RGB_LED_TLC59731::GREEN
RGB_LED_TLC59731::BLUE
RGB_LED_TLC59731::MAGENTA
RGB_LED_TLC59731::CYAN
RGB_LED_TLC59731::YELLOW
RGB_LED_TLC59731::WHITE
*/

#include <RGB_LED_TLC59731.h>

static uint8_t step = 0;
static uint8_t* sequence[] = { RGB_LED_TLC59731::RED,
RGB_LED_TLC59731::GREEN,
RGB_LED_TLC59731::BLUE,
RGB_LED_TLC59731::MAGENTA,
RGB_LED_TLC59731::CYAN,
RGB_LED_TLC59731::YELLOW,
RGB_LED_TLC59731::WHITE
};
/**
STM32WB5MM-DK have an RGB LED connected to TLC59731
It requires to enable it thanks LED_SELECT pin
and to have JP5 on and JP4 off
*/
#if defined(RGB_LED) && defined(LED_SELECT)
RGB_LED_TLC59731 LED(RGB_LED, LED_SELECT);
#else
RGB_LED_TLC59731 LED;
#endif

void setup() {
/* Change Brightness */
LED.setBrightness(0x10);
}

void loop() {
/* Blink */
LED.on(sequence[step]);
delay(500);
LED.off();
delay(500);
step = (step == 6) ? 0 : step + 1;
}
31 changes: 31 additions & 0 deletions libraries/RGB_LED_TLC59731/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#######################################
# Syntax Coloring Map For RGB_LED_TLC59731
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

RGB_LED_TLC59731 KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

on KEYWORD2
off KEYWORD2
getBrightness KEYWORD2
setBrightness KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

OFF LITERAL1
RED LITERAL1
GREEN LITERAL1
BLUE LITERAL1
MAGENTA LITERAL1
CYAN LITERAL1
YELLOW LITERAL1
WHITE LITERAL
9 changes: 9 additions & 0 deletions libraries/RGB_LED_TLC59731/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=RGB LED TLC59731
version=1.0.0
author=Frederic Pillon
maintainer=stm32duino
sentence=Allows to control one RGB LED driven by TLC59731 PWM LED Driver
paragraph=Control one RGB LED driven by TLC59731 PWM LED Driver
category=Signal Input/Output
url=https://github.com/stm32duino/Arduino_Core_STM32/tree/master/libraries/RGB_LED_TLC59731
architectures=stm32
142 changes: 142 additions & 0 deletions libraries/RGB_LED_TLC59731/src/RGB_LED_TLC59731.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
*******************************************************************************
* Copyright (c) 2021, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
#include "RGB_LED_TLC59731.h"

#define WRITE_COMMAND 0x3A
#ifndef DEFAULT_BRIGHTNESS
#define DEFAULT_BRIGHTNESS 0x41
#endif
uint8_t RGB_LED_TLC59731::brightness = DEFAULT_BRIGHTNESS;
uint8_t RGB_LED_TLC59731::OFF[3] = {0, 0, 0 };
uint8_t RGB_LED_TLC59731::RED[3] = {DEFAULT_BRIGHTNESS, 0, 0 };
uint8_t RGB_LED_TLC59731::GREEN[3] = {0, DEFAULT_BRIGHTNESS, 0 };
uint8_t RGB_LED_TLC59731::BLUE[3] = {0, 0, DEFAULT_BRIGHTNESS};
uint8_t RGB_LED_TLC59731::MAGENTA[3] = {DEFAULT_BRIGHTNESS, 0, DEFAULT_BRIGHTNESS};
uint8_t RGB_LED_TLC59731::CYAN[3] = {0, DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS};
uint8_t RGB_LED_TLC59731::YELLOW[3] = {DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS, 0 };
uint8_t RGB_LED_TLC59731::WHITE[3] = {DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS};

/**
* @brief Set RGB LED color
* @param rgb[3]: red,green, blue value in range [0-255]
* @retval None
*/
void RGB_LED_TLC59731::on(uint8_t rgb[3])
{
on(rgb[0], rgb[1], rgb[2]);
}

/**
* @brief Set RGB LED color
* @param red: red value in range [0-255]
* @param green: green value in range [0-255]
* @param blue: blue value in range [0-255]
* @retval None
*/
void RGB_LED_TLC59731::on(uint8_t red, uint8_t green, uint8_t blue)
{
if (!_enabled) {
if (_enable_pin != NC) {
pinMode(pinNametoDigitalPin(_enable_pin), OUTPUT);
digitalWriteFast(_enable_pin, HIGH);
}

pinMode(pinNametoDigitalPin(_rgb_pin), OUTPUT);
_enabled = true;
}
/* Data Transfer Rate (T_CYCLE) Measurement Sequence */
digitalWriteFast(_rgb_pin, HIGH);
delayMicroseconds(_T_Rise);
digitalWriteFast(_rgb_pin, LOW);
delayMicroseconds(_T_Cycle0);
/* Write command */
senByte(WRITE_COMMAND);
/* Write the GS data */
senByte(red);
senByte(green);
senByte(blue);
/* GS Latch */
delayMicroseconds(_T_GS_Lat);
}

/**
* @brief Set RGB LED Off
* @param None
* @retval None
*/
void RGB_LED_TLC59731::off(void)
{
/* Set RGB LED off value */
on(RGB_LED_TLC59731::OFF);
pinMode(pinNametoDigitalPin(_rgb_pin), INPUT_ANALOG);

if (_enable_pin != NC) {
digitalWriteFast(_enable_pin, LOW);
pinMode(pinNametoDigitalPin(_enable_pin), INPUT_ANALOG);
_enabled = false;
}
}

/**
* @brief Set brightness value
* @param value: new brightness value
* @retval None
*/
void RGB_LED_TLC59731::setBrightness(uint8_t value)
{
RGB_LED_TLC59731::brightness = value;
RGB_LED_TLC59731::RED[0] = value;
RGB_LED_TLC59731::GREEN[1] = value;
RGB_LED_TLC59731::BLUE[2] = value;
RGB_LED_TLC59731::MAGENTA[0] = value;
RGB_LED_TLC59731::MAGENTA[2] = value;
RGB_LED_TLC59731::CYAN[1] = value;
RGB_LED_TLC59731::CYAN[2] = value;
RGB_LED_TLC59731::YELLOW[0] = value;
RGB_LED_TLC59731::YELLOW[1] = value;
RGB_LED_TLC59731::WHITE[0] = value;
RGB_LED_TLC59731::WHITE[1] = value;
RGB_LED_TLC59731::WHITE[2] = value;
}

/* Private */
void RGB_LED_TLC59731::sendBit(uint8_t bit)
{
/* Start next cycle */
digitalWriteFast(_rgb_pin, HIGH);
delayMicroseconds(_T_Rise);
digitalWriteFast(_rgb_pin, LOW);
delayMicroseconds(_T_Rise);

if (bit) {
digitalWriteFast(_rgb_pin, HIGH);
delayMicroseconds(_T_Rise);
digitalWriteFast(_rgb_pin, LOW);
delayMicroseconds(_T_Cycle1);
} else {
delayMicroseconds(_T_Cycle0);
}
}


void RGB_LED_TLC59731::senByte(uint8_t byte)
{
sendBit(byte & (1 << 7));
sendBit(byte & (1 << 6));
sendBit(byte & (1 << 5));
sendBit(byte & (1 << 4));
sendBit(byte & (1 << 3));
sendBit(byte & (1 << 2));
sendBit(byte & (1 << 1));
sendBit(byte & (1 << 0));
}
57 changes: 57 additions & 0 deletions libraries/RGB_LED_TLC59731/src/RGB_LED_TLC59731.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*******************************************************************************
* Copyright (c) 2021, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
#ifndef __RGB_LED_TLC59731_H__
#define __RGB_LED_TLC59731_H__

#include "Arduino.h"

class RGB_LED_TLC59731 {

public:
RGB_LED_TLC59731(uint32_t rgb_pin = LED_BUILTIN, uint32_t enable_pin = NC):
_rgb_pin(digitalPinToPinName(rgb_pin)), _enable_pin(digitalPinToPinName(enable_pin)) {};
void on(uint8_t rgb[3]);
void on(uint8_t red, uint8_t green, uint8_t blue);
void off(void);
inline uint8_t getBrightness(void)
{
return brightness;
}
void setBrightness(uint8_t value);

static uint8_t brightness;
static uint8_t OFF[3];
static uint8_t RED[3];
static uint8_t GREEN[3];
static uint8_t BLUE[3];
static uint8_t MAGENTA[3];
static uint8_t CYAN[3];
static uint8_t YELLOW[3];
static uint8_t WHITE[3];

private:
PinName _rgb_pin;
PinName _enable_pin;

bool _enabled{false};
const uint32_t _T_Rise{1};
const uint32_t _T_Cycle0{4};
const uint32_t _T_Cycle1{1};
// GS Data Latch (GSLAT) Sequence delay
const uint32_t _T_GS_Lat{_T_Cycle0 * 8};

void sendBit(uint8_t bit);
void senByte(uint8_t byte);
};

#endif /* __RGB_LED_TLC59731_H__ */