123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- #ifndef NRF21540_SPI_H_
- #define NRF21540_SPI_H_
- #include <stdbool.h>
- #include <stdint.h>
- #include "nrfx_spim.h"
- #include "nrf21540_types.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRF21540_SPI_LENGTH_BYTES 2
- #define NRF21540_SPI_COMMAND_ADDR_BYTE 0
- #define NRF21540_SPI_DATA_BYTE 1
- #define NRF21540_SPI_COMMAND_Pos 6
- #define NRF21540_SPI_REG_Pos 0
- #define NRF21540_SPI_COMMAND_NOP 0x00
- #define NRF21540_SPI_COMMAND_READ 0x02
- #define NRF21540_SPI_COMMAND_WRITE 0x03
- #define NRF21540_BITS_CONFREG0_TX_EN_Pos 0
- #define NRF21540_BITS_CONFREG0_TX_EN_Msk (1 << NRF21540_BITS_CONFREG0_TX_EN_Pos)
- #define NRF21540_BITS_CONFREG0_TX_EN_Disable 0
- #define NRF21540_BITS_CONFREG0_TX_EN_Enable 1
- #define NRF21540_BITS_CONFREG0_MODE_Pos 1
- #define NRF21540_BITS_CONFREG0_MODE_Msk (1 << NRF21540_BITS_CONFREG0_MODE_Pos)
- #define NRF21540_BITS_CONFREG0_MODE_0 0
- #define NRF21540_BITS_CONFREG0_MODE_1 1
- #define NRF21540_BITS_CONFREG0_TX_GAIN_Pos 2
- #define NRF21540_BITS_CONFREG0_TX_GAIN_Msk (0x1F << NRF21540_BITS_CONFREG0_TX_GAIN_Pos)
- #define NRF21540_BITS_CONFREG0_TX_GAIN_Min 0
- #define NRF21540_BITS_CONFREG0_TX_GAIN_Max 31
- #define NRF21540_BITS_CONFREG1_RX_EN_Pos 0
- #define NRF21540_BITS_CONFREG1_RX_EN_Msk (1 << NRF21540_BITS_CONFREG1_RX_EN_Pos)
- #define NRF21540_BITS_CONFREG1_RX_EN_Disable 0
- #define NRF21540_BITS_CONFREG1_RX_EN_Enable 1
- #define NRF21540_BITS_CONFREG1_UICR_EN_Pos 2
- #define NRF21540_BITS_CONFREG1_UICR_EN_Msk (1 << NRF21540_BITS_CONFREG1_UICR_EN_Pos)
- #define NRF21540_BITS_CONFREG1_UICR_EN_Disable 0
- #define NRF21540_BITS_CONFREG1_UICR_EN_Enable 1
- #define NRF21540_BITS_CONFREG1_KEY_Pos 4
- #define NRF21540_BITS_CONFREG1_KEY_Msk (0x0F << NRF21540_BITS_CONFREG1_KEY_Pos)
- #define NRF21540_BITS_CONFREG1_KEY_Enter 15
- #define NRF21540_BITS_CONFREG1_KEY_Leave 0
- #define NRF21540_BITS_CONFREG2_POUTA_UICR_Pos 0
- #define NRF21540_BITS_CONFREG2_POUTA_UICR_Msk (0x1F << NRF21540_BITS_CONFREG2_POUTA_UICR_Pos)
- #define NRF21540_BITS_CONFREG2_POUTA_UICR_Min 0
- #define NRF21540_BITS_CONFREG2_POUTA_UICR_Max 31
- #define NRF21540_BITS_CONFREG2_POUTA_SEL_Pos 5
- #define NRF21540_BITS_CONFREG2_POUTA_SEL_Msk (1 << NRF21540_BITS_CONFREG2_POUTA_SEL_Pos)
- #define NRF21540_BITS_CONFREG2_POUTA_SEL_PROD 0
- #define NRF21540_BITS_CONFREG2_POUTA_SEL_UICR 1
- #define NRF21540_BITS_CONFREG2_WR_UICR_Pos 7
- #define NRF21540_BITS_CONFREG2_WR_UICR_Msk (1 << NRF21540_BITS_CONFREG2_WR_UICR_Pos)
- #define NRF21540_BITS_CONFREG2_WR_UICR_IDLE 0
- #define NRF21540_BITS_CONFREG2_WR_UICR_WRITE 1
- #define NRF21540_BITS_CONFREG3_POUTB_UICR_Pos 0
- #define NRF21540_BITS_CONFREG3_POUTB_UICR_Msk (0x1F << NRF21540_BITS_CONFREG3_POUTB_SEL_Pos)
- #define NRF21540_BITS_CONFREG3_POUTB_UICR_Min 0
- #define NRF21540_BITS_CONFREG3_POUTB_UICR_Max 31
- #define NRF21540_BITS_CONFREG3_POUTB_SEL_Pos 5
- #define NRF21540_BITS_CONFREG3_POUTB_SEL_Msk (1 << NRF21540_BITS_CONFREG3_POUTB_SEL_Pos)
- #define NRF21540_BITS_CONFREG3_POUTB_SEL_PROD 0
- #define NRF21540_BITS_CONFREG3_POUTB_SEL_UICR 1
- #define NRF21540_PARTNUMBER_PARTNUMBER_Pos 0
- #define NRF21540_PARTNUMBER_PARTNUMBER_Msk (0xFF << NRF21540_PARTNUMBER_PARTNUMBER_Pos)
- #define NRF21540_HW_REVISON_HW_REVISION_Pos 4
- #define NRF21540_HW_REVISON_HW_REVISION_Msk (0xF << NRF21540_HW_REVISON_HW_REVISION_Pos)
- #define NRF21540_HW_ID0_Pos 0
- #define NRF21540_HW_ID0_Msk (0xFF << NRF21540_HW_ID0_Pos)
- #define NRF21540_HW_ID1_Pos 0
- #define NRF21540_HW_ID1_Msk (0xFF << NRF21540_HW_ID1_Pos)
- typedef enum
- {
- NRF21540_REG_CONFREG0 = 0x00,
- NRF21540_REG_CONFREG1 = 0x01,
- NRF21540_REG_CONFREG2 = 0x02,
- NRF21540_REG_CONFREG3 = 0x03,
- NRF21540_REG_PARTNUMBER = 0x14,
- NRF21540_REG_HW_REVISION = 0x15,
- NRF21540_REG_HW_ID0 = 0x16,
- NRF21540_REG_HW_ID1 = 0x17,
- } nrf21540_reg_t;
- ret_code_t nrf21540_spi_init(void);
- uint32_t nrf21540_spim_trx_task_start_address_get(void);
- void nrf21540_spim_for_trx_configure(nrf21540_trx_t dir, nrf21540_bool_state_t required_state);
- ret_code_t nrf21540_spi_pwr_mode_set(nrf21540_pwr_mode_t mode);
- ret_code_t nrf21540_pdn_drive(bool state, nrf21540_execution_mode_t mode);
- #ifdef __cplusplus
- }
- #endif
- #endif
|