-
Notifications
You must be signed in to change notification settings - Fork 0
/
CC2530ZNP.h
141 lines (104 loc) · 3.33 KB
/
CC2530ZNP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* @file CC2530ZNP.h
* @author Pham Huu Dang Nhat <[email protected]>, HLib MBoard team.
* @version 1.3
* @date 18-11-2013
* @brief This is header file for CC2530ZNP APIs.
* How to use this lib:
* - Declare CC_ns::conf_SPIParams_s, CC_ns::conf_GPIOParams_s and add SPI and GPIOs params.
* - Declare an CC2530ZNP instance.
* - Call init with params from these two structs.
* - sys_reset_hard should be called.
* - When we want to use this instance.
* + attach SPI.
* + do s.t
* + release SPI so other device can use.
*/
#ifndef _CC2530ZNP_H_
#define _CC2530ZNP_H_
#include "HA_Glb.h"
/**< ---------------------------- Definitions ------------------------------------- */
namespace CC_ns{
/**< attributes */
typedef enum {
successful,
failed,
SPI_busy
} status_t;
/**< end attributes */
/**< configurations */
typedef struct {
uint16_t baudRatePrescaler;
SPI* SPI_p;
SPI_ns::SM_device_t deviceType;
} conf_SPIParams_s;
typedef struct {
GPIO_TypeDef *resetGPIO_port;
uint16_t resetGPIO_pin;
uint32_t resetGPIO_clk;
GPIO_TypeDef *srdyGPIO_port;
uint16_t srdyGPIO_pin;
uint32_t srdyGPIO_clk;
bool mrdyGPIO_isUsed; // if it's false, no need to config other params for mrdy.
GPIO_TypeDef *mrdyGPIO_port;
uint16_t mrdyGPIO_pin;
uint32_t mrdyGPIO_clk;
} conf_GPIOParams_s;
/**< end configuration */
/**< ---------------------------- Definitions ------------------------------------- */
}
class CC2530ZNP {
public:
CC2530ZNP (void);
/**< conf (run-time) */
CC_ns::status_t init (CC_ns::conf_SPIParams_s *SPIParams_s, CC_ns::conf_GPIOParams_s *GPIOParams_s);
CC_ns::status_t SPI_reInit (void);
CC_ns::status_t GPIOs_reInit (void);
/**< command interface */
CC_ns::status_t cmd_SPI_attach (void);
CC_ns::status_t cmd_SPI_release (void);
CC_ns::status_t cmd_POLL (void);
CC_ns::status_t cmd_SREQ (uint16_t cmd, uint8_t len, uint8_t* data_p);
CC_ns::status_t cmd_AREQ (uint16_t cmd, uint8_t len, uint8_t* data_p);
uint8_t *cmd_dataBuffer_get (void){ return dataBuffer; }
uint8_t cmd_dataLen_get (void) { return dataLen; }
uint8_t *cmd_cmdBuffer_get (void) { return cmdBuffer; }
uint8_t cmd_cmdLen_get (void) { return 2; }
bool cmd_isNewMessage (void);
/**< end command interface */
/**< SYS interface */
CC_ns::status_t sys_reset_hard (void);
CC_ns::status_t sys_reset_req (void);
/**< end SYS interface */
private:
/**< conf (run-time) interface */
uint16_t baudRatePrescaler;
SPI* SPI_p;
SPI_ns::SM_device_t deviceType;
GPIO_TypeDef *resetGPIO_port;
uint16_t resetGPIO_pin;
uint32_t resetGPIO_clk;
GPIO_TypeDef *srdyGPIO_port;
uint16_t srdyGPIO_pin;
uint32_t srdyGPIO_clk;
bool mrdyGPIO_isUsed; // if it's false, no need to config other params for mrdy.
GPIO_TypeDef *mrdyGPIO_port;
uint16_t mrdyGPIO_pin;
uint32_t mrdyGPIO_clk;
/**< end conf (run-time) interface */
/**< command interface */
bool SPI_isAttached;
uint8_t dataBuffer [250];
uint8_t dataLen;
uint8_t cmdBuffer [2];
/**< end command interface */
/**< attributes */
uint8_t transportRev;
uint8_t productID;
uint8_t majorRel;
uint8_t minorRel;
uint8_t maintRel;
uint8_t errno;
/**< end attributes */
};
#endif // _CC2530ZNP_H_