Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00022 #ifndef HAL_W2_H__
00023 #define HAL_W2_H__
00024
00025 #include <stdint.h>
00026 #include <stdbool.h>
00027 #include "nrf24le1.h"
00028
00029 #define W2CON0_FLAG_X_STOP 0x20
00030 #define W2CON0_FLAG_X_START 0x10
00031
00032 #define W2CON1_FLAG_NACK 0x02
00033 #define W2CON1_FLAG_DATA_READY 0x01
00034
00035 #define HAL_W2_ISSUE_START_COND (W2CON0 |= W2CON0_FLAG_X_START)
00036 #define HAL_W2_ISSUE_STOP_COND (W2CON0 |= W2CON0_FLAG_X_STOP)
00037 #define HAL_W2_WAIT_FOR_INTERRUPT {while(!SPIF); SPIF = 0; }
00038 #define HAL_W2_WRITE(a) W2DAT = (a)
00039 #define HAL_W2_READ() W2DAT
00040
00041 #if defined(NRF24LE1_48)
00042 #define W2_PIN_SDA P13
00043 #define W2_PIN_SCL P12
00044 #define HAL_W2_CLEAR_SDA_SCL (P1 &= 0xF3)
00045 #define HAL_W2_OVERRIDE_SDA_SCL(a, b) P1DIR = (P1DIR & 0xF3) | (a << 3) | (b << 2)
00046 #elif defined(NRF24LE1_32)
00047 #define W2_PIN_SDA P05
00048 #define W2_PIN_SCL P04
00049 #define HAL_W2_CLEAR_SDA_SCL (P0 &= 0xCF)
00050 #define HAL_W2_OVERRIDE_SDA_SCL(a, b) P0DIR = (P0DIR & 0xCF) | (a << 5) | (b << 4)
00051 #elif defined(NRF24LE1_24)
00052 #define W2_PIN_SDA P06
00053 #define W2_PIN_SCL P05
00054 #define HAL_W2_CLEAR_SDA_SCL (P0 &= 0x9F)
00055 #define HAL_W2_OVERRIDE_SDA_SCL(a, b) P0DIR = (P0DIR & 0x9F) | (a << 6) | (b << 5)
00056 #else
00057 #warning "LE1 package type not defined! Add project wide definition depending on the LE1 package variant you are using. Valid options are NRF24LE1_48, NRF24LE1_32 and NRF24LE1_24."
00058 #define W2_SOFT_RESET_NOT_AVAILABLE
00059 #endif
00060
00064 typedef enum {
00065 HAL_W2_IDLE = 0x00,
00066 HAL_W2_100KHZ = 0x01,
00067 HAL_W2_400KHZ = 0x02
00068 } hal_w2_clk_freq_t;
00069
00073 typedef enum {
00074 HAL_W2_MASTER,
00075 HAL_W2_SLAVE
00076 } hal_w2_op_mode_t;
00077
00081 typedef enum {
00082 HAL_W2_STOP_COND = 0x08,
00083 HAL_W2_ADRESS_MATCH = 0x04,
00084 HAL_W2_DATA_READY = 0x01
00085 } hal_w2_irq_source_t;
00086
00090 typedef enum {
00091 HAL_W2_DIR_WRITE,
00092 HAL_W2_DIR_READ
00093 } hal_w2_direction_t;
00094
00095
00098
00099
00107 void hal_w2_respond_to_gen_adr(bool resp_gen);
00108
00113 void hal_w2_alter_clock(bool alt_clk);
00114
00121 void hal_w2_irq_stop_cond_enable(bool stop_cond);
00122
00129 void hal_w2_irq_adr_match_enable(bool addr_match);
00130
00136 void hal_w2_set_slave_address(uint8_t address);
00138
00140
00146 void hal_w2_set_clk_freq(hal_w2_clk_freq_t freq);
00147
00153 void hal_w2_set_op_mode(hal_w2_op_mode_t mode);
00154
00161 void hal_w2_enable(bool en);
00162
00168 void hal_w2_all_irq_enable(bool irq);
00169
00170 void hal_w2_configure_master(hal_w2_clk_freq_t mode);
00171
00172 bool hal_w2_init_transfer(uint8_t address, hal_w2_direction_t direction);
00173
00174 bool hal_w2_write(uint8_t address, const uint8_t *data_ptr, uint8_t data_len);
00175 bool hal_w2_read(uint8_t address, uint8_t *buffer, uint8_t buffer_size);
00176
00177 #endif // HAL_W2_H__
00178