1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/digit7seg: add asset in init

This commit is contained in:
Pierre Le Meur 2024-11-25 11:13:41 +01:00
parent 37ceefb9d1
commit b42ef802b1
3 changed files with 4 additions and 38 deletions

View File

@ -13,6 +13,7 @@
* @author Pierre Le Meur <pierre1.lemeur@orange.com> * @author Pierre Le Meur <pierre1.lemeur@orange.com>
*/ */
#include <assert.h>
#include "digit7seg.h" #include "digit7seg.h"
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
@ -94,25 +95,8 @@ int digit7seg_init(digit7seg_t *dev, const digit7seg_params_t *params)
PIN_DIG1, PIN_DIG2, PIN_DIG3, PIN_DIG4 PIN_DIG1, PIN_DIG2, PIN_DIG3, PIN_DIG4
}; };
const int pin_errs[] =
{
DIGIT7SEG_ERR_A_GPIO, DIGIT7SEG_ERR_B_GPIO, DIGIT7SEG_ERR_C_GPIO, DIGIT7SEG_ERR_D_GPIO,
DIGIT7SEG_ERR_E_GPIO, DIGIT7SEG_ERR_F_GPIO, DIGIT7SEG_ERR_G_GPIO, DIGIT7SEG_ERR_DP_GPIO,
DIGIT7SEG_ERR_DIG1_GPIO, DIGIT7SEG_ERR_DIG2_GPIO, DIGIT7SEG_ERR_DIG3_GPIO,
DIGIT7SEG_ERR_DIG4_GPIO
};
for (int i = 0; i < NB_PIN; i++) { for (int i = 0; i < NB_PIN; i++) {
if (!gpio_is_valid(pins[i])) { assert(gpio_init(pins[i], GPIO_OUT));
DEBUG("[Error] GPIO isn't valid.\n");
return -pin_errs[i];
}
if (gpio_init(pins[i], GPIO_OUT) < 0) {
DEBUG("[Error] Initializing gpio error.\n");
return -pin_errs[i];
}
gpio_clear(pins[i]); gpio_clear(pins[i]);
} }
@ -142,7 +126,6 @@ int digit7seg_set_value(digit7seg_t *dev, int index, uint8_t value)
int digit7seg_poweron(digit7seg_t *dev) int digit7seg_poweron(digit7seg_t *dev)
{ {
if (timer_init(dev->params.timer, DIGIT7SEG_TIMER_HZ, _shift_display, dev) != 0) { if (timer_init(dev->params.timer, DIGIT7SEG_TIMER_HZ, _shift_display, dev) != 0) {
DEBUG("[Error] Not possible to init timer.\n"); DEBUG("[Error] Not possible to init timer.\n");
return -1; return -1;

View File

@ -174,12 +174,7 @@ else {
... ...
if (digit7seg_poweroff(&dev) == 0) { digit7seg_poweroff(&dev)
puts("...Stopped");
}
else {
puts("Error");
}
``` ```
*/ */

View File

@ -44,19 +44,7 @@ extern "C" {
* @brief Return codes for @ref digit7seg_init * @brief Return codes for @ref digit7seg_init
*/ */
typedef enum { typedef enum {
DIGIT7SEG_OK = 0, /**< All ok */ DIGIT7SEG_OK = 0,
DIGIT7SEG_ERR_A_GPIO, /**< Something went wrong with A GPIO */
DIGIT7SEG_ERR_B_GPIO, /**< Something went wrong with B GPIO */
DIGIT7SEG_ERR_C_GPIO, /**< Something went wrong with C GPIO */
DIGIT7SEG_ERR_D_GPIO, /**< Something went wrong with D GPIO */
DIGIT7SEG_ERR_E_GPIO, /**< Something went wrong with E GPIO */
DIGIT7SEG_ERR_F_GPIO, /**< Something went wrong with F GPIO */
DIGIT7SEG_ERR_G_GPIO, /**< Something went wrong with G GPIO */
DIGIT7SEG_ERR_DP_GPIO, /**< Something went wrong with DP GPIO */
DIGIT7SEG_ERR_DIG1_GPIO, /**< Something went wrong with DIG1 GPIO */
DIGIT7SEG_ERR_DIG2_GPIO, /**< Something went wrong with DIG2 GPIO */
DIGIT7SEG_ERR_DIG3_GPIO, /**< Something went wrong with DIG3 GPIO */
DIGIT7SEG_ERR_DIG4_GPIO, /**< Something went wrong with DIG4 GPIO */
DIGIT7SEG_ERR_DIGITS, /**< Something went wrong with digits value */ DIGIT7SEG_ERR_DIGITS, /**< Something went wrong with digits value */
} digit7seg_error_codes; } digit7seg_error_codes;