summaryrefslogtreecommitdiff
path: root/lib/cc1101.h
blob: 82cd1096fbe8df809a4b54abf857d46865f888f7 (plain) (blame)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 *  spreadspace avr utils
 *
 *
 *  Copyright (C) 2013-2018 Christian Pointner <equinox@spreadspace.org>
 *
 *  This file is part of spreadspace avr utils.
 *
 *  spreadspace avr utils is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  spreadspace avr utils is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SPREADAVR_cc1101_h_INCLUDED
#define SPREADAVR_cc1101_h_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

typedef enum { unknown, sleep, idle, xoff, mancal, fs_wakeup, calibrate, settling, rx, txrx_settling,
               rxfifo_overflow, fstxon, tx, rxtx_settling, txfifo_underflow } cc1101_state_t;
char* cc1101_state_to_string(cc1101_state_t);

#define CC1101_FREQ_CORR(xtal) ((float)(xtal/65536.0))

typedef struct {
  void (*spi_cs_enable)(void);
  void (*spi_cs_disable)(void);
  uint8_t (*spi_read_miso)(void);
  void (*spi_write_byte)(const uint8_t);
  uint8_t (*spi_read_byte)(void);
  uint8_t (*spi_transfer_byte)(const uint8_t);
  float freq_corr;
} cc1101_driver_conf_t;

// high level interface

void cc1101_init(cc1101_driver_conf_t conf);
void cc1101_reg_init(void);
void cc1101_soft_reset(void);

void cc1101_powerdown(void);
void cc1101_idle(void);
void cc1101_osc_off(void);
void cc1101_calibrate(void);
void cc1101_fasttxon(void);
void cc1101_rx(void);
void cc1101_tx(void);
void cc1101_reset_rx_fifo(void);
void cc1101_reset_tx_fifo(void);
cc1101_state_t cc1101_get_state(void);

uint32_t cc1101_get_freq_hz(void);
void cc1101_set_freq_hz(uint32_t hz);

// normalized register access

uint8_t cc1101_get_iocfg0(void);
void cc1101_set_iocfg0(uint8_t iocfg);
uint8_t cc1101_get_iocfg1(void);
void cc1101_set_iocfg1(uint8_t iocfg);
uint8_t cc1101_get_iocfg2(void);
void cc1101_set_iocfg2(uint8_t iocfg);

uint8_t cc1101_get_fifothr(void);
void cc1101_set_fifothr(uint8_t fifothr);

uint16_t cc1101_get_sync(void);
void cc1101_set_sync(uint16_t sync);
uint8_t cc1101_get_pktlen(void);
void cc1101_set_pktlen(uint8_t len);
uint16_t cc1101_get_pktctrl(void);
void cc1101_set_pktctrl(uint16_t ctrl);
uint8_t cc1101_get_addr(void);
void cc1101_set_addr(uint8_t addr);

uint8_t cc1101_get_channr(void);
void cc1101_set_channr(uint8_t nr);
uint8_t cc1101_get_iffreq(void);
void cc1101_set_iffreq(uint8_t iffreq);
uint8_t cc1101_get_freq_offset(void);
void cc1101_set_freq_offset(uint8_t freqoff);
uint32_t cc1101_get_freq(void);
void cc1101_set_freq(uint32_t freq);
uint32_t cc1101_get_modemcfg(void);
void cc1101_set_modemcfg(uint32_t cfg);
uint16_t cc1101_get_drate_bw(void);
void cc1101_set_drate_bw(uint16_t cfg);
uint8_t cc1101_get_deviatn(void);
void cc1101_set_deviatn(uint8_t dev);

uint32_t cc1101_get_mcsm(void);
void cc1101_set_mcsm(uint32_t cfg);

uint8_t cc1101_get_foccfg(void);
void cc1101_set_foccfg(uint8_t cfg);
uint8_t cc1101_get_bscfg(void);
void cc1101_set_bscfg(uint8_t cfg);
uint32_t cc1101_get_agcctrl(void);
void cc1101_set_agcctrl(uint32_t ctrl);
uint16_t cc1101_get_worevt(void);
void cc1101_set_worevt(uint16_t timeout);
uint8_t cc1101_get_worctrl(void);
void cc1101_set_worctrl(uint8_t ctrl);

uint16_t cc1101_get_frend(void);
void cc1101_set_frend(uint16_t cfg);
uint32_t cc1101_get_fscal(void);
void cc1101_set_fscal(uint32_t cal);
uint16_t cc1101_get_rcctrl(void);
void cc1101_set_rcctrl(uint16_t ctrl);

uint8_t cc1101_get_fstest(void);
void cc1101_set_fstest(uint8_t test);
uint8_t cc1101_get_ptest(void);
void cc1101_set_ptest(uint8_t test);
uint8_t cc1101_get_agctest(void);
void cc1101_set_agctest(uint8_t test);
uint8_t cc1101_get_test0(void);
void cc1101_set_test0(uint8_t test);
uint8_t cc1101_get_test1(void);
void cc1101_set_test1(uint8_t test);
uint8_t cc1101_get_test2(void);
void cc1101_set_test2(uint8_t test);

uint8_t cc1101_get_partnum(void);
uint8_t cc1101_get_chip_version(void);
uint8_t cc1101_get_freq_offset_est(void);
uint8_t cc1101_get_lqi(void);
int8_t cc1101_get_rssi(void);
uint8_t cc1101_get_marcstate(void);
uint16_t cc1101_get_wortime(void);
uint8_t cc1101_get_pkt_status(void);
uint8_t cc1101_get_vco_vc_dac(void);
uint8_t cc1101_get_tx_bytes(void);
uint8_t cc1101_get_rx_bytes(void);
uint8_t cc1101_get_rcctrl0_status(void);
uint8_t cc1101_get_rcctrl1_status(void);

uint8_t cc1101_read_patable(uint8_t* data, const uint8_t len);
uint8_t cc1101_write_patable(const uint8_t* data, const uint8_t len);
uint8_t cc1101_read_rxfifo(uint8_t* data, const uint8_t len);
uint8_t cc1101_write_txfifo(const uint8_t* data, const uint8_t len);

void cc1101_dump_register(void);

#ifdef __cplusplus
}
#endif

#endif