Skip to content

Commit

Permalink
drivers/digit7seg: add asset in init
Browse files Browse the repository at this point in the history
  • Loading branch information
plmorange committed Nov 25, 2024
1 parent 37ceefb commit b42ef80
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 38 deletions.
21 changes: 2 additions & 19 deletions drivers/digit7seg/digit7seg.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @author Pierre Le Meur <[email protected]>
*/

#include <assert.h>
#include "digit7seg.h"

#define ENABLE_DEBUG 0
Expand Down Expand Up @@ -94,25 +95,8 @@ int digit7seg_init(digit7seg_t *dev, const digit7seg_params_t *params)
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++) {
if (!gpio_is_valid(pins[i])) {
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];
}

assert(gpio_init(pins[i], GPIO_OUT));
gpio_clear(pins[i]);
}

Expand Down Expand Up @@ -142,7 +126,6 @@ int digit7seg_set_value(digit7seg_t *dev, int index, uint8_t value)

int digit7seg_poweron(digit7seg_t *dev)
{

if (timer_init(dev->params.timer, DIGIT7SEG_TIMER_HZ, _shift_display, dev) != 0) {
DEBUG("[Error] Not possible to init timer.\n");
return -1;
Expand Down
7 changes: 1 addition & 6 deletions drivers/digit7seg/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ else {

...

if (digit7seg_poweroff(&dev) == 0) {
puts("...Stopped");
}
else {
puts("Error");
}
digit7seg_poweroff(&dev)

```
*/
14 changes: 1 addition & 13 deletions drivers/include/digit7seg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,7 @@ extern "C" {
* @brief Return codes for @ref digit7seg_init
*/
typedef enum {
DIGIT7SEG_OK = 0, /**< All ok */
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_OK = 0,
DIGIT7SEG_ERR_DIGITS, /**< Something went wrong with digits value */
} digit7seg_error_codes;

Expand Down

0 comments on commit b42ef80

Please sign in to comment.