├── .gitignore ├── .gitmodules ├── LICENSE.md ├── README.md ├── boards.txt ├── cores └── arduino │ ├── Arduino.h │ ├── Client.h │ ├── HardwareI2C.h │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── RingBuffer.h │ ├── Server.h │ ├── Stream.cpp │ ├── Stream.h │ ├── Tone.cpp │ ├── UARTClass.cpp │ ├── UARTClass.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WInterrupts.c │ ├── WInterrupts.h │ ├── WMath.cpp │ ├── WMath.h │ ├── WString.cpp │ ├── WString.h │ ├── abi.cpp │ ├── avr │ ├── dtostrf.h │ └── pgmspace.h │ ├── binary.h │ ├── hal │ ├── Maix_SPI.cpp │ └── include │ │ └── SPI_hal.h │ ├── hooks.c │ ├── itoa.h │ ├── main.cpp │ ├── st7789.c │ ├── st7789.h │ ├── stdlib_noniso.c │ ├── stdlib_noniso.h │ ├── wiring.c │ ├── wiring.h │ ├── wiring_analog.c │ ├── wiring_analog.h │ ├── wiring_constants.h │ ├── wiring_digital.c │ ├── wiring_digital.h │ ├── wiring_private.h │ ├── wiring_pulse.c │ ├── wiring_pulse.h │ ├── wiring_shift.c │ └── wiring_shift.h ├── keywords.txt ├── libraries ├── AXP173 │ ├── AXP173.cpp │ └── AXP173.h ├── AXP192 │ ├── AXP192.cpp │ └── AXP192.h ├── Camera │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Camera.cpp │ │ └── Camera.h ├── MSA300 │ ├── examples │ │ └── msa_basic │ │ │ └── msa_basic.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── MSA300.cpp │ │ └── MSA300.h ├── Maix_KPU │ ├── examples │ │ └── mobilenet_v1 │ │ │ ├── MBNet_1000.cpp │ │ │ ├── MBNet_1000.h │ │ │ ├── mobilenet_v1.ino │ │ │ ├── names.cpp │ │ │ └── names.h │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Maix_KPU.cpp │ │ └── Maix_KPU.h ├── Maix_Speech_Recognition │ ├── examples │ │ ├── get_voice_model │ │ │ └── get_voice_model.ino │ │ ├── voice_control_led_en │ │ │ ├── voice_control_led_en.ino │ │ │ └── voice_model.h │ │ └── voice_control_led_zh │ │ │ ├── voice_control_led_zh.ino │ │ │ └── voice_model.h │ ├── library.properties │ └── src │ │ ├── Maix_Speech_Recognition.cpp │ │ ├── Maix_Speech_Recognition.h │ │ └── util │ │ ├── ADC.h │ │ ├── DTW.c │ │ ├── DTW.h │ │ ├── FIR.c │ │ ├── FIR.h │ │ ├── MFCC.c │ │ ├── MFCC.h │ │ ├── MFCC_Arg.h │ │ ├── VAD.c │ │ ├── VAD.h │ │ ├── flash.c │ │ ├── flash.h │ │ └── g_def.h ├── NS2009 │ ├── examples │ │ └── drawline │ │ │ └── drawline.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── mean.c │ │ ├── mean.h │ │ ├── median.c │ │ ├── median.h │ │ ├── ns2009.c │ │ ├── ns2009.h │ │ ├── touchscreen.cpp │ │ ├── touchscreen.h │ │ ├── tscal.c │ │ ├── tscal.h │ │ ├── tsfilter.c │ │ └── tsfilter.h ├── SD │ ├── README.adoc │ ├── examples │ │ ├── CardInfo │ │ │ └── CardInfo.ino │ │ ├── Datalogger │ │ │ └── Datalogger.ino │ │ ├── DumpFile │ │ │ └── DumpFile.ino │ │ ├── Files │ │ │ └── Files.ino │ │ ├── ReadWrite │ │ │ └── ReadWrite.ino │ │ ├── SD_Test │ │ │ └── SD_Test.ino │ │ └── listfiles │ │ │ └── listfiles.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── File.cpp │ │ ├── README.txt │ │ ├── SD.cpp │ │ ├── SD.h │ │ └── utility │ │ ├── FatStructs.h │ │ ├── Sd2Card.cpp │ │ ├── Sd2Card.h │ │ ├── Sd2PinMap.h │ │ ├── SdFat.h │ │ ├── SdFatUtil.h │ │ ├── SdFatmainpage.h │ │ ├── SdFile.cpp │ │ ├── SdInfo.h │ │ └── SdVolume.cpp ├── SPI │ ├── examples │ │ └── basic │ │ │ └── basic.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ └── SPI.h ├── Sipeed_GC0328 │ ├── examples │ │ ├── sipeed_gc0328.ino │ │ └── sipeed_gc0328_binocular.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Sipeed_GC0328.cpp │ │ └── Sipeed_GC0328.h ├── Sipeed_OV2640 │ ├── examples │ │ └── selfie │ │ │ └── selfie.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Sipeed_OV2640.cpp │ │ ├── Sipeed_OV2640.h │ │ └── ov2640_regs.h ├── Sipeed_ST7789 │ ├── examples │ │ └── basic_display │ │ │ └── basic_display.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Sipeed_ST7789.cpp │ │ ├── Sipeed_ST7789.h │ │ ├── lcd.c │ │ └── lcd.h ├── Ticker │ ├── examples │ │ ├── Arguments │ │ │ └── Arguments.ino │ │ └── Blinker │ │ │ └── Blinker.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Ticker.cpp │ │ └── Ticker.h └── Wire │ ├── examples │ ├── i2c_rxtx │ │ └── i2c_rxtx.ino │ └── i2c_scaner │ │ └── i2c_scaner.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ ├── Wire.cpp │ └── Wire.h ├── package.json ├── platform.txt ├── programmers.txt └── variants ├── ioxgd4 └── pins_arduino.h ├── lamloei_aiot_daan └── pins_arduino.h ├── m5stack_m5stick_v └── pins_arduino.h ├── m5stack_m5unit_v └── pins_arduino.h ├── sipeed_maix_amigo └── pins_arduino.h ├── sipeed_maix_bit └── pins_arduino.h ├── sipeed_maix_bit_mic └── pins_arduino.h ├── sipeed_maix_cube └── pins_arduino.h ├── sipeed_maix_go └── pins_arduino.h ├── sipeed_maix_one_dock └── pins_arduino.h ├── sipeed_maix_one_w_dock └── pins_arduino.h └── sipeed_maixduino └── pins_arduino.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # vscode 35 | .vscode 36 | 37 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cores/arduino/kendryte-standalone-sdk"] 2 | path = cores/arduino/kendryte-standalone-sdk 3 | url = https://github.com/sipeed/kendryte-standalone-sdk 4 | [submodule "libraries/Adafruit-GFX-Library"] 5 | path = libraries/Adafruit-GFX-Library 6 | url = https://github.com/adafruit/Adafruit-GFX-Library 7 | [submodule "libraries/WiFiEsp"] 8 | path = libraries/WiFiEsp 9 | url = https://github.com/btx000/WiFiEsp 10 | [submodule "libraries/lv_arduino"] 11 | path = libraries/lv_arduino 12 | url = https://github.com/btx000/lv_arduino.git 13 | [submodule "libraries/lv_maixduino"] 14 | path = libraries/lv_maixduino 15 | url = https://github.com/littlevgl/lv_maixduino.git 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | License 3 | ====== 4 | 5 | All the source code in this repository is released under LGPL or Apache v2.0 license even more. 6 | 7 | 8 | All the sources created/modified by the repository owner are released under Apache v2.0 license and contains the following copyright notice: 9 | Copyright 2019 Sipeed Co.,Ltd. 10 | 11 | Most of the source files contains license and copyright notice, please check the individual files for more information. 12 | Also check the license information in individual components directories. 13 | 14 | ``` 15 | Copyright 2019 Sipeed Co.,Ltd. 16 | 17 | Licensed under the Apache License, Version 2.0 (the "License"); 18 | you may not use this file except in compliance with the License. 19 | You may obtain a copy of the License at 20 | 21 | http://www.apache.org/licenses/LICENSE-2.0 22 | 23 | Unless required by applicable law or agreed to in writing, software 24 | distributed under the License is distributed on an "AS IS" BASIS, 25 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | See the License for the specific language governing permissions and 27 | limitations under the License. 28 | ``` 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Maixduino 2 | ======== 3 | 4 | # Arduino Core for K210 based devices 5 | 6 | 7 | 8 | ## Supported devices 9 | 10 | ### Sipeed Maix series 11 | - [Amigo](https://dl.sipeed.com/MAIX/HDK/Sipeed-Amigo) 12 | - [Cube](https://dl.sipeed.com/MAIX/HDK/Sipeed-Maix-Cube) 13 | - [Go](https://dl.sipeed.com/MAIX/HDK/Sipeed-Maix-GO) 14 | - [Maixduino](https://dl.sipeed.com/MAIX/HDK/Sipeed-Maixduino) 15 | - [Dock](https://dl.sipeed.com/MAIX/HDK/Sipeed-Maix-Dock) 16 | - [BiT](https://dl.sipeed.com/MAIX/HDK/Sipeed-Maix-Bit) 17 | - [Nano](https://dl.sipeed.com/MAIX/HDK/Sipeed-Maix-Nano) 18 | 19 | ### M5Stack 20 | * [M5StickV](https://m5stack.com/products/stickv) 21 | * [M5UnitV](https://m5stack.com/collections/m5-unit/products/unitv-ai-camera) 22 | 23 | ### Various custom boards 24 | * [LAMLOEI AOIT DAAN](https://github.com/lamloei/AIoTDaaN/tree/master/hardware/20190505-R2/AIoTDaaN_R2/pdf) 25 | * [IOXGD4](https://github.com/ioxgd/IOXGD-hardware/tree/master/IOXGD4/pdf) 26 | 27 | ## Docs 28 | 29 | Docs: [wiki.sipeed.com](https://wiki.sipeed.com/soft/maixduino/zh/index.html) 30 | 31 | ## Install 32 | 33 | Refer install doc: [Install](https://maixduino.sipeed.com/en/get_started/install.html) 34 | 35 | ## Installing 36 | 37 | ### From Board Manager 38 | 39 | 1. [Download and install the Arduino IDE](https://www.arduino.cc/en/Main/Software) (at least version v1.9.8) 40 | 2. Start the Arduino IDE 41 | 3. Go into Preferences 42 | 4. Add ```https://dl.sipeed.com/MAIX/Maixduino/package_Maixduino_k210_index.json``` as an "Additional Board Manager URL" 43 | 5. Open the Boards Manager from the Tools -> Board menu and install "Maixduino(K210)" 44 | 6. Select your K210 board from the Tools -> Board menu 45 | 46 | ### From git 47 | 48 | 1. Follow steps from Board Manager section above 49 | 2. ```cd ```, where `````` is your Arduino Sketch folder: 50 | * OS X: ```~/Documents/Arduino``` 51 | * Linux: ```~/Arduino``` 52 | * Windows: ```~/Documents/Arduino``` 53 | 3. Create a folder named ```hardware```, if it does not exist, and change directories to it 54 | 4. Clone this repo: ```git clone https://github.com/Sipeed/Maixduino Maixduino/k210``` 55 | 5. Restart the Arduino IDE 56 | 57 | ### Firmware flashing 58 | The firmware of the K210 devices is updated with a Python-based [kflash](https://github.com/sipeed/kflash.py) cross-platform tool. 59 | Follow ```kflash``` github page on installation instruction. 60 | 61 | 62 | ###### Change board settings in Tools section on the top of Arduino IDE 63 | 64 | 1. Board: The same as your dev board 65 | 2. Burn Toolfirmware: leave default, for Maix Go Kit - ```open-ec``` 66 | 3. Burn Baudrate: Decrease it if download fails 67 | 4. Port: Serial port, e.g. ```/dev/ttyUSB0``` 68 | 5. Programmer: ```k-flash``` 69 | 70 | ## Credits 71 | 72 | This core is based on and compatible with the [Sipeed Maixduino Core](https://github.com/sipeed/Maixduino) 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /cores/arduino/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 | 20 | #ifndef Arduino_h 21 | #define Arduino_h 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // some libraries and sketches depend on this 30 | // AVR stuff, assuming Arduino.h or WProgram.h 31 | // automatically includes it... 32 | #include 33 | #include 34 | //#include 35 | 36 | #include "binary.h" 37 | #include "pins_arduino.h" 38 | 39 | #include "fpioa.h" 40 | #include "gpiohs.h" 41 | #include "gpio.h" 42 | #include "gpio_common.h" 43 | #include "plic.h" 44 | #include "uarths.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C"{ 48 | #endif // __cplusplus 49 | #include "wiring.h" 50 | #include "wiring_constants.h" 51 | 52 | #define SystemCoreClock F_CPU 53 | 54 | #define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) 55 | #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) 56 | #define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) 57 | 58 | void yield(void); 59 | 60 | /* sketch */ 61 | extern void setup( void ) ; 62 | extern void loop( void ) ; 63 | 64 | typedef void (*voidFuncPtr)( void ) ; 65 | 66 | /* Define attribute */ 67 | #define WEAK __attribute__ ((weak)) 68 | 69 | #ifdef __cplusplus 70 | } // extern "C" 71 | 72 | #include "WCharacter.h" 73 | #include "WString.h" 74 | #include "WMath.h" 75 | #include "HardwareSerial.h" 76 | #include "wiring_pulse.h" 77 | #include "Client.h" 78 | #include "HardwareI2C.h" 79 | #include "IPAddress.h" 80 | #include "Server.h" 81 | #include "Udp.h" 82 | 83 | // Tone function prototypes 84 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); 85 | void noTone(uint8_t _pin); 86 | 87 | #endif // __cplusplus 88 | 89 | #include "wiring_digital.h" 90 | #include "wiring_analog.h" 91 | #include "wiring_shift.h" 92 | #include "WInterrupts.h" 93 | 94 | #endif // Arduino_h 95 | -------------------------------------------------------------------------------- /cores/arduino/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 | #pragma once 21 | 22 | #include "Stream.h" 23 | #include "IPAddress.h" 24 | 25 | class Client : public Stream { 26 | 27 | public: 28 | virtual int connect(IPAddress ip, uint16_t port) =0; 29 | virtual int connect(const char *host, uint16_t port) =0; 30 | virtual size_t write(uint8_t) =0; 31 | virtual size_t write(const uint8_t *buf, size_t size) =0; 32 | virtual int available() = 0; 33 | virtual int read() = 0; 34 | virtual int read(uint8_t *buf, size_t size) = 0; 35 | virtual int peek() = 0; 36 | virtual void flush() = 0; 37 | virtual void stop() = 0; 38 | virtual uint8_t connected() = 0; 39 | virtual operator bool() = 0; 40 | protected: 41 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /cores/arduino/HardwareI2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Arduino LLC. 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 | #pragma once 20 | 21 | #include 22 | #include "Stream.h" 23 | 24 | class HardwareI2C : public Stream 25 | { 26 | public: 27 | virtual void begin() = 0; 28 | virtual void begin(uint8_t address) = 0; 29 | virtual void end() = 0; 30 | 31 | virtual void setClock(uint32_t freq) = 0; 32 | 33 | virtual void beginTransmission(uint8_t address) = 0; 34 | virtual uint8_t endTransmission(bool stopBit) = 0; 35 | virtual uint8_t endTransmission(void) = 0; 36 | 37 | virtual uint8_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0; 38 | virtual uint8_t requestFrom(uint8_t address, size_t len) = 0; 39 | 40 | virtual void onReceive(void(*)(int)) = 0; 41 | virtual void onRequest(void(*)(void)) = 0; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /cores/arduino/HardwareSerial.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 HardwareSerial_h 20 | #define HardwareSerial_h 21 | 22 | #include 23 | 24 | #include "Stream.h" 25 | 26 | class HardwareSerial : public Stream 27 | { 28 | public: 29 | virtual void begin(uint32_t) {}; 30 | virtual void end() {}; 31 | virtual int available(void) = 0; 32 | virtual int availableForWrite(void) = 0; 33 | virtual int peek(void) = 0; 34 | virtual int read(void) = 0; 35 | virtual void flush(void) = 0; 36 | virtual size_t write(uint8_t) = 0; 37 | using Print::write; // pull in write(str) and write(buf, size) from Print 38 | virtual operator bool() = 0; 39 | }; 40 | 41 | extern void serialEventRun(void) __attribute__((weak)); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /cores/arduino/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 "IPAddress.h" 21 | #include "Print.h" 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 | // TODO: add support for "a", "a.b", "a.b.c" formats 49 | 50 | uint16_t acc = 0; // Accumulator 51 | uint8_t dots = 0; 52 | 53 | while (*address) 54 | { 55 | char c = *address++; 56 | if (c >= '0' && c <= '9') 57 | { 58 | acc = acc * 10 + (c - '0'); 59 | if (acc > 255) { 60 | // Value out of [0..255] range 61 | return false; 62 | } 63 | } 64 | else if (c == '.') 65 | { 66 | if (dots == 3) { 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 | // Too few dots (there must be 3 dots) 82 | return false; 83 | } 84 | _address.bytes[3] = acc; 85 | return true; 86 | } 87 | 88 | IPAddress& IPAddress::operator=(const uint8_t *address) 89 | { 90 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 91 | return *this; 92 | } 93 | 94 | IPAddress& IPAddress::operator=(uint32_t address) 95 | { 96 | _address.dword = address; 97 | return *this; 98 | } 99 | 100 | bool IPAddress::operator==(const uint8_t* addr) const 101 | { 102 | return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; 103 | } 104 | 105 | size_t IPAddress::printTo(Print& p) const 106 | { 107 | size_t n = 0; 108 | for (int i =0; i < 3; i++) 109 | { 110 | n += p.print(_address.bytes[i], DEC); 111 | n += p.print('.'); 112 | } 113 | n += p.print(_address.bytes[3], DEC); 114 | return n; 115 | } 116 | 117 | const IPAddress INADDR_NONE(0,0,0,0); 118 | -------------------------------------------------------------------------------- /cores/arduino/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 | #pragma once 21 | 22 | #include 23 | #include "Printable.h" 24 | #include "WString.h" 25 | 26 | // A class to make it easier to handle and pass around IP addresses 27 | 28 | class IPAddress : public Printable { 29 | private: 30 | union { 31 | uint8_t bytes[4]; // IPv4 address 32 | uint32_t dword; 33 | } _address; 34 | 35 | // Access the raw byte array containing the address. Because this returns a pointer 36 | // to the internal structure rather than a copy of the address this function should only 37 | // be used when you know that the usage of the returned uint8_t* will be transient and not 38 | // stored. 39 | uint8_t* raw_address() { return _address.bytes; }; 40 | 41 | public: 42 | // Constructors 43 | IPAddress(); 44 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 45 | IPAddress(uint32_t address); 46 | IPAddress(const uint8_t *address); 47 | 48 | bool fromString(const char *address); 49 | bool fromString(const String &address) { return fromString(address.c_str()); } 50 | 51 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 52 | // to a four-byte uint8_t array is expected 53 | operator uint32_t() const { return _address.dword; }; 54 | bool operator==(const IPAddress& addr) const { return _address.dword == addr._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 | 68 | friend class EthernetClass; 69 | friend class UDP; 70 | friend class Client; 71 | friend class Server; 72 | friend class DhcpClass; 73 | friend class DNSClient; 74 | }; 75 | 76 | extern const IPAddress INADDR_NONE; 77 | 78 | -------------------------------------------------------------------------------- /cores/arduino/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 | #ifdef __cplusplus 24 | extern "C"{ 25 | #endif // __cplusplus 26 | #include 27 | #include // for size_t 28 | #include 29 | #include 30 | #include 31 | #ifdef __cplusplus 32 | } // extern "C" 33 | #endif // __cplusplus 34 | 35 | #include "WString.h" 36 | #include "Printable.h" 37 | 38 | #define DEC 10 39 | #define HEX 16 40 | #define OCT 8 41 | #define BIN 2 42 | 43 | class Print 44 | { 45 | private: 46 | int write_error; 47 | size_t printNumber(unsigned long, uint8_t); 48 | size_t printFloat(double, uint8_t); 49 | protected: 50 | void setWriteError(int err = 1) { write_error = err; } 51 | public: 52 | Print() : write_error(0) {} 53 | 54 | int getWriteError() { return write_error; } 55 | void clearWriteError() { setWriteError(0); } 56 | 57 | virtual size_t write(uint8_t) = 0; 58 | size_t write(const char *str) { 59 | if (str == NULL) return 0; 60 | return write((const uint8_t *)str, strlen(str)); 61 | } 62 | virtual size_t write(const uint8_t *buffer, size_t size); 63 | size_t write(const char *buffer, size_t size) { 64 | return write((const uint8_t *)buffer, size); 65 | } 66 | 67 | size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3))); 68 | size_t print(const __FlashStringHelper *); 69 | size_t print(const String &); 70 | size_t print(const char[]); 71 | size_t print(char); 72 | size_t print(unsigned char, int = DEC); 73 | size_t print(int, int = DEC); 74 | size_t print(unsigned int, int = DEC); 75 | size_t print(long, int = DEC); 76 | size_t print(unsigned long, int = DEC); 77 | size_t print(double, int = 2); 78 | size_t print(const Printable&); 79 | 80 | size_t println(const __FlashStringHelper *); 81 | size_t println(const String &s); 82 | size_t println(const char[]); 83 | size_t println(char); 84 | size_t println(unsigned char, int = DEC); 85 | size_t println(int, int = DEC); 86 | size_t println(unsigned int, int = DEC); 87 | size_t println(long, int = DEC); 88 | size_t println(unsigned long, int = DEC); 89 | size_t println(double, int = 2); 90 | size_t println(const Printable&); 91 | size_t println(void); 92 | }; 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /cores/arduino/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/arduino/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 | #define RING_BUFFER_SIZE 64 31 | 32 | template 33 | class RingBufferN 34 | { 35 | public: 36 | uint8_t _aucBuffer[N] ; 37 | volatile int _iHead ; 38 | volatile int _iTail ; 39 | 40 | public: 41 | RingBufferN( void ) ; 42 | void store_char( uint8_t c ) ; 43 | void clear(); 44 | int read_char(); 45 | int available(); 46 | int availableForStore(); 47 | int peek(); 48 | bool isFull(); 49 | 50 | private: 51 | int nextIndex(int index); 52 | }; 53 | 54 | typedef RingBufferN RingBuffer; 55 | 56 | 57 | template 58 | RingBufferN::RingBufferN( void ) 59 | { 60 | memset( _aucBuffer, 0, N ) ; 61 | clear(); 62 | } 63 | 64 | template 65 | void RingBufferN::store_char( uint8_t c ) 66 | { 67 | int i = nextIndex(_iHead); 68 | 69 | // if we should be storing the received character into the location 70 | // just before the tail (meaning that the head would advance to the 71 | // current location of the tail), we're about to overflow the buffer 72 | // and so we don't write the character or advance the head. 73 | if ( i != _iTail ) 74 | { 75 | _aucBuffer[_iHead] = c ; 76 | _iHead = i ; 77 | } 78 | } 79 | 80 | template 81 | void RingBufferN::clear() 82 | { 83 | _iHead = 0; 84 | _iTail = 0; 85 | } 86 | 87 | template 88 | int RingBufferN::read_char() 89 | { 90 | if(_iTail == _iHead) 91 | return -1; 92 | 93 | uint8_t value = _aucBuffer[_iTail]; 94 | _iTail = nextIndex(_iTail); 95 | 96 | return value; 97 | } 98 | 99 | template 100 | int RingBufferN::available() 101 | { 102 | int delta = _iHead - _iTail; 103 | 104 | if(delta < 0) 105 | return N + delta; 106 | else 107 | return delta; 108 | } 109 | 110 | template 111 | int RingBufferN::availableForStore() 112 | { 113 | if (_iHead >= _iTail) 114 | return N - 1 - _iHead + _iTail; 115 | else 116 | return _iTail - _iHead - 1; 117 | } 118 | 119 | template 120 | int RingBufferN::peek() 121 | { 122 | if(_iTail == _iHead) 123 | return -1; 124 | 125 | return _aucBuffer[_iTail]; 126 | } 127 | 128 | template 129 | int RingBufferN::nextIndex(int index) 130 | { 131 | return (uint32_t)(index + 1) % N; 132 | } 133 | 134 | template 135 | bool RingBufferN::isFull() 136 | { 137 | return (nextIndex(_iHead) == _iTail); 138 | } 139 | 140 | #endif /* _RING_BUFFER_ */ 141 | 142 | #endif /* __cplusplus */ -------------------------------------------------------------------------------- /cores/arduino/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 | #pragma once 21 | 22 | #include "Print.h" 23 | 24 | class Server : public Print { 25 | public: 26 | virtual void begin() = 0; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /cores/arduino/Tone.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "encoding.h" 3 | #include "pwm.h" 4 | 5 | extern pwm_fpio_set_t pwm_pins[VARIANT_NUM_PWM]; 6 | 7 | void tone(uint8_t pin, unsigned int frequency, unsigned long duration) 8 | { 9 | int8_t _pin = k210FpioSet(MD_PIN_MAP(pin)); 10 | if(_pin >= 0){ 11 | if (duration > 0) { 12 | pwm_set_frequency(pwm_pins[_pin].device, pwm_pins[_pin].channel,(double)frequency,0.5); 13 | uint64_t _start_time = millis(); 14 | pwm_set_enable(pwm_pins[_pin].device, pwm_pins[_pin].channel,1); 15 | while ( millis() - _start_time < duration ); 16 | pwm_set_enable(pwm_pins[_pin].device, pwm_pins[_pin].channel,0); 17 | }else{ 18 | pwm_set_frequency(pwm_pins[_pin].device, pwm_pins[_pin].channel,(double)frequency,0.5); 19 | pwm_set_enable(pwm_pins[_pin].device, pwm_pins[_pin].channel,1); 20 | } 21 | } 22 | 23 | } 24 | 25 | void noTone(uint8_t pin) 26 | { 27 | int8_t _pin = k210FpioSet(MD_PIN_MAP(pin)); 28 | if(_pin >= 0){ 29 | pwm_set_enable(pwm_pins[_pin].device, pwm_pins[_pin].channel,0); 30 | } 31 | } -------------------------------------------------------------------------------- /cores/arduino/UARTClass.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 _UART_CLASS_ 20 | #define _UART_CLASS_ 21 | 22 | #include "platform.h" 23 | #include "HardwareSerial.h" 24 | #include "uarths.h" 25 | #include "uart.h" 26 | #include "fpioa.h" 27 | #include "pins_arduino.h" 28 | #include "RingBuffer.h" 29 | 30 | 31 | 32 | class UARTClass : public HardwareSerial 33 | { 34 | public: 35 | UARTClass(); 36 | UARTClass(uart_device_number_t device_select); 37 | void begin(uint32_t dwBaudRate); 38 | void begin(uint32_t dwBaudRate, uint8_t _rx, uint8_t _tx); 39 | void end(void); 40 | int available(void); 41 | int availableForWrite(void); 42 | int peek(void); 43 | int read(void); 44 | void flush(void); 45 | size_t write(const uint8_t c); 46 | using Print::write; // pull in write(str) and write(buf, size) from Print 47 | 48 | operator bool() {return (true);}; // UART always active 49 | //protected: 50 | RingBuffer *_buff; 51 | uint32_t _timeout = 1000; 52 | uart_device_number_t _uart; 53 | private: 54 | fpioa_function_t _rxfunc; 55 | fpioa_function_t _txfunc; 56 | //static int _rec_callback(void *ctx); 57 | }; 58 | 59 | class UARTHSClass : public UARTClass 60 | { 61 | public: 62 | UARTHSClass(); 63 | void begin(uint32_t dwBaudRate); 64 | void begin(uint32_t dwBaudRate, uint8_t _rx, uint8_t _tx); 65 | void end(void); 66 | size_t write(const uint8_t c); 67 | using Print::write; 68 | operator bool() {return (true);}; // UART always active 69 | //private: 70 | //static int _rec_callback(void *ctx); 71 | }; 72 | 73 | extern volatile uart_t* const uart[3]; 74 | extern int uarths_putchar(char c); 75 | extern int uarths_getc(void); 76 | 77 | #endif // _UART_CLASS_ 78 | -------------------------------------------------------------------------------- /cores/arduino/WInterrupts.c: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "WInterrupts.h" 3 | #include "wiring_constants.h" 4 | #include "plic.h" 5 | 6 | void attachInterrupt(uint8_t intnum, voidFuncPtr user_callback, uint8_t mode) 7 | { 8 | int gpionum = get_gpio(MD_PIN_MAP(intnum)); 9 | if(gpionum >= 0){ 10 | fpioa_function_t function = FUNC_GPIOHS0 + gpionum; 11 | fpioa_set_function(intnum, function); 12 | gpiohs_set_drive_mode(gpionum, GPIO_DM_INPUT_PULL_UP); 13 | switch(mode){ 14 | case LOW : 15 | gpiohs_set_pin_edge((uint8_t)gpionum, GPIO_PE_LOW); 16 | break; 17 | case HIGH : 18 | gpiohs_set_pin_edge((uint8_t)gpionum, GPIO_PE_HIGH); 19 | break; 20 | case FALLING : 21 | gpiohs_set_pin_edge((uint8_t)gpionum, GPIO_PE_FALLING); 22 | break; 23 | case CHANGE : 24 | gpiohs_set_pin_edge((uint8_t)gpionum, GPIO_PE_BOTH); 25 | break; 26 | case RISING : 27 | gpiohs_set_pin_edge((uint8_t)gpionum, GPIO_PE_RISING); 28 | break; 29 | } 30 | gpiohs_irq_register((uint8_t)gpionum, 10, gpiohs_callback, user_callback); 31 | sysctl_enable_irq(); 32 | } 33 | } 34 | 35 | void detachInterrupt(uint8_t intnum) 36 | { 37 | int gpionum = get_gpio(MD_PIN_MAP(intnum)); 38 | if(gpionum >= 0){ 39 | gpiohs_irq_unregister((uint8_t)gpionum); 40 | } 41 | } 42 | 43 | int gpiohs_callback(void *ctx) 44 | { 45 | voidFuncPtr user_callback = ctx; 46 | user_callback(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /cores/arduino/WInterrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. 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_INTERRUPTS_ 20 | #define _WIRING_INTERRUPTS_ 21 | 22 | #include 23 | #include "plic.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C"{ 27 | #endif // __cplusplus 28 | 29 | // LOW 0 30 | // HIGH 1 31 | #define CHANGE 2 32 | #define FALLING 3 33 | #define RISING 4 34 | 35 | #define DEFAULT 1 36 | #define EXTERNAL 0 37 | 38 | #define digitalPinToInterrupt(Pin) Pin 39 | typedef void (*voidFuncPtr)(void); 40 | /* 41 | * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. Use digitalPinToInterrupt(pin) to get the correct intnum. 42 | * Other interrupt numbers are available, see platform.h. 43 | * Replaces any previous function that was attached to the interrupt. 44 | */ 45 | void attachInterrupt(uint8_t intnum, voidFuncPtr callback, uint8_t mode); 46 | 47 | /* 48 | * \brief Turns off the given interrupt. 49 | */ 50 | void detachInterrupt(uint8_t intnum); 51 | 52 | int gpiohs_callback(void *ctx); 53 | 54 | #ifdef __cplusplus 55 | } // extern "C" 56 | #endif // __cplusplus 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /cores/arduino/WMath.cpp: -------------------------------------------------------------------------------- 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 | extern "C" { 20 | #include "stdlib.h" 21 | #include "stdint.h" 22 | } 23 | #include "WMath.h" 24 | 25 | extern void randomSeed( uint32_t dwSeed ) 26 | { 27 | if ( dwSeed != 0 ) 28 | { 29 | srand( dwSeed ) ; 30 | } 31 | } 32 | 33 | extern long random( long howbig ) 34 | { 35 | if ( howbig == 0 ) 36 | { 37 | return 0 ; 38 | } 39 | 40 | return rand() % howbig; 41 | } 42 | 43 | extern long random( long howsmall, long howbig ) 44 | { 45 | if (howsmall >= howbig) 46 | { 47 | return howsmall; 48 | } 49 | 50 | long diff = howbig - howsmall; 51 | 52 | return random(diff) + howsmall; 53 | } 54 | 55 | extern long map(long x, long in_min, long in_max, long out_min, long out_max) 56 | { 57 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 58 | } 59 | 60 | extern uint16_t makeWord( uint16_t w ) 61 | { 62 | return w ; 63 | } 64 | 65 | extern uint16_t makeWord( uint8_t h, uint8_t l ) 66 | { 67 | return (h << 8) | l ; 68 | } 69 | -------------------------------------------------------------------------------- /cores/arduino/WMath.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_MATH_ 20 | #define _WIRING_MATH_ 21 | #include 22 | 23 | extern long random( long ) ; 24 | extern long random( long, long ) ; 25 | extern void randomSeed( uint32_t dwSeed ) ; 26 | extern long map( long, long, long, long, long ) ; 27 | 28 | extern uint16_t makeWord( uint16_t w ) ; 29 | extern uint16_t makeWord( uint8_t h, uint8_t l ) ; 30 | 31 | #define word(...) makeWord(__VA_ARGS__) 32 | 33 | 34 | #endif /* _WIRING_MATH_ */ 35 | -------------------------------------------------------------------------------- /cores/arduino/abi.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 | extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); 22 | extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); 23 | 24 | void __cxa_pure_virtual(void) { 25 | // We might want to write some diagnostics to uart in this case 26 | //std::terminate(); 27 | while (1) 28 | ; 29 | } 30 | 31 | void __cxa_deleted_virtual(void) { 32 | // We might want to write some diagnostics to uart in this case 33 | //std::terminate(); 34 | while (1) 35 | ; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /cores/arduino/avr/dtostrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 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 | #pragma once 21 | 22 | #if !defined(ARDUINO_ARCH_AVR) 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/arduino/avr/pgmspace.h: -------------------------------------------------------------------------------- 1 | #ifndef __PGMSPACE_H_ 2 | #define __PGMSPACE_H_ 1 3 | 4 | #include 5 | 6 | #define PROGMEM 7 | #define PGM_P const char * 8 | #define PSTR(str) (str) 9 | 10 | #define _SFR_BYTE(n) (n) 11 | 12 | typedef void prog_void; 13 | typedef char prog_char; 14 | typedef unsigned char prog_uchar; 15 | typedef int8_t prog_int8_t; 16 | typedef uint8_t prog_uint8_t; 17 | typedef int16_t prog_int16_t; 18 | typedef uint16_t prog_uint16_t; 19 | typedef int32_t prog_int32_t; 20 | typedef uint32_t prog_uint32_t; 21 | 22 | #define memcmp_P memcmp 23 | #define memccpy_P memccpy 24 | #define memmem_P memmem 25 | #define memcpy_P memcpy 26 | #define strcpy_P strcpy 27 | #define strncpy_P strncpy 28 | #define strcat_P strcat 29 | #define strncat_P strncat 30 | #define strcmp_P strcmp 31 | #define strncmp_P strncmp 32 | #define strcasecmp_P strcasecmp 33 | #define strncasecmp_P strncasecmp 34 | #define strlen_P strlen 35 | #define strnlen_P strnlen 36 | #define strstr_P strstr 37 | #define printf_P printf 38 | #define sprintf_P sprintf 39 | #define snprintf_P snprintf 40 | #define vsnprintf_P vsnprintf 41 | 42 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 43 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 44 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) 45 | #define pgm_read_float(addr) (*(const float *)(addr)) 46 | 47 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) 48 | #define pgm_read_word_near(addr) pgm_read_word(addr) 49 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) 50 | #define pgm_read_float_near(addr) pgm_read_float(addr) 51 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) 52 | #define pgm_read_word_far(addr) pgm_read_word(addr) 53 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) 54 | #define pgm_read_float_far(addr) pgm_read_float(addr) 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /cores/arduino/hal/include/SPI_hal.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ARDUINO_SPI_HAL_H 3 | #define __ARDUINO_SPI_HAL_H 4 | 5 | #define SPI_MUTEX_LOCK() 6 | #define SPI_MUTEX_UNLOCK() 7 | 8 | 9 | #endif //__ARDUINO_SPI_HAL_H 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cores/arduino/hooks.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 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 | /** 20 | * Empty yield() hook. 21 | * 22 | * This function is intended to be used by library writers to build 23 | * libraries or sketches that supports cooperative threads. 24 | * 25 | * Its defined as a weak symbol and it can be redefined to implement a 26 | * real cooperative scheduler. 27 | */ 28 | static void __empty() { 29 | // Empty 30 | } 31 | void yield(void) __attribute__ ((weak, alias("__empty"))); 32 | 33 | /** 34 | * SysTick hook 35 | * 36 | * This function is called from SysTick handler, before the default 37 | * handler provided by Arduino. 38 | */ 39 | static int __false() { 40 | // Return false 41 | return 0; 42 | } 43 | int sysTickHook(void) __attribute__ ((weak, alias("__false"))); 44 | 45 | /** 46 | * SVC hook 47 | * PendSV hook 48 | * 49 | * These functions are called from SVC handler, and PensSV handler. 50 | * Default action is halting. 51 | */ 52 | static void __halt() { 53 | // Halts 54 | while (1) 55 | ; 56 | } 57 | void svcHook(void) __attribute__ ((weak, alias("__halt"))); 58 | void pendSVHook(void) __attribute__ ((weak, alias("__halt"))); 59 | -------------------------------------------------------------------------------- /cores/arduino/itoa.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 _ITOA_ 20 | #define _ITOA_ 21 | 22 | #ifdef __cplusplus 23 | extern "C"{ 24 | #endif // __cplusplus 25 | 26 | extern char* itoa(int value, char *string, int radix); 27 | extern char* ltoa(long value, char *string, int radix); 28 | extern char* utoa(unsigned value, char *string, int radix); 29 | extern char* ultoa(unsigned long value, char *string, int radix); 30 | 31 | #ifdef __cplusplus 32 | } // extern "C" 33 | #endif // __cplusplus 34 | 35 | #endif // _ITOA_ 36 | -------------------------------------------------------------------------------- /cores/arduino/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #define ARDUINO_MAIN 3 | #include "Arduino.h" 4 | #include "encoding.h" 5 | 6 | 7 | #define cmb() __asm__ __volatile__ ("" ::: "memory") 8 | extern "C"{ void * __dso_handle = 0 ;} 9 | 10 | /* 11 | * \brief Main entry point of Arduino application 12 | */ 13 | int main( void ) 14 | { 15 | pll_init(); 16 | plic_init(); 17 | uarths_init(); 18 | gpio_init(); 19 | sysctl_set_power_mode(SYSCTL_POWER_BANK6,SYSCTL_POWER_V18); 20 | sysctl_set_power_mode(SYSCTL_POWER_BANK7,SYSCTL_POWER_V18); 21 | sysctl_enable_irq(); 22 | setup(); 23 | 24 | do { 25 | loop(); 26 | //if (serialEventRun) 27 | // serialEventRun(); 28 | } while (1); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /cores/arduino/st7789.c: -------------------------------------------------------------------------------- 1 | #include "st7789.h" 2 | 3 | 4 | static uint8_t g_gpio_dcx; 5 | static int8_t g_gpio_rst; 6 | static spi_device_num_t g_spi_num; 7 | static dmac_channel_number_t g_dma_ch; 8 | static uint8_t g_ss; 9 | 10 | static void init_dcx(uint8_t dcx, int8_t dcx_pin) 11 | { 12 | fpioa_set_function(dcx_pin , FUNC_GPIO0 + dcx); 13 | g_gpio_dcx = dcx; 14 | gpio_set_drive_mode(g_gpio_dcx, GPIO_DM_OUTPUT); 15 | gpio_set_pin(g_gpio_dcx, GPIO_PV_HIGH); 16 | } 17 | 18 | static void set_dcx_control(void) 19 | { 20 | gpio_set_pin(g_gpio_dcx, GPIO_PV_LOW); 21 | } 22 | 23 | static void set_dcx_data(void) 24 | { 25 | gpio_set_pin(g_gpio_dcx, GPIO_PV_HIGH); 26 | } 27 | 28 | static void init_rst(uint8_t rst, int8_t rst_pin) 29 | { 30 | g_gpio_rst = rst; 31 | if( rst_pin < 0) 32 | return ; 33 | fpioa_set_function(rst_pin , FUNC_GPIO0 + rst); 34 | gpio_set_drive_mode(g_gpio_rst, GPIO_DM_OUTPUT); 35 | gpio_set_pin(g_gpio_rst, GPIO_PV_HIGH); 36 | } 37 | 38 | static void set_rst(uint8_t val) 39 | { 40 | if(g_gpio_rst < 0) 41 | return ; 42 | gpio_set_pin(g_gpio_rst, val); 43 | } 44 | 45 | void tft_set_clk_freq(uint32_t freq) 46 | { 47 | spi_set_clk_rate(g_spi_num, freq); 48 | } 49 | 50 | void tft_hard_init(uint8_t spi, uint8_t ss, uint8_t rst, uint8_t dcx, uint32_t freq, int8_t rst_pin, int8_t dcx_pin, uint8_t dma_ch) 51 | { 52 | g_spi_num = spi; 53 | g_dma_ch = dma_ch; 54 | g_ss = ss; 55 | init_dcx(dcx, dcx_pin); 56 | init_rst(rst, rst_pin); 57 | set_rst(0); 58 | spi_init(g_spi_num, SPI_WORK_MODE_0, SPI_FF_OCTAL, 8, 0); 59 | tft_set_clk_freq(freq); 60 | set_rst(1); 61 | } 62 | 63 | void tft_write_command(uint8_t cmd) 64 | { 65 | set_dcx_control(); 66 | spi_init(g_spi_num, SPI_WORK_MODE_0, SPI_FF_OCTAL, 8, 0); 67 | spi_init_non_standard(g_spi_num, 8 /*instrction length*/, 0 /*address length*/, 0 /*wait cycles*/, 68 | SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); 69 | spi_send_data_normal_dma(g_dma_ch, g_spi_num, g_ss, (uint8_t *)(&cmd), 1, SPI_TRANS_CHAR); 70 | } 71 | 72 | void tft_write_byte(uint8_t *data_buf, uint32_t length) 73 | { 74 | set_dcx_data(); 75 | spi_init(g_spi_num, SPI_WORK_MODE_0, SPI_FF_OCTAL, 8, 0); 76 | spi_init_non_standard(g_spi_num, 8 /*instrction length*/, 0 /*address length*/, 0 /*wait cycles*/, 77 | SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); 78 | spi_send_data_normal_dma(g_dma_ch, g_spi_num, g_ss, data_buf, length, SPI_TRANS_CHAR); 79 | } 80 | 81 | void tft_write_half(uint16_t *data_buf, uint32_t length) 82 | { 83 | set_dcx_data(); 84 | spi_init(g_spi_num, SPI_WORK_MODE_0, SPI_FF_OCTAL, 16, 0); 85 | spi_init_non_standard(g_spi_num, 16 /*instrction length*/, 0 /*address length*/, 0 /*wait cycles*/, 86 | SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); 87 | spi_send_data_normal_dma(g_dma_ch, g_spi_num, g_ss, data_buf, length, SPI_TRANS_SHORT); 88 | } 89 | 90 | void tft_write_word(uint32_t *data_buf, uint32_t length) 91 | { 92 | set_dcx_data(); 93 | spi_init(g_spi_num, SPI_WORK_MODE_0, SPI_FF_OCTAL, 32, 0); 94 | 95 | spi_init_non_standard(g_spi_num, 0 /*instrction length*/, 32 /*address length*/, 0 /*wait cycles*/, 96 | SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); 97 | spi_send_data_normal_dma(g_dma_ch, g_spi_num, g_ss, data_buf, length, SPI_TRANS_INT); 98 | } 99 | 100 | void tft_fill_data(uint32_t *data_buf, uint32_t length) 101 | { 102 | set_dcx_data(); 103 | spi_init(g_spi_num, SPI_WORK_MODE_0, SPI_FF_OCTAL, 32, 0); 104 | spi_init_non_standard(g_spi_num, 0 /*instrction length*/, 32 /*address length*/, 0 /*wait cycles*/, 105 | SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); 106 | spi_fill_data_dma(g_dma_ch, g_spi_num, g_ss, data_buf, length); 107 | } 108 | -------------------------------------------------------------------------------- /cores/arduino/stdlib_noniso.h: -------------------------------------------------------------------------------- 1 | /* 2 | stdlib_noniso.h - nonstandard (but usefull) conversion functions 3 | 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 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 STDLIB_NONISO_H 22 | #define STDLIB_NONISO_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | int atoi(const char *s); 29 | 30 | long atol(const char* s); 31 | 32 | double atof(const char* s); 33 | 34 | char* itoa (int val, char *s, int radix); 35 | 36 | char* ltoa (long val, char *s, int radix); 37 | 38 | char* utoa (unsigned int val, char *s, int radix); 39 | 40 | char* ultoa (unsigned long val, char *s, int radix); 41 | 42 | char* dtostrf (double val, signed char width, unsigned char prec, char *s); 43 | 44 | #ifdef __cplusplus 45 | } // extern "C" 46 | #endif 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /cores/arduino/wiring.c: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "sysctl.h" 3 | #include "sleep.h" 4 | 5 | uint64_t millis(){ 6 | return sysctl_get_time_us()/1000; 7 | } 8 | uint64_t micros(){ 9 | return sysctl_get_time_us(); 10 | } 11 | void delay(uint64_t dwMs){ 12 | msleep(dwMs); 13 | return; 14 | } 15 | void delayMicroseconds(uint64_t dwUs){ 16 | usleep(dwUs); 17 | return; 18 | } 19 | 20 | void pll_init(){ 21 | sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL); 22 | sysctl_pll_set_freq(SYSCTL_PLL1, 300000000UL); 23 | sysctl_pll_set_freq(SYSCTL_PLL2, 45158400UL); 24 | return; 25 | } -------------------------------------------------------------------------------- /cores/arduino/wiring.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIRING_ 2 | #define _WIRING_ 3 | 4 | #include "sysctl.h" 5 | #include "sleep.h" 6 | /** 7 | * \brief Returns the number of milliseconds since the board began running the current program. 8 | * 9 | * \return Number of milliseconds since the program started (uint64_t) 10 | */ 11 | extern uint64_t millis(void); 12 | 13 | /** 14 | * \brief Returns the number of microseconds since the board began running the current program. 15 | * 16 | * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. 17 | */ 18 | extern uint64_t micros(void); 19 | 20 | /** 21 | * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. 22 | * (There are 1000 milliseconds in a second.) 23 | * 24 | * \param dwMs the number of milliseconds to pause (uint64_t) 25 | */ 26 | extern void delay(uint64_t dwMs); 27 | 28 | extern void delayMicroseconds(uint64_t dwUs); 29 | 30 | void pll_init(void); 31 | 32 | 33 | 34 | #endif -------------------------------------------------------------------------------- /cores/arduino/wiring_analog.c: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "wiring_analog.h" 3 | #include "pwm.h" 4 | #include "fpioa.h" 5 | #include "stdio.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C"{ 9 | #endif // __cplusplus 10 | 11 | static int _readResolution = 0; 12 | static int _writeResolution = 8; 13 | static double _writeFreq = 200000; 14 | 15 | pwm_fpio_set_t pwm_pins[VARIANT_NUM_PWM]={ 16 | {.channel = PWM_CHANNEL_0, .device = PWM_DEVICE_0, .inuse = 0x0}, 17 | {.channel = PWM_CHANNEL_1, .device = PWM_DEVICE_0, .inuse = 0x0}, 18 | {.channel = PWM_CHANNEL_2, .device = PWM_DEVICE_0, .inuse = 0x0}, 19 | {.channel = PWM_CHANNEL_3, .device = PWM_DEVICE_0, .inuse = 0x0}, 20 | {.channel = PWM_CHANNEL_0, .device = PWM_DEVICE_1, .inuse = 0x0}, 21 | {.channel = PWM_CHANNEL_1, .device = PWM_DEVICE_1, .inuse = 0x0}, 22 | {.channel = PWM_CHANNEL_2, .device = PWM_DEVICE_1, .inuse = 0x0}, 23 | {.channel = PWM_CHANNEL_3, .device = PWM_DEVICE_1, .inuse = 0x0}, 24 | {.channel = PWM_CHANNEL_0, .device = PWM_DEVICE_2, .inuse = 0x0}, 25 | {.channel = PWM_CHANNEL_1, .device = PWM_DEVICE_2, .inuse = 0x0}, 26 | {.channel = PWM_CHANNEL_2, .device = PWM_DEVICE_2, .inuse = 0x0}, 27 | {.channel = PWM_CHANNEL_3, .device = PWM_DEVICE_2, .inuse = 0x0}, 28 | }; 29 | static uint8_t _pwm_used_pin = 0; 30 | /* K210 CAN'T READ */ 31 | void analogReadResolution(int res){ 32 | _readResolution = res; 33 | } 34 | 35 | void analogWriteResolution(int res){ 36 | _writeResolution = res; 37 | } 38 | 39 | void analogWriteFrequency(double res){ 40 | _writeFreq = res; 41 | } 42 | 43 | void analogWritePhase(uint8_t pin, uint32_t phase) 44 | { 45 | 46 | } 47 | 48 | void analogOutputInit(void) 49 | { 50 | 51 | } 52 | 53 | void analogWrite(uint8_t ucPin, uint32_t ulValue ) 54 | { 55 | int8_t _pin = k210FpioSet(MD_PIN_MAP(ucPin)); 56 | double _duty; 57 | if(_pin >= 0){ 58 | _duty = dValueToDuty(ulValue); 59 | pwm_set_frequency(pwm_pins[_pin].device, pwm_pins[_pin].channel,_writeFreq,_duty>1?1:_duty); 60 | pwm_set_enable(pwm_pins[_pin].device, pwm_pins[_pin].channel,1); 61 | } 62 | } 63 | 64 | double dValueToDuty(uint32_t ulValue){ 65 | return (double)ulValue/(double)((1<<_writeResolution)-1); 66 | } 67 | 68 | int8_t k210FpioSet(uint8_t ucPin) 69 | { 70 | int8_t _pin; 71 | for(int i = 0; i < _pwm_used_pin; i++){ 72 | if(ucPin == pwm_pins[i].inuse){ 73 | return i; 74 | } 75 | } 76 | _pin = getPwmPin(); 77 | if(_pin >= 0){ 78 | fpioa_set_function(ucPin, FUNC_TIMER0_TOGGLE1 + _pin); 79 | pwm_pins[_pin].inuse = ucPin; 80 | pwm_init(pwm_pins[_pin].device); 81 | _pwm_used_pin += 1; 82 | return _pin; 83 | }else{ 84 | return -1; 85 | } 86 | 87 | } 88 | 89 | int8_t getPwmPin(void) 90 | { 91 | for(int i = _pwm_used_pin; i < VARIANT_NUM_PWM; i++){ 92 | if(pwm_pins[i].inuse == 0){ 93 | return i; 94 | } 95 | } 96 | return -1; 97 | } 98 | 99 | uint32_t analogRead( uint32_t ulPin ) 100 | { 101 | #if (defined(BOARD_SIPEED_MAIX_GO) || defined(BOARD_SIPEED_MAIX_ONE_DOCK) ) 102 | return 0; 103 | #endif 104 | } 105 | 106 | #ifdef __cplusplus 107 | } // extern "C" 108 | #endif // __cplusplus 109 | -------------------------------------------------------------------------------- /cores/arduino/wiring_analog.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _WIRING_ANALOG_ 3 | #define _WIRING_ANALOG_ 4 | 5 | #ifdef __cplusplus 6 | extern "C"{ 7 | #endif // __cplusplus 8 | 9 | 10 | typedef enum _eAnalogReference 11 | { 12 | AR_DEFAULT, 13 | } eAnalogReference ; 14 | 15 | 16 | /* 17 | * \brief Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). 18 | * This function is kept only for compatibility with existing AVR based API. 19 | * 20 | * \param ulMmode Should be set to AR_DEFAULT. 21 | */ 22 | extern void analogReference( eAnalogReference ulMode ) ; 23 | 24 | /* 25 | * \brief Writes an analog value (PWM wave) to a pin. 26 | * 27 | * \param ulPin 28 | * \param ulValue 29 | */ 30 | extern void analogWrite( uint8_t ucPin, uint32_t ulValue ) ; 31 | 32 | /* 33 | * \brief Reads the value from the specified analog pin. 34 | * 35 | * \param ulPin 36 | * 37 | * \return Read value from selected pin, if no error. 38 | */ 39 | extern uint32_t analogRead( uint32_t ulPin ) ; 40 | 41 | /* 42 | * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023). 43 | * 44 | * \param res 45 | */ 46 | extern void analogReadResolution(int res); 47 | 48 | /* 49 | * \brief Set the resolution of analogWrite parameters. Default is 8 bits (range from 0 to 255). 50 | * 51 | * \param res 52 | */ 53 | extern void analogWriteResolution(int res); 54 | 55 | /* 56 | * \brief Set the frequency of analogWrite PWM output. Default is 980 Hz (range from 20 to 25000). 57 | * 58 | * \param res 59 | */ 60 | extern void analogWriteFrequency(double freq); 61 | 62 | extern void analogWritePhase(uint8_t pin, uint32_t phase); 63 | 64 | extern void analogOutputInit( void ) ; 65 | 66 | extern double dValueToDuty(uint32_t ulValue); 67 | 68 | extern int8_t k210FpioSet(uint8_t ucPin); 69 | 70 | extern int8_t getPwmPin(void); 71 | 72 | #ifdef __cplusplus 73 | } // extern "C" 74 | #endif // __cplusplus 75 | 76 | #endif /* _WIRING_ANALOG_ */ -------------------------------------------------------------------------------- /cores/arduino/wiring_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 | #include "encoding.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C"{ 28 | #endif // __cplusplus 29 | 30 | #define HIGH 0x1 31 | #define LOW 0x0 32 | 33 | #define INPUT 0x0 34 | #define OUTPUT 0x3 35 | #define INPUT_PULLUP 0x2 36 | #define INPUT_PULLDOWN 0X1 37 | 38 | #define PI 3.1415926535897932384626433832795 39 | #define HALF_PI 1.5707963267948966192313216916398 40 | #define TWO_PI 6.283185307179586476925286766559 41 | #define DEG_TO_RAD 0.017453292519943295769236907684886 42 | #define RAD_TO_DEG 57.295779513082320876798154814105 43 | #define EULER 2.718281828459045235360287471352 44 | 45 | #define SERIAL 0x0 46 | #define DISPLAY 0x1 47 | 48 | enum BitOrder { 49 | LSBFIRST = 0, 50 | MSBFIRST = 1 51 | }; 52 | 53 | // LOW 0 54 | // HIGH 1 55 | #define CHANGE 2 56 | #define FALLING 3 57 | #define RISING 4 58 | 59 | #define DEFAULT 1 60 | #define EXTERNAL 0 61 | 62 | // undefine stdlib's abs if encountered 63 | #ifdef abs 64 | #undef abs 65 | #endif // abs 66 | 67 | #ifndef min 68 | #define min(a,b) (((a)<(b))?(a):(b)) 69 | #endif // min 70 | 71 | #ifndef max 72 | #define max(a,b) (((a)>(b))?(a):(b)) 73 | #endif // max 74 | 75 | #define abs(x) ((x)>0?(x):-(x)) 76 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 77 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 78 | #define radians(deg) ((deg)*DEG_TO_RAD) 79 | #define degrees(rad) ((rad)*RAD_TO_DEG) 80 | #define sq(x) ((x)*(x)) 81 | 82 | #define interrupts() set_csr(mstatus, MSTATUS_MIE) 83 | #define noInterrupts() clear_csr(mstatus, MSTATUS_MIE) 84 | 85 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 86 | #define highByte(w) ((uint8_t) ((w) >> 8)) 87 | 88 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 89 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 90 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 91 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 92 | 93 | typedef unsigned int word; 94 | 95 | #define bit(b) (1UL << (b)) 96 | 97 | typedef bool boolean ; 98 | typedef uint8_t byte ; 99 | 100 | #ifdef __cplusplus 101 | } // extern "C" 102 | #endif // __cplusplus 103 | 104 | 105 | #endif /* _WIRING_CONSTANTS_ */ -------------------------------------------------------------------------------- /cores/arduino/wiring_digital.c: -------------------------------------------------------------------------------- 1 | 2 | #include "Arduino.h" 3 | 4 | #include 5 | 6 | #include "fpioa.h" 7 | #include "gpiohs.h" 8 | #include "gpio.h" 9 | #include "wiring_constants.h" 10 | #include "wiring_digital.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C"{ 14 | #endif // __cplusplus 15 | 16 | static int8_t _fpio_to_gpio_table[48]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; 17 | 18 | void pinMode(uint8_t dwPin, uint8_t dwMode){ 19 | int gpionum = get_gpio(MD_PIN_MAP(dwPin)); 20 | if(gpionum >= 0){ 21 | fpioa_function_t function = FUNC_GPIOHS0 + gpionum; 22 | fpioa_set_function(MD_PIN_MAP(dwPin), function); 23 | gpiohs_set_drive_mode((uint8_t)gpionum, (gpio_drive_mode_t)dwMode); 24 | } 25 | return ; 26 | } 27 | 28 | void digitalWrite(uint8_t dwPin, uint8_t dwVal){ 29 | int8_t gpio_pin = _fpio_to_gpio_table[MD_PIN_MAP(dwPin)]; 30 | if( gpio_pin >= 0){ 31 | gpiohs_set_pin((uint8_t)gpio_pin, (gpio_pin_value_t)dwVal); 32 | } 33 | return ; 34 | } 35 | 36 | int digitalRead(uint8_t dwPin){ 37 | int8_t gpio_pin = _fpio_to_gpio_table[MD_PIN_MAP(dwPin)]; 38 | if(gpio_pin >= 0){ 39 | return (int)gpiohs_get_pin((uint8_t)gpio_pin); 40 | } 41 | return -1; 42 | } 43 | 44 | int get_gpio(uint8_t fpio_pin) 45 | { 46 | if(_fpio_to_gpio_table[fpio_pin] >= 0){ 47 | return (int)_fpio_to_gpio_table[fpio_pin]; 48 | }else{ 49 | _fpio_to_gpio_table[fpio_pin] = (int8_t)find_unused_gpiohs_io(); 50 | return (int)_fpio_to_gpio_table[fpio_pin]; 51 | } 52 | } 53 | 54 | fpioa_function_t fpioa_get_function_by_io(uint8_t fpioPin) 55 | { 56 | return (fpioa_function_t)fpioa->io[fpioPin].ch_sel ; 57 | } 58 | 59 | int find_unused_gpiohs_io(void) //返回一个未使用的gpio ,失败返回-1 60 | { 61 | static fpioa_function_t function = FUNC_GPIOHS0; 62 | int _io ; 63 | if (function <= FUNC_GPIOHS31) 64 | { 65 | _io = (int)(function - FUNC_GPIOHS0); 66 | function++; 67 | return _io; 68 | } 69 | return -1; 70 | } 71 | 72 | int read_fpio_to_gpio_table(int number) 73 | { 74 | return _fpio_to_gpio_table[number]; 75 | } 76 | 77 | #ifdef __cplusplus 78 | } // extern "C" 79 | #endif // __cplusplus -------------------------------------------------------------------------------- /cores/arduino/wiring_digital.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIRING_DIGITAL_ 2 | #define _WIRING_DIGITAL_ 3 | 4 | #include "Arduino.h" 5 | #include 6 | #include "platform.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C"{ 10 | #endif // __cplusplus 11 | 12 | #define PortValue_t uint32_t 13 | #define PortAddr_t uint32_t 14 | #define PortRegister_t volatile uint32_t * 15 | 16 | #define digitalPinToPort(pin) ((PortAddr_t) GPIOHS_BASE_ADDR) 17 | #define digitalPinToPortIn(pin) ((PortAddr_t) GPIOHS_BASE_ADDR) 18 | #define digitalPinToBitMask(pin) ((PortValue_t) (1< 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef void (*voidFuncPtr)(void); 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | 43 | #endif -------------------------------------------------------------------------------- /cores/arduino/wiring_pulse.c: -------------------------------------------------------------------------------- 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 | #include "Arduino.h" 20 | #include "wiring_private.h" 21 | #include "sysctl.h" 22 | 23 | 24 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 25 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 26 | * to 3 minutes in length, but must be called at least a few dozen microseconds 27 | * before the start of the pulse. */ 28 | extern uint32_t pulseIn(uint32_t pin, bool state, uint32_t timeout) 29 | { 30 | uint32_t cpu_freq = sysctl_clock_get_freq(SYSCTL_CLOCK_CPU); 31 | uint32_t numloops = 0; 32 | uint32_t maxloops = timeout * (cpu_freq / 1000000L) / 16; // microsecondsToClockCycles(timeout) / 16; ??? 33 | uint32_t start, end; 34 | 35 | // wait for any previous pulse to end 36 | while (digitalRead(pin) == state) 37 | if (numloops++ == maxloops) 38 | return 0; 39 | 40 | // wait for the pulse to start 41 | while (digitalRead(pin) != state) 42 | if (numloops++ == maxloops) 43 | return 0; 44 | 45 | // wait for the pulse to stop 46 | start = micros(); 47 | while (digitalRead(pin) == state) 48 | if (numloops++ == maxloops) 49 | return 0; 50 | end = micros(); 51 | 52 | return (end - start); 53 | } 54 | -------------------------------------------------------------------------------- /cores/arduino/wiring_pulse.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_PULSE_ 20 | #define _WIRING_PULSE_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C"{ 26 | #endif // __cplusplus 27 | 28 | /* 29 | * \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH 30 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 31 | * to 3 minutes in length, but must be called at least a few dozen microseconds 32 | * before the start of the pulse. 33 | */ 34 | extern uint32_t pulseIn(uint32_t ulPin, bool ulState, uint32_t ulTimeout = 1000000L); 35 | 36 | #ifdef __cplusplus 37 | } // extern "C" 38 | #endif // __cplusplus 39 | 40 | #endif /* _WIRING_PULSE_ */ -------------------------------------------------------------------------------- /cores/arduino/wiring_shift.c: -------------------------------------------------------------------------------- 1 | #include "wiring_private.h" 2 | 3 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 4 | uint32_t value = 0; 5 | uint8_t i; 6 | 7 | for (i = 0; i < 8; ++i) { 8 | digitalWrite(clockPin, HIGH); 9 | if (bitOrder == LSBFIRST) 10 | value |= digitalRead(dataPin) << i; 11 | else 12 | value |= digitalRead(dataPin) << (7 - i); 13 | digitalWrite(clockPin, LOW); 14 | } 15 | return value; 16 | } 17 | 18 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 19 | { 20 | uint8_t i; 21 | 22 | for (i = 0; i < 8; i++) { 23 | if (bitOrder == LSBFIRST) 24 | digitalWrite(dataPin, !!(val & (1 << i))); 25 | else 26 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 27 | 28 | digitalWrite(clockPin, HIGH); 29 | digitalWrite(clockPin, LOW); 30 | } 31 | } -------------------------------------------------------------------------------- /cores/arduino/wiring_shift.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIRING_SHIFT_ 2 | #define _WIRING_SHIFT_ 3 | 4 | #include 5 | #include "Arduino.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C"{ 9 | #endif // __cplusplus 10 | /* 11 | * \brief 12 | */ 13 | extern uint8_t shiftIn( uint8_t ulDataPin, uint8_t ulClockPin, uint8_t ulBitOrder ) ; 14 | 15 | 16 | /* 17 | * \brief 18 | */ 19 | extern void shiftOut( uint8_t ulDataPin, uint8_t ulClockPin, uint8_t ulBitOrder, uint8_t ulVal ) ; 20 | 21 | #ifdef __cplusplus 22 | } // extern "C" 23 | #endif // __cplusplus 24 | 25 | #endif /* _WIRING_SHIFT_ */ -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For ExampleLibrary 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | 14 | 15 | ####################################### 16 | # Instances (KEYWORD2) 17 | ####################################### 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | 23 | PIN_LED_GREEN LITERAL1 24 | PIN_LED_BLUE LITERAL1 25 | PIN_LED_RED LITERAL1 26 | PIN_LED LITERAL1 -------------------------------------------------------------------------------- /libraries/AXP173/AXP173.cpp: -------------------------------------------------------------------------------- 1 | #include "AXP173.h" 2 | 3 | AXP173::AXP173() 4 | { 5 | 6 | } 7 | 8 | void AXP173::begin(bool isInited) 9 | { 10 | if(!isInited){ 11 | Wire.begin((uint8_t) SDA, (uint8_t) SCL, 400000); 12 | } 13 | #if defined (ARDUINO_MAIX_AMIGO) 14 | Write1Byte(0x27, 0x20); //LDO4 - 0.8V (default 0x48 1.8V) 15 | Write1Byte(0x28, 0x0C); //LDO2/3 - LDO2 1.8V / LDO3 3.0V 16 | #else //ARDUINO_MAIX_CUBE 17 | Write1Byte(0x46, 0xFF); //Clear interupts 18 | Write1Byte(0x33, 0xC1); //Set Bat Charging Voltage to 4V2, Current to 190mA 19 | Write1Byte(0x10, (Read8bit(0x10) & 0xFC)); //EXTEN & DC-DC2 control 20 | #endif 21 | } 22 | 23 | void AXP173::Write1Byte( uint8_t Addr , uint8_t Data ) 24 | { 25 | Wire.beginTransmission(AXP_ADDR); 26 | Wire.write(Addr); 27 | Wire.write(Data); 28 | Wire.endTransmission(); 29 | } 30 | 31 | uint8_t AXP173::Read8bit( uint8_t Addr ) 32 | { 33 | Wire.beginTransmission(AXP_ADDR); 34 | Wire.write(Addr); 35 | Wire.endTransmission(); 36 | Wire.requestFrom(AXP_ADDR, 1); 37 | return Wire.read(); 38 | } 39 | 40 | uint16_t AXP173::Read12Bit( uint8_t Addr) 41 | { 42 | uint16_t Data = 0; 43 | uint8_t buf[2]; 44 | ReadBuff(Addr,2,buf); 45 | Data = ((buf[0] << 4) + buf[1]); 46 | return Data; 47 | } 48 | 49 | uint16_t AXP173::Read13Bit( uint8_t Addr) 50 | { 51 | uint16_t Data = 0; 52 | uint8_t buf[2]; 53 | ReadBuff(Addr,2,buf); 54 | Data = ((buf[0] << 5) + buf[1]); 55 | return Data; 56 | } 57 | 58 | uint16_t AXP173::Read16bit( uint8_t Addr ) 59 | { 60 | uint16_t ReData = 0; 61 | Wire.beginTransmission(AXP_ADDR); 62 | Wire.write(Addr); 63 | Wire.endTransmission(); 64 | Wire.requestFrom(AXP_ADDR, 2); 65 | for( int i = 0 ; i < 2 ; i++ ) 66 | { 67 | ReData <<= 8; 68 | ReData |= Wire.read(); 69 | } 70 | return ReData; 71 | } 72 | 73 | uint32_t AXP173::Read24bit( uint8_t Addr ) 74 | { 75 | uint32_t ReData = 0; 76 | Wire.beginTransmission(AXP_ADDR); 77 | Wire.write(Addr); 78 | Wire.endTransmission(); 79 | Wire.requestFrom(AXP_ADDR, 3); 80 | for( int i = 0 ; i < 3 ; i++ ) 81 | { 82 | ReData <<= 8; 83 | ReData |= Wire.read(); 84 | } 85 | return ReData; 86 | } 87 | 88 | uint32_t AXP173::Read32bit( uint8_t Addr ) 89 | { 90 | uint32_t ReData = 0; 91 | Wire.beginTransmission(AXP_ADDR); 92 | Wire.write(Addr); 93 | Wire.endTransmission(); 94 | Wire.requestFrom(AXP_ADDR, 4); 95 | for( int i = 0 ; i < 4 ; i++ ) 96 | { 97 | ReData <<= 8; 98 | ReData |= Wire.read(); 99 | } 100 | return ReData; 101 | } 102 | 103 | void AXP173::ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff ) 104 | { 105 | Wire.beginTransmission(AXP_ADDR); 106 | Wire.write(Addr); 107 | Wire.endTransmission(); 108 | Wire.requestFrom(AXP_ADDR, (int)Size); 109 | for (int i = 0; i < Size; i++) 110 | { 111 | *( Buff + i ) = Wire.read(); 112 | } 113 | } 114 | 115 | 116 | -------------------------------------------------------------------------------- /libraries/AXP173/AXP173.h: -------------------------------------------------------------------------------- 1 | #ifndef __AXP173_H__ 2 | #define __AXP173_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define SLEEP_MSEC(us) (((uint64_t)us) * 1000L) 8 | #define SLEEP_SEC(us) (((uint64_t)us) * 1000000L) 9 | #define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L) 10 | #define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L) 11 | 12 | #define AXP_ADDR 0X34 13 | 14 | #define CURRENT_100MA (0b0000) 15 | #define CURRENT_190MA (0b0001) 16 | #define CURRENT_280MA (0b0010) 17 | #define CURRENT_360MA (0b0011) 18 | #define CURRENT_450MA (0b0100) 19 | #define CURRENT_550MA (0b0101) 20 | #define CURRENT_630MA (0b0110) 21 | #define CURRENT_700MA (0b0111) 22 | 23 | class AXP173 { 24 | public: 25 | 26 | AXP173(); 27 | /** 28 | * DCDC1: 3V3 Main rail. When not set the stick shuts down 29 | * DCDC2: 0V9 K210 VCore 30 | * DCDC3: 1V8 Use unknown 31 | * LDO1: Don't set GPIO1 as LDO 32 | * LDO2: 2V8 Display backlight 33 | * LDO3: 1V5 Display Control 34 | * GPIO0: LDO1 LCD_BL 35 | * EXTEN: 36 | */ 37 | void begin(bool isInited = false); 38 | 39 | 40 | public: 41 | 42 | private: 43 | void Write1Byte( uint8_t Addr , uint8_t Data ); 44 | uint8_t Read8bit( uint8_t Addr ); 45 | uint16_t Read12Bit( uint8_t Addr); 46 | uint16_t Read13Bit( uint8_t Addr); 47 | uint16_t Read16bit( uint8_t Addr ); 48 | uint32_t Read24bit( uint8_t Addr ); 49 | uint32_t Read32bit( uint8_t Addr ); 50 | void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff ); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libraries/AXP192/AXP192.h: -------------------------------------------------------------------------------- 1 | #ifndef __AXP192_H__ 2 | #define __AXP192_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define SLEEP_MSEC(us) (((uint64_t)us) * 1000L) 8 | #define SLEEP_SEC(us) (((uint64_t)us) * 1000000L) 9 | #define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L) 10 | #define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L) 11 | 12 | #define AXP_ADDR 0X34 13 | 14 | #define CURRENT_100MA (0b0000) 15 | #define CURRENT_190MA (0b0001) 16 | #define CURRENT_280MA (0b0010) 17 | #define CURRENT_360MA (0b0011) 18 | #define CURRENT_450MA (0b0100) 19 | #define CURRENT_550MA (0b0101) 20 | #define CURRENT_630MA (0b0110) 21 | #define CURRENT_700MA (0b0111) 22 | 23 | class AXP192 { 24 | public: 25 | 26 | AXP192(); 27 | /** 28 | * DCDC1: 3V3 Main rail. When not set the stick shuts down 29 | * DCDC2: 0V9 K210 VCore 30 | * DCDC3: 1V8 Use unknown 31 | * LDO1: Don't set GPIO1 as LDO 32 | * LDO2: 2V8 Display backlight 33 | * LDO3: 1V5 Display Control 34 | * GPIO0: LDO1 LCD_BL 35 | * EXTEN: 36 | */ 37 | void begin(bool isInited = false); 38 | void ScreenBreath(uint8_t brightness); 39 | bool GetBatState(); 40 | 41 | uint8_t GetInputPowerStatus(); 42 | uint8_t GetBatteryChargingStatus(); 43 | 44 | void EnableCoulombcounter(void); 45 | void DisableCoulombcounter(void); 46 | void StopCoulombcounter(void); 47 | void ClearCoulombcounter(void); 48 | uint32_t GetCoulombchargeData(void); // Raw Data for Charge 49 | uint32_t GetCoulombdischargeData(void); // Raw Data for Discharge 50 | float GetCoulombData(void); // total in - total out and calc 51 | uint8_t GetBtnPress(void); 52 | void SetSleep(void); 53 | uint8_t GetWarningLeve(void); 54 | 55 | public: 56 | // void SetChargeVoltage( uint8_t ); 57 | void SetChargeCurrent( uint8_t ); 58 | float GetBatVoltage(); 59 | float GetBatCurrent(); 60 | float GetVinVoltage(); 61 | float GetVinCurrent(); 62 | float GetVBusVoltage(); 63 | float GetVBusCurrent(); 64 | float GetTempInAXP192(); 65 | float GetBatPower(); 66 | float GetBatChargeCurrent(); 67 | float GetAPSVoltage(); 68 | float GetBatCoulombInput(); 69 | float GetBatCoulombOut(); 70 | uint8_t GetWarningLevel(void); 71 | void SetLDO2( bool State ); // Can turn LCD Backlight OFF for power saving 72 | void SetLDO3( bool State ); 73 | void SetAdcState(bool State); 74 | 75 | // -- Power Off 76 | void PowerOff(); 77 | 78 | // Power Maintained Storage 79 | void Read6BytesStorage( uint8_t *bufPtr ); 80 | void Write6BytesStorage( uint8_t *bufPtr ); 81 | 82 | 83 | private: 84 | void Write1Byte( uint8_t Addr , uint8_t Data ); 85 | uint8_t Read8bit( uint8_t Addr ); 86 | uint16_t Read12Bit( uint8_t Addr); 87 | uint16_t Read13Bit( uint8_t Addr); 88 | uint16_t Read16bit( uint8_t Addr ); 89 | uint32_t Read24bit( uint8_t Addr ); 90 | uint32_t Read32bit( uint8_t Addr ); 91 | void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff ); 92 | }; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /libraries/Camera/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | framesize_t KEYWORD1 10 | pixformat_t KEYWORD1 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | begin KEYWORD2 16 | end KEYWORD2 17 | run KEYWORD2 18 | id KEYWORD2 19 | snapshot KEYWORD2 20 | getRGB565 KEYWORD2 21 | getRGB888 KEYWORD2 22 | setRotation KEYWORD2 23 | setInver KEYWORD2 24 | width KEYWORD2 25 | height KEYWORD2 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | 31 | PIXFORMAT_RGB565 LITERAL1 32 | FRAMESIZE_QQVGA LITERAL1 33 | FRAMESIZE_QVGA LITERAL1 34 | FRAMESIZE_VGA LITERAL1 35 | 36 | 37 | -------------------------------------------------------------------------------- /libraries/Camera/library.properties: -------------------------------------------------------------------------------- 1 | name=Camera 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=Camera interface 6 | paragraph=Camera interface 7 | category=Sensors 8 | url= 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Camera/src/Camera.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Camera.h" 3 | 4 | 5 | 6 | static const int resolution[][2] = { 7 | {0, 0 }, 8 | // C/SIF Resolutions 9 | {88, 72 }, /* QQCIF */ 10 | {176, 144 }, /* QCIF */ 11 | {352, 288 }, /* CIF */ 12 | {88, 60 }, /* QQSIF */ 13 | {176, 120 }, /* QSIF */ 14 | {352, 240 }, /* SIF */ 15 | // VGA Resolutions 16 | {40, 30 }, /* QQQQVGA */ 17 | {80, 60 }, /* QQQVGA */ 18 | {160, 120 }, /* QQVGA */ 19 | {320, 240 }, /* QVGA */ 20 | {640, 480 }, /* VGA */ 21 | {60, 40 }, /* HQQQVGA */ 22 | {120, 80 }, /* HQQVGA */ 23 | {240, 160 }, /* HQVGA */ 24 | // FFT Resolutions 25 | {64, 32 }, /* 64x32 */ 26 | {64, 64 }, /* 64x64 */ 27 | {128, 64 }, /* 128x64 */ 28 | {128, 128 }, /* 128x64 */ 29 | // Other 30 | {128, 160 }, /* LCD */ 31 | {128, 160 }, /* QQVGA2 */ 32 | {720, 480 }, /* WVGA */ 33 | {752, 480 }, /* WVGA2 */ 34 | {800, 600 }, /* SVGA */ 35 | {1280, 1024}, /* SXGA */ 36 | {1600, 1200}, /* UXGA */ 37 | }; 38 | 39 | Camera::Camera(framesize_t frameSize, pixformat_t pixFormat) 40 | { 41 | _frameSize = frameSize; 42 | _pixFormat = pixFormat; 43 | _width = resolution[frameSize][0]; 44 | _height = resolution[frameSize][1]; 45 | } 46 | 47 | Camera::Camera(int16_t width, uint16_t height, pixformat_t pixFormat) 48 | { 49 | _frameSize = FRAMESIZE_CUSTOM; 50 | _pixFormat = pixFormat; 51 | _width = width; 52 | _height = height; 53 | } 54 | 55 | Camera::~Camera() 56 | { 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /libraries/Camera/src/Camera.h: -------------------------------------------------------------------------------- 1 | #ifndef __CAMERA_H 2 | #define __CAMERA_H 3 | 4 | #include 5 | #include 6 | 7 | typedef enum { 8 | PIXFORMAT_INVALID = 0, 9 | PIXFORMAT_BAYER, // RAW 10 | PIXFORMAT_RGB565, // RGB565 11 | PIXFORMAT_YUV422, // YUV422 12 | PIXFORMAT_GRAYSCALE, // GRAYSCALE 13 | PIXFORMAT_JPEG, // JPEG/COMPRESSED 14 | } pixformat_t; 15 | 16 | typedef enum { 17 | FRAMESIZE_INVALID = 0, 18 | // C/SIF Resolutions 19 | FRAMESIZE_QQCIF, // 88x72 20 | FRAMESIZE_QCIF, // 176x144 21 | FRAMESIZE_CIF, // 352x288 22 | FRAMESIZE_QQSIF, // 88x60 23 | FRAMESIZE_QSIF, // 176x120 24 | FRAMESIZE_SIF, // 352x240 25 | // VGA Resolutions 26 | FRAMESIZE_QQQQVGA, // 40x30 27 | FRAMESIZE_QQQVGA, // 80x60 28 | FRAMESIZE_QQVGA, // 160x120 29 | FRAMESIZE_QVGA, // 320x240 30 | FRAMESIZE_VGA, // 640x480 31 | FRAMESIZE_HQQQVGA, // 60x40 32 | FRAMESIZE_HQQVGA, // 120x80 33 | FRAMESIZE_HQVGA, // 240x160 34 | // FFT Resolutions 35 | FRAMESIZE_64X32, // 64x32 36 | FRAMESIZE_64X64, // 64x64 37 | FRAMESIZE_128X64, // 128x64 38 | FRAMESIZE_128X128, // 128x128 39 | // Other 40 | FRAMESIZE_LCD, // 128x160 41 | FRAMESIZE_QQVGA2, // 128x160 42 | FRAMESIZE_WVGA, // 720x480 43 | FRAMESIZE_WVGA2, // 752x480 44 | FRAMESIZE_SVGA, // 800x600 45 | FRAMESIZE_SXGA, // 1280x1024 46 | FRAMESIZE_UXGA, // 1600x1200 47 | FRAMESIZE_CUSTOM, 48 | } framesize_t; 49 | 50 | 51 | class Camera{ 52 | 53 | public: 54 | Camera(framesize_t frameSize, pixformat_t pixFormat); 55 | Camera(int16_t width, uint16_t height, pixformat_t pixFormat); 56 | ~Camera(); 57 | virtual bool begin( ) = 0; 58 | virtual void end() = 0; 59 | // virtual bool reset() = 0; 60 | // virtual bool setPixFormat(int pixFormat) = 0; 61 | // virtual bool setFrameSize(int frameSize) = 0; 62 | virtual bool run(bool run) = 0; 63 | virtual int id() = 0; 64 | /** 65 | * @return pixels 66 | * If pixels format is RGB565: return RGB565 pixels with every uint16_t one pixel, e.g. RED: 0xF800 67 | */ 68 | virtual uint8_t* snapshot() = 0; 69 | /** 70 | * @return pixels with RGB565 format, every uint16_t one pixel, e.g. RED: 0xF800, so two pixels: {0xF800, 0xF800} 71 | */ 72 | virtual uint16_t* getRGB565(){ return nullptr; }; 73 | /** 74 | * 75 | * @return pixels with RGB888 format, for n pixels: {{R0,R1,...,Rn-1,},{G0,G1,...,Gn-1},{B0,B1,...,Bn-1}} 76 | * e.g. two RED pixel: {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00} 77 | */ 78 | virtual uint8_t* getRGB888(){ return nullptr; }; 79 | virtual void setRotation(uint8_t rotation) = 0; 80 | virtual void setInvert(bool invert) = 0; 81 | virtual void flip(bool horiz, bool vert); 82 | 83 | 84 | virtual int width(){ return _width; } 85 | virtual int height(){ return _height; } 86 | 87 | protected: 88 | pixformat_t _pixFormat; 89 | framesize_t _frameSize; 90 | int _width; 91 | int _height; 92 | }; 93 | 94 | 95 | 96 | #endif 97 | 98 | -------------------------------------------------------------------------------- /libraries/MSA300/examples/msa_basic/msa_basic.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // This is the length of the string that will be created 5 | // included minus and decimal point 6 | const signed char formattedStringLength = 11; 7 | 8 | // The number of digits after the deimal point to print 9 | const unsigned char numVarsAfterDecimal = 6; 10 | 11 | acc_t data; 12 | MSA300 msa; 13 | 14 | static char outstr[formattedStringLength]; 15 | 16 | char * formatValue(float value) 17 | { 18 | dtostrf(value, formattedStringLength, numVarsAfterDecimal, outstr); 19 | return outstr; 20 | } 21 | 22 | void setup() 23 | { 24 | Serial.begin(9600); 25 | Wire.begin(); 26 | msa.begin(); 27 | } 28 | 29 | void loop() 30 | { 31 | data = msa.getAcceleration(); 32 | 33 | Serial.printf("Xa:%s ", formatValue(data.x)); 34 | Serial.printf("Ya:%s ", formatValue(data.y)); 35 | Serial.printf("Za:%s", formatValue(data.z)); 36 | Serial.println(); 37 | 38 | delay(100); 39 | } 40 | -------------------------------------------------------------------------------- /libraries/MSA300/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | acc_t KEYWORD1 9 | orient_t KEYWORD1 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | 14 | begin KEYWORD2 15 | getAcceleration KEYWORD2 16 | checkOrientation KEYWORD2 17 | 18 | 19 | ####################################### 20 | # Instances (KEYWORD2) 21 | ####################################### 22 | 23 | MSA300 KEYWORD2 24 | 25 | ####################################### 26 | # Constants (LITERAL1) 27 | ####################################### 28 | 29 | -------------------------------------------------------------------------------- /libraries/MSA300/library.properties: -------------------------------------------------------------------------------- 1 | name=MSA300 2 | version=1.0.0 3 | author=Bigbits 4 | maintainer=Bigbits 5 | sentence= Arduino library for the MSA300 digital 14-bit accelerometer built into the Sipeed Maix Go. 6 | paragraph=Arduino library for the MSA300 digital 14-bit accelerometer built into the Sipeed Maix Go. 7 | category=Sensors 8 | url=http://www.sipeed.com 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/examples/mobilenet_v1/MBNet_1000.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MBNet_1000.h 3 | * @brief Detect object type 4 | * @author Neucrack@sipeed.com 5 | */ 6 | 7 | 8 | #ifndef __MBNET_1000_H 9 | #define __MBNET_1000_H 10 | 11 | #include "Sipeed_OV2640.h" 12 | #include "Sipeed_ST7789.h" 13 | #include 14 | #include 15 | 16 | #define KMODEL_SIZE (4220 * 1024) 17 | #define STATISTICS_NUM 5 18 | 19 | typedef struct{ 20 | const char* name; 21 | float sum; 22 | bool updated; 23 | } statistics_t; 24 | 25 | 26 | class MBNet_1000{ 27 | 28 | public: 29 | MBNet_1000(KPUClass& kpu, Sipeed_ST7789& lcd, Sipeed_OV2640& camera); 30 | ~MBNet_1000(); 31 | int begin(const char* kmodel_name); 32 | int detect(); 33 | void show(); 34 | const char** _names; 35 | 36 | private: 37 | KPUClass& _kpu; 38 | Sipeed_ST7789& _lcd; 39 | Sipeed_OV2640& _camera; 40 | uint8_t* _model; 41 | size_t _count; 42 | statistics_t _statistics[STATISTICS_NUM]; 43 | float* _result; 44 | uint16_t _index[1000]; 45 | 46 | void label_init(); 47 | void label_get(uint16_t index, float* prob, const char** name); 48 | void label_sort(void); 49 | }; 50 | 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/examples/mobilenet_v1/mobilenet_v1.ino: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * 5 | * Download model here: 6 | * http://dl.sipeed.com/MAIX/MaixPy/model/mobilenet_0x300000.kfpkg 7 | * Unpack it(zip format), get m.kmodel, change name to a short name "m" for example, 8 | * put it in SD card at root path 9 | * 10 | * 11 | * 12 | */ 13 | 14 | 15 | #include 16 | #include 17 | #include "MBNet_1000.h" 18 | #include "Maix_KPU.h" 19 | 20 | SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD 21 | Sipeed_ST7789 lcd(320, 240, spi_); 22 | Sipeed_OV2640 camera(224, 224, PIXFORMAT_RGB565); 23 | KPUClass KPU; 24 | MBNet_1000 mbnet(KPU, lcd, camera); 25 | 26 | const char* kmodel_name = "m"; 27 | 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | while (!Serial) { 33 | ; // wait for serial port to connect. Needed for native USB port only 34 | } 35 | 36 | Serial.println("init mobile net, load kmodel from SD card, it may takes a long time"); 37 | if( mbnet.begin(kmodel_name) != 0) 38 | { 39 | Serial.println("mobile net init fail"); 40 | while(1); 41 | } 42 | 43 | } 44 | 45 | void loop() 46 | { 47 | if(mbnet.detect() != 0) 48 | { 49 | Serial.println("detect object fail"); 50 | return; 51 | } 52 | mbnet.show(); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/examples/mobilenet_v1/names.h: -------------------------------------------------------------------------------- 1 | #ifndef __MBNET_NAMES_H 2 | #define __MBNET_NAMES_H 3 | 4 | extern const char* mbnet_label_name[]; 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SD 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | KPUClass KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | forward KEYWORD2 17 | isForwardOk KEYWORD2 18 | getResult KEYWORD2 19 | 20 | ####################################### 21 | # Constants (LITERAL1) 22 | ####################################### 23 | KPU_ERROR_BUSY LITERAL1 24 | KPU_ERROR_BAD_MODEL LITERAL1 25 | KPU_ERROR_MODEL_VERSION LITERAL1 26 | KPU_ERROR_NONE LITERAL1 27 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/library.properties: -------------------------------------------------------------------------------- 1 | name=Maix_KPU 2 | version=1.0.0 3 | author= Neucrack Sipeed 4 | maintainer=Sipeed 5 | sentence=KPU API of k210 6 | paragraph=KPU API of k210 7 | category=Other 8 | url= 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/src/Maix_KPU.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "Maix_KPU.h" 4 | #include "sysctl.h" 5 | 6 | 7 | #define AI_STATUS_IDLE 0 8 | #define AI_STATUS_BUSY 1 9 | #define AI_STATUS_OK 2 10 | 11 | 12 | static volatile uint32_t g_ai_done_flag = AI_STATUS_IDLE; 13 | 14 | KPUClass::KPUClass() 15 | :_flagGotResult(true) 16 | { 17 | 18 | } 19 | 20 | KPUClass::~KPUClass() 21 | { 22 | end(); 23 | } 24 | 25 | int KPUClass::begin(uint8_t* model) 26 | { 27 | sysctl_clock_enable(SYSCTL_CLOCK_AI); 28 | if (kpu_load_kmodel(&_task, model) != 0) 29 | return KPU_ERROR_BAD_MODEL; 30 | return KPU_ERROR_NONE; 31 | } 32 | 33 | void KPUClass::end() 34 | { 35 | sysctl_clock_disable(SYSCTL_CLOCK_AI); 36 | } 37 | 38 | extern "C" { 39 | static void ai_done(void* userdata) 40 | { 41 | bool* user_used = (bool*)userdata; 42 | g_ai_done_flag = AI_STATUS_OK; 43 | *user_used = false; 44 | } 45 | } 46 | 47 | int KPUClass::forward(uint8_t* imgSrc, uint8_t dmaCh) 48 | { 49 | if(g_ai_done_flag == AI_STATUS_BUSY) 50 | return KPU_ERROR_BUSY; 51 | g_ai_done_flag = AI_STATUS_BUSY; 52 | if (kpu_run_kmodel(&_task, imgSrc, (dmac_channel_number_t)dmaCh, ai_done, (void*)&_flagGotResult) != 0) 53 | { 54 | g_ai_done_flag = AI_STATUS_IDLE; 55 | return KPU_ERROR_BAD_MODEL; 56 | } 57 | return KPU_ERROR_NONE; 58 | } 59 | 60 | bool KPUClass::isForwardOk() 61 | { 62 | return g_ai_done_flag==AI_STATUS_OK; 63 | } 64 | 65 | int KPUClass::getResult(uint8_t**data, size_t* count, uint32_t startIndex ) 66 | { 67 | _flagGotResult = true; 68 | kpu_get_output(&_task, startIndex, data, count); 69 | return KPU_ERROR_NONE; 70 | } 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /libraries/Maix_KPU/src/Maix_KPU.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __MOBILENET_V1_H 3 | #define __MOBILENET_V1_H 4 | 5 | extern "C" { 6 | #include "kpu.h" 7 | } 8 | #include "stdint.h" 9 | #include "stdbool.h" 10 | 11 | 12 | typedef enum{ 13 | KPU_ERROR_BUSY = -3, 14 | KPU_ERROR_BAD_MODEL = -2, 15 | KPU_ERROR_MODEL_VERSION = -1, 16 | KPU_ERROR_NONE = 0, 17 | } KPU_Error_t; 18 | 19 | 20 | class KPUClass{ 21 | 22 | public: 23 | KPUClass(); 24 | ~KPUClass(); 25 | int begin(uint8_t* model); 26 | void end(); 27 | /** 28 | * @param imgSrc RGB888 image source 29 | * @param dmaCh [0,5) 30 | */ 31 | int forward(uint8_t* imgSrc, uint8_t dmaCh=0); 32 | bool isForwardOk(); 33 | int getResult(uint8_t**data, size_t* count, uint32_t startIndex = 0); 34 | 35 | 36 | private: 37 | kpu_model_context_t _task; 38 | bool _flagGotResult; 39 | 40 | 41 | }; 42 | 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/examples/get_voice_model/get_voice_model.ino: -------------------------------------------------------------------------------- 1 | #include "Maix_Speech_Recognition.h" 2 | 3 | SpeechRecognizer rec; 4 | 5 | void setup() 6 | { 7 | rec.begin(); 8 | Serial.begin(115200); 9 | Serial.println("start rec..."); 10 | if( rec.record(0, 0) == 0) //keyword_num, model_num 11 | { 12 | rec.print_model(0, 0); 13 | } 14 | else 15 | Serial.println("rec failed"); 16 | } 17 | 18 | void loop() 19 | { 20 | } -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/examples/voice_control_led_en/voice_control_led_en.ino: -------------------------------------------------------------------------------- 1 | #include "Maix_Speech_Recognition.h" 2 | #include "voice_model.h" 3 | 4 | SpeechRecognizer rec; 5 | 6 | void setup() 7 | { 8 | pinMode(LED_RED, OUTPUT); 9 | pinMode(LED_BLUE, OUTPUT); 10 | pinMode(LED_GREEN, OUTPUT); 11 | rec.begin(); 12 | Serial.begin(115200); 13 | Serial.println("init model..."); 14 | rec.addVoiceModel(0, 0, red_0, fram_num_red_0); 15 | rec.addVoiceModel(0, 1, red_1, fram_num_red_1); 16 | rec.addVoiceModel(0, 2, red_2, fram_num_red_2); 17 | rec.addVoiceModel(0, 3, red_3, fram_num_red_3); 18 | rec.addVoiceModel(1, 0, green_0, fram_num_green_0); 19 | rec.addVoiceModel(1, 1, green_1, fram_num_green_1); 20 | rec.addVoiceModel(1, 2, green_2, fram_num_green_2); 21 | rec.addVoiceModel(1, 3, green_3, fram_num_green_3); 22 | rec.addVoiceModel(2, 0, blue_0, fram_num_blue_0); 23 | rec.addVoiceModel(2, 1, blue_1, fram_num_blue_1); 24 | rec.addVoiceModel(2, 2, blue_2, fram_num_blue_2); 25 | rec.addVoiceModel(2, 3, blue_3, fram_num_blue_3); 26 | rec.addVoiceModel(3, 0, turnoff_0, fram_num_turnoff_0); 27 | rec.addVoiceModel(3, 1, turnoff_1, fram_num_turnoff_1); 28 | rec.addVoiceModel(3, 2, turnoff_2, fram_num_turnoff_2); 29 | rec.addVoiceModel(3, 3, turnoff_3, fram_num_turnoff_3); 30 | Serial.println("init model ok!"); 31 | } 32 | void loop() 33 | { 34 | int res; 35 | res = rec.recognize(); 36 | Serial.printf("res : %d ", res); 37 | if (res > 0){ 38 | switch (res) 39 | { 40 | case 1: 41 | digitalWrite(LED_RED, LOW); //power on red led 42 | digitalWrite(LED_GREEN, HIGH); 43 | digitalWrite(LED_BLUE, HIGH); 44 | Serial.println("rec : red "); 45 | break; 46 | case 2: 47 | digitalWrite(LED_GREEN, LOW); //power on green led 48 | digitalWrite(LED_RED, HIGH); 49 | digitalWrite(LED_BLUE, HIGH); 50 | Serial.println("rec : green "); 51 | break; 52 | case 3: 53 | digitalWrite(LED_BLUE, LOW); //power on blue led 54 | digitalWrite(LED_RED, HIGH); 55 | digitalWrite(LED_GREEN, HIGH); 56 | Serial.println("rec : blue "); 57 | break; 58 | case 4: 59 | digitalWrite(LED_RED, HIGH); 60 | digitalWrite(LED_GREEN, HIGH); 61 | digitalWrite(LED_BLUE, HIGH); //power off all leds 62 | Serial.println("rec : turnoff "); 63 | default: 64 | break; 65 | } 66 | }else 67 | { 68 | Serial.println("recognize failed."); 69 | } 70 | delay(1000); 71 | } -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/examples/voice_control_led_zh/voice_control_led_zh.ino: -------------------------------------------------------------------------------- 1 | #include "Maix_Speech_Recognition.h" 2 | #include "voice_model.h" 3 | 4 | SpeechRecognizer rec; 5 | 6 | void setup() 7 | { 8 | pinMode(LED_RED, OUTPUT); 9 | pinMode(LED_BLUE, OUTPUT); 10 | pinMode(LED_GREEN, OUTPUT); 11 | rec.begin(); 12 | Serial.begin(115200); 13 | Serial.println("init model..."); 14 | rec.addVoiceModel(0, 0, hongse_0, fram_num_hongse_0); //36 15 | rec.addVoiceModel(0, 1, hongse_1, fram_num_hongse_1); //20 16 | rec.addVoiceModel(0, 2, hongse_2, fram_num_hongse_2); //23 17 | rec.addVoiceModel(0, 3, hongse_3, fram_num_hongse_3); //21 18 | rec.addVoiceModel(1, 0, lvse_0, fram_num_lvse_0); //20 19 | rec.addVoiceModel(1, 1, lvse_1, fram_num_lvse_1); //37 20 | rec.addVoiceModel(1, 2, lvse_2, fram_num_lvse_2); //19 21 | rec.addVoiceModel(1, 3, lvse_3, fram_num_lvse_3); //26 22 | rec.addVoiceModel(2, 0, lanse_0, fram_num_lanse_0); //19 23 | rec.addVoiceModel(2, 1, lanse_1, fram_num_lanse_1); //21 24 | rec.addVoiceModel(2, 2, lanse_2, fram_num_lanse_2); //28 25 | rec.addVoiceModel(2, 3, lanse_3, fram_num_lanse_3); //22 26 | rec.addVoiceModel(3, 0, guandeng_0, fram_num_guandeng_0); //26 27 | rec.addVoiceModel(3, 1, guandeng_1, fram_num_guandeng_1); //29 28 | rec.addVoiceModel(3, 2, guandeng_2, fram_num_guandeng_2); //33 29 | rec.addVoiceModel(3, 3, guandeng_3, fram_num_guandeng_3); //29 30 | Serial.println("init model ok!"); 31 | } 32 | void loop() 33 | { 34 | int res; 35 | res = rec.recognize(); 36 | Serial.printf("res : %d ", res); 37 | if (res > 0){ 38 | switch (res) 39 | { 40 | case 1: 41 | digitalWrite(LED_RED, LOW); //power on red led 42 | digitalWrite(LED_GREEN, HIGH); 43 | digitalWrite(LED_BLUE, HIGH); 44 | Serial.println("rec : hongse "); 45 | break; 46 | case 2: 47 | digitalWrite(LED_GREEN, LOW); //power on green led 48 | digitalWrite(LED_RED, HIGH); 49 | digitalWrite(LED_BLUE, HIGH); 50 | Serial.println("rec : lvse "); 51 | break; 52 | case 3: 53 | digitalWrite(LED_BLUE, LOW); //power on blue led 54 | digitalWrite(LED_RED, HIGH); 55 | digitalWrite(LED_GREEN, HIGH); 56 | Serial.println("rec : lanse "); 57 | break; 58 | case 4: 59 | digitalWrite(LED_RED, HIGH); 60 | digitalWrite(LED_GREEN, HIGH); 61 | digitalWrite(LED_BLUE, HIGH); //power off all leds 62 | Serial.println("rec : guandeng "); 63 | default: 64 | break; 65 | } 66 | }else 67 | { 68 | Serial.println("recognize failed."); 69 | } 70 | delay(1000); 71 | } -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/library.properties: -------------------------------------------------------------------------------- 1 | name=Maix_Speech_Recognition 2 | version=1.0 3 | author=BigBits 4 | maintainer=BigBits 5 | sentence=Maix Boards Speech Recognition Lib 6 | paragraph=Maix Boards Speech Recognition Lib 7 | category=Uncategorized 8 | url= 9 | architectures=k210 -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/Maix_Speech_Recognition.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIX_SPEECH_RECOGNITION_H 2 | #define __MAIX_SPEECH_RECOGNITION_H 3 | 4 | #include "Arduino.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "sysctl.h" 12 | #include "plic.h" 13 | #include "uarths.h" 14 | #include "util/g_def.h" 15 | #include "i2s.h" 16 | 17 | #include "util/VAD.h" 18 | #include "util/MFCC.h" 19 | #include "util/DTW.h" 20 | #include "util/flash.h" 21 | #include "util/ADC.h" 22 | 23 | 24 | class SpeechRecognizer{ 25 | public: 26 | SpeechRecognizer(); 27 | ~SpeechRecognizer(); 28 | int begin(); //初始化i2s 29 | int record(uint8_t keyword_num, uint8_t model_num); //记录关键词 30 | int recognize(); //识别,返回关键词号 31 | int addVoiceModel(uint8_t keyword_num, uint8_t model_num, const int16_t *voice_model, uint16_t frame_num); 32 | int print_model(uint8_t keyword_num, uint8_t model_num); 33 | private: 34 | uint8_t save_mdl(uint16_t *v_dat, uint32_t addr); 35 | uint8_t spch_recg(uint16_t *v_dat, uint32_t *mtch_dis); 36 | 37 | private: 38 | uint8_t comm; //关键词号 39 | 40 | 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/ADC.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADC_H 2 | #define _ADC_H 3 | 4 | 5 | #define fs 8000 //ADC采样率 Hz 8000 6 | #define voice_len 3000 //录音时间长度 单位ms 7 | #define VcBuf_Len ((fs/1000)*voice_len) //语音缓存区长度 单位点数 每个采样点16位 8 | #define atap_len_t 300 //背景噪音自适应时间长度 ms 9 | #define atap_len ((fs/1000)*atap_len_t) //背景噪音自适应长度 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | void ADC_DMA_Init(void); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/DTW.h: -------------------------------------------------------------------------------- 1 | #ifndef _DTW_H 2 | #define _DTW_H 3 | #include "g_def.h" 4 | 5 | #define dis_err 0xFFFFFFFF 6 | #define dis_max 0xFFFFFFFF 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | 13 | u32 dtw(v_ftr_tag *ftr_in, v_ftr_tag *frt_mdl); 14 | u32 get_mdl(v_ftr_tag *ftr_in1, v_ftr_tag *ftr_in2, v_ftr_tag *ftr_mdl); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/FIR.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "FIR.h" 3 | 4 | const double Gains[39] = { 5 | -0.01152483856464, -0.0225638929287, -0.002300804134165, 0.01259363093284, 6 | -0.0003113695305127, -0.01591961043518, 0.005297252625722, 0.01846679452201, 7 | -0.01074864266549, -0.02187510941784, 0.0192688121099, 0.02485021814652, 8 | -0.03198920030056, -0.02754770718169, 0.05351978821001, 0.0296026126381, 9 | -0.09977798297944, -0.03089664322888, 0.3161729116138, 0.5313543998522, 10 | 0.3161729116138, -0.03089664322888, -0.09977798297944, 0.0296026126381, 11 | 0.05351978821001, -0.02754770718169, -0.03198920030056, 0.02485021814652, 12 | 0.0192688121099, -0.02187510941784, -0.01074864266549, 0.01846679452201, 13 | 0.005297252625722, -0.01591961043518, -0.0003113695305127, 0.01259363093284, 14 | -0.002300804134165, -0.0225638929287, -0.01152483856464 15 | }; 16 | #define ORDER 38 //阶数 17 | 18 | double Buffer[ORDER + 1]; //采样历史数据 19 | 20 | double Fir(double Input) 21 | { 22 | double Output = 0.0; //数据输出 23 | int Index; //下标索引 24 | 25 | //采样数据移位 26 | for (Index = ORDER; Index > 0; Index--) 27 | Buffer[Index] = Buffer[Index-1]; 28 | 29 | Buffer[0] = Input; 30 | 31 | //计算输出 32 | for (Index = 0; Index < ORDER+1; Index++) 33 | Output += Gains[Index]*Buffer[Index]; 34 | 35 | return Output; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/FIR.h: -------------------------------------------------------------------------------- 1 | #ifndef _FIR_H_ 2 | #define _FIR_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | double Fir(double Input); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/MFCC.h: -------------------------------------------------------------------------------- 1 | #ifndef _MFCC_H 2 | #define _MFCC_H 3 | #include "VAD.h" 4 | #include "g_def.h" 5 | 6 | #define hp_ratio(x) (x*95/100)//预加重系数 0.95 7 | #define mfcc_fft_point 512 //FFT点数 8 | #define frq_max (mfcc_fft_point/2) //最大频率 9 | #define hamm_top 10000 //汉明窗最大值 10 | #define tri_top 1000 //三角滤波器顶点值 11 | #define tri_num 24 //三角滤波器个数 12 | //#define tri_num 17 //三角滤波器个数 13 | #define mfcc_num 12 //MFCC阶数 14 | 15 | #define vv_tim_max 2200 //单段有效语音最长时间 ms 16 | #define vv_frm_max ((vv_tim_max-frame_time)/(frame_time-frame_mov_t)+1) //单段有效语音最长帧数 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | //#pragma pack(4) 24 | typedef struct { 25 | u16 save_sign; //存储标记 用于判断flash中特征模板是否有效 26 | u16 frm_num; //帧数 27 | // u8 word_num; 28 | s16 mfcc_dat[vv_frm_max*mfcc_num]; //MFCC转换结果 29 | // float mfcc_dat[vv_frm_max*mfcc_num]; 30 | } v_ftr_tag; //语音特征结构体 31 | //#pragma pack() 32 | 33 | void get_mfcc(valid_tag *valid, v_ftr_tag *v_ftr, atap_tag *atap_arg); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/VAD.h: -------------------------------------------------------------------------------- 1 | #ifndef _VAD_H 2 | #define _VAD_H 3 | 4 | #include "g_def.h" 5 | 6 | #define max_vc_con 3 //VAD最多检测的语音段数 7 | #define frame_time 20 // 每帧时间长度 单位ms 8 | #define frame_mov_t 10 // 帧移 9 | #define FRAME_LEN (frame_time*fs/1000) // 帧长 10 | #define frame_mov (frame_mov_t *fs/1000) // 帧移,相邻帧交叠部分 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | 17 | #pragma pack(1) 18 | typedef struct { 19 | u32 mid_val; //语音段中值 相当于有符号的0值 用于短时过零率计算 20 | u16 n_thl; //噪声阈值,用于短时过零率计算 21 | u16 z_thl; //短时过零率阈值,超过此阈值,视为进入过渡段。 22 | u32 s_thl; //短时累加和阈值,超过此阈值,视为进入过渡段。 23 | } atap_tag; //自适应参数 24 | #pragma pack() 25 | 26 | //#pragma pack(4) 27 | typedef struct { 28 | u16 *start; //起始点 29 | u16 *end; //结束点 30 | // u8 word_num; 31 | } valid_tag; //有效语音段 32 | //#pragma pack() 33 | 34 | void noise_atap(const u16 *noise, u16 n_len, atap_tag *atap); 35 | void VAD(const u16 *vc, u16 buf_len, valid_tag *valid_voice, atap_tag *atap_arg); 36 | u8 VAD2(const u16 *vc, valid_tag *valid_voice, atap_tag *atap_arg); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/flash.c: -------------------------------------------------------------------------------- 1 | /* 适用于STM32F103VE 2 | * 全部falsh 512KB 256页 每页2KB 3 | 4 | 每个语音特征模板占用4KB 采用冗余模板 每个语音指令4个特征模板 5 | 初步设计设定20个语音指令 共占用320KB 6 | 7 | flash最后320KB用于存储语音特征模板 8 | 编译器需设置 以免存储区被代码占用 9 | 烧写程序时也不能擦除存储区 选擦除需要的页 10 | */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "g_def.h" 16 | #include "flash.h" 17 | #include "uarths.h" 18 | #include "MFCC.h" 19 | //#include "voice_modle.h" 20 | 21 | v_ftr_tag ftr_save[20 * 4]; 22 | 23 | u8 save_ftr_mdl(v_ftr_tag *ftr, u32 addr) 24 | { 25 | // u32 ftr_size; 26 | 27 | addr = addr / size_per_ftr; 28 | 29 | if (addr > 40) { 30 | printf("flash addr error"); 31 | return Flash_Fail; 32 | } 33 | ftr->save_sign = save_mask; 34 | ftr_save[addr] = *ftr; 35 | 36 | // ftr_size=2*mfcc_num*ftr->frm_num; 37 | 38 | return Flash_Success; 39 | } 40 | #if 0 41 | void init_voice_mdl(void) 42 | { 43 | uint16_t i, j, comm; 44 | 45 | for (comm = 0; comm < 4; comm++) { 46 | for (j = 0; j < 4; j++) { 47 | ftr_save[comm*4+j].save_sign = save_mask; 48 | ftr_save[comm*4+j].frm_num = mdl_fram_num[comm*4+j]; 49 | // ftr_save[comm*4+j].word_num = 2; 50 | } 51 | } 52 | // 53 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 54 | ftr_save[0].mfcc_dat[i] = start1[i]; 55 | 56 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 57 | ftr_save[1].mfcc_dat[i] = start2[i]; 58 | 59 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 60 | ftr_save[2].mfcc_dat[i] = start3[i]; 61 | 62 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 63 | ftr_save[3].mfcc_dat[i] = start4[i]; 64 | 65 | 66 | // 67 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 68 | ftr_save[4].mfcc_dat[i] = pause1[i]; 69 | 70 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 71 | ftr_save[5].mfcc_dat[i] = pause2[i]; 72 | 73 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 74 | ftr_save[6].mfcc_dat[i] = pause3[i]; 75 | 76 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 77 | ftr_save[7].mfcc_dat[i] = pause4[i]; 78 | 79 | // 80 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 81 | ftr_save[8].mfcc_dat[i] = cancle1[i]; 82 | 83 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 84 | ftr_save[9].mfcc_dat[i] = cancle2[i]; 85 | 86 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 87 | ftr_save[10].mfcc_dat[i] = cancle3[i]; 88 | 89 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 90 | ftr_save[11].mfcc_dat[i] = cancle4[i]; 91 | 92 | // 93 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 94 | ftr_save[12].mfcc_dat[i] = confirm1[i]; 95 | 96 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 97 | ftr_save[13].mfcc_dat[i] = confirm2[i]; 98 | 99 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 100 | ftr_save[14].mfcc_dat[i] = confirm3[i]; 101 | 102 | for (i = 0; i < (vv_frm_max * mfcc_num); i++) 103 | ftr_save[15].mfcc_dat[i] = confirm4[i]; 104 | } 105 | #endif -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLASH_H 2 | #define __FLASH_H 3 | 4 | #include "g_def.h" 5 | #include "MFCC.h" 6 | 7 | #define FLASH_PAGE_SIZE 2048 8 | 9 | #define Flash_Fail 3 10 | #define Flash_Success 0 11 | 12 | #define save_mask 12345 13 | 14 | #define size_per_ftr (4*1024) 15 | #define page_per_ftr (size_per_ftr/FLASH_PAGE_SIZE) 16 | #define ftr_per_comm 4 17 | #define size_per_comm (ftr_per_comm*size_per_ftr) 18 | #define comm_num 10 19 | #define ftr_total_size (size_per_comm*comm_num) 20 | //#define ftr_end_addr 0x8080000 21 | #define ftr_end_addr (size_per_ftr * ftr_per_comm * comm_num) 22 | #define ftr_start_addr 0 //(ftr_end_addr-ftr_total_size) 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | u8 save_ftr_mdl(v_ftr_tag *ftr, u32 addr); 30 | 31 | //void init_voice_mdl(void); 32 | extern v_ftr_tag ftr_save[20 * 4]; 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /libraries/Maix_Speech_Recognition/src/util/g_def.h: -------------------------------------------------------------------------------- 1 | #ifndef _G_DEF_H_ 2 | #define _G_DEF_H_ 3 | 4 | typedef uint32_t u32; 5 | typedef uint16_t u16; 6 | typedef uint8_t u8; 7 | 8 | typedef int32_t s32; 9 | typedef int16_t s16; 10 | typedef int8_t s8; 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /libraries/NS2009/examples/drawline/drawline.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "touchscreen.h" 3 | 4 | SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD 5 | Sipeed_ST7789 lcd(320, 240, spi_); 6 | TouchScreen touchscreen; 7 | int key = KEY0; 8 | 9 | int touchscreen_status = 0; 10 | int touchscreen_x = 0; 11 | int touchscreen_y = 0; 12 | int status_last = TOUCH_NONE; 13 | int x_last = 0; 14 | int y_last = 0; 15 | bool draw = false; 16 | 17 | 18 | void setup() 19 | { 20 | pinMode(key, INPUT); 21 | lcd.begin(15000000, COLOR_RED); 22 | touchscreen.begin(); 23 | touchscreen.calibrate(320, 240); 24 | } 25 | 26 | void loop() 27 | { 28 | touchscreen.read(); 29 | touchscreen_status = touchscreen.getStatus(); 30 | touchscreen_x = touchscreen.getX(); 31 | touchscreen_y = touchscreen.getY(); 32 | if (draw) { 33 | lcd.writeLine(x_last,y_last,touchscreen_x,touchscreen_y,COLOR_WHITE); 34 | } 35 | if (status_last != touchscreen_status) { 36 | draw = (touchscreen_status == TOUCH_BEGIN || touchscreen_status == TOUCH_MOVE); 37 | status_last = touchscreen_status; 38 | } 39 | x_last = touchscreen_x; 40 | y_last = touchscreen_y; 41 | if (digitalRead(key) == LOW) { 42 | lcd.fillScreen(COLOR_BLACK); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /libraries/NS2009/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | read KEYWORD2 15 | getStatus KEYWORD2 16 | getX KEYWORD2 17 | getY KEYWORD2 18 | calibrate KEYWORD2 19 | is_init KEYWORD2 20 | end KEYWORD2 21 | 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### -------------------------------------------------------------------------------- /libraries/NS2009/library.properties: -------------------------------------------------------------------------------- 1 | name=Touchscreen 2 | version=1.0 3 | author=BigBits 4 | maintainer=BigBits 5 | sentence=NS2009 Touchscreen driver 6 | paragraph=NS2009 Touchscreen driver 7 | category=Display 8 | url= 9 | architectures=k210 10 | includes=touchscreen.h 11 | -------------------------------------------------------------------------------- /libraries/NS2009/src/mean.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libc/filter/mean.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "stdlib.h" 9 | 10 | #define touchscreen_malloc(p) malloc(p) 11 | #define touchscreen_free(p) free(p) 12 | 13 | struct mean_filter_t *mean_alloc(int length) 14 | { 15 | struct mean_filter_t *filter; 16 | int i; 17 | if (length <= 0) 18 | return NULL; 19 | 20 | filter = touchscreen_malloc(sizeof(struct mean_filter_t)); 21 | if (!filter) 22 | return NULL; 23 | 24 | filter->buffer = touchscreen_malloc(sizeof(int) * length); 25 | if (!filter->buffer) 26 | { 27 | touchscreen_free(filter); 28 | return NULL; 29 | } 30 | for (i = 0; i < length; i++) 31 | filter->buffer[i] = 0; 32 | filter->length = length; 33 | filter->index = 0; 34 | filter->count = 0; 35 | filter->sum = 0; 36 | 37 | return filter; 38 | } 39 | 40 | void mean_free(struct mean_filter_t *filter) 41 | { 42 | if (filter) 43 | { 44 | if (filter->buffer) 45 | touchscreen_free(filter->buffer); 46 | touchscreen_free(filter); 47 | } 48 | } 49 | 50 | int mean_update(struct mean_filter_t *filter, int value) 51 | { 52 | filter->sum -= filter->buffer[filter->index]; 53 | filter->sum += value; 54 | filter->buffer[filter->index] = value; 55 | filter->index = (filter->index + 1) % filter->length; 56 | 57 | if (filter->count < filter->length) 58 | filter->count++; 59 | return filter->sum / filter->count; 60 | } 61 | 62 | void mean_clear(struct mean_filter_t *filter) 63 | { 64 | int i; 65 | 66 | if (filter) 67 | { 68 | for (i = 0; i < filter->length; i++) 69 | filter->buffer[i] = 0; 70 | filter->index = 0; 71 | filter->count = 0; 72 | filter->sum = 0; 73 | } 74 | } -------------------------------------------------------------------------------- /libraries/NS2009/src/mean.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEAN_H__ 2 | #define __MEAN_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | struct mean_filter_t 10 | { 11 | int *buffer; 12 | int length; 13 | int index; 14 | int count; 15 | int sum; 16 | }; 17 | 18 | struct mean_filter_t *mean_alloc(int length); 19 | void mean_free(struct mean_filter_t *filter); 20 | int mean_update(struct mean_filter_t *filter, int value); 21 | void mean_clear(struct mean_filter_t *filter); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* __MEAN_H__ */ -------------------------------------------------------------------------------- /libraries/NS2009/src/median.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libc/filter/median.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "stdlib.h" 9 | 10 | #define touchscreen_malloc(p) malloc(p) 11 | #define touchscreen_free(p) free(p) 12 | 13 | struct median_filter_t *median_alloc(int length) 14 | { 15 | struct median_filter_t *filter; 16 | 17 | if (length <= 0) 18 | return NULL; 19 | filter = touchscreen_malloc(sizeof(struct median_filter_t)); 20 | if (!filter) 21 | return NULL; 22 | 23 | filter->buffer = touchscreen_malloc(sizeof(int) * length); 24 | filter->index = touchscreen_malloc(sizeof(int) * length); 25 | if (!filter->buffer || !filter->index) 26 | { 27 | if (filter->buffer) 28 | touchscreen_free(filter->buffer); 29 | if (filter->index) 30 | touchscreen_free(filter->index); 31 | touchscreen_free(filter); 32 | return NULL; 33 | } 34 | filter->length = length; 35 | filter->position = 0; 36 | filter->count = 0; 37 | 38 | return filter; 39 | } 40 | 41 | void median_free(struct median_filter_t *filter) 42 | { 43 | if (filter) 44 | { 45 | if (filter->buffer) 46 | touchscreen_free(filter->buffer); 47 | if (filter->index) 48 | touchscreen_free(filter->index); 49 | touchscreen_free(filter); 50 | } 51 | } 52 | 53 | int median_update(struct median_filter_t *filter, int value) 54 | { 55 | int pos = filter->position; 56 | int cnt = filter->count; 57 | int *idx; 58 | int cidx; 59 | int oidx; 60 | int oval; 61 | int result; 62 | if (cnt > 0) 63 | { 64 | if (cnt == filter->length) 65 | { 66 | oidx = 0; 67 | while (filter->index[oidx] != pos) 68 | ++oidx; 69 | oval = filter->buffer[pos]; 70 | } 71 | else 72 | { 73 | filter->index[pos] = pos; 74 | oidx = pos; 75 | oval = INT_MAX; 76 | } 77 | 78 | filter->buffer[pos] = value; 79 | idx = &filter->index[oidx]; 80 | if (oval < value) 81 | { 82 | while (++oidx != cnt) 83 | { 84 | cidx = *(++idx); 85 | if (filter->buffer[cidx] < value) 86 | { 87 | *idx = *(idx - 1); 88 | *(idx - 1) = cidx; 89 | } 90 | else 91 | { 92 | break; 93 | } 94 | } 95 | } 96 | else if (oval > value) 97 | { 98 | while (oidx-- != 0) 99 | { 100 | cidx = *(--idx); 101 | if (filter->buffer[cidx] > value) 102 | { 103 | *idx = *(idx + 1); 104 | *(idx + 1) = cidx; 105 | } 106 | else 107 | { 108 | break; 109 | } 110 | } 111 | } 112 | result = filter->buffer[filter->index[cnt / 2]]; 113 | } 114 | else 115 | { 116 | filter->buffer[0] = value; 117 | filter->index[0] = 0; 118 | filter->position = 0; 119 | filter->count = 0; 120 | result = value; 121 | } 122 | 123 | pos++; 124 | filter->position = (pos == filter->length) ? 0 : pos; 125 | if (cnt < filter->length) 126 | filter->count++; 127 | 128 | return result; 129 | } 130 | 131 | void median_clear(struct median_filter_t *filter) 132 | { 133 | if (filter) 134 | { 135 | filter->position = 0; 136 | filter->count = 0; 137 | } 138 | } -------------------------------------------------------------------------------- /libraries/NS2009/src/median.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEDIAN_H__ 2 | #define __MEDIAN_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #define INT_MIN (-1 - 0x7fffffff) 10 | #define INT_MAX 0x7fffffff 11 | 12 | struct median_filter_t 13 | { 14 | int *buffer; 15 | int *index; 16 | int length; 17 | int position; 18 | int count; 19 | }; 20 | 21 | struct median_filter_t *median_alloc(int length); 22 | void median_free(struct median_filter_t *filter); 23 | int median_update(struct median_filter_t *filter, int value); 24 | void median_clear(struct median_filter_t *filter); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* __MEDIAN_H__ */ -------------------------------------------------------------------------------- /libraries/NS2009/src/ns2009.h: -------------------------------------------------------------------------------- 1 | #ifndef __NS2009_H 2 | #define __NS2009_H 3 | 4 | #include 5 | 6 | /* clang-format off */ 7 | #define NS2009_SLV_ADDR 0x48 8 | #define NS2009_IOCTL_SET_CALBRATION 0x1 9 | /* clang-format on */ 10 | #ifdef __cplusplus 11 | extern "C"{ 12 | #endif // __cplusplus 13 | 14 | enum 15 | { 16 | NS2009_LOW_POWER_READ_X = 0xc0, 17 | NS2009_LOW_POWER_READ_Y = 0xd0, 18 | NS2009_LOW_POWER_READ_Z1 = 0xe0, 19 | NS2009_LOW_POWER_READ_Z2 = 0xf0, 20 | }; 21 | 22 | enum event_type 23 | { 24 | TOUCH_NONE = 0, 25 | TOUCH_BEGIN, 26 | TOUCH_MOVE, 27 | TOUCH_END 28 | }; 29 | 30 | struct ts_ns2009_event_t 31 | { 32 | enum event_type type; 33 | int x, y; 34 | } __attribute__((aligned(8))); 35 | 36 | struct ts_ns2009_pdata_t 37 | { 38 | struct tsfilter_t *filter; 39 | struct ts_ns2009_event_t *event; 40 | int x, y; 41 | int press; 42 | } __attribute__((aligned(8))); 43 | 44 | int ts_ns2009_poll(struct ts_ns2009_pdata_t *ts_ns2009_pdata); 45 | int ts_ns2009_set_calibration(struct ts_ns2009_pdata_t *ts_ns2009_pdata, int cmd, void *arg); 46 | struct ts_ns2009_pdata_t *ts_ns2009_probe(int* cal, int* err); 47 | void ts_ns2009_remove(struct ts_ns2009_pdata_t *ts_ns2009_pdata); 48 | 49 | 50 | int ns2009_hal_i2c_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf, 51 | size_t receive_buf_len); 52 | #ifdef __cplusplus 53 | } 54 | #endif // __cplusplus 55 | 56 | #endif -------------------------------------------------------------------------------- /libraries/NS2009/src/touchscreen.cpp: -------------------------------------------------------------------------------- 1 | #include "touchscreen.h" 2 | #include "Wire.h" 3 | 4 | extern "C" 5 | { 6 | #include "tscal.h" 7 | } 8 | 9 | TouchScreen::TouchScreen() 10 | { 11 | 12 | } 13 | 14 | TouchScreen::~TouchScreen() 15 | { 16 | 17 | } 18 | 19 | 20 | int 21 | TouchScreen::begin() 22 | { 23 | int err; 24 | 25 | Wire.begin(); 26 | 27 | ts_ns2009_pdata = ts_ns2009_probe(calibration, &err); //calibration 28 | if (ts_ns2009_pdata == NULL || err!=0) 29 | return err; 30 | _is_init = true; 31 | return 0; 32 | } 33 | 34 | bool 35 | TouchScreen::is_init() 36 | { 37 | return _is_init; 38 | } 39 | 40 | int 41 | TouchScreen::read() 42 | { 43 | ts_ns2009_poll(ts_ns2009_pdata); 44 | _x = 0; 45 | _y = 0; 46 | switch (ts_ns2009_pdata->event->type) 47 | { 48 | case TOUCH_BEGIN: 49 | _x = ts_ns2009_pdata->event->x; 50 | _y = ts_ns2009_pdata->event->y; 51 | _status = TOUCHSCREEN_STATUS_PRESS; 52 | break; 53 | 54 | case TOUCH_MOVE: 55 | _x = ts_ns2009_pdata->event->x; 56 | _y = ts_ns2009_pdata->event->y; 57 | _status = TOUCHSCREEN_STATUS_MOVE; 58 | break; 59 | 60 | case TOUCH_END: 61 | _x= ts_ns2009_pdata->event->x; 62 | _y= ts_ns2009_pdata->event->y; 63 | _status = TOUCHSCREEN_STATUS_RELEASE; 64 | break; 65 | default: 66 | break; 67 | } 68 | return 0; 69 | 70 | } 71 | 72 | int 73 | TouchScreen::getStatus() 74 | { 75 | return _status; 76 | } 77 | 78 | int 79 | TouchScreen::getX() 80 | { 81 | return _x; 82 | } 83 | 84 | int 85 | TouchScreen::getY() 86 | { 87 | return _y; 88 | } 89 | 90 | int 91 | TouchScreen::end() 92 | { 93 | ts_ns2009_remove(ts_ns2009_pdata); 94 | _is_init = false; 95 | return 0; 96 | } 97 | 98 | int 99 | TouchScreen::calibrate(int w, int h) 100 | { 101 | return do_tscal(ts_ns2009_pdata, w, h, calibration); 102 | } 103 | 104 | //////////////HAL////////////// 105 | 106 | int ns2009_hal_i2c_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf, 107 | size_t receive_buf_len) 108 | { 109 | Wire.beginTransmission(NS2009_SLV_ADDR); 110 | Wire.write(send_buf,send_buf_len); 111 | Wire.endTransmission(); 112 | Wire.requestFrom(NS2009_SLV_ADDR,receive_buf_len); 113 | while(Wire.available()){ 114 | *receive_buf++ = Wire.read(); 115 | } 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /libraries/NS2009/src/touchscreen.h: -------------------------------------------------------------------------------- 1 | #ifndef __TOUCHSCREEN_H_ 2 | #define __TOUCHSCREEN_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "stdbool.h" 9 | 10 | typedef enum{ 11 | TOUCHSCREEN_STATUS_IDLE =0, 12 | TOUCHSCREEN_STATUS_RELEASE, 13 | TOUCHSCREEN_STATUS_PRESS, 14 | TOUCHSCREEN_STATUS_MOVE 15 | } touchscreen_type_t; 16 | 17 | #ifdef __cplusplus 18 | }//extern "C" 19 | #endif 20 | 21 | #include "Wire.h" 22 | #include "ns2009.h" 23 | #define CALIBRATION_SIZE 7 24 | 25 | #ifdef __cplusplus 26 | class TouchScreen{ 27 | public : 28 | TouchScreen(); 29 | ~TouchScreen(); 30 | int begin(); 31 | int read(); 32 | int getStatus(); 33 | int getX(); 34 | int getY(); 35 | int calibrate(int w = 320, int h = 240); 36 | bool is_init(); 37 | int end(); 38 | private: 39 | int calibration[CALIBRATION_SIZE] = { 40 | -6, 41 | -5941, 42 | 22203576, 43 | 4232, 44 | -8, 45 | -700369, 46 | 65536 47 | }; 48 | bool _is_init = false ; 49 | ts_ns2009_pdata_t *ts_ns2009_pdata; 50 | int _status = TOUCHSCREEN_STATUS_IDLE; 51 | int _x = 0; 52 | int _y = 0; 53 | }; 54 | #endif 55 | 56 | #include "stdlib.h" 57 | 58 | 59 | #define touchscreen_malloc(p) malloc(p) 60 | #define touchscreen_free(p) free(p) 61 | 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /libraries/NS2009/src/tscal.h: -------------------------------------------------------------------------------- 1 | #ifndef __TSCAL_H 2 | #define __TSCAL_H 3 | 4 | #include 5 | 6 | struct tscal_t 7 | { 8 | int x[5], xfb[5]; 9 | int y[5], yfb[5]; 10 | int a[7]; 11 | }; 12 | 13 | int do_tscal(struct ts_ns2009_pdata_t *ts_ns2009_pdata, int w, int h, int* cal_ret); 14 | 15 | #endif -------------------------------------------------------------------------------- /libraries/NS2009/src/tsfilter.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stdlib.h" 4 | 5 | #define touchscreen_malloc(p) malloc(p) 6 | #define touchscreen_free(p) free(p) 7 | 8 | struct tsfilter_t *tsfilter_alloc(int ml, int nl) 9 | { 10 | struct tsfilter_t *filter; 11 | if (ml <= 0 || nl <= 0) 12 | return NULL; 13 | 14 | filter = touchscreen_malloc(sizeof(struct tsfilter_t)); 15 | if (!filter) 16 | return NULL; 17 | 18 | filter->mx = median_alloc(ml); 19 | filter->my = median_alloc(ml); 20 | filter->nx = mean_alloc(nl); 21 | filter->ny = mean_alloc(nl); 22 | filter->cal[0] = 1; 23 | filter->cal[1] = 0; 24 | filter->cal[2] = 0; 25 | filter->cal[3] = 0; 26 | filter->cal[4] = 1; 27 | filter->cal[5] = 0; 28 | filter->cal[6] = 1; 29 | 30 | if (!filter->mx || !filter->my || !filter->nx || !filter->ny) 31 | { 32 | if (filter->mx) 33 | median_free(filter->mx); 34 | if (filter->my) 35 | median_free(filter->my); 36 | if (filter->nx) 37 | mean_free(filter->nx); 38 | if (filter->ny) 39 | mean_free(filter->ny); 40 | } 41 | return filter; 42 | } 43 | 44 | void tsfilter_free(struct tsfilter_t *filter) 45 | { 46 | if (filter) 47 | { 48 | if (filter->mx) 49 | median_free(filter->mx); 50 | if (filter->my) 51 | median_free(filter->my); 52 | if (filter->nx) 53 | mean_free(filter->nx); 54 | if (filter->ny) 55 | mean_free(filter->ny); 56 | touchscreen_free(filter); 57 | } 58 | } 59 | 60 | void tsfilter_setcal(struct tsfilter_t *filter, int *cal) 61 | { 62 | if (filter) 63 | { 64 | filter->cal[0] = cal[0]; 65 | filter->cal[1] = cal[1]; 66 | filter->cal[2] = cal[2]; 67 | filter->cal[3] = cal[3]; 68 | filter->cal[4] = cal[4]; 69 | filter->cal[5] = cal[5]; 70 | filter->cal[6] = cal[6]; 71 | } 72 | } 73 | 74 | void tsfilter_update(struct tsfilter_t *filter, int *x, int *y) 75 | { 76 | int tx, ty; 77 | tx = median_update(filter->mx, *x); 78 | ty = median_update(filter->my, *y); 79 | tx = mean_update(filter->nx, tx); 80 | ty = mean_update(filter->ny, ty); 81 | *x = (filter->cal[2] + filter->cal[0] * tx + filter->cal[1] * ty) / filter->cal[6]; 82 | *y = (filter->cal[5] + filter->cal[3] * tx + filter->cal[4] * ty) / filter->cal[6]; 83 | } 84 | 85 | void tsfilter_clear(struct tsfilter_t *filter) 86 | { 87 | if (filter) 88 | { 89 | if (filter->mx) 90 | median_clear(filter->mx); 91 | if (filter->my) 92 | median_clear(filter->my); 93 | if (filter->nx) 94 | mean_clear(filter->nx); 95 | if (filter->ny) 96 | mean_clear(filter->ny); 97 | } 98 | } -------------------------------------------------------------------------------- /libraries/NS2009/src/tsfilter.h: -------------------------------------------------------------------------------- 1 | #ifndef __TSFILTER_H__ 2 | #define __TSFILTER_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | struct tsfilter_t 13 | { 14 | struct median_filter_t *mx, *my; 15 | struct mean_filter_t *nx, *ny; 16 | int cal[7]; 17 | } __attribute__((aligned(8))); 18 | 19 | struct tsfilter_t *tsfilter_alloc(int ml, int nl); 20 | void tsfilter_free(struct tsfilter_t *filter); 21 | void tsfilter_setcal(struct tsfilter_t *filter, int *cal); 22 | void tsfilter_update(struct tsfilter_t *filter, int *x, int *y); 23 | void tsfilter_clear(struct tsfilter_t *filter); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* __TSFILTER_H__ */ -------------------------------------------------------------------------------- /libraries/SD/README.adoc: -------------------------------------------------------------------------------- 1 | = SD Library for Arduino = 2 | 3 | The SD library allows for reading from and writing to SD cards. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/SD 7 | 8 | == License == 9 | 10 | Copyright (C) 2009 by William Greiman 11 | Copyright (c) 2010 SparkFun Electronics 12 | Copyright (c) 2019 Sipeed 13 | 14 | This program is free software: you can redistribute it and/or modify 15 | it under the terms of the GNU General Public License as published by 16 | the Free Software Foundation, either version 3 of the License, or 17 | (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | -------------------------------------------------------------------------------- /libraries/SD/examples/Datalogger/Datalogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card datalogger 3 | 4 | This example shows how to log data from three analog sensors 5 | to an SD card using the SD library. 6 | 7 | The circuit: 8 | * analog sensors on analog ins 0, 1, and 2 9 | * SD card attached to SPI bus as follows: 10 | ** MOSI - pin 28 11 | ** MISO - pin 26 12 | ** CLK - pin 27 13 | ** CS - pin 29 14 | 15 | created 24 Nov 2010 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified for k210 30 Mar 2019 19 | by Neucrack 20 | 21 | This example code is in the public domain. 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | const int chipSelect = 29; 29 | 30 | void setup() { 31 | // Open serial communications and wait for port to open: 32 | Serial.begin(9600); 33 | while (!Serial) { 34 | ; // wait for serial port to connect. Needed for native USB port only 35 | } 36 | 37 | 38 | Serial.print("Initializing SD card..."); 39 | 40 | // see if the card is present and can be initialized: 41 | // SD object used default SPI object( use SPI1 ), 42 | // if you want to modify, as follows: 43 | // SPIClass spi(SPI1, 27, 26, 28, -1); 44 | // SDClass sd(spi); 45 | // sd.begin(29) 46 | if (!SD.begin(chipSelect)) { 47 | Serial.println("Card failed, or not present"); 48 | // don't do anything more: 49 | while (1); 50 | } 51 | Serial.println("card initialized."); 52 | } 53 | 54 | void loop() { 55 | // make a string for assembling the data to log: 56 | String dataString = ""; 57 | 58 | // read three sensors and append to the string: 59 | for (int analogPin = 0; analogPin < 3; analogPin++) { 60 | int sensor = analogRead(analogPin); 61 | dataString += String(sensor); 62 | if (analogPin < 2) { 63 | dataString += ","; 64 | } 65 | } 66 | 67 | // open the file. note that only one file can be open at a time, 68 | // so you have to close this one before opening another. 69 | File dataFile = SD.open("datalog.txt", FILE_WRITE); 70 | 71 | // if the file is available, write to it: 72 | if (dataFile) { 73 | dataFile.println(dataString); 74 | dataFile.close(); 75 | // print to the serial port too: 76 | Serial.println(dataString); 77 | } 78 | // if the file isn't open, pop up an error: 79 | else { 80 | Serial.println("error opening datalog.txt"); 81 | } 82 | } 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /libraries/SD/examples/DumpFile/DumpFile.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card file dump 3 | 4 | This example shows how to read a file from the SD card using the 5 | SD library and send it over the serial port. 6 | 7 | The circuit: 8 | * SD card attached to SPI bus as follows: 9 | ** MOSI - pin 28 10 | ** MISO - pin 26 11 | ** CLK - pin 27 12 | ** CS - pin 29 13 | 14 | created 22 December 2010 15 | by Limor Fried 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified for k210 30 Mar 2019 19 | by Neucrack 20 | 21 | This example code is in the public domain. 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | const int chipSelect = 29; 29 | 30 | void setup() { 31 | // Open serial communications and wait for port to open: 32 | Serial.begin(9600); 33 | while (!Serial) { 34 | ; // wait for serial port to connect. Needed for native USB port only 35 | } 36 | 37 | 38 | Serial.print("Initializing SD card..."); 39 | 40 | // see if the card is present and can be initialized: 41 | if (!SD.begin(chipSelect)) { 42 | Serial.println("Card failed, or not present"); 43 | // don't do anything more: 44 | while (1); 45 | } 46 | Serial.println("card initialized."); 47 | 48 | // open the file. note that only one file can be open at a time, 49 | // so you have to close this one before opening another. 50 | File dataFile = SD.open("datalog.txt"); 51 | 52 | // if the file is available, write to it: 53 | if (dataFile) { 54 | while (dataFile.available()) { 55 | Serial.write(dataFile.read()); 56 | } 57 | dataFile.close(); 58 | } 59 | // if the file isn't open, pop up an error: 60 | else { 61 | Serial.println("error opening datalog.txt"); 62 | } 63 | } 64 | 65 | void loop() { 66 | } 67 | 68 | -------------------------------------------------------------------------------- /libraries/SD/examples/Files/Files.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card basic file example 3 | 4 | This example shows how to create and destroy an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 28 8 | ** MISO - pin 26 9 | ** CLK - pin 27 10 | ** CS - pin 29 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | modified for k210 30 Mar 2019 17 | by Neucrack 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | #include 23 | #include 24 | 25 | File myFile; 26 | 27 | void setup() { 28 | // Open serial communications and wait for port to open: 29 | Serial.begin(9600); 30 | while (!Serial) { 31 | ; // wait for serial port to connect. Needed for native USB port only 32 | } 33 | 34 | 35 | Serial.print("Initializing SD card..."); 36 | 37 | if (!SD.begin(29)) { 38 | Serial.println("initialization failed!"); 39 | while (1); 40 | } 41 | Serial.println("initialization done."); 42 | 43 | if (SD.exists("example.txt")) { 44 | Serial.println("example.txt exists."); 45 | } else { 46 | Serial.println("example.txt doesn't exist."); 47 | } 48 | 49 | // open a new file and immediately close it: 50 | Serial.println("Creating example.txt..."); 51 | myFile = SD.open("example.txt", FILE_WRITE); 52 | myFile.close(); 53 | 54 | // Check to see if the file exists: 55 | if (SD.exists("example.txt")) { 56 | Serial.println("example.txt exists."); 57 | } else { 58 | Serial.println("example.txt doesn't exist."); 59 | } 60 | 61 | // delete the file: 62 | Serial.println("Removing example.txt..."); 63 | SD.remove("example.txt"); 64 | 65 | if (SD.exists("example.txt")) { 66 | Serial.println("example.txt exists."); 67 | } else { 68 | Serial.println("example.txt doesn't exist."); 69 | } 70 | } 71 | 72 | void loop() { 73 | // nothing happens after setup finishes. 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /libraries/SD/examples/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card read/write 3 | 4 | This example shows how to read and write data to and from an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 28 8 | ** MISO - pin 26 9 | ** CLK - pin 27 10 | ** CS - pin 29 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | modified for k210 30 Mar 2019 17 | by Neucrack 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | File myFile; 27 | 28 | void setup() { 29 | // Open serial communications and wait for port to open: 30 | Serial.begin(9600); 31 | while (!Serial) { 32 | ; // wait for serial port to connect. Needed for native USB port only 33 | } 34 | 35 | 36 | Serial.print("Initializing SD card..."); 37 | 38 | if (!SD.begin(29)) { 39 | Serial.println("initialization failed!"); 40 | while (1); 41 | } 42 | Serial.println("initialization done."); 43 | 44 | // open the file. note that only one file can be open at a time, 45 | // so you have to close this one before opening another. 46 | myFile = SD.open("test.txt", FILE_WRITE); 47 | 48 | // if the file opened okay, write to it: 49 | if (myFile) { 50 | Serial.print("Writing to test.txt..."); 51 | myFile.println("testing 1, 2, 3."); 52 | // close the file: 53 | myFile.close(); 54 | Serial.println("done."); 55 | } else { 56 | // if the file didn't open, print an error: 57 | Serial.println("error opening test.txt"); 58 | } 59 | 60 | // re-open the file for reading: 61 | myFile = SD.open("test.txt"); 62 | if (myFile) { 63 | Serial.println("test.txt:"); 64 | 65 | // read from the file until there's nothing else in it: 66 | while (myFile.available()) { 67 | Serial.write(myFile.read()); 68 | } 69 | // close the file: 70 | myFile.close(); 71 | } else { 72 | // if the file didn't open, print an error: 73 | Serial.println("error opening test.txt"); 74 | } 75 | } 76 | 77 | void loop() { 78 | // nothing happens after setup 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /libraries/SD/examples/listfiles/listfiles.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Listfiles 3 | 4 | This example shows how print out the files in a 5 | directory on a SD card 6 | 7 | The circuit: 8 | * SD card attached to SPI bus as follows: 9 | ** MOSI - pin 28 10 | ** MISO - pin 26 11 | ** CLK - pin 27 12 | ** CS - pin 29 13 | 14 | created Nov 2010 15 | by David A. Mellis 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified 2 Feb 2014 19 | by Scott Fitzgerald 20 | modified for k210 30 Mar 2019 21 | by Neucrack 22 | 23 | This example code is in the public domain. 24 | 25 | */ 26 | #include 27 | #include 28 | 29 | File root; 30 | 31 | void setup() { 32 | // Open serial communications and wait for port to open: 33 | Serial.begin(9600); 34 | while (!Serial) { 35 | ; // wait for serial port to connect. Needed for native USB port only 36 | } 37 | 38 | Serial.print("Initializing SD card..."); 39 | 40 | if (!SD.begin(29)) { 41 | Serial.println("initialization failed!"); 42 | while (1); 43 | } 44 | Serial.println("initialization done."); 45 | 46 | root = SD.open("/"); 47 | 48 | printDirectory(root, 0); 49 | 50 | Serial.println("done!"); 51 | } 52 | 53 | void loop() { 54 | // nothing happens after setup finishes. 55 | } 56 | 57 | void printDirectory(File dir, int numTabs) { 58 | while (true) { 59 | 60 | File entry = dir.openNextFile(); 61 | if (! entry) { 62 | // no more files 63 | break; 64 | } 65 | for (uint8_t i = 0; i < numTabs; i++) { 66 | Serial.print('\t'); 67 | } 68 | Serial.print(entry.name()); 69 | if (entry.isDirectory()) { 70 | Serial.println("/"); 71 | printDirectory(entry, numTabs + 1); 72 | } else { 73 | // files have sizes, directories do not 74 | Serial.print("\t\t"); 75 | Serial.println(entry.size(), DEC); 76 | } 77 | entry.close(); 78 | } 79 | } 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /libraries/SD/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SD 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SD KEYWORD1 SD 10 | File KEYWORD1 SD 11 | SDFile KEYWORD1 SD 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | begin KEYWORD2 17 | exists KEYWORD2 18 | mkdir KEYWORD2 19 | remove KEYWORD2 20 | rmdir KEYWORD2 21 | open KEYWORD2 22 | close KEYWORD2 23 | seek KEYWORD2 24 | position KEYWORD2 25 | size KEYWORD2 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | FILE_READ LITERAL1 31 | FILE_WRITE LITERAL1 32 | -------------------------------------------------------------------------------- /libraries/SD/library.properties: -------------------------------------------------------------------------------- 1 | name=SD 2 | version=1.2.4 3 | author=Arduino, SparkFun, Neucrack 4 | maintainer=Sipeed 5 | sentence=Enables reading and writing on SD cards. 6 | paragraph=Once an SD memory card is connected to the SPI interface of the Arduino or Genuino board you can create files and read/write on them. You can also move through directories on the SD card. 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/SD 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/SD/src/File.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SD - a slightly more friendly wrapper for sdfatlib 4 | 5 | This library aims to expose a subset of SD card functionality 6 | in the form of a higher level "wrapper" object. 7 | 8 | License: GNU General Public License V3 9 | (Because sdfatlib is licensed with this.) 10 | 11 | (C) Copyright 2010 SparkFun Electronics 12 | 13 | */ 14 | 15 | #include 16 | 17 | /* for debugging file open/close leaks 18 | uint8_t nfilecount=0; 19 | */ 20 | 21 | File::File(SdFile f, const char *n) { 22 | // oh man you are kidding me, new() doesnt exist? Ok we do it by hand! 23 | _file = (SdFile *)malloc(sizeof(SdFile)); 24 | if (_file) { 25 | memcpy((void*)_file, &f, sizeof(SdFile)); 26 | 27 | strncpy(_name, n, 12); 28 | _name[12] = 0; 29 | 30 | /* for debugging file open/close leaks 31 | nfilecount++; 32 | Serial.print("Created \""); 33 | Serial.print(n); 34 | Serial.print("\": "); 35 | Serial.println(nfilecount, DEC); 36 | */ 37 | } 38 | } 39 | 40 | File::File(void) { 41 | _file = 0; 42 | _name[0] = 0; 43 | //Serial.print("Created empty file object"); 44 | } 45 | 46 | // returns a pointer to the file name 47 | char *File::name(void) { 48 | return _name; 49 | } 50 | 51 | // a directory is a special type of file 52 | boolean File::isDirectory(void) { 53 | return (_file && _file->isDir()); 54 | } 55 | 56 | 57 | size_t File::write(uint8_t val) { 58 | return write(&val, 1); 59 | } 60 | 61 | size_t File::write(const uint8_t *buf, size_t size) { 62 | size_t t; 63 | if (!_file) { 64 | setWriteError(); 65 | return 0; 66 | } 67 | _file->clearWriteError(); 68 | t = _file->write(buf, size); 69 | if (_file->getWriteError()) { 70 | setWriteError(); 71 | return 0; 72 | } 73 | return t; 74 | } 75 | 76 | int File::peek() { 77 | if (! _file) 78 | return 0; 79 | 80 | int c = _file->read(); 81 | if (c != -1) _file->seekCur(-1); 82 | return c; 83 | } 84 | 85 | int File::read() { 86 | if (_file) 87 | return _file->read(); 88 | return -1; 89 | } 90 | 91 | // buffered read for more efficient, high speed reading 92 | int File::read(void *buf, uint16_t nbyte) { 93 | if (_file) 94 | return _file->read(buf, nbyte); 95 | return 0; 96 | } 97 | 98 | long File::read(void *buf, uint32_t nbyte) { 99 | if (!_file) 100 | return 0; 101 | uint32_t bytesToRead = nbyte; 102 | uint16_t ret, readBytesOnece; 103 | while(bytesToRead) 104 | { 105 | readBytesOnece = (bytesToRead>65000) ? 65000 : bytesToRead; 106 | ret = (uint16_t)_file->read(buf+(nbyte-bytesToRead), readBytesOnece); 107 | if(ret == 0xffff) 108 | return -1; 109 | bytesToRead -= ret; 110 | } 111 | return nbyte; 112 | } 113 | 114 | int File::available() { 115 | if (! _file) return 0; 116 | 117 | uint32_t n = size() - position(); 118 | 119 | return n > 0X7FFF ? 0X7FFF : n; 120 | } 121 | 122 | void File::flush() { 123 | if (_file) 124 | _file->sync(); 125 | } 126 | 127 | boolean File::seek(uint32_t pos) { 128 | if (! _file) return false; 129 | 130 | return _file->seekSet(pos); 131 | } 132 | 133 | uint32_t File::position() { 134 | if (! _file) return -1; 135 | return _file->curPosition(); 136 | } 137 | 138 | uint32_t File::size() { 139 | if (! _file) return 0; 140 | return _file->fileSize(); 141 | } 142 | 143 | void File::close() { 144 | if (_file) { 145 | _file->close(); 146 | free(_file); 147 | _file = 0; 148 | 149 | /* for debugging file open/close leaks 150 | nfilecount--; 151 | Serial.print("Deleted "); 152 | Serial.println(nfilecount, DEC); 153 | */ 154 | } 155 | } 156 | 157 | File::operator bool() { 158 | if (_file) 159 | return _file->isOpen(); 160 | return false; 161 | } 162 | 163 | -------------------------------------------------------------------------------- /libraries/SD/src/README.txt: -------------------------------------------------------------------------------- 1 | 2 | ** SD - a slightly more friendly wrapper for sdfatlib ** 3 | 4 | This library aims to expose a subset of SD card functionality in the 5 | form of a higher level "wrapper" object. 6 | 7 | License: GNU General Public License V3 8 | (Because sdfatlib is licensed with this.) 9 | 10 | (C) Copyright 2010 SparkFun Electronics 11 | (C) Copyright 2019 Sipeed 12 | 13 | Now better than ever with optimization, multiple file support, directory handling, etc - ladyada! 14 | 15 | -------------------------------------------------------------------------------- /libraries/SD/src/utility/SdFatUtil.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2008 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (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 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #ifndef SdFatUtil_h 21 | #define SdFatUtil_h 22 | /** 23 | * \file 24 | * Useful utility functions. 25 | */ 26 | #include 27 | #ifdef __AVR__ 28 | #include 29 | /** Store and print a string in flash memory.*/ 30 | #define PgmPrint(x) SerialPrint_P(PSTR(x)) 31 | /** Store and print a string in flash memory followed by a CR/LF.*/ 32 | #define PgmPrintln(x) SerialPrintln_P(PSTR(x)) 33 | /** Defined so doxygen works for function definitions. */ 34 | #endif 35 | #define NOINLINE __attribute__((noinline,unused)) 36 | #define UNUSEDOK __attribute__((unused)) 37 | //------------------------------------------------------------------------------ 38 | /** Return the number of bytes currently free in RAM. */ 39 | static UNUSEDOK int FreeRam(void) { 40 | extern int __bss_end; 41 | extern int* __brkval; 42 | long free_memory; 43 | if (reinterpret_cast(__brkval) == 0) { 44 | // if no heap use from end of bss section 45 | free_memory = reinterpret_cast(&free_memory) 46 | - reinterpret_cast(&__bss_end); 47 | } else { 48 | // use from top of stack to heap 49 | free_memory = reinterpret_cast(&free_memory) 50 | - reinterpret_cast(__brkval); 51 | } 52 | return free_memory; 53 | } 54 | #ifdef __AVR__ 55 | //------------------------------------------------------------------------------ 56 | /** 57 | * %Print a string in flash memory to the serial port. 58 | * 59 | * \param[in] str Pointer to string stored in flash memory. 60 | */ 61 | static NOINLINE void SerialPrint_P(PGM_P str) { 62 | for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.write(c); 63 | } 64 | //------------------------------------------------------------------------------ 65 | /** 66 | * %Print a string in flash memory followed by a CR/LF. 67 | * 68 | * \param[in] str Pointer to string stored in flash memory. 69 | */ 70 | static NOINLINE void SerialPrintln_P(PGM_P str) { 71 | SerialPrint_P(str); 72 | Serial.println(); 73 | } 74 | #endif // __AVR__ 75 | #endif // #define SdFatUtil_h 76 | -------------------------------------------------------------------------------- /libraries/SPI/examples/basic/basic.ino: -------------------------------------------------------------------------------- 1 | #include "SPI.h" 2 | 3 | 4 | void setup() 5 | { 6 | SPI.setFrequency(10000000); 7 | SPI.begin(27, 26, 28, 29); 8 | SPI.transfer(1); 9 | SPI.transfer(2); 10 | SPI.transfer(3); 11 | SPI.transfer(0xEE); 12 | } 13 | 14 | void loop() 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /libraries/SPI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SPI KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | transfer KEYWORD2 17 | transferBytes KEYWORD2 18 | setBitOrder KEYWORD2 19 | setDataMode KEYWORD2 20 | setFrequency KEYWORD2 21 | beginTransaction KEYWORD2 22 | endTransaction KEYWORD2 23 | bus KEYWORD2 24 | 25 | 26 | ####################################### 27 | # Constants (LITERAL1) 28 | ####################################### 29 | SPI_MODE0 LITERAL1 30 | SPI_MODE1 LITERAL1 31 | SPI_MODE2 LITERAL1 32 | SPI_MODE3 LITERAL1 33 | SPI_MSBFIRST LITERAL1 34 | SPI0 LITERAL1 35 | SPI1 LITERAL1 -------------------------------------------------------------------------------- /libraries/SPI/library.properties: -------------------------------------------------------------------------------- 1 | name=SPI 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. 6 | paragraph=SPI is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It uses three lines common to all devices (MISO, MOSI and SCK) and one specific for each device. 7 | category=Communication 8 | url=http://arduino.cc/en/Reference/SPI 9 | architectures=k210 -------------------------------------------------------------------------------- /libraries/SPI/src/SPI.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPI__fafefef_H 2 | #define __SPI__fafefef_H 3 | 4 | #include "stdint.h" 5 | 6 | typedef enum{ 7 | SPI_SOFT = -1, 8 | SPI0 = 0, 9 | SPI1, 10 | SPI2, 11 | SPI3, 12 | SPI_MAX 13 | } spi_id_t; 14 | 15 | 16 | #define SPI_LSBFIRST 0 17 | #define SPI_MSBFIRST 1 18 | 19 | #define SPI_MODE0 0 20 | #define SPI_MODE1 1 21 | #define SPI_MODE2 2 22 | #define SPI_MODE3 3 23 | 24 | 25 | class SPISettings 26 | { 27 | public: 28 | SPISettings() :_freq(1000000), _bitOrder(SPI_MSBFIRST), _dataMode(SPI_MODE0) {} 29 | SPISettings(uint32_t freq, uint8_t bitOrder, uint8_t dataMode); 30 | uint32_t _freq; 31 | uint8_t _bitOrder; 32 | uint8_t _dataMode; 33 | }; 34 | 35 | class SPIClass 36 | { 37 | private: 38 | spi_id_t _spiNum; 39 | uint32_t _freq; 40 | int8_t _sck; 41 | int8_t _miso; 42 | int8_t _mosi; 43 | int8_t _ss; //pin 44 | int8_t _ssPeriph; //peripheral 45 | uint8_t _dataMode; 46 | uint8_t _bitOrder; 47 | bool _inTransaction; 48 | bool _initPinsInConstruct; 49 | 50 | public: 51 | SPIClass(spi_id_t spi_bus = SPI1); 52 | /* 53 | * API just for k210 54 | */ 55 | SPIClass(spi_id_t spi_bus, int8_t sck, int8_t miso, int8_t mosi, int8_t ss, uint32_t freq = 1000000); 56 | void begin(int8_t sck=27, int8_t miso=26, int8_t mosi=28, int8_t ss=-1); 57 | void end(); 58 | 59 | void setBitOrder(uint8_t bitOrder); 60 | void setDataMode(uint8_t dataMode); 61 | void setFrequency(uint32_t freq); 62 | 63 | void beginTransaction(SPISettings settings); 64 | void endTransaction(void); 65 | void transfer(uint8_t * data, uint32_t size); 66 | uint8_t transfer(uint8_t data); 67 | 68 | void transferBytes(uint8_t * data, uint8_t * out, uint32_t size); 69 | 70 | // special 71 | spi_id_t busId(){ return _spiNum; } 72 | 73 | }; 74 | 75 | extern SPIClass SPI; 76 | 77 | 78 | #endif //__SPI_H 79 | -------------------------------------------------------------------------------- /libraries/Sipeed_GC0328/examples/sipeed_gc0328.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD 5 | Sipeed_ST7789 lcd(320, 240, spi_); 6 | Sipeed_GC0328 camera(FRAMESIZE_QVGA, PIXFORMAT_RGB565, &Wire); 7 | 8 | void setup() 9 | { 10 | Serial.begin(115200); 11 | lcd.begin(15000000, COLOR_RED); 12 | if(!camera.begin()) 13 | Serial.printf("camera init fail\n"); 14 | else 15 | Serial.printf("camera init success\n"); 16 | camera.run(true); 17 | } 18 | 19 | void loop() 20 | { 21 | uint8_t*img = camera.snapshot(); 22 | if(img == nullptr || img==0) 23 | Serial.printf("snap fail\r\n"); 24 | else 25 | lcd.drawImage(0, 0, camera.width(), camera.height(), (uint16_t*)img); 26 | } 27 | -------------------------------------------------------------------------------- /libraries/Sipeed_GC0328/examples/sipeed_gc0328_binocular.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD 5 | Sipeed_ST7789 lcd(320, 240, spi_); 6 | Sipeed_GC0328 camera(FRAMESIZE_QVGA, PIXFORMAT_RGB565, &Wire); 7 | 8 | // Use left camera if true, right camera when true 9 | bool leftCamera = true; 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | lcd.begin(15000000, COLOR_RED); 15 | 16 | // Start camera in binocular mode 17 | if(!camera.begin(true)) 18 | Serial.printf("camera init fail\n"); 19 | else 20 | Serial.printf("camera init success\n"); 21 | camera.run(true); 22 | } 23 | 24 | void loop() 25 | { 26 | // Switch left/right cameras 27 | camera.shutdown(leftCamera); 28 | leftCamera = !leftCamera; 29 | 30 | uint8_t*img = camera.snapshot(); 31 | if(img == nullptr || img==0) 32 | Serial.printf("snap fail\r\n"); 33 | else 34 | lcd.drawImage(0, 0, camera.width(), camera.height(), (uint16_t*)img); 35 | } 36 | -------------------------------------------------------------------------------- /libraries/Sipeed_GC0328/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | begin KEYWORD2 14 | end KEYWORD2 15 | reset KEYWORD2 16 | setPixFormat KEYWORD2 17 | setFrameSize KEYWORD2 18 | run KEYWORD2 19 | id KEYWORD2 20 | snapshot KEYWORD2 21 | setRotation KEYWORD2 22 | setInvert KEYWORD2 23 | 24 | ####################################### 25 | # Constants (LITERAL1) 26 | ####################################### 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /libraries/Sipeed_GC0328/library.properties: -------------------------------------------------------------------------------- 1 | name=Sipeed_GC0328 2 | version=1.0 3 | author=vamoosebbf 4 | maintainer=vamoosebbf 5 | sentence=Camera Sipeed_GC0328 driver 6 | paragraph=Camera Sipeed_GC0328 driver 7 | category=Sensors 8 | url= 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Sipeed_OV2640/examples/selfie/selfie.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD 5 | Sipeed_ST7789 lcd(320, 240, spi_); 6 | 7 | Sipeed_OV2640 camera(FRAMESIZE_QVGA, PIXFORMAT_RGB565); 8 | 9 | 10 | void setup() 11 | { 12 | Serial.begin(115200); 13 | lcd.begin(15000000, COLOR_RED); 14 | if(!camera.begin()) 15 | Serial.printf("camera init fail\n"); 16 | else 17 | Serial.printf("camera init success\n"); 18 | camera.run(true); 19 | } 20 | 21 | void loop() 22 | { 23 | uint8_t*img = camera.snapshot(); 24 | if(img == nullptr || img==0) 25 | Serial.printf("snap fail\n"); 26 | else 27 | lcd.drawImage(0, 0, camera.width(), camera.height(), (uint16_t*)img); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /libraries/Sipeed_OV2640/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | begin KEYWORD2 14 | end KEYWORD2 15 | reset KEYWORD2 16 | setPixFormat KEYWORD2 17 | setFrameSize KEYWORD2 18 | run KEYWORD2 19 | id KEYWORD2 20 | snapshot KEYWORD2 21 | setRotation KEYWORD2 22 | setInvert KEYWORD2 23 | 24 | ####################################### 25 | # Constants (LITERAL1) 26 | ####################################### 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /libraries/Sipeed_OV2640/library.properties: -------------------------------------------------------------------------------- 1 | name=Sipeed_OV2640 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=Camera Sipeed_OV2640 driver 6 | paragraph=Camera Sipeed_OV2640 driver 7 | category=Sensors 8 | url= 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Sipeed_ST7789/examples/basic_display/basic_display.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD 4 | Sipeed_ST7789 lcd(320, 240, spi_); 5 | 6 | 7 | void func() 8 | { 9 | lcd.fillScreen(COLOR_RED); 10 | lcd.drawRect(20, 20, 50, 50, COLOR_WHITE); 11 | lcd.fillCircle(100, 100, 40, COLOR_WHITE); 12 | lcd.fillTriangle(10, 200, 300, 200, 300, 150, COLOR_WHITE); 13 | lcd.setTextSize(2); 14 | lcd.setTextColor(COLOR_WHITE); 15 | lcd.setCursor(100,30); 16 | lcd.println("hello Sipeed Maix"); 17 | } 18 | 19 | void func2() 20 | { 21 | lcd.fillScreen(COLOR_RED); 22 | lcd.drawRect(20, 20, 50, 50, COLOR_WHITE); 23 | lcd.fillCircle(180, 50, 40, COLOR_WHITE); 24 | lcd.fillTriangle(10, 300, 200, 300, 200, 150, COLOR_WHITE); 25 | lcd.setTextSize(2); 26 | lcd.setTextColor(COLOR_WHITE); 27 | lcd.setCursor(1,100); 28 | lcd.println("hello Sipeed Maix"); 29 | } 30 | 31 | void setup() 32 | { 33 | lcd.begin(15000000, COLOR_RED); 34 | } 35 | 36 | void loop() 37 | { 38 | lcd.setRotation(0); 39 | func(); 40 | delay(3000); 41 | lcd.invertDisplay(true); 42 | func(); 43 | delay(3000); 44 | lcd.setRotation(1); 45 | func2(); 46 | delay(3000); 47 | lcd.setRotation(2); 48 | func(); 49 | delay(3000); 50 | lcd.setRotation(3); 51 | func2(); 52 | delay(3000); 53 | } 54 | -------------------------------------------------------------------------------- /libraries/Sipeed_ST7789/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Sipeed_ST7789 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | drawPixel KEYWORD2 16 | writePixel KEYWORD2 17 | writeFillRect KEYWORD2 18 | writeFastVLine KEYWORD2 19 | writeFastHLine KEYWORD2 20 | drawFastVLine KEYWORD2 21 | drawFastHLine KEYWORD2 22 | fillRect KEYWORD2 23 | fillScreen KEYWORD2 24 | drawRect KEYWORD2 25 | setRotation KEYWORD2 26 | invertDisplay KEYWORD2 27 | 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | 32 | COLOR_BLACK LITERAL1 33 | COLOR_NAVY LITERAL1 34 | COLOR_DARKGREEN LITERAL1 35 | COLOR_DARKCYAN LITERAL1 36 | COLOR_MAROON LITERAL1 37 | COLOR_PURPLE LITERAL1 38 | COLOR_OLIVE LITERAL1 39 | COLOR_LIGHTGREY LITERAL1 40 | COLOR_DARKGREY LITERAL1 41 | COLOR_BLUE LITERAL1 42 | COLOR_GREEN LITERAL1 43 | COLOR_CYAN LITERAL1 44 | COLOR_RED LITERAL1 45 | COLOR_MAGENTA LITERAL1 46 | COLOR_YELLOW LITERAL1 47 | COLOR_WHITE LITERAL1 48 | COLOR_ORANGE LITERAL1 49 | COLOR_GREENYELLOW LITERAL1 50 | COLOR_PINK LITERAL1 51 | 52 | -------------------------------------------------------------------------------- /libraries/Sipeed_ST7789/library.properties: -------------------------------------------------------------------------------- 1 | name=Sipeed_ST7789 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=LCD display st7789 driver 6 | paragraph=LCD display st7789 driver 7 | category=Display 8 | url= 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Sipeed_ST7789/src/Sipeed_ST7789.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIPEED_ST7789_H 2 | #define _SIPEED_ST7789_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | 9 | #if (defined(BOARD_SIPEED_MAIX_GO) || defined(BOARD_SIPEED_MAIX_ONE_DOCK) ) 10 | #define SIPEED_ST7789_RST_PIN 37 11 | #define SIPEED_ST7789_DCX_PIN 38 12 | #define SIPEED_ST7789_SS_PIN 36 13 | #define SIPEED_ST7789_SCLK_PIN 39 14 | #else 15 | #define SIPEED_ST7789_RST_PIN 37 16 | #define SIPEED_ST7789_DCX_PIN 38 17 | #define SIPEED_ST7789_SS_PIN 36 18 | #define SIPEED_ST7789_SCLK_PIN 39 19 | #endif 20 | 21 | // default peripheral 22 | #define SIPEED_ST7789_RST_GPIONUM 6 23 | #define SIPEED_ST7789_DCX_GPIONUM 7 24 | #define SIPEED_ST7789_SS 3 25 | 26 | 27 | #define COLOR_BLACK 0x0000 28 | #define COLOR_NAVY 0x000F 29 | #define COLOR_DARKGREEN 0x03E0 30 | #define COLOR_DARKCYAN 0x03EF 31 | #define COLOR_MAROON 0x7800 32 | #define COLOR_PURPLE 0x780F 33 | #define COLOR_OLIVE 0x7BE0 34 | #define COLOR_LIGHTGREY 0xC618 35 | #define COLOR_DARKGREY 0x7BEF 36 | #define COLOR_BLUE 0x001F 37 | #define COLOR_GREEN 0x07E0 38 | #define COLOR_CYAN 0x07FF 39 | #define COLOR_RED 0xF800 40 | #define COLOR_MAGENTA 0xF81F 41 | #define COLOR_YELLOW 0xFFE0 42 | #define COLOR_WHITE 0xFFFF 43 | #define COLOR_ORANGE 0xFD20 44 | #define COLOR_GREENYELLOW 0xAFE5 45 | #define COLOR_PINK 0xF81F 46 | 47 | 48 | class Sipeed_ST7789 : public Adafruit_GFX{ 49 | public: 50 | /** 51 | * @param rst_pin -1: not use reset pin 52 | */ 53 | Sipeed_ST7789(uint16_t w, uint16_t h, SPIClass& spi, int8_t dc_pin = SIPEED_ST7789_DCX_PIN, int8_t rst_pin = SIPEED_ST7789_RST_PIN , uint8_t dma_ch = 3); 54 | 55 | ~Sipeed_ST7789(void); 56 | 57 | boolean begin( uint32_t freq = 15000000, uint16_t color = 0xffff ); 58 | 59 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color); 60 | virtual void writePixel(int16_t x, int16_t y, uint16_t color); 61 | virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 62 | virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 63 | virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 64 | 65 | virtual void 66 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 67 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 68 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 69 | fillScreen(uint16_t color), 70 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 71 | 72 | void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth); 73 | 74 | virtual void setRotation(uint8_t r); 75 | virtual void invertDisplay(boolean invert); 76 | 77 | void drawImage(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t* img); 78 | 79 | private: 80 | SPIClass& _spi; 81 | int8_t _dcxPin; 82 | int8_t _rstPin; 83 | uint8_t _dmaCh; 84 | uint32_t _freq; 85 | uint16_t _screenDir; 86 | 87 | 88 | }; 89 | 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /libraries/Sipeed_ST7789/src/lcd.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Canaan Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #ifndef _LCD_H_ 16 | #define _LCD_H_ 17 | 18 | #include 19 | #include "st7789.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | 26 | /* clang-format off */ 27 | #define LCD_X_MAX (240) 28 | #define LCD_Y_MAX (320) 29 | #define LCD_MAX_PIXELS (76800) //LCD_X_MAX*LCD_Y_MAX 30 | 31 | #define BLACK 0x0000 32 | #define NAVY 0x000F 33 | #define DARKGREEN 0x03E0 34 | #define DARKCYAN 0x03EF 35 | #define MAROON 0x7800 36 | #define PURPLE 0x780F 37 | #define OLIVE 0x7BE0 38 | #define LIGHTGREY 0xC618 39 | #define DARKGREY 0x7BEF 40 | #define BLUE 0x001F 41 | #define GREEN 0x07E0 42 | #define CYAN 0x07FF 43 | #define RED 0xF800 44 | #define MAGENTA 0xF81F 45 | #define YELLOW 0xFFE0 46 | #define WHITE 0xFFFF 47 | #define ORANGE 0xFD20 48 | #define GREENYELLOW 0xAFE5 49 | #define PINK 0xF81F 50 | #define USER_COLOR 0xAA55 51 | /* clang-format on */ 52 | 53 | typedef enum _lcd_dir 54 | { 55 | DIR_XY_RLUD = 0x00, 56 | DIR_YX_RLUD = 0x20, 57 | DIR_XY_LRUD = 0x40, 58 | DIR_YX_LRUD = 0x60, 59 | DIR_XY_RLDU = 0x80, 60 | DIR_YX_RLDU = 0xA0, 61 | DIR_XY_LRDU = 0xC0, 62 | DIR_YX_LRDU = 0xE0, 63 | DIR_XY_MASK = 0x20, 64 | DIR_RL_MASK = 0x40, 65 | DIR_UD_MASK = 0x80 66 | } lcd_dir_t; 67 | 68 | typedef struct _lcd_ctl 69 | { 70 | uint8_t mode; 71 | uint8_t dir; 72 | uint16_t width; 73 | uint16_t height; 74 | } lcd_ctl_t; 75 | 76 | void lcd_polling_enable(void); 77 | void lcd_interrupt_enable(void); 78 | void lcd_init(uint8_t spi, uint8_t ss, uint8_t rst, uint8_t dcx, uint32_t freq, int8_t rst_pin, int8_t dcx_pin, uint8_t dma_ch); 79 | void lcd_clear(uint16_t color); 80 | void lcd_set_freq(uint32_t freq); 81 | uint32_t lcd_get_freq(); 82 | void lcd_set_direction(lcd_dir_t dir); 83 | void lcd_set_area(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); 84 | void lcd_draw_point(uint16_t x, uint16_t y, uint16_t color); 85 | void lcd_draw_string(uint16_t x, uint16_t y, char *str, uint16_t color); 86 | void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t *ptr); 87 | void lcd_draw_pic_roi(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t rx, uint16_t ry, uint16_t rw, uint16_t rh, uint32_t *ptr); 88 | void lcd_draw_pic_gray(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint8_t *ptr); 89 | void lcd_draw_pic_grayroi(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t rx, uint16_t ry, uint16_t rw, uint16_t rh, uint8_t *ptr); 90 | void lcd_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 91 | void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t width, uint16_t color); 92 | void lcd_ram_cpyimg(char* lcd, int lcdw, char* img, int imgw, int imgh, int x, int y); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /libraries/Ticker/examples/Arguments/Arguments.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // attach a LED to GPIO 21 5 | #define LED_PIN 13 6 | 7 | Ticker tickerSetHigh(TIMER1); 8 | Ticker tickerSetLow(TIMER2); 9 | 10 | void setPin(int state) { 11 | digitalWrite(LED_PIN, state); 12 | } 13 | 14 | void setup() { 15 | pinMode(LED_PIN, OUTPUT); 16 | 17 | // every 25 ms, call setPin(0) 18 | tickerSetLow.attach_ms(25, setPin, 0); 19 | 20 | // every 26 ms, call setPin(1) 21 | tickerSetHigh.attach_ms(26, setPin, 1); 22 | } 23 | 24 | void loop() { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /libraries/Ticker/examples/Blinker/Blinker.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // attach a LED to pPIO 13 5 | #define LED_PIN 13 6 | 7 | Ticker blinker(TIMER0); 8 | Ticker toggler(TIMER1); 9 | Ticker changer(TIMER2); 10 | float blinkerPace = 0.1; //seconds 11 | const float togglePeriod = 5; //seconds 12 | 13 | void change() { 14 | blinkerPace = 0.5; 15 | } 16 | 17 | void blink() { 18 | digitalWrite(LED_PIN, !digitalRead(LED_PIN)); 19 | } 20 | 21 | void toggle() { 22 | static bool isBlinking = false; 23 | if (isBlinking) { 24 | blinker.detach(); 25 | isBlinking = false; 26 | } 27 | else { 28 | blinker.attach(blinkerPace, blink); 29 | isBlinking = true; 30 | } 31 | digitalWrite(LED_PIN, LOW); //make sure LED on on after toggling (pin LOW = led ON) 32 | } 33 | 34 | void setup() { 35 | pinMode(LED_PIN, OUTPUT); 36 | toggler.attach(togglePeriod, toggle); 37 | changer.once(30, change); 38 | } 39 | 40 | void loop() { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /libraries/Ticker/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Datatypes (KEYWORD1) 3 | ####################################### 4 | 5 | Ticker KEYWORD1 6 | 7 | ####################################### 8 | # Methods and Functions (KEYWORD2) 9 | ####################################### 10 | 11 | attach KEYWORD2 12 | attach_ms KEYWORD2 13 | attach_us KEYWORD2 14 | once KEYWORD2 15 | once_ms KEYWORD2 16 | once_us KEYWORD2 17 | detach KEYWORD2 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | TIMER0 LITERAL1 23 | TIMER1 LITERAL1 24 | TIMER2 LITERAL1 25 | -------------------------------------------------------------------------------- /libraries/Ticker/library.properties: -------------------------------------------------------------------------------- 1 | name=Ticker 2 | version=1.0 3 | author=BigBits 4 | maintainer=BigBits 5 | sentence=Allows to call functions with a given interval. 6 | paragraph=Allows to call functions with a given interval. 7 | category=Timing 8 | url= 9 | architectures=k210 -------------------------------------------------------------------------------- /libraries/Ticker/src/Ticker.cpp: -------------------------------------------------------------------------------- 1 | #include "Ticker.h" 2 | #include "sysctl.h" 3 | 4 | static int timer_callback(void* ctx); 5 | 6 | Ticker::Ticker(timer_id_t id) 7 | :timer_id(id) 8 | { 9 | timer_init(timer_device_number_t(timer_id)); 10 | } 11 | 12 | Ticker::~Ticker() 13 | { 14 | detach(); 15 | } 16 | 17 | void 18 | Ticker::_attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, size_t arg) 19 | { 20 | user_callback = callback; 21 | _arg = arg; 22 | timer_set_interval(timer_device_number_t(timer_id), TIMER_CHANNEL_0, milliseconds * 1000000); 23 | timer_irq_register(timer_device_number_t(timer_id), TIMER_CHANNEL_0, !repeat, 4, timer_callback, this); 24 | timer_set_enable(timer_device_number_t(timer_id), TIMER_CHANNEL_0, 1); 25 | sysctl_enable_irq(); 26 | } 27 | 28 | void 29 | Ticker::_attach_us(uint32_t microseconds, bool repeat, callback_with_arg_t callback, size_t arg) 30 | { 31 | user_callback = callback; 32 | _arg = arg; 33 | timer_set_interval(timer_device_number_t(timer_id), TIMER_CHANNEL_0, microseconds * 1000); 34 | timer_irq_register(timer_device_number_t(timer_id), TIMER_CHANNEL_0, !repeat, 4, timer_callback, this); 35 | timer_set_enable(timer_device_number_t(timer_id), TIMER_CHANNEL_0, 1); 36 | sysctl_enable_irq(); 37 | } 38 | 39 | void 40 | Ticker::detach() 41 | { 42 | timer_irq_unregister(timer_device_number_t(timer_id), TIMER_CHANNEL_0); 43 | timer_set_enable(timer_device_number_t(timer_id), TIMER_CHANNEL_0, 0); 44 | } 45 | 46 | static int timer_callback(void* ctx) 47 | { 48 | auto &driver = *reinterpret_cast(ctx); 49 | driver.user_callback((void *)driver._arg); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /libraries/Wire/examples/i2c_rxtx/i2c_rxtx.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void setup() { 5 | Serial.begin (115200); 6 | 7 | // Leonardo: wait for serial port to connect 8 | while (!Serial) 9 | { 10 | } 11 | 12 | Serial.println (); 13 | Serial.println ("I2C Testing ..."); 14 | byte count = 0; 15 | 16 | Wire.begin(); 17 | Wire.beginTransmission(0x3C); 18 | Wire.write(0x80); 19 | Wire.write(0xAF); 20 | Wire.endTransmission(); 21 | Serial.println ("Done."); 22 | 23 | } // end of setup 24 | 25 | void loop() {} 26 | -------------------------------------------------------------------------------- /libraries/Wire/examples/i2c_scaner/i2c_scaner.ino: -------------------------------------------------------------------------------- 1 | // I2C Scanner 2 | // Written by Nick Gammon 3 | // Date: 20th April 2011 4 | 5 | #include 6 | 7 | void setup() { 8 | Serial.begin (115200); 9 | 10 | // Leonardo: wait for serial port to connect 11 | while (!Serial) 12 | { 13 | } 14 | 15 | Serial.println (); 16 | Serial.println ("I2C scanner. Scanning ..."); 17 | byte count = 0; 18 | 19 | Wire.begin(); 20 | for (byte i = 8; i < 120; i++) 21 | { 22 | Wire.beginTransmission (i); 23 | if (Wire.endTransmission () == 0) 24 | { 25 | Serial.print ("Found address: "); 26 | Serial.print (i, DEC); 27 | Serial.print (" (0x"); 28 | Serial.print (i, HEX); 29 | Serial.println (")"); 30 | count++; 31 | //delay (1); // maybe unneeded? 32 | } // end of good response 33 | } // end of for loop 34 | Serial.println ("Done."); 35 | Serial.print ("Found "); 36 | Serial.print (count, DEC); 37 | Serial.println (" device(s)."); 38 | } // end of setup 39 | 40 | void loop() {} 41 | -------------------------------------------------------------------------------- /libraries/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | setClock KEYWORD2 15 | setClockStretchLimit KEYWORD2 16 | beginTransmission KEYWORD2 17 | endTransmission KEYWORD2 18 | requestFrom KEYWORD2 19 | send KEYWORD2 20 | receive KEYWORD2 21 | onReceive KEYWORD2 22 | onRequest KEYWORD2 23 | 24 | ####################################### 25 | # Instances (KEYWORD2) 26 | ####################################### 27 | 28 | Wire KEYWORD2 29 | Wire1 KEYWORD2 30 | Wire2 KEYWORD2 31 | 32 | ####################################### 33 | # Constants (LITERAL1) 34 | ####################################### 35 | 36 | -------------------------------------------------------------------------------- /libraries/Wire/library.properties: -------------------------------------------------------------------------------- 1 | name=Wire 2 | version=1.0.0 3 | author=Bigbits 4 | maintainer= 5 | sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For k210 boards. 6 | paragraph= 7 | category=Signal Input/Output 8 | url=http://arduino.cc/en/Reference/Wire 9 | architectures=k210 10 | -------------------------------------------------------------------------------- /libraries/Wire/src/Wire.h: -------------------------------------------------------------------------------- 1 | #ifndef TwoWire_h 2 | #define TwoWire_h 3 | 4 | #include "Arduino.h" 5 | #include "Stream.h" 6 | #include "RingBuffer.h" 7 | 8 | #include "fpioa.h" 9 | #include "i2c.h" 10 | 11 | #define I2C_BUFFER_LENGTH 128 12 | 13 | #define I2C_CON_SPEED_STANDARD 1 // <=100Kbit/s 14 | #define I2C_CON_SPEED_FAST 2 // <=400Kbit/s or <=1000Kbit/s 15 | #define I2C_CON_SPEED_HIGH 3 // <=3.4Mbit/s 16 | 17 | typedef void(*user_onRequest)(void); 18 | typedef void(*user_onReceive)(uint8_t*, int); 19 | 20 | class TwoWire : public Stream 21 | { 22 | public: 23 | i2c_device_number_t _i2c_num; 24 | 25 | TwoWire(i2c_device_number_t i2c_device); 26 | ~TwoWire(); 27 | void begin(uint8_t sda = SDA, uint8_t scl = SCL, uint32_t frequency = 400000); 28 | void begin(uint16_t slave_address, uint8_t sda = SDA, uint8_t scl = SCL); 29 | 30 | void setClock(uint32_t frequency); 31 | uint32_t getClock(); 32 | 33 | void setTimeOut(uint16_t timeOutMillis); 34 | uint16_t getTimeOut(); 35 | 36 | int writeTransmission(uint16_t address, uint8_t* send_buf, size_t send_buf_len, bool sendStop); 37 | int readTransmission(uint16_t address, uint8_t* receive_buf, size_t receive_buf_len, bool sendStop); 38 | 39 | void beginTransmission(uint16_t address); 40 | void beginTransmission(uint8_t address); 41 | void beginTransmission(int address); 42 | 43 | uint8_t endTransmission(bool sendStop); 44 | uint8_t endTransmission(void); 45 | 46 | uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop); 47 | uint8_t requestFrom(uint16_t address, uint8_t size, uint8_t sendStop); 48 | uint8_t requestFrom(uint16_t address, uint8_t size); 49 | uint8_t requestFrom(uint8_t address, uint8_t size, uint8_t sendStop); 50 | uint8_t requestFrom(uint8_t address, uint8_t size); 51 | uint8_t requestFrom(int address, int size, int sendStop); 52 | uint8_t requestFrom(int address, int size); 53 | 54 | size_t write(uint8_t); 55 | size_t write(const uint8_t *, int); 56 | int available(void); 57 | int read(void); 58 | int peek(void); 59 | int flush(void); 60 | 61 | inline int write(const char * s) 62 | { 63 | return write((uint8_t*) s, strlen(s)); 64 | } 65 | inline int write(unsigned long n) 66 | { 67 | return write((uint8_t)n); 68 | } 69 | inline int write(long n) 70 | { 71 | return write((uint8_t)n); 72 | } 73 | inline int write(unsigned int n) 74 | { 75 | return write((uint8_t)n); 76 | } 77 | inline int write(int n) 78 | { 79 | return write((uint8_t)n); 80 | } 81 | 82 | void onReceive( void (*)(int) ); 83 | void onRequest( void (*)(void) ); 84 | 85 | uint8_t on_event(i2c_event_t event); 86 | uint8_t on_transmit(); 87 | void on_receive(uint8_t rec_data); 88 | 89 | bool busy(); 90 | 91 | void scan(); 92 | 93 | private: 94 | uint16_t i2c_slave_address; 95 | bool is_master_mode = false; 96 | uint32_t address_width = 7; 97 | uint8_t sda = FPIOA_NUM_IO; 98 | uint8_t scl = FPIOA_NUM_IO; 99 | uint32_t i2c_clk; 100 | fpioa_function_t sda_func; 101 | fpioa_function_t scl_func; 102 | 103 | RingBuffer *i2c_tx_buff; 104 | RingBuffer *i2c_rx_buff; 105 | 106 | uint16_t txAddress; 107 | uint8_t transmitting; 108 | 109 | uint16_t _timeOutMillis; 110 | 111 | bool slave_irq_event_start = false; 112 | 113 | void (*slave_recv_handler)(int) ; 114 | void (*slave_send_handler)(void) ; 115 | 116 | }; 117 | 118 | 119 | 120 | extern volatile i2c_t* const i2c[3]; 121 | 122 | extern TwoWire Wire; 123 | extern TwoWire Wire1; 124 | extern TwoWire Wire2; 125 | 126 | #endif //TwoWire_h -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "framework-maixduino", 3 | "description": "Arduino Wiring-based Framework (K210 Core)", 4 | "version": "0.3.11", 5 | "url": "https://github.com/sipeed/Maixduino" 6 | } -------------------------------------------------------------------------------- /programmers.txt: -------------------------------------------------------------------------------- 1 | kflash.name=k-flash 2 | kflash.communication=usb 3 | kflash.program.params.verbose=-v 4 | kflash.program.params.quiet=-q 5 | kflash.program.tool=kflash -------------------------------------------------------------------------------- /variants/ioxgd4/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_IOXGD4 2 | #define _VARIANT_IOXGD4 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* LEDs */ 22 | #define PIN_LED_GREEN 13 23 | #define PIN_LED_BLUE 12 24 | #define PIN_LED_RED 14 25 | #define PIN_LED 13 26 | #define LED_BUILTIN 13 27 | #define LED_GREEN 13 28 | #define LED_BLUE 12 29 | #define LED_RED 14 30 | /* KEY */ 31 | #define KEY0 16 32 | /* MIC ARRAY */ 33 | #define MIC_BCK 18 34 | #define MIC_WS 19 35 | #define MIC_DAT3 20 36 | #define MIC_DAT2 21 37 | #define MIC_DAT1 22 38 | #define MIC_DAT0 23 39 | #define MIC_LED_DAT 24 40 | /* SPI0 */ 41 | #define SPI0_CS1 25 42 | #define SPI0_MISO 26 43 | #define SPI0_SCLK 27 44 | #define SPI0_MOSI 28 45 | #define SPI0_CS0 29 46 | /* I2S */ 47 | #define MIC0_WS 30 48 | #define MIC0_DATA 31 49 | #define MIC0_BCK 32 50 | #define I2S_WS 33 51 | #define I2S_DA 34 52 | #define I2S_BCK 35 53 | /* LCD */ 54 | #define LCD_CS 36 55 | #define LCD_RST 37 56 | #define LCD_DC 38 57 | #define LCD_WR 39 58 | 59 | #define RX0 4 60 | #define TX0 5 61 | 62 | #define RX1 7 63 | #define TX1 6 64 | 65 | #define SDA 33 66 | #define SCL 32 67 | 68 | #define MD_PIN_MAP(fpio) (fpio) 69 | #define ORG_PIN_MAP(org_pin) (org_pin) 70 | 71 | static const uint8_t SS = SPI0_CS0 ; 72 | static const uint8_t MOSI = SPI0_MOSI; 73 | static const uint8_t MISO = SPI0_MISO; 74 | static const uint8_t SCK = SPI0_SCLK; 75 | 76 | typedef struct _pwm_fpio_set_t{ 77 | pwm_channel_number_t channel; 78 | pwm_device_number_t device; 79 | uint8_t inuse; 80 | }pwm_fpio_set_t; 81 | 82 | 83 | 84 | #define VARIANT_NUM_GPIOHS (32) 85 | #define VARIANT_NUM_GPIO ( 8) 86 | #define VARIANT_NUM_PWM (12) 87 | #define VARIANT_NUM_I2C ( 3) 88 | #define VARIANT_NUM_SPI ( 3) 89 | #define VARIANT_NUM_UART ( 3) 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /variants/lamloei_aiot_daan/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_LAMLOEI_AIOT_DAAN 2 | #define _VARIANT_LAMLOEI_AIOT_DAAN 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* LEDs */ 22 | #define PIN_LED_GREEN 13 23 | #define PIN_LED_BLUE 12 24 | #define PIN_LED_RED 14 25 | #define PIN_LED 13 26 | #define LED_BUILTIN 13 27 | #define LED_GREEN 13 28 | #define LED_BLUE 12 29 | #define LED_RED 14 30 | /* KEY */ 31 | #define KEY0 16 32 | /* MIC ARRAY */ 33 | #define MIC_BCK 18 34 | #define MIC_WS 19 35 | #define MIC_DAT3 20 36 | #define MIC_DAT2 21 37 | #define MIC_DAT1 22 38 | #define MIC_DAT0 23 39 | #define MIC_LED_DAT 24 40 | /* SPI0 */ 41 | #define SPI0_CS1 25 42 | #define SPI0_MISO 26 43 | #define SPI0_SCLK 27 44 | #define SPI0_MOSI 28 45 | #define SPI0_CS0 29 46 | /* I2S */ 47 | #define MIC0_WS 30 48 | #define MIC0_DATA 31 49 | #define MIC0_BCK 32 50 | #define I2S_WS 33 51 | #define I2S_DA 34 52 | #define I2S_BCK 35 53 | /* LCD */ 54 | #define LCD_CS 36 55 | #define LCD_RST 37 56 | #define LCD_DC 38 57 | #define LCD_WR 39 58 | 59 | #define RX0 4 60 | #define TX0 5 61 | 62 | #define RX1 6 63 | #define TX1 7 64 | 65 | #define SDA 31 66 | #define SCL 30 67 | 68 | #define MD_PIN_MAP(fpio) (fpio) 69 | #define ORG_PIN_MAP(org_pin) (org_pin) 70 | 71 | static const uint8_t SS = SPI0_CS0 ; 72 | static const uint8_t MOSI = SPI0_MOSI; 73 | static const uint8_t MISO = SPI0_MISO; 74 | static const uint8_t SCK = SPI0_SCLK; 75 | 76 | typedef struct _pwm_fpio_set_t{ 77 | pwm_channel_number_t channel; 78 | pwm_device_number_t device; 79 | uint8_t inuse; 80 | }pwm_fpio_set_t; 81 | 82 | 83 | 84 | #define VARIANT_NUM_GPIOHS (32) 85 | #define VARIANT_NUM_GPIO ( 8) 86 | #define VARIANT_NUM_PWM (12) 87 | #define VARIANT_NUM_I2C ( 3) 88 | #define VARIANT_NUM_SPI ( 3) 89 | #define VARIANT_NUM_UART ( 3) 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /variants/m5stack_m5stick_v/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_M5STACK_M5STICK_V 2 | #define _VARIANT_M5STACK_M5STICK_V 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UART */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* LEDs */ 25 | #define PIN_LED_RED 6 26 | #define PIN_LED_WHITE 7 27 | #define PIN_LED_BLUE 8 28 | #define PIN_LED_GREEN 9 29 | #define PIN_LED 9 30 | #define LED_RED 6 31 | #define LED_WHITE 7 32 | #define LED_BLUE 8 33 | #define LED_GREEN 9 34 | #define LED_BUILTIN 9 35 | /* MIC ARRAY */ 36 | #define MIC_WS 10 37 | #define MIC_DAT3 12 38 | #define MIC_BCK 13 39 | /* SPK MAX98357 */ 40 | #define I2S_SD 11 41 | #define I2S_LRCLK 14 42 | #define I2S_BCLK 15 43 | #define I2S_DIN 17 44 | /* LCD ST7789 135x240 */ 45 | #define LCD_SDA 18 46 | #define LCD_SCL 19 47 | #define LCD_DC 20 48 | #define LCD_RST 21 49 | #define LCD_CS 22 50 | /* AXP192 INT PIN */ 51 | #define INTL_INT 23 52 | /* INTL I2C - AXP192, MPU6886 */ 53 | #define SCL 28 54 | #define SDA 29 55 | /* SPI0 */ 56 | #define SPI0_SCLK 30 57 | #define SPI0_MISO 31 58 | #define SPI0_CS0 32 59 | #define SPI0_MOSI 33 60 | /* GROVE */ 61 | #define RX1 34 62 | #define TX1 35 63 | #define EXTL_SCL 34 64 | #define EXTL_SDA 35 65 | /* BUTTONS */ 66 | #define BTN_A 36 67 | #define BTN_B 37 68 | #define KEY0 36 69 | #define KEY1 37 70 | 71 | #define MD_PIN_MAP(fpio) (fpio) 72 | #define ORG_PIN_MAP(org_pin) (org_pin) 73 | 74 | static const uint8_t SS = SPI0_CS0 ; 75 | static const uint8_t MOSI = SPI0_MOSI; 76 | static const uint8_t MISO = SPI0_MISO; 77 | static const uint8_t SCK = SPI0_SCLK; 78 | 79 | typedef struct _pwm_fpio_set_t{ 80 | pwm_channel_number_t channel; 81 | pwm_device_number_t device; 82 | uint8_t inuse; 83 | } pwm_fpio_set_t; 84 | 85 | 86 | #define VARIANT_NUM_GPIOHS (32) 87 | #define VARIANT_NUM_GPIO ( 8) 88 | #define VARIANT_NUM_PWM (12) 89 | #define VARIANT_NUM_I2C ( 3) 90 | #define VARIANT_NUM_SPI ( 3) 91 | #define VARIANT_NUM_UART ( 3) 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /variants/m5stack_m5unit_v/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_M5STACK_M5UNIT_V 2 | #define _VARIANT_M5STACK_M5UNIT_V 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UART */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* WS2812 LEDs */ 25 | #define PIN_LED_RGB 8 26 | 27 | /* MIC ARRAY */ 28 | #define MIC_WS 10 29 | #define MIC_DAT3 12 30 | #define MIC_BCK 13 31 | /* SPK MAX98357 */ 32 | #define SPK_LRCLK 14 33 | #define SPK_BCLK 15 34 | #define SPK_DIN 17 35 | #define SPK_SD 25 36 | /* BUTTONS */ 37 | #define BTN_A 18 38 | #define BTN_B 19 39 | #define KEY0 18 40 | #define KEY1 19 41 | /* AXP192 INT PIN */ 42 | #define AXP_INT 23 43 | /* INTL I2C */ 44 | #define SCL 28 45 | #define SDA 29 46 | /* SPI0 */ 47 | #define SPI0_SCLK 30 48 | #define SPI0_MISO 31 49 | #define SPI0_CS0 32 50 | #define SPI0_MOSI 33 51 | /* EXTL I2C */ 52 | #define EXTL_SCL 34 53 | #define EXTL_SDA 35 54 | 55 | 56 | #define MD_PIN_MAP(fpio) (fpio) 57 | #define ORG_PIN_MAP(org_pin) (org_pin) 58 | 59 | static const uint8_t SS = SPI0_CS0 ; 60 | static const uint8_t MOSI = SPI0_MOSI; 61 | static const uint8_t MISO = SPI0_MISO; 62 | static const uint8_t SCK = SPI0_SCLK; 63 | 64 | typedef struct _pwm_fpio_set_t{ 65 | pwm_channel_number_t channel; 66 | pwm_device_number_t device; 67 | uint8_t inuse; 68 | }pwm_fpio_set_t; 69 | 70 | 71 | #define VARIANT_NUM_GPIOHS (32) 72 | #define VARIANT_NUM_GPIO ( 8) 73 | #define VARIANT_NUM_PWM (12) 74 | #define VARIANT_NUM_I2C ( 3) 75 | #define VARIANT_NUM_SPI ( 3) 76 | #define VARIANT_NUM_UART ( 3) 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /variants/sipeed_maix_amigo/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_AMIGO 2 | #define _VARIANT_SIPEED_MAIX_AMIGO 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS CH552T */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* UART Grove */ 25 | #define RX1 9 //Grove 26 | #define TX1 7 //Grove 27 | /* 8P Connector */ 28 | // #define PB0 8 //8P-12 29 | // #define PB1 12 //8P-3 30 | /* SPI0 */ 31 | #define SPI0_MISO 6 //8P-11 32 | #define SPI0_MOSI 10 //8P-2 33 | #define SPI0_SCLK 11 //8P-1 34 | #define SPI0_CS0 26 //TF 35 | /* KEYs */ 36 | #define KEY2 20 //Grove 37 | #define KEY1 23 //Grove 38 | /* LEDs */ 39 | #define PIN_LED_RED 14 40 | #define PIN_LED_GREEN 15 41 | #define PIN_LED_BLUE 17 42 | #define PIN_LED 15 43 | #define LED_RED 14 44 | #define LED_GREEN 15 45 | #define LED_BLUE 17 46 | #define LED_BUILTIN 15 47 | /* UART3 */ 48 | #define TX2 22 //8P-4 49 | #define RX2 25 //8P-5 50 | /* I2C1 - AXP173, MSA301, TOUCH */ 51 | #define SCL 24 52 | #define SDA 27 53 | /* USB_SBU */ 54 | #define USB_DP 28 //8P-8 55 | #define USB_DM 29 //8P-9 56 | /* I2S AUDIO CODEC ES8374 */ 57 | #define I2S2_MCLK 13 58 | #define I2S2_WS 18 59 | #define I2S2_SCLK 21 60 | #define I2S2_DOUT 34 61 | #define I2S2_DIN 35 62 | /* Flash LED */ 63 | #define WLED_EN 32 64 | /* TouchScreen */ 65 | #define CAP_TOUCH_IRQ 33 66 | /* LCD */ 67 | #define LCD_TEN 19 68 | #define LCD_CS 36 69 | #define LCD_RST 37 70 | #define LCD_DC 38 71 | #define LCD_WR 39 72 | 73 | 74 | #define MD_PIN_MAP(fpio) (fpio) 75 | #define ORG_PIN_MAP(org_pin) (org_pin) 76 | 77 | static const uint8_t SS = SPI0_CS0 ; 78 | static const uint8_t MOSI = SPI0_MOSI; 79 | static const uint8_t MISO = SPI0_MISO; 80 | static const uint8_t SCK = SPI0_SCLK; 81 | 82 | typedef struct _pwm_fpio_set_t{ 83 | pwm_channel_number_t channel; 84 | pwm_device_number_t device; 85 | uint8_t inuse; 86 | } pwm_fpio_set_t; 87 | 88 | 89 | #define VARIANT_NUM_GPIOHS (32) 90 | #define VARIANT_NUM_GPIO ( 8) 91 | #define VARIANT_NUM_PWM (12) 92 | #define VARIANT_NUM_I2C ( 3) 93 | #define VARIANT_NUM_SPI ( 3) 94 | #define VARIANT_NUM_UART ( 3) 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /variants/sipeed_maix_bit/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_BIT 2 | #define _VARIANT_SIPEED_MAIX_BIT 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* UART */ 25 | #define RX1 6 26 | #define TX1 7 27 | 28 | // #define IO_8 8 29 | // #define IO_9 9 30 | // #define IO_10 10 31 | /* LEDs */ 32 | #define PIN_LED_GREEN 12 33 | #define PIN_LED_RED 13 34 | #define PIN_LED_BLUE 14 35 | #define PIN_LED 12 36 | #define LED_RED 13 37 | #define LED_GREEN 12 38 | #define LED_BLUE 14 39 | #define LED_BUILTIN 12 40 | // #define IO_15 15 41 | // #define IO_17 17 42 | 43 | /* I2S MIC */ 44 | #define MIC_BCK 18 45 | #define MIC_WS 19 46 | #define MIC_DAT3 20 47 | 48 | // #define IO_21 21 49 | // #define IO_22 22 50 | // #define IO_23 23 51 | // #define IO_24 24 52 | // #define IO_25 25 53 | /* SPI0 */ 54 | #define SPI0_MISO 26 55 | #define SPI0_SCLK 27 56 | #define SPI0_MOSI 28 57 | #define SPI0_CS0 29 58 | 59 | // #define SCL 30 60 | // #define SDA 31 61 | // #define IO_30 30 62 | // #define IO_31 31 63 | // #define IO_32 32 64 | // #define IO_33 33 65 | // #define IO_34 34 66 | // #define IO_35 35 67 | /* LCD */ 68 | #define LCD_CS 36 69 | #define LCD_RST 37 70 | #define LCD_DC 38 71 | #define LCD_WR 39 72 | 73 | 74 | #define MD_PIN_MAP(fpio) (fpio) 75 | #define ORG_PIN_MAP(org_pin) (org_pin) 76 | 77 | static const uint8_t SS = SPI0_CS0 ; 78 | static const uint8_t MOSI = SPI0_MOSI; 79 | static const uint8_t MISO = SPI0_MISO; 80 | static const uint8_t SCK = SPI0_SCLK; 81 | 82 | typedef struct _pwm_fpio_set_t{ 83 | pwm_channel_number_t channel; 84 | pwm_device_number_t device; 85 | uint8_t inuse; 86 | } pwm_fpio_set_t; 87 | 88 | 89 | #define VARIANT_NUM_GPIOHS (32) 90 | #define VARIANT_NUM_GPIO ( 8) 91 | #define VARIANT_NUM_PWM (12) 92 | #define VARIANT_NUM_I2C ( 3) 93 | #define VARIANT_NUM_SPI ( 3) 94 | #define VARIANT_NUM_UART ( 3) 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /variants/sipeed_maix_bit_mic/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_BIT_MIC 2 | #define _VARIANT_SIPEED_MAIX_BIT_MIC 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* UART */ 25 | #define RX1 6 26 | #define TX1 7 27 | 28 | #define IO_8 8 29 | #define IO_9 9 30 | #define IO_10 10 31 | /* LEDs */ 32 | #define PIN_LED_GREEN 12 33 | #define PIN_LED_RED 13 34 | #define PIN_LED_BLUE 14 35 | #define PIN_LED 12 36 | #define LED_RED 13 37 | #define LED_GREEN 12 38 | #define LED_BLUE 14 39 | #define LED_BUILTIN 12 40 | // #define IO_15 15 41 | // #define IO_17 17 42 | /* I2S MIC */ 43 | #define MIC_BCK 18 44 | #define MIC_WS 19 45 | #define MIC_DAT3 20 46 | // #define IO_21 21 47 | // #define IO_22 22 48 | // #define IO_23 23 49 | // #define IO_24 24 50 | // #define IO_25 25 51 | /* SPI0 */ 52 | #define SPI0_MISO 26 53 | #define SPI0_SCLK 27 54 | #define SPI0_MOSI 28 55 | #define SPI0_CS0 29 56 | 57 | // #define SCL 30 58 | // #define SDA 31 59 | // #define IO_30 30 60 | // #define IO_31 31 61 | // #define IO_32 32 62 | // #define IO_33 33 63 | // #define IO_34 34 64 | // #define IO_35 35 65 | /* LCD */ 66 | #define LCD_CS 36 67 | #define LCD_RST 37 68 | #define LCD_DC 38 69 | #define LCD_WR 39 70 | 71 | 72 | #define MD_PIN_MAP(fpio) (fpio) 73 | #define ORG_PIN_MAP(org_pin) (org_pin) 74 | 75 | static const uint8_t SS = SPI0_CS0 ; 76 | static const uint8_t MOSI = SPI0_MOSI; 77 | static const uint8_t MISO = SPI0_MISO; 78 | static const uint8_t SCK = SPI0_SCLK; 79 | 80 | typedef struct _pwm_fpio_set_t{ 81 | pwm_channel_number_t channel; 82 | pwm_device_number_t device; 83 | uint8_t inuse; 84 | } pwm_fpio_set_t; 85 | 86 | 87 | #define VARIANT_NUM_GPIOHS (32) 88 | #define VARIANT_NUM_GPIO ( 8) 89 | #define VARIANT_NUM_PWM (12) 90 | #define VARIANT_NUM_I2C ( 3) 91 | #define VARIANT_NUM_SPI ( 3) 92 | #define VARIANT_NUM_UART ( 3) 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /variants/sipeed_maix_cube/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_CUBE 2 | #define _VARIANT_SIPEED_MAIX_CUBE 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS CH552T */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* SPMOD */ 25 | #define RX1 6 26 | #define TX1 7 27 | // #define IO_8 8 28 | // #define IO_9 9 29 | /* KEYs */ 30 | #define KEY1 10 31 | #define KEY2 11 32 | #define PIN_KEY_DOWN 10 33 | #define PIN_KEY_UP 11 34 | /* LEDs */ 35 | #define PIN_LED_GREEN 12 36 | #define PIN_LED_RED 13 37 | #define PIN_LED_BLUE 14 38 | #define PIN_LED 12 39 | #define LED_RED 13 40 | #define LED_GREEN 12 41 | #define LED_BLUE 14 42 | #define LED_BUILTIN 12 43 | /* SPMOD */ 44 | // #define IO_15 15 45 | // #define IO_20 20 46 | // #define IO_21 21 47 | /* I2S AUDIO CODEC ES8374 */ 48 | #define I2S_DIN 18 49 | #define I2S_MCLK 19 50 | #define I2S_LRCK 33 51 | #define I2S_DOUT 34 52 | #define I2S_SCLK 35 53 | /* USB_SBU */ 54 | // #define IO_22 22 55 | // #define IO_23 23 56 | /* GROVE */ 57 | // #define IO_24 24 58 | // #define IO_25 25 59 | /* SPI0 */ 60 | #define SPI0_MISO 26 61 | #define SPI0_SCLK 27 62 | #define SPI0_MOSI 28 63 | #define SPI0_CS0 29 64 | /* I2C1 - AXP173, MSA301*/ 65 | #define SCL 30 66 | #define SDA 31 67 | /* Flash LED */ 68 | #define WLED_EN 32 69 | /* LCD */ 70 | #define LCD_BL 17 71 | #define LCD_CS 36 72 | #define LCD_RST 37 73 | #define LCD_DC 38 74 | #define LCD_WR 39 75 | 76 | 77 | #define MD_PIN_MAP(fpio) (fpio) 78 | #define ORG_PIN_MAP(org_pin) (org_pin) 79 | 80 | static const uint8_t SS = SPI0_CS0 ; 81 | static const uint8_t MOSI = SPI0_MOSI; 82 | static const uint8_t MISO = SPI0_MISO; 83 | static const uint8_t SCK = SPI0_SCLK; 84 | 85 | typedef struct _pwm_fpio_set_t{ 86 | pwm_channel_number_t channel; 87 | pwm_device_number_t device; 88 | uint8_t inuse; 89 | } pwm_fpio_set_t; 90 | 91 | 92 | #define VARIANT_NUM_GPIOHS (32) 93 | #define VARIANT_NUM_GPIO ( 8) 94 | #define VARIANT_NUM_PWM (12) 95 | #define VARIANT_NUM_I2C ( 3) 96 | #define VARIANT_NUM_SPI ( 3) 97 | #define VARIANT_NUM_UART ( 3) 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /variants/sipeed_maix_go/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_GO 2 | #define _VARIANT_SIPEED_MAIX_GO 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* WIFI UART1 */ 25 | #define RX1 6 26 | #define TX1 7 27 | #define ESP_TX 6 28 | #define ESP_RX 7 29 | #define ESP_EN 8 30 | /* BPSK */ 31 | #define BPSK_P 9 32 | #define BPSK_N 10 33 | // #define IO_11 11 34 | /* LEDs */ 35 | #define PIN_LED_BLUE 12 36 | #define PIN_LED_GREEN 13 37 | #define PIN_LED_RED 14 38 | #define PIN_LED 13 39 | #define LED_RED 14 40 | #define LED_GREEN 13 41 | #define LED_BLUE 12 42 | #define LED_BUILTIN 13 43 | /* KEY */ 44 | #define KEY1 15 45 | #define KEY0 16 46 | #define KEY2 17 47 | #define PIN_KEY_DOWN 15 48 | #define PIN_KEY_PRESS 16 49 | #define PIN_KEY_UP 17 50 | /* MIC ARRAY */ 51 | /* I2S MIC MSM261S4030H0 */ 52 | #define MIC_BCK 18 53 | #define MIC_WS 19 54 | #define MIC_DAT3 20 55 | #define MIC_DAT2 21 56 | #define MIC_DAT1 22 57 | #define MIC_DAT0 23 58 | #define MIC_LED_DAT 24 59 | #define MIC_LED_CLK 25 60 | /* SPI0 TF */ 61 | #define SPI0_MISO 26 62 | #define SPI0_SCLK 27 63 | #define SPI0_MOSI 28 64 | #define SPI0_CS0 29 65 | /* I2C1 MSA300 */ 66 | #define SCL 30 67 | #define SDA 31 68 | // #define IO_32 32 69 | /* I2S DAC PT8211 */ 70 | #define I2S_WS 33 71 | #define I2S_DA 34 72 | #define I2S_BCK 35 73 | /* LCD */ 74 | #define LCD_CS 36 75 | #define LCD_RST 37 76 | #define LCD_DC 38 77 | #define LCD_WR 39 78 | 79 | 80 | #define MD_PIN_MAP(fpio) (fpio) 81 | #define ORG_PIN_MAP(org_pin) (org_pin) 82 | 83 | static const uint8_t SS = SPI0_CS0 ; 84 | static const uint8_t MOSI = SPI0_MOSI; 85 | static const uint8_t MISO = SPI0_MISO; 86 | static const uint8_t SCK = SPI0_SCLK; 87 | 88 | typedef struct _pwm_fpio_set_t{ 89 | pwm_channel_number_t channel; 90 | pwm_device_number_t device; 91 | uint8_t inuse; 92 | } pwm_fpio_set_t; 93 | 94 | 95 | #define VARIANT_NUM_GPIOHS (32) 96 | #define VARIANT_NUM_GPIO ( 8) 97 | #define VARIANT_NUM_PWM (12) 98 | #define VARIANT_NUM_I2C ( 3) 99 | #define VARIANT_NUM_SPI ( 3) 100 | #define VARIANT_NUM_UART ( 3) 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /variants/sipeed_maix_one_dock/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_ONE_DOCK 2 | #define _VARIANT_SIPEED_MAIX_ONE_DOCK 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* WIFI UART1 */ 25 | #define RX1 6 26 | #define TX1 7 27 | /* LEDs */ 28 | #define PIN_LED_GREEN 13 29 | #define PIN_LED_BLUE 12 30 | #define PIN_LED_RED 14 31 | #define PIN_LED 13 32 | #define LED_RED 14 33 | #define LED_GREEN 13 34 | #define LED_BLUE 12 35 | #define LED_BUILTIN 13 36 | /* KEY */ 37 | //#define KEY0 16 38 | /* MIC ARRAY */ 39 | #define MIC_BCK 18 40 | #define MIC_WS 19 41 | #define MIC_DAT3 20 42 | #define MIC_DAT2 21 43 | #define MIC_DAT1 22 44 | #define MIC_DAT0 23 45 | #define MIC_LED_DAT 24 46 | /* SPI0 */ 47 | #define SPI0_CS1 25 48 | #define SPI0_MISO 26 49 | #define SPI0_SCLK 27 50 | #define SPI0_MOSI 28 51 | #define SPI0_CS0 29 52 | /* I2S */ 53 | #define MIC0_WS 30 54 | #define MIC0_DATA 31 55 | #define MIC0_BCK 32 56 | #define I2S_WS 33 57 | #define I2S_DA 34 58 | #define I2S_BCK 35 59 | /* LCD */ 60 | #define LCD_CS 36 61 | #define LCD_RST 37 62 | #define LCD_DC 38 63 | #define LCD_WR 39 64 | 65 | 66 | #define MD_PIN_MAP(fpio) (fpio) 67 | #define ORG_PIN_MAP(org_pin) (org_pin) 68 | 69 | static const uint8_t SS = SPI0_CS0 ; 70 | static const uint8_t MOSI = SPI0_MOSI; 71 | static const uint8_t MISO = SPI0_MISO; 72 | static const uint8_t SCK = SPI0_SCLK; 73 | 74 | typedef struct _pwm_fpio_set_t{ 75 | pwm_channel_number_t channel; 76 | pwm_device_number_t device; 77 | uint8_t inuse; 78 | }pwm_fpio_set_t; 79 | 80 | 81 | 82 | #define VARIANT_NUM_GPIOHS (32) 83 | #define VARIANT_NUM_GPIO ( 8) 84 | #define VARIANT_NUM_PWM (12) 85 | #define VARIANT_NUM_I2C ( 3) 86 | #define VARIANT_NUM_SPI ( 3) 87 | #define VARIANT_NUM_UART ( 3) 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /variants/sipeed_maix_one_w_dock/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIX_ONE_W_DOCK 2 | #define _VARIANT_SIPEED_MAIX_ONE_W_DOCK 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | /* UARTHS */ 22 | #define RX0 4 23 | #define TX0 5 24 | /* WIFI UART1 */ 25 | #define RX1 6 26 | #define TX1 7 27 | /* LEDs */ 28 | #define PIN_LED_RED 14 29 | #define PIN_LED_GREEN 13 30 | #define PIN_LED_BLUE 12 31 | #define PIN_LED 13 32 | #define LED_RED 14 33 | #define LED_GREEN 13 34 | #define LED_BLUE 12 35 | #define LED_BUILTIN 13 36 | /* KEY */ 37 | //#define KEY0 16 38 | /* MIC ARRAY */ 39 | #define MIC_BCK 18 40 | #define MIC_WS 19 41 | #define MIC_DAT3 20 42 | #define MIC_DAT2 21 43 | #define MIC_DAT1 22 44 | #define MIC_DAT0 23 45 | #define MIC_LED_DAT 24 46 | /* SPI0 */ 47 | #define SPI0_CS1 25 48 | #define SPI0_MISO 26 49 | #define SPI0_SCLK 27 50 | #define SPI0_MOSI 28 51 | #define SPI0_CS0 29 52 | /* I2S */ 53 | #define MIC0_WS 30 54 | #define MIC0_DATA 31 55 | #define MIC0_BCK 32 56 | 57 | #define I2S_WS 33 58 | #define I2S_DA 34 59 | #define I2S_BCK 35 60 | /* LCD */ 61 | #define LCD_CS 36 62 | #define LCD_RST 37 63 | #define LCD_DC 38 64 | #define LCD_WR 39 65 | 66 | 67 | #define MD_PIN_MAP(fpio) (fpio) 68 | #define ORG_PIN_MAP(org_pin) (org_pin) 69 | 70 | static const uint8_t SS = SPI0_CS0 ; 71 | static const uint8_t MOSI = SPI0_MOSI; 72 | static const uint8_t MISO = SPI0_MISO; 73 | static const uint8_t SCK = SPI0_SCLK; 74 | 75 | typedef struct _pwm_fpio_set_t{ 76 | pwm_channel_number_t channel; 77 | pwm_device_number_t device; 78 | uint8_t inuse; 79 | }pwm_fpio_set_t; 80 | 81 | 82 | 83 | #define VARIANT_NUM_GPIOHS (32) 84 | #define VARIANT_NUM_GPIO ( 8) 85 | #define VARIANT_NUM_PWM (12) 86 | #define VARIANT_NUM_I2C ( 3) 87 | #define VARIANT_NUM_SPI ( 3) 88 | #define VARIANT_NUM_UART ( 3) 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /variants/sipeed_maixduino/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARIANT_SIPEED_MAIXDUINO 2 | #define _VARIANT_SIPEED_MAIXDUINO 3 | 4 | #include 5 | 6 | #define RISCV 7 | #include "platform.h" 8 | 9 | #include "Arduino.h" 10 | #include "pwm.h" 11 | 12 | #ifdef __cplusplus 13 | #include "UARTClass.h" 14 | extern class UARTHSClass Serial; 15 | extern class UARTClass Serial1; 16 | extern class UARTClass Serial2; 17 | extern class UARTClass Serial3; 18 | #endif 19 | 20 | /* BOARD PIN DEFINE */ 21 | #define RX0 0 22 | #define TX0 1 23 | /* LEDs (USE Builtin TX PIN led)*/ 24 | #define PIN_LED_RED 13 25 | #define PIN_LED_GREEN 12 26 | #define PIN_LED_BLUE 14 27 | #define PIN_LED 12 28 | #define LED_RED 13 29 | #define LED_GREEN 12 30 | #define LED_BLUE 14 31 | #define LED_BUILTIN 12 32 | /* KEY */ 33 | //#define KEY0 16 34 | /* ONBOARD ESP32 */ 35 | #define ESP_TX 6 36 | #define ESP_RX 7 37 | #define ESP_EN 8 38 | #define ESP_READY 9 39 | #define ESP_SPI_CS 25 40 | /* SPI0 */ 41 | #define SPI0_MISO 26 42 | #define SPI0_SCLK 27 43 | #define SPI0_MOSI 28 44 | #define SPI0_CS0 29 45 | /* I2S */ 46 | #define MIC_BCK 18 47 | #define MIC_WS 19 48 | #define MIC_DATA 20 49 | /* I2C1 */ 50 | #define SCL 30 51 | #define SDA 31 52 | /* DAC PT8211 */ 53 | #define I2S_WS 33 54 | #define I2S_DA 34 55 | #define I2S_BCK 35 56 | /* LCD */ 57 | #define LCD_BL 17 58 | #define LCD_CS 36 59 | #define LCD_RST 37 60 | #define LCD_DC 38 61 | #define LCD_WR 39 62 | 63 | 64 | static const uint8_t SS = SPI0_CS0 ; 65 | static const uint8_t MOSI = SPI0_MOSI; 66 | static const uint8_t MISO = SPI0_MISO; 67 | static const uint8_t SCK = SPI0_SCLK; 68 | 69 | typedef struct _pwm_fpio_set_t{ 70 | pwm_channel_number_t channel; 71 | pwm_device_number_t device; 72 | uint8_t inuse; 73 | }pwm_fpio_set_t; 74 | 75 | #define MD_PIN_MAP(fpio) (((fpio) < 17) ? _maixduino_pin_map[(fpio)] : (fpio)) 76 | 77 | static const uint8_t _maixduino_pin_map[17] = {4, 5, 21, 22, 23, 24, 32, 15, 14, 13, 12, 11, 10, 3, 31, 30, 16}; 78 | 79 | #define ORG_PIN_MAP(org_pin) _original_pin_map[(org_pin)] 80 | 81 | static const uint8_t _original_pin_map[48] = {255, 255, 255, 13, 0, 1, 255, 255, 255, 255, 82 | 12, 11, 10, 9, 8, 7, 16, 255, 255, 255, 83 | 255, 2, 3, 4, 5, 255, 255, 255, 255, 255, 84 | 15, 14, 6, 255, 255, 255, 255, 255, 255, 255, 85 | 255, 255, 255, 255, 255, 255, 255, 255}; 86 | 87 | typedef enum _analog_output_pin_t{ 88 | A0, 89 | A1, 90 | A2, 91 | A3, 92 | A4, 93 | A5, 94 | ANALOG_OUTPUT_PIN_MAX, 95 | }analog_output_pin_t; 96 | 97 | #define VARIANT_NUM_GPIOHS (32) 98 | #define VARIANT_NUM_GPIO ( 8) 99 | #define VARIANT_NUM_PWM (12) 100 | #define VARIANT_NUM_I2C ( 3) 101 | #define VARIANT_NUM_SPI ( 3) 102 | #define VARIANT_NUM_UART ( 3) 103 | 104 | #endif 105 | --------------------------------------------------------------------------------