21 #include "out_pattern_gen.h" 22 #include "nrf_assert.h" 28 #include "common_util.h" 31 #define OUT_GEN_MS_TIMER_USED CONCAT_2(MS_TIMER, MS_TIMER_USED_OUT_GEN) 39 uint32_t num_transitions;
40 uint32_t current_transition;
45 void (*done_handler)(uint32_t out_gen_state);
47 static uint32_t timer_start_ticks_value;
49 static void timer_handler(
void)
51 context.current_transition++;
54 for(uint32_t i = 0; i< context.num_out; i++)
56 hal_gpio_pin_write(context.out_pins[i], context.next_out[i][context.current_transition]);
59 if(context.current_transition == context.num_transitions)
61 context.is_on =
false;
62 if(done_handler != NULL)
64 done_handler(context.end_context);
70 context.transitions_durations[context.current_transition],timer_handler);
74 void out_gen_init(uint32_t num_out, uint32_t * out_pins,
bool * out_init_value)
76 log_printf(
"OUT_GEN_INIT\n");
79 context.num_out = num_out;
80 for(uint32_t i = 0; i < num_out; i++)
82 context.out_pins[i] = out_pins[i];
83 hal_gpio_cfg_output(out_pins[i], out_init_value[i]);
86 context.is_on =
false;
93 memset(context.next_out, 0,
sizeof(context.next_out));
94 memset(context.transitions_durations, 0 ,
95 sizeof(context.transitions_durations));
97 context.current_transition = 0;
101 for(uint32_t i = 0; i < context.num_out; i++)
103 memcpy( (*(context.next_out + i)), (*(out_gen_config->
next_out+i)),
105 hal_gpio_pin_write(context.out_pins[i],
106 out_gen_config->
next_out[i][context.current_transition]);
108 context.is_on =
true;
119 context.is_on =
false;
121 for(uint32_t i = 0; i< context.num_out; i++)
123 hal_gpio_pin_write(context.out_pins[i], out_vals[i]);
129 return context.is_on;
void(* done_handler)(uint32_t out_gen_state)
A pointer to a handler called after a pattern is generated.
uint32_t ms_timer_get_current_count(void)
Return the current count (24 bit) of the RTC timer used.
uint32_t transitions_durations[OUT_GEN_MAX_TRANSITIONS]
1 dimensional array containing the durations in terms of LFCLK frequency ticks for the transitions.
uint32_t num_transitions
The number of transitions in this pattern.
bool next_out[OUT_GEN_MAX_NUM_OUT][OUT_GEN_MAX_TRANSITIONS]
A 2 dimensional boolean array containing the next digital output value for the various transitions ac...
uint32_t out_gen_state
State which is to be started with this configuration, passed as an argument with the done_handler.
void out_gen_init(uint32_t num_out, uint32_t *out_pins, bool *out_init_value)
Initialize the output pattern generator module with the information of the pins on which the pattern ...
void out_gen_stop(bool *out_vals)
Stop the output pattern generation and sets the output pins as specified in the arguments.
#define ASSERT(expression)
Macro for runtime assertion of an expression. If the expression is false the assert_nrf_callback func...
bool out_gen_is_on(void)
To know if the output pattern generator module is on.
#define OUT_GEN_MAX_TRANSITIONS
void ms_timer_start(ms_timer_num id, ms_timer_mode mode, uint64_t ticks, void(*handler)(void))
Configuration structure for output pattern generation.
#define OUT_GEN_MAX_NUM_OUT
void out_gen_start(out_gen_config_t *out_gen_config)
Start the generation of the pattern with the information provided.
uint32_t out_gen_get_ticks(void)
Function to get ticks since last call of out_gen_start.
void ms_timer_stop(ms_timer_num id)
One shot call of the timer.