GSwifiInterface library (interface for GainSpan Wi-Fi GS1011 modules) Please see https://mbed.org/users/gsfan/notebook/GSwifiInterface/
Dependents: GSwifiInterface_HelloWorld GSwifiInterface_HelloServo GSwifiInterface_UDPEchoServer GSwifiInterface_UDPEchoClient ... more
Fork of WiflyInterface by
GainSpan Wi-Fi library
The GS1011/GS2100 is an ultra low power 802.11b wireless module from GainSpan.
mbed RTOS supported.
- about this library: http://mbed.org/users/gsfan/notebook/GSwifiInterface/
- about Wi-Fi module: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011/GS2100 シリーズ用のライブラリです。
mbed RTOS に対応しています。(mbed2.0)
- このライブラリについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- Wi-FIモジュールについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- UARTコマンド、SPIデータインターフェースに対応しました。(2019/09)
GSwifi/GSwifi_hal.cpp
- Committer:
- gsfan
- Date:
- 2019-09-24
- Revision:
- 22:d25a5a0d2497
- Parent:
- 19:d035412a7803
File content as of revision 22:d25a5a0d2497:
/* Copyright (C) 2013 gsfan, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "GSwifi.h" void GSwifi::setReset (bool flg) { if (flg) { // low _reset.output(); _reset = 0; } else { // high z _reset.input(); _reset.mode(PullNone); } } void GSwifi::setAlarm (bool flg) { if (_alarm == NULL) return; if (flg) { // low _alarm->output(); // low _alarm->write(0); } else { // high _alarm->input(); // high _alarm->mode(PullUp); } } void GSwifi::isrUart () { recvData(getUart()); } int GSwifi::getUart () { #ifdef CFG_UART_DIRECT return _uart->RBR; #else return _gs.getc(); #endif } void GSwifi::putUart (char c) { #ifdef CFG_UART_DIRECT while(!(_uart->LSR & (1<<5))); _uart->THR = c; #else _gs.putc(c); #endif } void GSwifi::setRts (bool flg) { if (flg) { // low if (_flow == 1) { #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC176X) || defined(TARGET_LPC11UXX) || defined(TARGET_LPC408X) _uart->MCR |= (1<<6); // RTSEN #endif } else if (_flow == 2) { if (_rts) { _rts->write(0); // low } } } else { // high if (_flow == 1) { #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC176X) || defined(TARGET_LPC11UXX) || defined(TARGET_LPC408X) _uart->MCR &= ~(1<<6); // RTS off _uart->MCR &= ~(1<<1); #endif } else if (_flow == 2) { if (_rts) { _rts->write(1); // high } } } } int GSwifi::lockUart (int ms) { Timer t; if (_state.mode != MODE_COMMAND) { t.start(); while (_state.mode != MODE_COMMAND) { if (t.read_ms() >= ms) { WARN("lock timeout (%d)\r\n", _state.mode); return -1; } } } #ifdef CFG_ENABLE_RTOS if (_mutexUart.lock(ms) != osOK) return -1; #endif if (_flow == 1) { #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC176X) || defined(TARGET_LPC11UXX) || defined(TARGET_LPC408X) if (!(_uart->MSR & (1<<4))) { // CTS check t.start(); while (!(_uart->MSR & (1<<4))) { if (t.read_ms() >= ms) { DBG("cts timeout\r\n"); return -1; } } } #endif } else if (_flow == 2) { if (_cts && _cts->read()) { // CTS check t.start(); while (_cts->read()) { if (t.read_ms() >= ms) { DBG("cts timeout\r\n"); return -1; } } } } setRts(false); return 0; } void GSwifi::unlockUart () { setRts(true); #ifdef CFG_ENABLE_RTOS _mutexUart.unlock(); #endif } void GSwifi::initUart (PinName cts, PinName rts, PinName alarm, int baud) { _baud = baud; if (_baud) _gs.baud(_baud); _gs.attach(this, &GSwifi::isrUart, Serial::RxIrq); _cts = NULL; _rts = NULL; _flow = 0; #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC176X) _uart = LPC_UART1; if (cts == p12) { // CTS input (P0_17) _uart->MCR |= (1<<7); // CTSEN LPC_PINCON->PINSEL1 &= ~(3 << 2); LPC_PINCON->PINSEL1 |= (1 << 2); // UART CTS } else if (cts != NC) { _cts = new DigitalIn(cts); } if (rts == P0_22) { // RTS output (P0_22) _uart->MCR |= (1<<6); // RTSEN LPC_PINCON->PINSEL1 &= ~(3 << 12); LPC_PINCON->PINSEL1 |= (1 << 12); // UART RTS _flow = 1; } else if (rts != NC) { _rts = new DigitalOut(rts); _flow = 2; } #elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11UXX) _uart = LPC_USART; if (cts == p21) { // CTS input (P0_7) _uart->MCR |= (1<<7); // CTSEN LPC_IOCON->PIO0_7 &= ~0x07; LPC_IOCON->PIO0_7 |= 0x01; // UART CTS } else if (cts != NC) { _cts = new DigitalIn(cts); } if (rts == p22) { // RTS output (P0_17) _uart->MCR |= (1<<6); // RTSEN LPC_IOCON->PIO0_17 &= ~0x07; LPC_IOCON->PIO0_17 |= 0x01; // UART RTS _flow = 1; } else if (rts != NC) { _rts = new DigitalOut(rts); _flow = 2; } #elif defined(TARGET_LPC4088) || defined(TARGET_LPC408X) _uart = (LPC_UART1_TypeDef*)LPC_UART2; if (cts != NC) { _cts = new DigitalIn(cts); } if (rts != NC) { _rts = new DigitalOut(rts); _flow = 2; } #else if (cts != NC) { _cts = new DigitalIn(cts); } if (rts != NC) { _rts = new DigitalOut(rts); _flow = 2; } #endif if (alarm != NC) { _alarm = new DigitalInOut(alarm); } else { _alarm = NULL; } } #ifdef CFG_SPI_DATAINTERFACE void GSwifi::putSpi (char c) { _spi.write(c); } void GSwifi::isrSpi () { char c; while (_wake == 1) { c = _spi.write(0xf5); recvData(c); } } int GSwifi::lockSpi (int ms) { Timer t; if (_state.mode != MODE_COMMAND) { t.start(); while (_state.mode != MODE_COMMAND) { if (t.read_ms() >= ms) { WARN("lock timeout (%d)\r\n", _state.mode); return -1; } } } #ifdef CFG_ENABLE_RTOS if (_mutexSpi.lock(ms) != osOK) return -1; #endif if (_wake.read()) { t.start(); while (_wake.read()) { if (t.read_ms() >= ms) { DBG("hostwake timeout\r\n"); return -1; } } } return 0; } void GSwifi::unlockSpi () { #ifdef CFG_ENABLE_RTOS _mutexSpi.unlock(); #endif } void GSwifi::initSpi (PinName cs, int freq) { _spi.format(8, 0); _spi.frequency(freq); _wake.mode(PullDown); _wake.rise(this, &GSwifi::isrSpi); #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC176X) if (cs == p8) { // SPI_1 (P0_6) LPC_PINCON->PINSEL0 &= ~(3 << 12); LPC_PINCON->PINSEL0 |= (2 << 12); // SSEL1 } else if (cs == p14) { // (SPI_0) P0_16 LPC_PINCON->PINSEL1 &= ~(3 << 0); LPC_PINCON->PINSEL1 |= (2 << 0); // SSEL0 } else if (cs == P1_21) { // (SPI_0) P1_21 LPC_PINCON->PINSEL3 &= ~(3 << 10); LPC_PINCON->PINSEL3 |= (3 << 10); // SSEL0 } #endif } #endif