123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #include "nrf21540_gpio.h"
- #include "nrf_assert.h"
- #include "boards.h"
- #include "nrf21540_defs.h"
- #include "nrf_gpiote.h"
- #include "nrf_ppi.h"
- #include "nrf_timer.h"
- void nrf21540_gpio_init(void)
- {
- nrf_gpio_cfg_output(NRF21540_ANTSEL_PIN);
- #if NRF21540_USE_GPIO_MANAGEMENT
- nrf_gpio_cfg_output(NRF21540_MODE_PIN);
-
- nrf_gpiote_task_configure(NRF21540_PA_GPIOTE_CHANNEL_NO,
- NRF21540_TXEN_PIN,
- (nrf_gpiote_polarity_t) GPIOTE_CONFIG_POLARITY_None,
- NRF_GPIOTE_INITIAL_VALUE_LOW);
- nrf_gpiote_task_enable(NRF21540_PA_GPIOTE_CHANNEL_NO);
-
- nrf_gpiote_task_configure(NRF21540_LNA_GPIOTE_CHANNEL_NO,
- NRF21540_RXEN_PIN,
- (nrf_gpiote_polarity_t) GPIOTE_CONFIG_POLARITY_None,
- NRF_GPIOTE_INITIAL_VALUE_LOW);
- nrf_gpiote_task_enable(NRF21540_LNA_GPIOTE_CHANNEL_NO);
- #endif
- }
- ret_code_t nrf21540_gpio_ant_set(nrf21540_antenna_t antenna)
- {
- if (antenna == NRF21540_ANT1)
- {
- nrf_gpio_pin_clear(NRF21540_ANTSEL_PIN);
- }
- else if (antenna == NRF21540_ANT2)
- {
- nrf_gpio_pin_set(NRF21540_ANTSEL_PIN);
- }
- else
- {
- return NRF_ERROR_INVALID_PARAM;
- }
- return NRF_SUCCESS;
- }
- #if NRF21540_USE_GPIO_MANAGEMENT
- uint32_t nrf21540_gpio_trx_task_start_address_get(nrf21540_trx_t dir,
- nrf21540_bool_state_t required_state)
- {
- uint8_t gpiote_rx_tx_channel =
- dir == NRF21540_TX ?
- NRF21540_PA_GPIOTE_CHANNEL_NO :
- NRF21540_LNA_GPIOTE_CHANNEL_NO;
- return required_state == NRF21540_ENABLE ?
- nrf_gpiote_task_addr_get(nrf_gpiote_set_task_get(gpiote_rx_tx_channel)) :
- nrf_gpiote_task_addr_get(nrf_gpiote_clr_task_get(gpiote_rx_tx_channel));
- }
- void nrf21540_gpio_trx_enable(nrf21540_trx_t dir)
- {
- uint32_t gpiote_task_start = nrf21540_gpio_trx_task_start_address_get(dir, NRF21540_ENABLE);
- nrf_ppi_channel_endpoint_setup(NRF21540_TRX_PPI_CHANNEL,
- (uint32_t)nrf_timer_event_address_get(NRF21540_TIMER,
- NRF21540_TIMER_CC_PD_PG_EVENT),
- gpiote_task_start);
- nrf_ppi_channel_enable(NRF21540_TRX_PPI_CHANNEL);
- }
- ret_code_t nrf21540_gpio_pwr_mode_set(nrf21540_pwr_mode_t mode)
- {
- if (mode == NRF21540_PWR_MODE_A)
- {
- nrf_gpio_pin_clear(NRF21540_MODE_PIN);
- }
- else if (mode == NRF21540_PWR_MODE_B)
- {
- nrf_gpio_pin_set(NRF21540_MODE_PIN);
- }
- else
- {
- return NRF_ERROR_INVALID_PARAM;
- }
- return NRF_SUCCESS;
- }
- #endif
|