#include <stdint.h>
#include "pin.h"

#ifndef DISPLAY_H
#define DISPLAY_H

typedef struct {
  // Display board configuration
  uint16_t digits_count;
  pin_t pin_data;
  pin_t pin_sftclk;
  pin_t pin_strobe;

  // Current application data
  char digits[4];
  uint8_t digit_dots;

  // Current application state
  uint8_t digits_en;

  // Current internal state of the display
  uint16_t current_cycle;
  uint32_t current_shifter;
  uint8_t current_digit;
  uint16_t max_value;
} display_t;

typedef enum {
  DISPLAY_UPDATE_NEW_DIGIT,
  DISPLAY_UPDATE_DISPLAY_DIGIT,
  DISPLAY_UPDATE_SHIFT,
} display_update_state_t;

void display_init(display_t* display, uint16_t digits, pin_t pin_data, pin_t pin_sftclk, pin_t pin_strobe);

void display_convert_number(display_t* display, uint32_t number);
void display_digits_set(display_t *display, char* digits);
void display_digit_set(display_t* display, uint8_t digit, uint8_t number);

void display_dots(display_t* display, uint8_t dots);
void display_enable_digit(display_t* display, uint8_t digit, uint8_t enable);

display_update_state_t display_update(display_t* display);

#endif // DISPLAY_H
