Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.74 KB | None | 0 0
  1. static void pin_clear(const ble_pa_lna_cfg_t * p_cfg)
  2. {
  3.     if (p_cfg->enable)
  4.     {
  5.         if(p_cfg->gpio_pin <= ARRAY_SIZE(NRF_P0->PIN_CNF)) {
  6.             if (p_cfg->active_high)
  7.             {
  8.                 NRF_P0->OUTCLR = (1UL << p_cfg->gpio_pin);
  9.             }
  10.             else
  11.             {
  12.                 NRF_P0->OUTSET = (1UL << p_cfg->gpio_pin);
  13.             }
  14.         } else {
  15.             if (p_cfg->active_high)
  16.             {
  17.                 NRF_P1->OUTCLR = (1UL << p_cfg->gpio_pin);
  18.             }
  19.             else
  20.             {
  21.                 NRF_P1->OUTSET = (1UL << p_cfg->gpio_pin);
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27. static void pin_init(const ble_pa_lna_cfg_t * p_cfg)
  28. {
  29.     if (p_cfg->enable)
  30.     {
  31.         uint32_t pinNumber = p_cfg->gpio_pin;
  32.         NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pinNumber);
  33.  
  34.         reg->PIN_CNF[p_cfg->gpio_pin] =
  35.             ((uint32_t) GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) |
  36.             ((uint32_t) GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) |
  37.             ((uint32_t) GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
  38.             ((uint32_t) GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
  39.             ((uint32_t) GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
  40.         reg->DIRSET = (GPIO_DIRSET_PIN0_Output << (GPIO_DIRSET_PIN0_Pos + p_cfg->gpio_pin));
  41.         pin_clear(p_cfg);
  42.        
  43.     }
  44. }
  45.  
  46. uint32_t m_mesh_pa_lna_gpiote_enable(const mesh_pa_lna_gpiote_params_t * p_params)
  47. {
  48. /*
  49.     if(p_params->lna_cfg.gpio_pin > ARRAY_SIZE(NRF_P0->PIN_CNF)) {
  50.         __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "LNA pin for mesh remapped!\n");
  51.         p_params->lna_cfg.gpio_pin -= ARRAY_SIZE(NRF_P0->PIN_CNF);
  52.     }
  53.  
  54.     if(p_params->_cfg.gpio_pin > ARRAY_SIZE(NRF_P0->PIN_CNF)) {
  55.         __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "PA pin for mesh remapped!\n");
  56.         p_params->pa_cfg.gpio_pin -= ARRAY_SIZE(NRF_P0->PIN_CNF);
  57.     }
  58. */
  59.     if (p_params == NULL)
  60.     {
  61.         return NRF_ERROR_NULL;
  62.     }
  63.  
  64.     if ((p_params->ppi_ch_id_set >= TIMER_PPI_CH_START &&
  65.          p_params->ppi_ch_id_set <= TIMER_PPI_CH_STOP) ||
  66.         (p_params->ppi_ch_id_clr >= TIMER_PPI_CH_START &&
  67.          p_params->ppi_ch_id_clr <= TIMER_PPI_CH_STOP) ||
  68.         (p_params->ppi_ch_id_set >= ARRAY_SIZE(NRF_PPI->CH)) ||
  69.         (p_params->ppi_ch_id_clr >= ARRAY_SIZE(NRF_PPI->CH)) ||
  70.         (p_params->ppi_ch_id_set == p_params->ppi_ch_id_clr) ||
  71.         (p_params->gpiote_ch_id >= ARRAY_SIZE(NRF_GPIOTE->CONFIG)))
  72.     {
  73.         return NRF_ERROR_INVALID_PARAM;
  74.     }
  75.  
  76.     m_gpiote.enabled = false;
  77.     m_gpiote.params = *p_params;
  78.     m_gpiote.enabled = true;
  79.     pin_init(&p_params->lna_cfg);
  80.     pin_init(&p_params->pa_cfg);
  81.     return NRF_SUCCESS;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement