123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- #ifndef NRF_QDEC_H__
- #define NRF_QDEC_H__
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRF_QDEC_LED_NOT_CONNECTED 0xFFFFFFFF
- typedef enum
- {
- NRF_QDEC_TASK_START = offsetof(NRF_QDEC_Type, TASKS_START),
- NRF_QDEC_TASK_STOP = offsetof(NRF_QDEC_Type, TASKS_STOP),
- NRF_QDEC_TASK_READCLRACC = offsetof(NRF_QDEC_Type, TASKS_READCLRACC)
- } nrf_qdec_task_t;
- typedef enum
- {
- NRF_QDEC_EVENT_SAMPLERDY = offsetof(NRF_QDEC_Type, EVENTS_SAMPLERDY),
- NRF_QDEC_EVENT_REPORTRDY = offsetof(NRF_QDEC_Type, EVENTS_REPORTRDY),
- NRF_QDEC_EVENT_ACCOF = offsetof(NRF_QDEC_Type, EVENTS_ACCOF)
- } nrf_qdec_event_t;
- typedef enum
- {
- NRF_QDEC_SHORT_REPORTRDY_READCLRACC_MASK = QDEC_SHORTS_REPORTRDY_READCLRACC_Msk,
- NRF_QDEC_SHORT_SAMPLERDY_STOP_MASK = QDEC_SHORTS_SAMPLERDY_STOP_Msk
- } nrf_qdec_short_mask_t;
- typedef enum
- {
- NRF_QDEC_INT_SAMPLERDY_MASK = QDEC_INTENSET_SAMPLERDY_Msk,
- NRF_QDEC_INT_REPORTRDY_MASK = QDEC_INTENSET_REPORTRDY_Msk,
- NRF_QDEC_INT_ACCOF_MASK = QDEC_INTENSET_ACCOF_Msk
- } nrf_qdec_int_mask_t;
- typedef enum
- {
- NRF_QDEC_DISABLE = QDEC_ENABLE_ENABLE_Disabled,
- NRF_QDEC_ENABLE = QDEC_ENABLE_ENABLE_Enabled
- } nrf_qdec_enable_t;
- typedef enum
- {
- NRF_QDEC_DBFEN_DISABLE = QDEC_DBFEN_DBFEN_Disabled,
- NRF_QDEC_DBFEN_ENABLE = QDEC_DBFEN_DBFEN_Enabled
- } nrf_qdec_dbfen_t;
- typedef enum
- {
- NRF_QDEC_LEPOL_ACTIVE_LOW = QDEC_LEDPOL_LEDPOL_ActiveLow,
- NRF_QDEC_LEPOL_ACTIVE_HIGH = QDEC_LEDPOL_LEDPOL_ActiveHigh
- } nrf_qdec_ledpol_t;
- typedef enum
- {
- NRF_QDEC_SAMPLEPER_128us = QDEC_SAMPLEPER_SAMPLEPER_128us,
- NRF_QDEC_SAMPLEPER_256us = QDEC_SAMPLEPER_SAMPLEPER_256us,
- NRF_QDEC_SAMPLEPER_512us = QDEC_SAMPLEPER_SAMPLEPER_512us,
- NRF_QDEC_SAMPLEPER_1024us = QDEC_SAMPLEPER_SAMPLEPER_1024us,
- NRF_QDEC_SAMPLEPER_2048us = QDEC_SAMPLEPER_SAMPLEPER_2048us,
- NRF_QDEC_SAMPLEPER_4096us = QDEC_SAMPLEPER_SAMPLEPER_4096us,
- NRF_QDEC_SAMPLEPER_8192us = QDEC_SAMPLEPER_SAMPLEPER_8192us,
- NRF_QDEC_SAMPLEPER_16384us = QDEC_SAMPLEPER_SAMPLEPER_16384us
- } nrf_qdec_sampleper_t;
- typedef enum
- {
- NRF_QDEC_REPORTPER_10 = QDEC_REPORTPER_REPORTPER_10Smpl,
- NRF_QDEC_REPORTPER_40 = QDEC_REPORTPER_REPORTPER_40Smpl,
- NRF_QDEC_REPORTPER_80 = QDEC_REPORTPER_REPORTPER_80Smpl,
- NRF_QDEC_REPORTPER_120 = QDEC_REPORTPER_REPORTPER_120Smpl,
- NRF_QDEC_REPORTPER_160 = QDEC_REPORTPER_REPORTPER_160Smpl,
- NRF_QDEC_REPORTPER_200 = QDEC_REPORTPER_REPORTPER_200Smpl,
- NRF_QDEC_REPORTPER_240 = QDEC_REPORTPER_REPORTPER_240Smpl,
- NRF_QDEC_REPORTPER_280 = QDEC_REPORTPER_REPORTPER_280Smpl,
- NRF_QDEC_REPORTPER_DISABLED
- } nrf_qdec_reportper_t;
- __STATIC_INLINE void nrf_qdec_enable(void);
- __STATIC_INLINE void nrf_qdec_disable(void);
- __STATIC_INLINE uint32_t nrf_qdec_enable_get(void);
- __STATIC_INLINE void nrf_qdec_int_enable(uint32_t mask);
- __STATIC_INLINE void nrf_qdec_int_disable(uint32_t mask);
- __STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t mask);
- __STATIC_INLINE void nrf_qdec_dbfen_enable(void);
- __STATIC_INLINE void nrf_qdec_dbfen_disable(void);
- __STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void);
- __STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled);
- __STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t task);
- __STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t task);
- __STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t event);
- __STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t event);
- __STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t event);
- __STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t mask);
- __STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t mask);
- __STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void);
- __STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper);
- __STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per);
- __STATIC_INLINE int32_t nrf_qdec_sample_get(void);
- __STATIC_INLINE int32_t nrf_qdec_acc_get(void);
- __STATIC_INLINE int32_t nrf_qdec_accread_get(void);
- __STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void);
- __STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void);
- __STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us);
- __STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void);
- __STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper);
- __STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void);
- __STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper);
- __STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol);
- __STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_qdec_enable(void)
- {
- NRF_QDEC->ENABLE = NRF_QDEC_ENABLE;
- }
- __STATIC_INLINE void nrf_qdec_disable(void)
- {
- NRF_QDEC->ENABLE = NRF_QDEC_DISABLE;
- }
- __STATIC_INLINE uint32_t nrf_qdec_enable_get(void)
- {
- return NRF_QDEC->ENABLE;
- }
- __STATIC_INLINE void nrf_qdec_int_enable(uint32_t mask)
- {
- NRF_QDEC->INTENSET = mask;
- }
- __STATIC_INLINE void nrf_qdec_int_disable(uint32_t mask)
- {
- NRF_QDEC->INTENCLR = mask;
- }
- __STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t mask)
- {
- return NRF_QDEC->INTENSET & mask;
- }
- __STATIC_INLINE void nrf_qdec_dbfen_enable(void)
- {
- NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_ENABLE;
- }
- __STATIC_INLINE void nrf_qdec_dbfen_disable(void)
- {
- NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_DISABLE;
- }
- __STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void)
- {
- return NRF_QDEC->DBFEN;
- }
- __STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled)
- {
- #if defined(QDEC_PSEL_A_CONNECT_Pos)
- NRF_QDEC->PSEL.A = psela;
- #else
- NRF_QDEC->PSELA = psela;
- #endif
- #if defined(QDEC_PSEL_B_CONNECT_Pos)
- NRF_QDEC->PSEL.B = pselb;
- #else
- NRF_QDEC->PSELB = pselb;
- #endif
- #if defined(QDEC_PSEL_LED_CONNECT_Pos)
- NRF_QDEC->PSEL.LED = pselled;
- #else
- NRF_QDEC->PSELLED = pselled;
- #endif
- }
- __STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t task)
- {
- *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)task) ) = 1;
- }
- __STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t task)
- {
- return (uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)task);
- }
- __STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t event)
- {
- *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)event) ) = 0;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_QDEC + event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t event)
- {
- return *(volatile uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)event);
- }
- __STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t event)
- {
- return (uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t mask)
- {
- NRF_QDEC->SHORTS |= mask;
- }
- __STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t mask)
- {
- NRF_QDEC->SHORTS &= ~mask;
- }
- __STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void)
- {
- return NRF_QDEC->SAMPLEPER;
- }
- __STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper)
- {
- return (1 << (7 + sampleper));
- }
- __STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per)
- {
- NRF_QDEC->SAMPLEPER = sample_per;
- }
- __STATIC_INLINE int32_t nrf_qdec_sample_get(void)
- {
- return NRF_QDEC->SAMPLE;
- }
- __STATIC_INLINE int32_t nrf_qdec_acc_get(void)
- {
- return NRF_QDEC->ACC;
- }
- __STATIC_INLINE int32_t nrf_qdec_accread_get(void)
- {
- return NRF_QDEC->ACCREAD;
- }
- __STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void)
- {
- return NRF_QDEC->ACCDBL;
- }
- __STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void)
- {
- return NRF_QDEC->ACCDBLREAD;
- }
- __STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us)
- {
- NRF_QDEC->LEDPRE = time_us;
- }
- __STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void)
- {
- return NRF_QDEC->LEDPRE;
- }
- __STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper)
- {
- NRF_QDEC->REPORTPER = reportper;
- }
- __STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void)
- {
- return NRF_QDEC->REPORTPER;
- }
- __STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper)
- {
- return (reportper == NRF_QDEC_REPORTPER_10) ? 10 : reportper * 40;
- }
- __STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol)
- {
- NRF_QDEC->LEDPOL = pol;
- }
- __STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void)
- {
- return NRF_QDEC->LEDPOL;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|