| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /**
- * @author Tilen MAJERLE
- * @email tilen@majerle.eu
- * @website http://stm32f4-discovery.net
- * @link http://stm32f4-discovery.net/2015/09/hal-library-25-nrf24l01-for-stm32fxxx/
- * @version v1.0
- * @ide Keil uVision
- * @license MIT
- * @brief Library template
- *
- \verbatim
- ----------------------------------------------------------------------
- Copyright (c) 2016 Tilen MAJERLE
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- ----------------------------------------------------------------------
- \endverbatim
- */
- /**
- * @defgroup TM_NRF24L01P
- * @brief nRF24L01+ library for STM32xxx devices - http://stm32f4-discovery.net/2015/09/hal-library-25-nrf24l01-for-stm32fxxx/
- * @{
- *
- * This library allows you to work with nRF24L01+ modules.
- *
- * You can send and receive data from nRF24L01+ modules.
- *
- * \par Default pinout
- *
- \verbatim
- NRF24L01+ DESCRIPTION
- GND Ground
- VCC 3.3V
- CE RF activated pin
- CSN Chip select pin for SPI
- SCK SCK pin for SPI
- MOSI MOSI pin for SPI
- MISO MISO pin for SPI
- IRQ Not used. Interrupt pin. Goes low when active. Pin functionality is active, but not used in library
- \endverbatim
- *
- * IRQ pin is not used in this library, but its functionality is enabled by this software.
- *
- * You can still set any pin on Fxxx to be an external interrupt and handle interrupts from nRF24L01+ module.
- *
- * The easiest way to that is to use @ref TM_EXTI library and attach interrupt functionality to this pin
- *
- * \par Custom pinout
- *
- * Add lines below in your defines.h file if you want to change default pinout:
- */
- #ifndef _NRF_24L01_H_
- #define _NRF_24L01_H_
- #if defined(STM32F401xC) || defined(STM32F401xE)
- #include "stm32f4xx_hal.h"
- #endif
- #if defined (STM32L432xx)
- #include "stm32l4xx_hal.h"
- #endif
- #include "nrf24l01_defines.h"
- #include "nrfManager.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- class Nrf24L01 {
- protected:
- NRF24L01_Conig_t nrf_config;
- NrfManager *_nrfManager;
- GPIO_TypeDef *_cs_port;
- GPIO_TypeDef *_ce_port;
- uint16_t _ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
- uint16_t _cs_pin; /**< SPI Chip select */
- uint32_t spi_speed; /**< SPI Bus Speed */
- uint8_t status; /** The status byte returned from every SPI transaction */
- uint8_t _payload_size; /**< Fixed size of payloads */
- uint8_t _channel;
- public:
- Nrf24L01(uint8_t channel, NrfManager *nrf_manager, GPIO_TypeDef *port_cs, uint16_t pin_cs, GPIO_TypeDef *port_ce, uint16_t pin_ce);
- void SetMyAddress(uint8_t* adr);
- void SetTxAddress(uint8_t* adr);
- uint8_t GetRetransmissionsCount(void);
- void PowerUpTx(void);
- void PowerUpRx(void);
- void PowerDown(void);
- Transmit_Status_t GetTransmissionStatus(void);
- void Transmit(uint8_t *data);
- uint8_t DataReady(void);
- void GetData(uint8_t *data);
- void SetChannel(uint8_t channel);
- void SetRF(NRF_DataRate_t DataRate, NRF_OutputPower_t OutPwr);
- uint8_t GetStatus(void);
- uint8_t Read_Interrupts(NRF_IRQ_t* IRQ);
- void Clear_Interrupts(void);
- private:
- uint8_t _buffer[8];
- uint8_t init();
- void initPins(void);
- void softwareReset(void);
- void writeRegister(uint8_t reg, uint8_t value);
- void writeBit(uint8_t reg, uint8_t bit, uint8_t value);
- uint8_t readBit(uint8_t reg, uint8_t bit);
- uint8_t readRegister(uint8_t reg);
- void readRegisterMulti(uint8_t reg, uint8_t* data, uint8_t count);
- void writeRegisterMulti(uint8_t reg, uint8_t *data, uint8_t count);
- uint8_t rxFifoEmpty(void);
- };
- #ifdef __cplusplus
- }
- #endif
- #endif /* _NRF_24L01_H_ */
|