Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
radio.h
00001 #include "sx12xx.h" 00002 00003 #ifdef SX127x_H 00004 #include "sx127x_lora.h" 00005 #include "sx127x_fsk.h" 00006 #endif /* SX127x_H */ 00007 00008 #define FIRST_CHIP_MENU_ROW 3 00009 #define LAST_CHIP_MENU_ROW (MAX_MENU_ROWS-5) 00010 00011 #if defined(SX128x_H) 00012 #define MAX_MENU_ROWS 16 00013 #define MAX_MENU_COLUMNS 6 00014 #elif defined(SX127x_H) 00015 #define MAX_MENU_ROWS 16 00016 #define MAX_MENU_COLUMNS 6 00017 #elif defined(SX126x_H) 00018 //#define MEMSCAN 00019 #define MAX_MENU_ROWS 17 00020 #define MAX_MENU_COLUMNS 6 00021 #elif defined(SX1265_H) 00022 #define MAX_MENU_ROWS 23 00023 #define MAX_MENU_COLUMNS 14 00024 #endif 00025 00026 #define PA_OFF_DBM -127 00027 00028 typedef enum { 00029 _READ_, 00030 _WRITE_ 00031 } action_e; 00032 00033 typedef struct { 00034 uint8_t row; 00035 uint8_t col; 00036 } pos_t; 00037 00038 #define _ITEM_VALUE 0xbb 00039 #define _ITEM_DROPDOWN 0xaa 00040 #define _ITEM_BUTTON 0xcc 00041 #define _ITEM_TOGGLE 0xdd 00042 00043 typedef enum { 00044 MENUMODE_NONE = 0, 00045 MENUMODE_ENTRY, 00046 MENUMODE_DROPDOWN, 00047 MENUMODE_REDRAW, 00048 MENUMODE_REINIT_MENU, 00049 } menuMode_e; 00050 00051 typedef struct { 00052 uint8_t itemType; 00053 00054 const char* const * printed_strs; // displayed values index from read callback return 00055 const char* const * selectable_strs; // choices 00056 00057 unsigned (*const read)(bool forWriting); 00058 menuMode_e (*const write)(unsigned); 00059 } dropdown_item_t; 00060 00061 typedef struct { 00062 uint8_t itemType; 00063 00064 unsigned width; // num columns printed 00065 00066 void (*const print)(void); 00067 bool (*const write)(const char*); // NULL for read-only. return true: redraw menu 00068 } value_item_t; 00069 00070 typedef struct { 00071 uint8_t itemType; 00072 00073 const char * const label; 00074 void (*const push)(void); 00075 } button_item_t; 00076 00077 typedef struct { 00078 uint8_t itemType; 00079 00080 const char * const label0; 00081 const char * const label1; 00082 bool (*const read)(void); 00083 bool (*const push)(void); 00084 } toggle_item_t; 00085 00086 #define FLAG_MSGTYPE_ALL 0x07 00087 #define FLAG_MSGTYPE_PKT 0x01 00088 #define FLAG_MSGTYPE_PER 0x02 00089 #define FLAG_MSGTYPE_PING 0x04 00090 00091 typedef struct { 00092 pos_t pos; // on screen position, both row & col with 1 starting value 00093 const char* const label; 00094 00095 const void* const itemPtr; 00096 00097 uint8_t flags; 00098 00099 const void* refreshReadItem; /* other item to be read after activation */ 00100 } menu_t; 00101 00102 00103 typedef struct { 00104 menuMode_e mode; 00105 uint8_t sel_idx; 00106 const menu_t* sm; 00107 uint8_t dropdown_col; 00108 } menuState_t; 00109 00110 extern menuState_t menuState; 00111 extern menu_t* menu[][MAX_MENU_COLUMNS]; 00112 extern int8_t StopMenuCols[]; 00113 00114 extern uint8_t entry_buf_idx; 00115 extern char entry_buf[]; 00116 00117 void log_printf(const char* format, ...); 00118 00119 typedef struct { 00120 unsigned hz; 00121 uint8_t bwf; 00122 } rxbw_t; 00123 00124 typedef struct 00125 { 00126 void (*const TxDone_botHalf)(void); // read irqAt for timestamp of interrupt 00127 void (*const RxDone)(uint8_t size, float rssi, float snr); // read radio.rx_buf for payload, irqAt for timestamp of interrupt 00128 } RadioEvents_t; 00129 00130 void printRxPkt(uint8_t size); 00131 00132 class Radio { 00133 public: 00134 static const char* const chipNum_str; 00135 00136 static void boardInit(const RadioEvents_t* e); 00137 static void hw_reset(void); 00138 static void clearIrqFlags(void); 00139 static void readChip(void); 00140 static void tx_carrier(void); 00141 static void tx_preamble(void); 00142 static void get_rssi(void); 00143 static void txPkt(void); 00144 static void Rx(void); 00145 static void setFS(void); 00146 00147 static const value_item_t tx_dbm_item; 00148 00149 static const menu_t* get_modem_menu(void); 00150 static const menu_t* get_modem_sub_menu(void); 00151 00152 static unsigned pktType_read(bool); 00153 static menuMode_e pktType_write(unsigned); 00154 static const char* const pktType_strs[]; 00155 00156 static void tx_dbm_print(void); 00157 static bool tx_dbm_write(const char*); 00158 00159 static unsigned tx_ramp_read(bool); 00160 static menuMode_e tx_ramp_write(unsigned); 00161 static const char* tx_ramp_strs[]; 00162 00163 static const char* const opmode_status_strs[]; 00164 static const char* const opmode_select_strs[]; 00165 static unsigned opmode_read(bool); 00166 static menuMode_e opmode_write(unsigned); 00167 00168 static uint8_t get_payload_length(void); 00169 static void set_payload_length(uint8_t); 00170 00171 static void tx_payload_length_print(void); 00172 static bool tx_payload_length_write(const char*); 00173 #ifdef SX127x_H 00174 static SX127x radio; 00175 static SX127x_lora lora; 00176 static SX127x_fsk fsk; 00177 static void rfsw_callback(void); 00178 static void ocp(uint8_t ma); 00179 static InterruptIn dio0; 00180 static InterruptIn dio1; 00181 #elif defined(SX126x_H) 00182 static SX126x radio; 00183 static ModulationParams_t mpFSK, mpLORA; 00184 static PacketParams_t ppFSK, ppLORA; 00185 #elif defined(SX128x_H) 00186 static SX128x radio; 00187 static uint8_t tx_param_buf[]; 00188 static ModulationParams_t mpFLRC, mpBLE_GFSK, mpLORA; 00189 static PacketParams_t ppGFSK, ppFLRC, ppLORA, ppBLE; 00190 #elif defined(SX1265_H) 00191 static SX1265 radio; 00192 static uint8_t tx_param_buf[]; 00193 static uint8_t pa_config_buf[]; 00194 static irq_t memRegRead(uint32_t addr, uint16_t len_dwords, uint8_t *dest); 00195 static uint32_t from_big_endian32(const uint8_t *in); 00196 static void print_stat(stat_t stat); 00197 static uint8_t gfsk_pp_buf[]; 00198 static uint8_t gfsk_mp_buf[]; 00199 static uint8_t lora_pp_buf[]; 00200 static uint8_t lora_mp_buf[]; 00201 #else 00202 #error import radio driver library 00203 #endif 00204 static bool service(int8_t); 00205 static const menu_t common_menu[]; 00206 00207 static void test(void); 00208 00209 static unsigned read_register(unsigned); 00210 static void write_register(unsigned, unsigned); 00211 00212 private: 00213 static const RadioEvents_t* RadioEvents; 00214 00215 static void txDoneBottom(void); 00216 static void cadDone(bool); 00217 00218 static const menu_t lora_menu[]; 00219 00220 static LowPowerTimer lpt; 00221 #if defined(SX128x_H) 00222 #include "radio_sx128x_private.h" 00223 #elif defined(SX127x_H) 00224 #include "radio_sx127x_private.h" 00225 #elif defined(SX126x_H) 00226 #include "radio_sx126x_private.h" 00227 #elif defined(SX1265_H) 00228 #include "radio_lr1110_private.h" 00229 #endif 00230 }; 00231
Generated on Mon Aug 5 2024 20:07:26 by
1.7.2