├── .github └── FUNDING.yml ├── M66_TEST.ino ├── README.md ├── arduino_quectel_m66.png ├── boards.txt ├── cores └── opencpu │ ├── Arduino.h │ ├── Client.h │ ├── DEV.cpp │ ├── DEV.h │ ├── GPRS.cpp │ ├── GPRS.h │ ├── HardwareSerial.cpp │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── RilCLass.cpp │ ├── RilClass.h │ ├── RingBuffer.h │ ├── Server.h │ ├── Stream.cpp │ ├── Stream.h │ ├── Tone.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WMath.cpp │ ├── WProgram.h │ ├── WString.cpp │ ├── WString.h │ ├── api │ ├── AT_TOK.c │ ├── AT_TOK.h │ └── api.h │ ├── arduino_main.cpp │ ├── binary.h │ ├── cbuf.cpp │ ├── cbuf.h │ ├── constants.h │ ├── cpp_m66.ld │ ├── custom_config.c │ ├── custom_feature_def.h │ ├── custom_gpio_cfg.h │ ├── custom_heap_cfg.h │ ├── custom_sys_cfg.c │ ├── custom_task_cfg.h │ ├── dbg.c │ ├── dbg.h │ ├── dtostrf.c │ ├── dtostrf.h │ ├── fota │ ├── inc │ │ ├── fota_ftp.h │ │ ├── fota_http.h │ │ ├── fota_http_code.h │ │ └── fota_main.h │ └── src │ │ ├── fota_ftp.c │ │ ├── fota_http.c │ │ ├── fota_http_code.c │ │ └── fota_main.c │ ├── include │ ├── nema_pro.h │ ├── ql_adc.h │ ├── ql_clock.h │ ├── ql_common.h │ ├── ql_eint.h │ ├── ql_error.h │ ├── ql_fota.h │ ├── ql_fs.h │ ├── ql_gpio.h │ ├── ql_gprs.h │ ├── ql_iic.h │ ├── ql_memory.h │ ├── ql_power.h │ ├── ql_pwm.h │ ├── ql_socket.h │ ├── ql_spi.h │ ├── ql_stdlib.h │ ├── ql_system.h │ ├── ql_time.h │ ├── ql_timer.h │ ├── ql_trace.h │ ├── ql_type.h │ ├── ql_uart.h │ └── ql_wtd.h │ ├── interface.c │ ├── interface.h │ ├── lib_M66FAR01A12BT.a │ ├── lib_app_start_m66.a │ ├── new.cpp │ ├── new.h │ ├── pgmspace.h │ ├── ril │ ├── inc │ │ ├── lib_ril_sms.h │ │ ├── ril.h │ │ ├── ril_alarm.h │ │ ├── ril_audio.h │ │ ├── ril_bluetooth.h │ │ ├── ril_dtmf.h │ │ ├── ril_ftp.h │ │ ├── ril_http.h │ │ ├── ril_location.h │ │ ├── ril_network.h │ │ ├── ril_ntp.h │ │ ├── ril_sim.h │ │ ├── ril_sms.h │ │ ├── ril_system.h │ │ ├── ril_telephony.h │ │ └── ril_util.h │ └── src │ │ ├── ril_alarm.c │ │ ├── ril_atResponse.c │ │ ├── ril_audio.c │ │ ├── ril_bluetooth.c │ │ ├── ril_custom.c │ │ ├── ril_dtmf.c │ │ ├── ril_ftp.c │ │ ├── ril_http.c │ │ ├── ril_init.c │ │ ├── ril_location.c │ │ ├── ril_network.c │ │ ├── ril_ntp.c │ │ ├── ril_sim.c │ │ ├── ril_sms.c │ │ ├── ril_system.c │ │ ├── ril_telephony.c │ │ ├── ril_urc.c │ │ └── ril_util.c │ ├── wiring.c │ ├── wiring_analog.c │ ├── wiring_digital.c │ ├── wiring_pulse.c │ └── wiring_shift.c ├── libraries ├── EEPROM │ ├── examples │ │ ├── eeprom_clear │ │ │ └── eeprom_clear.ino │ │ ├── eeprom_crc │ │ │ └── eeprom_crc.ino │ │ ├── eeprom_get │ │ │ └── eeprom_get.ino │ │ ├── eeprom_iteration │ │ │ └── eeprom_iteration.ino │ │ ├── eeprom_put │ │ │ └── eeprom_put.ino │ │ ├── eeprom_read │ │ │ └── eeprom_read.ino │ │ ├── eeprom_update │ │ │ └── eeprom_update.ino │ │ └── eeprom_write │ │ │ └── eeprom_write.ino │ ├── library.properties │ └── src │ │ ├── EEPROM.cpp │ │ └── EEPROM.h ├── Ethernet │ ├── examples │ │ └── tcp_http │ │ │ └── tcp_http.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── gprsClient.cpp │ │ ├── gprsClient.h │ │ ├── gprsDNS.cpp │ │ ├── gprsDNS.h │ │ ├── gprsUdp.cpp │ │ └── gprsUdp.h ├── GSM │ ├── library.properties │ └── src │ │ ├── GSM.cpp │ │ ├── GSM.h │ │ ├── Modem.cpp │ │ ├── Modem.h │ │ ├── PIN.cpp │ │ ├── PIN.h │ │ ├── SMS.cpp │ │ └── SMS.h ├── SPI │ ├── library.properties │ └── src │ │ ├── LICENSE │ │ ├── SPI.cpp │ │ └── SPI.h ├── Timer │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── GPTimer.cpp │ │ └── GPTimer.h └── Wire │ ├── library.properties │ └── src │ ├── Wire.cpp │ └── Wire.h ├── platform.txt ├── programmers.txt ├── tools ├── M66FAR01A12BT.zip ├── README.md ├── m66_core.2.0.0.zip ├── m66_tools.1.0.zip └── package_wizio.m66_index.json └── variants └── m66 ├── variant.cpp ├── variant.h └── variant_pins.c /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ESUP9LCZMZTD6 13 | -------------------------------------------------------------------------------- /M66_TEST.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Quectel M66 - Test 3 | Created on: 01.04.2019 4 | Author: Georgi Angelov 5 | */ 6 | 7 | void setup() 8 | { 9 | int t = millis(); 10 | String imei; 11 | 12 | Serial.begin(115200); 13 | Serial.debug(); // enable debug for this port, DBG( work as printf ) 14 | 15 | Serial.printf("Arduino %s\n", Dev.getVersion()); 16 | Dev.getImei(imei); 17 | Serial.printf("IMEI %s\n", imei.c_str()); 18 | 19 | Dev.waitSimReady(); 20 | Serial.printf("SIM Ready\n"); 21 | 22 | Dev.waitCereg(); // wait GREG and CGREG 23 | delay(200); 24 | Serial.printf("NET Ready\n"); 25 | 26 | pinMode(LED, OUTPUT); 27 | digitalWrite(LED, 1); 28 | Serial.printf("Elapsed: %d mili seconds\n", millis() - t); 29 | } 30 | 31 | void loop() 32 | { 33 | static int led = 0; 34 | delay(200); 35 | Serial.print(">"); 36 | digitalWrite(LED, ++led & 1); 37 | /* loop must be state machine, dont make long delays */ 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino for Quectel M66 GPRS modules 2 | ... and [Quectel development platform for PlatformIO](https://github.com/Wiz-IO/platform-quectel) v 2.0.0 3 | (must be full Arduino compatible) 4 | 5 | **A few words in the beginning** 6 | * **Version 2.0.0** ... beta, not everything tested... 7 | * This project not an official product of Quectel / Mediatek 8 | * The project is based on Quectel OpenCPU and **reverse engineering** 9 | 10 | **Chipset Mediatek MD2503 SoC** 11 | 12 | https://www.mediatek.com/products/ 13 | 14 | 15 | **Module: Quectel M66** 16 | 17 | https://www.quectel.com/product/m66.htm 18 | * you need firmware **M66FAR01A12BT** 19 | 20 | 21 | **Videos** 22 | 23 | https://www.youtube.com/watch?v=sQMidyRvn2A 24 | 25 | https://www.youtube.com/channel/UCNOuJcC5qgU-SrtUwyqmtJQ?view_as=subscriber 26 | 27 | ![Arduino Quectel M66](https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/master/arduino_quectel_m66.png) 28 | 29 | ## Install 30 | 31 | * Add json link to Arduino - Preferences 32 | 33 | https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/master/tools/package_wizio.m66_index.json 34 | 35 | * Open Borad Manager, Find WizIO, Install OR Update (remove old versions) 36 | * Select Board 37 | * Select Firmware 38 | * Click [Compile] or [Upload] 39 | 40 | 41 | >If you want to help / support: 42 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ESUP9LCZMZTD6) 43 | -------------------------------------------------------------------------------- /arduino_quectel_m66.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/arduino_quectel_m66.png -------------------------------------------------------------------------------- /boards.txt: -------------------------------------------------------------------------------- 1 | # WizIO 2018 Georgi Angelov 2 | # https://github.com/Wiz-IO/Arduino-Quectel-M66 3 | # the.wizarda@gmail.com 4 | # 5 | # Arduino Core and platform. 6 | # For more info: 7 | # https:\\github.com\arduino\Arduino\wiki\Arduino-IDE-1.5---3rd-party-Hardware-specification 8 | 9 | menu.firmware=Firmware 10 | 11 | M66.build.core=opencpu 12 | M66.build.variant=m66 13 | M66.name=Quectel M66 Module 14 | M66.build.board=Quectel M66 15 | M66.build.compiler_path={runtime.tools.m66_gcc.path}\bin\ 16 | M66.build.mcu=-march=armv5te -mfloat-abi=soft -mfpu=vfp -mthumb-interwork 17 | M66.build.extra_flags= 18 | M66.build.f_cpu=260000000L 19 | 20 | M66.menu.firmware.V1=M66FAR01A12BT 21 | M66.menu.firmware.V1.build.firmware=M66FAR01A12BT 22 | 23 | M66.upload.maximum_size=368640 24 | M66.upload.maximum_data_size=102400 25 | M66.upload.tool=m66 26 | M66.upload.protocol=quectel 27 | M66.upload.use_1200bps_touch=false 28 | M66.upload.wait_for_upload_port=false 29 | M66.upload.native_usb=false 30 | M66.upload.via_ssh=false 31 | 32 | 33 | -------------------------------------------------------------------------------- /cores/opencpu/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.h - Main include file for the Arduino SDK 3 | Copyright (c) 2005-2013 Arduino Team. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 28 September 2018 by Georgi Angelov 20 | */ 21 | 22 | #ifndef Arduino_h 23 | #define Arduino_h 24 | 25 | #include 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" 30 | { 31 | #endif 32 | 33 | #include "pgmspace.h" 34 | #include "binary.h" 35 | #include "constants.h" 36 | 37 | unsigned int seconds(void); 38 | unsigned int millis(void); 39 | unsigned int micros(void); 40 | void delay(unsigned int); 41 | void delayMicroseconds(unsigned int us); 42 | 43 | void pinMode(uint8_t, uint8_t); 44 | void digitalWrite(uint8_t, uint8_t); 45 | int digitalRead(uint8_t); 46 | 47 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 48 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 49 | 50 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) __attribute__((weak)); 51 | unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout) __attribute__((weak)); 52 | 53 | void yield(void) __attribute__((weak)); 54 | void interrupts(void) __attribute__((weak)); 55 | void noInterrupts(void) __attribute__((weak)); 56 | void attachInterrupt(uint8_t, void (*)(void), int mode) __attribute__((weak)); 57 | void detachInterrupt(uint8_t) __attribute__((weak)); 58 | 59 | #ifdef __cplusplus 60 | } // extern "C" 61 | 62 | //////////////////////////////////////////////////////////////////////////////////////////////// 63 | 64 | #include "WCharacter.h" 65 | #include "WString.h" 66 | 67 | long random(long); 68 | long random(long howsmall, long howbig); 69 | void randomSeed(unsigned long seed); 70 | long map(long x, long in_min, long in_max, long out_min, long out_max); 71 | unsigned int makeWord(unsigned int w); 72 | unsigned int makeWord(unsigned char h, unsigned char l); 73 | 74 | void noTone(uint8_t _pin) __attribute__((weak)); 75 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0) __attribute__((weak)); 76 | 77 | #endif //__cplusplus 78 | 79 | #endif //Arduino_h 80 | -------------------------------------------------------------------------------- /cores/opencpu/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /cores/opencpu/DEV.cpp: -------------------------------------------------------------------------------- 1 | #include "DEV.h" 2 | 3 | void DeviceClass::getImsi(char *buffer, uint32_t size) 4 | { 5 | if (buffer && size > 15) 6 | { 7 | memset(buffer, 0, size); 8 | api_getIMSI(buffer); 9 | } 10 | } 11 | 12 | void DeviceClass::getImsi(String &s) 13 | { 14 | char buffer[16]; 15 | memset(buffer, 0, 16); 16 | api_getIMSI(buffer); 17 | s = buffer; 18 | } 19 | 20 | void DeviceClass::getImei(char *buffer, uint32_t size) 21 | { 22 | if (buffer && size > 15) 23 | { 24 | memset(buffer, 0, size); 25 | api_getIMEI(buffer); 26 | } 27 | } 28 | 29 | void DeviceClass::getImei(String &s) 30 | { 31 | char buffer[16]; 32 | memset(buffer, 0, 16); 33 | api_getIMEI(buffer); 34 | s = buffer; 35 | } 36 | 37 | int DeviceClass::getSimStatus() 38 | { 39 | return api_getSimStatus(); // 0 = READY, 40 | } 41 | 42 | void DeviceClass::enterPin(const char *pin) 43 | { 44 | int res; 45 | if (pin) 46 | { 47 | Dev.ril.sendf("AP+CPIN =\"%s\"", pin); 48 | if (ril.waitForResponse() == 1) 49 | return; 50 | } 51 | TRACE("[PIN] ERROR\n"); 52 | while (true) 53 | Ql_Sleep(1000); 54 | } 55 | 56 | void DeviceClass::waitSimReady(const char *pin) 57 | { 58 | int status; 59 | do 60 | { 61 | delayEx(100); 62 | status = api_getSimStatus(); 63 | if (status == -666) // TODO status enum 64 | enterPin(pin); 65 | } while (0 != status); 66 | } 67 | 68 | void DeviceClass::waitCreg() 69 | { 70 | while (1) 71 | { 72 | int res = getCreg(); 73 | if (res == 5 || res == 1) 74 | break; 75 | delayEx(100); 76 | } 77 | } 78 | 79 | void DeviceClass::waitCgreg() 80 | { 81 | while (1) 82 | { 83 | int res = getCgreg(); 84 | if (res == 5 || res == 1) 85 | break; 86 | delayEx(100); 87 | } 88 | } 89 | 90 | void DeviceClass::waitCereg(){ 91 | waitCreg(); 92 | delay(200); 93 | waitCgreg(); 94 | delay(200); 95 | } 96 | 97 | DeviceClass Dev; -------------------------------------------------------------------------------- /cores/opencpu/DEV.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEV_H__ 2 | #define __DEV_H__ 3 | 4 | #include 5 | #include "RilClass.h" 6 | extern HardwareSerial Virtual; 7 | 8 | typedef void (*vCallback)(void); 9 | typedef void (*uCallback)(u32, u32); 10 | typedef void (*mCallback)(ST_MSG *msg); 11 | 12 | class DeviceClass 13 | { 14 | public: 15 | DeviceClass() 16 | { 17 | onMessage = NULL; 18 | onUrc = NULL; 19 | wtdID = -1; 20 | } 21 | 22 | RilClass ril = RilClass(Virtual); 23 | RilClass &operator=(RilClass &ril); 24 | void begin() 25 | { 26 | ril.begin(); 27 | } 28 | 29 | mCallback onMessage; 30 | void m_Message(ST_MSG *m) 31 | { 32 | if (onMessage) 33 | onMessage(m); 34 | } 35 | 36 | uCallback onUrc; 37 | void m_Urc(u32 urc, u32 data) 38 | { 39 | if (onUrc) 40 | onUrc(urc, data); 41 | } 42 | 43 | const char *getVersion() { return api_getVersion(); } 44 | void getImsi(char *imsi, uint32_t size = 16); 45 | void getImsi(String &s); 46 | 47 | void getImei(char *imei, uint32_t size = 16); 48 | void getImei(String &s); 49 | 50 | int getSimStatus(); 51 | void waitSimReady(const char *pin = NULL); 52 | void enterPin(const char *pin); 53 | 54 | int getCreg() { return api_getNetworkState(1); } 55 | void waitCreg(); 56 | 57 | int getCgreg() { return api_getNetworkState(2); } 58 | void waitCgreg(); 59 | void waitCereg(); 60 | 61 | void reset() { Ql_Reset(0); } 62 | void powerOff() { Ql_PowerDown(1); } 63 | int powerReason() { return Ql_GetPowerOnReason(); } 64 | void Sleep() { Ql_SleepEnable(); } 65 | void noSleep() { Ql_SleepDisable(); } 66 | 67 | ///for pin pulse 68 | int watchdog(uint8_t pin, unsigned int interval = 1000) 69 | { 70 | if (interval < 200) 71 | interval == 200; 72 | //A2Q(pin); 73 | return Ql_WTD_Init(0, (Enum_PinName)pin, interval); 74 | } 75 | ///internal watchdog 76 | void beginWatchdog(unsigned int interval = 1000) 77 | { 78 | if (interval < 400) 79 | interval = 400; 80 | wtdID = Ql_WTD_Start(interval); 81 | } 82 | void endWatchdog() 83 | { 84 | if (wtdID > 0) 85 | Ql_WTD_Stop(wtdID); 86 | } 87 | void kickWatchdog() 88 | { 89 | if (wtdID > 0) 90 | Ql_WTD_Feed(wtdID); 91 | } 92 | 93 | private: 94 | int wtdID; 95 | }; 96 | 97 | extern DeviceClass Dev; 98 | 99 | #endif //__DEV_H__ -------------------------------------------------------------------------------- /cores/opencpu/GPRS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void GPRS::onActive(u8 id, s32 ret, void *gprs) 4 | { 5 | DEBUG_GPRS("onActive( %d %d )", id, ret); 6 | if (gprs) 7 | { 8 | GPRS *p = (GPRS *)gprs; 9 | p->result = (ret == GPRS_PDP_ALREADY || ret == GPRS_PDP_SUCCESS); 10 | Ql_OS_SetEvent(p->event, 1); 11 | } 12 | } 13 | 14 | void GPRS::onDeactive(u8 id, s32 ret, void *user) 15 | { 16 | DEBUG_GPRS("onDeactivedGPRS( %d %d )", id, ret); 17 | } 18 | 19 | bool GPRS::act(bool blocked) 20 | { 21 | int r = Ql_GPRS_ActivateEx(id, blocked); // 150 sec 22 | if (GPRS_PDP_SUCCESS == r || GPRS_PDP_SUCCESS == r) 23 | return true; 24 | DEBUG_GPRS("Ql_GPRS_ActivateEx( %d ) = %d", id, r); 25 | //todo non-blocked 26 | Ql_OS_WaitEvent(event, 1); 27 | return result; 28 | } 29 | 30 | bool GPRS::deact(void) 31 | { 32 | int r = Ql_GPRS_Deactivate(id); 33 | if (GPRS_PDP_SUCCESS == r || GPRS_PDP_SUCCESS == r) 34 | return true; 35 | DEBUG_GPRS("Ql_GPRS_Deactivate( %d ) = %d", id, r); // 2 = GPRS_PDP_WOULDBLOCK 36 | //todo non-blocked 37 | Ql_OS_WaitEvent(event, 1); 38 | return result; 39 | } 40 | 41 | bool GPRS::begin(const char *name, const char *user, const char *pass) 42 | { 43 | if (name) 44 | Ql_snprintf((char *)st_apn.apnName, sizeof(st_apn.apnName), name); 45 | else 46 | Ql_snprintf((char *)st_apn.apnName, sizeof(st_apn.apnName), "name"); 47 | 48 | if (user) 49 | Ql_snprintf((char *)st_apn.apnUserId, sizeof(st_apn.apnUserId), user); 50 | else 51 | Ql_snprintf((char *)st_apn.apnUserId, sizeof(st_apn.apnUserId), "user"); 52 | 53 | if (pass) 54 | Ql_snprintf((char *)st_apn.apnUserId, sizeof(st_apn.apnUserId), pass); 55 | else 56 | Ql_snprintf((char *)st_apn.apnUserId, sizeof(st_apn.apnUserId), "pass"); 57 | if (0 == event) 58 | event = Ql_OS_CreateEvent((char *)"GPRS_EVENT"); 59 | int res = Ql_GPRS_Config(id, &st_apn); 60 | return (res == GPRS_PDP_ALREADY || res == GPRS_PDP_SUCCESS); 61 | } 62 | bool GPRS::begin() 63 | { 64 | return begin(NULL, NULL, NULL); 65 | } 66 | 67 | bool GPRS::begin(const char *name) 68 | { 69 | return begin(name, NULL, NULL); 70 | } 71 | 72 | GPRS gprs(0); -------------------------------------------------------------------------------- /cores/opencpu/GPRS.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DEBUG_GPRS(F, ...) DBG("[GPRS] " F "\n", ##__VA_ARGS__) 4 | 5 | class GPRS 6 | { 7 | protected: 8 | u8 id; 9 | ST_PDPContxt_Callback st_callbacks; 10 | ST_GprsConfig st_apn; 11 | static void onDeactive(u8 id, s32 ret, void *gprs); 12 | static void onActive(u8 id, s32 ret, void *gprs); 13 | bool result; 14 | u32 event; 15 | 16 | public: 17 | GPRS(u8 context) 18 | { 19 | id = context; 20 | result = -1; 21 | st_callbacks.Callback_GPRS_Actived = onActive; 22 | st_callbacks.CallBack_GPRS_Deactived = onDeactive; 23 | Ql_snprintf((char *)st_apn.apnName, sizeof(st_apn.apnName), "name"); 24 | Ql_snprintf((char *)st_apn.apnUserId, sizeof(st_apn.apnUserId), "user"); 25 | Ql_snprintf((char *)st_apn.apnUserId, sizeof(st_apn.apnUserId), "pass"); 26 | event = Ql_OS_CreateEvent((char *)"GPRS_EVENT"); 27 | Ql_GPRS_Config(id, &st_apn); 28 | Ql_GPRS_Register(context, &st_callbacks, this); 29 | }; 30 | bool begin(); 31 | bool begin(const char *apn); 32 | bool begin(const char *apn, const char *name, const char *pass); 33 | bool act(bool blocked = true); // blocking mode 34 | bool deact(void); 35 | bool acted; 36 | }; 37 | 38 | extern GPRS gprs; 39 | -------------------------------------------------------------------------------- /cores/opencpu/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.01.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #include 7 | #include 8 | #include "Arduino.h" 9 | #include 10 | 11 | #define DEBUG_UART TRACE 12 | 13 | extern "C" void debug_enable(unsigned long port); 14 | extern "C" void debug_disable(void); 15 | 16 | void HardwareSerial::debug(void) 17 | { 18 | debug_enable(port); 19 | } 20 | 21 | void HardwareSerial::nodebug(void) 22 | { 23 | debug_disable(); 24 | } 25 | 26 | /*static*/ void HardwareSerial::callback(Enum_SerialPort port, Enum_UARTEventType event, bool pinLevel, void *serial) 27 | { 28 | //DBG("[UART] callback port=%d, event=%d\n", port, event); 29 | if (NULL == serial) 30 | return; 31 | if (event == EVENT_UART_READY_TO_READ) 32 | { 33 | uint8_t c; 34 | HardwareSerial *p = (HardwareSerial *)serial; 35 | while (Ql_UART_Read((Enum_SerialPort)port, &c, 1) > 0) 36 | { 37 | //DEBUG_UART("%c", c); 38 | if (p->save(c)) 39 | return; 40 | } 41 | } 42 | } 43 | 44 | HardwareSerial::HardwareSerial(uint32_t id) 45 | { 46 | port = (Enum_SerialPort)id; 47 | _rx_buffer_head = _rx_buffer_tail = 0; 48 | } 49 | 50 | void HardwareSerial::begin(unsigned long baud, void *config) // TODO 51 | { 52 | _rx_buffer_head = _rx_buffer_tail = 0; 53 | Ql_memset(_rx_buffer, 0, SERIAL_RX_BUFFER_SIZE); 54 | int res = Ql_UART_Register(port, (CallBack_UART_Notify)this->callback, this); 55 | DEBUG_UART("Ql_UART_Register( %d ) = %d\n", port, res); 56 | if (config) 57 | res = Ql_UART_OpenEx(port, (ST_UARTDCB *)config); 58 | else 59 | res = Ql_UART_Open(port, baud, FC_NONE); 60 | DEBUG_UART("Ql_UART_Open( %d ) = %d\n", port, res); 61 | } 62 | 63 | void HardwareSerial::begin(unsigned long baud) 64 | { 65 | begin(baud, NULL); 66 | } 67 | 68 | void HardwareSerial::end() 69 | { 70 | Ql_UART_Close(port); 71 | DEBUG_UART("Ql_UART_Close( %d )\n", port); 72 | _rx_buffer_head = _rx_buffer_tail; 73 | } 74 | 75 | size_t HardwareSerial::write(uint8_t c) 76 | { 77 | //DEBUG_UART("> %c\n", c); 78 | return Ql_UART_Write(port, &c, 1); 79 | } 80 | 81 | size_t HardwareSerial::write(const uint8_t *buf, size_t size) 82 | { 83 | if (buf && size) 84 | { 85 | //DEBUG_UART("> %s\n", buf); 86 | return Ql_UART_Write(port, (uint8_t *)buf, size); 87 | } 88 | return 0; 89 | } 90 | 91 | int HardwareSerial::available(void) 92 | { 93 | return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE; 94 | } 95 | 96 | int HardwareSerial::peek(void) 97 | { 98 | if (_rx_buffer_head == _rx_buffer_tail) 99 | return -1; 100 | else 101 | return _rx_buffer[_rx_buffer_tail]; 102 | } 103 | 104 | int HardwareSerial::read(void) 105 | { 106 | if (_rx_buffer_head == _rx_buffer_tail) 107 | { 108 | return -1; 109 | } 110 | else 111 | { 112 | unsigned char c = _rx_buffer[_rx_buffer_tail]; 113 | _rx_buffer_tail = (buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE; 114 | return c; 115 | } 116 | } 117 | 118 | void HardwareSerial::clear(int who) 119 | { 120 | if (who & 0x10) 121 | { 122 | Ql_UART_ClrTxBuffer(port); 123 | } 124 | if (who & 0x01) 125 | { 126 | Ql_UART_ClrRxBuffer(port); 127 | _rx_buffer_head = _rx_buffer_tail = 0; 128 | Ql_memset(_rx_buffer, 0, SERIAL_RX_BUFFER_SIZE); 129 | } 130 | } 131 | 132 | int HardwareSerial::save(uint8_t c) 133 | { 134 | uint32_t i = (uint32_t)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE; 135 | if (i != _rx_buffer_tail) 136 | { 137 | _rx_buffer[_rx_buffer_head] = c; 138 | _rx_buffer_head = i; 139 | return 0; // saved 140 | } 141 | return 1; // full 142 | } -------------------------------------------------------------------------------- /cores/opencpu/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.01.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #ifndef HardwareSerial_h 7 | #define HardwareSerial_h 8 | 9 | #include 10 | #include 11 | 12 | #define SERIAL_RX_BUFFER_SIZE 256 13 | typedef uint8_t buffer_index_t; 14 | 15 | class HardwareSerial : public Stream 16 | { 17 | protected: 18 | static void callback(Enum_SerialPort port, Enum_UARTEventType event, bool pinLevel, void *serial); 19 | Enum_SerialPort port; 20 | 21 | volatile buffer_index_t _rx_buffer_head; 22 | volatile buffer_index_t _rx_buffer_tail; 23 | unsigned _rx_buffer[SERIAL_RX_BUFFER_SIZE]; 24 | 25 | public: 26 | int save(uint8_t c); 27 | HardwareSerial(uint32_t id); 28 | void debug(void); 29 | void nodebug(void); 30 | void begin(unsigned long baud, void *user); 31 | void begin(unsigned long baud); 32 | void end(); 33 | size_t setRxBufferSize(size_t new_size); 34 | void clear(int who = -1); //ALL, x01=rx, x10=tx 35 | virtual int available(void); 36 | virtual int peek(void); 37 | virtual int read(void); 38 | virtual void flush(void){}; 39 | virtual size_t write(uint8_t); 40 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 41 | inline size_t write(long n) { return write((uint8_t)n); } 42 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 43 | inline size_t write(int n) { return write((uint8_t)n); } 44 | size_t write(const char *buf); 45 | size_t write(const uint8_t *buf, size_t size); 46 | using Print::write; 47 | operator bool() { return true; } 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /cores/opencpu/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.cpp - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | IPAddress::IPAddress() 24 | { 25 | _address.dword = 0; 26 | } 27 | 28 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 29 | { 30 | _address.bytes[0] = first_octet; 31 | _address.bytes[1] = second_octet; 32 | _address.bytes[2] = third_octet; 33 | _address.bytes[3] = fourth_octet; 34 | } 35 | 36 | IPAddress::IPAddress(uint32_t address) 37 | { 38 | _address.dword = address; 39 | } 40 | 41 | IPAddress::IPAddress(const uint8_t *address) 42 | { 43 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 44 | } 45 | 46 | bool IPAddress::fromString(const char *address) 47 | { 48 | uint16_t acc = 0; // Accumulator 49 | uint8_t dots = 0; 50 | 51 | while (*address) 52 | { 53 | char c = *address++; 54 | if (c >= '0' && c <= '9') 55 | { 56 | acc = acc * 10 + (c - '0'); 57 | if (acc > 255) 58 | { 59 | // Value out of [0..255] range 60 | return false; 61 | } 62 | } 63 | else if (c == '.') 64 | { 65 | if (dots == 3) 66 | { 67 | // Too much dots (there must be 3 dots) 68 | return false; 69 | } 70 | _address.bytes[dots++] = acc; 71 | acc = 0; 72 | } 73 | else 74 | { 75 | // Invalid char 76 | return false; 77 | } 78 | } 79 | 80 | if (dots != 3) 81 | { 82 | // Too few dots (there must be 3 dots) 83 | return false; 84 | } 85 | _address.bytes[3] = acc; 86 | return true; 87 | } 88 | 89 | IPAddress &IPAddress::operator=(const uint8_t *address) 90 | { 91 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 92 | return *this; 93 | } 94 | 95 | IPAddress &IPAddress::operator=(uint32_t address) 96 | { 97 | _address.dword = address; 98 | return *this; 99 | } 100 | 101 | bool IPAddress::operator==(const uint8_t *addr) const 102 | { 103 | return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; 104 | } 105 | 106 | size_t IPAddress::printTo(Print &p) const 107 | { 108 | size_t n = 0; 109 | for (int i = 0; i < 3; i++) 110 | { 111 | n += p.print(_address.bytes[i], DEC); 112 | n += p.print('.'); 113 | } 114 | n += p.print(_address.bytes[3], DEC); 115 | return n; 116 | } 117 | 118 | String IPAddress::toString() const 119 | { 120 | char szRet[16]; 121 | sprintf(szRet,"%u.%u.%u.%u", _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3]); 122 | return String(szRet); 123 | } -------------------------------------------------------------------------------- /cores/opencpu/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.h - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef IPAddress_h 21 | #define IPAddress_h 22 | 23 | #include 24 | #include "Printable.h" 25 | #include "WString.h" 26 | 27 | // A class to make it easier to handle and pass around IP addresses 28 | 29 | class IPAddress : public Printable { 30 | private: 31 | union { 32 | uint8_t bytes[4]; // IPv4 address 33 | uint32_t dword; 34 | } _address; 35 | 36 | // Access the raw byte array containing the address. Because this returns a pointer 37 | // to the internal structure rather than a copy of the address this function should only 38 | // be used when you know that the usage of the returned uint8_t* will be transient and not 39 | // stored. 40 | uint8_t* raw_address() { return _address.bytes; }; 41 | 42 | public: 43 | // Constructors 44 | IPAddress(); 45 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 46 | IPAddress(uint32_t address); 47 | IPAddress(const uint8_t *address); 48 | 49 | bool fromString(const char *address); 50 | bool fromString(const String &address) { return fromString(address.c_str()); } 51 | 52 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 53 | // to a four-byte uint8_t array is expected 54 | operator uint32_t() const { return _address.dword; }; 55 | bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; 56 | bool operator==(const uint8_t* addr) const; 57 | 58 | // Overloaded index operator to allow getting and setting individual octets of the address 59 | uint8_t operator[](int index) const { return _address.bytes[index]; }; 60 | uint8_t& operator[](int index) { return _address.bytes[index]; }; 61 | 62 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 63 | IPAddress& operator=(const uint8_t *address); 64 | IPAddress& operator=(uint32_t address); 65 | 66 | virtual size_t printTo(Print& p) const; 67 | String toString() const; 68 | 69 | friend class EthernetClass; 70 | friend class UDP; 71 | friend class Client; 72 | friend class Server; 73 | friend class DhcpClass; 74 | friend class DNSClient; 75 | }; 76 | 77 | //const IPAddress INADDR_NONE(0,0,0,0); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /cores/opencpu/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar 33 | #undef BIN 34 | #endif 35 | #define BIN 2 36 | 37 | class Print 38 | { 39 | private: 40 | int write_error; 41 | size_t printNumber(unsigned long, uint8_t); 42 | size_t printFloat(double, uint8_t); 43 | protected: 44 | void setWriteError(int err = 1) { write_error = err; } 45 | public: 46 | Print() : write_error(0) {} 47 | 48 | int getWriteError() { return write_error; } 49 | void clearWriteError() { setWriteError(0); } 50 | 51 | virtual size_t write(uint8_t) = 0; 52 | size_t write(const char *str) { 53 | if (str == NULL) return 0; 54 | return write((const uint8_t *)str, strlen(str)); 55 | } 56 | virtual size_t write(const uint8_t *buffer, size_t size); 57 | size_t write(const char *buffer, size_t size) { 58 | return write((const uint8_t *)buffer, size); 59 | } 60 | 61 | // default to zero, meaning "a single write may block" 62 | // should be overriden by subclasses with buffering 63 | virtual int availableForWrite() { return 0; } 64 | 65 | size_t print(const __FlashStringHelper *); 66 | size_t print(const String &); 67 | size_t print(const char[]); 68 | size_t print(char); 69 | size_t print(unsigned char, int = DEC); 70 | size_t print(int, int = DEC); 71 | size_t print(unsigned int, int = DEC); 72 | size_t print(long, int = DEC); 73 | size_t print(unsigned long, int = DEC); 74 | size_t print(double, int = 2); 75 | size_t print(const Printable&); 76 | 77 | size_t println(const __FlashStringHelper *); 78 | size_t println(const String &s); 79 | size_t println(const char[]); 80 | size_t println(char); 81 | size_t println(unsigned char, int = DEC); 82 | size_t println(int, int = DEC); 83 | size_t println(unsigned int, int = DEC); 84 | size_t println(long, int = DEC); 85 | size_t println(unsigned long, int = DEC); 86 | size_t println(double, int = 2); 87 | size_t println(const Printable&); 88 | size_t println(void); 89 | 90 | size_t printf(const char *format, ...); 91 | 92 | virtual void flush() { /* Empty implementation for backward compatibility */ } 93 | }; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /cores/opencpu/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /cores/opencpu/RilCLass.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "RilClass.h" 3 | 4 | #define RIL_MIN_RESPONSE_OR_URC_WAIT_TIME_MS 20 5 | 6 | RilClass::RilClass(HardwareSerial &uart) : _uart(&uart), 7 | _atCommandState(AT_COMMAND_IDLE), 8 | _ready(1), 9 | _responseDataStorage(NULL) 10 | { 11 | _buffer.reserve(256); 12 | } 13 | 14 | int RilClass::noop() 15 | { 16 | send("AT"); 17 | return (waitForResponse() == 1); 18 | } 19 | 20 | int RilClass::single(const char *command) 21 | { 22 | send(command); 23 | return (waitForResponse() == 1); 24 | } 25 | 26 | size_t RilClass::write(uint8_t c) 27 | { 28 | return _uart->write(c); 29 | } 30 | 31 | size_t RilClass::write(const uint8_t *buf, size_t size) 32 | { 33 | return _uart->write(buf, size); 34 | } 35 | 36 | void RilClass::send(const char *command) 37 | { 38 | TRACE("[RIL] Send: %s\n", command); 39 | _uart->clear(); 40 | _uart->println(command); 41 | _atCommandState = AT_COMMAND_IDLE; 42 | _ready = 0; 43 | } 44 | 45 | void RilClass::sendf(const char *fmt, ...) 46 | { 47 | char buf[BUFSIZ]; 48 | va_list ap; 49 | va_start((ap), (fmt)); 50 | vsnprintf(buf, sizeof(buf) - 1, fmt, ap); 51 | va_end(ap); 52 | send(buf); 53 | } 54 | 55 | int RilClass::waitForResponse(unsigned long timeout, String *responseDataStorage) 56 | { 57 | _responseDataStorage = responseDataStorage; 58 | for (unsigned long start = millis(); (millis() - start) < timeout;) 59 | { 60 | int r = ready(); 61 | if (r != 0) 62 | { 63 | _responseDataStorage = NULL; 64 | return r; 65 | } 66 | } 67 | _responseDataStorage = NULL; 68 | _buffer = ""; 69 | return -1; 70 | } 71 | 72 | int RilClass::waitForPrompt(unsigned long timeout) 73 | { 74 | for (unsigned long start = millis(); (millis() - start) < timeout;) 75 | { 76 | ready(); 77 | if (_buffer.endsWith(">")) 78 | return 1; 79 | } 80 | return -1; 81 | } 82 | 83 | int RilClass::ready() 84 | { 85 | poll(); 86 | return _ready; 87 | } 88 | 89 | void RilClass::poll() 90 | { 91 | arduinoProcessMessages(50); 92 | while (_uart->available()) 93 | { 94 | char c = _uart->read(); 95 | _buffer += c; 96 | TRACE("%c", c); 97 | switch (_atCommandState) 98 | { 99 | case AT_COMMAND_IDLE: 100 | default: 101 | { 102 | if (_buffer.startsWith("AT") && _buffer.endsWith("\r\n")) 103 | { 104 | _atCommandState = AT_RECEIVING_RESPONSE; 105 | _buffer = ""; 106 | } 107 | else if (_buffer.endsWith("\r\n")) 108 | { 109 | _buffer = ""; 110 | } 111 | break; 112 | } 113 | 114 | case AT_RECEIVING_RESPONSE: 115 | { 116 | if (c == '\n') 117 | { 118 | int responseResultIndex = _buffer.lastIndexOf("OK\r\n"); 119 | if (responseResultIndex != -1) 120 | { 121 | _ready = 1; 122 | } 123 | else 124 | { 125 | responseResultIndex = _buffer.lastIndexOf("ERROR\r\n"); 126 | if (responseResultIndex != -1) 127 | { 128 | _ready = 2; 129 | } 130 | else 131 | { 132 | responseResultIndex = _buffer.lastIndexOf("NO CARRIER\r\n"); 133 | if (responseResultIndex != -1) 134 | { 135 | _ready = 3; 136 | } 137 | } 138 | } 139 | if (_ready != 0) 140 | { 141 | if (_responseDataStorage != NULL) 142 | { 143 | _buffer.remove(responseResultIndex); 144 | _buffer.trim(); 145 | *_responseDataStorage = _buffer; 146 | _responseDataStorage = NULL; 147 | } 148 | _atCommandState = AT_COMMAND_IDLE; 149 | _buffer = ""; 150 | return; 151 | } 152 | } 153 | break; 154 | } 155 | } //switch 156 | } //while 157 | } 158 | 159 | void RilClass::setResponseDataStorage(String *responseDataStorage) 160 | { 161 | _responseDataStorage = responseDataStorage; 162 | } 163 | 164 | RilClass Ril(Virtual1); -------------------------------------------------------------------------------- /cores/opencpu/RilClass.h: -------------------------------------------------------------------------------- 1 | #ifndef _RILCLASS_H 2 | #define _RILCLASS_H 3 | 4 | #include 5 | #include 6 | extern HardwareSerial Virtual1; 7 | 8 | class RilClass 9 | { 10 | public: 11 | RilClass(HardwareSerial &uart); 12 | 13 | void begin() 14 | { 15 | _uart->end(); 16 | _uart->begin(0); 17 | } 18 | void end() { _uart->end(); } 19 | 20 | int noop(); 21 | int single(const char *command); 22 | 23 | size_t write(uint8_t c); 24 | size_t write(const uint8_t *, size_t); 25 | 26 | void send(const char *command); 27 | void send(const String &command) { send(command.c_str()); } 28 | void sendf(const char *fmt, ...); 29 | 30 | int waitForResponse(unsigned long timeout = 500, String *responseDataStorage = NULL); 31 | int waitForPrompt(unsigned long timeout = 500); 32 | int ready(); 33 | void poll(); 34 | void setResponseDataStorage(String *responseDataStorage); 35 | 36 | int SMS_formatText(bool f); 37 | int SMS_characterSet(const char *cs); 38 | int SMS_begin(const char *to); 39 | int SMS_end(); 40 | 41 | private: 42 | HardwareSerial *_uart; 43 | enum 44 | { 45 | AT_COMMAND_IDLE, 46 | AT_RECEIVING_RESPONSE 47 | } _atCommandState; 48 | int _ready; 49 | String _buffer; 50 | String *_responseDataStorage; 51 | }; 52 | 53 | extern RilClass Ril; 54 | 55 | #endif //_RIL_CLASS_H -------------------------------------------------------------------------------- /cores/opencpu/RingBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifdef __cplusplus 20 | 21 | #ifndef _RING_BUFFER_ 22 | #define _RING_BUFFER_ 23 | 24 | #include 25 | 26 | // Define constants and variables for buffering incoming serial data. We're 27 | // using a ring buffer (I think), in which head is the index of the location 28 | // to which to write the next incoming character and tail is the index of the 29 | // location from which to read. 30 | // defined in interface.h 31 | #ifndef SERIAL_BUFFER_SIZE 32 | #define SERIAL_BUFFER_SIZE 256 33 | #endif 34 | 35 | template 36 | class RingBufferN 37 | { 38 | public: 39 | uint8_t _aucBuffer[N]; 40 | volatile int _iHead; 41 | volatile int _iTail; 42 | 43 | public: 44 | RingBufferN(void); 45 | void store_char(uint8_t c); 46 | void clear(); 47 | int read_char(); 48 | int available(); 49 | int availableForStore(); 50 | int peek(); 51 | bool isFull(); 52 | 53 | private: 54 | int nextIndex(int index); 55 | }; 56 | 57 | typedef RingBufferN RingBuffer; 58 | 59 | template RingBufferN::RingBufferN(void) 60 | { 61 | memset(_aucBuffer, 0, N); 62 | clear(); 63 | } 64 | 65 | template 66 | void RingBufferN::store_char(uint8_t c) 67 | { 68 | int i = nextIndex(_iHead); 69 | 70 | // if we should be storing the received character into the location 71 | // just before the tail (meaning that the head would advance to the 72 | // current location of the tail), we're about to overflow the buffer 73 | // and so we don't write the character or advance the head. 74 | if (i != _iTail) 75 | { 76 | _aucBuffer[_iHead] = c; 77 | _iHead = i; 78 | } 79 | } 80 | 81 | template 82 | void RingBufferN::clear() 83 | { 84 | _iHead = 0; 85 | _iTail = 0; 86 | } 87 | 88 | template 89 | int RingBufferN::read_char() 90 | { 91 | if (_iTail == _iHead) 92 | return -1; 93 | 94 | uint8_t value = _aucBuffer[_iTail]; 95 | _iTail = nextIndex(_iTail); 96 | 97 | return value; 98 | } 99 | 100 | template 101 | int RingBufferN::available() 102 | { 103 | int delta = _iHead - _iTail; 104 | 105 | if (delta < 0) 106 | return N + delta; 107 | else 108 | return delta; 109 | } 110 | 111 | template 112 | int RingBufferN::availableForStore() 113 | { 114 | if (_iHead >= _iTail) 115 | return N - 1 - _iHead + _iTail; 116 | else 117 | return _iTail - _iHead - 1; 118 | } 119 | 120 | template 121 | int RingBufferN::peek() 122 | { 123 | if (_iTail == _iHead) 124 | return -1; 125 | 126 | return _aucBuffer[_iTail]; 127 | } 128 | 129 | template 130 | int RingBufferN::nextIndex(int index) 131 | { 132 | return (uint32_t)(index + 1) % N; 133 | } 134 | 135 | template 136 | bool RingBufferN::isFull() 137 | { 138 | return (nextIndex(_iHead) == _iTail); 139 | } 140 | 141 | #endif /* _RING_BUFFER_ */ 142 | 143 | #endif /* __cplusplus */ 144 | -------------------------------------------------------------------------------- /cores/opencpu/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print { 26 | public: 27 | virtual void begin() =0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /cores/opencpu/Tone.h: -------------------------------------------------------------------------------- 1 | #ifndef __TONE_H__ 2 | #define __TONE_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | extern void tone(uint8_t pin, unsigned int frequency, unsigned long duration = 0); 15 | extern void noTone(uint8_t pin); 16 | 17 | #endif //Tone.h -------------------------------------------------------------------------------- /cores/opencpu/WMath.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void randomSeed(unsigned long seed) 4 | { 5 | if (seed != 0) 6 | { 7 | srand(seed); 8 | } 9 | } 10 | 11 | long random(long howbig) 12 | { 13 | if (howbig == 0) 14 | { 15 | return 0; 16 | } 17 | return rand() % howbig; 18 | } 19 | 20 | long random(long howsmall, long howbig) 21 | { 22 | if (howsmall >= howbig) 23 | { 24 | return howsmall; 25 | } 26 | long diff = howbig - howsmall; 27 | return random(diff) + howsmall; 28 | } 29 | 30 | long map(long x, long in_min, long in_max, long out_min, long out_max) 31 | { 32 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 33 | } 34 | 35 | unsigned int makeWord(unsigned int w) 36 | { 37 | return w; 38 | } 39 | 40 | unsigned int makeWord(unsigned char h, unsigned char l) 41 | { 42 | return (h << 8) | l; 43 | } 44 | -------------------------------------------------------------------------------- /cores/opencpu/WProgram.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" -------------------------------------------------------------------------------- /cores/opencpu/api/AT_TOK.c: -------------------------------------------------------------------------------- 1 | #include "AT_TOK.h" 2 | 3 | char * strpbrk(const char *s1, const char *s2) 4 | { 5 | register const char * scanp; 6 | register int c, sc; 7 | while ((c = *s1++) != 0) 8 | { 9 | for (scanp = s2; (sc = *scanp++) != 0;) 10 | if (sc == c) 11 | return ((char *)(s1 - 1)); 12 | } 13 | return (NULL); 14 | } 15 | 16 | char * strsep(char **stringp, const char *delim) 17 | { 18 | if (*stringp == NULL) { return NULL; } 19 | char *token_start = *stringp; 20 | *stringp = strpbrk(token_start, delim); 21 | if (*stringp) 22 | { 23 | **stringp = '\0'; 24 | (*stringp)++; 25 | } 26 | return token_start; 27 | } 28 | 29 | int at_tok_start(char **p_cur) 30 | { 31 | if (*p_cur == NULL) return -1; 32 | *p_cur = Ql_strchr(*p_cur, ':'); 33 | if (*p_cur == NULL) return -1; 34 | (*p_cur)++; 35 | return 0; 36 | } 37 | 38 | void skipWhiteSpace(char **p_cur) 39 | { 40 | if (*p_cur == NULL) return; 41 | while (**p_cur != '\0' && isspace(**p_cur)) (*p_cur)++; 42 | } 43 | 44 | static void skipNextComma(char **p_cur) 45 | { 46 | if (*p_cur == NULL) return; 47 | while (**p_cur != '\0' && **p_cur != ',') (*p_cur)++; 48 | if (**p_cur == ',') (*p_cur)++; 49 | } 50 | 51 | char * nextTok(char **p_cur) 52 | { 53 | char *ret = NULL; 54 | skipWhiteSpace(p_cur); 55 | if (*p_cur == NULL) 56 | { 57 | ret = NULL; 58 | } else if (**p_cur == CHR_QUOTES) 59 | { 60 | (*p_cur)++; 61 | ret = strsep(p_cur, STR_QUOTES); 62 | skipNextComma(p_cur); 63 | } else { 64 | ret = strsep(p_cur, ","); 65 | } 66 | return ret; 67 | } 68 | 69 | static int at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns) 70 | { 71 | char *ret; 72 | if (*p_cur == NULL) { 73 | return -1; 74 | } 75 | ret = nextTok(p_cur); 76 | if (ret == NULL) { 77 | return -1; 78 | } else { 79 | long l; 80 | char *end; 81 | if (uns) 82 | l = strtoul(ret, &end, base); 83 | else 84 | l = strtol(ret, &end, base); 85 | *p_out = (int)l; 86 | if (end == ret) { 87 | return -1; 88 | } 89 | } 90 | return 0; 91 | } 92 | 93 | int at_tok_nextint(char **p_cur, int *p_out) 94 | { 95 | return at_tok_nextint_base(p_cur, p_out, 10, 0); 96 | } 97 | 98 | int at_tok_nexthexint(char **p_cur, int *p_out) 99 | { 100 | return at_tok_nextint_base(p_cur, p_out, 16, 1); 101 | } 102 | 103 | int at_tok_nextbool(char **p_cur, char *p_out) 104 | { 105 | int ret; 106 | int result; 107 | ret = at_tok_nextint(p_cur, &result); 108 | if (ret < 0) 109 | return -1; 110 | if (!(result == 0 || result == 1)) 111 | return -1; 112 | if (p_out != NULL) 113 | *p_out = (char)result; 114 | return ret; 115 | } 116 | 117 | int at_tok_nextstr(char **p_cur, char **p_out) 118 | { 119 | if (*p_cur == NULL) 120 | return -1; 121 | *p_out = nextTok(p_cur); 122 | return 0; 123 | } 124 | 125 | /** returns 1 on "has more tokens" and 0 if no */ 126 | int at_tok_hasmore(char **p_cur) 127 | { 128 | return ! (*p_cur == NULL || **p_cur == '\0'); 129 | } 130 | -------------------------------------------------------------------------------- /cores/opencpu/api/AT_TOK.h: -------------------------------------------------------------------------------- 1 | #ifndef _AT_TOK_H_ 2 | #define _AT_TOK_H_ 3 | 4 | #define __OCPU_AT_TOK_SUPPORT__ 5 | 6 | /* 7 | * android_hardware_ril /reference-ril/at_tok.c 8 | * https://searchcode.com/codesearch/view/40550194/ 9 | */ 10 | 11 | #include "ql_type.h" 12 | #include "ql_stdlib.h" 13 | #include "ql_system.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define CHR_DELIM ':' 20 | #define CHR_QUOTES '"' 21 | #define STR_QUOTES "\"" 22 | 23 | int isspace(int c); 24 | char * strpbrk(const char *s1, const char *s2); 25 | char * strsep(char **stringp, const char *delim); 26 | void skipWhiteSpace(char **p_cur); 27 | char * nextTok(char **p_cur); 28 | 29 | int at_tok_start(char **p_cur); 30 | int at_tok_nextint(char **p_cur, int *p_out); 31 | int at_tok_nexthexint(char **p_cur, int *p_out); 32 | int at_tok_nextbool(char **p_cur, char *p_out); 33 | int at_tok_nextstr(char **p_cur, char **out); 34 | int at_tok_hasmore(char **p_cur); 35 | 36 | #endif /* _AT_TOK_H_ */ 37 | -------------------------------------------------------------------------------- /cores/opencpu/arduino_main.cpp: -------------------------------------------------------------------------------- 1 | /* M66 2 | * Created on: 01.01.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #include 7 | #include 8 | extern DeviceClass Dev; 9 | 10 | extern void initVariant() __attribute__((weak)); 11 | extern void setup(); 12 | extern void loop(); 13 | 14 | static struct 15 | { 16 | uint32_t wait; 17 | uint32_t event; 18 | ST_MSG msg; 19 | } arduino = {10 /* default task wait */, 0, {0, 0, 0, 0}}; 20 | 21 | void arduinoSetWait(u32 wait) 22 | { 23 | arduino.wait = wait == 0 ? 1 : wait; 24 | } 25 | 26 | static inline bool arduinoInit(void) 27 | { 28 | if (0 == arduino.event) 29 | arduino.event = Ql_OS_CreateEvent((char *)"AEVENT"); // once 30 | return arduino.event == 0; 31 | } 32 | 33 | static inline void arduinoDispatchMessages(void) 34 | { 35 | switch (arduino.msg.message) 36 | { 37 | case MSG_ID_URC_INDICATION: 38 | Dev.m_Urc(arduino.msg.param1, arduino.msg.param2); 39 | break; 40 | default: 41 | Dev.m_Message(&arduino.msg); 42 | break; 43 | } 44 | } 45 | 46 | void arduinoProcessMessages(unsigned int wait) 47 | { 48 | u32 id = Ql_OS_GetActiveTaskId(); 49 | if (ARDUINO_TASK_ID == id) 50 | { 51 | Ql_OS_GetMessage(&arduino.msg); // there is always more than zero 52 | Ql_OS_SendMessage(id, MSG_PROCESS_MESSAGES, 0, 0); // send one message 53 | arduinoDispatchMessages(); 54 | } 55 | Ql_Sleep(wait); 56 | } 57 | 58 | void delayEx(unsigned int ms) 59 | { 60 | #define BLOCK_TIME 100 61 | unsigned int count = ms / BLOCK_TIME; 62 | while (count--) 63 | arduinoProcessMessages(BLOCK_TIME); // step 64 | arduinoProcessMessages(ms % BLOCK_TIME); // remain 65 | } 66 | 67 | /// Arduino Task 68 | extern "C" void proc_arduino(int id) 69 | { 70 | TRACE("[A] proc_arduino\n"); 71 | while (arduino.event == 0) 72 | Ql_Sleep(10); 73 | Ql_OS_WaitEvent(arduino.event, EVENT_FLAG0); // wait ril ready 74 | initVariant(); 75 | Ql_OS_SendMessage(id, MSG_PROCESS_MESSAGES, 0, 0); // dont touch 76 | TRACE("[A] BEGIN\n"); 77 | arduinoProcessMessages(arduino.wait); 78 | setup(); 79 | while (true) 80 | { 81 | arduinoProcessMessages(arduino.wait); 82 | loop(); 83 | } 84 | } 85 | 86 | /// Main Task 87 | extern "C" void proc_main_task(int taskId) 88 | { 89 | TRACE("[M] proc_main_task\n"); 90 | if (api_check_api()) 91 | { 92 | TRACE("[M] ERROR Firmware not support\n"); 93 | abort(); 94 | } 95 | TRACE("[M] proc_main_task\n"); 96 | if (arduinoInit()) 97 | { 98 | TRACE("[M] ERROR arduinoInit()\n"); 99 | abort(); 100 | } 101 | __libc_init_array(); 102 | entry_main(taskId); // if exist - OpenCPU style 103 | ST_MSG m; 104 | while (true) 105 | { 106 | Ql_OS_GetMessage(&m); 107 | switch (m.message) 108 | { 109 | case MSG_ID_RIL_READY: 110 | Ql_RIL_Initialize(); 111 | Ql_OS_SetEvent(arduino.event, EVENT_FLAG0); // start arduino 112 | TRACE("[M] RIL READY\n"); 113 | break; 114 | case MSG_ID_URC_INDICATION: 115 | if (m.message > URC_GPRS_NW_STATE_IND) // ignore first urc-s 116 | Ql_OS_SendMessage(ARDUINO_TASK_ID, m.message, m.param1, m.param2); // resend to arduino task 117 | break; 118 | default: 119 | Ql_OS_SendMessage(ARDUINO_TASK_ID, m.message, m.param1, m.param2); // resend to arduino task 120 | break; 121 | } // SWITCH 122 | } // WHILE 123 | } 124 | 125 | extern "C" void proc_reserved1(int); 126 | extern "C" void proc_reserved2(int); 127 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// 128 | -------------------------------------------------------------------------------- /cores/opencpu/cbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | cbuf.h - Circular buffer implementation 3 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 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 | #ifndef __cbuf_h 22 | #define __cbuf_h 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class cbuf 29 | { 30 | public: 31 | cbuf(size_t size); 32 | ~cbuf(); 33 | 34 | size_t resizeAdd(size_t addSize); 35 | size_t resize(size_t newSize); 36 | size_t available() const; 37 | size_t size(); 38 | 39 | size_t room() const; 40 | 41 | inline bool empty() const 42 | { 43 | return _begin == _end; 44 | } 45 | 46 | inline bool full() const 47 | { 48 | return wrap_if_bufend(_end + 1) == _begin; 49 | } 50 | 51 | int peek(); 52 | size_t peek(char *dst, size_t size); 53 | 54 | int read(); 55 | size_t read(char* dst, size_t size); 56 | 57 | size_t write(char c); 58 | size_t write(const char* src, size_t size); 59 | 60 | void flush(); 61 | size_t remove(size_t size); 62 | 63 | cbuf *next; 64 | 65 | private: 66 | inline char* wrap_if_bufend(char* ptr) const 67 | { 68 | return (ptr == _bufend) ? _buf : ptr; 69 | } 70 | 71 | size_t _size; 72 | char* _buf; 73 | const char* _bufend; 74 | char* _begin; 75 | char* _end; 76 | 77 | }; 78 | 79 | #endif//__cbuf_h -------------------------------------------------------------------------------- /cores/opencpu/constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_CONSTANTS_ 20 | #define _WIRING_CONSTANTS_ 21 | 22 | #ifdef __cplusplus 23 | extern "C"{ 24 | #endif // __cplusplus 25 | 26 | #include 27 | 28 | #define LOW (0x0) 29 | #define HIGH (0x1) 30 | 31 | #define CLOSE (0xFF) 32 | #define INPUT (0) 33 | #define INPUT_PULLUP (1<<1) 34 | #define INPUT_PULLDOWN (1<<2) 35 | #define OUTPUT (1<<3) 36 | #define OUTPUT_LO (1<<4) 37 | #define OUTPUT_HI (1<<5) 38 | 39 | #define CHANGE (0x2) 40 | #define FALLING (0x3) 41 | #define RISING (0x4) 42 | 43 | #define DEFAULT (0x1) 44 | #define EXTERNAL (0x0) 45 | 46 | enum BitOrder { 47 | LSBFIRST = 0, 48 | MSBFIRST = 1 49 | }; 50 | 51 | typedef bool boolean; 52 | typedef uint8_t byte; 53 | typedef uint16_t word; 54 | 55 | #define PI 3.1415926535897932384626433832795 56 | #define HALF_PI 1.5707963267948966192313216916398 57 | #define TWO_PI 6.283185307179586476925286766559 58 | #define DEG_TO_RAD 0.017453292519943295769236907684886 59 | #define RAD_TO_DEG 57.295779513082320876798154814105 60 | #define EULER 2.718281828459045235360287471352 61 | 62 | 63 | #ifdef abs 64 | #undef abs 65 | #endif 66 | #define abs(x) ((x)>0?(x):-(x)) 67 | 68 | #define min(a,b) ((a)<(b)?(a):(b)) 69 | #define max(a,b) ((a)>(b)?(a):(b)) 70 | 71 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 72 | 73 | //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 74 | #define radians(deg) ((deg)*DEG_TO_RAD) 75 | #define degrees(rad) ((rad)*RAD_TO_DEG) 76 | #define sq(x) ((x)*(x)) 77 | 78 | 79 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 80 | #define highByte(w) ((uint8_t) ((w) >> 8)) 81 | 82 | #define bit(b) (1UL << (b)) 83 | 84 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 85 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 86 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 87 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 88 | 89 | #ifndef _NOP 90 | #define _NOP() do { __asm__ volatile ("nop"); } while (0) 91 | #endif 92 | 93 | #ifdef __cplusplus 94 | } // extern "C" 95 | #endif // __cplusplus 96 | 97 | #endif /* _WIRING_CONSTANTS_ */ -------------------------------------------------------------------------------- /cores/opencpu/cpp_m66.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ROM (rx) : ORIGIN = 0x102C7040, LENGTH = 0x0005A000 4 | RAM (rwx) : ORIGIN = 0xf03D2000, LENGTH = 0x00019000 5 | } 6 | 7 | SECTIONS 8 | { 9 | . = 0x102C7040; 10 | .initdata : ALIGN(4) 11 | { 12 | KEEP(*(.initdata)); 13 | } AT > ROM 14 | 15 | text : ALIGN(4) 16 | { 17 | PROVIDE_HIDDEN (__preinit_array_start = .); 18 | KEEP( *(SORT(.preinit_array.*)) ) 19 | KEEP( *(.preinit_init_array*) ) 20 | PROVIDE_HIDDEN (__preinit_array_end = .); 21 | 22 | PROVIDE_HIDDEN (__init_array_start = .); 23 | KEEP( *(SORT(.init_array.*)) ) 24 | KEEP( *(.init_array*) ) 25 | PROVIDE_HIDDEN (__init_array_end = .); 26 | 27 | PROVIDE_HIDDEN (__fini_array_start = .); 28 | KEEP( *(SORT(.fini_array.*)) ) 29 | KEEP( *(.fini_array*) ) 30 | PROVIDE_HIDDEN (__fini_array_end = .); 31 | 32 | *( .text .text.* i.* ) 33 | *( .glue_7t ) 34 | *( .glue_7 ) 35 | *( .ctors ) 36 | *( .dtors ) 37 | *( .gnu.linkonce.t.* ) 38 | *( .gnu.linkonce.r.* ) 39 | *( .gcc_except_table ) 40 | *( .rodata .rodata* .constdata* .conststring* ) 41 | } AT > ROM 42 | 43 | .ARM.exidx : ALIGN(8) 44 | { 45 | __exidx_start = .; 46 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 47 | __exidx_end = .; 48 | } AT > ROM 49 | 50 | .data : ALIGN(8) 51 | { 52 | __data_load = LOADADDR(.data); 53 | __data_start = .; 54 | *(.data) 55 | *(.data.*) 56 | . = ALIGN (8); 57 | _edata = .; 58 | } > RAM AT > ROM 59 | 60 | .bss : ALIGN(8) 61 | { 62 | __bss_start__ = .; 63 | *(.bss) 64 | *(.bss.*) 65 | . = ALIGN (8); 66 | __bss_end__ = .; 67 | } > RAM 68 | } -------------------------------------------------------------------------------- /cores/opencpu/custom_config.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * sys_config.c 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The file is for some common system definition. Developer don't have to 23 | * care. 24 | * 25 | * Author: 26 | * ------- 27 | * ------- 28 | * 29 | *============================================================================ 30 | * HISTORY 31 | *---------------------------------------------------------------------------- 32 | * 33 | ****************************************************************************/ 34 | #include "custom_feature_def.h" 35 | #include "ql_type.h" 36 | #include "ril.h" 37 | #include "ql_system.h" 38 | #include "custom_heap_cfg.h" 39 | 40 | #define DEFAULT_VALUE1 (200) 41 | #define DEFAULT_VALUE2 (30) 42 | 43 | 44 | //const u32 HeapMemSize = HEAP_MEMSIZE; 45 | //u8 OpenCPUHeapSpace[HEAP_MEMSIZE]; 46 | 47 | 48 | /* 49 | *-------------------------- 50 | * Task Configuration 51 | *-------------------------- 52 | * TaskStackSize: 53 | * The stack size of task. Range from 1K to 10K. 54 | * If there are any file operations to do in task, 55 | * the stack size of this task must be set to at least 4K. 56 | *****************************************************************/ 57 | 58 | #ifdef TASK_ID_DEF 59 | #undef TASK_ID_DEF 60 | #endif 61 | #ifdef TASK_DEFINITION 62 | #undef TASK_DEFINITION 63 | #endif 64 | #define TASK_FUNC_DECLARATION 65 | #include "ql_common.h" 66 | TASK_DEFINITION_BEGIN 67 | #include "custom_task_cfg.h" 68 | TASK_DEFINITION_END 69 | #undef TASK_FUNC_DECLARATION 70 | 71 | 72 | 73 | #ifdef TASK_FUNC_DECLARATION 74 | #undef TASK_FUNC_DECLARATION 75 | #endif 76 | #ifdef TASK_ID_DEF 77 | #undef TASK_ID_DEF 78 | #endif 79 | #define TASK_DEFINITION 80 | #include "ql_common.h" 81 | TASK_DEFINITION_BEGIN 82 | #include "custom_task_cfg.h" 83 | TASK_DEFINITION_END 84 | #undef TASK_DEFINITION 85 | 86 | 87 | 88 | #define GPIO_DEFINITION 89 | #include "ql_common.h" 90 | GPIO_DEFINITION_BEGIN 91 | #include "custom_gpio_cfg.h" 92 | GPIO_DEFINITION_END 93 | #undef GPIO_DEFINITION 94 | -------------------------------------------------------------------------------- /cores/opencpu/custom_feature_def.h: -------------------------------------------------------------------------------- 1 | #ifndef __CUSTOM_FEATURE_DEF_H__ 2 | #define __CUSTOM_FEATURE_DEF_H__ 3 | 4 | /************************************************************************ 5 | * RIL Function on/off 6 | ************************************************************************/ 7 | #define __OCPU_RIL_SUPPORT__ 8 | #define __OCPU_RIL_SMS_SUPPORT__ 9 | #define __OCPU_RIL_CALL_SUPPORT__ 10 | #define __OCPU_RIL_BT_SUPPORT__ 11 | 12 | 13 | 14 | /************************************************************************ 15 | * FOTA Feature Definition 16 | ************************************************************************/ 17 | //#define __OCPU_FOTA_APP__ 18 | //#define __OCPU_FOTA_BY_FTP__ 19 | //#define __OCPU_FOTA_BY_HTTP__ 20 | 21 | /************************************************************************ 22 | * Smart Cloud Support 23 | ************************************************************************/ 24 | #define __OCPU_SMART_CLOUD_SUPPORT__ 25 | #endif //__CUSTOM_FEATURE_DEF_H__ 26 | -------------------------------------------------------------------------------- /cores/opencpu/custom_gpio_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * custom_gpio_cfg.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The file intends for GPIO initialization definition. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __CUSTOM_GPIO_CFG_H__ 34 | #define __CUSTOM_GPIO_CFG_H__ 35 | 36 | /*======================================================================== 37 | | 38 | | GPIO initialization configurations. 39 | |------------------------------------ 40 | | IMPORTANT NOTES: 41 | |------------------ 42 | | 43 | | This is the initialization list for GPIOs at the early of module booting. 44 | | Developer can do configuring here if some GPIOs need to be initialized at 45 | | the early booting. For example, some GPIO is used to control the power 46 | | supply of peripheral. 47 | | 48 | | Besides this config list, developer may call Ql_GPIO_Init() to initialize 49 | | the parameters of I/O interfaces dynamically. But it's later than the 50 | | previous method on time sequence. 51 | \=========================================================================*/ 52 | /*---------------------------------------------------------------------------------------------- 53 | { Pin Name | Direction | Level | Pull Selection } 54 | *---------------------------------------------------------------------------------------------*/ 55 | 56 | #if 0 // If needed, config GPIOs here 57 | GPIO_ITEM(PINNAME_NETLIGHT, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 58 | GPIO_ITEM(PINNAME_DTR, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 59 | GPIO_ITEM(PINNAME_RI, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 60 | GPIO_ITEM(PINNAME_DCD, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 61 | GPIO_ITEM(PINNAME_CTS, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 62 | GPIO_ITEM(PINNAME_RTS, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 63 | GPIO_ITEM(PINNAME_RXD_AUX, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 64 | GPIO_ITEM(PINNAME_TXD_AUX, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 65 | GPIO_ITEM(PINNAME_PCM_CLK, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 66 | GPIO_ITEM(PINNAME_PCM_SYNC, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 67 | GPIO_ITEM(PINNAME_PCM_IN, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 68 | GPIO_ITEM(PINNAME_PCM_OUT, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP) 69 | #endif 70 | 71 | #endif //__CUSTOM_GPIO_CFG_H__ 72 | -------------------------------------------------------------------------------- /cores/opencpu/custom_heap_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * custom_heap_cfg.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The file intends for heap space definition of OpenCPU application. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __CUSTOM_HEAP_CFG_H__ 34 | #define __CUSTOM_HEAP_CFG_H__ 35 | 36 | /*======================================================================== 37 | | 38 | | Heap Configuration. 39 | |------------------ 40 | | Predefine a block of memory, and the o.s will allocate the memory from 41 | | the predefined memory when calling Ql_MEM_Alloc(). 42 | | Min value is 1, and max value depends one the max memory available. 43 | | Unit in byte. 44 | \=========================================================================*/ 45 | /*======================================================================== 46 | | 47 | | Note. 48 | |------------------ 49 | | This method is no longer used On the new platform,the o.s will allocate 50 | | the memory from the "RAM FILE" memory when calling Ql_MEM_Alloc(). 51 | | The size of the "RAM FILE" about 500KB. 52 | | Unit in byte. 53 | \=========================================================================*/ 54 | 55 | //#define HEAP_MEMSIZE (30 * 1024) 56 | 57 | #endif //__CUSTOM_HEAP_CFG_H__ 58 | -------------------------------------------------------------------------------- /cores/opencpu/custom_task_cfg.h: -------------------------------------------------------------------------------- 1 | 2 | TASK_ITEM(proc_main_task, main_task_id, 10*1024, DEFAULT_VALUE1, DEFAULT_VALUE2) 3 | TASK_ITEM(proc_reserved1, reserved1_id, 10*1024, DEFAULT_VALUE1, DEFAULT_VALUE2) 4 | TASK_ITEM(proc_reserved2, reserved2_id, 10*1024, DEFAULT_VALUE1, DEFAULT_VALUE2) 5 | TASK_ITEM(proc_arduino, arduino3_id, 10*1024, DEFAULT_VALUE1, DEFAULT_VALUE2) 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /cores/opencpu/dbg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.c 3 | * 4 | * Created on: 26.02.2019 5 | * Author: georgi.angelov 6 | */ 7 | 8 | #include "ql_stdlib.h" 9 | #include "ql_uart.h" 10 | #include "dbg.h" 11 | #include "api.h" 12 | 13 | static Enum_SerialPort debugPort = UART_PORT_END; 14 | static u32 debugMutex = 0; 15 | 16 | void debug_enable(unsigned long port) 17 | { 18 | if (0 == debugMutex) 19 | debugMutex = Ql_OS_CreateMutex("DEBUG_MUTEX"); 20 | debugPort = (Enum_SerialPort)port; 21 | } 22 | 23 | void debug_disable(void) 24 | { 25 | debugPort = (Enum_SerialPort)UART_PORT_END; 26 | } 27 | 28 | #ifdef ENABLE_DEBUG 29 | 30 | static char bufferDebug[1024]; 31 | 32 | int log_printf(const char *frm, ...) 33 | { 34 | if (0 == debugMutex) 35 | return 0; 36 | va_list arg; 37 | va_start(arg, frm); 38 | if (debugPort < UART_PORT1 || debugPort > UART_PORT3) 39 | return 0; 40 | if (debugMutex) 41 | Ql_OS_TakeMutex(debugMutex); 42 | int n = wiz__vsnprintf(bufferDebug, sizeof(bufferDebug), frm, arg); 43 | va_end(arg); 44 | if (n > 0) 45 | n = Ql_UART_Write(debugPort, (u8 *)bufferDebug, n); 46 | if (debugMutex) 47 | Ql_OS_GiveMutex(debugMutex); 48 | return n; 49 | } 50 | 51 | void log_buf(const char *text, const unsigned char *buf, unsigned int len) 52 | { 53 | char txt[17]; 54 | char bufferDump[512]; 55 | unsigned int i, idx = 0; 56 | Ql_snprintf(bufferDump + idx, sizeof(bufferDump) - idx, "[DMP] '%s' (%u bytes)\n", text, (unsigned int)len); 57 | log_printf(bufferDump); 58 | idx = 0; 59 | Ql_memset(txt, 0, sizeof(txt)); 60 | for (i = 0; i < len; i++) 61 | { 62 | if (i >= 4096) 63 | break; 64 | if (i % 16 == 0) 65 | { 66 | if (i > 0) 67 | { 68 | Ql_snprintf(bufferDump + idx, sizeof(bufferDump) - idx, " %s\n", txt); 69 | log_printf(bufferDump); 70 | idx = 0; 71 | Ql_memset(txt, 0, sizeof(txt)); 72 | } 73 | idx += Ql_snprintf(bufferDump + idx, sizeof(bufferDump) - idx, "%04X: ", (unsigned int)i); 74 | } 75 | idx += Ql_snprintf(bufferDump + idx, sizeof(bufferDump) - idx, " %02X", (unsigned int)buf[i]); 76 | txt[i % 16] = (buf[i] > 31 && buf[i] < 127) ? buf[i] : '.'; 77 | } 78 | if (len > 0) 79 | { 80 | for (/* i = i */; i % 16 != 0; i++) 81 | idx += Ql_snprintf(bufferDump + idx, sizeof(bufferDump) - idx, " "); 82 | Ql_snprintf(bufferDump + idx, sizeof(bufferDump) - idx, " %s\n", txt); 83 | log_printf(bufferDump); 84 | } 85 | } 86 | 87 | #endif -------------------------------------------------------------------------------- /cores/opencpu/dbg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * 4 | * Created on: 26.02.2019 5 | * Author: georgi.angelov 6 | */ 7 | 8 | #ifndef DBG_H_ 9 | #define DBG_H_ 10 | 11 | #define ENABLE_DEBUG 12 | #define ENABLE_TRACE 13 | 14 | void debug_enable(unsigned long port); 15 | 16 | int log_printf(const char *frm, ...) __attribute__((weak)); 17 | void log_buf(const char *text, const unsigned char *buf, unsigned int len) __attribute__((weak)); 18 | 19 | #ifdef ENABLE_DEBUG 20 | # include "ql_trace.h" 21 | # define DBG(FORMAT, ...) log_printf(FORMAT, ##__VA_ARGS__) 22 | # define DMP(TEXT, BUFFER, LEN) log_buf(TEXT, (unsigned char *)BUFFER, LEN) 23 | #else 24 | # define DBG(FORMAT, ...) 25 | # define DMP(TEXT, BUFFER, LEN) 26 | #endif 27 | 28 | 29 | #ifdef ENABLE_TRACE 30 | # define TRACE Ql_Debug_Trace 31 | #else 32 | # define TRACE 33 | #endif 34 | 35 | #endif /* DBG_H_ */ 36 | -------------------------------------------------------------------------------- /cores/opencpu/dtostrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2013 Arduino. All rights reserved. 4 | Written by Cristian Maglie 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 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 22 | 23 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { 24 | char fmt[20]; 25 | sprintf(fmt, "%%%d.%df", width, prec); 26 | sprintf(sout, fmt, val); 27 | return sout; 28 | } 29 | -------------------------------------------------------------------------------- /cores/opencpu/dtostrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2013 Arduino. All rights reserved. 4 | Written by Cristian Maglie 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 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 | #ifndef __DTOSTRF__ 22 | #define __DTOSTRF__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cores/opencpu/fota/inc/fota_ftp.h: -------------------------------------------------------------------------------- 1 | #ifndef __FOTA_FTP_H__ 2 | #define __FOTA_FTP_H__ 3 | 4 | #include "ql_type.h" 5 | #include "ql_stdlib.h" 6 | 7 | typedef enum tagATCmdType { 8 | FTP_ATQIFGCNT, 9 | FTP_ATQICSGP, 10 | FTP_ATQFTPOPEN, 11 | FTP_ATQFTPCFG, 12 | FTP_ATQFTPPATH, 13 | FTP_ATQFTPGET, 14 | FTP_ATQFTPCLOSE, 15 | FTP_FOTAUPGRADE, 16 | }AT_FTPCmdType; 17 | 18 | typedef struct { 19 | s32 id; 20 | u32 interval; 21 | bool autoRepeat; 22 | bool runState; 23 | }ST_FTPTimer; 24 | 25 | #define UP_DATA_BUFFER_LEN 512 26 | #define FTP_SERVERADD_LEN 40 27 | #define FTP_FILEPATH_LEN 60 28 | #define FTP_USERNAME_LEN 20 29 | #define FTP_PASSWORD_LEN 20 30 | #define FTP_BINFILENAME_LEN 25 31 | #define FTP_SERVICE_PORT 21 32 | 33 | #define APP_BINFILE_PATH "RAM" 34 | 35 | bool FTP_IsFtpServer(u8* URL); 36 | s32 FTP_FotaMain(u8 contextId, u8* URL); 37 | 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /cores/opencpu/fota/inc/fota_http.h: -------------------------------------------------------------------------------- 1 | #ifndef __FOTA_HTTP_H__ 2 | #define __FOTA_HTTP_H__ 3 | 4 | #include "ql_type.h" 5 | #include "ql_stdlib.h" 6 | #include "fota_http_code.h" 7 | 8 | /****************************************************************************** 9 | * Macros 10 | ******************************************************************************/ 11 | #define QUECTEL_HTTP_URL_LENGTH 200 12 | #define QUECTEL_HTTP_DOMAINNAME_LENGTH 150 13 | #define QUECTEL_HTTP_DATABUFFER_SIZE 512 14 | #define HTTP_SERVICE_PORT 80 15 | #define HTTP_GETREADTIMEROUT 120000 // 2 mins for read socket timerout 16 | #define HTTP_GETREADTIMERID 0x2F 17 | 18 | 19 | typedef enum HttpResultTag 20 | { 21 | HTTP_RESULT_ERROR_WOULDBLOCK=-2, 22 | 23 | HTTP_RESULT_OK=0, 24 | HTTP_RESULT_ERROR_SOC_CLOSE, 25 | HTTP_RESULT_ERROR_HTTP_RELOCATION, 26 | HTTP_RESULT_ERROR_HTTP_RESPONSE_FAILED, 27 | HTTP_RESULT_ERROR_DECODEERROR, 28 | END_OF_HTTP_RESULT 29 | }HttpResult_e; 30 | 31 | 32 | typedef struct HttpMainContextTag 33 | { 34 | u8 contextId; /*relation for tcpip*/ 35 | u8 sourceid; /*relation for tcpip*/ 36 | u8 socketid;/*relation for tcpip*/ 37 | 38 | bool bpeersocketclose; 39 | 40 | u32 httpGettimeout; 41 | u32 httpGetHeadTimer; 42 | bool httpGettimerstate; 43 | 44 | u32 downloadsize; 45 | u32 downloadtimeout; 46 | u32 httpDownloadTimer; 47 | 48 | u8 Address[QUECTEL_HTTP_URL_LENGTH+1]; 49 | u32 AddressValidLegth; 50 | 51 | u32 ContentLength; 52 | 53 | bool getbody; 54 | u32 receivedbodydata; 55 | 56 | u8 hostip[30]; 57 | u16 hostport; 58 | u8 hostname[QUECTEL_HTTP_DOMAINNAME_LENGTH+1]; 59 | u8 hostipAddres[5]; 60 | 61 | u8 *http_socketdata_p; // porint to the http socket received buffer 62 | u8 *genhttp_dstconstptr; 63 | u16 genhttp_dstconstsize; 64 | u16 genhttp_dstpos; 65 | s32 genhttp_dstvaliddatalen; 66 | 67 | HttpHeader_t httpheader; 68 | 69 | u8 httpversion; 70 | }HttpMainContext_t; 71 | 72 | 73 | 74 | extern HttpMainContext_t httpMainContext; 75 | 76 | void http_TimerCallback(u32 timerId, void* param); 77 | void Callback_GetIpByHostName(u8 contexId, u8 requestId, s32 errCode, u32 ipAddrCnt, u32* ipAddr); 78 | 79 | 80 | /***************************************************************** 81 | * GPRS and Socket callback function 82 | ******************************************************************/ 83 | void HttpCallback_GPRS_Actived(u8 contexId, s32 errCode, void* customParam); 84 | void HttpCallBack_GPRS_Deactived(u8 contextId, s32 errCode, void* customParam ); 85 | 86 | /***************************************************************** 87 | *socket callback function 88 | ******************************************************************/ 89 | void Httpcallback_socket_connect(s32 socketId, s32 errCode, void* customParam); 90 | void Httpcallback_socket_close(s32 socketId, s32 errCode, void* customParam); 91 | void Httpcallback_socket_accept(s32 listenSocketId, s32 errCode, void* customParam); 92 | void Httpcallback_socket_read(s32 socketId, s32 errCode, void* customParam); 93 | void Httpcallback_socket_write(s32 socketId, s32 errCode, void* customParam); 94 | 95 | bool HTTP_IsHttpServer(u8* URL); 96 | 97 | s32 HTTP_FotaMain(u8 contextId, u8* URL); 98 | 99 | void http_initialize(void); 100 | 101 | void http_ConnectToServer(void); 102 | 103 | s32 http_SendHttpGetHead( s32 socketId); 104 | 105 | s8 http_RecvHttpHead(s32 socketid, bool bContinue); 106 | 107 | s8 http_RecvHttpBody(s32 socketid, bool bContinue); 108 | 109 | s8 http_RecvHttpChunkedBody(s32 socketid, bool bContinue); 110 | 111 | bool http_DecodeURL(u8 *Address, u32 *AddressValidLegth, u8 *hostip, u16 hostiplength, 112 | u8 *hostname, u16 hostnamelength, u16 *hostport); 113 | 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /cores/opencpu/fota/inc/fota_http_code.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/fota/inc/fota_http_code.h -------------------------------------------------------------------------------- /cores/opencpu/fota/inc/fota_main.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/fota/inc/fota_main.h -------------------------------------------------------------------------------- /cores/opencpu/fota/src/fota_http_code.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/fota/src/fota_http_code.c -------------------------------------------------------------------------------- /cores/opencpu/include/nema_pro.h: -------------------------------------------------------------------------------- 1 | #ifndef __NMEA_PRO_H__ 2 | #define __NMEA_PRO_H__ 3 | 4 | #include "ql_type.h" 5 | #include "ql_stdlib.h" 6 | #define MAX_I2C_BUF_SIZE 255 7 | #define MAX_NMEA_LEN 255 8 | #define IIC_DEV_ADDR 0x20 9 | 10 | 11 | #define MSG_ID_IIC_READ_INDICATION 0x1011 12 | #define MSG_ID_OUTPUT_INDICATION 0x1012 13 | 14 | #define TIMERID1 100 15 | #define INTERVAL500MS 500 16 | #define INTERVAL5MS 5 17 | #define NMEA_TX_MAX 2048 18 | 19 | 20 | 21 | 22 | typedef enum 23 | { 24 | RXS_DAT_HBD, // receive HBD data 25 | RXS_PRM_HBD2, // receive HBD preamble 2 26 | RXS_PRM_HBD3, // receive HBD preamble 3 27 | RXS_DAT, // receive NMEA data 28 | RXS_DAT_DBG, // receive DBG data 29 | RXS_ETX, // End-of-packet 30 | } RX_SYNC_STATE_T; 31 | 32 | typedef struct 33 | { 34 | s16 inst_id; // 1 - NMEA, 2 - DBG, 3 - HBD 35 | s16 dat_idx; 36 | s16 dat_siz; 37 | }st_queue; 38 | 39 | extern u8 rd_buf[MAX_I2C_BUF_SIZE+1]; 40 | extern u8 tx_buf[NMEA_TX_MAX]; 41 | extern s32 tx_data_len; 42 | extern s32 tx_size; 43 | 44 | bool iop_init_pcrx( void ); 45 | void iop_pcrx_nmea( u8 data ); 46 | void iop_get_inst(s16 idx, s16 size, void *data); 47 | bool iop_inst_avail(s16 *inst_id, s16 *dat_idx, s16 *dat_siz) ; 48 | bool iop_init_pcrx( void ) ; 49 | 50 | void get_nmea(void); 51 | void extract_nmea(void); 52 | bool read_gps_I2C_buffer(void); 53 | s32 IIC_ReadBytes(u32 chnnlNo,u8 slaveAddr,u8 *buf,u32 len) ; 54 | s32 IIC_WriteBytyes(u32 chnnlNo,u8 slaveAddr,u8 *pdata,u32 len); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /cores/opencpu/include/ql_clock.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ql_clock.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The module defines the information, and APIs related to the clock function. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | 34 | 35 | #ifndef __QL_CLOCK_H__ 36 | #define __QL_CLOCK_H__ 37 | 38 | 39 | typedef enum{ 40 | CLOCKSOURCE_26M= 0, 41 | CLOCKSOURCE_13M, 42 | CLOCKSOURCE_6DOT5M, 43 | CLOCKSOURCE_32K, 44 | END_OF_CLOCKSOURCE 45 | }Enum_ClockSource; 46 | 47 | /***************************************************************** 48 | * Function: Ql_CLK_Init 49 | * 50 | * Description: 51 | * This function Initialization a clock pin. 52 | * 53 | * NOTES: 54 | * The clock can't out immediately after Ql_CLK_Init Initialization 55 | * you must invoke Ql_CLK_Output functinon to control clock on or off 56 | * Parameters: 57 | * pinName: 58 | * Pin name, one value of Enum_PinName. 59 | * Enum_ClockSource: 60 | * source clock , one value of Enum_ClockSource. 61 | * Return: 62 | * QL_RET_OK, this function succeeds. 63 | * QL_RET_ERR_NOSUPPORTPIN, the input pin is invalid. 64 | * QL_RET_ERR_PINALREADYSUBCRIBE, the pin is in use in 65 | * other place. For example this pin has been using as EINT. 66 | * QL_RET_ERR_NOGPIOMODE, the input pin no clock mode 67 | * QL_RET_ERR_NOSUPPORTSET not support this function 68 | *****************************************************************/ 69 | s32 Ql_CLK_Init(Enum_PinName clkName,Enum_ClockSource clkSrc); 70 | 71 | /***************************************************************** 72 | * Function: Ql_CLK_Uninit 73 | * 74 | * Description: 75 | * This function release a clock pin. 76 | * 77 | * Parameters: 78 | * pinName: 79 | * Pin name, one value of Enum_PinName. 80 | * Return: 81 | * QL_RET_OK, this function succeeds. 82 | * QL_RET_ERR_NOSUPPORTPIN, the input pin is invalid. 83 | * QL_RET_ERR_BUSSUBBUSY, the PIN not used as clock, 84 | * Maby is used by IIC or SPI,this function can't release it 85 | *****************************************************************/ 86 | s32 Ql_CLK_Uninit(Enum_PinName clkName); 87 | 88 | /***************************************************************** 89 | * Function: Ql_CLK_Output 90 | * 91 | * Description: 92 | * This function control clock on or off 93 | * 94 | * Parameters: 95 | * pinName: 96 | * Pin name, one value of Enum_PinName. 97 | * 98 | * Return: 99 | * QL_RET_OK, this function succeeds. 100 | * QL_RET_ERR_NOSUPPORTPIN, the input pin is invalid. 101 | * QL_RET_ERR_NORIGHTOPERATE, the PIN not in clock mode or not init, 102 | * QL_RET_ERR_NOSUPPORTCONTROL not support control 103 | *****************************************************************/ 104 | s32 Ql_CLK_Output(Enum_PinName pinName,bool clkOnOff); 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /cores/opencpu/include/ql_memory.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ql_memory.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * Memory APIs defines. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | 34 | 35 | #ifndef __QL_MEMORY_H__ 36 | #define __QL_MEMORY_H__ 37 | 38 | 39 | /***************************************************************** 40 | * Function: Ql_MEM_Alloc 41 | * 42 | * Description: 43 | * Allocates memory with the specified size in the memory heap. 44 | * Parameters: 45 | * Size: 46 | * [in]Number of bytes of memory to be allocated. 47 | * Return: 48 | * A pointer of void type to the allocated space. 49 | *****************************************************************/ 50 | void* Ql_MEM_Alloc (u32 size); 51 | 52 | /***************************************************************** 53 | * Function: Ql_MEM_Free 54 | * 55 | * Description: 56 | * Free memory 57 | * Parameters: 58 | * Ptr: 59 | * [in]Previously allocated memory block to be freed. 60 | * Return: 61 | * none 62 | * 63 | *****************************************************************/ 64 | void Ql_MEM_Free (void *ptr); 65 | 66 | #endif // End-of __QL_MEMORY_H__ 67 | 68 | -------------------------------------------------------------------------------- /cores/opencpu/include/ql_stdlib.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ql_stdlib.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * this file provides some Standard library APIs 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | 34 | 35 | #ifndef __QL_STDLIB_H__ 36 | #define __QL_STDLIB_H__ 37 | #include "ql_type.h" 38 | 39 | s32 Ql_atoi(const char* s); 40 | double Ql_atof(const char* s); 41 | void* Ql_memset(void* dest, u8 value, u32 size); 42 | void* Ql_memcpy(void* dest, const void* src, u32 size); 43 | s32 Ql_memcmp(const void* dest, const void*src, u32 size); 44 | void* Ql_memmove(void* dest, const void* src, u32 size); 45 | char* Ql_strcpy(char* dest, const char* src); 46 | char* Ql_strncpy(char* dest, const char* src, u32 size); 47 | char* Ql_strcat(char* s1, const char* s2); 48 | char* Ql_strncat(char* s1, const char* s2, u32 size); 49 | s32 Ql_strcmp(const char*s1, const char*s2); 50 | s32 Ql_strncmp(const char* s1, const char* s2, u32 size); 51 | char* Ql_strchr(const char* s1, s32 ch); 52 | u32 Ql_strlen(const char* str); 53 | char* Ql_strstr(const char* s1, const char* s2); 54 | s32 Ql_toupper(s32 c); 55 | s32 Ql_tolower(s32 c); 56 | s32 Ql_isdigit(char c); 57 | extern s32 (*Ql_sprintf)(char *, const char *, ...); 58 | extern s32 (*Ql_snprintf)(char *, u32, const char *, ...); 59 | extern s32 (*Ql_sscanf)(const char*, const char*, ...); 60 | #endif // __QL_STDLIB_H__ 61 | -------------------------------------------------------------------------------- /cores/opencpu/include/ql_time.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ql_time.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * Time related APIs 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | 34 | 35 | #ifndef __QL_TIME_H__ 36 | #define __QL_TIME_H__ 37 | #include "ql_type.h" 38 | 39 | typedef struct { 40 | s32 year; 41 | s32 month; 42 | s32 day; 43 | s32 hour; 44 | s32 minute; 45 | s32 second; 46 | s32 timezone; // one digit expresses a quarter of an hour, for example: 22 indicates "+5:30" 47 | }ST_Time; 48 | 49 | /***************************************************************** 50 | * Function: Ql_SetLocalTime 51 | * 52 | * Description: 53 | * Set the current local date and time. 54 | * 55 | * Parameters: 56 | * dateTime: 57 | * [in] Point to the ST_Time object 58 | * Return: 59 | * QL_RET_OK indicates this function is executed successesfully. 60 | * QL_RET_ERR_PARAM, indicates the parameter is error. 61 | * 62 | *****************************************************************/ 63 | s32 Ql_SetLocalTime(ST_Time* dateTime); 64 | 65 | /***************************************************************** 66 | * Function: Ql_GetLocalTime 67 | * 68 | * Description: 69 | * Get the current local date and time. 70 | * 71 | * Parameters: 72 | * dateTime: 73 | * [out] Point to the ST_Time object 74 | * Return: 75 | * if succeed,return the current local date and time 76 | * , NULL means get failure. 77 | *****************************************************************/ 78 | ST_Time* Ql_GetLocalTime(ST_Time* dateTime); 79 | 80 | /***************************************************************** 81 | * Function: Ql_Mktime 82 | * 83 | * Description: 84 | * This function get total seconds elapsed 85 | * since 1970.01.01 00:00:00. 86 | * 87 | * Parameters: 88 | * dateTime: 89 | * [in] Point to the ST_Time object 90 | * Return: 91 | * The total seconds 92 | *--------------- 93 | * Usage: 94 | * ST_Time systime; 95 | * Ql_GetLocalTime(&systime); 96 | * seconds = Ql_Mktime(&systime); 97 | *****************************************************************/ 98 | u64 Ql_Mktime(ST_Time* dateTime); 99 | 100 | /***************************************************************** 101 | * Function: Ql_MKTime2CalendarTime 102 | * 103 | * Description: 104 | * This function convert the seconds elapsed since 105 | * 1970.01.01 00:00:00 to local date and time. 106 | * 107 | * Parameters: 108 | * seconds: 109 | * [in] the seconds elapsed since 110 | * 1970.01.01 00:00:00 111 | * pOutDateTime: 112 | * [out] Point to the ST_Time object 113 | * Return: 114 | * if succeed,return the current local date and time 115 | * , NULL means operation failure. 116 | * 117 | *--------------- 118 | * Usage: 119 | * ST_Time systime; 120 | * systime = Ql_MKTime2CalendarTime(seconds, &systime); 121 | * 122 | *****************************************************************/ 123 | ST_Time* Ql_MKTime2CalendarTime(u64 seconds, ST_Time* pOutDateTime); 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /cores/opencpu/include/ql_trace.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ql_trace.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * debug trace API 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | 34 | 35 | #ifndef __QL_TRACE_H__ 36 | #define __QL_TRACE_H__ 37 | #include "ql_type.h" 38 | 39 | typedef enum { 40 | BASIC_MODE, /* In basic mode, debug messages from application will be 41 | output to debug serial port as text. 42 | */ 43 | ADVANCE_MODE /* Default mode. 44 | In advance mode, debug messages from System and application 45 | will be output to debug serial port in special format. Only 46 | the Catcher Tool can capture and display these debug messages 47 | legibly. 48 | */ 49 | } Enum_DebugMode; 50 | 51 | typedef enum{ 52 | PORTNAME_UART1, 53 | PORTNAME_UART2 54 | }Enum_PortName; 55 | 56 | /***************************************************************** 57 | * Function: Ql_Debug_Trace 58 | * 59 | * Description: 60 | * This function prints formatted output to 61 | * debug serial port. Its function is same to 'sprintf'. 62 | * 63 | * Parameters: 64 | * fmt: 65 | * Pointer to a null-terminated multibyte string 66 | * specifying how to interpret the data. 67 | * The maximum string length is 512 bytes. 68 | * Return: 69 | * Number of characters printed 70 | *****************************************************************/ 71 | extern s32 (*Ql_Debug_Trace)(char* fmt, ...); 72 | 73 | #endif // #end-of __QL_TRACE_H__ 74 | -------------------------------------------------------------------------------- /cores/opencpu/include/ql_type.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ql_type.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * OpenCPU Type Definitions 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | 34 | #ifndef __QL_TYPE_H__ 35 | #define __QL_TYPE_H__ 36 | 37 | #ifndef FALSE 38 | #define FALSE 0 39 | #endif 40 | 41 | #ifndef TRUE 42 | #define TRUE 1 43 | #endif 44 | 45 | #ifndef NULL 46 | #define NULL ((void *)0) 47 | #endif 48 | 49 | /**************************************************************************** 50 | * Type Definitions 51 | ***************************************************************************/ 52 | #ifndef ARDUINO 53 | typedef unsigned char bool; 54 | #else 55 | #include 56 | #endif 57 | 58 | typedef unsigned char u8; 59 | typedef signed char s8; 60 | typedef unsigned short u16; 61 | typedef short s16; 62 | typedef unsigned int u32; 63 | typedef int s32; 64 | typedef unsigned long long u64; 65 | typedef long long s64; 66 | typedef unsigned int ticks; 67 | 68 | #endif // End-of __QL_TYPE_H__ 69 | -------------------------------------------------------------------------------- /cores/opencpu/lib_M66FAR01A12BT.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/lib_M66FAR01A12BT.a -------------------------------------------------------------------------------- /cores/opencpu/lib_app_start_m66.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/lib_app_start_m66.a -------------------------------------------------------------------------------- /cores/opencpu/new.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | void * operator new(size_t size) 22 | { 23 | return malloc(size); 24 | } 25 | 26 | void * operator new[](size_t size) 27 | { 28 | return malloc(size); 29 | } 30 | 31 | void operator delete(void *ptr) 32 | { 33 | free(ptr); 34 | } 35 | 36 | void operator delete[](void *ptr) 37 | { 38 | free(ptr); 39 | } 40 | -------------------------------------------------------------------------------- /cores/opencpu/new.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef NEW_H 20 | #define NEW_H 21 | 22 | #include 23 | 24 | void * operator new(size_t size); 25 | void * operator new[](size_t size); 26 | void operator delete(void * ptr); 27 | void operator delete[](void * ptr); 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /cores/opencpu/pgmspace.h: -------------------------------------------------------------------------------- 1 | /* 2 | pgmspace.h - Definitions for compatibility with AVR pgmspace macros 3 | 4 | Copyright (c) 2015 Arduino LLC 5 | 6 | Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE 25 | */ 26 | 27 | #ifndef __PGMSPACE_H_ 28 | #define __PGMSPACE_H_ 1 29 | 30 | #include 31 | 32 | #define PROGMEM 33 | #define PGM_P const char * 34 | #define PSTR(str) (str) 35 | 36 | #define _SFR_BYTE(n) (n) 37 | 38 | typedef void prog_void; 39 | typedef char prog_char; 40 | typedef unsigned char prog_uchar; 41 | typedef int8_t prog_int8_t; 42 | typedef uint8_t prog_uint8_t; 43 | typedef int16_t prog_int16_t; 44 | typedef uint16_t prog_uint16_t; 45 | typedef int32_t prog_int32_t; 46 | typedef uint32_t prog_uint32_t; 47 | typedef int64_t prog_int64_t; 48 | typedef uint64_t prog_uint64_t; 49 | 50 | typedef const void* int_farptr_t; 51 | typedef const void* uint_farptr_t; 52 | 53 | #define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) 54 | #define strcpy_P(dest, src) strcpy((dest), (src)) 55 | #define strncpy_P strncpy 56 | #define strcat_P(dest, src) strcat((dest), (src)) 57 | #define strcmp_P(a, b) strcmp((a), (b)) 58 | #define strstr_P(a, b) strstr((a), (b)) 59 | #define strlen_P(a) strlen((a)) 60 | #define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) 61 | 62 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 63 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 64 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) 65 | #define pgm_read_float(addr) (*(const float *)(addr)) 66 | #define pgm_read_ptr(addr) (*(const void *)(addr)) 67 | 68 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) 69 | #define pgm_read_word_near(addr) pgm_read_word(addr) 70 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) 71 | #define pgm_read_float_near(addr) pgm_read_float(addr) 72 | #define pgm_read_ptr_near(addr) pgm_read_ptr(addr) 73 | 74 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) 75 | #define pgm_read_word_far(addr) pgm_read_word(addr) 76 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) 77 | #define pgm_read_float_far(addr) pgm_read_float(addr) 78 | #define pgm_read_ptr_far(addr) pgm_read_ptr(addr) 79 | 80 | #define pgm_get_far_address(addr) (&(addr)) 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_alarm.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2014 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_alarm.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The module declares RTC alarm related APIs. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __RIL_ALARM_H__ 34 | #define __RIL_ALARM_H__ 35 | #include "ql_time.h" 36 | 37 | /***************************************************************** 38 | * Function: RIL_Alarm_Create 39 | * 40 | * Description: 41 | * Set and start the alarm with the specified date and time. 42 | * 43 | * Parameters: 44 | * dateTime: [in] Pointer to the ST_Time 45 | * mode:[in] 46 | * 0: start alarm only one time. 47 | * 1: repeat alarm every day. 48 | * 2: repeat alarm every week. 49 | * 3: repeat alarm every month. 50 | * Return: 51 | * QL_RET_OK indicates this function successes. 52 | * QL_RET_ERR_PARAM indicates parameter error. 53 | * QL_RET_ERR_INVALID_TIMER indicates invalid timer. 54 | *****************************************************************/ 55 | s32 RIL_Alarm_Create(ST_Time* dateTime, u8 mode); 56 | 57 | /***************************************************************** 58 | * Function: RIL_Alarm_Query 59 | * 60 | * Description: 61 | * Query the current setting of the clock alarm. 62 | * 63 | * Parameters: 64 | * dateTime: [out] Pointer to the ST_Time 65 | * Return: 66 | * QL_RET_OK indicates this function successes. 67 | * QL_RET_ERR_PARAM indicates parameter error. 68 | * QL_RET_ERR_INVALID_TIMER indicates invalid timer. 69 | *****************************************************************/ 70 | s32 RIL_Alarm_Query(ST_Time* dateTime); 71 | 72 | /***************************************************************** 73 | * Function: RIL_Alarm_Remove 74 | * 75 | * Description: 76 | * Remove the alarm. 77 | * 78 | * Parameters: 79 | * dateTime: [out] Pointer to the ST_Time 80 | * 81 | * Return: 82 | * QL_RET_OK indicates this function successes. 83 | * QL_RET_ERR_PARAM indicates this function fail. 84 | *****************************************************************/ 85 | s32 RIL_Alarm_Remove(ST_Time* dateTime); 86 | 87 | #endif //__RIL_ALARM_H__ 88 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_ftp.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_ftp.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The file is for OpenCPU RIL sytem definitions and APIs. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __RIL_SYSTEM_H__ 34 | #define __RIL_FTP_H__ 35 | 36 | typedef void (*CallBack_Ftp_Upload)(s32 result,s32 size); 37 | typedef void (*CallBack_Ftp_Download)(s32 result,s32 size); 38 | 39 | typedef struct{ 40 | char *prefix; 41 | s32 data; 42 | }ST_AT_ftpParam; 43 | 44 | typedef enum 45 | { 46 | FTP_STATUS_IDLE = 0, //No FTP service. 47 | FTP_STATUS_OPENING, //Opening an FTP service. 48 | FTP_STATUS_OPENED, //The FTP service is opened and idle. 49 | FTP_STATUS_WORKING, //Sending FTP commands to the FTP server and receiving response from the FTP server to start data transfer. 50 | FTP_STATUS_TRANSFER, //Transferring data between the module and the FTP server. 51 | FTP_STATUS_CLOSING, //Closing the FTP service. 52 | FTP_STATUS_CLOSED //The FTP service is closed 53 | 54 | }ENUM_FTP_STATUS; 55 | 56 | s32 RIL_FTP_QFTPOPEN(u8* hostName, u32 port,u8* userName,u8* password, bool mode); 57 | 58 | s32 RIL_FTP_QFTPCLOSE(void); 59 | 60 | s32 RIL_FTP_QFTPPUT(u8* fileName, u32 fileSize, u32 timeOut, CallBack_Ftp_Upload ftpPut_CB); 61 | 62 | s32 RIL_FTP_QFTPGET(u8* fileName, u32 fileSize,CallBack_Ftp_Download ftpGet_CB); 63 | 64 | s32 RIL_FTP_QFTPPATH(u8* pathName); 65 | 66 | s32 RIL_FTP_QFTPCFG(u8 type, u8* value); 67 | 68 | s32 RIL_FTP_QFTPSTAT(s32* state); 69 | 70 | s32 RIL_FTP_QFTPLEN(s32* len); 71 | 72 | s32 RIL_FTP_QFTPRENAME(u8* sourcName, u8* targetName); 73 | 74 | s32 RIL_FTP_QFTPSIZE(u8* fileName, u32* fileSize); 75 | 76 | s32 RIL_FTP_QFTPDELETE(u8* fileName); 77 | 78 | s32 RIL_FTP_QFTPMKDIR(u8* pathName); 79 | 80 | s32 RIL_FTP_QFTPRMDIR(u8* pathName); 81 | 82 | s32 RIL_FTP_QIDEACT(void); 83 | 84 | #endif 85 | 86 | 87 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_http.h: -------------------------------------------------------------------------------- 1 | #ifndef __RIL_HTTP_H__ 2 | #define __RIL_HTTP_H__ 3 | 4 | typedef enum{ 5 | HTTP_ACTION_IDLE = 0, 6 | HTTP_ACTION_SETRUL, 7 | HTTP_ACTION_GET_REQ, 8 | HTTP_ACTION_POST_REQ, 9 | HTTP_ACTION_READ_RSP, 10 | HTTP_ACTION_DOWNLOAD_FILE 11 | }Enum_HTTP_Ation; 12 | 13 | // 14 | // 15 | // Set http server URL address. 16 | s32 RIL_HTTP_SetServerURL(char* strURL, u16 len); 17 | // 18 | // Send http-get request. 19 | s32 RIL_HTTP_RequestToGet(u32 timeout); 20 | // 21 | // Send http-post request. 22 | s32 RIL_HTTP_RequestToPost(char* strPostMsg, u16 len); 23 | // 24 | // Read response from HTTP server. 25 | s32 RIL_HTTP_ReadResponse(u32 timeout, CB_RIL_RcvDataFrmCore cb_rcvData); 26 | // 27 | // Downlaod the file from http server to a local file. 28 | // The http file is specified by the url when calling RIL_HTTP_SetServerURL(). 29 | typedef void (*CB_HTTP_DwnldFile)(u32 dllSize, u32 cntntLen, s32 errCode); 30 | s32 RIL_HTTP_DownloadFile(char* filePath, u32 size, CB_HTTP_DwnldFile cb); 31 | 32 | #endif //__RIL_HTTP_H__ 33 | 34 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_location.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_location.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __RIL_LOCATION_H__ 34 | #define __RIL_LOCATION_H__ 35 | 36 | #include "ql_type.h" 37 | 38 | 39 | // Cell info 40 | typedef struct { 41 | u16 mcc; 42 | u16 mnc; 43 | u32 lac; 44 | s32 cellId; 45 | s16 rssi; 46 | u16 timeAd; 47 | }ST_CellInfo; 48 | 49 | // Location info 50 | typedef struct{ 51 | float longitude; 52 | float latitude; 53 | //u16 reserved; 54 | }ST_LocInfo; 55 | 56 | typedef void(*CB_LocInfo)(s32 result,ST_LocInfo* loc_info); 57 | 58 | s32 RIL_GetLocation(CB_LocInfo cb_loc); 59 | s32 RIL_GetLocation_Ex(ST_LocInfo* locinfo); 60 | s32 RIL_GetLocationByCell(ST_CellInfo* cell, CB_LocInfo cb_loc); 61 | 62 | #endif //__RIL_LOCATION_H__ 63 | 64 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_ntp.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2014 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_ntp.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The module implements NTP related APIs. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __RIL_NTP_H__ 34 | #define __RIL_NTP_H__ 35 | 36 | #include "ql_type.h" 37 | 38 | 39 | /***************************************************************** 40 | * Function: RIL_NTP_START 41 | * 42 | * Description: 43 | * This function is used to synchronize time with NTP server. 44 | * 45 | * Parameters: 46 | * : [IN] point to the string which indicates NTP server address. 47 | * : [IN] the NTP server port. 48 | * : [IN] callback function for NTP URC handle. 49 | * Return: 50 | * RIL_AT_SUCCESS,send AT successfully. 51 | * RIL_AT_FAILED, send AT failed. 52 | * RIL_AT_TIMEOUT,send AT timeout. 53 | * RIL_AT_BUSY, sending AT. 54 | * RIL_AT_INVALID_PARAM, invalid input parameter. 55 | * RIL_AT_UNINITIALIZED, RIL is not ready, need to wait for MSG_ID_RIL_READY 56 | * and then call Ql_RIL_Initialize to initialize RIL. 57 | *****************************************************************/ 58 | typedef void (* CB_NTPCMD)(char *strURC); 59 | s32 RIL_NTP_START(u8 *server_addr, u16 server_port, CB_NTPCMD cb_NTPCMD_hdl); 60 | 61 | #endif //__RIL_NTP_H__ 62 | 63 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_sim.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_network.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The file declares some API functions, which are related to SIM card, including 23 | * SIM state, IMSI and CCID. 24 | * 25 | * Author: 26 | * ------- 27 | * ------- 28 | * 29 | *============================================================================ 30 | * HISTORY 31 | *---------------------------------------------------------------------------- 32 | * 33 | ****************************************************************************/ 34 | #ifndef __RIL_SIM_H__ 35 | #define __RIL_SIM_H__ 36 | #include "ql_type.h" 37 | 38 | 39 | /**************************************************************************** 40 | * Definition for SIM Card State 41 | ***************************************************************************/ 42 | typedef enum { 43 | SIM_STAT_NOT_INSERTED = 0, 44 | SIM_STAT_READY, 45 | SIM_STAT_PIN_REQ, 46 | SIM_STAT_PUK_REQ, 47 | SIM_STAT_PH_PIN_REQ, 48 | SIM_STAT_PH_PUK_REQ, 49 | SIM_STAT_PIN2_REQ, 50 | SIM_STAT_PUK2_REQ, 51 | SIM_STAT_BUSY, 52 | SIM_STAT_NOT_READY, 53 | SIM_STAT_UNSPECIFIED 54 | }Enum_SIMState; 55 | 56 | 57 | /****************************************************************************** 58 | * Function: RIL_SIM_GetSimState 59 | * 60 | * Description: 61 | * This function gets the state of SIM card. 62 | * 63 | * Related AT: 64 | * "AT+CPIN?". 65 | * 66 | * Parameters: 67 | * stat: 68 | * [out]SIM card State code, one value of Enum_SIMState. 69 | * Return: 70 | * RIL_AT_SUCCESS, this function succeeds. 71 | * Or, please see the definition of Enum_ATSndError. 72 | ******************************************************************************/ 73 | s32 RIL_SIM_GetSimState(s32* state); 74 | 75 | /****************************************************************************** 76 | * Function: RIL_SIM_GetIMSI 77 | * 78 | * Description: 79 | * This function gets the state of SIM card. 80 | * 81 | * Related AT: 82 | * "AT+CIMI". 83 | * 84 | * Parameters: 85 | * imsi: 86 | * [out]IMSI number, a string of 15-byte. 87 | * Return: 88 | * RIL_AT_SUCCESS, this function succeeds. 89 | * Or, please see the definition of Enum_ATSndError. 90 | ******************************************************************************/ 91 | s32 RIL_SIM_GetIMSI(char* imsi); 92 | 93 | /****************************************************************************** 94 | * Function: RIL_SIM_GetCCID 95 | * 96 | * Description: 97 | * This function gets the CCID of SIM card. 98 | * 99 | * Related AT: 100 | * "AT+CCID". 101 | * 102 | * Parameters: 103 | * ccid: 104 | * [out] CCID number, a string of 20-byte. 105 | * Return: 106 | * RIL_AT_SUCCESS, this function succeeds. 107 | * Or, please see the definition of Enum_ATSndError. 108 | ******************************************************************************/ 109 | s32 RIL_SIM_GetCCID(char* ccid); 110 | 111 | #endif //__RIL_SIM_H__ 112 | 113 | -------------------------------------------------------------------------------- /cores/opencpu/ril/inc/ril_util.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_tuil.h 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The file is for some useful definitions and APIs in common. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #ifndef __RIL_UTIL_H__ 34 | #define __RIL_UTIL_H__ 35 | #include "ql_type.h" 36 | 37 | typedef enum { 38 | CHAR_0 = '0', 39 | CHAR_9 = '9', 40 | CHAR_A = 'A', 41 | CHAR_F = 'F', 42 | END_OF_STR = '\0' 43 | }Enum_Char; 44 | #define IS_NUMBER(alpha_char) \ 45 | (((alpha_char >= CHAR_0) && (alpha_char <= CHAR_9) ) ? 1 : 0) 46 | 47 | extern s32 Ql_StrPrefixMatch(const char* str, const char *prefix); 48 | extern bool Ql_HexStrToInt(u8 *str, u32 *val); 49 | extern char* Ql_StrToUpper(char* str); 50 | /****************************************************************************** 51 | * Function: Ql_RIL_FindString 52 | * 53 | * Description: 54 | * This function is used to match string within a specified length. 55 | * This function is very much like strstr. 56 | * 57 | * Parameters: 58 | * line: 59 | * [in]The address of the string. 60 | * len: 61 | * [in]The length of the string. 62 | * str: 63 | * [in]The specified item which you want to look for in the string. 64 | * 65 | * Return: 66 | The function returns a pointer to the located string, 67 | or a null pointer if the specified string is not found. 68 | ******************************************************************************/ 69 | extern char* Ql_RIL_FindString(char *line, u32 len,char *str); 70 | 71 | /****************************************************************************** 72 | * Function: Ql_RIL_FindLine 73 | * 74 | * Description: 75 | * This function is used to find the specified character line by line. 76 | * for example,if you want to find "OK", In fact, we think that you are 77 | * looking for OK,OK or OK. 78 | * 79 | * 80 | * Parameters: 81 | * line: 82 | * [in]The address of the string. 83 | * len: 84 | * [in]The length of the string. 85 | * str: 86 | * [in]The specified item which you want to look for in the string. 87 | * 88 | * Return: 89 | The function returns a pointer to the located string, 90 | or a null pointer if the specified string is not found. 91 | ******************************************************************************/ 92 | extern char* Ql_RIL_FindLine(char *line, u32 len,char *str); 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_alarm.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_alarm.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_atResponse.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_atResponse.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_bluetooth.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_bluetooth.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_custom.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_custom.c 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The module has been designed for customer to develop new API functions over RIL. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #include "custom_feature_def.h" 34 | #include "ril.h" 35 | #include "ril_util.h" 36 | #include "ql_stdlib.h" 37 | 38 | 39 | #if defined(__OCPU_RIL_SUPPORT__) 40 | 41 | /***************************************************************** 42 | * Function: Ql_RIL_RcvDataFrmCore 43 | * 44 | * Description: 45 | * This function is used to receive data from the core 46 | * system when programing some AT commands that need to 47 | * response with much data, such as "AT+QHTTPREAD". 48 | * 49 | * This function is implemented in ril_custom.c. Developer 50 | * don't need to call this function. Under mode, this function 51 | * will be invoken when data coming automatically. 52 | * 53 | * The CB_RIL_RcvDataFrmCore is defined for ustomer to define 54 | * the callback function for each AT command. 55 | * Parameters: 56 | * [in]ptrData: 57 | * Pointer to the data to be received. 58 | * 59 | * [in]dataLen: 60 | * The length to be received. 61 | * 62 | * [in]reserved: 63 | * Not used. 64 | * 65 | * Return: 66 | * None. 67 | * 68 | *****************************************************************/ 69 | CB_RIL_RcvDataFrmCore cb_rcvCoreData = NULL; 70 | void Ql_RIL_RcvDataFrmCore(u8* ptrData, u32 dataLen, void* reserved) 71 | { 72 | if (cb_rcvCoreData != NULL) 73 | { 74 | cb_rcvCoreData(ptrData, dataLen, reserved); 75 | } 76 | } 77 | 78 | // 79 | // Customer may add new API functions definition here. 80 | // 81 | // 82 | // 83 | // 84 | // 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_init.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_init.c 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * This file is used for customer to inital RIL interface. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #include "custom_feature_def.h" 34 | #include "ril.h" 35 | #include "ql_stdlib.h" 36 | #include "ql_trace.h" 37 | #include "ql_error.h" 38 | #include "ql_system.h" 39 | 40 | #ifdef __OCPU_RIL_SUPPORT__ 41 | 42 | /*********************************************************************** 43 | * Initial commands for RIL. g_InitCmds[] will be used by Ql_RIL_Initialize function. 44 | * Now RIL is implemented based on the following AT commands. 45 | ************************************************************************/ 46 | const char* g_InitCmds[] = { 47 | //"ATE0Q0V1\r", // verbose result codes 48 | "AT+CMEE=1\r", // Extended errors. This item is necessary. 49 | "ATS0=0\r", // No auto-answer. If customer want auto answer the incoming call , must change this string as "ATS0=n\r" (n=1~255). 50 | "AT+CREG=1\r", // GSM registration events . 51 | "AT+CGREG=1\r", // GPRS registration events 52 | "AT+CLIP=1\r", // Display RING number 53 | "AT+COLP=0\r" // no connected line identification 54 | 55 | //...... More customization setting can add here 56 | }; 57 | 58 | u32 RIL_GetInitCmdCnt(void) 59 | { 60 | return NUM_ELEMS(g_InitCmds); 61 | } 62 | 63 | /*********************************************************************** 64 | * Limited commands for RIL. 65 | * Now RIL is implemented based on the opposite functions of the 66 | * following AT commands. 67 | ************************************************************************/ 68 | const char* g_LimitedCmds[] = { 69 | "AT+CMEE=0", 70 | "AT+CLIP", 71 | }; 72 | u32 RIL_GetLimitedCmdCnt(void) 73 | { 74 | return NUM_ELEMS(g_LimitedCmds); 75 | } 76 | 77 | #endif //__OCPU_RIL_SUPPORT__ 78 | -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_location.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_location.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_network.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_network.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_ntp.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2014 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_ntp.c 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The module implements NTP related APIs. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #include "ril_ntp.h" 34 | #include "ril.h" 35 | #include "ril_util.h" 36 | #include "ql_stdlib.h" 37 | #include "ql_error.h" 38 | #include "ql_trace.h" 39 | 40 | static CB_NTPCMD callback_NTPCMD = NULL; 41 | 42 | void OnURCHandler_NTPCMD(const char* strURC, void* reserved) 43 | { 44 | char urcHead[] = "\r\n+QNTP:\0"; 45 | 46 | if ( NULL != callback_NTPCMD ) 47 | { 48 | if( Ql_StrPrefixMatch(strURC, urcHead) ) 49 | { 50 | callback_NTPCMD(strURC); 51 | } 52 | } 53 | } 54 | 55 | s32 RIL_NTP_START(u8 *server_addr, u16 server_port, CB_NTPCMD cb_NTPCMD_hdl) 56 | { 57 | s32 ret = RIL_AT_FAILED; 58 | char strAT[200]; 59 | 60 | if (server_addr == NULL) 61 | { 62 | return RIL_AT_INVALID_PARAM; 63 | } 64 | 65 | callback_NTPCMD = cb_NTPCMD_hdl; 66 | 67 | Ql_memset( strAT, 0, sizeof(strAT) ); 68 | Ql_sprintf( strAT, "AT+QNTP=\"%s\",%d\r\n", server_addr, server_port); 69 | ret = Ql_RIL_SendATCmd( strAT, Ql_strlen(strAT), NULL, NULL, 0 ) ; 70 | 71 | return ret; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_sim.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_sim.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_system.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/cores/opencpu/ril/src/ril_system.c -------------------------------------------------------------------------------- /cores/opencpu/ril/src/ril_telephony.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright Statement: 3 | * -------------------- 4 | * This software is protected by Copyright and the information contained 5 | * herein is confidential. The software may not be copied and the information 6 | * contained herein may not be used or disclosed except with the written 7 | * permission of Quectel Co., Ltd. 2013 8 | * 9 | *****************************************************************************/ 10 | /***************************************************************************** 11 | * 12 | * Filename: 13 | * --------- 14 | * ril_sms.c 15 | * 16 | * Project: 17 | * -------- 18 | * OpenCPU 19 | * 20 | * Description: 21 | * ------------ 22 | * The module implements telephony related APIs. 23 | * 24 | * Author: 25 | * ------- 26 | * ------- 27 | * 28 | *============================================================================ 29 | * HISTORY 30 | *---------------------------------------------------------------------------- 31 | * 32 | ****************************************************************************/ 33 | #include "custom_feature_def.h" 34 | #include "ril.h" 35 | #include "ril_util.h" 36 | #include "ril_telephony.h " 37 | #include "ql_stdlib.h" 38 | 39 | #if defined(__OCPU_RIL_SUPPORT__) 40 | 41 | ST_ComingCallInfo g_comingCall; 42 | 43 | #if defined(__OCPU_RIL_CALL_SUPPORT__) 44 | static s32 Telephony_Dial_AT_handler(char* line, u32 len, void* userdata) 45 | { 46 | char *head = Ql_RIL_FindLine(line, len, "NO DIALTONE"); 47 | if(head) 48 | { 49 | (*(s32* )userdata) = CALL_STATE_NO_DIALTONE; 50 | return RIL_ATRSP_SUCCESS; 51 | } 52 | 53 | head = Ql_RIL_FindLine(line, len, "BUSY"); 54 | if(head) 55 | { 56 | (*(s32* )userdata) = CALL_STATE_BUSY; 57 | return RIL_ATRSP_SUCCESS; 58 | } 59 | 60 | head = Ql_RIL_FindLine(line, len, "NO CARRIER"); 61 | if(head) 62 | { 63 | (*(s32* )userdata) = CALL_STATE_NO_CARRIER; 64 | return RIL_ATRSP_SUCCESS; 65 | } 66 | 67 | head = Ql_RIL_FindLine(line, len, "OK"); 68 | if(head) 69 | { 70 | (*(s32* )userdata) = CALL_STATE_OK; 71 | return RIL_ATRSP_SUCCESS; 72 | } 73 | 74 | head = Ql_RIL_FindLine(line, len, "ERROR"); 75 | if(head) 76 | { 77 | (*(s32* )userdata) = CALL_STATE_ERROR; 78 | return RIL_ATRSP_FAILED; 79 | } 80 | 81 | head = Ql_RIL_FindString(line, len, "+CME ERROR:");//fail 82 | if(head) 83 | { 84 | (*(s32* )userdata) = CALL_STATE_ERROR; 85 | return RIL_ATRSP_FAILED; 86 | } 87 | 88 | return RIL_ATRSP_CONTINUE; //continue wait 89 | } 90 | 91 | s32 RIL_Telephony_Dial(u8 type, char* phoneNumber, s32 *result) 92 | { 93 | char strAT[40]; 94 | if (NULL == phoneNumber) 95 | { 96 | return -1; 97 | } 98 | Ql_memset(strAT, 0x0, sizeof(strAT)); 99 | Ql_sprintf(strAT, "ATD%s;", phoneNumber); 100 | return Ql_RIL_SendATCmd(strAT, Ql_strlen(strAT), Telephony_Dial_AT_handler, (void* )result, 0); 101 | } 102 | 103 | static s32 Telephony_Answer_AT_handler(char* line, u32 len, void* userdata) 104 | { 105 | char *head; 106 | head = Ql_RIL_FindLine(line, len, "OK"); 107 | if(head) 108 | { 109 | (*(s32* )userdata) = CALL_STATE_OK; 110 | return RIL_ATRSP_SUCCESS; 111 | } 112 | 113 | head = Ql_RIL_FindLine(line, len, "NO CARRIER"); 114 | if(head) 115 | { 116 | (*(s32* )userdata) = CALL_STATE_NO_CARRIER; 117 | return RIL_ATRSP_SUCCESS; 118 | } 119 | 120 | head = Ql_RIL_FindLine(line, len, "ERROR"); 121 | if(head) 122 | { 123 | (*(s32* )userdata) = CALL_STATE_ERROR; 124 | return RIL_ATRSP_FAILED; 125 | } 126 | 127 | head = Ql_RIL_FindString(line, len, "+CME ERROR:");//fail 128 | if(head) 129 | { 130 | (*(s32* )userdata) = CALL_STATE_ERROR; 131 | return RIL_ATRSP_FAILED; 132 | } 133 | 134 | return RIL_ATRSP_CONTINUE; //continue wait 135 | } 136 | 137 | s32 RIL_Telephony_Answer(s32 *result) 138 | { 139 | return Ql_RIL_SendATCmd("ATA", 3, Telephony_Answer_AT_handler, result, 0); 140 | } 141 | 142 | s32 RIL_Telephony_Hangup(void) 143 | { 144 | return Ql_RIL_SendATCmd("ATH", 3, NULL, NULL, 0); 145 | } 146 | #endif 147 | #endif 148 | -------------------------------------------------------------------------------- /cores/opencpu/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c 3 | 4 | Copyright (c) 2019 Georgi Angelov 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General 17 | Public License along with this library; if not, write to the 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 19 | Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #include 23 | 24 | inline void yield(void) 25 | { 26 | Ql_Sleep(1); 27 | } 28 | 29 | inline unsigned int millis() 30 | { 31 | return Ql_GetMsSincePwrOn(); 32 | } 33 | 34 | inline unsigned int seconds(void) 35 | { 36 | return millis() / 1000; 37 | } 38 | 39 | inline unsigned int micros() 40 | { 41 | return api_getMicro(); 42 | } 43 | 44 | inline void delayMicroseconds(unsigned int us) 45 | { 46 | api_delayMicro(us); 47 | } 48 | 49 | inline void delay(unsigned int ms) 50 | { 51 | Ql_Sleep(ms); 52 | } 53 | 54 | /////////////////////////////////////////////////////////// 55 | 56 | #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0])) 57 | 58 | PinDescription *getArduinoPin(uint8_t arduinoPin) 59 | { 60 | for (int i = 0; i < ARRAYLEN(pinsMap); i++) 61 | if (pinsMap[i].arduino == arduinoPin) 62 | return &pinsMap[i]; 63 | return NULL; 64 | } 65 | 66 | PinDescription *getDevicePin(uint8_t devicePin) 67 | { 68 | for (int i = 0; i < ARRAYLEN(pinsMap); i++) 69 | if (pinsMap[i].device == devicePin) 70 | return &pinsMap[i]; 71 | return NULL; 72 | } 73 | 74 | static void eint_callback(Enum_PinName eintPinName, Enum_PinLevel pinLevel, void *user) 75 | { 76 | Enum_PinName pin = (Enum_PinName)user; 77 | PinDescription *n = getDevicePin(pin); 78 | if (n && n->eint) 79 | { 80 | Ql_EINT_Mask(pin); 81 | eint_callback_t cb = (eint_callback_t)n->eint; 82 | cb(Ql_EINT_GetLevel(n->device)); 83 | Ql_EINT_Unmask(pin); 84 | } 85 | } 86 | 87 | void eintMode(uint8_t pin, Enum_EintType type, eint_callback_t cb, uint32_t hwDebounce, uint32_t swDebounce, bool automask) 88 | { 89 | PinDescription *n = getArduinoPin(pin); 90 | if (n) 91 | { 92 | if (type == EINT_CLOSE) 93 | { 94 | Ql_EINT_Uninit(n->device); 95 | n->eint = NULL; 96 | } 97 | else if (cb) 98 | { 99 | n->eint = cb; 100 | Ql_EINT_RegisterFast(n->device, eint_callback, (void *)((int)n->device)); 101 | Ql_EINT_Init(n->device, type, hwDebounce, swDebounce, automask); 102 | } 103 | } 104 | } 105 | 106 | /////////////////////////////////////////////////////////// 107 | 108 | static int _irq_; 109 | int api_SaveAndSetIRQMask(void) __attribute__((weak)); 110 | void api_RestoreIRQMask(int) __attribute__((weak)); 111 | 112 | void interrupts(void) 113 | { 114 | api_RestoreIRQMask(_irq_); 115 | } 116 | 117 | void noInterrupts(void) 118 | { 119 | _irq_ = api_SaveAndSetIRQMask(); 120 | } -------------------------------------------------------------------------------- /cores/opencpu/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.15.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #include 7 | 8 | #define PWM_MAX 8193 9 | 10 | static u32 adc_value = 0; 11 | 12 | void analogReference(uint8_t mode) {} 13 | 14 | void analogWrite(uint8_t pin, int val) 15 | { 16 | if (PWM0 == pin) 17 | Ql_PWM_Output((Enum_PinName)pin, val); 18 | } 19 | 20 | void analogClose(uint8_t pin) 21 | { 22 | switch (pin) 23 | { 24 | case ADC0: 25 | Ql_ADC_Sampling((Enum_ADCPin)(pin - PINNAME_END), false); 26 | adc_value = 0; 27 | break; 28 | case PWM0: 29 | Ql_PWM_Uninit((Enum_PinName)pin); 30 | } 31 | } 32 | 33 | int analogRead(uint8_t pin) 34 | { 35 | return adc_value; // 0 ~ 2800mV 36 | } 37 | 38 | static void onADC(Enum_ADCPin adcPin, u32 adcValue, void *customParam) 39 | { 40 | adc_value = adcValue; 41 | } 42 | 43 | void analogOpen(uint8_t pin, /* val, src, div */...) 44 | { 45 | switch (pin) 46 | { 47 | case ADC0: 48 | { 49 | Enum_ADCPin aPin = (Enum_ADCPin)(pin - PINNAME_END); 50 | Ql_ADC_Register(aPin, onADC, NULL); 51 | Ql_ADC_Init(aPin, 5, 200); 52 | Ql_ADC_Sampling(aPin, true); 53 | } 54 | break; 55 | 56 | case PWM0: 57 | { 58 | va_list list; 59 | va_start(list, pin); 60 | uint32_t val = va_arg(list, uint32_t); 61 | uint32_t pwmSrcClk = va_arg(list, uint32_t); 62 | uint32_t pwmDiv = va_arg(list, uint32_t); 63 | Ql_GPIO_Uninit((Enum_PinName)pin); 64 | uint32_t PWM_lowPulseNum = PWM_MAX / 2; 65 | uint32_t PWM_highPulseNum = PWM_MAX / 2; 66 | Ql_PWM_Init((Enum_PinName)pin, (Enum_PwmSource)pwmSrcClk, (Enum_PwmSourceDiv)pwmDiv, PWM_lowPulseNum, PWM_highPulseNum); 67 | Ql_PWM_Output((Enum_PinName)pin, val); 68 | } 69 | break; 70 | 71 | } //switch 72 | } 73 | -------------------------------------------------------------------------------- /cores/opencpu/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 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 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 28 September 2018 by Georgi Angelov 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | void pinMode(uint8_t pin, uint8_t mode) 29 | { 30 | PinDescription *n = getArduinoPin(pin); 31 | if (n) 32 | { 33 | if (mode == CLOSE) 34 | { 35 | Ql_GPIO_Uninit(n->device); 36 | n->device = PINNAME_END; 37 | } 38 | else 39 | { 40 | Enum_PinPullSel pull = PINPULLSEL_DISABLE; 41 | Enum_PinDirection dir = PINDIRECTION_IN; 42 | Enum_PinLevel level = PINLEVEL_LOW; 43 | if (mode & INPUT_PULLUP) 44 | pull = PINPULLSEL_PULLUP; 45 | if (mode & INPUT_PULLDOWN) 46 | pull = PINPULLSEL_PULLDOWN; 47 | if ((mode & OUTPUT) || (mode & OUTPUT_LO) || (mode & OUTPUT_HI)) 48 | dir = PINDIRECTION_OUT; 49 | if (mode & OUTPUT_HI) 50 | level = PINLEVEL_HIGH; 51 | Ql_GPIO_Init(n->device, dir, level, pull); 52 | } 53 | } 54 | } 55 | 56 | void digitalWrite(uint8_t pin, uint8_t val) 57 | { 58 | PinDescription *n = getArduinoPin(pin); 59 | if (n) 60 | Ql_GPIO_SetLevel(n->device, (Enum_PinLevel)val & 1); 61 | } 62 | 63 | int digitalRead(uint8_t pin) 64 | { 65 | PinDescription *n = getArduinoPin(pin); 66 | if (n) 67 | return Ql_GPIO_GetLevel(n->device); 68 | return -1; 69 | } 70 | -------------------------------------------------------------------------------- /cores/opencpu/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_pulse.c - pulseIn() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 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 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #include 24 | 25 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) 26 | { 27 | uint32_t init_time = micros(); 28 | uint32_t curr_time = init_time; 29 | uint32_t max_time = init_time + timeout; 30 | int pin_state = 0; 31 | 32 | /* read GPIO info */ 33 | pin_state = digitalRead(pin); 34 | 35 | // wait for any previous pulse to end 36 | while ((pin_state == state) && (curr_time < max_time)) 37 | { 38 | curr_time = micros(); 39 | pin_state = digitalRead(pin); 40 | } 41 | 42 | // wait for the pulse to start 43 | while ((pin_state != state) && (curr_time < max_time)) 44 | { 45 | curr_time = micros(); 46 | init_time = curr_time; 47 | pin_state = digitalRead(pin); 48 | } 49 | 50 | // wait for the pulse to stop 51 | while ((pin_state == state) && (curr_time < max_time)) 52 | { 53 | curr_time = micros(); 54 | pin_state = digitalRead(pin); 55 | } 56 | 57 | if (curr_time < max_time) 58 | { 59 | return (curr_time - init_time); 60 | } 61 | else 62 | { 63 | return 0; 64 | } 65 | } -------------------------------------------------------------------------------- /cores/opencpu/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 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 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #include 24 | 25 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) 26 | { 27 | uint8_t value = 0; 28 | uint8_t i; 29 | for (i = 0; i < 8; ++i) 30 | { 31 | digitalWrite(clockPin, HIGH); 32 | if (bitOrder == LSBFIRST) 33 | value |= digitalRead(dataPin) << i; 34 | else 35 | value |= digitalRead(dataPin) << (7 - i); 36 | digitalWrite(clockPin, LOW); 37 | } 38 | return value; 39 | } 40 | 41 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 42 | { 43 | uint8_t i; 44 | for (i = 0; i < 8; i++) 45 | { 46 | if (bitOrder == LSBFIRST) 47 | digitalWrite(dataPin, !!(val & (1 << i))); 48 | else 49 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 50 | 51 | digitalWrite(clockPin, HIGH); 52 | digitalWrite(clockPin, LOW); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Clear 3 | * 4 | * Sets all of the bytes of the EEPROM to 0. 5 | * Please see eeprom_iteration for a more in depth 6 | * look at how to traverse the EEPROM. 7 | * 8 | * This example code is in the public domain. 9 | */ 10 | 11 | #include 12 | 13 | void setup() { 14 | // initialize the LED pin as an output. 15 | pinMode(13, OUTPUT); 16 | 17 | /*** 18 | Iterate through each byte of the EEPROM storage. 19 | 20 | Larger AVR processors have larger EEPROM sizes, E.g: 21 | - Arduno Duemilanove: 512b EEPROM storage. 22 | - Arduino Uno: 1kb EEPROM storage. 23 | - Arduino Mega: 4kb EEPROM storage. 24 | 25 | Rather than hard-coding the length, you should use the pre-provided length function. 26 | This will make your code portable to all AVR processors. 27 | ***/ 28 | 29 | for (int i = 0 ; i < EEPROM.length() ; i++) { 30 | EEPROM.write(i, 0); 31 | } 32 | 33 | // turn the LED on when we're done 34 | digitalWrite(13, HIGH); 35 | } 36 | 37 | void loop() { 38 | /** Empty loop. **/ 39 | } 40 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | Written by Christopher Andrews. 3 | CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). 4 | 5 | A CRC is a simple way of checking whether data has changed or become corrupted. 6 | This example calculates a CRC value directly on the EEPROM values. 7 | The purpose of this example is to highlight how the EEPROM object can be used just like an array. 8 | ***/ 9 | 10 | #include 11 | #include 12 | 13 | void setup() { 14 | 15 | //Start serial 16 | Serial.begin(9600); 17 | while (!Serial) { 18 | ; // wait for serial port to connect. Needed for native USB port only 19 | } 20 | 21 | //Print length of data to run CRC on. 22 | Serial.print("EEPROM length: "); 23 | Serial.println(EEPROM.length()); 24 | 25 | //Print the result of calling eeprom_crc() 26 | Serial.print("CRC32 of EEPROM data: 0x"); 27 | Serial.println(eeprom_crc(), HEX); 28 | Serial.print("\n\nDone!"); 29 | } 30 | 31 | void loop() { 32 | /* Empty loop */ 33 | } 34 | 35 | unsigned long eeprom_crc(void) { 36 | 37 | const unsigned long crc_table[16] = { 38 | 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 39 | 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 40 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 41 | 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c 42 | }; 43 | 44 | unsigned long crc = ~0L; 45 | 46 | for (int index = 0 ; index < EEPROM.length() ; ++index) { 47 | crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); 48 | crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); 49 | crc = ~crc; 50 | } 51 | return crc; 52 | } 53 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_get/eeprom_get.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_get example. 3 | 4 | This shows how to use the EEPROM.get() method. 5 | 6 | To pre-set the EEPROM data, run the example sketch eeprom_put. 7 | This sketch will run without it, however, the values shown 8 | will be shown from what ever is already on the EEPROM. 9 | 10 | This may cause the serial object to print out a large string 11 | of garbage if there is no null character inside one of the strings 12 | loaded. 13 | 14 | Written by Christopher Andrews 2015 15 | Released under MIT licence. 16 | ***/ 17 | 18 | #include 19 | 20 | void setup() { 21 | 22 | float f = 0.00f; //Variable to store data read from EEPROM. 23 | int eeAddress = 0; //EEPROM address to start reading from 24 | 25 | Serial.begin(9600); 26 | while (!Serial) { 27 | ; // wait for serial port to connect. Needed for native USB port only 28 | } 29 | Serial.print("Read float from EEPROM: "); 30 | 31 | //Get the float data from the EEPROM at position 'eeAddress' 32 | EEPROM.get(eeAddress, f); 33 | Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. 34 | 35 | /*** 36 | As get also returns a reference to 'f', you can use it inline. 37 | E.g: Serial.print( EEPROM.get( eeAddress, f ) ); 38 | ***/ 39 | 40 | /*** 41 | Get can be used with custom structures too. 42 | I have separated this into an extra function. 43 | ***/ 44 | 45 | secondTest(); //Run the next test. 46 | } 47 | 48 | struct MyObject { 49 | float field1; 50 | byte field2; 51 | char name[10]; 52 | }; 53 | 54 | void secondTest() { 55 | int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. 56 | 57 | MyObject customVar; //Variable to store custom object read from EEPROM. 58 | EEPROM.get(eeAddress, customVar); 59 | 60 | Serial.println("Read custom object from EEPROM: "); 61 | Serial.println(customVar.field1); 62 | Serial.println(customVar.field2); 63 | Serial.println(customVar.name); 64 | } 65 | 66 | void loop() { 67 | /* Empty loop */ 68 | } 69 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_iteration example. 3 | 4 | A set of example snippets highlighting the 5 | simplest methods for traversing the EEPROM. 6 | 7 | Running this sketch is not necessary, this is 8 | simply highlighting certain programming methods. 9 | 10 | Written by Christopher Andrews 2015 11 | Released under MIT licence. 12 | ***/ 13 | 14 | #include 15 | 16 | void setup() { 17 | 18 | /*** 19 | Iterate the EEPROM using a for loop. 20 | ***/ 21 | 22 | for (int index = 0 ; index < EEPROM.length() ; index++) { 23 | 24 | //Add one to each cell in the EEPROM 25 | EEPROM[ index ] += 1; 26 | } 27 | 28 | /*** 29 | Iterate the EEPROM using a while loop. 30 | ***/ 31 | 32 | int index = 0; 33 | 34 | while (index < EEPROM.length()) { 35 | 36 | //Add one to each cell in the EEPROM 37 | EEPROM[ index ] += 1; 38 | index++; 39 | } 40 | 41 | /*** 42 | Iterate the EEPROM using a do-while loop. 43 | ***/ 44 | 45 | int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. 46 | 47 | do { 48 | 49 | //Add one to each cell in the EEPROM 50 | EEPROM[ idx ] += 1; 51 | idx++; 52 | } while (idx < EEPROM.length()); 53 | 54 | 55 | } //End of setup function. 56 | 57 | void loop() {} -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_put/eeprom_put.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_put example. 3 | 4 | This shows how to use the EEPROM.put() method. 5 | Also, this sketch will pre-set the EEPROM data for the 6 | example sketch eeprom_get. 7 | 8 | Note, unlike the single byte version EEPROM.write(), 9 | the put method will use update semantics. As in a byte 10 | will only be written to the EEPROM if the data is actually 11 | different. 12 | 13 | Written by Christopher Andrews 2015 14 | Released under MIT licence. 15 | ***/ 16 | 17 | #include 18 | 19 | struct MyObject { 20 | float field1; 21 | byte field2; 22 | char name[10]; 23 | }; 24 | 25 | void setup() { 26 | 27 | Serial.begin(9600); 28 | while (!Serial) { 29 | ; // wait for serial port to connect. Needed for native USB port only 30 | } 31 | 32 | float f = 123.456f; //Variable to store in EEPROM. 33 | int eeAddress = 0; //Location we want the data to be put. 34 | 35 | 36 | //One simple call, with the address first and the object second. 37 | EEPROM.put(eeAddress, f); 38 | 39 | Serial.println("Written float data type!"); 40 | 41 | /** Put is designed for use with custom structures also. **/ 42 | 43 | //Data to store. 44 | MyObject customVar = { 45 | 3.14f, 46 | 65, 47 | "Working!" 48 | }; 49 | 50 | eeAddress += sizeof(float); //Move address to the next byte after float 'f'. 51 | 52 | EEPROM.put(eeAddress, customVar); 53 | Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); 54 | } 55 | 56 | void loop() { 57 | /* Empty loop */ 58 | } 59 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_read/eeprom_read.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Read 3 | * 4 | * Reads the value of each byte of the EEPROM and prints it 5 | * to the computer. 6 | * This example code is in the public domain. 7 | */ 8 | 9 | #include 10 | 11 | // start reading from the first byte (address 0) of the EEPROM 12 | int address = 0; 13 | byte value; 14 | 15 | void setup() { 16 | // initialize serial and wait for port to open: 17 | Serial.begin(9600); 18 | while (!Serial) { 19 | ; // wait for serial port to connect. Needed for native USB port only 20 | } 21 | } 22 | 23 | void loop() { 24 | // read a byte from the current address of the EEPROM 25 | value = EEPROM.read(address); 26 | 27 | Serial.print(address); 28 | Serial.print("\t"); 29 | Serial.print(value, DEC); 30 | Serial.println(); 31 | 32 | /*** 33 | Advance to the next address, when at the end restart at the beginning. 34 | 35 | Larger AVR processors have larger EEPROM sizes, E.g: 36 | - Arduno Duemilanove: 512b EEPROM storage. 37 | - Arduino Uno: 1kb EEPROM storage. 38 | - Arduino Mega: 4kb EEPROM storage. 39 | 40 | Rather than hard-coding the length, you should use the pre-provided length function. 41 | This will make your code portable to all AVR processors. 42 | ***/ 43 | address = address + 1; 44 | if (address == EEPROM.length()) { 45 | address = 0; 46 | } 47 | 48 | /*** 49 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 50 | EEPROM address is also doable by a bitwise and of the length - 1. 51 | 52 | ++address &= EEPROM.length() - 1; 53 | ***/ 54 | 55 | delay(500); 56 | } 57 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_update/eeprom_update.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | EEPROM Update method 3 | 4 | Stores values read from analog input 0 into the EEPROM. 5 | These values will stay in the EEPROM when the board is 6 | turned off and may be retrieved later by another sketch. 7 | 8 | If a value has not changed in the EEPROM, it is not overwritten 9 | which would reduce the life span of the EEPROM unnecessarily. 10 | 11 | Released using MIT licence. 12 | ***/ 13 | 14 | #include 15 | 16 | /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ 17 | int address = 0; 18 | 19 | void setup() { 20 | /** EMpty setup **/ 21 | } 22 | 23 | void loop() { 24 | /*** 25 | need to divide by 4 because analog inputs range from 26 | 0 to 1023 and each byte of the EEPROM can only hold a 27 | value from 0 to 255. 28 | ***/ 29 | int val = analogRead(0) / 4; 30 | 31 | /*** 32 | Update the particular EEPROM cell. 33 | these values will remain there when the board is 34 | turned off. 35 | ***/ 36 | EEPROM.update(address, val); 37 | 38 | /*** 39 | The function EEPROM.update(address, val) is equivalent to the following: 40 | 41 | if( EEPROM.read(address) != val ){ 42 | EEPROM.write(address, val); 43 | } 44 | ***/ 45 | 46 | 47 | /*** 48 | Advance to the next address, when at the end restart at the beginning. 49 | 50 | Larger AVR processors have larger EEPROM sizes, E.g: 51 | - Arduno Duemilanove: 512b EEPROM storage. 52 | - Arduino Uno: 1kb EEPROM storage. 53 | - Arduino Mega: 4kb EEPROM storage. 54 | 55 | Rather than hard-coding the length, you should use the pre-provided length function. 56 | This will make your code portable to all AVR processors. 57 | ***/ 58 | address = address + 1; 59 | if (address == EEPROM.length()) { 60 | address = 0; 61 | } 62 | 63 | /*** 64 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 65 | EEPROM address is also doable by a bitwise and of the length - 1. 66 | 67 | ++address &= EEPROM.length() - 1; 68 | ***/ 69 | 70 | delay(100); 71 | } 72 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_write/eeprom_write.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Write 3 | * 4 | * Stores values read from analog input 0 into the EEPROM. 5 | * These values will stay in the EEPROM when the board is 6 | * turned off and may be retrieved later by another sketch. 7 | */ 8 | 9 | #include 10 | 11 | /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ 12 | int addr = 0; 13 | 14 | void setup() { 15 | /** Empty setup. **/ 16 | } 17 | 18 | void loop() { 19 | /*** 20 | Need to divide by 4 because analog inputs range from 21 | 0 to 1023 and each byte of the EEPROM can only hold a 22 | value from 0 to 255. 23 | ***/ 24 | 25 | int val = analogRead(0) / 4; 26 | 27 | /*** 28 | Write the value to the appropriate byte of the EEPROM. 29 | these values will remain there when the board is 30 | turned off. 31 | ***/ 32 | 33 | EEPROM.write(addr, val); 34 | 35 | /*** 36 | Advance to the next address, when at the end restart at the beginning. 37 | 38 | Larger AVR processors have larger EEPROM sizes, E.g: 39 | - Arduno Duemilanove: 512b EEPROM storage. 40 | - Arduino Uno: 1kb EEPROM storage. 41 | - Arduino Mega: 4kb EEPROM storage. 42 | 43 | Rather than hard-coding the length, you should use the pre-provided length function. 44 | This will make your code portable to all AVR processors. 45 | ***/ 46 | addr = addr + 1; 47 | if (addr == EEPROM.length()) { 48 | addr = 0; 49 | } 50 | 51 | /*** 52 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 53 | EEPROM address is also doable by a bitwise and of the length - 1. 54 | 55 | ++addr &= EEPROM.length() - 1; 56 | ***/ 57 | 58 | 59 | delay(100); 60 | } 61 | -------------------------------------------------------------------------------- /libraries/EEPROM/library.properties: -------------------------------------------------------------------------------- 1 | name=EEPROM 2 | version=1.0 3 | author=MediaTek Labs 4 | maintainer=Georgi Angelov 5 | sentence=EEPROM implementation by NVDM 6 | paragraph= 7 | category=Data Storage 8 | url=https://github.com/Wiz-IO 9 | architectures=m66 -------------------------------------------------------------------------------- /libraries/EEPROM/src/EEPROM.cpp: -------------------------------------------------------------------------------- 1 | /* for Quectel 2 | * Created on: 01.01.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #include "EEPROM.h" 7 | 8 | #ifdef __OCPU_RIL_SUPPORT__ 9 | 10 | EEPROMClass EEPROM; 11 | 12 | // cell from 1 to 13 13 | static void ql_eeprom_get_index(u32 address, u8 *cell, u32 *size, u32 *offset) 14 | { 15 | if (address < 400) 16 | { 17 | *cell = 1 + (address / 50); 18 | *size = 50; 19 | *offset = 0; 20 | return; 21 | } 22 | else if (address < 800) 23 | { 24 | address -= 400; 25 | *cell = 9 + (address / 100); 26 | *size = 100; 27 | *offset = 400; 28 | return; 29 | } 30 | else 31 | { 32 | *cell = 13; 33 | *size = 500; 34 | *offset = 800; 35 | } 36 | } 37 | 38 | uint8_t EERef::operator*() const 39 | { 40 | if (index < _EEPROM_SIZE) 41 | { 42 | u8 cell; 43 | u32 size, offset; 44 | ql_eeprom_get_index(index, &cell, &size, &offset); 45 | uint8_t data[size]; 46 | int res = Ql_SecureData_Read(cell, (u8 *)data, size); // RIL 47 | DEBUG_EEP("Read cell = %d, size = %d, res = %d", cell, size, res); 48 | if (size == res) 49 | { 50 | return data[index - offset]; 51 | } 52 | else 53 | { 54 | DEBUG_EEP("Read failed. Return 0 as value"); 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | EERef &EERef::operator=(uint8_t in) 61 | { 62 | if (index < _EEPROM_SIZE) 63 | { 64 | u8 cell; 65 | u32 size, offset; 66 | ql_eeprom_get_index(index, &cell, &size, &offset); 67 | uint8_t data[size]; 68 | int res = Ql_SecureData_Read(cell, (u8 *)data, size); // RIL 69 | DEBUG_EEP("Write cell = %d, size = %d, res = %d", cell, size, res); 70 | if (size == res) 71 | { 72 | data[index - offset] = in; 73 | Ql_SecureData_Store(cell, (u8 *)data, size); // RIL 74 | } 75 | else 76 | { 77 | DEBUG_EEP("Write failed ( %d )", res); 78 | } 79 | } 80 | return *this; 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/tcp_http/tcp_http.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | gprsClient tcp; 5 | #define HOST "wizio.eu" 6 | 7 | void tcp_http() 8 | { 9 | Serial.println("Test TCP\n"); 10 | int timeout = 0; 11 | int r = tcp.connect(HOST, 80); 12 | DBG("connect: %d\n", r); 13 | if (r == 1) 14 | { 15 | char data[] = "GET /iot.php HTTP/1.1\r\nHost:" HOST "\r\n\r\n"; 16 | r = tcp.write(data, strlen(data)); 17 | DBG("sent: %d\n", r); 18 | delay(100); 19 | do 20 | { 21 | while (tcp.available()) 22 | { 23 | r = tcp.read(); // read byte 24 | if (r > 0) { 25 | Serial.print((char)r); 26 | continue; 27 | } else 28 | goto end; 29 | } 30 | delay(100); 31 | } while (++timeout < 100); 32 | end: 33 | delay(10); 34 | } 35 | tcp.stop(); 36 | } 37 | 38 | void setup() { 39 | String imei; 40 | Dev.noSleep(); 41 | Serial.begin(115200); 42 | Serial.printf("Arduino %s\n", Dev.getVersion()); 43 | Dev.getImei(imei); 44 | Serial.printf("IMEI %s\n", imei.c_str()); 45 | Dev.waitSimReady(); 46 | Serial.println("Sim Ready"); 47 | Dev.waitCereg(); 48 | delay(200); // must 49 | Serial.println("Net Ready"); 50 | while (false == gprs.act()) 51 | delay(10000); 52 | Serial.println("GPRS Ready"); 53 | tcp_http(); 54 | pinMode(LED, OUTPUT); 55 | } 56 | 57 | void loop() { 58 | static int state = 0; 59 | static int led = 0; 60 | if(200 % state == 0) 61 | digitalWrite(LED, ++led & 1); 62 | state++; 63 | } 64 | 65 | 66 | /* RESULT: 67 | 68 | Arduino M66FAR01A12BT 69 | IMEI 868325029039365 70 | Sim Ready 71 | Net Ready 72 | GPRS Ready 73 | Test TCP 74 | 75 | HTTP/1.1 200 OK 76 | Date: Mon, 15 Apr 2019 07:15:00 GMT 77 | Server: Apache 78 | Upgrade: h2,h2c 79 | Connection: Upgrade 80 | Cache-Control: max-age=0 81 | Expires: Mon, 15 Apr 2019 07:15:00 GMT 82 | Content-Length: 47 83 | Content-Type: text/html 84 | 85 | [WIZIO.EU] Hello World ( 2019-04-15 10:15:00 ) 86 | 87 | */ -------------------------------------------------------------------------------- /libraries/Ethernet/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ethernet 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Ethernet KEYWORD1 Ethernet 10 | EthernetClient KEYWORD1 EthernetClient 11 | EthernetServer KEYWORD1 EthernetServer 12 | IPAddress KEYWORD1 EthernetIPAddress 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | status KEYWORD2 19 | connect KEYWORD2 20 | write KEYWORD2 21 | available KEYWORD2 22 | read KEYWORD2 23 | peek KEYWORD2 24 | flush KEYWORD2 25 | stop KEYWORD2 26 | connected KEYWORD2 27 | begin KEYWORD2 28 | beginPacket KEYWORD2 29 | endPacket KEYWORD2 30 | parsePacket KEYWORD2 31 | remoteIP KEYWORD2 32 | remotePort KEYWORD2 33 | getSocketNumber KEYWORD2 34 | localIP KEYWORD2 35 | maintain KEYWORD2 36 | 37 | ####################################### 38 | # Constants (LITERAL1) 39 | ####################################### 40 | 41 | -------------------------------------------------------------------------------- /libraries/Ethernet/library.properties: -------------------------------------------------------------------------------- 1 | name=GPRS Ethernet 2 | version=1.0.0 3 | author=Various 4 | maintainer=Georgi Angelov 5 | sentence=GPRS TCP/UDP Clients. 6 | paragraph=With this library you can connect to Internet. 7 | category=Communication 8 | url=https://github.com/Wiz-IO 9 | architectures=m66 10 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/gprsClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | gprsClient.cpp - Library 3 | 4 | Created on: 01.03.2019 5 | Author: Georgi Angelov 6 | */ 7 | 8 | #include "gprsClient.h" 9 | 10 | gprsClient::gprsClient() 11 | { 12 | id = 0; 13 | peeked = 0; 14 | Peek = 0; 15 | m_externalSocket = true; 16 | m_socket = -1; 17 | } 18 | 19 | gprsClient::gprsClient(int contextID) 20 | 21 | { 22 | id = contextID; 23 | peeked = 0; 24 | Peek = 0; 25 | m_externalSocket = 0; 26 | m_socket = -1; 27 | } 28 | 29 | gprsClient::gprsClient(int socket, int contextID) 30 | { 31 | id = contextID; 32 | peeked = 0; 33 | Peek = 0; 34 | m_externalSocket = 1; 35 | m_socket = socket; 36 | } 37 | 38 | gprsClient::~gprsClient() 39 | { 40 | if (!m_externalSocket) 41 | stop(); 42 | } 43 | 44 | int gprsClient::connect(unsigned int ip, unsigned short port) 45 | { 46 | if (m_socket) 47 | stop(); 48 | m_socket = Ql_SOC_Create(id, SOC_TYPE_TCP); 49 | m_externalSocket = true; 50 | if (m_socket < 0) 51 | { 52 | DEBUG_TCP("Ql_SOC_Create() failed!"); 53 | return false; 54 | } 55 | int res = Ql_SOC_ConnectEx(m_socket, (unsigned int)Ql_convertIP(ip), port, true); // blocked 56 | DEBUG_TCP("Ql_SOC_Connect( soc = %d ) r = %d", m_socket, res); 57 | return res == SOC_SUCCESS; // true = OK 58 | } 59 | 60 | int gprsClient::connect(IPAddress IP, unsigned short port) 61 | { 62 | return connect((uint32_t)IP, port); 63 | } 64 | 65 | int gprsClient::connect(const char *host, unsigned short port) 66 | { 67 | uint32_t ip; 68 | IPAddress IP; 69 | DNSClient d; 70 | if (d.getHostByName(host, IP)) 71 | return connect(IP, port); 72 | DEBUG_TCP("could not get host from dns"); 73 | return false; 74 | } 75 | 76 | size_t gprsClient::write(unsigned char b) 77 | { 78 | if (m_socket == -1) 79 | return 0; 80 | int w = Ql_SOC_Send(m_socket, &b, 1); 81 | DEBUG_TCP("Ql_SOC_Send( 1 ) w = %d", w); 82 | return w > -1 ? 1 : 0; 83 | } 84 | 85 | size_t gprsClient::write(const unsigned char *buffer, size_t size) 86 | { 87 | if (m_socket == -1 || NULL == buffer || size == 0) 88 | return 0; 89 | int w = Ql_SOC_Send(m_socket, (u8 *)buffer, size); 90 | DEBUG_TCP("Ql_SOC_Send( %d ) w = %d", size, w); 91 | return w > -1 ? w : 0; 92 | } 93 | 94 | int gprsClient::read() 95 | { 96 | if (m_socket == -1) 97 | return -1; 98 | if (peeked) 99 | { 100 | peeked = false; 101 | return Peek; 102 | } 103 | unsigned char b; 104 | return (1 == Ql_SOC_Recv(m_socket, &b, 1)) ? b : -1; // no wait 105 | } 106 | 107 | int gprsClient::read(unsigned char *buffer, size_t size) 108 | { 109 | if (m_socket == -1 || NULL == buffer || size == 0) 110 | return 0; 111 | unsigned char *p = buffer; 112 | if (peeked) 113 | { 114 | peeked = false; 115 | *p++ = Peek; 116 | size -= 1; 117 | if (0 == size) 118 | return 1; 119 | } 120 | int r = Ql_SOC_Recv(m_socket, p, size); // no wait 121 | DEBUG_TCP("Ql_SOC_Recv( %d ) r = %d", size, r); 122 | return r > -1 ? r : -1; 123 | } 124 | 125 | int gprsClient::available() 126 | { 127 | //return m_socket > -1 && peek() > -1;// without soc_getsockopt 128 | short val; 129 | return (0 == api_soc_getsockopt(m_socket, SOC_NREAD, &val, 2)) ? val : -1; 130 | } 131 | 132 | int gprsClient::peek() 133 | { 134 | if (m_socket > -1) 135 | { 136 | if (peeked) 137 | { 138 | DEBUG_TCP("peeked( %02X )", (int)Peek & 0xFF); 139 | return Peek; 140 | } 141 | peeked = 1 == Ql_SOC_Recv(m_socket, &Peek, 1); // no wait 142 | if (peeked) 143 | { 144 | DEBUG_TCP("peek( %02X )", (int)Peek & 0xFF); 145 | return Peek; 146 | } 147 | } 148 | return -1; 149 | } 150 | 151 | void gprsClient::stop() 152 | { 153 | if (m_socket > -1) 154 | { 155 | Ql_SOC_Close(m_socket); 156 | DEBUG_TCP("Ql_SOC_Close()"); 157 | m_socket = -1; 158 | } 159 | } 160 | 161 | unsigned char gprsClient::connected() 162 | { 163 | return m_socket > -1; 164 | } 165 | 166 | gprsClient::operator bool() 167 | { 168 | return connected(); 169 | } -------------------------------------------------------------------------------- /libraries/Ethernet/src/gprsClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | gprsClient.cpp - Library 3 | */ 4 | 5 | #ifndef _GPRS_TCP_H_ 6 | #define _GPRS_TCP_H_ 7 | 8 | #include 9 | #include "Client.h" 10 | #include "IPAddress.h" 11 | #include "gprsDNS.h" 12 | 13 | #define DEBUG_TCP(F, ...) 14 | //DBG("[TCP] " F "\n", ##__VA_ARGS__) 15 | 16 | class gprsClient : public Client 17 | { 18 | 19 | private: 20 | char id; 21 | unsigned char Peek; 22 | bool peeked; 23 | 24 | public: 25 | gprsClient(); 26 | gprsClient(int contextID); 27 | gprsClient(int soc, int contextID); 28 | ~gprsClient(); 29 | 30 | int connect(unsigned int ip, unsigned short port); 31 | virtual int connect(IPAddress ip, unsigned short port); 32 | virtual int connect(const char *host, unsigned short port); 33 | virtual size_t write(unsigned char); 34 | virtual size_t write(const unsigned char *buf, size_t size); 35 | virtual int available(); 36 | virtual int read(); 37 | virtual int read(unsigned char *buf, size_t size); 38 | virtual int peek(); 39 | virtual void flush() {} 40 | virtual void stop(); 41 | virtual unsigned char connected(); 42 | virtual operator bool(); 43 | 44 | friend class WiFiServer; 45 | using Print::write; 46 | 47 | private: 48 | int m_socket; 49 | bool m_externalSocket; 50 | }; 51 | 52 | #endif // _GPRS_TCP_H_ -------------------------------------------------------------------------------- /libraries/Ethernet/src/gprsDNS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DNSClient 3 | * 4 | * Created on: 03.03.2019 5 | * Author: Georgi Angelov 6 | */ 7 | 8 | #include "gprsDNS.h" 9 | 10 | static int dns_Code; 11 | static IPAddress dns_IP; 12 | static void Callback_GetIpByName(u8 contexId, u8 requestId, s32 errCode, u32 ipAddrCnt, u32 *ipAddr) 13 | { 14 | DEBUG_DNS("CALLBACK = %d, %d", errCode, ipAddrCnt); 15 | dns_Code = errCode; 16 | if (errCode == SOC_SUCCESS && ipAddrCnt > 0) 17 | { 18 | dns_IP = (uint32_t)*ipAddr; 19 | } 20 | else 21 | { 22 | DEBUG_DNS("[DNS] ERROR Callback: %d\n", errCode); 23 | } 24 | } 25 | 26 | bool DNSClient::getHostByName(const char *host, IPAddress &IP, unsigned char id) 27 | { 28 | uint32_t ip; 29 | if (Ql_inet_aton(host, &ip)) 30 | { 31 | IP = (uint32_t)ip; 32 | return true; 33 | } 34 | 35 | IP = (uint32_t)0; 36 | if (!host || id > 1) 37 | return false; 38 | // todo MUTEX_LOCK 39 | dns_Code = -1; 40 | int r = Ql_IpHelper_GetIPByHostName(0, 0, (u8 *)host, Callback_GetIpByName); 41 | // todo SET TIMEOUT 42 | for (int i = 0; i < 1000; i++) 43 | { 44 | arduinoProcessMessages(50); 45 | if (0 == dns_Code) 46 | goto ready; 47 | } 48 | DEBUG_DNS("[ERROR] DNS TIMEOUT"); 49 | // todo MUTEX_UNLOCK 50 | return false; 51 | ready: 52 | DEBUG_DNS("[DNS] READY"); 53 | IP = dns_IP; 54 | // todo MUTEX_UNLOCK 55 | return true; 56 | } 57 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/gprsDNS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DNSClient 3 | * 4 | * Created on: 03.03.2019 5 | * Author: Georgi Angelov 6 | */ 7 | 8 | #ifndef DNSClient_h 9 | #define DNSClient_h 10 | 11 | #include 12 | #include "IPAddress.h" 13 | 14 | #define DEBUG_DNS(F, ...) 15 | //DBG("[DNS] " F "\n", ##__VA_ARGS__) 16 | 17 | class DNSClient 18 | { 19 | public: 20 | bool getHostByName(const char *host, IPAddress &ip, unsigned char id = 0); 21 | }; 22 | 23 | #endif //DNSClient_h 24 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/gprsUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Udp.cpp: Library to send/receive UDP packets. 3 | * 4 | */ 5 | 6 | #ifndef _GPRS_UDP_H_ 7 | #define _GPRS_UDP_H_ 8 | 9 | #include "Udp.h" 10 | #include "gprsDNS.h" 11 | 12 | #define DEBUG_UDP(F, ...) DBG("[UDP] " F "\n", ##__VA_ARGS__) 13 | 14 | #define UDP_BUFFER_SIZE (1460) 15 | 16 | class gprsUDP : public UDP 17 | { 18 | private: 19 | int socket; 20 | IPAddress multicast_ip; 21 | IPAddress remote_ip; 22 | uint16_t server_port; 23 | uint16_t remote_port; 24 | char *tx_buffer; 25 | size_t tx_buffer_len; 26 | cbuf *rx_buffer; 27 | int id; 28 | 29 | public: 30 | gprsUDP(); 31 | gprsUDP(int context); 32 | ~gprsUDP(); 33 | uint8_t begin(IPAddress a, uint16_t p); 34 | uint8_t begin(uint16_t p); 35 | void stop(); 36 | int beginPacket(); 37 | int beginPacket(IPAddress ip, uint16_t port); 38 | int beginPacket(const char *host, uint16_t port); 39 | int endPacket(); 40 | size_t write(uint8_t); 41 | size_t write(const uint8_t *buffer, size_t size); 42 | int parsePacket(); 43 | int available(); 44 | int read(); 45 | int read(unsigned char *buffer, size_t len); 46 | int read(char *buffer, size_t len); 47 | int peek(); 48 | void flush(); 49 | IPAddress remoteIP(); 50 | uint16_t remotePort(); 51 | }; 52 | 53 | #endif /* _GPRS_UDP_H_ */ 54 | -------------------------------------------------------------------------------- /libraries/GSM/library.properties: -------------------------------------------------------------------------------- 1 | name=GSM 2 | version=1.0.0 3 | author=Georgi Angelov 4 | maintainer=Georgi Angelov 5 | sentence=GSM. 6 | paragraph= 7 | category=Communication 8 | url=https://github.com/Wiz-IO 9 | architectures=m66 10 | -------------------------------------------------------------------------------- /libraries/GSM/src/GSM.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the MKR GSM library. 3 | Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _GSM_H_INCLUDED 21 | #define _GSM_H_INCLUDED 22 | 23 | #include 24 | 25 | enum GSM3_NetworkStatus_t { ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED, GSM_OFF}; 26 | 27 | class GSM { 28 | 29 | public: 30 | /** Constructor 31 | @param debug Determines debug mode 32 | */ 33 | GSM(); 34 | 35 | /** Start the GSM/GPRS modem, attaching to the GSM network 36 | @param pin SIM PIN number (4 digits in a string, example: "1234"). If 37 | NULL the SIM has no configured PIN. 38 | @param restart Restart the modem. Default is TRUE. The modem receives 39 | a signal through the Ctrl/D7 pin. If it is shut down, it will 40 | start-up. If it is running, it will restart. Takes up to 10 41 | seconds 42 | @param synchronous If TRUE the call only returns after the Start is complete 43 | or fails. If FALSE the call will return inmediately. You have 44 | to call repeatedly ready() until you get a result. Default is TRUE. 45 | @return If synchronous, GSM3_NetworkStatus_t. If asynchronous, returns 0. 46 | */ 47 | GSM3_NetworkStatus_t begin(const char* pin = 0, bool restart = false, bool synchronous = true); 48 | 49 | /** Check network access status 50 | @return 1 if Alive, 0 if down 51 | */ 52 | int isAccessAlive(); 53 | 54 | /** Get last command status 55 | @return returns 0 if last command is still executing, 1 success, >1 error 56 | */ 57 | int ready(); 58 | 59 | void setTimeout(unsigned long timeout); 60 | 61 | GSM3_NetworkStatus_t status(); 62 | 63 | void getVersion(String &s); 64 | 65 | private: 66 | GSM3_NetworkStatus_t _state; 67 | int _readyState; 68 | const char* _pin; 69 | String _response; 70 | unsigned long _timeout; 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /libraries/GSM/src/Modem.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the MKR GSM library. 3 | Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | https://github.com/arduino-libraries/MKRGSM/tree/master/src 20 | 21 | MOD for Quectel by Georgi Angelov 22 | */ 23 | 24 | #ifndef _MODEM_INCLUDED_H 25 | #define _MODEM_INCLUDED_H 26 | 27 | #include 28 | 29 | class ModemClass 30 | { 31 | public: 32 | ModemClass(HardwareSerial &uart); 33 | 34 | void begin(bool restart = false); 35 | void end(); 36 | 37 | int noop(); // AT OK 38 | 39 | size_t write(uint8_t c); 40 | size_t write(const uint8_t *, size_t); 41 | 42 | void send(const char *command); 43 | void send(const String &command) { send(command.c_str()); } 44 | void sendf(const char *fmt, ...); 45 | 46 | int waitForResponse(unsigned long timeout = 500, String *responseDataStorage = NULL); 47 | int waitForPrompt(unsigned long timeout = 500); 48 | int ready(); 49 | void poll(); 50 | void setResponseDataStorage(String *responseDataStorage); 51 | 52 | private: 53 | HardwareSerial *_uart; 54 | unsigned long _lastResponseOrUrcMillis; 55 | 56 | enum 57 | { 58 | AT_COMMAND_IDLE, 59 | AT_RECEIVING_RESPONSE 60 | } _atCommandState; 61 | 62 | int _ready; 63 | String _buffer; 64 | String *_responseDataStorage; 65 | }; 66 | 67 | //extern ModemClass MODEM; 68 | 69 | #endif -------------------------------------------------------------------------------- /libraries/GSM/src/PIN.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the MKR GSM library. 3 | Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Modem.h" 21 | 22 | #include "PIN.h" 23 | 24 | GSMPIN::GSMPIN() : 25 | _pinUsed(false) 26 | { 27 | } 28 | 29 | void GSMPIN::begin() 30 | { 31 | MODEM.begin(); 32 | } 33 | 34 | int GSMPIN::isPIN() 35 | { 36 | String response; 37 | for (unsigned long start = millis(); (millis() - start) < 1000;) { 38 | MODEM.send("AT+CPIN?"); 39 | if (MODEM.waitForResponse(1000, &response) == 1) { 40 | if (response.startsWith("+CPIN: ")) { 41 | if (response.endsWith("READY")) { 42 | return 0; 43 | } else if (response.endsWith("SIM PIN")) { 44 | return 1; 45 | } else if (response.endsWith("SIM PUK")) { 46 | return -1; 47 | } else { 48 | return -2; 49 | } 50 | } 51 | } 52 | delay(100); 53 | } 54 | return -2; 55 | } 56 | 57 | int GSMPIN::checkPIN(String pin) 58 | { 59 | MODEM.sendf("AT+CPIN=\"%s\"", pin.c_str()); 60 | if (MODEM.waitForResponse(1000) == 1) { 61 | return 0; 62 | } 63 | return -1; 64 | } 65 | 66 | 67 | int GSMPIN::checkPUK(String puk, String pin) 68 | { 69 | MODEM.sendf("AT+CPIN=\"%s\",\"%s\"", puk.c_str(), pin.c_str()); 70 | if (MODEM.waitForResponse(1000) == 1) { 71 | return 0; 72 | } 73 | return -1; 74 | } 75 | 76 | void GSMPIN::changePIN(String old, String pin) 77 | { 78 | MODEM.sendf("AT+CPWD=\"SC\",\"%s\",\"%s\"", old.c_str(), pin.c_str()); 79 | if (MODEM.waitForResponse(1000) == 1) { 80 | Serial.println("Pin changed succesfully."); 81 | } else { 82 | Serial.println("ERROR"); 83 | } 84 | } 85 | 86 | void GSMPIN::switchPIN(String pin) 87 | { 88 | String response; 89 | MODEM.send("AT+CLCK=\"SC\",2"); 90 | if (MODEM.waitForResponse(180000, &response) != 1) { 91 | Serial.println("ERROR"); 92 | return; 93 | } 94 | if (response == "+CLCK: 0") { 95 | MODEM.sendf("AT+CLCK=\"SC\",1,\"%s\"", pin.c_str()); 96 | if (MODEM.waitForResponse(180000, &response) == 1) { 97 | Serial.println("OK. PIN lock on."); 98 | _pinUsed = true; 99 | } else { 100 | Serial.println("ERROR"); 101 | _pinUsed = false; 102 | } 103 | } else if (response == "+CLCK: 1") { 104 | MODEM.sendf("AT+CLCK=\"SC\",0,\"%s\"", pin.c_str()); 105 | if (MODEM.waitForResponse(180000, &response) == 1) { 106 | Serial.println("OK. PIN lock off."); 107 | _pinUsed = false; 108 | } else { 109 | Serial.println("ERROR"); 110 | _pinUsed = true; 111 | } 112 | } else { 113 | Serial.println("ERROR"); 114 | } 115 | } 116 | 117 | int GSMPIN::checkReg() 118 | { 119 | for (unsigned long start = millis(); (millis() - start) < 10000L;) { 120 | MODEM.send("AT+CREG?"); 121 | String response = ""; 122 | if (MODEM.waitForResponse(100, &response) == 1) { 123 | if (response.startsWith("+CREG: ")) { 124 | if (response.endsWith(",1")) { 125 | return 0; 126 | } else if (response.endsWith(",5")) { 127 | return 1; 128 | } 129 | } 130 | } 131 | 132 | delay(100); 133 | } 134 | return -1; 135 | } 136 | 137 | bool GSMPIN::getPINUsed() 138 | { 139 | return _pinUsed; 140 | } 141 | 142 | void GSMPIN::setPINUsed(bool used) 143 | { 144 | _pinUsed = used; 145 | } 146 | -------------------------------------------------------------------------------- /libraries/GSM/src/PIN.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the MKR GSM library. 3 | Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _GSM_PIN_H_INCLUDED 21 | #define _GSM_PIN_H_INCLUDED 22 | 23 | #include 24 | 25 | class GSMPIN { 26 | 27 | public: 28 | 29 | /** Constructor */ 30 | GSMPIN(); 31 | 32 | /** Check modem response and restart it 33 | */ 34 | void begin(); 35 | 36 | /** Check if PIN lock or PUK lock is activated 37 | @return 0 if PIN lock is off, 1 if PIN lock is on, -1 if PUK lock is on, -2 if error exists 38 | */ 39 | int isPIN(); 40 | 41 | /** Check if PIN code is correct and valid 42 | @param pin PIN code 43 | @return 0 if is correct, -1 if is incorrect 44 | */ 45 | int checkPIN(String pin); 46 | 47 | /** Check if PUK code is correct and establish new PIN code 48 | @param puk PUK code 49 | @param pin New PIN code 50 | @return 0 if successful, otherwise return -1 51 | */ 52 | int checkPUK(String puk, String pin); 53 | 54 | /** Change PIN code 55 | @param old Old PIN code 56 | @param pin New PIN code 57 | */ 58 | void changePIN(String old, String pin); 59 | 60 | /** Change PIN lock status 61 | @param pin PIN code 62 | */ 63 | void switchPIN(String pin); 64 | 65 | /** Check if modem was registered in GSM/GPRS network 66 | @return 0 if modem was registered, 1 if modem was registered in roaming, -1 if error exists 67 | */ 68 | int checkReg(); 69 | 70 | /** Return if PIN lock is used 71 | @return true if PIN lock is used, otherwise, return false 72 | */ 73 | bool getPINUsed(); 74 | 75 | /** Set PIN lock status 76 | @param used New PIN lock status 77 | */ 78 | void setPINUsed(bool used); 79 | 80 | private: 81 | bool _pinUsed; 82 | }; 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /libraries/GSM/src/SMS.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the MKR GSM library. 3 | Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _GSM_SMS_H_INCLUDED 21 | #define _GSM_SMS_H_INCLUDED 22 | 23 | #include 24 | 25 | typedef enum{ 26 | SMS_PDU, 27 | SMS_TEXT 28 | } sms_text_e; 29 | 30 | class SMS : public Stream { 31 | 32 | public: 33 | /** Constructor 34 | @param synch Determines sync mode 35 | */ 36 | SMS(bool synch = true); 37 | 38 | /** Write a character in SMS message 39 | @param c Character 40 | @return size 41 | */ 42 | size_t write(uint8_t c); 43 | 44 | /** Begin a SMS to send it 45 | @param to Destination 46 | @return error command if it exists 47 | */ 48 | int beginSMS(const char* to); 49 | 50 | /** Get last command status 51 | @return returns 0 if last command is still executing, 1 success, >1 error 52 | */ 53 | int ready(); 54 | 55 | /** End SMS 56 | @return error command if it exists 57 | */ 58 | int endSMS(); 59 | 60 | /** Check if SMS available and prepare it to be read 61 | @return number of bytes in a received SMS 62 | */ 63 | int available(); 64 | 65 | /** Read sender number phone 66 | @param number Buffer for save number phone 67 | @param nlength Buffer length 68 | @return 1 success, >1 error 69 | */ 70 | int remoteNumber(char* number, int nlength); 71 | 72 | /** Read one char for SMS buffer (advance circular buffer) 73 | @return byte 74 | */ 75 | int read(); 76 | 77 | /** Read a byte but do not advance the buffer header (circular buffer) 78 | @return byte 79 | */ 80 | int peek(); 81 | 82 | /** Delete the SMS from Modem memory and proccess answer 83 | */ 84 | void flush(); 85 | 86 | int formatText(bool f); 87 | int characterSet(const char *cs); 88 | 89 | private: 90 | bool _synch; 91 | int _state; 92 | String _incomingBuffer; 93 | int _smsDataIndex; 94 | int _smsDataEndIndex; 95 | bool _smsTxActive; 96 | }; 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /libraries/SPI/library.properties: -------------------------------------------------------------------------------- 1 | name=SPI 2 | version=1.0 3 | author=Georgi Angelov 4 | maintainer=Georgi Angelov 5 | sentence=Allows SPI half-duplex communication to slave devices 6 | paragraph= 7 | category=Signal Input/Output 8 | url=http://www.arduino.cc/en/Reference/SPI 9 | architectures=m66 10 | -------------------------------------------------------------------------------- /libraries/SPI/src/LICENSE: -------------------------------------------------------------------------------- 1 | This software is Copyright (C) 2008 Mike McCauley. Use is subject to license 2 | conditions. The main licensing options available are GPL V2 or Commercial: 3 | 4 | Open Source Licensing GPL V2 5 | 6 | This is the appropriate option if you want to share the source code of your 7 | application with everyone you distribute it to, and you also want to give them 8 | the right to share who uses it. If you wish to use this software under Open 9 | Source Licensing, you must contribute all your source code to the open source 10 | community in accordance with the GPL Version 2 when your application is 11 | distributed. See http://www.gnu.org/copyleft/gpl.html 12 | 13 | Commercial Licensing 14 | 15 | This is the appropriate option if you are creating proprietary applications 16 | and you are not prepared to distribute and share the source code of your 17 | application. Contact info@open.com.au for details. 18 | -------------------------------------------------------------------------------- /libraries/SPI/src/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.15.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #ifndef __SPI_H__ 7 | #define __SPI_H__ 8 | 9 | #include 10 | 11 | /* 12 | 13 | QUECTEL OpenCPU 14 | 15 | typedef enum 16 | { 17 | HAL_SPI_MASTER_LSB_FIRST = 0x0, 18 | HAL_SPI_MASTER_MSB_FIRST = 0x1, 19 | } hal_spi_master_bit_order_t; 20 | 21 | spi_config.bit_order = HAL_SPI_MASTER_MSB_FIRST = 0x1; 22 | 23 | */ 24 | 25 | typedef enum 26 | { 27 | SPI_MODE0 = 0, 28 | SPI_MODE1, 29 | SPI_MODE2, 30 | SPI_MODE3, 31 | } SPIDataMode; 32 | 33 | class SPISettings 34 | { 35 | public: 36 | SPISettings(uint32_t clockFrequency, BitOrder bitOrder, SPIDataMode dataMode); 37 | SPISettings(); 38 | 39 | private: 40 | uint32_t clock; 41 | BitOrder order; 42 | SPIDataMode mode; 43 | friend class SPIClass; 44 | }; 45 | 46 | class SPIClass 47 | { 48 | public: 49 | SPIClass(); 50 | SPIClass(uint32_t chnnl); 51 | SPIClass(uint32_t chnnl, int miso, int mosi, int clk, int cs); 52 | void begin(); 53 | void end(); 54 | 55 | void setBitOrder(BitOrder order); 56 | void setDataMode(uint8_t mode); 57 | void setFrequency(uint32_t frequency); 58 | 59 | void beginTransaction(SPISettings settings); 60 | void endTransaction(void); 61 | uint8_t transfer(uint8_t data); 62 | uint16_t transfer16(uint16_t _data); 63 | int transfer(uint8_t *tx, uint32_t wLen); 64 | int transfer(uint8_t *tx, uint32_t wLen, uint8_t *rx, uint32_t rLen); 65 | void cs(int level); 66 | 67 | void setClockDivider(uint8_t){}; 68 | void setClockDivider(uint8_t, uint8_t) {} 69 | void attachInterrupt(){}; 70 | void detachInterrupt(){}; 71 | 72 | private: 73 | uint32_t _port; 74 | uint32_t _clock; 75 | 76 | bool _order; 77 | bool _cpol; 78 | bool _cpha; 79 | bool _type; 80 | 81 | Enum_PinName _miso; 82 | Enum_PinName _mosi; 83 | Enum_PinName _clk; 84 | Enum_PinName _cs; 85 | void set_hard_pins(); 86 | }; 87 | 88 | extern SPIClass SPI; 89 | 90 | #endif -------------------------------------------------------------------------------- /libraries/Timer/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For LTimer 3 | ####################################### 4 | 5 | ####################################### 6 | # Library (KEYWORD1) 7 | ####################################### 8 | LTimer KEYWORD1 9 | 10 | ####################################### 11 | # Datatypes (KEYWORD1) 12 | ####################################### 13 | LTimerMode KEYWORD1 14 | LTimerStatus KEYWORD1 15 | LTimerID KEYWORD1 16 | 17 | ####################################### 18 | # Methods and Functions (KEYWORD2) 19 | ####################################### 20 | 21 | stop KEYWORD2 22 | begin KEYWORD2 23 | start KEYWORD2 24 | end KEYWORD2 25 | 26 | ####################################### 27 | # Constants (LITERAL1) 28 | ####################################### 29 | -------------------------------------------------------------------------------- /libraries/Timer/library.properties: -------------------------------------------------------------------------------- 1 | name=Timer 2 | version=1.0 3 | author=Georgi Angelov 4 | maintainer=Georgi Angelov 5 | sentence=Timer module for M66 6 | paragraph= 7 | category=Timing 8 | url=https://github.com/Wiz-IO 9 | architectures=m66 10 | -------------------------------------------------------------------------------- /libraries/Timer/src/GPTimer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "GPTimer.h" 3 | 4 | #define DEBUG_TMR 5 | //DBG 6 | 7 | GPTimer::GPTimer(TimerID id) 8 | { 9 | m_id = id; 10 | if (id < TIMER_FAST || id > TIMER_END) 11 | m_id = 0; 12 | } 13 | 14 | bool GPTimer::start(uint32_t interval, bool mode, Callback_Timer_OnTimer callback, void *user) 15 | { 16 | int res = -1; 17 | if (callback && m_id) 18 | { 19 | if (TIMER_FAST == m_id) 20 | { 21 | res = Ql_Timer_RegisterFast(m_id, callback, user); 22 | } 23 | else 24 | { 25 | res = Ql_Timer_Register(m_id, callback, user); 26 | } 27 | DEBUG_TMR("Ql_Timer_Register( %X ) = %d\n", (int)m_id, res); 28 | if (QL_RET_OK == res) 29 | { 30 | res = Ql_Timer_Start(m_id, interval, mode == TIMER_REPEAT_MODE); 31 | DEBUG_TMR("Ql_Timer_Start( %X ) = %d\n", (int)m_id, res); 32 | } 33 | } 34 | return res == QL_RET_OK; 35 | } 36 | 37 | bool GPTimer::stop() 38 | { 39 | int res = -1; 40 | if (m_id) 41 | res = Ql_Timer_Stop(m_id); 42 | return res == QL_RET_OK; 43 | } 44 | -------------------------------------------------------------------------------- /libraries/Timer/src/GPTimer.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIMER_H__ 2 | #define __TIMER_H__ 3 | 4 | #include 5 | 6 | typedef enum 7 | { 8 | TIMER_FAST = 0x100, /* Fast Timer*/ 9 | /* Normal Timers */ 10 | TIMER_1, 11 | TIMER_2, 12 | TIMER_3, 13 | TIMER_4, 14 | TIMER_5, 15 | TIMER_6, 16 | TIMER_7, 17 | TIMER_8, 18 | TIMER_9, 19 | TIMER_END 20 | } TimerID; 21 | 22 | typedef enum 23 | { 24 | TIMER_ONESHOT_MODE = 0, 25 | TIMER_REPEAT_MODE 26 | } TimerMode; 27 | 28 | class GPTimer 29 | { 30 | public: 31 | GPTimer(TimerID id); 32 | bool begin() { return m_id; } 33 | bool end() { return 1; } 34 | bool start(uint32_t interval, bool mode, Callback_Timer_OnTimer callbackFunc, void *user = NULL); 35 | bool stop(); 36 | //TODO RTC ALARM 37 | private: 38 | uint32_t m_id; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libraries/Wire/library.properties: -------------------------------------------------------------------------------- 1 | name=Wire 2 | version=1.0 3 | author=Georgi Angelov 4 | maintainer=Georgi Angelov 5 | sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. 6 | paragraph= 7 | category=Signal Input/Output 8 | url=https://github.com/Wiz-IO 9 | architectures=m66 -------------------------------------------------------------------------------- /libraries/Wire/src/Wire.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TWI/I2C library for Arduino Zero 3 | */ 4 | 5 | #include 6 | #include "Wire.h" 7 | 8 | #define DEBUG_I2C 9 | //DBG 10 | 11 | #define IIC_TYPE (i2c_port == 1) 12 | 13 | #define SLC0 PINNAME_CTS 14 | #define SDA0 PINNAME_RTS 15 | 16 | TwoWire::TwoWire(uint8_t port, uint8_t address, u32 brg) 17 | { 18 | if (brg == 400) // work around 19 | brg += 1; 20 | i2c_port = port; 21 | slaveAddress = address; 22 | i2c_speed = brg; 23 | transmissionBegun = false; 24 | } 25 | 26 | void TwoWire::begin(void) 27 | { 28 | int res; 29 | if (1 == i2c_port) 30 | { 31 | res = Ql_IIC_Init(i2c_port, PINNAME_RI, PINNAME_DCD, IIC_TYPE); 32 | DEBUG_I2C("[I2C] Ql_IIC_Init( %d ) HW: %d\n", i2c_port, res); 33 | } 34 | else 35 | { 36 | res = Ql_IIC_Init(i2c_port, SLC0, SDA0, IIC_TYPE); 37 | DEBUG_I2C("[I2C] Ql_IIC_Init( %d ) SW: %d\n", i2c_port, res); 38 | } 39 | res = Ql_IIC_Config(i2c_port, 1, slaveAddress, i2c_speed); // set default speed 40 | DEBUG_I2C("[I2C] Ql_IIC_Config( %d ): %d\n", i2c_port, res); 41 | } 42 | 43 | void TwoWire::setClock(uint32_t brg) 44 | { 45 | if (brg == 400) // work around 46 | brg += 1; 47 | i2c_speed = brg; 48 | int res = Ql_IIC_Config(i2c_port, 1, slaveAddress, brg); 49 | DEBUG_I2C("[I2C] setClock( %d ) %d, %d\n", i2c_port, res, brg); 50 | return; 51 | } 52 | 53 | void TwoWire::end() 54 | { 55 | Ql_IIC_Uninit(i2c_port); 56 | } 57 | 58 | uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit) 59 | { 60 | int res = -1; 61 | if (quantity == 0) 62 | return 0; 63 | if (!stopBit) 64 | return 0; 65 | rx.clear(); 66 | //TODO: if IICtype = 1 ,1 < len < 8 . because our IIC contronller at most support 8 bytes 67 | res = Ql_IIC_Read(i2c_port, address, (uint8_t *)(rx._aucBuffer), (uint32_t)quantity); 68 | if (res < 0) 69 | { 70 | DEBUG_I2C("[I2C] R( %02X ) %d\n", (int)address, res); 71 | quantity = 0; 72 | } 73 | rx._iHead = quantity; 74 | return rx.available(); 75 | } 76 | 77 | uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity) 78 | { 79 | return requestFrom(address, quantity, true); 80 | } 81 | 82 | void TwoWire::beginTransmission(uint8_t address) 83 | { 84 | slaveAddress = address; 85 | tx.clear(); 86 | transmissionBegun = true; 87 | } 88 | 89 | uint8_t TwoWire::endTransmission(bool stopBit) 90 | { 91 | if (!stopBit) 92 | return 1; 93 | u32 count, i, size; 94 | u8 buf[8]; 95 | transmissionBegun = false; 96 | // if IICtype = 1 ,1 < len < 8 . because our IIC contronller at most support 8 bytes for one time transaction 97 | while (tx.available() > 0) 98 | { 99 | size = tx.available(); 100 | for (i = 0, count = 0; i < size; i++) 101 | { 102 | if (i > 7) 103 | break; 104 | buf[i] = tx.read_char(); 105 | count++; 106 | } 107 | int res = Ql_IIC_Write(i2c_port, slaveAddress, buf, count); 108 | if (res < 0) 109 | { 110 | DEBUG_I2C("[I2C] ERROR Write %d\n", res); 111 | return 1; 112 | } 113 | } 114 | return 0; 115 | } 116 | 117 | uint8_t TwoWire::endTransmission() 118 | { 119 | return endTransmission(true); 120 | } 121 | 122 | size_t TwoWire::write(uint8_t ucData) 123 | { 124 | if (!transmissionBegun || tx.isFull()) 125 | return 0; 126 | tx.store_char(ucData); 127 | return 1; 128 | } 129 | 130 | size_t TwoWire::write(const uint8_t *data, size_t quantity) 131 | { 132 | for (size_t i = 0; i < quantity; ++i) 133 | { 134 | if (!write(data[i])) 135 | return i; 136 | } 137 | return quantity; 138 | } 139 | 140 | int TwoWire::available(void) 141 | { 142 | return rx.available(); 143 | } 144 | 145 | int TwoWire::read(void) 146 | { 147 | return rx.read_char(); 148 | } 149 | 150 | int TwoWire::peek(void) 151 | { 152 | return rx.peek(); 153 | } 154 | 155 | void TwoWire::flush(void) 156 | { 157 | // Do nothing, use endTransmission(..) to force data transfer. 158 | } 159 | -------------------------------------------------------------------------------- /libraries/Wire/src/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TWI/I2C library for Arduino Zero 3 | * Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef __WIRE_H__ 21 | #define __WIRE_H__ 22 | 23 | #include "interface.h" 24 | #include "Stream.h" 25 | #include "variant.h" 26 | #include "RingBuffer.h" 27 | 28 | #define BUFFER_LENGTH SERIAL_BUFFER_SIZE 29 | 30 | class TwoWire : public Stream 31 | { 32 | public: 33 | TwoWire(uint8_t i2c_port, uint8_t slaveAddress, u32 i2c_speed = 500); 34 | 35 | void begin(); 36 | void end(); 37 | void setClock(uint32_t); 38 | void beginTransmission(uint8_t); 39 | uint8_t endTransmission(bool stopBit); 40 | uint8_t endTransmission(void); 41 | uint8_t requestFrom(uint8_t address, size_t quantity, bool stopBit); 42 | uint8_t requestFrom(uint8_t address, size_t quantity); 43 | size_t write(uint8_t data); 44 | size_t write(const uint8_t *data, size_t quantity); 45 | virtual int available(void); 46 | virtual int read(void); 47 | virtual int peek(void); 48 | virtual void flush(void); 49 | using Print::write; 50 | 51 | void onService(void){}; 52 | void onReceive(void (*)(int)){}; 53 | void onRequest(void (*)(void)){}; 54 | 55 | private: 56 | uint8_t i2c_port; 57 | u32 i2c_speed; 58 | 59 | bool transmissionBegun; 60 | uint8_t slaveAddress; 61 | 62 | // RX Buffer 63 | RingBuffer rx; 64 | 65 | // TX buffer 66 | RingBuffer tx; 67 | 68 | void (*onRequestCallback)(void){}; 69 | void (*onReceiveCallback)(int){}; 70 | 71 | }; 72 | 73 | extern TwoWire Wire; 74 | 75 | #endif -------------------------------------------------------------------------------- /platform.txt: -------------------------------------------------------------------------------- 1 | # WizIO 2019 Georgi Angelov 2 | # https://github.com/Wiz-IO/Arduino-Quectel-M66/blob/master/README.md 3 | # the.wizarda@gmail.com 4 | # 5 | # Arduino Core and platform. 6 | # For more info: 7 | # https:\\github.com\arduino\Arduino\wiki\Arduino-IDE-1.5---3rd-party-Hardware-specification 8 | 9 | name=WizIO 10 | version=2.0.0 11 | 12 | compiler.path={build.compiler_path} 13 | compiler.c.cmd=arm-none-eabi-gcc 14 | compiler.cpp.cmd=arm-none-eabi-g++ 15 | compiler.c.elf.cmd=arm-none-eabi-g++ 16 | compiler.ar.cmd=arm-none-eabi-ar 17 | compiler.objcopy.cmd=arm-none-eabi-objcopy 18 | compiler.size.cmd=arm-none-eabi-size 19 | 20 | compiler.include="-I{build.core.path}\" "-I{build.core.path}\include\" "-I{build.core.path}\ril\inc\" "-I{build.core.path}\fota\inc\" "-I{build.core.path}\api\" 21 | 22 | compiler.S.flags=-x assembler-with-cpp 23 | 24 | compiler.gcc.c.flags=-Os -Wall -g -fno-strict-aliasing -ffunction-sections -fdata-sections -Wno-pointer-sign -Wstrict-prototypes -Wp,-w "-DARDUINO=200" 25 | 26 | compiler.c.flags=-std=c11 27 | 28 | compiler.cpp.flags=-std=c++11 -fno-exceptions -fno-non-call-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics 29 | 30 | compiler.c.elf.flags=-nostartfiles -fno-use-cxa-atexit -Xlinker --gc-sections -Wl,--gc-sections 31 | 32 | compiler.ar.flags=rcs 33 | 34 | compiler.objcopy.remove.flags=--strip-debug 35 | 36 | compiler.objcopy.bin.flags=-O binary 37 | 38 | ###### Compile S files 39 | recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {build.mcu} {compiler.S.flags} {compiler.c.flags} {compiler.include} {includes} "{source_file}" -o "{object_file}" 40 | 41 | ###### C Compile files 42 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {build.mcu} {compiler.c.flags} {build.extra_flags} {compiler.gcc.c.flags} {compiler.include} {includes} "{source_file}" -c -o "{object_file}" 43 | 44 | ###### CPP Compile files 45 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {build.mcu} {compiler.cpp.flags} {build.extra_flags} {compiler.gcc.c.flags} {compiler.include} {includes} "{source_file}" -c -o "{object_file}" 46 | 47 | ###### AR Create archives 48 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}" 49 | 50 | ###### ELF Combine gc-sections, archives, and objects 51 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.mcu} {compiler.c.elf.flags} "-T{build.core.path}/cpp_m66.ld" -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--start-group "{build.path}/{archive_file}" {object_files} "{build.core.path}/lib_app_start_m66.a" "{build.core.path}/lib_{build.firmware}.a" -Wl,--end-group -v 52 | 53 | ###### Create BIN 54 | recipe.objcopy.bin.1.pattern="{compiler.path}{compiler.objcopy.cmd}" -g -R .comment "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.dat" 55 | recipe.objcopy.bin.2.pattern="{compiler.path}{compiler.objcopy.cmd}" -O binary "{build.path}/{build.project_name}.dat" "{build.path}/ARDUINO.bin" 56 | 57 | ###### Add header to BIN 58 | recipe.objcopy.hex.1.pattern="{runtime.tools.m66_tools.path}/GFH_Generator.exe" "{build.path}/ARDUINO.bin" 59 | recipe.objcopy.hex.2.pattern=cmd /C copy /y "{runtime.tools.m66_tools.path}\app_image_bin.cfg" "{build.path}\" 60 | 61 | ###### Compute size 62 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" 63 | recipe.size.regex=^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).* 64 | recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).* 65 | 66 | ########################################## 67 | 68 | tools.m66.cmd= 69 | tools.m66.cmd.windows= 70 | tools.m66.path= 71 | tools.m66.upload.params.verbose=-vvvvvv 72 | tools.m66.upload.params.quiet=-q 73 | tools.m66.upload.pattern=cmd /C echo [ UPLOAD ] USE QFlash Tool 74 | -------------------------------------------------------------------------------- /programmers.txt: -------------------------------------------------------------------------------- 1 | # WizIO 2018 Georgi Angelov 2 | # https://github.com/Wiz-IO/Arduino-MT2625-BC66/blob/master/README.md 3 | # the.wizarda@gmail.com 4 | 5 | -------------------------------------------------------------------------------- /tools/M66FAR01A12BT.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/tools/M66FAR01A12BT.zip -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | # Tools 2 | -------------------------------------------------------------------------------- /tools/m66_core.2.0.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/tools/m66_core.2.0.0.zip -------------------------------------------------------------------------------- /tools/m66_tools.1.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wiz-IO/Arduino-Quectel-M66/efeadb3872173f4318c1daa0b2022fedf2b42030/tools/m66_tools.1.0.zip -------------------------------------------------------------------------------- /tools/package_wizio.m66_index.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "WizIO", 5 | "maintainer": "WizIO", 6 | "websiteURL": "https://github.com/Wiz-IO", 7 | "email": "the_wizarda@gmail.com", 8 | "platforms": [ 9 | { 10 | "name": "Quectel M66", 11 | "architecture": "m66", 12 | "version": "2.0.0", 13 | "category": "Contributed", 14 | "url": "https://github.com/Wiz-IO/Arduino-Quectel-M66/raw/master/tools/m66_core.2.0.0.zip", 15 | "archiveFileName": "m66_core.2.0.0.zip", 16 | "checksum": "", 17 | "size": "293394", 18 | "help": { "online": "https://github.com/Wiz-IO/Arduino-Quectel-M66" }, 19 | "boards": [ 20 | { "name": "M66" } 21 | ], 22 | "toolsDependencies": [ 23 | { 24 | "packager": "WizIO", 25 | "name": "m66_gcc", 26 | "version": "1.70201.0" 27 | }, 28 | { 29 | "packager": "WizIO", 30 | "name": "m66_tools", 31 | "version": "1.0" 32 | } 33 | ] 34 | } 35 | ], 36 | "tools": [ 37 | { 38 | "name": "m66_gcc", 39 | "version": "1.70201.0", 40 | "systems": [ 41 | { 42 | "host": "i686-mingw32", 43 | "url": "http://wizio.eu/arduino/bc66/gcc.1.70201.0.zip", 44 | "archiveFileName": "gcc.1.70201.0.zip", 45 | "size": "106761211", 46 | "checksum": "" 47 | } 48 | ] 49 | }, 50 | { 51 | "name": "m66_tools", 52 | "version": "1.0", 53 | "systems": [ 54 | { 55 | "host": "i686-mingw32", 56 | "url": "https://github.com/Wiz-IO/Arduino-Quectel-M66/raw/master/tools/m66_tools.1.0.zip", 57 | "archiveFileName": "m66_tools.1.0.zip", 58 | "size": "15665840", 59 | "checksum": "" 60 | } 61 | ] 62 | } 63 | ] 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /variants/m66/variant.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.15.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #include 7 | 8 | HardwareSerial Serial(UART_PORT1); 9 | HardwareSerial Serial1(UART_PORT2); 10 | HardwareSerial Serial2(UART_PORT3); 11 | 12 | HardwareSerial Virtual(VIRTUAL_PORT1); 13 | HardwareSerial Virtual1(VIRTUAL_PORT2); -------------------------------------------------------------------------------- /variants/m66/variant.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.15.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #ifndef __VARIANT_H__ 7 | #define __VARIANT_H__ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | #define LED 0 /* PINNAME_NETLIGHT */ 17 | #define LED_BUILTIN 0 /* PINNAME_NETLIGHT */ 18 | #define PWM0 PINNAME_NETLIGHT /* ONLY ONE PIN */ 19 | #define ADC0 PINNAME_END /* ONLY ONE PIN */ 20 | 21 | typedef struct 22 | { 23 | uint8_t arduino; 24 | uint8_t device; 25 | void *eint; 26 | } PinDescription; 27 | extern PinDescription pinsMap[13]; 28 | 29 | PinDescription *getArduinoPin(uint8_t arduinoPin); 30 | PinDescription *getDevicePin(uint8_t devicePin); 31 | 32 | typedef void (*eint_callback_t)(uint32_t level); 33 | void eintMode(uint8_t pin, Enum_EintType type, eint_callback_t cb, uint32_t hwDebounce, uint32_t swDebounce, bool automask); 34 | 35 | void analogReference(uint8_t mode) __attribute__((weak)); 36 | void analogOpen(uint8_t pin, /* val, src, div */...); 37 | void analogClose(uint8_t pin); 38 | int analogRead(uint8_t pin); 39 | void analogWrite(uint8_t pin, int val); 40 | 41 | #ifdef __cplusplus 42 | } 43 | 44 | #include 45 | extern HardwareSerial Serial; 46 | extern HardwareSerial Serial1; 47 | extern HardwareSerial Serial2; 48 | extern HardwareSerial Virtual; 49 | extern HardwareSerial Virtual1; 50 | 51 | #include 52 | extern DeviceClass Dev; 53 | 54 | #endif //__cplusplus 55 | 56 | #endif /* __VARIANT_H__ */ 57 | -------------------------------------------------------------------------------- /variants/m66/variant_pins.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on: 01.15.2019 3 | * Author: Georgi Angelov 4 | */ 5 | 6 | #include "variant.h" 7 | 8 | PinDescription pinsMap[13] = { 9 | {0, PINNAME_NETLIGHT, NULL}, 10 | {1, PINNAME_DTR, NULL}, 11 | {2, PINNAME_RI, NULL}, 12 | {3, PINNAME_DCD, NULL}, 13 | {4, PINNAME_CTS, NULL}, 14 | {5, PINNAME_RTS, NULL}, 15 | {6, PINNAME_RXD_AUX, NULL}, 16 | {7, PINNAME_TXD_AUX, NULL}, 17 | {8, PINNAME_PCM_CLK, NULL}, 18 | {9, PINNAME_PCM_SYNC, NULL}, 19 | {10, PINNAME_PCM_IN, NULL}, 20 | {11, PINNAME_PCM_OUT, NULL}, 21 | {12, PINNAME_RFTXMON, NULL}, 22 | }; 23 | --------------------------------------------------------------------------------