esp_phy.h
Go to the documentation of this file.
1 /*
2  Adapted from Arduino for Sming.
3  Original copyright note is kept below.
4 
5  phy.c - ESP8266 PHY initialization data
6  Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
7  This file is part of the esp8266 core for Arduino environment.
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <esp_attr.h>
22 #include <sys/pgmspace.h>
23 #include <string.h>
24 
33 struct PhyInitData {
37  using txpwr_index_t = uint8_t;
38 
39  uint8_t* data; // [128]
40 
44  uint8_t get_version() const
45  {
46  return data[1];
47  }
48 
63  {
64  }
65 
74  {
75  data[78] = 2; // Enable bytes 30-33 to set maximum TX power
76  data[30] = chan1;
77  data[31] = chan11;
78  data[32] = chan13;
79  data[33] = chan14;
80  }
81 
86  {
87  data[78] = 0; // disable bytes 30-33
88  }
89 
107  void set_txpwr_dqb(txpwr_index_t level, uint8_t value)
108  {
109  if(level < 6) {
110  data[34 + level] = value;
111  }
112  }
113 
129  void set_txpwr(uint8_t mcs_index, txpwr_index_t txpwr_qdb)
130  {
131  if(mcs_index < 8 && txpwr_qdb < 6) {
132  data[40 + mcs_index] = txpwr_qdb;
133  }
134  }
135 
143  void set_crystal_freq(uint8_t value = 1)
144  {
145  data[48] = value;
146  }
147 
155  void set_sdio_configure(uint8_t value = 0)
156  {
157  data[50] = value;
158  }
159 
176  void set_bt_configure(uint8_t value = 0)
177  {
178  data[51] = value;
179  }
180 
191  void set_bt_protocol(uint8_t value = 0)
192  {
193  data[52] = value;
194  }
195 
204  void set_dual_ant_configure(uint8_t value = 0)
205  {
206  data[53] = value;
207  }
208 
218  void set_share_xtal(uint8_t value = 0)
219  {
220  data[55] = value;
221  }
222 
240  {
241  }
242 
249  void set_low_power_en(uint8_t value = 0)
250  {
251  data[93] = value;
252  }
253 
266  void set_lp_rf_stg10(uint8_t value = 0)
267  {
268  data[94] = value;
269  }
270 
285  void set_lp_bb_att_ext(uint8_t value = 0)
286  {
287  data[95] = value;
288  }
289 
295  {
296  data[96] = 0;
297  }
298 
304  void set_power_limits_11b(txpwr_index_t txpwr_index_11b_0, txpwr_index_t txpwr_index_11b_1)
305  {
306  data[96] = 1;
307  data[97] = txpwr_index_11b_0;
308  data[98] = txpwr_index_11b_1;
309  }
310 
333  void set_vdd33_const(uint8_t value = 33)
334  {
335  data[107] = value;
336  }
337 
345  void set_rf_cal_disable(uint8_t value = 0)
346  {
347  data[108] = value;
348  }
349 
371  void set_freq_correct(uint8_t bbpll = 3, int8_t force_freq_offset = 0)
372  {
373  data[112] = bbpll;
374  data[113] = uint8_t(force_freq_offset);
375  }
376 
388  void set_rf_calibration(uint8_t value = 1)
389  {
390  data[114] = value;
391  }
392 };
393 
394 extern void customPhyInit(PhyInitData data);
void customPhyInit(PhyInitData data)
Structure to manage low-level adjustment of PHY data Does not contain the data but a reference to it....
Definition: esp_phy.h:33
void set_lp_bb_att_ext(uint8_t value=0)
Set attenuation of BB gain.
Definition: esp_phy.h:285
void undocumented_26_29()
Ordinal 26-29.
Definition: esp_phy.h:62
void set_txpwr(uint8_t mcs_index, txpwr_index_t txpwr_qdb)
Select target power level for specific data rate according to Modulation Coding Scheme (MCS)
Definition: esp_phy.h:129
void set_power_limits_11b(txpwr_index_t txpwr_index_11b_0, txpwr_index_t txpwr_index_11b_1)
Configure 802.11b power limits.
Definition: esp_phy.h:304
uint8_t get_version() const
PHY data version number. Currently version 8.
Definition: esp_phy.h:44
void set_crystal_freq(uint8_t value=1)
Select crystal frequency.
Definition: esp_phy.h:143
void set_freq_correct(uint8_t bbpll=3, int8_t force_freq_offset=0)
Enable frequency correction.
Definition: esp_phy.h:371
void set_power_limits(txpwr_index_t chan1, txpwr_index_t chan11, txpwr_index_t chan13, txpwr_index_t chan14)
Configure the maximum TX powers for channels 1, 11, 13 and 14.
Definition: esp_phy.h:73
void set_txpwr_dqb(txpwr_index_t level, uint8_t value)
Set TX power level. TX power can be switched between six levels. Level 0 represents the maximum TX po...
Definition: esp_phy.h:107
void set_dual_ant_configure(uint8_t value=0)
Configure dual antenna arrangement.
Definition: esp_phy.h:204
void set_bt_protocol(uint8_t value=0)
Configure Bluetooth protocol.
Definition: esp_phy.h:191
void set_sdio_configure(uint8_t value=0)
Configure SDIO behaviour.
Definition: esp_phy.h:155
void set_rf_cal_disable(uint8_t value=0)
Disable RF calibration for certain number of times.
Definition: esp_phy.h:345
void set_vdd33_const(uint8_t value=33)
Set PA_VDD voltage.
Definition: esp_phy.h:333
void set_default_power_limits_11b()
Set power limits for 802.11b to default, which is same as MCS0 and 6Mbits/s modes....
Definition: esp_phy.h:294
void set_low_power_en(uint8_t value=0)
Configure low-power mode.
Definition: esp_phy.h:249
uint8_t * data
Definition: esp_phy.h:39
void disable_power_limits()
Disable power limits on channels 1, 11, 13 and 14.
Definition: esp_phy.h:85
void undocumented_64_73()
Ordinal 64-73.
Definition: esp_phy.h:239
uint8_t txpwr_index_t
Index for configurable power level, from 0-5. See PhyInitData::set_txpwr_dqb.
Definition: esp_phy.h:37
void set_lp_rf_stg10(uint8_t value=0)
Set attenuation of RF gain stage 0 and 1.
Definition: esp_phy.h:266
void set_rf_calibration(uint8_t value=1)
RF_calibration.
Definition: esp_phy.h:388
void set_share_xtal(uint8_t value=0)
Set Crystal state during sleep mode This option is to share crystal clock for BT.
Definition: esp_phy.h:218
void set_bt_configure(uint8_t value=0)
Configure bluetooth.
Definition: esp_phy.h:176