ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
ci24r1.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef __FW_CI24R1_H__
16#define __FW_CI24R1_H__
17
18#include "fw_hal.h"
19#include "string.h"
20
21#define CI24R1_PLOAD_WIDTH 16 // Payload width, 0:dynamic, [1,32]:fixed
22
23#define CI24R1_CSN P35
24#define CI24R1_MOSI P34
25#define CI24R1_SCK P32
26
27#define CI24R1_DATA_OUT() GPIO_P3_SetMode(GPIO_Pin_4, GPIO_Mode_Output_PP)
28#define CI24R1_DATA_IN() GPIO_P3_SetMode(GPIO_Pin_4, GPIO_Mode_Input_HIP)
29#define CI24R1_DATA_LOW() CI24R1_MOSI = 0
30#define CI24R1_DATA_HIGH() CI24R1_MOSI = 1
31#define CI24R1_DATA_READ() CI24R1_MOSI
32
33#define CI24R1_CLK_LOW() CI24R1_SCK = 0
34#define CI24R1_CLK_HIGH() CI24R1_SCK = 1
35
36#define CI24R1_NSS_LOW() CI24R1_CSN = 0
37#define CI24R1_NSS_HIGH() CI24R1_CSN = 1
38
39#define CI24R1_CE_LOW() CI24R1_WriteReg(CI24R1_CMD_CE_OFF, CI24R1_CMD_NOP)
40#define CI24R1_CE_HIGH() CI24R1_WriteReg(CI24R1_CMD_CE_ON, CI24R1_CMD_NOP)
41
45/****************** CMD REGISTER ********************/
46#define CI24R1_CMD_R_REGISTER 0x00 // [000A AAAA] Register read
47#define CI24R1_CMD_W_REGISTER 0x20 // [001A AAAA] Register write
48#define CI24R1_CMD_R_RX_PAYLOAD 0x61 // Read RX payload
49#define CI24R1_CMD_W_TX_PAYLOAD 0xA0 // Write TX payload
50#define CI24R1_CMD_FLUSH_TX 0xE1 // Flush TX FIFO
51#define CI24R1_CMD_FLUSH_RX 0xE2 // Flush RX FIFO
52#define CI24R1_CMD_REUSE_TX_PL 0xE3 // Reuse TX Payload
53#define CI24R1_CMD_R_RX_PL_WID 0x60 // Read width of RX data
54#define CI24R1_CMD_W_ACK_PAYLOAD 0xA8 // Data with ACK
55#define CI24R1_CMD_W_TX_PAYLOAD_NOACK 0xB0 // TX Payload no ACK Request
56#define CI24R1_CMD_NOP 0xFF // No operation (used for reading status register)
57#define CI24R1_CMD_CE_ON 0x70 // CE high
58#define CI24R1_CMD_CE_OFF 0x71 // CE low
59#define CI24R1_CMD_SELSPI 0x74 // DATA pin as SPI
60#define CI24R1_CMD_SELIRQ 0x75 // DATA pin as IRQ
61
62/******************CONTROL REGISTER ******************/
63#define CI24R1_REG_CONFIG 0x00 // Configuration register
64#define CI24R1_REG_EN_AA 0x01 // Enable "Auto acknowledgment"
65#define CI24R1_REG_EN_RXADDR 0x02 // Enable RX addresses
66#define CI24R1_REG_SETUP_AW 0x03 // Setup of address widths
67#define CI24R1_REG_SETUP_RETR 0x04 // Setup of automatic re-transmit
68#define CI24R1_REG_RF_CH 0x05 // RF channel, [0,6] -> 0~125 -> 2400~2525 MHz
69#define CI24R1_REG_RF_SETUP 0x06 // RF setup
70#define CI24R1_REG_STATUS 0x07 // Status
71#define CI24R1_REG_OBSERVE_TX 0x08 // Transmit observe register
72#define CI24R1_REG_RSSI 0x09 // Data output and RSSI
73#define CI24R1_REG_RX_ADDR_P0 0x0A // Receive address data pipe 0, 40 bits
74#define CI24R1_REG_RX_ADDR_P1 0x0B // Receive address data pipe 1, 40 bits
75#define CI24R1_REG_RX_ADDR_P2 0x0C // Receive address data pipe 2
76#define CI24R1_REG_RX_ADDR_P3 0x0D // Receive address data pipe 3
77#define CI24R1_REG_RX_ADDR_P4 0x0E // Receive address data pipe 4
78#define CI24R1_REG_RX_ADDR_P5AF 0x0F // Receive address data pipe 5 and other settings
79 // 0x0F can be switched to different function registers
80 // according 0x06(CI24R1_REG_RF_SETUP) bit [0,2], defined
81 // by CI24R1_EN_RXADDR_xxx
82
83#define CI24R1_REG_TX_ADDR 0x10 // Transmit address, 40 bits
84#define CI24R1_REG_RX_PW_P0 0x11 // Length of RX payload of pipe 0, set to 0 will stop receiving
85#define CI24R1_REG_RX_PW_P1 0x12 // Length of RX payload of pipe 1
86#define CI24R1_REG_RX_PW_P2 0x13 // Length of RX payload of pipe 2
87#define CI24R1_REG_RX_PW_P3 0x14 // Length of RX payload of pipe 3
88#define CI24R1_REG_RX_PW_P4 0x15 // Length of RX payload of pipe 4
89#define CI24R1_REG_RX_PW_P5 0x16 // Length of RX payload of pipe 5
90#define CI24R1_REG_FIFO_STATUS 0x17 // FIFO status
91#define CI24R1_REG_DYNPD 0x1C // Enable dynamic payload length
92#define CI24R1_REG_FEATURE 0x1D // Feature config
93
94/**************************** CONFIGs ************************************/
95
96#define CI24R1_EN_RXADDR_P5 0x00 // [0,1]->EN_AA[6,7], [2,3]->EN_RXADDR[6,7]
97#define CI24R1_EN_RXADDR_CRC 0x01
98#define CI24R1_EN_RXADDR_OSC_C 0x02
99#define CI24R1_EN_RXADDR_BT 0x04
100#define CI24R1_EN_RXADDR_BT_CRC_L 0x06
101#define CI24R1_EN_RXADDR_BT_CRC_M 0x07
102#define CI24R1_EN_RXADDR_BT_CRC_H 0x08
103
104#define CI24R1_RF_SETUP_11DB 0x07
105#define CI24R1_RF_SETUP_10DB 0x06
106#define CI24R1_RF_SETUP_9DB 0x05
107#define CI24R1_RF_SETUP_7DB 0x04
108#define CI24R1_RF_SETUP_3DB 0x03
109#define CI24R1_RF_SETUP__1DB 0x02
110#define CI24R1_RF_SETUP__4DB 0x01
111#define CI24R1_RF_SETUP__9DB 0x00
112
113#define CI24R1_RF_SETUP_250K 0x20
114#define CI24R1_RF_SETUP_1M 0x00
115#define CI24R1_RF_SETUP_2M 0x08
116
117
118#define CI24R1_FLAG_RX_READY 0x40 // RX_DR bit (data ready RX FIFO interrupt)
119#define CI24R1_FLAG_TX_SENT 0x20 // TX_DS bit (data sent TX FIFO interrupt)
120#define CI24R1_FLAG_MAX_RT 0x10 // MAX_RT bit (maximum number of TX re-transmits interrupt)
121
122#define CI24R1_PLOAD_MAX_WIDTH 32 // Max payload width
123#define CI24R1_TEST_ADDR "CI24R"
124
125/******************* FUNCTION DECLARE *******************/
128
129void CI24R1_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len);
130void CI24R1_ReadToBuf(uint8_t reg, uint8_t *pBuf, uint8_t len);
131
133
134void CI24R1_Init(void);
135void CI24R1_SetChannel(uint8_t channel);
136
137void CI24R1_SetTxAddress(uint8_t *address);
138void CI24R1_SetRxAddress(uint8_t *address);
139
140void CI24R1_SetTxMode(void);
141void CI24R1_SetRxMode(void);
142
143uint8_t CI24R1_Tx(uint8_t *ucPayload, uint8_t length);
144uint8_t CI24R1_Rx(void);
145
148
149#endif
value
Definition: DS18B20_ATY.c:216
uint8_t CI24R1_ReadStatus(void)
Definition: ci24r1.c:249
void CI24R1_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len)
Definition: ci24r1.c:91
void CI24R1_SetTxAddress(uint8_t *address)
Definition: ci24r1.c:146
uint8_t CI24R1_ReadReg(uint8_t reg)
Definition: ci24r1.c:74
void CI24R1_SetChannel(uint8_t channel)
Definition: ci24r1.c:157
void CI24R1_SetTxMode(void)
Definition: ci24r1.c:116
void CI24R1_WriteReg(uint8_t reg, uint8_t value)
Definition: ci24r1.c:66
uint8_t CI24R1_Tx(uint8_t *ucPayload, uint8_t length)
Definition: ci24r1.c:193
void CI24R1_SetRxAddress(uint8_t *address)
Definition: ci24r1.c:152
void CI24R1_SetRxMode(void)
Definition: ci24r1.c:124
uint8_t CI24R1_Rx(void)
Definition: ci24r1.c:217
void CI24R1_Init(void)
Definition: ci24r1.c:163
void CI24R1_ReadToBuf(uint8_t reg, uint8_t *pBuf, uint8_t len)
Definition: ci24r1.c:103
uint8_t CI24R1_SPI_Test(void)
Definition: ci24r1.c:132
uint8_t CI24R1_PrintStatus(void)
Definition: ci24r1.c:269
unsigned char uint8_t
Definition: fw_types.h:18