Merge pull request #14831 from jeromecoutant/PR_DISCO_WB_LED

DISCO_WB5MMG: add RGB LED
pull/15189/head
Martin Kojtal 2021-07-26 13:21:09 +02:00 committed by GitHub
commit e2ec3cd720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 152 additions and 1 deletions

View File

@ -27,6 +27,13 @@
extern "C" {
#endif
void rgb_led_on(uint8_t RedValue, uint8_t GreenValue, uint8_t BlueValue);
void rgb_led_off(void);
void rgb_led_red(void);
void rgb_led_green(void);
void rgb_led_blue(void);
typedef enum {
ALT0 = 0x100,
} ALTx;
@ -185,10 +192,13 @@ typedef enum {
} PinName;
// Standardized LED and button names
#define LED1 PA_7 // LD4 is a RGB LED connected to a PWM LED driver // TODO
#define BUTTON1 PC_12
#define BUTTON2 PC_13
// RBG LED
#define RGB_LED PA_7 // LD4 is a RGB LED connected to a PWM LED driver
#define GPIO_SELECT2 PH_1 // See User Manual
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,141 @@
/* mbed Microcontroller Library
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************
*
* 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
*
******************************************************************************
*/
/* application example
#include "mbed.h"
int main()
{
while (true) {
rgb_led_off();
ThisThread::sleep_for(2s);
rgb_led_red();
ThisThread::sleep_for(2s);
rgb_led_green();
ThisThread::sleep_for(2s);
rgb_led_blue();
ThisThread::sleep_for(2s);
rgb_led_on(0x41, 0x41, 0); // yellow
ThisThread::sleep_for(2s);
rgb_led_on(0x41, 0, 0x41); // magenta
ThisThread::sleep_for(2s);
rgb_led_on(0, 0x41, 0x41); // cyan
ThisThread::sleep_for(2s);
rgb_led_on(0x41, 0x41, 0x41); // white
ThisThread::sleep_for(2s);
}
}
*/
#include "drivers/DigitalOut.h"
#include "platform/mbed_wait_api.h"
#define DELAY 1
#define T_CYCLE_0 4
#define T_CYCLE_1 1
#define WRITE_COMMAND 0x3A
#define rgb_led_wait(NbCycles) wait_us(NbCycles * 10)
void rgb_led_send_bit(uint8_t bit)
{
mbed::DigitalOut RGB_LED_SDI(RGB_LED);
/* Start next cycle */
RGB_LED_SDI = 1;
rgb_led_wait(DELAY);
RGB_LED_SDI = 0;
rgb_led_wait(DELAY);
if (bit) {
RGB_LED_SDI = 1;
rgb_led_wait(DELAY);
RGB_LED_SDI = 0;
rgb_led_wait(T_CYCLE_1);
} else {
rgb_led_wait(T_CYCLE_0);
}
}
void rgb_led_send_byte(uint8_t byte)
{
rgb_led_send_bit(byte & (1 << 7));
rgb_led_send_bit(byte & (1 << 6));
rgb_led_send_bit(byte & (1 << 5));
rgb_led_send_bit(byte & (1 << 4));
rgb_led_send_bit(byte & (1 << 3));
rgb_led_send_bit(byte & (1 << 2));
rgb_led_send_bit(byte & (1 << 1));
rgb_led_send_bit(byte & (1 << 0));
}
void rgb_led_on(uint8_t RedValue, uint8_t GreenValue, uint8_t BlueValue)
{
mbed::DigitalOut RGB_SELECT(GPIO_SELECT2);
mbed::DigitalOut RGB_LED_SDI(RGB_LED);
RGB_SELECT = 1;
/* TCycle measurement sequence */
RGB_LED_SDI = 1;
rgb_led_wait(DELAY);
RGB_LED_SDI = 0;
rgb_led_wait(T_CYCLE_0);
/* Write command */
rgb_led_send_byte(WRITE_COMMAND);
/* Write the GS data */
rgb_led_send_byte(RedValue);
rgb_led_send_byte(GreenValue);
rgb_led_send_byte(BlueValue);
rgb_led_wait(T_CYCLE_0 * 2);
RGB_SELECT = 0;
}
void rgb_led_off(void)
{
rgb_led_on(0, 0, 0);
}
void rgb_led_red(void)
{
rgb_led_on(0x41, 0, 0);
}
void rgb_led_green(void)
{
rgb_led_on(0, 0x41, 0);
}
void rgb_led_blue(void)
{
rgb_led_on(0, 0, 0x41);
}