⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_nrf.h

📁 NRf24l01 代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 * $LastChangedRevision: 2132 $
 */ 

/** @file
 * Interface for nRF HAL
 * @defgroup nordic_hal_nrf nRF HAL
 * @{
 * @ingroup nordic_hal
 * HAL interface for Nordic Semiconductor's radio chip.
 */

#ifndef HAL_NRF_H__
#define HAL_NRF_H__

#include <stdint.h>
#include <stdbool.h>

#include "hal_nrf_reg.h"
#include "hal_nrf_hw.h"


/** @name  << SETUP FUNCTIONS >> */
//@{
/* Setup function prototypes */

/** Enable or disable interrupt for radio.
 * Use this function to enable or disable
 * one of the interrupt sources for the radio.
 * This function only changes state for selected
 * int_type, the rest of the interrupt sources
 * are left unchanged.
 *
 * @param int_source Radio interrupt Source.
 * @param irq_state Enable or Disable.
*/
void hal_nrf_set_irq_mode(hal_nrf_irq_source_t int_source, bool irq_state);

/** Activate features
 * Sends the ACTIVATE command to the RF tranceiver. By calling this function
 * once it is possible to use the functions related to the FEATURE register.  
 */
void hal_nrf_lock_unlock(void);

/** Enables the ACK payload feature
 */
void hal_nrf_enable_ack_pl(void);

/** Disables the ACK payload feature
 */
void hal_nrf_disable_ack_pl(void);

/** Enables the dynamic payload feature
 */
void hal_nrf_enable_dynamic_pl(void);

/** Disables the dynamic payload feature
 */
void hal_nrf_disable_dynamic_pl(void);

/** Sets the dynamic payload features for the RX pipes
* The input parameter contains is a byte where the bit values tells weather the
*  pipe uses the ack payload feature or not. For example if bit 0 is set then 
* Pipe 0 uses ack payload,
 * @param setup Byte value with bit set for pipes that uses the dynamic payload feature
 */
void hal_nrf_setup_dyn_pl(uint8_t setup);

/** Reads the payload width of the received ack payload
 * @return Payload width of the received ack payload
 */
uint8_t hal_nrf_read_rx_pl_w(void);

/** Write ack payload
 * Writes the payload that will be transmitted with the ack on the given pipe.
 * @param pipe Pipe that transmits the payload
 * @param tx_pload Pointer to the payload data
 * @param length Size of the data to transmit
 */
void hal_nrf_write_ack_pload(uint8_t pipe, uint8_t *tx_pload, uint8_t length);

/** Enables the no-ack feature
 */
void hal_nrf_enable_dynamic_ack(void);

/** Disables the no-ack feature
 */
void hal_nrf_disable_dynamic_ack(void);

/** Read then clears all interrupt flags.
 * Use this function to get the interrupt flags and clear them in the same operation.
 * Reduced radio interface activity and speed optimized.
 *
 * @return  Interrupt_flags
 * @retval 0x10 Max Retransmit interrupt
 * @retval 0x20 TX Data sent interrupt
 * @retval 0x40 RX Data received interrupt
*/
uint8_t hal_nrf_get_clear_irq_flags(void);

/** Clear one selected interrupt flag.
 * Use this function to clear one @a spesific interrupt flag.
 * Other interrupt flags are left unchanged.
 *
 * @param int_source Interrupt source of which flag to clear
*/
void hal_nrf_clear_irq_flag(hal_nrf_irq_source_t int_source);

/** Set the CRC mode used by the radio.
 * Use this function to set the CRC mode; CRC disabled, 1 or 2 bytes.
 *
 * @param crc_mode CRC mode to use
*/
void hal_nrf_set_crc_mode(hal_nrf_crc_mode_t crc_mode);

/** Open radio pipe(s) and enable/ disable auto acknowledge.
 * Use this function to open one or all pipes,
 * with or without auto acknowledge.
 *
 * @param pipe_num Radio pipe to open
 * @param auto_ack Auto_Ack ON/OFF
 * @see hal_nrf_address
*/
void hal_nrf_open_pipe(hal_nrf_address_t pipe_num, bool auto_ack);

/** Close radio pipe(s).
 * Use this function to close one pipe or all pipes.
 *
 * @param pipe_num Pipe# number to close
*/
void hal_nrf_close_pipe(hal_nrf_address_t pipe_num);

/** Set radio's RX address and TX address.
 * Use this function to set a RX address, or to set the TX address.
 * Beware of the difference for single and multibyte address registers.
 *
 * @param address Which address to set
 * @param *addr Buffer from which the address is stored in
*/
void hal_nrf_set_address(hal_nrf_address_t address, uint8_t *addr);

/** Set auto acknowledge parameters.
 * Use this function to set retransmit and retransmit delay
 * parameters.
 *
 * @param retr Number of retransmit, 0 equ retransmit OFF
 * @param delay Retransmit delay in 祍
*/
void hal_nrf_set_auto_retr(uint8_t retr, uint16_t delay);

/** Set radio's address width.
 * Use this function to define the radio's address width,
 * referes to both RX and TX.
 *
 * @param address_width Address with in bytes
*/
void hal_nrf_set_address_width(hal_nrf_address_width_t address_width);

/** Set payload width for selected pipe.
 * Use this function to set the number of bytes expected
 * on a selected pipe.
 *
 * @param pipe_num Pipe number to set payload width for
 * @param pload_width number of bytes expected
*/
void hal_nrf_set_rx_pload_width(uint8_t pipe_num, uint8_t pload_width);

/** Read current interrupt mode for selected interrupt source.
 * Use this function to get the interrupt source's mode,
 * either enabled or disabled.
 *
 * @param int_source Interrupt source to get mode from
 *
 * @return Interrupt Mode
 * @retval FALSE Interrupt disabled
 * @retval TRUE Interrupt enabled
*/
bool hal_nrf_get_irq_mode(uint8_t int_source);

/** Read all interrupt flags.
 * Use this function to get the interrupt flags. This function is similar
 * to hal_nrf_get_clear_irq_flags with the exception that it does <I><B>NOT</B></I> clear
 * the irq_flags.
 *
 * @return Interrupt_flags
 * @retval 0x10 Max Retransmit interrupt
 * @retval 0x20 TX Data sent interrupt
 * @retval 0x40 RX Data received interrupt
*/
uint8_t hal_nrf_get_irq_flags(void);

/** Get CRC mode.
 * Use this function to check which CRC mode is used.
 *
 * @return CRC_mode
 * @retval 0x00 CRC_OFF
 * @retval 0x02 CRC_8BIT
 * @retval 0x03 CRC_16BIT
*/
uint8_t hal_nrf_get_crc_mode(void);

/** Get pipe status.
 * Use this function to check status for a selected pipe.
 *
 * @param  pipe_num Pipe number to check status for
 *
 * @return Pipe_Status
 * @retval 0x00 Pipe is closed, autoack disabled
 * @retval 0x01 Pipe is open, autoack disabled
 * @retval 0x03 Pipe is open, autoack enabled
*/
uint8_t hal_nrf_get_pipe_status(uint8_t pipe_num);

/** Get address for selected pipe.
 * Use this function to get address for selected pipe.
 *
 *
 * @param address Which address to get, Pipe- or TX-address
 * @param *addr buffer in which address bytes are written.
 * <BR><BR>For pipes containing only LSB byte of address, this byte is returned
 * in the<BR> *addr buffer.
 *
 * @return Address_Width in bytes
*/
uint8_t hal_nrf_get_address(uint8_t address, uint8_t *addr);

/** Get auto retransmit parameters.
 * Use this function to get the auto retransmit parameters,
 * retrans count and retrans delay.
 *
 * @return AutoRetrans Parameters
 *
 * @retval UpperNibble Retransmit Delay
 * @retval LowerNibble Retransmit Count
*/
uint8_t hal_nrf_get_auto_retr_status(void);

/** Get packet lost counter
 * Use this function to get the packet(s) counter.
 *
 * @return packet lost counter
*/
uint8_t hal_nrf_get_packet_lost_ctr(void);

/** Get address width for radio.
 * Use this function to get the address width used for
 * the radio, both RX and TX.
 *
 * @return Address_Width in bytes
*/
uint8_t hal_nrf_get_address_width(void);

/** Get RX payload width for selected pipe.
 * Use this function to get the expected payload
 * width for selected ppe number.
 *
 * @param pipe_num Pipe number to get payload width for
 *
 * @return Payload_Width in bytes
*/
uint8_t hal_nrf_get_rx_pload_width(uint8_t pipe_num);
//@}

/** @name  << OPERATION FUNCTIONS >> */
//@{
/* Operation function prototypes */

/** Set radio's operation mode.
 * Use this function to enter PTX (primary TX)
 * or PRX (primary RX).
 *
 * @param op_mode Operation mode
*/
void hal_nrf_set_operation_mode(hal_nrf_operation_mode_t op_mode);

/** Set radio's power mode.
 * Use this function to power_up or power_down radio.
 *
 * @param pwr_mode POWER_UP or POWER_DOWN
*/
void hal_nrf_set_power_mode(hal_nrf_pwr_mode_t pwr_mode);

/** Set radio's RF channel.
 * Use this function to select which RF channel to use.
 *
 * @param channel RF channel
*/
void hal_nrf_set_rf_channel(uint8_t channel);

/** Set radio's TX output power.
 * Use this function set the radio's TX output power.
 *
 * @param power Radio's TX output power
*/
void hal_nrf_set_output_power(hal_nrf_output_power_t power);

/** Set radio's on-air datarate.
 * Use this function to select radio's on-air
 * datarate.
 *
 * @param datarate On-air datarate
*/
void hal_nrf_set_datarate(hal_nrf_datarate_t datarate);

/** Get radio's current operation mode.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -