wifi test
Dependencies: X_NUCLEO_IKS01A2 mbed-http
easy-connect/stm-spirit1-rf-driver/stm-spirit1-rf-driver/SimpleSpirit1.h@0:24d3eb812fd4, 2018-09-05 (annotated)
- Committer:
- JMF
- Date:
- Wed Sep 05 14:28:24 2018 +0000
- Revision:
- 0:24d3eb812fd4
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JMF | 0:24d3eb812fd4 | 1 | /*** Mbed Includes ***/ |
| JMF | 0:24d3eb812fd4 | 2 | #include "mbed.h" |
| JMF | 0:24d3eb812fd4 | 3 | #include "mbed_debug.h" |
| JMF | 0:24d3eb812fd4 | 4 | |
| JMF | 0:24d3eb812fd4 | 5 | |
| JMF | 0:24d3eb812fd4 | 6 | /*** Cube Includes ***/ |
| JMF | 0:24d3eb812fd4 | 7 | #include "SPIRIT_Radio.h" |
| JMF | 0:24d3eb812fd4 | 8 | #include "SPIRIT_Management.h" |
| JMF | 0:24d3eb812fd4 | 9 | #include "SPIRIT_Commands.h" |
| JMF | 0:24d3eb812fd4 | 10 | #include "MCU_Interface.h" |
| JMF | 0:24d3eb812fd4 | 11 | |
| JMF | 0:24d3eb812fd4 | 12 | |
| JMF | 0:24d3eb812fd4 | 13 | /*** Contiki Lib Includes ***/ |
| JMF | 0:24d3eb812fd4 | 14 | #include "spirit1.h" |
| JMF | 0:24d3eb812fd4 | 15 | #include "spirit1-config.h" |
| JMF | 0:24d3eb812fd4 | 16 | #include "spirit1-const.h" |
| JMF | 0:24d3eb812fd4 | 17 | |
| JMF | 0:24d3eb812fd4 | 18 | |
| JMF | 0:24d3eb812fd4 | 19 | // betzw: enable beyond macro if you want debug messages also from IRQ handler |
| JMF | 0:24d3eb812fd4 | 20 | // #define DEBUG_IRQ |
| JMF | 0:24d3eb812fd4 | 21 | |
| JMF | 0:24d3eb812fd4 | 22 | |
| JMF | 0:24d3eb812fd4 | 23 | /*** Macros from Cube Implementation ***/ |
| JMF | 0:24d3eb812fd4 | 24 | #define CLEAR_TXBUF() (spirit_tx_len = 0) |
| JMF | 0:24d3eb812fd4 | 25 | #define IS_RXBUF_EMPTY() (spirit_rx_len == 0) |
| JMF | 0:24d3eb812fd4 | 26 | #define CLEAR_RXBUF() do { \ |
| JMF | 0:24d3eb812fd4 | 27 | spirit_rx_len = 0; \ |
| JMF | 0:24d3eb812fd4 | 28 | _spirit_rx_pos = 0; \ |
| JMF | 0:24d3eb812fd4 | 29 | } while(0) |
| JMF | 0:24d3eb812fd4 | 30 | |
| JMF | 0:24d3eb812fd4 | 31 | |
| JMF | 0:24d3eb812fd4 | 32 | /*** Macros from Cube Implementation ***/ |
| JMF | 0:24d3eb812fd4 | 33 | /* transceiver state. */ |
| JMF | 0:24d3eb812fd4 | 34 | #define ON 0 |
| JMF | 0:24d3eb812fd4 | 35 | #define OFF 1 |
| JMF | 0:24d3eb812fd4 | 36 | |
| JMF | 0:24d3eb812fd4 | 37 | |
| JMF | 0:24d3eb812fd4 | 38 | /*** Macros for Spirit1 API ***/ |
| JMF | 0:24d3eb812fd4 | 39 | /* max payload */ |
| JMF | 0:24d3eb812fd4 | 40 | #define SPIRIT1_MAX_PAYLOAD (MAX_PACKET_LEN) |
| JMF | 0:24d3eb812fd4 | 41 | |
| JMF | 0:24d3eb812fd4 | 42 | |
| JMF | 0:24d3eb812fd4 | 43 | /*** Missing Cube External Declarations ***/ |
| JMF | 0:24d3eb812fd4 | 44 | extern "C" void SpiritManagementSetFrequencyBase(uint32_t); |
| JMF | 0:24d3eb812fd4 | 45 | |
| JMF | 0:24d3eb812fd4 | 46 | |
| JMF | 0:24d3eb812fd4 | 47 | /*** UnlockedSPI for Usage in IRQ context ***/ |
| JMF | 0:24d3eb812fd4 | 48 | class UnlockedSPI : public SPI { |
| JMF | 0:24d3eb812fd4 | 49 | public: |
| JMF | 0:24d3eb812fd4 | 50 | UnlockedSPI(PinName mosi, PinName miso, PinName sclk) : |
| JMF | 0:24d3eb812fd4 | 51 | SPI(mosi, miso, sclk) { } |
| JMF | 0:24d3eb812fd4 | 52 | virtual ~UnlockedSPI() {} |
| JMF | 0:24d3eb812fd4 | 53 | virtual void lock() { } |
| JMF | 0:24d3eb812fd4 | 54 | virtual void unlock() { } |
| JMF | 0:24d3eb812fd4 | 55 | }; |
| JMF | 0:24d3eb812fd4 | 56 | |
| JMF | 0:24d3eb812fd4 | 57 | |
| JMF | 0:24d3eb812fd4 | 58 | /*** A Simple Spirit1 Class ***/ |
| JMF | 0:24d3eb812fd4 | 59 | // NOTE: must be a singleton (due to mix of MBED/CUBE code)!!! |
| JMF | 0:24d3eb812fd4 | 60 | // NOTE: implementation is IRQ-save but (intentionally) NOT thread-safe!!! |
| JMF | 0:24d3eb812fd4 | 61 | /** Simple Spirit1 Class |
| JMF | 0:24d3eb812fd4 | 62 | * |
| JMF | 0:24d3eb812fd4 | 63 | * @Note Synchronization level: implementation is IRQ-save but (intentionally) NOT thread-safe!!! |
| JMF | 0:24d3eb812fd4 | 64 | * |
| JMF | 0:24d3eb812fd4 | 65 | * Example: |
| JMF | 0:24d3eb812fd4 | 66 | * @code |
| JMF | 0:24d3eb812fd4 | 67 | * #include "mbed.h" |
| JMF | 0:24d3eb812fd4 | 68 | * #include "SimpleSpirit1.h" |
| JMF | 0:24d3eb812fd4 | 69 | * |
| JMF | 0:24d3eb812fd4 | 70 | * static char send_buf[] = "Hello World!"; |
| JMF | 0:24d3eb812fd4 | 71 | * |
| JMF | 0:24d3eb812fd4 | 72 | * static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); |
| JMF | 0:24d3eb812fd4 | 73 | * |
| JMF | 0:24d3eb812fd4 | 74 | * static volatile bool tx_done_flag = false; |
| JMF | 0:24d3eb812fd4 | 75 | * |
| JMF | 0:24d3eb812fd4 | 76 | * static void callback_func(int event) |
| JMF | 0:24d3eb812fd4 | 77 | * { |
| JMF | 0:24d3eb812fd4 | 78 | * if (event == SimpleSpirit1::TX_DONE) { |
| JMF | 0:24d3eb812fd4 | 79 | * tx_done_flag = true; |
| JMF | 0:24d3eb812fd4 | 80 | * } |
| JMF | 0:24d3eb812fd4 | 81 | * } |
| JMF | 0:24d3eb812fd4 | 82 | * |
| JMF | 0:24d3eb812fd4 | 83 | * int main() |
| JMF | 0:24d3eb812fd4 | 84 | * { |
| JMF | 0:24d3eb812fd4 | 85 | * myspirit.attach_irq_callback(callback_func); |
| JMF | 0:24d3eb812fd4 | 86 | * myspirit.on(); |
| JMF | 0:24d3eb812fd4 | 87 | * |
| JMF | 0:24d3eb812fd4 | 88 | * while(1) |
| JMF | 0:24d3eb812fd4 | 89 | * { |
| JMF | 0:24d3eb812fd4 | 90 | * size_t curr_len = strlen((const char*)send_buf); |
| JMF | 0:24d3eb812fd4 | 91 | * myspirit.send(send_buf, curr_len); |
| JMF | 0:24d3eb812fd4 | 92 | * |
| JMF | 0:24d3eb812fd4 | 93 | * while(!tx_done_flag); |
| JMF | 0:24d3eb812fd4 | 94 | * tx_done_flag = false; |
| JMF | 0:24d3eb812fd4 | 95 | * } |
| JMF | 0:24d3eb812fd4 | 96 | * } |
| JMF | 0:24d3eb812fd4 | 97 | * @endcode |
| JMF | 0:24d3eb812fd4 | 98 | */ |
| JMF | 0:24d3eb812fd4 | 99 | class SimpleSpirit1 { |
| JMF | 0:24d3eb812fd4 | 100 | protected: |
| JMF | 0:24d3eb812fd4 | 101 | static SimpleSpirit1 *_singleton; |
| JMF | 0:24d3eb812fd4 | 102 | |
| JMF | 0:24d3eb812fd4 | 103 | /** Communication Interface Instance Variables **/ |
| JMF | 0:24d3eb812fd4 | 104 | UnlockedSPI _spi; // betzw - NOTE: Morpho/Zio pins are valid only for NUCLEO-F401RE |
| JMF | 0:24d3eb812fd4 | 105 | // mosi: PA_7 (D11) |
| JMF | 0:24d3eb812fd4 | 106 | // miso: PA_6 (D12) |
| JMF | 0:24d3eb812fd4 | 107 | // sclk: PB_3 (D3) or |
| JMF | 0:24d3eb812fd4 | 108 | // PA_5 (D13) (only in case you unmount R4 & mount R7, |
| JMF | 0:24d3eb812fd4 | 109 | // (note: in this case you may not use LED1 on some platforms) |
| JMF | 0:24d3eb812fd4 | 110 | // bits: 8-bit |
| JMF | 0:24d3eb812fd4 | 111 | // mode: 0 |
| JMF | 0:24d3eb812fd4 | 112 | // ordr: MSB |
| JMF | 0:24d3eb812fd4 | 113 | // freq: max 10MHz |
| JMF | 0:24d3eb812fd4 | 114 | InterruptIn _irq; // PC_7 (D9) (falling) |
| JMF | 0:24d3eb812fd4 | 115 | DigitalOut _chip_select; // PB_6 (D10) ('1' == chip unselected) |
| JMF | 0:24d3eb812fd4 | 116 | DigitalOut _shut_down; // PA_10 (D2) ('1' == shut_down) |
| JMF | 0:24d3eb812fd4 | 117 | DigitalOut _led; // PB_4 (D5) (optional) |
| JMF | 0:24d3eb812fd4 | 118 | |
| JMF | 0:24d3eb812fd4 | 119 | Callback<void(int)> _current_irq_callback; |
| JMF | 0:24d3eb812fd4 | 120 | Timeout _rx_receiving_timeout; |
| JMF | 0:24d3eb812fd4 | 121 | |
| JMF | 0:24d3eb812fd4 | 122 | void rx_timeout_handler(void) { |
| JMF | 0:24d3eb812fd4 | 123 | set_ready_state(); |
| JMF | 0:24d3eb812fd4 | 124 | cmd_strobe(SPIRIT1_STROBE_RX); |
| JMF | 0:24d3eb812fd4 | 125 | #ifdef DEBUG_IRQ |
| JMF | 0:24d3eb812fd4 | 126 | debug("\r\n%s (%d)\r\n", __func__, __LINE__); |
| JMF | 0:24d3eb812fd4 | 127 | #endif |
| JMF | 0:24d3eb812fd4 | 128 | } |
| JMF | 0:24d3eb812fd4 | 129 | |
| JMF | 0:24d3eb812fd4 | 130 | void start_rx_timeout(void) { |
| JMF | 0:24d3eb812fd4 | 131 | _rx_receiving_timeout.attach_us(Callback<void()>(this, &SimpleSpirit1::rx_timeout_handler), 100 * 1000); // 100ms |
| JMF | 0:24d3eb812fd4 | 132 | } |
| JMF | 0:24d3eb812fd4 | 133 | |
| JMF | 0:24d3eb812fd4 | 134 | void stop_rx_timeout(void) { |
| JMF | 0:24d3eb812fd4 | 135 | _rx_receiving_timeout.detach(); |
| JMF | 0:24d3eb812fd4 | 136 | } |
| JMF | 0:24d3eb812fd4 | 137 | |
| JMF | 0:24d3eb812fd4 | 138 | /** Static Variables from Cube Implementation **/ |
| JMF | 0:24d3eb812fd4 | 139 | /* |
| JMF | 0:24d3eb812fd4 | 140 | * The buffers which hold incoming data. |
| JMF | 0:24d3eb812fd4 | 141 | * The +1 because of the first byte, |
| JMF | 0:24d3eb812fd4 | 142 | * which will contain the length of the packet. |
| JMF | 0:24d3eb812fd4 | 143 | */ |
| JMF | 0:24d3eb812fd4 | 144 | volatile uint16_t spirit_tx_len; |
| JMF | 0:24d3eb812fd4 | 145 | volatile bool _spirit_tx_started; |
| JMF | 0:24d3eb812fd4 | 146 | volatile uint16_t spirit_rx_len; |
| JMF | 0:24d3eb812fd4 | 147 | volatile uint16_t _spirit_rx_pos; |
| JMF | 0:24d3eb812fd4 | 148 | volatile bool _spirit_rx_err; |
| JMF | 0:24d3eb812fd4 | 149 | uint8_t spirit_rx_buf[MAX_PACKET_LEN]; |
| JMF | 0:24d3eb812fd4 | 150 | volatile bool _is_receiving; |
| JMF | 0:24d3eb812fd4 | 151 | |
| JMF | 0:24d3eb812fd4 | 152 | /** Status Variables from Cube Implementation **/ |
| JMF | 0:24d3eb812fd4 | 153 | unsigned int spirit_on; |
| JMF | 0:24d3eb812fd4 | 154 | uint8_t last_rssi; //MGR |
| JMF | 0:24d3eb812fd4 | 155 | uint8_t last_sqi; //MGR |
| JMF | 0:24d3eb812fd4 | 156 | |
| JMF | 0:24d3eb812fd4 | 157 | /** Low Level Instance Variables **/ |
| JMF | 0:24d3eb812fd4 | 158 | unsigned int _nr_of_irq_disables; |
| JMF | 0:24d3eb812fd4 | 159 | |
| JMF | 0:24d3eb812fd4 | 160 | /** Low Level Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 161 | void disable_spirit_irq(void) { |
| JMF | 0:24d3eb812fd4 | 162 | _irq.disable_irq(); |
| JMF | 0:24d3eb812fd4 | 163 | _nr_of_irq_disables++; |
| JMF | 0:24d3eb812fd4 | 164 | #ifndef NDEBUG |
| JMF | 0:24d3eb812fd4 | 165 | debug_if(_nr_of_irq_disables == 0, "\r\nassert failed in: %s (%d)\r\n", __func__, __LINE__); |
| JMF | 0:24d3eb812fd4 | 166 | #endif |
| JMF | 0:24d3eb812fd4 | 167 | } |
| JMF | 0:24d3eb812fd4 | 168 | |
| JMF | 0:24d3eb812fd4 | 169 | void enable_spirit_irq(void) { |
| JMF | 0:24d3eb812fd4 | 170 | #ifndef NDEBUG |
| JMF | 0:24d3eb812fd4 | 171 | debug_if(_nr_of_irq_disables == 0, "\r\nassert failed in: %s (%d)\r\n", __func__, __LINE__); |
| JMF | 0:24d3eb812fd4 | 172 | #endif |
| JMF | 0:24d3eb812fd4 | 173 | if(--_nr_of_irq_disables == 0) |
| JMF | 0:24d3eb812fd4 | 174 | _irq.enable_irq(); |
| JMF | 0:24d3eb812fd4 | 175 | } |
| JMF | 0:24d3eb812fd4 | 176 | |
| JMF | 0:24d3eb812fd4 | 177 | void chip_select() { _chip_select = 0; } |
| JMF | 0:24d3eb812fd4 | 178 | void chip_unselect() { _chip_select = 1; } |
| JMF | 0:24d3eb812fd4 | 179 | |
| JMF | 0:24d3eb812fd4 | 180 | void enter_shutdown() { |
| JMF | 0:24d3eb812fd4 | 181 | _shut_down = 1; |
| JMF | 0:24d3eb812fd4 | 182 | wait_ms(5); // wait 5 milliseconds (to allow Spirit1 to shut down) |
| JMF | 0:24d3eb812fd4 | 183 | } |
| JMF | 0:24d3eb812fd4 | 184 | |
| JMF | 0:24d3eb812fd4 | 185 | void exit_shutdown() { |
| JMF | 0:24d3eb812fd4 | 186 | _shut_down = 0; |
| JMF | 0:24d3eb812fd4 | 187 | wait_ms(10); // wait 10 milliseconds (to allow Spirit1 a proper boot-up sequence) |
| JMF | 0:24d3eb812fd4 | 188 | } |
| JMF | 0:24d3eb812fd4 | 189 | |
| JMF | 0:24d3eb812fd4 | 190 | void cs_to_sclk_delay(void) { |
| JMF | 0:24d3eb812fd4 | 191 | wait_us(1); // heuristic value |
| JMF | 0:24d3eb812fd4 | 192 | } |
| JMF | 0:24d3eb812fd4 | 193 | |
| JMF | 0:24d3eb812fd4 | 194 | /** |
| JMF | 0:24d3eb812fd4 | 195 | * @brief Write and read a buffer to/from the SPI peripheral device at the same time |
| JMF | 0:24d3eb812fd4 | 196 | * in 8-bit data mode using synchronous SPI communication. |
| JMF | 0:24d3eb812fd4 | 197 | * @param[in] pBufferToWrite pointer to the buffer of data to send. |
| JMF | 0:24d3eb812fd4 | 198 | * @param[out] pBufferToRead pointer to the buffer to read data into. |
| JMF | 0:24d3eb812fd4 | 199 | * @param[in] NumBytes number of bytes to read and write. |
| JMF | 0:24d3eb812fd4 | 200 | * @retval 0 if ok. |
| JMF | 0:24d3eb812fd4 | 201 | * @retval -1 if data format error. |
| JMF | 0:24d3eb812fd4 | 202 | * @note When using the SPI in Interrupt-mode, remember to disable interrupts |
| JMF | 0:24d3eb812fd4 | 203 | * before calling this function and to enable them again after. |
| JMF | 0:24d3eb812fd4 | 204 | */ |
| JMF | 0:24d3eb812fd4 | 205 | void spi_write_read(uint8_t* pBufferToWrite, uint8_t* pBufferToRead, uint16_t NumBytes) |
| JMF | 0:24d3eb812fd4 | 206 | { |
| JMF | 0:24d3eb812fd4 | 207 | /* Read and write data at the same time. */ |
| JMF | 0:24d3eb812fd4 | 208 | for (int i = 0; i < NumBytes; i++) { |
| JMF | 0:24d3eb812fd4 | 209 | pBufferToRead[i] = _spi.write(pBufferToWrite[i]); |
| JMF | 0:24d3eb812fd4 | 210 | } |
| JMF | 0:24d3eb812fd4 | 211 | } |
| JMF | 0:24d3eb812fd4 | 212 | |
| JMF | 0:24d3eb812fd4 | 213 | /** Radio Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 214 | void radio_set_xtal_freq(uint32_t freq) { |
| JMF | 0:24d3eb812fd4 | 215 | SpiritRadioSetXtalFrequency(freq); |
| JMF | 0:24d3eb812fd4 | 216 | } |
| JMF | 0:24d3eb812fd4 | 217 | |
| JMF | 0:24d3eb812fd4 | 218 | void radio_set_pa_level_dbm(uint8_t cIndex, float fPowerdBm) { |
| JMF | 0:24d3eb812fd4 | 219 | SpiritRadioSetPALeveldBm(cIndex, fPowerdBm); |
| JMF | 0:24d3eb812fd4 | 220 | } |
| JMF | 0:24d3eb812fd4 | 221 | |
| JMF | 0:24d3eb812fd4 | 222 | void radio_set_pa_level_max_index(uint8_t cIndex) { |
| JMF | 0:24d3eb812fd4 | 223 | SpiritRadioSetPALevelMaxIndex(cIndex); |
| JMF | 0:24d3eb812fd4 | 224 | } |
| JMF | 0:24d3eb812fd4 | 225 | |
| JMF | 0:24d3eb812fd4 | 226 | uint8_t radio_init(SRadioInit *init_struct) { |
| JMF | 0:24d3eb812fd4 | 227 | return SpiritRadioInit(init_struct); |
| JMF | 0:24d3eb812fd4 | 228 | } |
| JMF | 0:24d3eb812fd4 | 229 | |
| JMF | 0:24d3eb812fd4 | 230 | void radio_persistent_rx(SpiritFunctionalState xNewState) { |
| JMF | 0:24d3eb812fd4 | 231 | SpiritRadioPersistenRx(xNewState); |
| JMF | 0:24d3eb812fd4 | 232 | } |
| JMF | 0:24d3eb812fd4 | 233 | |
| JMF | 0:24d3eb812fd4 | 234 | void radio_afc_freeze_on_sync(SpiritFunctionalState xNewState) { |
| JMF | 0:24d3eb812fd4 | 235 | SpiritRadioAFCFreezeOnSync(xNewState); |
| JMF | 0:24d3eb812fd4 | 236 | } |
| JMF | 0:24d3eb812fd4 | 237 | |
| JMF | 0:24d3eb812fd4 | 238 | /** Packet System Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 239 | void pkt_basic_init(PktBasicInit* pxPktBasicInit) { |
| JMF | 0:24d3eb812fd4 | 240 | SpiritPktBasicInit(pxPktBasicInit); |
| JMF | 0:24d3eb812fd4 | 241 | } |
| JMF | 0:24d3eb812fd4 | 242 | |
| JMF | 0:24d3eb812fd4 | 243 | void pkt_basic_set_payload_length(uint16_t nPayloadLength) { |
| JMF | 0:24d3eb812fd4 | 244 | SpiritPktBasicSetPayloadLength(nPayloadLength); |
| JMF | 0:24d3eb812fd4 | 245 | } |
| JMF | 0:24d3eb812fd4 | 246 | |
| JMF | 0:24d3eb812fd4 | 247 | uint16_t pkt_basic_get_received_pkt_length(void) { |
| JMF | 0:24d3eb812fd4 | 248 | return SpiritPktBasicGetReceivedPktLength(); |
| JMF | 0:24d3eb812fd4 | 249 | } |
| JMF | 0:24d3eb812fd4 | 250 | |
| JMF | 0:24d3eb812fd4 | 251 | /** IRQ Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 252 | void irq_de_init(SpiritIrqs* pxIrqInit) { |
| JMF | 0:24d3eb812fd4 | 253 | SpiritIrqDeInit(pxIrqInit); |
| JMF | 0:24d3eb812fd4 | 254 | } |
| JMF | 0:24d3eb812fd4 | 255 | |
| JMF | 0:24d3eb812fd4 | 256 | void irq_clear_status(void) { |
| JMF | 0:24d3eb812fd4 | 257 | SpiritIrqClearStatus(); |
| JMF | 0:24d3eb812fd4 | 258 | } |
| JMF | 0:24d3eb812fd4 | 259 | |
| JMF | 0:24d3eb812fd4 | 260 | void irq_set_status(IrqList xIrq, SpiritFunctionalState xNewState) { |
| JMF | 0:24d3eb812fd4 | 261 | SpiritIrq(xIrq, xNewState); |
| JMF | 0:24d3eb812fd4 | 262 | } |
| JMF | 0:24d3eb812fd4 | 263 | |
| JMF | 0:24d3eb812fd4 | 264 | void irq_get_status(SpiritIrqs* pxIrqStatus) { |
| JMF | 0:24d3eb812fd4 | 265 | SpiritIrqGetStatus(pxIrqStatus); |
| JMF | 0:24d3eb812fd4 | 266 | } |
| JMF | 0:24d3eb812fd4 | 267 | |
| JMF | 0:24d3eb812fd4 | 268 | /** Management Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 269 | void mgmt_set_freq_base(uint32_t freq) { |
| JMF | 0:24d3eb812fd4 | 270 | SpiritManagementSetFrequencyBase(freq); |
| JMF | 0:24d3eb812fd4 | 271 | } |
| JMF | 0:24d3eb812fd4 | 272 | |
| JMF | 0:24d3eb812fd4 | 273 | void mgmt_refresh_status(void) { |
| JMF | 0:24d3eb812fd4 | 274 | SpiritRefreshStatus(); |
| JMF | 0:24d3eb812fd4 | 275 | } |
| JMF | 0:24d3eb812fd4 | 276 | |
| JMF | 0:24d3eb812fd4 | 277 | /** Spirit GPIO Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 278 | void spirit_gpio_init(SGpioInit* pxGpioInitStruct) { |
| JMF | 0:24d3eb812fd4 | 279 | SpiritGpioInit(pxGpioInitStruct); |
| JMF | 0:24d3eb812fd4 | 280 | } |
| JMF | 0:24d3eb812fd4 | 281 | |
| JMF | 0:24d3eb812fd4 | 282 | /** Qi Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 283 | void qi_set_sqi_threshold(SqiThreshold xSqiThr) { |
| JMF | 0:24d3eb812fd4 | 284 | SpiritQiSetSqiThreshold(xSqiThr); |
| JMF | 0:24d3eb812fd4 | 285 | } |
| JMF | 0:24d3eb812fd4 | 286 | |
| JMF | 0:24d3eb812fd4 | 287 | void qi_sqi_check(SpiritFunctionalState xNewState) { |
| JMF | 0:24d3eb812fd4 | 288 | SpiritQiSqiCheck(xNewState); |
| JMF | 0:24d3eb812fd4 | 289 | } |
| JMF | 0:24d3eb812fd4 | 290 | |
| JMF | 0:24d3eb812fd4 | 291 | void qi_set_rssi_threshold_dbm(int nDbmValue) { |
| JMF | 0:24d3eb812fd4 | 292 | SpiritQiSetRssiThresholddBm(nDbmValue); |
| JMF | 0:24d3eb812fd4 | 293 | } |
| JMF | 0:24d3eb812fd4 | 294 | |
| JMF | 0:24d3eb812fd4 | 295 | float qi_get_rssi_dbm() { |
| JMF | 0:24d3eb812fd4 | 296 | last_rssi = qi_get_rssi(); |
| JMF | 0:24d3eb812fd4 | 297 | return get_last_rssi_dbm(); |
| JMF | 0:24d3eb812fd4 | 298 | } |
| JMF | 0:24d3eb812fd4 | 299 | |
| JMF | 0:24d3eb812fd4 | 300 | uint8_t qi_get_rssi() { |
| JMF | 0:24d3eb812fd4 | 301 | return SpiritQiGetRssi(); |
| JMF | 0:24d3eb812fd4 | 302 | } |
| JMF | 0:24d3eb812fd4 | 303 | |
| JMF | 0:24d3eb812fd4 | 304 | uint8_t qi_get_sqi() { |
| JMF | 0:24d3eb812fd4 | 305 | return SpiritQiGetSqi(); |
| JMF | 0:24d3eb812fd4 | 306 | } |
| JMF | 0:24d3eb812fd4 | 307 | |
| JMF | 0:24d3eb812fd4 | 308 | /** Timer Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 309 | void timer_set_rx_timeout_stop_condition(RxTimeoutStopCondition xStopCondition) { |
| JMF | 0:24d3eb812fd4 | 310 | SpiritTimerSetRxTimeoutStopCondition(xStopCondition); |
| JMF | 0:24d3eb812fd4 | 311 | } |
| JMF | 0:24d3eb812fd4 | 312 | |
| JMF | 0:24d3eb812fd4 | 313 | void timer_set_rx_timeout_counter(uint8_t cCounter) { |
| JMF | 0:24d3eb812fd4 | 314 | SpiritTimerSetRxTimeoutCounter(cCounter); |
| JMF | 0:24d3eb812fd4 | 315 | } |
| JMF | 0:24d3eb812fd4 | 316 | |
| JMF | 0:24d3eb812fd4 | 317 | void timer_set_infinite_rx_timeout(void) { |
| JMF | 0:24d3eb812fd4 | 318 | timer_set_rx_timeout_counter(0); |
| JMF | 0:24d3eb812fd4 | 319 | } |
| JMF | 0:24d3eb812fd4 | 320 | |
| JMF | 0:24d3eb812fd4 | 321 | /** CSMA/CA Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 322 | void csma_ca_state(SpiritFunctionalState xNewState) { |
| JMF | 0:24d3eb812fd4 | 323 | SpiritCsma(xNewState); |
| JMF | 0:24d3eb812fd4 | 324 | } |
| JMF | 0:24d3eb812fd4 | 325 | |
| JMF | 0:24d3eb812fd4 | 326 | void csma_ca_init(CsmaInit* pxCsmaInit) { |
| JMF | 0:24d3eb812fd4 | 327 | csma_ca_state(S_DISABLE); // Disabled at init |
| JMF | 0:24d3eb812fd4 | 328 | SpiritCsmaInit(pxCsmaInit); |
| JMF | 0:24d3eb812fd4 | 329 | SpiritCsmaSeedReloadMode(S_DISABLE); // always disable seed reload |
| JMF | 0:24d3eb812fd4 | 330 | } |
| JMF | 0:24d3eb812fd4 | 331 | |
| JMF | 0:24d3eb812fd4 | 332 | /** Command Instance Methods**/ |
| JMF | 0:24d3eb812fd4 | 333 | void cmd_strobe(uint8_t cmd) { |
| JMF | 0:24d3eb812fd4 | 334 | SpiritCmdStrobeCommand((SpiritCmd)cmd); |
| JMF | 0:24d3eb812fd4 | 335 | } |
| JMF | 0:24d3eb812fd4 | 336 | |
| JMF | 0:24d3eb812fd4 | 337 | void cmd_strobe_flush_rx_fifo() { |
| JMF | 0:24d3eb812fd4 | 338 | SpiritCmdStrobeCommand(CMD_FLUSHRXFIFO); |
| JMF | 0:24d3eb812fd4 | 339 | } |
| JMF | 0:24d3eb812fd4 | 340 | |
| JMF | 0:24d3eb812fd4 | 341 | /** SPI Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 342 | StatusBytes spi_write_linear_fifo(uint8_t cNbBytes, uint8_t* pcBuffer) { |
| JMF | 0:24d3eb812fd4 | 343 | return SdkEvalSpiWriteFifo(cNbBytes, pcBuffer); |
| JMF | 0:24d3eb812fd4 | 344 | } |
| JMF | 0:24d3eb812fd4 | 345 | |
| JMF | 0:24d3eb812fd4 | 346 | StatusBytes spi_read_linear_fifo(uint8_t cNbBytes, uint8_t* pcBuffer) { |
| JMF | 0:24d3eb812fd4 | 347 | return SdkEvalSpiReadFifo(cNbBytes, pcBuffer); |
| JMF | 0:24d3eb812fd4 | 348 | } |
| JMF | 0:24d3eb812fd4 | 349 | |
| JMF | 0:24d3eb812fd4 | 350 | /** Linear FIFO Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 351 | uint8_t linear_fifo_read_num_elements_rx_fifo(void) { |
| JMF | 0:24d3eb812fd4 | 352 | return SpiritLinearFifoReadNumElementsRxFifo(); |
| JMF | 0:24d3eb812fd4 | 353 | } |
| JMF | 0:24d3eb812fd4 | 354 | |
| JMF | 0:24d3eb812fd4 | 355 | uint8_t linear_fifo_read_num_elements_tx_fifo(void) { |
| JMF | 0:24d3eb812fd4 | 356 | return SpiritLinearFifoReadNumElementsTxFifo(); |
| JMF | 0:24d3eb812fd4 | 357 | } |
| JMF | 0:24d3eb812fd4 | 358 | |
| JMF | 0:24d3eb812fd4 | 359 | void linear_fifo_set_almost_full_thr_rx(uint8_t cThrRxFifo) { |
| JMF | 0:24d3eb812fd4 | 360 | SpiritLinearFifoSetAlmostFullThresholdRx(cThrRxFifo); |
| JMF | 0:24d3eb812fd4 | 361 | } |
| JMF | 0:24d3eb812fd4 | 362 | |
| JMF | 0:24d3eb812fd4 | 363 | /** Calibration Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 364 | void calibration_rco(SpiritFunctionalState xNewState) { |
| JMF | 0:24d3eb812fd4 | 365 | SpiritCalibrationRco(xNewState); |
| JMF | 0:24d3eb812fd4 | 366 | } |
| JMF | 0:24d3eb812fd4 | 367 | |
| JMF | 0:24d3eb812fd4 | 368 | /** Internal Spirit Methods */ |
| JMF | 0:24d3eb812fd4 | 369 | void set_ready_state(void); |
| JMF | 0:24d3eb812fd4 | 370 | uint8_t refresh_state(void); |
| JMF | 0:24d3eb812fd4 | 371 | |
| JMF | 0:24d3eb812fd4 | 372 | /** Friend Functions **/ |
| JMF | 0:24d3eb812fd4 | 373 | friend StatusBytes SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 374 | friend StatusBytes SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 375 | friend StatusBytes SdkEvalSpiCommandStrobes(uint8_t cCommandCode); |
| JMF | 0:24d3eb812fd4 | 376 | friend StatusBytes SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 377 | friend StatusBytes SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 378 | |
| JMF | 0:24d3eb812fd4 | 379 | /** Sdk Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 380 | StatusBytes SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 381 | StatusBytes SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 382 | StatusBytes SdkEvalSpiCommandStrobes(uint8_t cCommandCode); |
| JMF | 0:24d3eb812fd4 | 383 | StatusBytes SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 384 | StatusBytes SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer); |
| JMF | 0:24d3eb812fd4 | 385 | |
| JMF | 0:24d3eb812fd4 | 386 | /** Helper Instance Methods **/ |
| JMF | 0:24d3eb812fd4 | 387 | void chip_sync_select() { |
| JMF | 0:24d3eb812fd4 | 388 | disable_spirit_irq(); |
| JMF | 0:24d3eb812fd4 | 389 | chip_select(); |
| JMF | 0:24d3eb812fd4 | 390 | cs_to_sclk_delay(); |
| JMF | 0:24d3eb812fd4 | 391 | } |
| JMF | 0:24d3eb812fd4 | 392 | |
| JMF | 0:24d3eb812fd4 | 393 | void chip_sync_unselect() { |
| JMF | 0:24d3eb812fd4 | 394 | chip_unselect(); |
| JMF | 0:24d3eb812fd4 | 395 | enable_spirit_irq(); |
| JMF | 0:24d3eb812fd4 | 396 | } |
| JMF | 0:24d3eb812fd4 | 397 | |
| JMF | 0:24d3eb812fd4 | 398 | /** Init Instance Method **/ |
| JMF | 0:24d3eb812fd4 | 399 | void init(); |
| JMF | 0:24d3eb812fd4 | 400 | |
| JMF | 0:24d3eb812fd4 | 401 | /** Spirit Irq Callback */ |
| JMF | 0:24d3eb812fd4 | 402 | void IrqHandler(); |
| JMF | 0:24d3eb812fd4 | 403 | |
| JMF | 0:24d3eb812fd4 | 404 | /** Constructor **/ |
| JMF | 0:24d3eb812fd4 | 405 | SimpleSpirit1(PinName mosi, PinName miso, PinName sclk, |
| JMF | 0:24d3eb812fd4 | 406 | PinName irq, PinName cs, PinName sdn, |
| JMF | 0:24d3eb812fd4 | 407 | PinName led); |
| JMF | 0:24d3eb812fd4 | 408 | |
| JMF | 0:24d3eb812fd4 | 409 | /** Destructor **/ |
| JMF | 0:24d3eb812fd4 | 410 | ~SimpleSpirit1(void); // should never be called! |
| JMF | 0:24d3eb812fd4 | 411 | |
| JMF | 0:24d3eb812fd4 | 412 | public: |
| JMF | 0:24d3eb812fd4 | 413 | enum { |
| JMF | 0:24d3eb812fd4 | 414 | RX_DONE, |
| JMF | 0:24d3eb812fd4 | 415 | TX_DONE, |
| JMF | 0:24d3eb812fd4 | 416 | TX_ERR |
| JMF | 0:24d3eb812fd4 | 417 | }; |
| JMF | 0:24d3eb812fd4 | 418 | |
| JMF | 0:24d3eb812fd4 | 419 | /** Create singleton instance of 'SimpleSpirit1' |
| JMF | 0:24d3eb812fd4 | 420 | * |
| JMF | 0:24d3eb812fd4 | 421 | * @param mosi 'PinName' of mosi pin to use |
| JMF | 0:24d3eb812fd4 | 422 | * @param miso 'PinName' of miso pin to use |
| JMF | 0:24d3eb812fd4 | 423 | * @param sclk 'PinName' of clock pin to use |
| JMF | 0:24d3eb812fd4 | 424 | * @param irq 'PinName' of interrupt pin to use |
| JMF | 0:24d3eb812fd4 | 425 | * @param cs 'PinName' of chip-select pin pin to use |
| JMF | 0:24d3eb812fd4 | 426 | * @param sdn 'PinName' of pin to use for device shutdown |
| JMF | 0:24d3eb812fd4 | 427 | * |
| JMF | 0:24d3eb812fd4 | 428 | * @returns reference to singleton instance |
| JMF | 0:24d3eb812fd4 | 429 | */ |
| JMF | 0:24d3eb812fd4 | 430 | static SimpleSpirit1& CreateInstance(PinName mosi, PinName miso, PinName sclk, |
| JMF | 0:24d3eb812fd4 | 431 | PinName irq, PinName cs, PinName sdn, |
| JMF | 0:24d3eb812fd4 | 432 | PinName led = NC) { |
| JMF | 0:24d3eb812fd4 | 433 | |
| JMF | 0:24d3eb812fd4 | 434 | if(_singleton == NULL) { |
| JMF | 0:24d3eb812fd4 | 435 | _singleton = new SimpleSpirit1(mosi, miso, sclk, |
| JMF | 0:24d3eb812fd4 | 436 | irq, cs, sdn, led); |
| JMF | 0:24d3eb812fd4 | 437 | _singleton->init(); |
| JMF | 0:24d3eb812fd4 | 438 | } else { |
| JMF | 0:24d3eb812fd4 | 439 | error("SimpleSpirit1 singleton already created!\n"); |
| JMF | 0:24d3eb812fd4 | 440 | } |
| JMF | 0:24d3eb812fd4 | 441 | |
| JMF | 0:24d3eb812fd4 | 442 | return *_singleton; |
| JMF | 0:24d3eb812fd4 | 443 | } |
| JMF | 0:24d3eb812fd4 | 444 | |
| JMF | 0:24d3eb812fd4 | 445 | /** Get singleton instance of 'SimpleSpirit1' |
| JMF | 0:24d3eb812fd4 | 446 | * |
| JMF | 0:24d3eb812fd4 | 447 | * @returns reference to singleton instance |
| JMF | 0:24d3eb812fd4 | 448 | */ |
| JMF | 0:24d3eb812fd4 | 449 | static SimpleSpirit1& Instance() { |
| JMF | 0:24d3eb812fd4 | 450 | if(_singleton == NULL) { |
| JMF | 0:24d3eb812fd4 | 451 | error("SimpleSpirit1 must be created before used!\n"); |
| JMF | 0:24d3eb812fd4 | 452 | } |
| JMF | 0:24d3eb812fd4 | 453 | |
| JMF | 0:24d3eb812fd4 | 454 | return *_singleton; |
| JMF | 0:24d3eb812fd4 | 455 | } |
| JMF | 0:24d3eb812fd4 | 456 | |
| JMF | 0:24d3eb812fd4 | 457 | /** Attach a function to be called by the Spirit Irq handler when an event has occurred |
| JMF | 0:24d3eb812fd4 | 458 | * |
| JMF | 0:24d3eb812fd4 | 459 | * @param func A void(int) callback, or 0 to set as none |
| JMF | 0:24d3eb812fd4 | 460 | * |
| JMF | 0:24d3eb812fd4 | 461 | * @note Function 'func' will be executed in interrupt context! |
| JMF | 0:24d3eb812fd4 | 462 | * @note Function 'func' will be call with either 'RX_DONE', 'TX_DONE', or 'TX_ERR' as parameter |
| JMF | 0:24d3eb812fd4 | 463 | * to indicate which event has occurred. |
| JMF | 0:24d3eb812fd4 | 464 | */ |
| JMF | 0:24d3eb812fd4 | 465 | void attach_irq_callback(Callback<void(int)> func) { |
| JMF | 0:24d3eb812fd4 | 466 | _current_irq_callback = func; |
| JMF | 0:24d3eb812fd4 | 467 | } |
| JMF | 0:24d3eb812fd4 | 468 | |
| JMF | 0:24d3eb812fd4 | 469 | /** Switch Radio On |
| JMF | 0:24d3eb812fd4 | 470 | */ |
| JMF | 0:24d3eb812fd4 | 471 | int on(void); |
| JMF | 0:24d3eb812fd4 | 472 | |
| JMF | 0:24d3eb812fd4 | 473 | /** Switch Radio Off |
| JMF | 0:24d3eb812fd4 | 474 | */ |
| JMF | 0:24d3eb812fd4 | 475 | int off(void); |
| JMF | 0:24d3eb812fd4 | 476 | |
| JMF | 0:24d3eb812fd4 | 477 | /** Set Channel |
| JMF | 0:24d3eb812fd4 | 478 | */ |
| JMF | 0:24d3eb812fd4 | 479 | void set_channel(uint8_t channel) { |
| JMF | 0:24d3eb812fd4 | 480 | SpiritRadioSetChannel(channel); |
| JMF | 0:24d3eb812fd4 | 481 | } |
| JMF | 0:24d3eb812fd4 | 482 | |
| JMF | 0:24d3eb812fd4 | 483 | /** Send a Buffer |
| JMF | 0:24d3eb812fd4 | 484 | * |
| JMF | 0:24d3eb812fd4 | 485 | * @param payload pointer to buffer to be send |
| JMF | 0:24d3eb812fd4 | 486 | * @param payload_len length of payload buffer in bytes |
| JMF | 0:24d3eb812fd4 | 487 | * @param use_csma_ca should CSMA/CA be enabled for transmission |
| JMF | 0:24d3eb812fd4 | 488 | * |
| JMF | 0:24d3eb812fd4 | 489 | * @returns zero in case of success, non-zero error code otherwise |
| JMF | 0:24d3eb812fd4 | 490 | * |
| JMF | 0:24d3eb812fd4 | 491 | * @note the maximum payload size in bytes allowed is defined by macro 'SPIRIT1_MAX_PAYLOAD' |
| JMF | 0:24d3eb812fd4 | 492 | */ |
| JMF | 0:24d3eb812fd4 | 493 | int send(const void *payload, unsigned int payload_len, bool use_csma_ca = true); |
| JMF | 0:24d3eb812fd4 | 494 | |
| JMF | 0:24d3eb812fd4 | 495 | /** Copy received data into buffer |
| JMF | 0:24d3eb812fd4 | 496 | * |
| JMF | 0:24d3eb812fd4 | 497 | * @param buf pointer to buffer to be filled |
| JMF | 0:24d3eb812fd4 | 498 | * @param bufsize size of buffer |
| JMF | 0:24d3eb812fd4 | 499 | * |
| JMF | 0:24d3eb812fd4 | 500 | * @returns number of bytes copied into the buffer |
| JMF | 0:24d3eb812fd4 | 501 | * |
| JMF | 0:24d3eb812fd4 | 502 | * @note the buffer should be (at least) of size 'SPIRIT1_MAX_PAYLOAD' (in bytes). |
| JMF | 0:24d3eb812fd4 | 503 | */ |
| JMF | 0:24d3eb812fd4 | 504 | int read(void *buf, unsigned int bufsize); |
| JMF | 0:24d3eb812fd4 | 505 | |
| JMF | 0:24d3eb812fd4 | 506 | /** Perform a Clear-Channel Assessment (CCA) to find out whether the medium is idle or not. |
| JMF | 0:24d3eb812fd4 | 507 | * |
| JMF | 0:24d3eb812fd4 | 508 | * @returns 1 if the medium is busy. |
| JMF | 0:24d3eb812fd4 | 509 | */ |
| JMF | 0:24d3eb812fd4 | 510 | int channel_clear(void); |
| JMF | 0:24d3eb812fd4 | 511 | |
| JMF | 0:24d3eb812fd4 | 512 | /** Check if the radio driver has just received a packet |
| JMF | 0:24d3eb812fd4 | 513 | */ |
| JMF | 0:24d3eb812fd4 | 514 | int get_pending_packet(void); |
| JMF | 0:24d3eb812fd4 | 515 | |
| JMF | 0:24d3eb812fd4 | 516 | /** Is radio currently receiving |
| JMF | 0:24d3eb812fd4 | 517 | */ |
| JMF | 0:24d3eb812fd4 | 518 | bool is_receiving(void) { |
| JMF | 0:24d3eb812fd4 | 519 | return _is_receiving; |
| JMF | 0:24d3eb812fd4 | 520 | } |
| JMF | 0:24d3eb812fd4 | 521 | |
| JMF | 0:24d3eb812fd4 | 522 | /** Get latest value of RSSI (in dBm) |
| JMF | 0:24d3eb812fd4 | 523 | */ |
| JMF | 0:24d3eb812fd4 | 524 | float get_last_rssi_dbm(void) { |
| JMF | 0:24d3eb812fd4 | 525 | get_last_rssi_raw(); |
| JMF | 0:24d3eb812fd4 | 526 | return (-120.0+((float)(last_rssi-20))/2); |
| JMF | 0:24d3eb812fd4 | 527 | } |
| JMF | 0:24d3eb812fd4 | 528 | |
| JMF | 0:24d3eb812fd4 | 529 | /** Get latest value of RSSI (as Spirit1 raw value) |
| JMF | 0:24d3eb812fd4 | 530 | */ |
| JMF | 0:24d3eb812fd4 | 531 | uint8_t get_last_rssi_raw(void) { |
| JMF | 0:24d3eb812fd4 | 532 | if(last_rssi == 0) { |
| JMF | 0:24d3eb812fd4 | 533 | last_rssi = qi_get_rssi(); |
| JMF | 0:24d3eb812fd4 | 534 | } |
| JMF | 0:24d3eb812fd4 | 535 | return last_rssi; |
| JMF | 0:24d3eb812fd4 | 536 | } |
| JMF | 0:24d3eb812fd4 | 537 | |
| JMF | 0:24d3eb812fd4 | 538 | /** Get latest value of LQI (scaled to 8-bit) |
| JMF | 0:24d3eb812fd4 | 539 | */ |
| JMF | 0:24d3eb812fd4 | 540 | uint8_t get_last_sqi(void) { |
| JMF | 0:24d3eb812fd4 | 541 | const uint8_t max_sqi = 8 * ((SYNC_LENGTH>>1)+1); |
| JMF | 0:24d3eb812fd4 | 542 | if(last_sqi == 0) { |
| JMF | 0:24d3eb812fd4 | 543 | last_sqi = qi_get_sqi(); |
| JMF | 0:24d3eb812fd4 | 544 | } |
| JMF | 0:24d3eb812fd4 | 545 | if(last_sqi > max_sqi) last_sqi = max_sqi; |
| JMF | 0:24d3eb812fd4 | 546 | |
| JMF | 0:24d3eb812fd4 | 547 | return (last_sqi * 255 / max_sqi); |
| JMF | 0:24d3eb812fd4 | 548 | } |
| JMF | 0:24d3eb812fd4 | 549 | |
| JMF | 0:24d3eb812fd4 | 550 | /** Reset Board |
| JMF | 0:24d3eb812fd4 | 551 | */ |
| JMF | 0:24d3eb812fd4 | 552 | void reset_board() { |
| JMF | 0:24d3eb812fd4 | 553 | init(); |
| JMF | 0:24d3eb812fd4 | 554 | } |
| JMF | 0:24d3eb812fd4 | 555 | }; |