20 #include "nrf_assert.h" 25 #include "isr_manager.h" 31 #define PWM_ID CONCAT_2(NRF_PWM,PWM_USED) 32 #define PWM_IRQN PWM_IRQN_a(PWM_USED) 33 #define PWM_IRQ_Handler PWM_IRQ_Handler_a(PWM_USED) 35 #define PWM_IRQN_a(n) PWM_IRQN_b(n) 36 #define PWM_IRQN_b(n) PWM##n##_IRQn 38 #define PWM_IRQ_Handler_a(n) PWM_IRQ_Handler_b(n) 39 #define PWM_IRQ_Handler_b(n) PWM##n##_IRQHandler 51 if(cxt.handler != NULL)
53 cxt.handler(irq_source);
57 void hal_pwm_Handler (
void)
59 void PWM_IRQ_Handler(
void)
62 if(PWM_ID->EVENTS_STOPPED == 1)
65 PWM_ID->EVENTS_STOPPED = 0;
66 (void) PWM_ID->EVENTS_STOPPED;
71 if(PWM_ID->EVENTS_SEQSTARTED[0] == 1)
74 PWM_ID->EVENTS_SEQSTARTED[0] = 0;
75 (void) PWM_ID->EVENTS_SEQSTARTED[0];
80 if(PWM_ID->EVENTS_SEQSTARTED[1] == 1)
83 PWM_ID->EVENTS_SEQSTARTED[1] = 0;
84 (void) PWM_ID->EVENTS_SEQSTARTED[1];
89 if(PWM_ID->EVENTS_SEQEND[0] == 1)
92 PWM_ID->EVENTS_SEQEND[0] = 0;
93 (void) PWM_ID->EVENTS_SEQEND[0];
98 if(PWM_ID->EVENTS_SEQEND[1] == 1)
101 PWM_ID->EVENTS_SEQEND[1] = 0;
102 (void) PWM_ID->EVENTS_SEQEND[1];
107 if(PWM_ID->EVENTS_PWMPERIODEND == 1)
110 PWM_ID->EVENTS_PWMPERIODEND = 0;
111 (void) PWM_ID->EVENTS_PWMPERIODEND;
116 if(PWM_ID->EVENTS_LOOPSDONE == 1)
119 PWM_ID->EVENTS_LOOPSDONE = 0;
120 (void) PWM_ID->EVENTS_LOOPSDONE;
131 cxt.pin_num = init_config->
pin_num;
134 PWM_ID->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos);
137 PWM_ID->TASKS_STOP = 1;
143 PWM_ID->PSEL.OUT[0] = (init_config->
pins[0] << PWM_PSEL_OUT_PIN_Pos) |
144 (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);
145 PWM_ID->PSEL.OUT[1] = (0 << PWM_PSEL_OUT_PIN_Pos) |
146 (PWM_PSEL_OUT_CONNECT_Disconnected << PWM_PSEL_OUT_CONNECT_Pos);
147 PWM_ID->PSEL.OUT[2] = (0 << PWM_PSEL_OUT_PIN_Pos) |
148 (PWM_PSEL_OUT_CONNECT_Disconnected << PWM_PSEL_OUT_CONNECT_Pos);
149 PWM_ID->PSEL.OUT[3] = (0 << PWM_PSEL_OUT_PIN_Pos) |
150 (PWM_PSEL_OUT_CONNECT_Disconnected << PWM_PSEL_OUT_CONNECT_Pos);
154 PWM_ID->PSEL.OUT[0] = (init_config->
pins[0] << PWM_PSEL_OUT_PIN_Pos) |
155 (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);
157 PWM_ID->PSEL.OUT[2] = (init_config->
pins[1] << PWM_PSEL_OUT_PIN_Pos) |
158 (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);
159 PWM_ID->PSEL.OUT[1] = (0 << PWM_PSEL_OUT_PIN_Pos) |
160 (PWM_PSEL_OUT_CONNECT_Disconnected << PWM_PSEL_OUT_CONNECT_Pos);
161 PWM_ID->PSEL.OUT[3] = (0 << PWM_PSEL_OUT_PIN_Pos) |
162 (PWM_PSEL_OUT_CONNECT_Disconnected << PWM_PSEL_OUT_CONNECT_Pos);
167 for(uint32_t i = 0; i < init_config->
pin_num; i++)
170 PWM_ID->PSEL.OUT[i] = (init_config->
pins[i] << PWM_PSEL_OUT_PIN_Pos) |
171 (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);
176 PWM_ID->PSEL.OUT[i] = (0 << PWM_PSEL_OUT_PIN_Pos) |
177 (PWM_PSEL_OUT_CONNECT_Disconnected << PWM_PSEL_OUT_CONNECT_Pos);
184 PWM_ID->PRESCALER = (init_config->
oper_freq <<
185 PWM_PRESCALER_PRESCALER_Pos);
186 PWM_ID->MODE = (init_config->
oper_mode << PWM_MODE_UPDOWN_Pos);
189 NVIC_EnableIRQ(PWM0_IRQn);
199 PWM_ID->TASKS_STOP = 1;
201 PWM_ID->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);
202 PWM_ID->COUNTERTOP = (start_config->
countertop << PWM_COUNTERTOP_COUNTERTOP_Pos);
203 PWM_ID->LOOP = (start_config->
loop << PWM_LOOP_CNT_Pos);
204 PWM_ID->DECODER = (start_config->
decoder_load << PWM_DECODER_LOAD_Pos) |
209 << PWM_SEQ_PTR_PTR_Pos);
210 PWM_ID->SEQ[0].CNT = (start_config->
seq_config[0].
len) << PWM_SEQ_CNT_CNT_Pos;
215 << PWM_SEQ_PTR_PTR_Pos);
216 PWM_ID->SEQ[1].CNT = (start_config->
seq_config[1].
len) << PWM_SEQ_CNT_CNT_Pos;
226 PWM_ID->TASKS_SEQSTART[0] = 1;
232 PWM_ID->TASKS_STOP = 1;
233 PWM_ID->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos);
uint32_t shorts_mask
Select the shortcuts that need to be enabled. OR the values in hal_pwm_short_mask_t to enable them.
Interrupt on SEQSTARTED[0] event.
hal_pwm_irq_mask_t
PWM interrupts.
uint32_t repeats
Number of times a particular value should be played. Only for HAL_PWM_STEP_INTERNAL mode.
uint32_t * pins
Pointer to array containing the pins number used by hal pwm.
uint32_t interrupt_masks
Select the interrupts that need to be enabled OR the values in hal_pwm_irq_mask_t to enable them.
uint16_t len
Number of 16-bit values in the buffer pointed by seq_values.
uint32_t countertop
Maximum count of the counter. This and oper_freq decide the frequency of the resulting PWM waveform.
hal_pwm_decoder_load_t decoder_load
Select the way in which the data pointed in seq_config is loaded into to the various channels.
uint32_t irq_priority
IRQ priority with which the irq_handler in hal_pwm_start_t is called.
void hal_pwm_start(hal_pwm_start_t *start_config)
Start the PWM generation based on the configuration provided.
uint16_t * seq_values
Pointer to an array containing the PWM duty cycle values. This array present in the data RAM should p...
Interrupt on PWMPERIODEND event.
#define ASSERT(expression)
Macro for runtime assertion of an expression. If the expression is false the assert_nrf_callback func...
hal_pwm_freq_t oper_freq
Select the operating frequency of the hal pwm module.
Interrupt on SEQEND[1] event.
uint32_t loop
The number of times the pattern of both seq_config must be repeated.
#define HAL_PWM_MAX_PIN_NUM
hal_pwm_dec_trigger_t decoder_trigger
Select when the next data is loaded to the PWM.
bool * pin_idle_state
Pointer to array having the state of pins when PWM generation isn't on.
uint32_t pin_num
Number of pins to be used by hal pwm. Maximum is HAL_PWM_MAX_PIN_NUM.
void hal_pwm_stop(void)
Stop the PWM generation.
Interrupt on SEQEND[0] event.
Interrupt on SEQSTARTED[1] event.
hal_pwm_mode_t oper_mode
Select the operating mode (Up or Up&Down) of the module's counter.
Interrupt on STOPPED event.
hal_pwm_sequence_config_t seq_config[2]
The two configurations for the sequences. If loop is zero only the first sequence is played once....
Struct for initializing the hal pwm module.
void hal_pwm_init(hal_pwm_init_t *init_config)
Initialize the HAL PWM module. Can be called again to change the initialization configuration.
Interrupt on LOOPSDONE event.
uint32_t end_delay
Additional number of cycles that the last PWM value is to be played after the end....
Struct containing the configuration for starting the hal pwm module.
1st three channels have their own 16 bit values, 4th one is the wave counter.
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...