123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- #ifndef NRFX_PWM_H__
- #define NRFX_PWM_H__
- #include <nrfx.h>
- #include <hal/nrf_pwm.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- NRF_PWM_Type * p_registers;
- uint8_t drv_inst_idx;
- } nrfx_pwm_t;
- #define NRFX_PWM_INSTANCE(id) \
- { \
- .p_registers = NRFX_CONCAT_2(NRF_PWM, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \
- }
- #ifndef __NRFX_DOXYGEN__
- enum {
- #if NRFX_CHECK(NRFX_PWM0_ENABLED)
- NRFX_PWM0_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_PWM1_ENABLED)
- NRFX_PWM1_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_PWM2_ENABLED)
- NRFX_PWM2_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_PWM3_ENABLED)
- NRFX_PWM3_INST_IDX,
- #endif
- NRFX_PWM_ENABLED_COUNT
- };
- #endif
- #define NRFX_PWM_PIN_NOT_USED 0xFF
- #define NRFX_PWM_PIN_INVERTED 0x80
- typedef struct
- {
- uint8_t output_pins[NRF_PWM_CHANNEL_COUNT];
-
- uint8_t irq_priority;
- nrf_pwm_clk_t base_clock;
- nrf_pwm_mode_t count_mode;
- uint16_t top_value;
- nrf_pwm_dec_load_t load_mode;
- nrf_pwm_dec_step_t step_mode;
- } nrfx_pwm_config_t;
- #define NRFX_PWM_DEFAULT_CONFIG \
- { \
- .output_pins = { NRFX_PWM_DEFAULT_CONFIG_OUT0_PIN, \
- NRFX_PWM_DEFAULT_CONFIG_OUT1_PIN, \
- NRFX_PWM_DEFAULT_CONFIG_OUT2_PIN, \
- NRFX_PWM_DEFAULT_CONFIG_OUT3_PIN }, \
- .irq_priority = NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY, \
- .base_clock = (nrf_pwm_clk_t)NRFX_PWM_DEFAULT_CONFIG_BASE_CLOCK, \
- .count_mode = (nrf_pwm_mode_t)NRFX_PWM_DEFAULT_CONFIG_COUNT_MODE, \
- .top_value = NRFX_PWM_DEFAULT_CONFIG_TOP_VALUE, \
- .load_mode = (nrf_pwm_dec_load_t)NRFX_PWM_DEFAULT_CONFIG_LOAD_MODE, \
- .step_mode = (nrf_pwm_dec_step_t)NRFX_PWM_DEFAULT_CONFIG_STEP_MODE, \
- }
- typedef enum
- {
- NRFX_PWM_FLAG_STOP = 0x01,
- NRFX_PWM_FLAG_LOOP = 0x02,
- NRFX_PWM_FLAG_SIGNAL_END_SEQ0 = 0x04,
- NRFX_PWM_FLAG_SIGNAL_END_SEQ1 = 0x08,
- NRFX_PWM_FLAG_NO_EVT_FINISHED = 0x10,
- NRFX_PWM_FLAG_START_VIA_TASK = 0x80,
- } nrfx_pwm_flag_t;
- typedef enum
- {
- NRFX_PWM_EVT_FINISHED,
- NRFX_PWM_EVT_END_SEQ0,
- NRFX_PWM_EVT_END_SEQ1,
- NRFX_PWM_EVT_STOPPED,
- } nrfx_pwm_evt_type_t;
- typedef void (* nrfx_pwm_handler_t)(nrfx_pwm_evt_type_t event_type);
- nrfx_err_t nrfx_pwm_init(nrfx_pwm_t const * const p_instance,
- nrfx_pwm_config_t const * p_config,
- nrfx_pwm_handler_t handler);
- void nrfx_pwm_uninit(nrfx_pwm_t const * const p_instance);
- uint32_t nrfx_pwm_simple_playback(nrfx_pwm_t const * const p_instance,
- nrf_pwm_sequence_t const * p_sequence,
- uint16_t playback_count,
- uint32_t flags);
- uint32_t nrfx_pwm_complex_playback(nrfx_pwm_t const * const p_instance,
- nrf_pwm_sequence_t const * p_sequence_0,
- nrf_pwm_sequence_t const * p_sequence_1,
- uint16_t playback_count,
- uint32_t flags);
- __STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance);
- bool nrfx_pwm_stop(nrfx_pwm_t const * const p_instance, bool wait_until_stopped);
- bool nrfx_pwm_is_stopped(nrfx_pwm_t const * const p_instance);
- __STATIC_INLINE void nrfx_pwm_sequence_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- nrf_pwm_sequence_t const * p_sequence);
- __STATIC_INLINE void nrfx_pwm_sequence_values_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- nrf_pwm_values_t values);
- __STATIC_INLINE void nrfx_pwm_sequence_length_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- uint16_t length);
- __STATIC_INLINE void nrfx_pwm_sequence_repeats_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- uint32_t repeats);
- __STATIC_INLINE void nrfx_pwm_sequence_end_delay_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- uint32_t end_delay);
- __STATIC_INLINE uint32_t nrfx_pwm_task_address_get(nrfx_pwm_t const * const p_instance,
- nrf_pwm_task_t task);
- __STATIC_INLINE uint32_t nrfx_pwm_event_address_get(nrfx_pwm_t const * const p_instance,
- nrf_pwm_event_t event);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance)
- {
- nrf_pwm_task_trigger(p_instance->p_registers, NRF_PWM_TASK_NEXTSTEP);
- }
- __STATIC_INLINE void nrfx_pwm_sequence_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- nrf_pwm_sequence_t const * p_sequence)
- {
- nrf_pwm_sequence_set(p_instance->p_registers, seq_id, p_sequence);
- }
- __STATIC_INLINE void nrfx_pwm_sequence_values_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- nrf_pwm_values_t values)
- {
- nrf_pwm_seq_ptr_set(p_instance->p_registers, seq_id, values.p_raw);
- }
- __STATIC_INLINE void nrfx_pwm_sequence_length_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- uint16_t length)
- {
- nrf_pwm_seq_cnt_set(p_instance->p_registers, seq_id, length);
- }
- __STATIC_INLINE void nrfx_pwm_sequence_repeats_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- uint32_t repeats)
- {
- nrf_pwm_seq_refresh_set(p_instance->p_registers, seq_id, repeats);
- }
- __STATIC_INLINE void nrfx_pwm_sequence_end_delay_update(nrfx_pwm_t const * const p_instance,
- uint8_t seq_id,
- uint32_t end_delay)
- {
- nrf_pwm_seq_end_delay_set(p_instance->p_registers, seq_id, end_delay);
- }
- __STATIC_INLINE uint32_t nrfx_pwm_task_address_get(nrfx_pwm_t const * const p_instance,
- nrf_pwm_task_t task)
- {
- return nrf_pwm_task_address_get(p_instance->p_registers, task);
- }
- __STATIC_INLINE uint32_t nrfx_pwm_event_address_get(nrfx_pwm_t const * const p_instance,
- nrf_pwm_event_t event)
- {
- return nrf_pwm_event_address_get(p_instance->p_registers, event);
- }
- #endif
- void nrfx_pwm_0_irq_handler(void);
- void nrfx_pwm_1_irq_handler(void);
- void nrfx_pwm_2_irq_handler(void);
- void nrfx_pwm_3_irq_handler(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|