@ -11,6 +11,8 @@
# include "system_settings.h"
# include "utils/hexdump.h"
# if SUPPORT_NRF
extern osSemaphoreId semVcomTxReadyHandle ;
# define RX_PIPE_NUM 0
@ -70,15 +72,17 @@ bool iface_nordic_init(void)
hw_periph_clock_enable ( NRF_SPI ) ;
// SPI pins
assert_param ( E_SUCCESS = = hw_configure_gpiorsc_af ( NRF_R_SCK , NRF_SPI _AF ) ) ;
assert_param ( E_SUCCESS = = hw_configure_gpiorsc_af ( NRF_R_MOSI , NRF_SP I_AF ) ) ;
assert_param ( E_SUCCESS = = hw_configure_gpiorsc_af ( NRF_R_MISO , NRF_SPI _AF ) ) ;
assert_param ( E_SUCCESS = = hw_configure_gpiorsc_af ( NRF_R_SCK , NRF_SCK _AF ) ) ;
assert_param ( E_SUCCESS = = hw_configure_gpiorsc_af ( NRF_R_MOSI , NRF_MO SI_AF ) ) ;
assert_param ( E_SUCCESS = = hw_configure_gpiorsc_af ( NRF_R_MISO , NRF_MISO _AF ) ) ;
// Manual pins
LL_GPIO_SetPinMode ( NRF_NSS_GPIO_Port , NRF_NSS_Pin , LL_GPIO_MODE_OUTPUT ) ;
LL_GPIO_SetPinMode ( NRF_CE_GPIO_Port , NRF_CE_Pin , LL_GPIO_MODE_OUTPUT ) ;
LL_GPIO_SetPinMode ( NRF_RST_GPIO_Port , NRF_RST_Pin , LL_GPIO_MODE_OUTPUT ) ;
LL_GPIO_SetPinMode ( NRF_IRQ_GPIO_Port , NRF_IRQ_Pin , LL_GPIO_MODE_INPUT ) ;
// set up SPI
LL_SPI_Disable ( NRF_SPI ) ;
{
LL_SPI_SetBaudRatePrescaler ( NRF_SPI , LL_SPI_BAUDRATEPRESCALER_DIV32 ) ;
@ -97,11 +101,19 @@ bool iface_nordic_init(void)
}
LL_SPI_Enable ( NRF_SPI ) ;
// reset the radio / enable its power supply
NRF_Reset ( 1 ) ;
LL_mDelay ( 5 ) ;
NRF_Reset ( 0 ) ;
dbg ( " configure nrf module " ) ;
// Now configure the radio
NRF_Init ( NRF_SPEED_2M ) ; // TODO configurable speed
if ( ! NRF_Init ( NRF_SPEED_2M ) ) { // TODO configurable speed - also maybe better to use slower
dbg ( " --- NRF not present! " ) ;
return false ;
}
NRF_SetChannel ( SystemSettings . nrf_channel ) ;
NRF_SetBaseAddress ( SystemSettings . nrf_network ) ;
NRF_SetRxAddress ( RX_PIPE_NUM , SystemSettings . nrf_address ) ;
@ -133,6 +145,7 @@ void iface_nordic_deinit(void)
hw_deinit_pin_rsc ( NRF_R_NSS ) ;
hw_deinit_pin_rsc ( NRF_R_CE ) ;
hw_deinit_pin_rsc ( NRF_R_IRQ ) ;
hw_deinit_pin_rsc ( NRF_R_RST ) ;
}
// FIXME
@ -173,3 +186,5 @@ void iface_nordic_transmit(const uint8_t *buff, uint32_t len)
// give when it's done
xSemaphoreGive ( semVcomTxReadyHandle ) ; // similar to how it's done in USB - this is called in the Tx Done handler
}
# endif // SUPPORT_NRF