Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6942 from smlng/driver/my9221
Add driver for MY9221 LED controller and (based on that) the Seeed Studio Grove LED bar
- Loading branch information
Showing
21 changed files
with
965 additions
and
2 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
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
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 @@ | ||
include $(RIOTBASE)/Makefile.base |
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,68 @@ | ||
/* | ||
* Copyright (C) 2017 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_grove_ledbar | ||
* | ||
* @{ | ||
* @file | ||
* @brief Driver for the Grove ledbar | ||
* | ||
* @author Sebastian Meiling <s@mlng.net> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include "log.h" | ||
#include "xtimer.h" | ||
|
||
#include "grove_ledbar.h" | ||
#include "my9221.h" | ||
|
||
#define DEV_LEDS (dev->params.leds) | ||
#define DEV_STATE(x) (dev->state[x]) | ||
|
||
int grove_ledbar_init(grove_ledbar_t *dev, const grove_ledbar_params_t *params) | ||
{ | ||
assert(dev && params); | ||
|
||
return my9221_init((my9221_t *)dev, (my9221_params_t *)params); | ||
} | ||
|
||
void grove_ledbar_set(grove_ledbar_t *dev, uint8_t level) | ||
{ | ||
assert(dev); | ||
|
||
uint8_t frac = GROVE_LEDBAR_MAX / DEV_LEDS; | ||
|
||
for (unsigned i = 0; i < DEV_LEDS; ++i) { | ||
if (level > frac) { | ||
DEV_STATE(i) = MY9221_LED_ON; | ||
level -= frac; | ||
} | ||
else if (level > 0) { | ||
DEV_STATE(i) = ~(MY9221_LED_ON << ((level << 3) / frac)); | ||
level = 0; | ||
} | ||
else { | ||
DEV_STATE(i) = MY9221_LED_OFF; | ||
} | ||
} | ||
my9221_set_state((my9221_t *)dev, NULL, 0); | ||
} | ||
|
||
void grove_ledbar_clear(grove_ledbar_t *dev) | ||
{ | ||
assert(dev); | ||
|
||
grove_ledbar_set(dev, 0); | ||
} |
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,38 @@ | ||
/* | ||
* Copyright (C) 2017 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_grove_ledbar | ||
* @{ | ||
* | ||
* @file | ||
* @brief Grove LED bar adaption to SAUL | ||
* | ||
* @author Sebastian Meiling <s@mlng.net> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "saul.h" | ||
#include "grove_ledbar.h" | ||
|
||
static int set_ledbar(const void *dev, phydat_t *res) | ||
{ | ||
uint8_t lvl = (uint8_t)res->val[0]; | ||
grove_ledbar_set((grove_ledbar_t *)dev, lvl); | ||
return 1; | ||
} | ||
|
||
const saul_driver_t grove_ledbar_saul_driver = { | ||
.read = saul_notsup, | ||
.write = set_ledbar, | ||
.type = SAUL_ACT_LED_RGB, | ||
}; |
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,91 @@ | ||
/* | ||
* Copyright (C) 2017 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_grove_ledbar | ||
* | ||
* @{ | ||
* @file | ||
* @brief Config for the Grove LED bar based on MY9221 LED controller | ||
* | ||
* @author Sebastian Meiling <s@mlng.net> | ||
*/ | ||
#ifndef GROVE_LEDBAR_PARAMS_H | ||
#define GROVE_LEDBAR_PARAMS_H | ||
|
||
#include "board.h" | ||
#include "periph/gpio.h" | ||
#include "saul_reg.h" | ||
|
||
#include "grove_ledbar.h" | ||
#include "my9221.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
/** | ||
* @brief Clock GPIO pin | ||
*/ | ||
#ifndef GROVE_LEDBAR_CLK | ||
#define GROVE_LEDBAR_CLK (GPIO_PIN(0,1)) | ||
#endif | ||
|
||
/** | ||
* @brief Data GPIO pin | ||
*/ | ||
#ifndef GROVE_LEDBAR_DAT | ||
#define GROVE_LEDBAR_DAT (GPIO_PIN(0,2)) | ||
#endif | ||
|
||
/** | ||
* @brief Direction of LEDs | ||
*/ | ||
#ifndef GROVE_LEDBAR_DIR | ||
#define GROVE_LEDBAR_DIR GROVE_LEDBAR_G2R | ||
#endif | ||
|
||
/** | ||
* @brief Default parameter settings | ||
*/ | ||
#define GROVE_LEDBAR_PARAMS { \ | ||
.leds = 10, \ | ||
.dir = GROVE_LEDBAR_DIR, \ | ||
.clk = GROVE_LEDBAR_CLK, \ | ||
.dat = GROVE_LEDBAR_DAT, \ | ||
} | ||
|
||
/** | ||
* @brief Grove LED bar configuration | ||
*/ | ||
static const grove_ledbar_params_t grove_ledbar_params[] = | ||
{ | ||
#ifdef GROVE_LEDBAR_CUSTOM | ||
GROVE_LEDBAR_CUSTOM, | ||
#else | ||
GROVE_LEDBAR_PARAMS, | ||
#endif | ||
}; | ||
|
||
/** | ||
* @brief Additional meta information to keep in the SAUL registry | ||
*/ | ||
static const saul_reg_info_t grove_ledbar_saul_info[] = | ||
{ | ||
{ | ||
.name = "Grove LED bar" | ||
} | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* GROVE_LEDBAR_PARAMS_H */ | ||
/** @} */ |
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,91 @@ | ||
/* | ||
* Copyright (C) 2017 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @defgroup drivers_grove_ledbar Grove ledbar | ||
* @ingroup drivers_actuators | ||
* @brief Driver for the Grove ledbar | ||
* | ||
* @{ | ||
* @file | ||
* @brief Interface for the Grove ledbar driver | ||
* | ||
* @author Sebastian Meiling <s@mlng.net> | ||
*/ | ||
|
||
#ifndef GROVE_LEDBAR_H | ||
#define GROVE_LEDBAR_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "my9221.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @name Ledbar direction, either red to green, or vice versa. | ||
* @{ | ||
*/ | ||
#define GROVE_LEDBAR_R2G MY9221_DIR_FWD | ||
#define GROVE_LEDBAR_G2R MY9221_DIR_REV | ||
/** @} */ | ||
|
||
/** | ||
* @brief Maximum value for ledbar level | ||
*/ | ||
#define GROVE_LEDBAR_MAX UINT8_MAX | ||
|
||
/** | ||
* @brief Parameters needed for device initialization | ||
*/ | ||
typedef my9221_params_t grove_ledbar_params_t; | ||
|
||
/** | ||
* @brief Device descriptor for grove ledbar, alias for MY9221 LED controller | ||
*/ | ||
typedef my9221_t grove_ledbar_t; | ||
|
||
/** | ||
* @brief Initialize the given driver | ||
* | ||
* @pre `dev != NULL` and `params != NULL` | ||
* | ||
* @param[out] dev device descriptor grove ledbar | ||
* @param[in] params configuration parameters | ||
* | ||
* @return 0 on success, otherwise error | ||
*/ | ||
int grove_ledbar_init(grove_ledbar_t *dev, const grove_ledbar_params_t *params); | ||
|
||
/** | ||
* @brief Set overall (brightness) level distributed over all LEDs | ||
* | ||
* @pre `dev != NULL` | ||
* | ||
* @param[in] dev device descriptor grove ledbar | ||
* @param[in] level overall brightness level | ||
*/ | ||
void grove_ledbar_set(grove_ledbar_t *dev, uint8_t level); | ||
|
||
/** | ||
* @brief Clear ledbar, i.e. set all LEDs off | ||
* | ||
* @pre `dev != NULL` | ||
* | ||
* @param[in] dev device descriptor grove ledbar | ||
*/ | ||
void grove_ledbar_clear(grove_ledbar_t *dev); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* GROVE_LEDBAR_H */ | ||
/** @} */ |
Oops, something went wrong.