Skip to content

Commit

Permalink
drivers/digit7seg: Add assert on gpio
Browse files Browse the repository at this point in the history
  • Loading branch information
plmorange committed Dec 2, 2024
1 parent b42ef80 commit d548653
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
14 changes: 9 additions & 5 deletions drivers/digit7seg/digit7seg.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ static void _set_pin_value(digit7seg_t *dev)
for (int i = 0; i < BYTE_BITS; i++) {
if (current_value & (1 << i)) {
gpio_set(pins[i]);
DEBUG("PIN SET\n");
}
else {
gpio_clear(pins[i]);
DEBUG("PIN CLEAR\n");
}
}
}
Expand All @@ -73,8 +71,6 @@ static void _shift_display(void *arg, int chan)
dev->current_digit = dev->current_digit % dev->params.digits;
gpio_set(digit_pins[dev->current_digit]);

DEBUG("[INFO] On display %d\n", dev->current_digit);

_set_pin_value(dev);
}

Expand All @@ -95,9 +91,17 @@ int digit7seg_init(digit7seg_t *dev, const digit7seg_params_t *params)
PIN_DIG1, PIN_DIG2, PIN_DIG3, PIN_DIG4
};

const char* pins_debug[] =
{
"A", "B", "C", "D", "E", "F", "G", "DP",
"DIG1", "DIG2", "DIG3", "DIG4"
};

for (int i = 0; i < NB_PIN; i++) {
assert(gpio_init(pins[i], GPIO_OUT));
DEBUG("[DIGIT7SEG] Trying the pin %s:...", pins_debug[i]);
assert(gpio_init(pins[i], GPIO_OUT) == 0);
gpio_clear(pins[i]);
DEBUG("Worked\n");
}

return DIGIT7SEG_OK;
Expand Down
2 changes: 1 addition & 1 deletion drivers/include/digit7seg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern "C" {
* @brief Return codes for @ref digit7seg_init
*/
typedef enum {
DIGIT7SEG_OK = 0,
DIGIT7SEG_OK = 0, /**< All ok */
DIGIT7SEG_ERR_DIGITS, /**< Something went wrong with digits value */
} digit7seg_error_codes;

Expand Down
11 changes: 0 additions & 11 deletions tests/drivers/digit7seg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,5 @@ int main(void)

digit7seg_poweroff(&dev);

ztimer_sleep(ZTIMER_USEC, TEST_DELAY_US * 3);

if (digit7seg_poweron(&dev) == 0) {
puts("Launched.");
}
else {
puts("Error");
}

while (1) {}

return 0;
}

0 comments on commit d548653

Please sign in to comment.