36 #define MAX_COUNT_PWM           1000    37 #define MAX_SEQ_LEN_SEC         20    38 #define PWM_UPDATE_PERIOD_MS    32    39 #define PWM_BUFFER_SIZE         ((uint32_t)((MAX_SEQ_LEN_SEC*1000)/PWM_UPDATE_PERIOD_MS))    49   uint16_t color[LED_COLOR_MAX];
    50 } seq_buffer[PWM_BUFFER_SIZE];
    52 const uint16_t zero_val_arr[32] = { 0 };
    59         if(led_ui_context[LED_UI_LOOP_SEQ].is_on == 
true)
    62                     led_ui_context[LED_UI_LOOP_SEQ].priority);
    67 static bool check_single_seq(led_sequences seq, 
led_ui_priority_t priority, 
bool reset)
    84      if((led_ui_context[LED_UI_LOOP_SEQ].priority > priority)
    85                       && (led_ui_context[LED_UI_LOOP_SEQ].is_on == 
true))
   101         if((led_ui_context[LED_UI_LOOP_SEQ].is_on == 
false) ||
   102            ((led_ui_context[LED_UI_LOOP_SEQ].priority < priority) &&
   103                    (led_ui_context[LED_UI_LOOP_SEQ].is_on == 
true)))
   105             led_ui_context[LED_UI_LOOP_SEQ].is_on = 
true;
   106             led_ui_context[LED_UI_LOOP_SEQ].seq = seq;
   107             led_ui_context[LED_UI_LOOP_SEQ].priority = priority;
   113     if((led_ui_context[LED_UI_LOOP_SEQ].priority > priority)
   114                       && (led_ui_context[LED_UI_LOOP_SEQ].is_on == 
true))
   130     led_ui_context[type].is_on = 
true;
   131     led_ui_context[type].seq = seq;
   132     led_ui_context[type].priority = priority;
   134     uint16_t * dur_ptr = led_seq_get_seq_duration_ptr(seq);
   135     uint32_t seq_seg_num = led_seq_get_seg_len(seq);
   137     uint32_t led_num = led_seq_get_pin_num(seq);
   139     uint16_t * seq_ptr[LED_COLOR_MAX];
   140     uint32_t pin_arr[LED_COLOR_MAX];
   141     bool pin_idle[LED_COLOR_MAX];
   143     for(uint32_t k = 0; k < led_num; k++)
   145         seq_ptr[k] = led_seq_get_seq_color_ptr(seq, k);
   146         pin_arr[k] = led_seq_get_pin_ptr()[k];
   149     for(uint32_t k = led_num; k < LED_COLOR_MAX; k++)
   151         seq_ptr[k] = (uint16_t *)zero_val_arr;
   152         pin_arr[k] = led_seq_get_pin_ptr()[0];
   156     uint32_t overflow = 0; 
   157     uint32_t buff_cnt = 0; 
   159     for(uint32_t i = 1; i<seq_seg_num; i++)
   161         uint32_t curr_seg_dur = dur_ptr[i] - overflow;
   162         uint32_t seg_updates_num = 1 + curr_seg_dur/PWM_UPDATE_PERIOD_MS;
   164         for(uint32_t j = 0; j < seg_updates_num; j++)
   166             uint32_t seg_count = overflow + j*PWM_UPDATE_PERIOD_MS;
   167             for(uint32_t k = 0; k < LED_COLOR_MAX; k++)
   169                 seq_buffer[buff_cnt].color[k] = ((int32_t)(seg_count *
   170                     ((int32_t)(seq_ptr[k][i] - seq_ptr[k][i-1]))))
   171                     /dur_ptr[i] + seq_ptr[k][i-1];
   174                         (seq_buffer[buff_cnt].color[k] | (1<<15)):
   175                         (seq_buffer[buff_cnt].color[k]);
   180         uint32_t curr_dur_mod = curr_seg_dur - (seg_updates_num-1)*PWM_UPDATE_PERIOD_MS;
   181         overflow = (curr_dur_mod)?(PWM_UPDATE_PERIOD_MS - curr_dur_mod):0;
   188         .pin_idle_state = pin_idle,
   189         .pin_num = LED_COLOR_MAX,
   192         .irq_priority = APP_IRQ_PRIORITY_MID
   204                 .seq_values = (uint16_t *) seq_buffer,
   205                 .len = (LED_COLOR_MAX * buff_cnt),
   206                 .repeats = (PWM_UPDATE_PERIOD_MS - 1),
   210                 .seq_values = (uint16_t *) seq_buffer,
   211                 .len = (LED_COLOR_MAX * buff_cnt),
   212                 .repeats = (PWM_UPDATE_PERIOD_MS - 1),
   220         start_config.
loop = 0;
   227         start_config.
loop = 1;
   239     if(check_single_seq(seq, priority, reset))
   249     if(check_loop_seq(seq, priority))
   254     start_seq_pwm(seq, LED_UI_LOOP_SEQ, priority);
   265     led_ui_context[type].is_on = 
false;
   268     if(led_ui_context[LED_UI_LOOP_SEQ].is_on == 
true)
   271                 led_ui_context[LED_UI_LOOP_SEQ].priority);
   277     if(led_ui_context[type].is_on == 
true)
   285     if((led_ui_context[type].is_on == 
true) &&
   286             (led_ui_context[type].seq == seq))
   294     if((led_ui_context[type].is_on == 
true) &&
   295             (led_ui_context[type].priority == priority))
   305     led_ui_context[LED_UI_LOOP_SEQ].is_on = 
false;
   310     return led_ui_context[type].seq;
 uint32_t shorts_mask
Select the shortcuts that need to be enabled. OR the values in hal_pwm_short_mask_t to enable them.
 
Short between LOOPSDONE event and SEQSTART[0] task.
 
hal_pwm_irq_mask_t
PWM interrupts.
 
uint32_t * pins
Pointer to array containing the pins number used by hal pwm.
 
Run a sequence only once.
 
uint32_t interrupt_masks
Select the interrupts that need to be enabled OR the values in hal_pwm_irq_mask_t to enable them.
 
After the loaded value is repeated for the number of times in REFRESH register.
 
uint32_t countertop
Maximum count of the counter. This and oper_freq decide the frequency of the resulting PWM waveform.
 
void led_ui_loop_start(led_sequences seq, led_ui_priority_t priority)
Start a sequence to play repeatedly.
 
#define LEDS_ACTIVE_STATE
 
void led_ui_single_start(led_sequences seq, led_ui_priority_t priority, bool reset)
Start a sequence to play once.
 
led_sequences led_ui_get_current_seq(led_ui_seq_t type)
Get the currently active LED UI sequence.
 
void hal_pwm_start(hal_pwm_start_t *start_config)
Start the PWM generation based on the configuration provided.
 
Up counter, reset to 0 on incrementing to CounterTop.
 
void led_ui_stop_everything(void)
Stops all LED sequences running.
 
void led_ui_type_stop_all(led_ui_seq_t type)
Stop all sequence of a particular type.
 
Run a sequence repeatedly.
 
uint32_t loop
The number of times the pattern of both seq_config must be repeated.
 
void hal_pwm_stop(void)
Stop the PWM generation.
 
Short between SEQEND[0] event and STOP task.
 
Interrupt on STOPPED event.
 
Struct for initializing the hal pwm module.
 
led_ui_seq_t
To specify if a sequence is run once or repeatedly.
 
void hal_pwm_init(hal_pwm_init_t *init_config)
Initialize the HAL PWM module. Can be called again to change the initialization configuration.
 
1st 16-bit value used in channels 0 and 1; 2nd one in channels 2 and 3.
 
void led_ui_stop_priority(led_ui_seq_t type, uint32_t priority)
Stops LED sequences of a particular type and of a priority level or less.
 
Struct containing the configuration for starting the hal pwm module.
 
led_ui_priority_t
The LED sequence priority levels.
 
void(* irq_handler)(hal_pwm_irq_mask_t irq_source)
the handler called based on the interrupt generated with the argument providing the source of the int...
 
void led_ui_stop_seq(led_ui_seq_t type, led_sequences seq)
Stops a particular sequence of a particular type.