├── .gitignore ├── .gitmodules ├── LICENSE.md ├── README.md ├── boards.txt ├── cores └── arduino │ ├── Arduino.h │ ├── ArduinoAPI.h │ ├── Binary.h │ ├── Client.h │ ├── Common.cpp │ ├── Common.h │ ├── GD32VF103_Firmware_Library │ ├── GD32VF103_standard_peripheral │ │ ├── Include │ │ │ ├── gd32vf103_adc.h │ │ │ ├── gd32vf103_bkp.h │ │ │ ├── gd32vf103_can.h │ │ │ ├── gd32vf103_crc.h │ │ │ ├── gd32vf103_dac.h │ │ │ ├── gd32vf103_dbg.h │ │ │ ├── gd32vf103_dma.h │ │ │ ├── gd32vf103_eclic.h │ │ │ ├── gd32vf103_exmc.h │ │ │ ├── gd32vf103_exti.h │ │ │ ├── gd32vf103_fmc.h │ │ │ ├── gd32vf103_fwdgt.h │ │ │ ├── gd32vf103_gpio.h │ │ │ ├── gd32vf103_i2c.h │ │ │ ├── gd32vf103_pmu.h │ │ │ ├── gd32vf103_rcu.h │ │ │ ├── gd32vf103_rtc.h │ │ │ ├── gd32vf103_spi.h │ │ │ ├── gd32vf103_timer.h │ │ │ ├── gd32vf103_usart.h │ │ │ └── gd32vf103_wwdgt.h │ │ ├── Source │ │ │ ├── gd32vf103_adc.c │ │ │ ├── gd32vf103_bkp.c │ │ │ ├── gd32vf103_can.c │ │ │ ├── gd32vf103_crc.c │ │ │ ├── gd32vf103_dac.c │ │ │ ├── gd32vf103_dbg.c │ │ │ ├── gd32vf103_dma.c │ │ │ ├── gd32vf103_eclic.c │ │ │ ├── gd32vf103_exmc.c │ │ │ ├── gd32vf103_exti.c │ │ │ ├── gd32vf103_fmc.c │ │ │ ├── gd32vf103_fwdgt.c │ │ │ ├── gd32vf103_gpio.c │ │ │ ├── gd32vf103_i2c.c │ │ │ ├── gd32vf103_pmu.c │ │ │ ├── gd32vf103_rcu.c │ │ │ ├── gd32vf103_rtc.c │ │ │ ├── gd32vf103_spi.c │ │ │ ├── gd32vf103_timer.c │ │ │ ├── gd32vf103_usart.c │ │ │ └── gd32vf103_wwdgt.c │ │ ├── gd32vf103.h │ │ ├── gd32vf103_libopt.h │ │ ├── system_gd32vf103.c │ │ └── system_gd32vf103.h │ ├── RISCV │ │ ├── drivers │ │ │ ├── n200_eclic.h │ │ │ ├── n200_func.c │ │ │ ├── n200_func.h │ │ │ ├── n200_timer.h │ │ │ ├── riscv_bits.h │ │ │ ├── riscv_const.h │ │ │ └── riscv_encoding.h │ │ ├── env_Eclipse │ │ │ ├── GD32VF103x4.lds │ │ │ ├── GD32VF103x6.lds │ │ │ ├── GD32VF103x8.lds │ │ │ ├── GD32VF103xB.lds │ │ │ ├── entry.S │ │ │ ├── handlers.c │ │ │ ├── init.c │ │ │ ├── start.S │ │ │ └── your_printf.c │ │ └── stubs │ │ │ ├── _exit.c │ │ │ ├── close.c │ │ │ ├── fstat.c │ │ │ ├── isatty.c │ │ │ ├── lseek.c │ │ │ ├── read.c │ │ │ ├── sbrk.c │ │ │ ├── stub.h │ │ │ ├── write.c │ │ │ └── write_hex.c │ └── package.json │ ├── HardwareI2C.h │ ├── HardwareSerial.cpp │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── PluggableUSB.cpp │ ├── PluggableUSB.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── RingBuffer.h │ ├── Server.h │ ├── Stream.cpp │ ├── Stream.h │ ├── Tone.cpp │ ├── USBAPI.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WInterrupts.c │ ├── WInterrupts.h │ ├── WMath.cpp │ ├── WString.cpp │ ├── WString.h │ ├── deprecated-avr-comp │ └── avr │ │ ├── dtostrf.c.impl │ │ ├── dtostrf.h │ │ ├── interrupt.h │ │ └── pgmspace.h │ ├── hooks.c │ ├── itoa.h │ ├── main.cpp │ ├── stdlib_noniso.c │ ├── stdlib_noniso.h │ ├── usart_com.c │ ├── usart_com.h │ ├── usart_types.h │ ├── wiring.c │ ├── wiring_analog.c │ ├── wiring_digital.c │ ├── wiring_pulse.c │ └── wiring_shift.c ├── libraries ├── FATFS │ ├── library.properties │ └── src │ │ ├── diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ ├── ffconf.h │ │ ├── ffsystem.c │ │ └── ffunicode.c ├── GD32V │ ├── examples │ │ ├── Backup_Data │ │ │ ├── Backup_Data.ino │ │ │ └── readme.txt │ │ ├── BlinkRGB │ │ │ └── BlinkRGB.ino │ │ ├── CRC_calculate │ │ │ ├── CRC_calculate.ino │ │ │ └── readme.txt │ │ ├── FWDGT_key │ │ │ ├── FWDGT_key.ino │ │ │ ├── fwdgt_key_it.c │ │ │ ├── fwdgt_key_it.h │ │ │ └── readme.txt │ │ ├── FadeRGB │ │ │ └── FadeRGB.ino │ │ ├── GPIOInterrupt │ │ │ └── GPIOInterrupt.ino │ │ ├── I2C_EEPROM │ │ │ ├── I2C_EEPROM.ino │ │ │ ├── at24cxx.c │ │ │ ├── at24cxx.h │ │ │ ├── i2c.c │ │ │ ├── i2c.h │ │ │ └── readme.txt │ │ ├── RTC_Calendar │ │ │ ├── RTC_Calendar.ino │ │ │ ├── readme.txt │ │ │ ├── rtc.c │ │ │ ├── rtc.h │ │ │ ├── rtc_it.c │ │ │ └── rtc_it.h │ │ ├── Tamper │ │ │ ├── Tamper.ino │ │ │ ├── readme.txt │ │ │ ├── tamper_it.c │ │ │ └── tamper_it.h │ │ ├── WWDGT_delay_feed │ │ │ ├── WWDGT_delay_feed.ino │ │ │ └── readme.txt │ │ └── WebLED │ │ │ └── WebLED.ino │ ├── library.properties │ └── src │ │ ├── dummy.h │ │ ├── gd32vf103v_eval.c │ │ └── gd32vf103v_eval.h ├── LCD │ ├── examples │ │ └── gd32v_lcd │ │ │ └── gd32v_lcd.ino │ ├── library.properties │ └── src │ │ ├── bmp.h │ │ ├── lcd.c │ │ ├── lcd.h │ │ └── oledfont.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 │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── SPI.cpp │ │ └── SPI.h ├── Seeed_GD32V_EXMC │ ├── examples │ │ ├── Flash2TFT │ │ │ └── Flash2TFT.ino │ │ ├── SD2Flash │ │ │ └── SD2Flash.ino │ │ ├── TFT_GD32 │ │ │ └── TFT_GD32.ino │ │ ├── basic_exmc │ │ │ └── basic_exmc.ino │ │ ├── image_exmc │ │ │ └── image_exmc.ino │ │ └── mock_exmc │ │ │ └── mock_exmc.ino │ ├── library.properties │ └── src │ │ ├── EXMC.cpp │ │ ├── EXMC.h │ │ └── TFT_comm.cpp ├── Sipeed_GD32V_LCD │ ├── examples │ │ ├── 160x80 │ │ │ ├── TFT_Clock │ │ │ │ └── TFT_Clock.ino │ │ │ ├── TFT_Mandlebrot │ │ │ │ └── TFT_Mandlebrot.ino │ │ │ ├── TFT_Pong │ │ │ │ └── TFT_Pong.ino │ │ │ ├── TFT_Spiro │ │ │ │ └── TFT_Spiro.ino │ │ │ └── TFT_Starfield │ │ │ │ └── TFT_Starfield.ino │ │ ├── basic_display │ │ │ └── basic_display.ino │ │ ├── image_display │ │ │ └── image_display.ino │ │ └── mock_display │ │ │ └── mock_display.ino │ ├── library.properties │ └── src │ │ ├── ST7735_Commands.h │ │ ├── Sipeed_GD32V_LCD.cpp │ │ └── Sipeed_GD32V_LCD.h ├── SysTick │ ├── library.properties │ └── src │ │ ├── systick.c │ │ └── systick.h ├── TF_CARD │ ├── library.properties │ └── src │ │ ├── tf_card.c │ │ ├── tf_card.h │ │ └── tf_card_pjt_include.h ├── Ticker │ ├── examples │ │ ├── Arguments │ │ │ └── Arguments.ino │ │ └── Blinker │ │ │ └── Blinker.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── TInterrupts.c │ │ ├── TInterrupts.h │ │ ├── Ticker.cpp │ │ └── Ticker.h ├── USBAudio │ ├── library.properties │ └── src │ │ ├── audio_core.c │ │ ├── audio_core.h │ │ ├── audio_usbd_conf.h │ │ ├── gd32vf103_audio_codec.c │ │ ├── gd32vf103_audio_codec.h │ │ ├── usbd_audio_out_if.c │ │ └── usbd_audio_out_if.h ├── USBCDC │ ├── examples │ │ ├── CDC_ACM │ │ │ └── CDC_ACM.ino │ │ └── USB_UART_BRIDGE │ │ │ ├── USB_UART_BRIDGE.ino │ │ │ ├── cdc_acm_uart.c │ │ │ └── cdc_acm_uart.h │ ├── library.properties │ └── src │ │ ├── cdc_acm_core.c │ │ ├── cdc_acm_core.h │ │ └── usbcdc_pjt_include.h ├── USBDEV │ ├── examples │ │ ├── Audio │ │ │ └── Audio.ino │ │ ├── HID_IAP │ │ │ ├── HID_IAP.ino │ │ │ ├── iap_core.c │ │ │ ├── iap_core.h │ │ │ └── iap_usbd_conf.h │ │ └── HID_Mouse │ │ │ ├── HID_Mouse.ino │ │ │ ├── hid_mouse_it.c │ │ │ ├── hid_mouse_it.h │ │ │ ├── hid_mouse_systick.c │ │ │ ├── hid_mouse_systick.h │ │ │ ├── hid_mouse_usbd_conf.h │ │ │ ├── standard_hid_core.c │ │ │ ├── standard_hid_core.h │ │ │ └── usb_hid.h │ ├── library.properties │ └── src │ │ ├── drv_usb_dev.c │ │ ├── drv_usb_dev.h │ │ ├── drv_usbd_int.c │ │ ├── drv_usbd_int.h │ │ ├── usbd_conf.h │ │ ├── usbd_core.c │ │ ├── usbd_core.h │ │ ├── usbd_enum.c │ │ ├── usbd_enum.h │ │ ├── usbd_transc.c │ │ └── usbd_transc.h ├── USBDEVHW │ ├── library.properties │ └── src │ │ ├── gd32vf103_usbd_hw.c │ │ ├── gd32vf103_usbd_hw.h │ │ ├── gd32vf103_usbd_it.c │ │ └── gd32vf103_usbd_it.h ├── USBFS │ ├── library.properties │ └── src │ │ ├── drv_usb_core.c │ │ ├── drv_usb_core.h │ │ ├── drv_usb_hw.h │ │ ├── drv_usb_regs.h │ │ ├── usb_ch9_std.h │ │ └── usb_conf.h ├── USBHID │ ├── library.properties │ └── src │ │ ├── usb_hid.h │ │ ├── usbh_hid_core.c │ │ ├── usbh_hid_core.h │ │ ├── usbh_hid_keybd.c │ │ ├── usbh_hid_keybd.h │ │ ├── usbh_hid_mouse.c │ │ ├── usbh_hid_mouse.h │ │ ├── usbh_usr.c │ │ └── usbh_usr.h ├── USBHOST │ ├── examples │ │ ├── HID_Host │ │ │ └── HID_Host.ino │ │ └── MSC_Host │ │ │ └── MSC_Host.ino │ ├── library.properties │ └── src │ │ ├── drv_usb_host.c │ │ ├── drv_usb_host.h │ │ ├── drv_usbh_int.c │ │ ├── drv_usbh_int.h │ │ ├── gd32vf103_usbh_hw.c │ │ ├── gd32vf103_usbh_it.c │ │ ├── gd32vf103_usbh_it.h │ │ ├── usbh_conf.h │ │ ├── usbh_core.c │ │ ├── usbh_core.h │ │ ├── usbh_enum.c │ │ ├── usbh_enum.h │ │ ├── usbh_pipe.c │ │ ├── usbh_pipe.h │ │ ├── usbh_transc.c │ │ └── usbh_transc.h ├── USBMSC │ ├── library.properties │ └── src │ │ ├── msc_bbb.h │ │ ├── msc_scsi.h │ │ ├── usb_msc.h │ │ ├── usbh_msc_bbb.c │ │ ├── usbh_msc_bbb.h │ │ ├── usbh_msc_core.c │ │ ├── usbh_msc_core.h │ │ ├── usbh_msc_fatfs.c │ │ ├── usbh_msc_scsi.c │ │ └── usbh_msc_scsi.h └── Wire │ ├── examples │ ├── i2c_eeprom_rxtx │ │ └── i2c_eeprom_rxtx.ino │ ├── 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 ├── gd32_risc-v_dev ├── pins_arduino.c └── pins_arduino.h ├── gd32vf103_eval ├── pins_arduino.c └── pins_arduino.h ├── sipeed-longan-nano-lite ├── pins_arduino.c └── pins_arduino.h ├── sipeed-longan-nano ├── pins_arduino.c └── pins_arduino.h └── wio_lite_risc-v ├── pins_arduino.c └── 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 | .package_gd32v_index.json -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libraries/Adafruit-GFX-Library"] 2 | path = libraries/Adafruit-GFX-Library 3 | url = https://github.com/adafruit/Adafruit-GFX-Library 4 | [submodule "libraries/WiFiEsp"] 5 | path = libraries/WiFiEsp 6 | url = https://github.com/scpcom/WiFiEsp 7 | [submodule "libraries/Seeed_Arduino_LCD"] 8 | path = libraries/Seeed_Arduino_LCD 9 | url = https://github.com/scpcom/Seeed_Arduino_LCD 10 | [submodule "libraries/SPIMemory"] 11 | path = libraries/SPIMemory 12 | url = https://github.com/scpcom/SPIMemory 13 | -------------------------------------------------------------------------------- /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 | # Longduino 2 | 3 | ## How to use 4 | 5 | ### PlatformIO 6 | Only need add follow line into `platformio.ini` 7 | ```ini 8 | platform_packages = framework-arduino-gd32v @ https://github.com/sipeed/Longduino.git 9 | ``` 10 | ### Arduino IDE 11 | 12 | Add follow url into `Boards Manager URLs`. 13 | ``` 14 | http://bigbits.oss-cn-qingdao.aliyuncs.com/Arduino_for_GD32V/package_longduino_index.json 15 | ``` 16 | ## TODO List 17 | 18 | See [Todo list](https://github.com/sipeed/Longduino/issues/1). -------------------------------------------------------------------------------- /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 | #include "ArduinoAPI.h" 36 | #include "pins_arduino.h" 37 | 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif // __cplusplus 42 | //#include "wiring.h" 43 | //#include "wiring_constants.h" 44 | //#include "wiring_digital.h" 45 | //#include "wiring_analog.h" 46 | //#include "wiring_shift.h" 47 | #include "Common.h" 48 | 49 | #define SystemCpuClock F_CPU 50 | 51 | #define clockCyclesPerMicrosecond() ( SystemCpuClock / 1000000L ) 52 | #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCpuClock / 1000L) ) 53 | #define microsecondsToClockCycles(a) ( (a) * (SystemCpuClock / 1000000L) ) 54 | 55 | void yield(void); 56 | 57 | /* sketch */ 58 | extern void setup( void ) ; 59 | extern void loop( void ) ; 60 | 61 | typedef void (*voidFuncPtr)( void ) ; 62 | 63 | /* Define attribute */ 64 | #define WEAK __attribute__ ((weak)) 65 | 66 | #ifdef __cplusplus 67 | } // extern "C" 68 | 69 | #endif // __cplusplus 70 | 71 | #endif // Arduino_h 72 | -------------------------------------------------------------------------------- /cores/arduino/ArduinoAPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino API main include 3 | Copyright (c) 2016 Arduino LLC. 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_API_H 21 | #define ARDUINO_API_H 22 | 23 | // version 1.0.0 24 | #define ARDUINO_API_VERSION 10000 25 | 26 | #include "Binary.h" 27 | 28 | #ifdef __cplusplus 29 | #include "Client.h" 30 | #include "HardwareI2C.h" 31 | #include "HardwareSerial.h" 32 | #include "WInterrupts.h" 33 | #include "IPAddress.h" 34 | #include "Print.h" 35 | #include "Printable.h" 36 | #include "PluggableUSB.h" 37 | #include "Server.h" 38 | #include "WString.h" 39 | #include "Stream.h" 40 | #include "Udp.h" 41 | #include "USBAPI.h" 42 | #include "WCharacter.h" 43 | #endif 44 | 45 | /* Standard C library includes */ 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | // Misc Arduino core functions 53 | #include "Common.h" 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /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/Common.cpp: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | 3 | /* C++ prototypes */ 4 | long map(long x, long in_min, long in_max, long out_min, long out_max) 5 | { 6 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 7 | } 8 | 9 | uint16_t makeWord(uint16_t w) { return w; } 10 | uint16_t makeWord(uint8_t h, uint8_t l) { return (h << 8) | l; } -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/GD32VF103_standard_peripheral/Source/gd32vf103_fmc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scpcom/Longduino/fd2d43865a004e6031e4c814c585c422f81e6e70/cores/arduino/GD32VF103_Firmware_Library/GD32VF103_standard_peripheral/Source/gd32vf103_fmc.c -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/GD32VF103_standard_peripheral/gd32vf103_libopt.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gd32vf103_libopt.h 3 | \brief library optional for gd32vf103 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GD32VF103_LIBOPT_H 36 | #define GD32VF103_LIBOPT_H 37 | 38 | #include "gd32vf103_adc.h" 39 | #include "gd32vf103_bkp.h" 40 | #include "gd32vf103_can.h" 41 | #include "gd32vf103_crc.h" 42 | #include "gd32vf103_dac.h" 43 | #include "gd32vf103_dma.h" 44 | #include "gd32vf103_eclic.h" 45 | #include "gd32vf103_exmc.h" 46 | #include "gd32vf103_exti.h" 47 | #include "gd32vf103_fmc.h" 48 | #include "gd32vf103_gpio.h" 49 | #include "gd32vf103_i2c.h" 50 | #include "gd32vf103_fwdgt.h" 51 | #include "gd32vf103_dbg.h" 52 | #include "gd32vf103_pmu.h" 53 | #include "gd32vf103_rcu.h" 54 | #include "gd32vf103_rtc.h" 55 | #include "gd32vf103_spi.h" 56 | #include "gd32vf103_timer.h" 57 | #include "gd32vf103_usart.h" 58 | #include "gd32vf103_wwdgt.h" 59 | #include "n200_func.h" 60 | 61 | #endif /* GD32VF103_LIBOPT_H */ 62 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/GD32VF103_standard_peripheral/system_gd32vf103.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file system_gd32vf103.h 3 | \brief RISC-V Device Peripheral Access Layer Header File for 4 | GD32VF103 Device Series 5 | 6 | \version 2019-06-05, V1.0.0, firmware for GD32VF103 7 | \version 2020-08-04, V1.1.0, firmware for GD32VF103 8 | */ 9 | 10 | /* 11 | Copyright (c) 2020, GigaDevice Semiconductor Inc. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, this 17 | list of conditions and the following disclaimer. 18 | 2. Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 3. Neither the name of the copyright holder nor the names of its contributors 22 | may be used to endorse or promote products derived from this software without 23 | specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 34 | OF SUCH DAMAGE. 35 | */ 36 | 37 | /* This file refers the RISC-V standard, some adjustments are made according to GigaDevice chips */ 38 | 39 | #ifndef SYSTEM_GD32VF103_H 40 | #define SYSTEM_GD32VF103_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #include 47 | 48 | #if defined (__ICCRISCV__) 49 | #include "compiler.h" 50 | #endif 51 | 52 | /* system clock frequency (core clock) */ 53 | extern uint32_t SystemCoreClock; 54 | 55 | /* function declarations */ 56 | /* initialize the system and update the SystemCoreClock variable */ 57 | extern void SystemInit(void); 58 | /* update the SystemCoreClock with current core clock retrieved from cpu registers */ 59 | extern void SystemCoreClockUpdate(void); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* SYSTEM_GD32VF103_H */ 66 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/drivers/n200_eclic.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for licence details */ 2 | 3 | #ifndef N200_ECLIC_H 4 | #define N200_ECLIC_H 5 | 6 | #include 7 | 8 | #define ECLICINTCTLBITS 4 9 | 10 | /*ECLIC memory map */ 11 | /* Offset */ 12 | /* 0x0000 1B RW ecliccfg */ 13 | #define ECLIC_CFG_OFFSET 0x0 14 | /* 0x0004 4B R eclicinfo */ 15 | #define ECLIC_INFO_OFFSET 0x4 16 | /* 0x000B 1B RW mintthresh */ 17 | #define ECLIC_MTH_OFFSET 0xB 18 | 19 | /* 0x1000+4*i 1B/input RW eclicintip[i] */ 20 | #define ECLIC_INT_IP_OFFSET _AC(0x1000,UL) 21 | /* 0x1001+4*i 1B/input RW eclicintie[i] */ 22 | #define ECLIC_INT_IE_OFFSET _AC(0x1001,UL) 23 | /* 0x1002+4*i 1B/input RW eclicintattr[i]*/ 24 | #define ECLIC_INT_ATTR_OFFSET _AC(0x1002,UL) 25 | 26 | #define ECLIC_INT_ATTR_SHV 0x01 27 | #define ECLIC_INT_ATTR_TRIG_LEVEL 0x00 28 | #define ECLIC_INT_ATTR_TRIG_EDGE 0x02 29 | #define ECLIC_INT_ATTR_TRIG_POS 0x00 30 | #define ECLIC_INT_ATTR_TRIG_NEG 0x04 31 | 32 | /* 0x1003+4*i 1B/input RW eclicintctl[i] */ 33 | #define ECLIC_INT_CTRL_OFFSET _AC(0x1003,UL) 34 | 35 | #define ECLIC_ADDR_BASE 0xd2000000 36 | 37 | 38 | #define ECLIC_CFG_NLBITS_MASK _AC(0x1E,UL) 39 | #define ECLIC_CFG_NLBITS_LSB (1u) 40 | 41 | #define MSIP_HANDLER eclic_msip_handler 42 | #define MTIME_HANDLER eclic_mtip_handler 43 | #define BWEI_HANDLER eclic_bwei_handler 44 | #define PMOVI_HANDLER eclic_pmovi_handler 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/drivers/n200_timer.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for licence details */ 2 | 3 | #ifndef N200_TIMER_H 4 | #define N200_TIMER_H 5 | 6 | #define TIMER_MSIP 0xFFC 7 | #define TIMER_MSIP_size 0x4 8 | #define TIMER_MTIMECMP 0x8 9 | #define TIMER_MTIMECMP_size 0x8 10 | #define TIMER_MTIME 0x0 11 | #define TIMER_MTIME_size 0x8 12 | 13 | #define TIMER_CTRL_ADDR 0xd1000000 14 | #define TIMER_REG(offset) _REG32(TIMER_CTRL_ADDR, offset) 15 | #define TIMER_FREQ ((uint32_t)SystemCoreClock/4) 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/drivers/riscv_bits.h: -------------------------------------------------------------------------------- 1 | // See LICENSE for license details. 2 | #ifndef _RISCV_BITS_H 3 | #define _RISCV_BITS_H 4 | 5 | #define likely(x) __builtin_expect((x), 1) 6 | #define unlikely(x) __builtin_expect((x), 0) 7 | 8 | #define ROUNDUP(a, b) ((((a)-1)/(b)+1)*(b)) 9 | #define ROUNDDOWN(a, b) ((a)/(b)*(b)) 10 | 11 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 12 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 13 | #define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi) 14 | 15 | #define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1))) 16 | #define INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1)))) 17 | 18 | #define STR(x) XSTR(x) 19 | #define XSTR(x) #x 20 | 21 | #if __riscv_xlen == 64 22 | # define SLL32 sllw 23 | # define STORE sd 24 | # define LOAD ld 25 | # define LWU lwu 26 | # define LOG_REGBYTES 3 27 | #else 28 | # define SLL32 sll 29 | # define STORE sw 30 | # define LOAD lw 31 | # define LWU lw 32 | # define LOG_REGBYTES 2 33 | #endif 34 | #define REGBYTES (1 << LOG_REGBYTES) 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/drivers/riscv_const.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE for license details.*/ 2 | /* Derived from */ 3 | 4 | #ifndef _RISCV_CONST_H 5 | #define _RISCV_CONST_H 6 | 7 | #ifdef __ASSEMBLER__ 8 | #define _AC(X,Y) X 9 | #define _AT(T,X) X 10 | #else 11 | #define _AC(X,Y) (X##Y) 12 | #define _AT(T,X) ((T)(X)) 13 | #endif /* !__ASSEMBLER__*/ 14 | 15 | #define _BITUL(x) (_AC(1,UL) << (x)) 16 | #define _BITULL(x) (_AC(1,ULL) << (x)) 17 | 18 | #endif /* _NUCLEI_CONST_H */ 19 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/env_Eclipse/handlers.c: -------------------------------------------------------------------------------- 1 | //See LICENSE for license details. 2 | #include 3 | #include 4 | #include 5 | #include "riscv_encoding.h" 6 | #include "n200_func.h" 7 | 8 | __attribute__((weak)) uintptr_t handle_nmi() 9 | { 10 | write(1, "nmi\n", 5); 11 | _exit(1); 12 | return 0; 13 | } 14 | 15 | 16 | __attribute__((weak)) uintptr_t handle_trap(uintptr_t mcause, uintptr_t sp) 17 | { 18 | if((mcause & 0xFFF) == 0xFFF) { 19 | handle_nmi(); 20 | } 21 | write(1, "trap\n", 5); 22 | //printf("In trap handler, the mcause is %d\n", mcause); 23 | //printf("In trap handler, the mepc is 0x%x\n", read_csr(mepc)); 24 | //printf("In trap handler, the mtval is 0x%x\n", read_csr(mbadaddr)); 25 | _exit(mcause); 26 | return 0; 27 | } 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/env_Eclipse/init.c: -------------------------------------------------------------------------------- 1 | //See LICENSE for license details. 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "riscv_encoding.h" 7 | #include "n200_func.h" 8 | 9 | extern uint32_t disable_mcycle_minstret(); 10 | void _init() 11 | { 12 | SystemInit(); 13 | 14 | //ECLIC init 15 | eclic_init(ECLIC_NUM_INTERRUPTS); 16 | eclic_mode_enable(); 17 | 18 | //printf("After ECLIC mode enabled, the mtvec value is %x \n\n\r", read_csr(mtvec)); 19 | 20 | // // It must be NOTED: 21 | // // * In the RISC-V arch, if user mode and PMP supported, then by default if PMP is not configured 22 | // // with valid entries, then user mode cannot access any memory, and cannot execute any instructions. 23 | // // * So if switch to user-mode and still want to continue, then you must configure PMP first 24 | //pmp_open_all_space(); 25 | //switch_m2u_mode(); 26 | 27 | /* Before enter into main, add the cycle/instret disable by default to save power, 28 | only use them when needed to measure the cycle/instret */ 29 | disable_mcycle_minstret(); 30 | } 31 | 32 | void _fini() 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/env_Eclipse/your_printf.c: -------------------------------------------------------------------------------- 1 | int __wrap_printf(const char* fmt, ...) 2 | { 3 | // You can implement your own printf to reduce the code size, because the printf is really a big function 4 | return 0; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/_exit.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | 5 | #include "stub.h" 6 | 7 | 8 | void _exit(int code) 9 | { 10 | const char message[] = "\nProgram has exited with code:"; 11 | 12 | write(STDERR_FILENO, message, sizeof(message) - 1); 13 | write_hex(STDERR_FILENO, code); 14 | write(STDERR_FILENO, "\n", 1); 15 | 16 | for (;;); 17 | } 18 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/close.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | #include "stub.h" 5 | 6 | int _close(int fd) 7 | { 8 | return _stub(EBADF); 9 | } 10 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/fstat.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "stub.h" 7 | 8 | int _fstat(int fd, struct stat* st) 9 | { 10 | if (isatty(fd)) { 11 | st->st_mode = S_IFCHR; 12 | return 0; 13 | } 14 | 15 | return _stub(EBADF); 16 | } 17 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/isatty.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | 5 | int _isatty(int fd) 6 | { 7 | if (fd == STDOUT_FILENO || fd == STDERR_FILENO) 8 | return 1; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/lseek.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "stub.h" 7 | 8 | off_t _lseek(int fd, off_t ptr, int dir) 9 | { 10 | if (isatty(fd)) 11 | return 0; 12 | 13 | return _stub(EBADF); 14 | } 15 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/read.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "stub.h" 9 | 10 | ssize_t _read(int fd, void* ptr, size_t len) 11 | { 12 | return _stub(EBADF); 13 | } 14 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/sbrk.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | 5 | void *_sbrk(ptrdiff_t incr) 6 | { 7 | extern char _end[]; 8 | extern char _heap_end[]; 9 | static char *curbrk = _end; 10 | 11 | if ((curbrk + incr < _end) || (curbrk + incr > _heap_end)) 12 | return NULL - 1; 13 | 14 | curbrk += incr; 15 | return curbrk - incr; 16 | } -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/stub.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | #ifndef _NUCLEI_SYS_STUB_H 3 | #define _NUCLEI_SYS_STUB_H 4 | 5 | #include 6 | #if defined (__GNUC__) 7 | #include 8 | #endif 9 | 10 | void write_hex(int fd, unsigned long int hex); 11 | 12 | static inline int _stub(int err) 13 | { 14 | return -1; 15 | } 16 | 17 | 18 | #endif /* _NUCLEI_SYS_STUB_H */ 19 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/write.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined (__GNUC__) 9 | #include 10 | #include 11 | #endif 12 | 13 | #include "stub.h" 14 | #include "gd32vf103.h" 15 | 16 | //typedef unsigned int size_t; 17 | extern int _put_char(int ch) __attribute__((weak)); 18 | 19 | #if defined (__ICCRISCV__) 20 | size_t __write(int handle, const unsigned char *buf, size_t bufSize) 21 | { 22 | size_t nChars = 0; 23 | 24 | if (handle == -1) 25 | { 26 | return 0; 27 | } 28 | 29 | for (; bufSize > 0; --bufSize) 30 | { 31 | _put_char((uint8_t) *buf); 32 | ++buf; 33 | ++nChars; 34 | } 35 | 36 | return nChars; 37 | } 38 | 39 | int puts(const char* string) { 40 | return __write(0, (const void *) string, strlen(string)); 41 | } 42 | 43 | #elif defined ( __GNUC__ ) 44 | ssize_t _write(int fd, const void* ptr, size_t len) { 45 | const uint8_t * current = (const uint8_t *) ptr; 46 | { 47 | for (size_t jj = 0; jj < len; jj++) { 48 | _put_char(current[jj]); 49 | 50 | if (current[jj] == '\n') { 51 | _put_char('\r'); 52 | } 53 | } 54 | return len; 55 | } 56 | 57 | return _stub(EBADF); 58 | } 59 | 60 | int __wrap_puts(const char* string) { 61 | return _write(0, (const void *) string, strlen(string)); 62 | } 63 | #endif 64 | 65 | int _put_char(int ch) 66 | { 67 | usart_data_transmit(USART0, (uint8_t) ch ); 68 | while (usart_flag_get(USART0, USART_FLAG_TBE)== RESET){ 69 | } 70 | 71 | return ch; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/RISCV/stubs/write_hex.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE of license details. */ 2 | 3 | #include 4 | #include 5 | 6 | void write_hex(int fd, unsigned long int hex) 7 | { 8 | uint8_t ii; 9 | uint8_t jj; 10 | char towrite; 11 | write(fd , "0x", 2); 12 | for (ii = sizeof(unsigned long int) * 2 ; ii > 0; ii--) { 13 | jj = ii - 1; 14 | uint8_t digit = ((hex & (0xF << (jj*4))) >> (jj*4)); 15 | towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA)); 16 | write(fd, &towrite, 1); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cores/arduino/GD32VF103_Firmware_Library/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "framework-gd32vf103_firmware_library", 3 | "description": "This is gd32vf103 firmware library", 4 | "version": "0.1.9", 5 | "url": "https://www.sipeed.com" 6 | } 7 | -------------------------------------------------------------------------------- /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/PluggableUSB.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PluggableUSB.cpp 3 | Copyright (c) 2015 Arduino LLC 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 "USBAPI.h" 21 | #include "PluggableUSB.h" 22 | 23 | int PluggableUSB_::getInterface(uint8_t* interfaceCount) 24 | { 25 | int sent = 0; 26 | PluggableUSBModule* node; 27 | for (node = rootNode; node; node = node->next) { 28 | int res = node->getInterface(interfaceCount); 29 | if (res < 0) 30 | return -1; 31 | sent += res; 32 | } 33 | return sent; 34 | } 35 | 36 | int PluggableUSB_::getDescriptor(USBSetup& setup) 37 | { 38 | PluggableUSBModule* node; 39 | for (node = rootNode; node; node = node->next) { 40 | int ret = node->getDescriptor(setup); 41 | // ret!=0 -> request has been processed 42 | if (ret) 43 | return ret; 44 | } 45 | return 0; 46 | } 47 | 48 | void PluggableUSB_::getShortName(char *iSerialNum) 49 | { 50 | PluggableUSBModule* node; 51 | for (node = rootNode; node; node = node->next) { 52 | iSerialNum += node->getShortName(iSerialNum); 53 | } 54 | *iSerialNum = 0; 55 | } 56 | 57 | bool PluggableUSB_::setup(USBSetup& setup) 58 | { 59 | PluggableUSBModule* node; 60 | for (node = rootNode; node; node = node->next) { 61 | if (node->setup(setup)) { 62 | return true; 63 | } 64 | } 65 | return false; 66 | } 67 | 68 | bool PluggableUSB_::plug(PluggableUSBModule *node) 69 | { 70 | if ((lastEp + node->numEndpoints) > totalEP) { 71 | return false; 72 | } 73 | 74 | if (!rootNode) { 75 | rootNode = node; 76 | } else { 77 | PluggableUSBModule *current = rootNode; 78 | while (current->next) { 79 | current = current->next; 80 | } 81 | current->next = node; 82 | } 83 | 84 | node->pluggedInterface = lastIf; 85 | node->pluggedEndpoint = lastEp; 86 | lastIf += node->numInterfaces; 87 | for (uint8_t i = 0; i < node->numEndpoints; i++) { 88 | *(unsigned int*)(epBuffer(lastEp)) = node->endpointType[i]; 89 | lastEp++; 90 | } 91 | return true; 92 | // restart USB layer??? 93 | } 94 | 95 | PluggableUSB_& PluggableUSB() 96 | { 97 | static PluggableUSB_ obj; 98 | return obj; 99 | } -------------------------------------------------------------------------------- /cores/arduino/PluggableUSB.h: -------------------------------------------------------------------------------- 1 | /* 2 | PluggableUSB.h 3 | Copyright (c) 2015 Arduino LLC 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 PUSB_h 21 | #define PUSB_h 22 | 23 | #include "USBAPI.h" 24 | #include 25 | #include 26 | 27 | // core need to define 28 | void* epBuffer(unsigned int n); // -> returns a poointer to the Nth element of the EP buffer structure 29 | 30 | class PluggableUSBModule { 31 | public: 32 | PluggableUSBModule(uint8_t numEps, uint8_t numIfs, unsigned int *epType) : 33 | numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) 34 | { } 35 | 36 | protected: 37 | virtual bool setup(USBSetup& setup) = 0; 38 | virtual int getInterface(uint8_t* interfaceCount) = 0; 39 | virtual int getDescriptor(USBSetup& setup) = 0; 40 | virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; } 41 | 42 | uint8_t pluggedInterface; 43 | uint8_t pluggedEndpoint; 44 | 45 | const uint8_t numEndpoints; 46 | const uint8_t numInterfaces; 47 | const unsigned int *endpointType; 48 | 49 | PluggableUSBModule *next = NULL; 50 | 51 | friend class PluggableUSB_; 52 | }; 53 | 54 | class PluggableUSB_ { 55 | public: 56 | PluggableUSB_(); 57 | bool plug(PluggableUSBModule *node); 58 | int getInterface(uint8_t* interfaceCount); 59 | int getDescriptor(USBSetup& setup); 60 | bool setup(USBSetup& setup); 61 | void getShortName(char *iSerialNum); 62 | 63 | private: 64 | uint8_t lastIf; 65 | uint8_t lastEp; 66 | PluggableUSBModule* rootNode; 67 | uint8_t totalEP; 68 | }; 69 | 70 | // Replacement for global singleton. 71 | // This function prevents static-initialization-order-fiasco 72 | // https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use 73 | PluggableUSB_& PluggableUSB(); 74 | 75 | #endif -------------------------------------------------------------------------------- /cores/arduino/Printable.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 | 23 | class Print; 24 | 25 | /** The Printable class provides a way for new classes to allow themselves to be printed. 26 | By deriving from Printable and implementing the printTo method, it will then be possible 27 | for users to print out instances of this class by passing them into the usual 28 | Print::print and Print::println methods. 29 | */ 30 | 31 | class Printable 32 | { 33 | public: 34 | virtual size_t printTo(Print& p) const = 0; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /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/USBAPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | USBAPI.h 3 | Copyright (c) 2005-2014 Arduino. 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 __USBAPI__ 21 | #define __USBAPI__ 22 | 23 | #include 24 | 25 | //================================================================================ 26 | //================================================================================ 27 | // Low level API 28 | 29 | typedef struct __attribute__((packed)) 30 | { 31 | union { 32 | uint8_t bmRequestType; 33 | struct { 34 | uint8_t direction : 5; 35 | uint8_t type : 2; 36 | uint8_t transferDirection : 1; 37 | }; 38 | }; 39 | uint8_t bRequest; 40 | uint8_t wValueL; 41 | uint8_t wValueH; 42 | uint16_t wIndex; 43 | uint16_t wLength; 44 | } USBSetup; 45 | 46 | //================================================================================ 47 | //================================================================================ 48 | 49 | int USB_SendControl(uint8_t flags, const void* d, int len); 50 | int USB_RecvControl(void* d, int len); 51 | int USB_RecvControlLong(void* d, int len); 52 | 53 | uint8_t USB_Available(uint8_t ep); 54 | uint8_t USB_SendSpace(uint8_t ep); 55 | int USB_Send(uint8_t ep, const void* data, int len); // blocking 56 | int USB_Recv(uint8_t ep, void* data, int len); // non-blocking 57 | int USB_Recv(uint8_t ep); // non-blocking 58 | void USB_Flush(uint8_t ep); 59 | 60 | #endif -------------------------------------------------------------------------------- /cores/arduino/WInterrupts.h: -------------------------------------------------------------------------------- 1 | #ifndef W_INTERRUPTS_CPP 2 | #define W_INTERRUPTS_CPP 3 | // #ifdef __cplusplus 4 | 5 | // #include 6 | // #include 7 | // #include 8 | // #include "Common.h" 9 | 10 | // typedef uint8_t pin_size_t; 11 | 12 | // template 13 | // using voidTemplateFuncPtrParam = void (*)(T param); 14 | 15 | // template struct __container__ { 16 | // void* param; 17 | // voidTemplateFuncPtrParam function; 18 | // }; 19 | 20 | // // C++ only overloaded version of attachInterrupt function 21 | // template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T& param) { 22 | 23 | // struct __container__ *cont = new __container__(); 24 | // cont->param = ¶m; 25 | // cont->function = userFunc; 26 | 27 | // // TODO: check lambda scope 28 | // // TODO: add structure to delete(__container__) when detachInterrupt() is called 29 | // auto f = [](void* a) -> void 30 | // { 31 | // T param = *(T*)((struct __container__*)a)->param; 32 | // (((struct __container__*)a)->function)(param); 33 | // }; 34 | 35 | // attachInterruptParam(interruptNum, f, mode, cont); 36 | // } 37 | 38 | // template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T* param) { 39 | // attachInterruptParam(interruptNum, (voidFuncPtrParam)userFunc, mode, (void*)param); 40 | // } 41 | 42 | // #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /cores/arduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct { 6 | uint64_t a, b; 7 | } xorshift128p_state_t; 8 | 9 | static xorshift128p_state_t _xorshift128p_state = { UINT64_MAX - 1, 1 }; 10 | 11 | void randomSeed(unsigned long seed) { 12 | if (seed != 0) { 13 | _xorshift128p_state.a = seed; 14 | } 15 | } 16 | 17 | uint64_t xorshift128p(void) { 18 | uint64_t t = _xorshift128p_state.a; 19 | uint64_t const s = _xorshift128p_state.b; 20 | _xorshift128p_state.a = s; 21 | t ^= t << 23; 22 | t ^= t >> 17; 23 | t ^= s ^ (s >> 26); 24 | _xorshift128p_state.b = t; 25 | return t + s; 26 | } 27 | 28 | long random(long upperBound) { 29 | if (upperBound == 0) { 30 | return 0; 31 | } 32 | return xorshift128p() % upperBound; 33 | } 34 | 35 | long random(long lowerBound, long upperBound) { 36 | if (lowerBound >= upperBound) { 37 | return lowerBound; 38 | } 39 | long diff = upperBound - lowerBound; 40 | return random(diff) + lowerBound; 41 | } 42 | 43 | uint64_t getSeed() { 44 | rcu_periph_clock_enable(RCU_BKPI); 45 | rcu_periph_clock_enable(RCU_PMU); 46 | pmu_backup_write_enable(); 47 | bkp_deinit(); 48 | rcu_osci_on(RCU_IRC40K); 49 | rcu_osci_stab_wait(RCU_IRC40K); 50 | rcu_rtc_clock_config(RCU_RTCSRC_IRC40K); 51 | rcu_periph_clock_enable(RCU_RTC); 52 | rtc_register_sync_wait(); 53 | rtc_lwoff_wait(); 54 | rtc_configuration_mode_enter(); 55 | rtc_lwoff_wait(); 56 | rtc_interrupt_enable(RTC_INT_SECOND); 57 | rtc_lwoff_wait(); 58 | // increase second per about 1/100 second 59 | rtc_prescaler_set(399); 60 | rtc_lwoff_wait(); 61 | rtc_counter_set(0); 62 | rtc_lwoff_wait(); 63 | rtc_configuration_mode_exit(); 64 | rtc_lwoff_wait(); 65 | uint64_t ret = 0; 66 | uint32_t virtualCounter = 0; 67 | for (size_t i = 0; i < 64; i++) { 68 | ret = ret << 1; 69 | uint32_t v0 = rtc_counter_get(); 70 | while (v0 == rtc_counter_get()) { 71 | virtualCounter++; 72 | } 73 | ret = ret | (virtualCounter & 0x1); 74 | } 75 | return ret; 76 | } 77 | -------------------------------------------------------------------------------- /cores/arduino/deprecated-avr-comp/avr/dtostrf.c.impl: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2016 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 | // This is a default implementation for dtostrf function. 21 | // This file should be used if the standard lib doesn't provide an 22 | // implementation of dtostrf. 23 | 24 | // Create a file called "dtostrf.c" with the following include: 25 | // #include "api/deprecated-avr-comp/avr/dtostrf.c.impl" 26 | 27 | #include 28 | 29 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { 30 | asm(".global _printf_float"); 31 | 32 | char fmt[20]; 33 | sprintf(fmt, "%%%d.%df", width, prec); 34 | sprintf(sout, fmt, val); 35 | return sout; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /cores/arduino/deprecated-avr-comp/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/deprecated-avr-comp/avr/interrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LCC. 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 file. 21 | This file is here to allow compatibility with sketches (made for AVR) 22 | that includes 23 | */ 24 | -------------------------------------------------------------------------------- /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) 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 | // Standard C functions required in Arduino API 22 | // If these functions are not provided by the standard library, the 23 | // core should supply an implementation of them. 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern char* itoa(int value, char *string, int radix); 30 | extern char* ltoa(long value, char *string, int radix); 31 | extern char* utoa(unsigned value, char *string, int radix); 32 | extern char* ultoa(unsigned long value, char *string, int radix); 33 | 34 | #ifdef __cplusplus 35 | } // extern "C" 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /cores/arduino/main.cpp: -------------------------------------------------------------------------------- 1 | #define ARDUINO_MAIN 2 | #include "Arduino.h" 3 | #include "ArduinoAPI.h" 4 | #include "Common.h" 5 | #include "gd32vf103_libopt.h" 6 | #include "usart_com.h" 7 | 8 | 9 | #define cmb() __asm__ __volatile__ ("" ::: "memory") 10 | extern "C"{ void * __dso_handle = 0 ;} 11 | 12 | /* 13 | * \brief Main entry point of Arduino application 14 | */ 15 | int main( void ) 16 | { 17 | usart_com_init(USART0, USART_WL_8BIT, 115200U); 18 | 19 | setup(); 20 | 21 | do { 22 | loop(); 23 | //if (serialEventRun) 24 | // serialEventRun(); 25 | } while (1); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /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/usart_com.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2020 SCP. 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 | // Standard C functions required in Arduino API 22 | // If these functions are not provided by the standard library, the 23 | // core should supply an implementation of them. 24 | 25 | #include 26 | 27 | #include "pins_arduino.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | extern usart_buffer_t usart_rx_buffer[3]; 34 | 35 | void usart_com_init(uint32_t com, uint32_t wlen, unsigned long baud); 36 | int usart_readable(uint32_t com); 37 | int usart_writable(uint32_t com); 38 | int usart_put_char(uint32_t com, uint32_t wlen, uint8_t ch); 39 | int usart_put_buf(uint32_t com, uint32_t wlen, const uint8_t *buffer, size_t size); 40 | int usart_get_char(uint32_t com, uint32_t wlen); 41 | 42 | #ifdef __cplusplus 43 | } // extern "C" 44 | #endif 45 | -------------------------------------------------------------------------------- /cores/arduino/usart_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2020 SCP. 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 | // Standard C functions required in Arduino API 22 | // If these functions are not provided by the standard library, the 23 | // core should supply an implementation of them. 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #if !defined(SERIAL_BUFFER_SIZE) 32 | #if defined(SERIAL_RX_BUFFER_SIZE) 33 | #define SERIAL_BUFFER_SIZE SERIAL_RX_BUFFER_SIZE 34 | #endif 35 | #endif 36 | 37 | #if !defined(SERIAL_BUFFER_SIZE) 38 | #if ((RAMEND - RAMSTART) < 1023) 39 | #define SERIAL_BUFFER_SIZE 16 40 | #else 41 | #define SERIAL_BUFFER_SIZE 64 42 | #endif 43 | #endif 44 | #if (SERIAL_BUFFER_SIZE>256) 45 | typedef uint16_t usart_buffer_index_t; 46 | #else 47 | typedef uint8_t usart_buffer_index_t; 48 | #endif 49 | 50 | typedef struct { 51 | uint32_t _com; 52 | uint32_t wlen; 53 | usart_buffer_index_t head; 54 | usart_buffer_index_t tail; 55 | 56 | unsigned char data[SERIAL_BUFFER_SIZE]; 57 | } usart_buffer_t; 58 | 59 | #ifdef __cplusplus 60 | } // extern "C" 61 | #endif 62 | -------------------------------------------------------------------------------- /cores/arduino/wiring.c: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "gd32vf103.h" 3 | 4 | uint64_t millis(void){ 5 | return (uint64_t)(get_timer_value() * (4000.F / SystemCoreClock)); 6 | } 7 | 8 | uint64_t micros(void){ 9 | return (uint64_t)(get_timer_value() * (4000000.F / SystemCoreClock)); 10 | } 11 | 12 | void delay(unsigned long dwMs){ 13 | return delayMicroseconds(dwMs * 1000); 14 | } 15 | 16 | void delayMicroseconds(unsigned int dwUs){ 17 | uint64_t start_mtime, delta_mtime; 18 | 19 | // Don't start measuruing until we see an mtime tick 20 | uint64_t tmp = get_timer_value(); 21 | do { 22 | start_mtime = get_timer_value(); 23 | } while (start_mtime == tmp); 24 | 25 | do { 26 | delta_mtime = get_timer_value() - start_mtime; 27 | }while(delta_mtime <(SystemCoreClock/4000000.0 *dwUs )); 28 | 29 | return; 30 | } -------------------------------------------------------------------------------- /cores/arduino/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | #include "gd32vf103.h" 2 | #include "pins_arduino.h" 3 | #include "riscv_encoding.h" 4 | #include 5 | 6 | #define _ClockCyclesPerMicrosecond() (SystemCoreClock / 1000000) 7 | #define _ClockCyclesToMicroseconds(n) (n * 1000000 / SystemCoreClock) 8 | 9 | union _mcycle_full { 10 | uint64_t v; 11 | uint32_t v_part[2]; 12 | }; 13 | 14 | 15 | static inline uint64_t get_mcycle(void) { 16 | union _mcycle_full ret; 17 | __asm volatile("rdcycle %[l]" : [ l ] "=r"(ret.v_part[0]) :); 18 | __asm volatile("rdcycleh %[h]" : [ h ] "=r"(ret.v_part[1]) :); 19 | return ret.v; 20 | } 21 | 22 | unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout) { 23 | if (pin >= VARIANT_GPIO_NUM) { 24 | return 0; 25 | } 26 | 27 | // enable cycle counter by resetting bit 0 of mcountinhibit register 28 | uint32_t mcountinhibit = read_csr(0x320); 29 | write_csr(0x320, mcountinhibit & 0xFFFFFFFE); 30 | 31 | uint64_t timeoutInCycles = timeout * _ClockCyclesPerMicrosecond(); 32 | uint64_t start = get_mcycle(); 33 | while (gpio_input_bit_get(digitalPinToPort(pin), digitalPinToBitMask(pin)) 34 | != state) { 35 | if (get_mcycle() - start > timeoutInCycles) { 36 | return 0; 37 | } 38 | } 39 | uint64_t pulseBegin = get_mcycle(); 40 | while (gpio_input_bit_get(digitalPinToPort(pin), digitalPinToBitMask(pin)) 41 | == state) { 42 | if (get_mcycle() - start > timeoutInCycles) { 43 | return 0; 44 | } 45 | } 46 | uint64_t pulseEnd = get_mcycle(); 47 | return _ClockCyclesToMicroseconds(pulseEnd - pulseBegin); 48 | } 49 | 50 | unsigned long pulseInLong( 51 | pin_size_t pin, uint8_t state, unsigned long timeout) { 52 | /* as counted cycles are based on mcycle[h] */ 53 | return pulseIn(pin, state, timeout); 54 | } 55 | -------------------------------------------------------------------------------- /cores/arduino/wiring_shift.c: -------------------------------------------------------------------------------- 1 | #include "gd32vf103.h" 2 | #include "pins_arduino.h" 3 | #include 4 | 5 | void shiftOut( 6 | pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val) { 7 | if (dataPin >= VARIANT_GPIO_NUM) { 8 | return; 9 | } 10 | if (clockPin >= VARIANT_GPIO_NUM) { 11 | return; 12 | } 13 | gpio_bit_reset(digitalPinToPort(clockPin), digitalPinToBitMask(clockPin)); 14 | for (size_t i = 0; i < 8; i++) { 15 | if (bitOrder == LSBFIRST) { 16 | gpio_bit_write(digitalPinToPort(dataPin), 17 | digitalPinToBitMask(dataPin), (val & 0x01) == 0 ? RESET : SET); 18 | val = val >> 1; 19 | } 20 | else { 21 | gpio_bit_write(digitalPinToPort(dataPin), 22 | digitalPinToBitMask(dataPin), (val & 0x80) == 0 ? RESET : SET); 23 | val = val << 1; 24 | } 25 | gpio_bit_set(digitalPinToPort(clockPin), digitalPinToBitMask(clockPin)); 26 | gpio_bit_reset( 27 | digitalPinToPort(clockPin), digitalPinToBitMask(clockPin)); 28 | } 29 | } 30 | 31 | pin_size_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder) { 32 | pin_size_t ret = 0; 33 | if (dataPin >= VARIANT_GPIO_NUM) { 34 | return 0; 35 | } 36 | if (clockPin >= VARIANT_GPIO_NUM) { 37 | return 0; 38 | } 39 | gpio_bit_reset(digitalPinToPort(clockPin), digitalPinToBitMask(clockPin)); 40 | for (size_t i = 0; i < 8; i++) { 41 | if (bitOrder == LSBFIRST) { 42 | ret = ret >> 1; 43 | ret = ret 44 | & (gpio_input_bit_get( 45 | digitalPinToPort(dataPin), digitalPinToBitMask(dataPin)) 46 | << 7); 47 | } 48 | else { 49 | ret = ret << 1; 50 | ret = ret 51 | & gpio_input_bit_get( 52 | digitalPinToPort(dataPin), digitalPinToBitMask(dataPin)); 53 | } 54 | gpio_bit_set(digitalPinToPort(clockPin), digitalPinToBitMask(clockPin)); 55 | gpio_bit_reset( 56 | digitalPinToPort(clockPin), digitalPinToBitMask(clockPin)); 57 | } 58 | return ret; 59 | } 60 | -------------------------------------------------------------------------------- /libraries/FATFS/library.properties: -------------------------------------------------------------------------------- 1 | name=FATFS(gd32v) 2 | version=0.13 3 | author=ELM ChaN, Sipeed 4 | maintainer=Longduino 5 | sentence=Generic FAT/exFAT filesystem module for small embedded systems. 6 | paragraph=Once an FAT formatted memory card is connected to the SPI interface of the Longduino board you can create files and read/write on them. You can also move through directories on the FatFs card. 7 | category=Data Storage 8 | url=http://elm-chan.org/fsw/ff/00index_e.html 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/CRC_calculate/CRC_calculate.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | \file main.c 3 | \brief CRC calculate demo 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "gd32vf103.h" 36 | #include 37 | #include "gd32vf103v_eval.h" 38 | #include 39 | 40 | uint32_t val = 0, valcrc = 0; 41 | 42 | /*! 43 | \brief main function 44 | \param[in] none 45 | \param[out] none 46 | \retval none 47 | */ 48 | void setup() 49 | { 50 | val = (uint32_t)0xabcd1234; 51 | 52 | /* initialize the LED2 and LED3, turn off them */ 53 | gd_eval_led_init(LED2); 54 | gd_eval_led_init(LED3); 55 | gd_eval_led_off(LED2); 56 | gd_eval_led_off(LED3); 57 | rcu_periph_clock_enable(RCU_CRC); 58 | 59 | /* reset the CRC data register and calculate the CRC of the value */ 60 | crc_data_register_reset(); 61 | valcrc = crc_single_data_calculate(val); 62 | 63 | if(0xf7018a40 == valcrc){ 64 | gd_eval_led_on(LED2); 65 | gd_eval_led_on(LED3); 66 | } 67 | } 68 | 69 | void loop() 70 | { 71 | } 72 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/CRC_calculate/readme.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | \file readme.txt 3 | \brief description of CRC example 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, this 17 | list of conditions and the following disclaimer. 18 | 2. Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 3. Neither the name of the copyright holder nor the names of its contributors 22 | may be used to endorse or promote products derived from this software without 23 | specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 34 | OF SUCH DAMAGE. 35 | */ 36 | 37 | This example is based on the GD32VF103V-EVAL-V1.0 board, it shows how to use CRC to 38 | calculate the CRC value. 39 | 40 | In this demo, 1 CRC value is calculated for a 32-bit data. If the result is success, 41 | turn on the LED2 and LED3. 42 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/FWDGT_key/fwdgt_key_it.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file fwdgt_key_it.c 3 | \brief interrupt service routines 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "fwdgt_key_it.h" 36 | #include "gd32vf103v_eval.h" 37 | 38 | 39 | /*! 40 | \brief this function handles external lines 10 to 15 interrupt request 41 | \param[in] none 42 | \param[out] none 43 | \retval none 44 | */ 45 | void KEY_B_IRQHandler() 46 | { 47 | /* reload FWDGT counter */ 48 | fwdgt_counter_reload(); 49 | } 50 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/FWDGT_key/fwdgt_key_it.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file fwdgt_key_it.h 3 | \brief the header file of the ISR 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GD32VF103_IT_H 36 | #define GD32VF103_IT_H 37 | 38 | #include "gd32vf103.h" 39 | 40 | /* function declarations */ 41 | /* external lines 10 to 15 interrupt handle function */ 42 | void KEY_B_IRQHandler(); 43 | 44 | #endif /* GD32VF103_IT_H */ 45 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/FWDGT_key/readme.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | \file readme.txt 3 | \brief description of the FWDGT_key example 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | This demo is based on the GD32VF103V-EVAL-V1.0 board, it shows how to reload the 36 | FWDGT counter at regulate period using the EXTI interrupt. The FWDGT timeout 37 | is set to 1.6s (the timeout may varies due to IRC40K frequency dispersion). 38 | 39 | An EXTI is connected to a specific GPIO pin and configured to generate an interrupt 40 | on its falling edge: when the EXTI Line interrupt is triggered (by pressing the Key_B 41 | on the board), the corresponding interrupt is served. In the ISR, FWDGT counter is 42 | reloaded). As a result, when the FWDGT counter is reloaded, which prevents any FWDGT 43 | reset, LED2 or LED3 remains illuminated. 44 | 45 | If the EXTI Line interrupt does not occur, the FWDGT counter is not reloaded before 46 | the FWDGT counter reaches 00h, and the FWDGT reset. If the FWDGT reset is generated, 47 | LED2 and LED3 are turned off with the system reset. FWDGTRST flag is set by hardware, 48 | and then LED3 is turned on. 49 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/FadeRGB/FadeRGB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | GD32V analogWrite() test 3 | 4 | This sketch fades the RGB LED up and down on digital pins PC13, PA1 and PA2. 5 | This sketch was written for the Longan Nano, and will only work on other GD32V boards. 6 | 7 | The circuit: 8 | - LEDs attached on pins PC13, PA1 and PA2 to ground (already builtin on Longan Nano). 9 | 10 | created 8 Feb 2009 11 | by Tom Igoe 12 | modified 28 Nov 2020 13 | by SCP 14 | 15 | This example code is in the public domain. 16 | 17 | Based on: 18 | http://www.arduino.cc/en/Tutorial/AnalogWriteMega 19 | */ 20 | 21 | pin_size_t ledPins[] = { LED_RED, LED_GREEN, LED_BLUE }; 22 | 23 | // These constants won't change. They're used to give names to the pins used: 24 | const int lowestPin = 0; 25 | const int highestPin = 2; 26 | 27 | 28 | void doWrite(pin_size_t pinNumber, int value) { 29 | if (value == 255) { 30 | pinMode(pinNumber, OUTPUT); 31 | digitalWrite(pinNumber, HIGH); 32 | } else if (value == 0) { 33 | pinMode(pinNumber, OUTPUT); 34 | digitalWrite(pinNumber, LOW); 35 | } else if (analogWritable(pinNumber)) { 36 | pinMode(pinNumber, OUTPUT_ANALOG); 37 | analogWrite(pinNumber, value); 38 | } else { 39 | pinMode(pinNumber, OUTPUT); 40 | digitalWrite(pinNumber, LOW); 41 | } 42 | } 43 | 44 | void doRGB(int mask, int brightness) 45 | { 46 | int r, b, g; 47 | r = (mask & 4) ? brightness : 255; 48 | g = (mask & 2) ? brightness : 255; 49 | b = (mask & 1) ? brightness : 255; 50 | doWrite(ledPins[0], r); 51 | doWrite(ledPins[1], g); 52 | doWrite(ledPins[2], b); 53 | } 54 | 55 | void setup() { 56 | // set LED pins as outputs: 57 | for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { 58 | if (analogWritable(ledPins[thisPin])) { 59 | /* only available on pins with timer/PWM */ 60 | pinMode(ledPins[thisPin], OUTPUT_ANALOG); 61 | } else { 62 | /* fallback to digital output */ 63 | pinMode(ledPins[thisPin], OUTPUT); 64 | } 65 | } 66 | } 67 | 68 | void loop() { 69 | // iterate over the pins: 70 | for (int mask = 0; mask <= 0x7; mask++) { 71 | // fade the LED on thisPin from off to brightest: 72 | for (int brightness = 0; brightness <= 255; brightness++) { 73 | doRGB(mask, brightness); 74 | delay(4); 75 | } 76 | // fade the LED on thisPin from brightest to off: 77 | for (int brightness = 255; brightness >= 0; brightness--) { 78 | doRGB(mask, brightness); 79 | delay(4); 80 | } 81 | // pause between LED states: 82 | delay(100); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/GPIOInterrupt/GPIOInterrupt.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Button { 4 | const uint8_t PIN; 5 | uint32_t numberKeyPresses; 6 | bool pressed; 7 | }; 8 | 9 | Button button1 = {PB0, 0, false}; 10 | Button button2 = {BUTTON_BUILTIN, 0, false}; 11 | 12 | void led_toggle(pin_size_t ledPin) { 13 | if (digitalRead(ledPin) == HIGH) 14 | digitalWrite(ledPin, LOW); 15 | else 16 | digitalWrite(ledPin, HIGH); 17 | } 18 | 19 | void IRAM_ATTR isr1(void* arg) { 20 | Button* s = static_cast(arg); 21 | s->numberKeyPresses += 1; 22 | s->pressed = true; 23 | } 24 | 25 | void IRAM_ATTR isr2() { 26 | button2.numberKeyPresses += 1; 27 | button2.pressed = true; 28 | } 29 | 30 | void setup() { 31 | Serial.begin(115200); 32 | pinMode(LED_BUILTIN, OUTPUT); 33 | pinMode(button1.PIN, INPUT_PULLUP); 34 | attachInterruptArg(button1.PIN, isr1, &button1, FALLING); 35 | pinMode(button2.PIN, INPUT_PULLUP); 36 | attachInterrupt(button2.PIN, isr2, FALLING); 37 | } 38 | 39 | void loop() { 40 | if (button1.pressed) { 41 | Serial.printf("Button 1 has been pressed %lu times\n", button1.numberKeyPresses); 42 | button1.pressed = false; 43 | } 44 | if (button2.pressed) { 45 | led_toggle(LED_BUILTIN); 46 | Serial.printf("Button 2 has been pressed %lu times\n", button2.numberKeyPresses); 47 | button2.pressed = false; 48 | } 49 | static uint32_t lastMillis = 0; 50 | if (millis() - lastMillis > 10000) { 51 | lastMillis = millis(); 52 | detachInterrupt(button1.PIN); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/I2C_EEPROM/i2c.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file i2c.h 3 | \brief the header file of I2C 4 | 5 | \version 2020-08-04, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2020, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef I2C_H 36 | #define I2C_H 37 | 38 | #include "gd32vf103.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #define I2C0_SPEED 100000 45 | #define I2C0_SLAVE_ADDRESS7 0xA0 46 | #define I2C_PAGE_SIZE 8 47 | 48 | /* configure the GPIO ports */ 49 | void gpio_config(void); 50 | /* configure the I2C0 interfaces */ 51 | void i2c_config(void); 52 | /* reset i2c bus */ 53 | void i2c_bus_reset(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* I2C_H */ 60 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/I2C_EEPROM/readme.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | \file readme.txt 3 | \brief description of using the I2C bus to write and read EEPROM 4 | 5 | \version 2020-08-04, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2020, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | This demo is based on the GD32V103V-EVAL-V1.0 board, It describes a communication 36 | method between I2C bus and EEPROM with timeout and bus release function. The 37 | access result will be printed by COM0. 38 | 39 | Procedures sequentially writes 256 bytes of data to the EEPROM from the 0x00 40 | address, and then the program sequentially reads 256 bytes of data from the 41 | EEPROM from the 0x00 address. Compare the written data and read data, if the 42 | same,"I2C-AT24C02 test passed!" will be printed, while the board of the four 43 | LED lights start flashing, otherwise "Err:data read and write aren't matching." 44 | will be printed, while the four LEDs light will on. 45 | 46 | JP5 and JP6 must be fitted to USART. JP16 must be fitted to I2C. 47 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/RTC_Calendar/readme.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | \file readme.txt 3 | \brief description of calendar demo 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | This demo is based on the GD32VF103V-EVAL-V1.0 board, it explains how to configure the 36 | RTC module. In this demo, RTC peripheral is configured to display calendar. 37 | Select LXTAL as RTC clock source. And the HyperTerminal should be connected to the 38 | evaluation board via COM0. 39 | After start-up,if the BKP data register is written to a key value. If the value 40 | is incorrect, the program will ask to set the time on the HyperTerminal. If the 41 | key value is correct, by the HyperTerminal set time,the calendar will be displayed 42 | on the HyperTerminal. 43 | The RTC module is in the Backup Domain, and is not reset by the system reset. 44 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/RTC_Calendar/rtc.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file rtc.h 3 | \brief headfile of RTC check and config,time_show and time_adjust function 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __RTC_H 36 | #define __RTC_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "gd32vf103.h" 43 | #include 44 | 45 | void rtc_configuration(void); 46 | uint32_t time_regulate(void); 47 | void time_adjust(void); 48 | void time_display(uint32_t timevar); 49 | void time_show(void); 50 | uint8_t usart_scanf(uint32_t value); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* __RTC_H */ 57 | 58 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/RTC_Calendar/rtc_it.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file rtc_it.c 3 | \brief interrupt service routines 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "rtc_it.h" 36 | #include "gd32vf103v_eval.h" 37 | 38 | extern __IO uint32_t timedisplay; 39 | 40 | /*! 41 | \brief this function handles RTC global interrupt request 42 | \param[in] none 43 | \param[out] none 44 | \retval none 45 | */ 46 | void RTC_IRQHandler(void) 47 | { 48 | if (rtc_flag_get(RTC_FLAG_SECOND) != RESET){ 49 | /* clear the RTC second interrupt flag*/ 50 | rtc_flag_clear(RTC_FLAG_SECOND); 51 | 52 | /* enable time update */ 53 | timedisplay = 1; 54 | 55 | /* wait until last write operation on RTC registers has finished */ 56 | rtc_lwoff_wait(); 57 | /* reset RTC counter when time is 23:59:59 */ 58 | if (rtc_counter_get() == 0x00015180){ 59 | rtc_counter_set(0x0); 60 | /* wait until last write operation on RTC registers has finished */ 61 | rtc_lwoff_wait(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/RTC_Calendar/rtc_it.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file rtc_it.h 3 | \brief the header file of the ISR 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GD32VF103_IT_H 36 | #define GD32VF103_IT_H 37 | 38 | #include "gd32vf103.h" 39 | 40 | /* function declarations */ 41 | /* RTC global interrupt function */ 42 | void RTC_IRQHandler(void); 43 | 44 | #endif /* GD32VF103_IT_H */ 45 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/Tamper/readme.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | \file readme.txt 3 | \brief description of tamper demo 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | This demo is based on the GD32VF103V-EVAL-V1.0 board, it shows how to write/read data 36 | to/from backup data registers and demonstrates the tamper detection function. In 37 | this demo, the TAMPER pin is configured active on low level. 38 | After system start-up, it writes the data to all backup data registers, then check 39 | whether the data were correctly written. If yes, LED1 is on, otherwise LED2 is on. 40 | When the tamper key(TAMPER pin) is pressed, the backup data registers are reset and 41 | the tamper interrupt is generated. In the corresponding ISR, it checks whether the 42 | backup data registers are cleared or not. If yes, LED3 is on, otherwise LED4 is on. 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/Tamper/tamper_it.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file tamper_it.h 3 | \brief the header file of the ISR 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GD32VF103_IT_H 36 | #define GD32VF103_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "gd32vf103.h" 43 | 44 | /* function declarations */ 45 | /* TAMPER handle function */ 46 | void TAMPER_IRQHandler(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* GD32VF103_IT_H */ 53 | -------------------------------------------------------------------------------- /libraries/GD32V/examples/WWDGT_delay_feed/readme.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | \file readme.txt 3 | \brief description of the WWDGT_delay_feed example 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | This demo is based on the GD32VF103V-EVAL-V1.0 board, it shows the WWDGT with different 36 | counter value and window value make the different WWDGT timeout. As a result, LED1 37 | and LED2 display a different phenomenon. 38 | 39 | In this demo, the WWDGT counter value is set to 127, the refresh window is set to 40 | 80. In this case the WWDGT timeout is set to 38.8ms(the timeout may varies due to 41 | APB1 frequency dispersion), the value in the delay function is set to 30ms, the WWDGT 42 | counter can reloaded normally, the LED2 is turn off, LED3 is blinking fast. 43 | 44 | If the value in the delay function is not set properly, the WWDGT counter is not 45 | reloaded. As a result, the system reset and only the LED2 is remain illuminated. 46 | 47 | In this example the system clock is set to 108 MHz , and the APB1 is set to 54MHz. 48 | -------------------------------------------------------------------------------- /libraries/GD32V/library.properties: -------------------------------------------------------------------------------- 1 | name=GD32V 2 | version=0.1 3 | author=SCP 4 | maintainer=Longduino 5 | sentence=GD32V sketches examples 6 | paragraph= 7 | category=Other 8 | url= 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/GD32V/src/dummy.h: -------------------------------------------------------------------------------- 1 | // This file is here only to silence warnings from Arduino IDE 2 | // Currently IDE doesn't support no-code libraries, like this collection of example sketches. 3 | -------------------------------------------------------------------------------- /libraries/LCD/library.properties: -------------------------------------------------------------------------------- 1 | name=LCD 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=LCD display gd32v driver 6 | paragraph=LCD display gd32v driver 7 | category=Display 8 | url= 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /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 PB15 11 | ** MISO - pin PB14 12 | ** CLK - pin PB13 13 | ** CS - pin PB12 (Longan Nano) or PB1 (Wio Lite RISC-V) 14 | 15 | created 24 Nov 2010 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified for gd32v 31 Oct 2020 19 | by SCP 20 | 21 | This example code is in the public domain. 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | const int chipSelect = SDCARD_SS_PIN; 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(PB15, PB14, PB13, -1); 44 | // SDClass sd(spi); 45 | // sd.begin(PB12) 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 PB15 10 | ** MISO - pin PB14 11 | ** CLK - pin PB13 12 | ** CS - pin PB12 (Longan Nano) or PB1 (Wio Lite RISC-V) 13 | 14 | created 22 December 2010 15 | by Limor Fried 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified for gd32v 31 Oct 2020 19 | by SCP 20 | 21 | This example code is in the public domain. 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | const int chipSelect = SDCARD_SS_PIN; 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 PB15 8 | ** MISO - pin PB14 9 | ** CLK - pin PB13 10 | ** CS - pin PB12 (Longan Nano) or PB1 (Wio Lite RISC-V) 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | modified for gd32v 31 Oct 2020 17 | by SCP 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()) { 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 PB15 8 | ** MISO - pin PB14 9 | ** CLK - pin PB13 10 | ** CS - pin PB12 (Longan Nano) or PB1 (Wio Lite RISC-V) 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | modified for gd32v 31 Oct 2020 17 | by SCP 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()) { 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 PB15 10 | ** MISO - pin PB14 11 | ** CLK - pin PB13 12 | ** CS - pin PB12 (Longan Nano) or PB1 (Wio Lite RISC-V) 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 gd32v 31 Oct 2020 21 | by SCP 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()) { 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(gd32v) 2 | version=1.2.4 3 | author=Arduino, SparkFun, Neucrack, SCP 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=gd32v 10 | -------------------------------------------------------------------------------- /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/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 | beginTransaction KEYWORD2 17 | endTransaction KEYWORD2 18 | transfer KEYWORD2 19 | setBitOrder KEYWORD2 20 | setDataMode KEYWORD2 21 | setFrequency KEYWORD2 22 | 23 | ####################################### 24 | # Constants (LITERAL1) 25 | ####################################### 26 | SPI_MODE0 LITERAL1 27 | SPI_MODE1 LITERAL1 28 | SPI_MODE2 LITERAL1 29 | SPI_MODE3 LITERAL1 30 | -------------------------------------------------------------------------------- /libraries/SPI/library.properties: -------------------------------------------------------------------------------- 1 | name=SPI 2 | version=0.1 3 | author=Reinforce-II 4 | maintainer=Longduino 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=gd32v 10 | -------------------------------------------------------------------------------- /libraries/SPI/src/SPI.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIB_SPI_H__ 2 | #define __LIB_SPI_H__ 3 | 4 | #include "stdint.h" 5 | 6 | #define SPI_HAS_TRANSACTION 1 7 | 8 | #define SPI_LSBFIRST 0 9 | #define SPI_MSBFIRST 1 10 | 11 | #define SPI_MODE0 0 12 | #define SPI_MODE1 1 13 | #define SPI_MODE2 2 14 | #define SPI_MODE3 3 15 | 16 | 17 | class SPISettings { 18 | public: 19 | SPISettings() 20 | : _freq(1000000) 21 | , _bitOrder(SPI_MSBFIRST) 22 | , _dataMode(SPI_MODE0) {} 23 | SPISettings(uint32_t freq, uint8_t bitOrder, uint8_t dataMode) 24 | : _freq(freq) 25 | , _bitOrder(bitOrder) 26 | , _dataMode(dataMode) {} 27 | uint32_t _freq; 28 | uint8_t _bitOrder; 29 | uint8_t _dataMode; 30 | }; 31 | 32 | class SPIClass { 33 | private: 34 | uint32_t _dev; 35 | uint32_t _dev_clk; 36 | uint32_t _mosi_bank; 37 | uint32_t _miso_bank; 38 | uint32_t _sclk_bank; 39 | uint32_t _ssel_bank; 40 | uint32_t _mosi_bit; 41 | uint32_t _miso_bit; 42 | uint32_t _sclk_bit; 43 | uint32_t _ssel_bit; 44 | uint32_t _mosi_bank_clk; 45 | uint32_t _miso_bank_clk; 46 | uint32_t _sclk_bank_clk; 47 | uint32_t _ssel_bank_clk; 48 | uint8_t _dataMode; 49 | uint8_t _bitOrder; 50 | uint32_t _freq; 51 | uint8_t _ssel_hard; 52 | 53 | void beginTransaction(); 54 | 55 | public: 56 | SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel = -1); 57 | void begin(); 58 | void end(); 59 | 60 | void beginTransaction(SPISettings settings); 61 | void endTransaction(); 62 | 63 | // timeout in ms 64 | void transfer(uint8_t* data, uint32_t size, uint32_t timeout = 1); 65 | void transfer( 66 | uint8_t* txdata, uint8_t* rxdata, uint32_t size, uint32_t timeout = 1); 67 | uint8_t transfer(uint8_t data); 68 | uint16_t transfer16(uint16_t data); 69 | 70 | void setBitOrder(uint8_t bitOrder); 71 | void setDataMode(uint8_t dataMode); 72 | void setFrequency(uint32_t freq); 73 | }; 74 | 75 | extern SPIClass SPI; 76 | extern SPIClass SD_SPI; 77 | 78 | 79 | 80 | #endif //__LIB_SPI_H__ 81 | -------------------------------------------------------------------------------- /libraries/Seeed_GD32V_EXMC/examples/Flash2TFT/Flash2TFT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Seeed_GD32V_EXMC example: Flash2TFT 3 | 4 | Shows 16-bit color raw bitmap images and animations on Seeed EXMC TFT. 5 | 6 | Before you can run this, you need to run SD2Flash example one time 7 | to store image in SPI flash memory. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "EXMC.h" 13 | #include "TFT_eSPI.h" 14 | 15 | SPIFlash flash; 16 | 17 | // Use hardware SPI 18 | TFT_eSPI lcd = TFT_eSPI(); 19 | 20 | #define LCD_W 320 21 | #define LCD_H 240 22 | 23 | #define LCD_IMG_W 160 24 | #define LCD_IMG_H 80 25 | 26 | #define LCD_BUF_H 10 27 | 28 | static uint8_t lcdBuffer[LCD_IMG_W*LCD_BUF_H*2]; 29 | 30 | 31 | void lcd_drawImage(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t* img) 32 | { 33 | uint16_t curcolor = 0; 34 | lcd.setAddrWindow(x1, y1, width, height); 35 | lcd.startWrite(); 36 | for (int i = 0; i< (width*height); i++) { 37 | curcolor = ((img[i] & 0xFF) << 8) | ((img[i] & 0xFF00) >> 8); 38 | lcd.pushColor(curcolor, 1); 39 | } 40 | lcd.endWrite(); 41 | } 42 | 43 | void DrawImageFromFlash(uint16_t x,uint16_t y,uint16_t width,uint16_t height, uint32_t addr) 44 | { 45 | uint32_t offset = 0; 46 | uint16_t top = 0; 47 | uint16_t chunklines = LCD_BUF_H; 48 | uint16_t bottomlines = 0; 49 | uint32_t dataSize = width*height*2; 50 | size_t chunksize = sizeof(lcdBuffer); 51 | size_t bottomsize; 52 | 53 | chunklines=chunksize/(width*2); 54 | chunksize=width*2*chunklines; 55 | 56 | offset = 0; 57 | 58 | while (offset < dataSize) { 59 | top = 0; 60 | 61 | while (top+chunklines < height) { 62 | flash.readByteArray(addr+offset, lcdBuffer, (uint16_t)chunksize); 63 | lcd_drawImage(x,y+top,width,chunklines,(uint16_t*)&lcdBuffer); 64 | 65 | offset += chunksize; 66 | top += chunklines; 67 | } 68 | 69 | if (top < height) { 70 | bottomlines = height-top; 71 | bottomsize=width*2*bottomlines; 72 | 73 | flash.readByteArray(addr+offset, lcdBuffer, (uint16_t)bottomsize); 74 | lcd_drawImage(x,y+top,width,bottomlines,(uint16_t*)&lcdBuffer); 75 | 76 | offset += bottomsize; 77 | top += bottomlines; 78 | } 79 | } 80 | } 81 | 82 | void setup() 83 | { 84 | lcd.begin(); 85 | lcd.setTextSize(2); 86 | lcd.setTextColor(TFT_BLACK); 87 | 88 | flash.begin(); 89 | 90 | lcd.setRotation(3); 91 | // read image from address 0 and draw image 92 | DrawImageFromFlash(40, 20, LCD_IMG_W, LCD_IMG_H, 0); 93 | } 94 | 95 | void loop() 96 | { 97 | // 98 | } 99 | -------------------------------------------------------------------------------- /libraries/Seeed_GD32V_EXMC/examples/basic_exmc/basic_exmc.ino: -------------------------------------------------------------------------------- 1 | #include "SPI.h" 2 | #include "EXMC.h" 3 | #include "TFT_eSPI.h" 4 | 5 | // Use hardware SPI 6 | TFT_eSPI lcd = TFT_eSPI(); 7 | 8 | #define LCD_W 320 9 | #define LCD_H 240 10 | 11 | void func() 12 | { 13 | lcd.fillScreen(TFT_RED); 14 | lcd.drawRect(20, 20, 50, 50, TFT_WHITE); 15 | lcd.fillCircle(100, 100, 40, TFT_WHITE); 16 | lcd.fillTriangle(10, 200, 300, 200, 300, 150, TFT_WHITE); 17 | lcd.setTextSize(2); 18 | lcd.setTextColor(TFT_WHITE); 19 | lcd.setCursor(100,30); 20 | lcd.println("hello Seeed GD32V"); 21 | } 22 | 23 | void func2() 24 | { 25 | lcd.fillScreen(TFT_RED); 26 | lcd.drawRect(20, 20, 50, 50, TFT_WHITE); 27 | lcd.fillCircle(180, 50, 40, TFT_WHITE); 28 | lcd.fillTriangle(10, 300, 200, 300, 200, 150, TFT_WHITE); 29 | lcd.setTextSize(2); 30 | lcd.setTextColor(TFT_WHITE); 31 | lcd.setCursor(1,100); 32 | lcd.println("hello Seeed GD32V"); 33 | } 34 | 35 | void setup() 36 | { 37 | lcd.begin(); 38 | } 39 | 40 | void loop() 41 | { 42 | lcd.setRotation(1); 43 | func(); 44 | delay(3000); 45 | lcd.invertDisplay(true); 46 | func(); 47 | delay(3000); 48 | lcd.invertDisplay(false); 49 | lcd.setRotation(0); 50 | func2(); 51 | delay(3000); 52 | lcd.setRotation(3); 53 | func(); 54 | delay(3000); 55 | lcd.setRotation(2); 56 | func2(); 57 | delay(3000); 58 | } 59 | -------------------------------------------------------------------------------- /libraries/Seeed_GD32V_EXMC/library.properties: -------------------------------------------------------------------------------- 1 | name=Seeed_GD32V_EXMC 2 | version=1.0 3 | author=Seeed 4 | maintainer=LynnL4 5 | sentence=EXMC display gd32v driver 6 | paragraph=EXMC display gd32v driver 7 | category=Display 8 | url= 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/Seeed_GD32V_EXMC/src/EXMC.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * title: a arduino library for GD32 EXMC 5 | * 6 | * Author: Seeed 7 | * 8 | * Copyright (C) 2019 Seeed Technology Co.,Ltd. 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | #ifndef __EXMCClass_H 29 | #define __EXMCClass_H 30 | 31 | #include "Arduino.h" 32 | 33 | 34 | class EXMCClass 35 | { 36 | private: 37 | /* data */ 38 | public: 39 | EXMCClass(uint32_t cmdPtrAddr, uint32_t datPtrAddr); 40 | ~EXMCClass(); 41 | void begin(); 42 | void end(); 43 | uint8_t transfer(uint8_t data); 44 | uint16_t transfer16(uint16_t data); 45 | uint8_t command(uint8_t cmd); 46 | void transfer(void *buf, uint32_t count); 47 | private: 48 | volatile uint16_t* cmdPtr; 49 | volatile uint16_t* datPtr; 50 | }; 51 | 52 | #endif /*__EXMCClass_H*/ 53 | 54 | -------------------------------------------------------------------------------- /libraries/Seeed_GD32V_EXMC/src/TFT_comm.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "EXMC.h" 3 | 4 | #define LCD_CMD_ADDR 0x60000000 5 | #define LCD_DAT_ADDR (0x60000000+(0x03FFFFFE)) 6 | 7 | EXMCClass exmc(LCD_CMD_ADDR, LCD_DAT_ADDR); 8 | 9 | void interface_begin() 10 | { 11 | exmc.begin(); 12 | } 13 | 14 | uint8_t interface_transfer(uint8_t data) 15 | { 16 | //LOG(data); 17 | return exmc.transfer(data); 18 | } 19 | 20 | uint16_t interface_transfer16(uint16_t data) 21 | { 22 | return exmc.transfer16(data); 23 | } 24 | 25 | void interface_transfer(void *data, uint32_t count) 26 | { 27 | exmc.transfer(data, count); 28 | } 29 | 30 | void interface_end() 31 | { 32 | return; 33 | } 34 | 35 | void interface_writeCommand(uint8_t c) 36 | { 37 | exmc.command(c); 38 | } 39 | 40 | void interface_writeData(uint8_t d) 41 | { 42 | exmc.transfer(d); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/examples/160x80/TFT_Mandlebrot/TFT_Mandlebrot.ino: -------------------------------------------------------------------------------- 1 | // Mandlebrot 2 | 3 | // This will run quite slowly due to the large number of floating point calculations per pixel 4 | 5 | #include 6 | 7 | #define LCD_W 160 8 | #define LCD_H 80 9 | 10 | Sipeed_GD32V_LCD tft(LCD_W, LCD_H); 11 | 12 | #define COLOR_GREY 0x7BEF 13 | 14 | unsigned long runTime = 0; 15 | 16 | float sx = 0, sy = 0; 17 | uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0; 18 | 19 | void setup() { 20 | Serial.begin(250000); 21 | //randomSeed(analogRead(A0)); 22 | Serial.println(); 23 | // Setup the LCD 24 | tft.begin(); 25 | tft.setRotation(2); 26 | } 27 | 28 | void loop() { 29 | runTime = millis(); 30 | 31 | tft.fillScreen(COLOR_BLACK); 32 | tft.startWrite(); 33 | for (int px = 1; px < LCD_W; px++) { 34 | for (int py = 0; py < LCD_H; py++) { 35 | float x0 = (map(px, 0, LCD_W, -250000 / 2, 36 | -242500 / 2)) / 100000.0; //scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1)) 37 | float yy0 = (map(py, 0, LCD_H, -75000 / 4, 38 | -61000 / 4)) / 100000.0; //scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1)) 39 | float xx = 0.0; 40 | float yy = 0.0; 41 | int iteration = 0; 42 | int max_iteration = 128; 43 | while (((xx * xx + yy * yy) < 4) && (iteration < max_iteration)) { 44 | float xtemp = xx * xx - yy * yy + x0; 45 | yy = 2 * xx * yy + yy0; 46 | xx = xtemp; 47 | iteration++; 48 | } 49 | int color = rainbow((3 * iteration + 64) % 128); 50 | yield(); tft.drawPixel(px, py, color); 51 | } 52 | } 53 | tft.endWrite(); 54 | 55 | Serial.println(millis() - runTime); 56 | while (1) { 57 | yield(); 58 | } 59 | } 60 | 61 | unsigned int rainbow(int value) { 62 | // Value is expected to be in range 0-127 63 | // The value is converted to a spectrum colour from 0 = blue through to red = blue 64 | 65 | byte red = 0; // Red is the top 5 bits of a 16 bit colour value 66 | byte green = 0;// Green is the middle 6 bits 67 | byte blue = 0; // Blue is the bottom 5 bits 68 | 69 | byte quadrant = value / 32; 70 | 71 | if (quadrant == 0) { 72 | blue = 31; 73 | green = 2 * (value % 32); 74 | red = 0; 75 | } 76 | if (quadrant == 1) { 77 | blue = 31 - (value % 32); 78 | green = 63; 79 | red = 0; 80 | } 81 | if (quadrant == 2) { 82 | blue = 0; 83 | green = 63; 84 | red = value % 32; 85 | } 86 | if (quadrant == 3) { 87 | blue = 0; 88 | green = 63 - 2 * (value % 32); 89 | red = 31; 90 | } 91 | return (red << 11) + (green << 5) + blue; 92 | } 93 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/examples/160x80/TFT_Spiro/TFT_Spiro.ino: -------------------------------------------------------------------------------- 1 | // Spiro 2 | // Rainbow patern generator 3 | 4 | #include 5 | 6 | #define LCD_W 160 7 | #define LCD_H 80 8 | 9 | Sipeed_GD32V_LCD tft(LCD_W, LCD_H); 10 | 11 | #define DEG2RAD 0.0174532925 // Convert angles in degrees to radians 12 | 13 | unsigned long runTime = 0; 14 | 15 | float sx = 0, sy = 0; 16 | uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0; 17 | 18 | void setup() { 19 | //randomSeed(analogRead(A0)); 20 | 21 | // Setup the LCD 22 | tft.begin(); 23 | tft.setRotation(2); 24 | } 25 | 26 | void loop() { 27 | runTime = millis(); 28 | 29 | tft.fillScreen(COLOR_BLACK); 30 | int n = random(2, 23), r = random(20, (LCD_H/2)-20), colour = 0; //rainbow(); 31 | 32 | for (long i = 0; i < (360 * n); i++) { 33 | sx = cos((i / n - 90) * DEG2RAD); 34 | sy = sin((i / n - 90) * DEG2RAD); 35 | x0 = sx * ((LCD_H/2) - r) + (LCD_W/2)-1; 36 | yy0 = sy * ((LCD_H/2) - r) + (LCD_H/2)-1; 37 | 38 | 39 | sy = cos(((i % 360) - 90) * DEG2RAD); 40 | sx = sin(((i % 360) - 90) * DEG2RAD); 41 | x1 = sx * r + x0; 42 | yy1 = sy * r + yy0; 43 | tft.drawPixel(x1, yy1, rainbow(map(i % 360, 0, 360, 0, 127))); //colour); 44 | } 45 | 46 | r = random(20, (LCD_H/2)-20);//r = r / random(2,4); 47 | for (long i = 0; i < (360 * n); i++) { 48 | sx = cos((i / n - 90) * DEG2RAD); 49 | sy = sin((i / n - 90) * DEG2RAD); 50 | x0 = sx * ((LCD_H/2) - r) + (LCD_W/2)-1; 51 | yy0 = sy * ((LCD_H/2) - r) + (LCD_H/2)-1; 52 | 53 | 54 | sy = cos(((i % 360) - 90) * DEG2RAD); 55 | sx = sin(((i % 360) - 90) * DEG2RAD); 56 | x1 = sx * r + x0; 57 | yy1 = sy * r + yy0; 58 | tft.drawPixel(x1, yy1, rainbow(map(i % 360, 0, 360, 0, 127))); //colour); 59 | } 60 | 61 | 62 | delay(2000); 63 | } 64 | 65 | unsigned int rainbow(int value) { 66 | // Value is expected to be in range 0-127 67 | // The value is converted to a spectrum colour from 0 = blue through to red = blue 68 | //int value = random (128); 69 | byte red = 0; // Red is the top 5 bits of a 16 bit colour value 70 | byte green = 0;// Green is the middle 6 bits 71 | byte blue = 0; // Blue is the bottom 5 bits 72 | 73 | byte quadrant = value / 32; 74 | 75 | if (quadrant == 0) { 76 | blue = 31; 77 | green = 2 * (value % 32); 78 | red = 0; 79 | } 80 | if (quadrant == 1) { 81 | blue = 31 - (value % 32); 82 | green = 63; 83 | red = 0; 84 | } 85 | if (quadrant == 2) { 86 | blue = 0; 87 | green = 63; 88 | red = value % 32; 89 | } 90 | if (quadrant == 3) { 91 | blue = 0; 92 | green = 63 - 2 * (value % 32); 93 | red = 31; 94 | } 95 | return (red << 11) + (green << 5) + blue; 96 | } 97 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/examples/160x80/TFT_Starfield/TFT_Starfield.ino: -------------------------------------------------------------------------------- 1 | // Animates white pixels to simulate flying through a star field 2 | 3 | #include 4 | 5 | #define LCD_W 160 6 | #define LCD_H 80 7 | 8 | Sipeed_GD32V_LCD tft(LCD_W, LCD_H); 9 | 10 | // With 1024 stars the update rate is ~65 frames per second 11 | #define NSTARS 1024 12 | uint8_t sx[NSTARS] = {}; 13 | uint8_t sy[NSTARS] = {}; 14 | uint8_t sz[NSTARS] = {}; 15 | 16 | uint8_t za, zb, zc, zx; 17 | 18 | // Fast 0-255 random number generator from http://eternityforest.com/Projects/rng.php: 19 | uint8_t __attribute__((always_inline)) rng() { 20 | zx++; 21 | za = (za ^ zc ^ zx); 22 | zb = (zb + za); 23 | zc = (zc + (zb >> 1)^za); 24 | return zc; 25 | } 26 | 27 | void setup() { 28 | za = random(256); 29 | zb = random(256); 30 | zc = random(256); 31 | zx = random(256); 32 | 33 | Serial.begin(115200); 34 | tft.begin(); 35 | tft.setRotation(0); 36 | tft.fillScreen(COLOR_BLACK); 37 | 38 | // fastSetup() must be used immediately before fastPixel() to prepare screen 39 | // It must be called after any other graphics drawing function call if fastPixel() 40 | // is to be called again 41 | //tft.fastSetup(); // Prepare plot window range for fast pixel plotting 42 | } 43 | 44 | void loop() { 45 | unsigned long t0 = micros(); 46 | uint8_t spawnDepthVariation = 255; 47 | 48 | for (int i = 0; i < NSTARS; ++i) { 49 | if (sz[i] <= 1) { 50 | sx[i] = (LCD_W/2) - (LCD_H/2) + rng(); 51 | sy[i] = rng(); 52 | sz[i] = spawnDepthVariation--; 53 | } else { 54 | int old_screen_x = ((int)sx[i] - (LCD_W/2)) * 256 / sz[i] + (LCD_W/2); 55 | int old_screen_y = ((int)sy[i] - (LCD_H/2)) * 256 / sz[i] + (LCD_H/2); 56 | 57 | // This is a faster pixel drawing function for occassions where many single pixels must be drawn 58 | tft.drawPixel(old_screen_x, old_screen_y, COLOR_BLACK); 59 | 60 | sz[i] -= 2; 61 | if (sz[i] > 1) { 62 | int screen_x = ((int)sx[i] - (LCD_W/2)) * 256 / sz[i] + (LCD_W/2); 63 | int screen_y = ((int)sy[i] - (LCD_H/2)) * 256 / sz[i] + (LCD_H/2); 64 | 65 | if (screen_x >= 0 && screen_y >= 0 && screen_x < LCD_W && screen_y < LCD_H) { 66 | uint8_t r, g, b; 67 | r = g = b = 255 - sz[i]; 68 | tft.drawPixel(screen_x, screen_y, tft.color565(r, g, b)); 69 | } else { 70 | sz[i] = 0; // Out of screen, die. 71 | } 72 | } 73 | } 74 | } 75 | unsigned long t1 = micros(); 76 | //static char timeMicros[8] = {}; 77 | 78 | // Calcualte frames per second 79 | Serial.println(1.0 / ((t1 - t0) / 1000000.0)); 80 | } 81 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/examples/basic_display/basic_display.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Sipeed_GD32V_LCD lcd(160, 80); 4 | 5 | 6 | void func() 7 | { 8 | lcd.fillScreen(COLOR_RED); 9 | lcd.drawRect(5, 5, 15, 15, COLOR_WHITE); 10 | lcd.fillCircle(135, 60, 15, COLOR_WHITE); 11 | lcd.fillTriangle(40, 76, 100, 76, 100, 50, COLOR_WHITE); 12 | lcd.setTextSize(2); 13 | lcd.setTextColor(COLOR_WHITE); 14 | lcd.setCursor(5,25); 15 | lcd.println("hello Sipeed GD32V"); 16 | } 17 | 18 | void func2() 19 | { 20 | lcd.fillScreen(COLOR_RED); 21 | lcd.drawRect(5, 5, 15, 15, COLOR_WHITE); 22 | lcd.fillCircle(50, 135, 15, COLOR_WHITE); 23 | lcd.fillTriangle(10, 110, 60, 110, 60, 75, COLOR_WHITE); 24 | lcd.setTextSize(2); 25 | lcd.setTextColor(COLOR_WHITE); 26 | lcd.setCursor(1,25); 27 | lcd.println("hello Sipeed GD32V"); 28 | } 29 | 30 | void setup() 31 | { 32 | lcd.begin(15000000, COLOR_RED); 33 | } 34 | 35 | void loop() 36 | { 37 | lcd.setRotation(0); 38 | func(); 39 | delay(3000); 40 | lcd.invertDisplay(true); 41 | func(); 42 | delay(3000); 43 | lcd.setRotation(1); 44 | func2(); 45 | delay(3000); 46 | lcd.setRotation(2); 47 | func(); 48 | delay(3000); 49 | lcd.setRotation(3); 50 | func2(); 51 | delay(3000); 52 | } 53 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/examples/image_display/image_display.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Sipeed_GD32V_LCD example: image_display 3 | 4 | Shows 16-bit color raw bitmap images and animations on Longan Nano LCD. 5 | 6 | To run this, you need to put this files on SD card: 7 | https://github.com/sipeed/Longan_GD32VF_examples/tree/master/put_into_tf_card 8 | 9 | Convert your own images using ffmpeg: 10 | ffmpeg -i image.png -f rawvideo -pix_fmt rgb565be image.bin 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #define LCD_W 160 17 | #define LCD_H 80 18 | 19 | #define LCD_BUF_H 10 20 | 21 | Sipeed_GD32V_LCD lcd(LCD_W, LCD_H); 22 | 23 | static uint8_t lcdBuffer[LCD_W*LCD_BUF_H*2]; 24 | bool sdMounted = false; 25 | 26 | 27 | void DrawImageFromFile(const char* path) 28 | { 29 | uint32_t offset = 0; 30 | uint16_t top = 0; 31 | uint32_t dataSize = 0; 32 | File dataFile; 33 | 34 | if (!sdMounted) { 35 | lcd.setTextSize(1); 36 | 37 | lcd.setTextColor(COLOR_BLACK); 38 | lcd.setCursor(24,16); 39 | lcd.println("No card found!"); 40 | 41 | lcd.setTextColor(COLOR_BLUE); 42 | lcd.setCursor(24,32); 43 | lcd.println("No card found!"); 44 | 45 | lcd.setTextColor(COLOR_RED); 46 | lcd.setCursor(24,48); 47 | lcd.println("No card found!"); 48 | 49 | return; 50 | } 51 | 52 | dataFile = SD.open(path, FILE_READ); 53 | if (dataFile) 54 | { 55 | dataSize = dataFile.size(); 56 | offset = 0; 57 | while (offset < dataSize) { 58 | top = 0; 59 | 60 | while (top < LCD_H) { 61 | dataFile.seek(offset); 62 | dataFile.read(lcdBuffer, (uint16_t)sizeof(lcdBuffer)); 63 | lcd.drawImage(0,top,LCD_W,LCD_BUF_H,(uint16_t*)&lcdBuffer); 64 | 65 | offset += sizeof(lcdBuffer); 66 | top += LCD_BUF_H; 67 | } 68 | } 69 | 70 | dataFile.close(); 71 | } 72 | else 73 | { 74 | lcd.setTextSize(1); 75 | lcd.setTextColor(COLOR_BLACK); 76 | lcd.setCursor(24,16); 77 | lcd.println("File not found."); 78 | 79 | lcd.setTextSize(2); 80 | lcd.setTextColor(COLOR_RED); 81 | lcd.setCursor(0,32); 82 | lcd.printf("File %s not found.", path); 83 | } 84 | } 85 | 86 | void setup() 87 | { 88 | lcd.begin(13500000, COLOR_WHITE); 89 | lcd.setTextSize(2); 90 | lcd.setTextColor(COLOR_BLACK); 91 | 92 | sdMounted = SD.begin(); 93 | } 94 | 95 | void loop() 96 | { 97 | DrawImageFromFile("logo.bin"); 98 | delay(1500); 99 | lcd.fillScreen(COLOR_WHITE); 100 | DrawImageFromFile("bmp.bin"); 101 | delay(1500); 102 | lcd.fillScreen(COLOR_WHITE); 103 | } 104 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/library.properties: -------------------------------------------------------------------------------- 1 | name=Sipeed_GD32V_LCD 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=LCD display gd32v driver 6 | paragraph=LCD display gd32v driver 7 | category=Display 8 | url= 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/src/ST7735_Commands.h: -------------------------------------------------------------------------------- 1 | #ifndef _ST7735_COMMANDS_H_ 2 | #define _ST7735_COMMANDS_H_ 3 | 4 | // ST7735 specific commands used in init 5 | #define ST7735_NOP 0x00 6 | #define ST7735_SWRESET 0x01 7 | #define ST7735_RDDID 0x04 8 | #define ST7735_RDDST 0x09 9 | 10 | #define ST7735_SLPIN 0x10 11 | #define ST7735_SLPOUT 0x11 12 | #define ST7735_PTLON 0x12 13 | #define ST7735_NORON 0x13 14 | 15 | #define ST7735_INVOFF 0x20 16 | #define ST7735_INVON 0x21 17 | #define ST7735_DISPOFF 0x28 18 | #define ST7735_DISPON 0x29 19 | #define ST7735_CASET 0x2A 20 | #define ST7735_RASET 0x2B // PASET 21 | #define ST7735_RAMWR 0x2C 22 | #define ST7735_RAMRD 0x2E 23 | 24 | #define ST7735_PTLAR 0x30 25 | #define ST7735_COLMOD 0x3A 26 | #define ST7735_MADCTL 0x36 27 | 28 | #define ST7735_FRMCTR1 0xB1 29 | #define ST7735_FRMCTR2 0xB2 30 | #define ST7735_FRMCTR3 0xB3 31 | #define ST7735_INVCTR 0xB4 32 | #define ST7735_DISSET5 0xB6 33 | 34 | #define ST7735_PWCTR1 0xC0 35 | #define ST7735_PWCTR2 0xC1 36 | #define ST7735_PWCTR3 0xC2 37 | #define ST7735_PWCTR4 0xC3 38 | #define ST7735_PWCTR5 0xC4 39 | #define ST7735_VMCTR1 0xC5 40 | 41 | #define ST7735_RDID1 0xDA 42 | #define ST7735_RDID2 0xDB 43 | #define ST7735_RDID3 0xDC 44 | #define ST7735_RDID4 0xDD 45 | 46 | #define ST7735_PWCTR6 0xFC 47 | 48 | #define ST7735_GMCTRP1 0xE0 49 | #define ST7735_GMCTRN1 0xE1 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libraries/Sipeed_GD32V_LCD/src/Sipeed_GD32V_LCD.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIPEED_GD32V_LCD_H 2 | #define _SIPEED_GD32V_LCD_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | 9 | #define COLOR_BLACK 0x0000 10 | #define COLOR_NAVY 0x000F 11 | #define COLOR_DARKGREEN 0x03E0 12 | #define COLOR_DARKCYAN 0x03EF 13 | #define COLOR_MAROON 0x7800 14 | #define COLOR_PURPLE 0x780F 15 | #define COLOR_OLIVE 0x7BE0 16 | #define COLOR_LIGHTGREY 0xC618 17 | #define COLOR_DARKGREY 0x7BEF 18 | #define COLOR_BLUE 0x001F 19 | #define COLOR_GREEN 0x07E0 20 | #define COLOR_CYAN 0x07FF 21 | #define COLOR_RED 0xF800 22 | #define COLOR_MAGENTA 0xF81F 23 | #define COLOR_YELLOW 0xFFE0 24 | #define COLOR_WHITE 0xFFFF 25 | #define COLOR_ORANGE 0xFD20 26 | #define COLOR_GREENYELLOW 0xAFE5 27 | #define COLOR_PINK 0xF81F 28 | 29 | 30 | class Sipeed_GD32V_LCD : public Adafruit_GFX{ 31 | public: 32 | /** 33 | * @param rst_pin -1: not use reset pin 34 | */ 35 | Sipeed_GD32V_LCD(uint16_t w, uint16_t h); 36 | 37 | ~Sipeed_GD32V_LCD(void); 38 | 39 | boolean begin( uint32_t freq = 15000000, uint16_t color = 0xffff ); 40 | 41 | void drawImage(int16_t x1, int16_t y1, int16_t width, int16_t height, uint16_t* img); 42 | 43 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color); 44 | virtual void writePixel(int16_t x, int16_t y, uint16_t color); 45 | virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 46 | virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 47 | virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 48 | 49 | virtual void 50 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 51 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 52 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 53 | fillScreen(uint16_t color), 54 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 55 | 56 | void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth); 57 | 58 | virtual void setRotation(uint8_t r); 59 | virtual void invertDisplay(boolean invert); 60 | 61 | uint16_t color565(uint8_t r, uint8_t g, uint8_t b); 62 | 63 | private: 64 | void writecommand(uint8_t c); 65 | void writedata(uint8_t c); 66 | void writedata16(uint16_t c); 67 | void drawWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2,uint16_t color, int16_t lineWidth); 68 | void fillWindow(int16_t xsta,int16_t ysta,int16_t xend,int16_t yend,uint16_t color); 69 | void setAddrWindow(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2); 70 | void writeRotation(void); 71 | 72 | uint32_t _freq; 73 | uint16_t _screenDir; 74 | 75 | 76 | }; 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /libraries/SysTick/library.properties: -------------------------------------------------------------------------------- 1 | name=Sipeed_GD32V_SysTick 2 | version=1.0 3 | author=Neucrack 4 | maintainer=Neucrack 5 | sentence=SysTick gd32v driver 6 | paragraph=SysTick gd32v driver 7 | category=Display 8 | url= 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/SysTick/src/systick.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file systick.c 3 | \brief the systick configuration file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "gd32vf103.h" 36 | #include "systick.h" 37 | 38 | //===================== 39 | uint64_t get_time(void) 40 | { 41 | uint64_t curr_mtime; 42 | 43 | // Wait for next mtime tick 44 | uint64_t tmp = get_timer_value(); 45 | do { 46 | curr_mtime = get_timer_value(); 47 | } while (curr_mtime == tmp); 48 | return curr_mtime; // time in system ticks 49 | } 50 | 51 | /*! 52 | \brief delay a time in milliseconds 53 | \param[in] count: count in milliseconds 54 | \param[out] none 55 | \retval none 56 | */ 57 | void delay_1ms(uint32_t count) 58 | { 59 | uint64_t start_mtime, delta_mtime; 60 | 61 | // Don't start measuruing until we see an mtime tick 62 | uint64_t tmp = get_timer_value(); 63 | do { 64 | start_mtime = get_timer_value(); 65 | } while (start_mtime == tmp); 66 | 67 | do { 68 | delta_mtime = get_timer_value() - start_mtime; 69 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 70 | } 71 | -------------------------------------------------------------------------------- /libraries/SysTick/src/systick.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file systick.h 3 | \brief the header file of systick 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef SYS_TICK_H 36 | #define SYS_TICK_H 37 | 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | uint64_t get_time(void); 45 | void delay_1ms(uint32_t count); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* SYS_TICK_H */ 52 | -------------------------------------------------------------------------------- /libraries/TF_CARD/library.properties: -------------------------------------------------------------------------------- 1 | name=TF_CARD(gd32v) 2 | version=1.2.4 3 | author=Arduino, SparkFun, Neucrack 4 | maintainer=Sipeed 5 | sentence=Enables reading and writing on TF_CARD cards. 6 | paragraph=Once an TF_CARD 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 TF_CARD card. 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/TF_CARD 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/TF_CARD/src/tf_card.h: -------------------------------------------------------------------------------- 1 | #ifndef _TF_CARD_H_ 2 | #define _TF_CARD_H_ 3 | 4 | #include "tf_card_pjt_include.h" 5 | #include "diskio.h" 6 | #include "ff.h" 7 | #include "systick.h" 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /libraries/TF_CARD/src/tf_card_pjt_include.h: -------------------------------------------------------------------------------- 1 | #ifndef _GD32V_PJT_INCLUDE_ 2 | #define _GD32V_PJT_INCLUDE_ 3 | 4 | #include "gd32vf103_libopt.h" 5 | #include 6 | 7 | #define PA_OUT(n,s) \ 8 | ({ if (s%2) gpio_bit_set(GPIOA, GPIO_PIN_##n); \ 9 | else gpio_bit_reset(GPIOA, GPIO_PIN_##n); }) 10 | #define PA_IN(n) gpio_input_bit_get(GPIOA, GPIO_PIN_##n) 11 | 12 | #define PB_OUT(n,s) \ 13 | ({ if (s%2) gpio_bit_set(GPIOB, GPIO_PIN_##n); \ 14 | else gpio_bit_reset(GPIOB, GPIO_PIN_##n); }) 15 | #define PB_IN(n) gpio_input_bit_get(GPIOB, GPIO_PIN_##n) 16 | 17 | #define PC_OUT(n,s) \ 18 | ({ if (s%2) gpio_bit_set(GPIOC, GPIO_PIN_##n); \ 19 | else gpio_bit_reset(GPIOC, GPIO_PIN_##n); }) 20 | #define PC_IN(n) gpio_input_bit_get(GPIOC, GPIO_PIN_##n) 21 | 22 | #define LEDR_TOG gpio_bit_write(GPIOC, GPIO_PIN_13, (bit_status)(1-gpio_input_bit_get(GPIOC, GPIO_PIN_13))) 23 | #define LEDR(s) PC_OUT(13, s) 24 | #define LEDG_TOG gpio_bit_write(GPIOA, GPIO_PIN_1, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_1))) 25 | #define LEDG(s) PA_OUT(1, s) 26 | #define LEDB_TOG gpio_bit_write(GPIOA, GPIO_PIN_2, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_2))) 27 | #define LEDB(s) PA_OUT(2, s) 28 | 29 | #endif /* _GD32V_PJT_INCLUDE_ */ 30 | -------------------------------------------------------------------------------- /libraries/Ticker/examples/Arguments/Arguments.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LED_PIN LED_BUILTIN 5 | 6 | Ticker tickerSetHigh(TIMERID1); 7 | Ticker tickerSetLow(TIMERID2); 8 | 9 | void setPin(PinStatus state) { 10 | digitalWrite(LED_PIN, state); 11 | } 12 | 13 | void setup() { 14 | pinMode(LED_PIN, OUTPUT); 15 | 16 | // every 25 ms, call setPin(0) 17 | tickerSetLow.attach_ms(25, setPin, LOW); 18 | 19 | // every 26 ms, call setPin(1) 20 | tickerSetHigh.attach_ms(26, setPin, HIGH); 21 | } 22 | 23 | void loop() { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /libraries/Ticker/examples/Blinker/Blinker.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LED_PIN LED_BUILTIN 5 | 6 | Ticker blinker(TIMERID0); 7 | Ticker toggler(TIMERID1); 8 | Ticker changer(TIMERID2); 9 | float blinkerPace = 0.1; //seconds 10 | const float togglePeriod = 5; //seconds 11 | 12 | void change() { 13 | blinkerPace = 0.5; 14 | } 15 | 16 | void blink() { 17 | if (digitalRead(LED_PIN) == HIGH) 18 | digitalWrite(LED_PIN, LOW); 19 | else 20 | digitalWrite(LED_PIN, HIGH); 21 | } 22 | 23 | void toggle() { 24 | static bool isBlinking = false; 25 | if (isBlinking) { 26 | blinker.detach(); 27 | isBlinking = false; 28 | } 29 | else { 30 | blinker.attach(blinkerPace, blink); 31 | isBlinking = true; 32 | } 33 | digitalWrite(LED_PIN, LOW); //make sure LED on on after toggling (pin LOW = led ON) 34 | } 35 | 36 | void setup() { 37 | pinMode(LED_PIN, OUTPUT); 38 | toggler.attach(togglePeriod, toggle); 39 | changer.once(30, change); 40 | } 41 | 42 | void loop() { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /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=gd32v 10 | -------------------------------------------------------------------------------- /libraries/Ticker/src/TInterrupts.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C"{ 3 | #endif 4 | 5 | #include "pins_arduino.h" 6 | 7 | void attachTicker(uint8_t interruptNumber, voidFuncPtr callback, uint32_t microseconds); 8 | void attachTickerParam(uint8_t interruptNumber, voidFuncPtrParam callback, uint32_t microseconds, void* param); 9 | void detachTicker(uint8_t interruptNumber); 10 | 11 | #define attachTickerArg(p,c,a,m) attachTickerParam(p,c,m,a) 12 | 13 | #ifdef __cplusplus 14 | } // extern "C" 15 | #endif 16 | -------------------------------------------------------------------------------- /libraries/Ticker/src/Ticker.cpp: -------------------------------------------------------------------------------- 1 | #include "Ticker.h" 2 | #include "TInterrupts.h" 3 | 4 | static void timer_callback(void* ctx); 5 | 6 | Ticker::Ticker(timer_id_t id) 7 | :timer_id(id) 8 | { 9 | /* */ 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 | _repeat = repeat; 23 | attachTickerParam(timer_id, timer_callback, milliseconds * 1000, this); 24 | } 25 | 26 | void 27 | Ticker::_attach_us(uint32_t microseconds, bool repeat, callback_with_arg_t callback, size_t arg) 28 | { 29 | user_callback = callback; 30 | _arg = arg; 31 | _repeat = repeat; 32 | attachTickerParam(timer_id, timer_callback, microseconds, this); 33 | } 34 | 35 | void 36 | Ticker::detach() 37 | { 38 | detachTicker(timer_id); 39 | } 40 | 41 | static void timer_callback(void* ctx) 42 | { 43 | auto &driver = *reinterpret_cast(ctx); 44 | driver.user_callback((void *)driver._arg); 45 | if (!driver._repeat) 46 | driver.detach(); 47 | } 48 | -------------------------------------------------------------------------------- /libraries/USBAudio/library.properties: -------------------------------------------------------------------------------- 1 | name=USBAudio 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBAudio gd32v driver 6 | paragraph=USBAudio gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Examples/USBFS/USB_Device/Audio 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBAudio/src/audio_usbd_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_USBD_CONF_H 2 | #define AUDIO_USBD_CONF_H 3 | 4 | /* USB feature -- Self Powered */ 5 | //#define USBD_SELF_POWERED 6 | 7 | /* USB user string supported */ 8 | /* #define USB_SUPPORT_USER_STRING_DESC */ 9 | 10 | //#define USBD_DYNAMIC_DESCRIPTOR_CHANGE_ENABLED 11 | 12 | #define USBD_AUDIO_FREQ 16000 /* Audio frequency in Hz for GD32VF103 devices family when 25MHz HSE value 13 | is used. */ 14 | 15 | /* Maximum number of supported media (Flash) */ 16 | #define MAX_USED_MEMORY_MEDIA 1 17 | 18 | #define USB_STRING_COUNT 6 19 | 20 | /* Audio endpoint define */ 21 | #define AUDIO_TOTAL_IF_NUM 0x02 22 | #define AUDIO_OUT_EP EP1_OUT 23 | #define AUDIO_IN_EP EP2_IN 24 | 25 | #define USB_SERIAL_STRING_SIZE 0x06 26 | #define DEVICE_ID (0x40022100) 27 | #define DEFAULT_VOLUME 65 /* Default volume in % (Mute=0%, Max = 100%) in Logarithmic values. 28 | To get accurate volume variations, it is possible to use a logarithmic 29 | coversion table to convert from percentage to logarithmic law. 30 | In order to keep this example code simple, this conversion is not used.*/ 31 | #endif /* AUDIO_USBD_CONF_H */ 32 | -------------------------------------------------------------------------------- /libraries/USBCDC/examples/USB_UART_BRIDGE/cdc_acm_uart.h: -------------------------------------------------------------------------------- 1 | #ifndef CDC_ACM_UART_H 2 | #define CDC_ACM_UART_H 3 | 4 | #include "cdc_acm_core.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | // ==== Conditional compile ==== 11 | #ifdef LCD_SS_PIN 12 | #define USE_DISPLAY 1 13 | #endif 14 | #define USE_LEDS 1 15 | #define UART_USE_BREAK_TO_CHANGE 1 16 | #define ENABLE_CUSTOM_REQUESTS 1 17 | 18 | // ==== Constants ==== 19 | #define UART_RXBUFFER_SIZE 4096 20 | #define UART_DEFAULT_BDR 115200 21 | 22 | #define UART0_TXPIN GPIO_PIN_9 23 | #define UART0_RXPIN GPIO_PIN_10 24 | #define UART0_RTSPIN GPIO_PIN_13 25 | #define UART0_DTRPIN GPIO_PIN_14 26 | #define UART0_PORT GPIOA 27 | #define UART0_RTS_DTR_MODE GPIO_MODE_AF_OD 28 | 29 | #define UART2_TXPIN GPIO_PIN_10 30 | #define UART2_RXPIN GPIO_PIN_11 31 | #define UART2_RTSPIN GPIO_PIN_13 32 | #define UART2_DTRPIN GPIO_PIN_14 33 | #define UART2_PORT GPIOB 34 | #define UART2_RTS_DTR_MODE GPIO_MODE_AF_PP 35 | 36 | extern __IO uint32_t uart_receive_count; 37 | extern __IO uint32_t uart_send_count; 38 | extern __IO uint32_t uart_error_count; 39 | extern __IO uint32_t active_uart; 40 | extern __IO uint32_t uart_change_req; 41 | 42 | void lcd_showUartSettings(void); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /libraries/USBCDC/library.properties: -------------------------------------------------------------------------------- 1 | name=USBCDC 2 | version=1.0 3 | author=loboris 4 | maintainer=Longduino 5 | sentence=USBCDC gd32v driver 6 | paragraph=USBCDC gd32v driver 7 | category=Communication 8 | url=https://github.com/loboris/GD32VF_USB_UART_BRIDGE 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBCDC/src/usbcdc_pjt_include.h: -------------------------------------------------------------------------------- 1 | #ifndef _GD32V_PJT_INCLUDE_ 2 | #define _GD32V_PJT_INCLUDE_ 3 | 4 | #include "gd32vf103_libopt.h" 5 | #include 6 | 7 | #define PA_OUT(n,s) \ 8 | ({ if (s%2) gpio_bit_set(GPIOA, GPIO_PIN_##n); \ 9 | else gpio_bit_reset(GPIOA, GPIO_PIN_##n); }) 10 | #define PA_IN(n) gpio_input_bit_get(GPIOA, GPIO_PIN_##n) 11 | 12 | #define PB_OUT(n,s) \ 13 | ({ if (s%2) gpio_bit_set(GPIOB, GPIO_PIN_##n); \ 14 | else gpio_bit_reset(GPIOB, GPIO_PIN_##n); }) 15 | #define PB_IN(n) gpio_input_bit_get(GPIOB, GPIO_PIN_##n) 16 | 17 | #define PC_OUT(n,s) \ 18 | ({ if (s%2) gpio_bit_set(GPIOC, GPIO_PIN_##n); \ 19 | else gpio_bit_reset(GPIOC, GPIO_PIN_##n); }) 20 | #define PC_IN(n) gpio_input_bit_get(GPIOC, GPIO_PIN_##n) 21 | 22 | #define LEDR_TOG gpio_bit_write(GPIOC, GPIO_PIN_13, (bit_status)(1-gpio_input_bit_get(GPIOC, GPIO_PIN_13))) 23 | #define LEDR(s) PC_OUT(13, s) 24 | #define LEDG_TOG gpio_bit_write(GPIOA, GPIO_PIN_1, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_1))) 25 | #define LEDG(s) PA_OUT(1, s) 26 | #define LEDB_TOG gpio_bit_write(GPIOA, GPIO_PIN_2, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_2))) 27 | #define LEDB(s) PA_OUT(2, s) 28 | 29 | #endif /* _GD32V_PJT_INCLUDE_ */ 30 | -------------------------------------------------------------------------------- /libraries/USBDEV/examples/HID_Mouse/hid_mouse_it.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file hid_mouse_it.h 3 | \brief the header file of the ISR 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef HID_MOUSE_IT_H 36 | #define HID_MOUSE_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "usbd_core.h" 43 | 44 | typedef enum { 45 | JOY_NONE = 0, 46 | JOY_SEL, 47 | JOY_UP, 48 | JOY_DOWN, 49 | JOY_LEFT, 50 | JOY_RIGHT 51 | } joystate_enum; 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif /* HID_MOUSE_IT_H */ 58 | -------------------------------------------------------------------------------- /libraries/USBDEV/examples/HID_Mouse/hid_mouse_systick.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file systick.c 3 | \brief the systick configuration file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, this 17 | list of conditions and the following disclaimer. 18 | 2. Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 3. Neither the name of the copyright holder nor the names of its contributors 22 | may be used to endorse or promote products derived from this software without 23 | specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 34 | OF SUCH DAMAGE. 35 | */ 36 | 37 | #include "gd32vf103.h" 38 | #include "hid_mouse_systick.h" 39 | 40 | void systick_config(void) 41 | { 42 | eclic_global_interrupt_enable(); 43 | *(uint64_t*)(TIMER_CTRL_ADDR + TIMER_MTIMECMP) = TIMER_FREQ / 100; 44 | eclic_set_nlbits(ECLIC_GROUP_LEVEL2_PRIO2); 45 | eclic_irq_enable(CLIC_INT_TMR, 3, 3); 46 | *(uint64_t*)(TIMER_CTRL_ADDR + TIMER_MTIME) = 0; 47 | } 48 | -------------------------------------------------------------------------------- /libraries/USBDEV/examples/HID_Mouse/hid_mouse_systick.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file hid_mouse_systick.h 3 | \brief the header file of systick 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, this 17 | list of conditions and the following disclaimer. 18 | 2. Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 3. Neither the name of the copyright holder nor the names of its contributors 22 | may be used to endorse or promote products derived from this software without 23 | specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 34 | OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef HID_MOUSE_SYS_TICK_H 38 | #define HID_MOUSE_SYS_TICK_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | 46 | void systick_config(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* SYS_TICK_H */ 53 | -------------------------------------------------------------------------------- /libraries/USBDEV/examples/HID_Mouse/hid_mouse_usbd_conf.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file hid_mouse_usbd_conf.h 3 | \brief the header file of USB device-mode configuration 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef HID_MOUSE_USBD_CONF_H 36 | #define HID_MOUSE_USBD_CONF_H 37 | 38 | #include "usb_conf.h" 39 | 40 | #define USB_STRING_COUNT 4U 41 | 42 | /* endpoint count used by the HID device */ 43 | #define HID_IN_EP EP1_IN 44 | #define HID_OUT_EP EP1_OUT 45 | 46 | #define HID_IN_PACKET 8 47 | #define HID_OUT_PACKET 8 48 | 49 | #endif /* HID_MOUSE_USBD_CONF_H */ 50 | -------------------------------------------------------------------------------- /libraries/USBDEV/examples/HID_Mouse/standard_hid_core.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file standard_hid_core.h 3 | \brief definitions for HID core 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __STANDARD_HID_CORE_H 36 | #define __STANDARD_HID_CORE_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "usbd_enum.h" 43 | #include "usb_hid.h" 44 | #include "hid_mouse_usbd_conf.h" 45 | 46 | #define USB_HID_CONFIG_DESC_LEN 0x22U 47 | #define USB_HID_REPORT_DESC_LEN 0x4AU 48 | 49 | #define NO_CMD 0xFFU 50 | 51 | extern void* const usbd_hid_strings[USB_STRING_COUNT]; 52 | extern const usb_desc_dev hid_dev_desc; 53 | extern const usb_hid_desc_config_set hid_config_desc; 54 | extern usb_class_core usbd_hid_cb; 55 | 56 | /* function declarations */ 57 | 58 | /* send keyboard report */ 59 | uint8_t hid_report_send (usb_dev *pudev, uint8_t *report, uint16_t len); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* __STANDARD_HID_CORE_H */ 66 | -------------------------------------------------------------------------------- /libraries/USBDEV/library.properties: -------------------------------------------------------------------------------- 1 | name=USBDEV 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBDEV gd32v driver 6 | paragraph=USBDEV gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Firmware/GD32VF103_usbfs_driver 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBDEV/src/drv_usbd_int.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file drv_usbd_int.h 3 | \brief USB device mode interrupt header file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __DRV_USBD_INT_H 36 | #define __DRV_USBD_INT_H 37 | 38 | #include "drv_usb_core.h" 39 | #include "drv_usb_dev.h" 40 | 41 | /* USB device-mode interrupts global service routine handler */ 42 | void usbd_isr (usb_core_driver *udev); 43 | 44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED 45 | 46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev); 47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev); 48 | 49 | #endif 50 | 51 | #endif /* __DRV_USBD_INT_H */ 52 | 53 | -------------------------------------------------------------------------------- /libraries/USBDEV/src/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file usbd_conf.h 3 | \brief the header file of USB device-mode configuration 4 | 5 | \version 2019-6-5, V1.0.0, demo for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USBD_CONF_H 36 | #define __USBD_CONF_H 37 | 38 | #include "usb_conf.h" 39 | 40 | #define USBD_CFG_MAX_NUM 1 41 | #define USBD_ITF_MAX_NUM 1 42 | 43 | #define USB_STR_DESC_MAX_SIZE 64 44 | 45 | //#define USB_STRING_COUNT 4U 46 | 47 | /* endpoint count used by the CDC ACM device */ 48 | #define CDC_ACM_CMD_EP EP2_IN 49 | #define CDC_ACM_DATA_IN_EP EP1_IN 50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT 51 | 52 | #define CDC_ACM_CMD_PACKET_SIZE 64 53 | #define CDC_ACM_DATA_PACKET_SIZE 64 54 | 55 | #endif /* __USBD_CONF_H */ 56 | -------------------------------------------------------------------------------- /libraries/USBDEV/src/usbd_transc.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file usbd_transc.h 3 | \brief USB transaction core functions prototype 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USBD_TRANSC_H 36 | #define __USBD_TRANSC_H 37 | 38 | #include "usbd_core.h" 39 | 40 | /* function declarations */ 41 | 42 | /* USB send data in the control transaction */ 43 | usbd_status usbd_ctl_send (usb_core_driver *udev); 44 | 45 | /* USB receive data in control transaction */ 46 | usbd_status usbd_ctl_recev (usb_core_driver *udev); 47 | 48 | /* USB send control transaction status */ 49 | usbd_status usbd_ctl_status_send (usb_core_driver *udev); 50 | 51 | /* USB control receive status */ 52 | usbd_status usbd_ctl_status_recev (usb_core_driver *udev); 53 | 54 | /* USB setup stage processing */ 55 | uint8_t usbd_setup_transc (usb_core_driver *udev); 56 | 57 | /* data out stage processing */ 58 | uint8_t usbd_out_transc (usb_core_driver *udev, uint8_t ep_num)__attribute__((optimize("O0"))); 59 | 60 | /* data in stage processing */ 61 | uint8_t usbd_in_transc (usb_core_driver *udev, uint8_t ep_num)__attribute__((optimize("O0"))); 62 | 63 | #endif /* __USBD_TRANSC_H */ 64 | 65 | -------------------------------------------------------------------------------- /libraries/USBDEVHW/library.properties: -------------------------------------------------------------------------------- 1 | name=USBDEVHW 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBDEVHW gd32v driver 6 | paragraph=USBDEVHW gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Firmware/GD32VF103_usbfs_driver 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBDEVHW/src/gd32vf103_usbd_hw.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file drv_usb_hw.h 3 | \brief usb hardware configuration header file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __DRV_USB_HW_H 36 | #define __DRV_USB_HW_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "usb_conf.h" 43 | 44 | /* configure USB clock */ 45 | void usb_rcu_config (void); 46 | 47 | /* configure USB interrupt */ 48 | void usb_intr_config (void); 49 | 50 | /* initializes delay unit using Timer2 */ 51 | void usb_timer_init (void); 52 | 53 | /* delay in micro seconds */ 54 | void usb_udelay (const uint32_t usec); 55 | 56 | /* delay in milli seconds */ 57 | void usb_mdelay (const uint32_t msec); 58 | 59 | #ifdef USE_HOST_MODE 60 | /* configure USB VBus */ 61 | void usb_vbus_config (void); 62 | /* drive usb VBus */ 63 | void usb_vbus_drive (uint8_t State); 64 | #endif /* USE_HOST_MODE */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __DRV_USB_HW_H */ 71 | -------------------------------------------------------------------------------- /libraries/USBDEVHW/src/gd32vf103_usbd_it.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gd32vf103_usbd_it.h 3 | \brief the header file of the ISR 4 | 5 | \version 2019-6-5, V1.0.0, demo for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GD32VF103_IT_H 36 | #define GD32VF103_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "usbd_core.h" 43 | 44 | /* function declarations */ 45 | /* this function handles USB wakeup interrupt handler */ 46 | void USBFS_WKUP_IRQHandler(void); 47 | /* this function handles USBFS IRQ Handler */ 48 | void USBFS_IRQHandler(void); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* GD32VF103_IT_H */ 55 | -------------------------------------------------------------------------------- /libraries/USBFS/library.properties: -------------------------------------------------------------------------------- 1 | name=USBFS 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBFS gd32v driver 6 | paragraph=USBFS gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Firmware/GD32VF103_usbfs_driver 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBFS/src/drv_usb_hw.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file drv_usb_hw.h 3 | \brief usb hardware configuration header file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __DRV_USB_HW_H 36 | #define __DRV_USB_HW_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "usb_conf.h" 43 | 44 | /* configure USB clock */ 45 | void usb_rcu_config (void); 46 | 47 | /* configure USB interrupt */ 48 | void usb_intr_config (void); 49 | 50 | /* initializes delay unit using Timer2 */ 51 | void usb_timer_init (void); 52 | 53 | /* delay in micro seconds */ 54 | void usb_udelay (const uint32_t usec); 55 | 56 | /* delay in milli seconds */ 57 | void usb_mdelay (const uint32_t msec); 58 | 59 | #ifdef USE_HOST_MODE 60 | /* configure USB VBus */ 61 | void usb_vbus_config (void); 62 | /* drive usb VBus */ 63 | void usb_vbus_drive (uint8_t State); 64 | #endif /* USE_HOST_MODE */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __DRV_USB_HW_H */ 71 | -------------------------------------------------------------------------------- /libraries/USBHID/library.properties: -------------------------------------------------------------------------------- 1 | name=USBHID 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBHID gd32v driver 6 | paragraph=USBHID gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Firmware/GD32VF103_usbfs_driver 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBHID/src/usbh_hid_keybd.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file usbh_hid_keybd.h 3 | \brief this file contains all the prototypes for the usbh_hid_keybd.c 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef USBH_HID_KEYBD_H 36 | #define USBH_HID_KEYBD_H 37 | 38 | #include "usb_conf.h" 39 | #include "usbh_hid_core.h" 40 | 41 | //#define AZERTY_KEYBOARD 42 | #define QWERTY_KEYBOARD 43 | 44 | #define KBD_LEFT_CTRL 0x01U 45 | #define KBD_LEFT_SHIFT 0x02U 46 | #define KBD_LEFT_ALT 0x04U 47 | #define KBD_LEFT_GUI 0x08U 48 | #define KBD_RIGHT_CTRL 0x10U 49 | #define KBD_RIGHT_SHIFT 0x20U 50 | #define KBD_RIGHT_ALT 0x40U 51 | #define KBD_RIGHT_GUI 0x80U 52 | 53 | #define KBR_MAX_NBR_PRESSED 6U 54 | 55 | extern hid_proc HID_KEYBRD_cb; 56 | 57 | /* function declarations */ 58 | /* init keyboard window */ 59 | void usr_keybrd_init (void); 60 | /* process keyboard data */ 61 | void usr_keybrd_process_data (uint8_t pbuf); 62 | 63 | #endif /* USBH_HID_KEYBD_H */ 64 | -------------------------------------------------------------------------------- /libraries/USBHOST/examples/HID_Host/HID_Host.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | \file main.c 3 | \brief this file realizes the HID host 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "drv_usb_hw.h" 36 | #include "drv_usb_core.h" 37 | #include "usbh_usr.h" 38 | #include "usbh_hid_core.h" 39 | #include 40 | #include 41 | #include 42 | 43 | 44 | usb_core_driver usbh_drv_core; 45 | 46 | usbh_host usb_host = { 47 | .class_cb = &usbh_hid_cb, 48 | .usr_cb = &user_callback_funs 49 | }; 50 | 51 | /** 52 | * @brief Main routine for HID mouse / keyboard class application 53 | * @param None 54 | * @retval None 55 | */ 56 | void setup() 57 | { 58 | eclic_global_interrupt_enable(); 59 | 60 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2); 61 | 62 | usb_rcu_config(); 63 | 64 | usb_timer_init(); 65 | 66 | /* configure GPIO pin used for switching VBUS power and charge pump I/O */ 67 | usb_vbus_config(); 68 | 69 | usbh_init (&usbh_drv_core, USB_CORE_ENUM_FS, &usb_host); 70 | 71 | /* enable interrupts */ 72 | usb_intr_config(); 73 | } 74 | 75 | void loop() { 76 | /* Host state handler */ 77 | usbh_core_task (&usbh_drv_core, &usb_host); 78 | } 79 | -------------------------------------------------------------------------------- /libraries/USBHOST/library.properties: -------------------------------------------------------------------------------- 1 | name=USBHOST 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBHOST gd32v driver 6 | paragraph=USBHOST gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Firmware/GD32VF103_usbfs_driver 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBHOST/src/drv_usbh_int.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file drv_usbh_int.h.h 3 | \brief USB host mode interrupt management header file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __DRV_USBH_INT_H 36 | #define __DRV_USBH_INT_H 37 | 38 | #include "drv_usb_host.h" 39 | 40 | typedef struct _usbh_int_cb 41 | { 42 | uint8_t (*SOF) (usb_core_driver *pudev); 43 | } usbh_int_cb; 44 | 45 | extern usbh_int_cb *usbh_int_fop; 46 | 47 | uint32_t usbh_isr (usb_core_driver *pudev); 48 | 49 | #endif /* __DRV_USBH_INT_H */ 50 | -------------------------------------------------------------------------------- /libraries/USBHOST/src/gd32vf103_usbh_it.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gd32vf103_usbh_it.c 3 | \brief main interrupt service routines 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "drv_usbh_int.h" 36 | #include "drv_usb_hw.h" 37 | #include "gd32vf103_usbh_it.h" 38 | 39 | extern usb_core_driver usbh_drv_core; 40 | 41 | extern void usb_timer_irq (void); 42 | 43 | /*! 44 | \brief this function handles USBD interrupt 45 | \param[in] none 46 | \param[out] none 47 | \retval none 48 | */ 49 | void USBFS_IRQHandler(void) 50 | { 51 | usbh_isr (&usbh_drv_core); 52 | } 53 | 54 | /*! 55 | \brief this function handles timer2 updata interrupt request. 56 | \param[in] none 57 | \param[out] none 58 | \retval none 59 | */ 60 | void TIMER2_IRQHandler(void) 61 | { 62 | usb_timer_irq(); 63 | } 64 | -------------------------------------------------------------------------------- /libraries/USBHOST/src/gd32vf103_usbh_it.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gd32vf103_usbh_it.h 3 | \brief the header file of the ISR 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GD32VF103_IT_H 36 | #define GD32VF103_IT_H 37 | 38 | #include "gd32vf103.h" 39 | 40 | /* function declarations */ 41 | /* this function handles USB wakeup interrupt handler */ 42 | void USBFS_WKUP_IRQHandler(void); 43 | /* this function handles USBFS IRQ Handler */ 44 | void USBFS_IRQHandler(void); 45 | 46 | #endif /* GD32VF103_IT_H */ 47 | -------------------------------------------------------------------------------- /libraries/USBHOST/src/usbh_conf.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file usbh_conf.h 3 | \brief general low level driver configuration 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USBH_CONF_H 36 | #define __USBH_CONF_H 37 | 38 | #define USBH_MAX_EP_NUM 2 39 | #define USBH_MAX_INTERFACES_NUM 2 40 | #define USBH_MSC_MPS_SIZE 0x200 41 | 42 | #endif /* __USBH_CONF_H */ 43 | -------------------------------------------------------------------------------- /libraries/USBHOST/src/usbh_transc.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file usbh_transc.h 3 | \brief USB host mode transactions header file 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USBH_TRANSC_H 36 | #define __USBH_TRANSC_H 37 | 38 | #include "usb_conf.h" 39 | #include "usbh_core.h" 40 | 41 | /* send the setup packet to the USB device */ 42 | usbh_status usbh_ctlsetup_send (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num); 43 | 44 | /* send a data packet to the USB device */ 45 | usbh_status usbh_data_send (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num, uint16_t len); 46 | 47 | /* receive a data packet from the USB device */ 48 | usbh_status usbh_data_recev (usb_core_driver *pudev, uint8_t *buf, uint8_t pp_num, uint16_t len); 49 | 50 | /* USB control transfer handler */ 51 | usbh_status usbh_ctl_handler (usb_core_driver *pudev, usbh_host *puhost); 52 | 53 | #endif /* __USBH_TRANSC_H */ 54 | 55 | -------------------------------------------------------------------------------- /libraries/USBMSC/library.properties: -------------------------------------------------------------------------------- 1 | name=USBMSC 2 | version=1.0 3 | author=GigaDevice 4 | maintainer=Longduino 5 | sentence=USBMSC gd32v driver 6 | paragraph=USBMSC gd32v driver 7 | category=Communication 8 | url=https://github.com/riscv-mcu/GD32VF103_Firmware_Library/tree/master/Firmware/GD32VF103_usbfs_driver 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /libraries/USBMSC/src/msc_bbb.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file msc_bbb.h 3 | \brief definitions for the USB MSC BBB(bulk/bulk/bulk) protocol 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __MSC_BBB_H 36 | #define __MSC_BBB_H 37 | 38 | #include "usb_ch9_std.h" 39 | 40 | #define BBB_CBW_SIGNATURE 0x43425355U 41 | #define BBB_CSW_SIGNATURE 0x53425355U 42 | #define BBB_CBW_LENGTH 31U 43 | #define BBB_CSW_LENGTH 13U 44 | 45 | typedef struct { 46 | uint32_t dCBWSignature; 47 | uint32_t dCBWTag; 48 | uint32_t dCBWDataTransferLength; 49 | uint8_t bmCBWFlags; 50 | uint8_t bCBWLUN; 51 | uint8_t bCBWCBLength; 52 | uint8_t CBWCB[16]; 53 | }msc_bbb_cbw; 54 | 55 | typedef struct { 56 | uint32_t dCSWSignature; 57 | uint32_t dCSWTag; 58 | uint32_t dCSWDataResidue; 59 | uint8_t bCSWStatus; 60 | }msc_bbb_csw; 61 | 62 | /* CSW command status */ 63 | enum msc_csw_status { 64 | CSW_CMD_PASSED = 0, 65 | CSW_CMD_FAILED, 66 | CSW_PHASE_ERROR 67 | }; 68 | 69 | #endif /* __MSC_BBB_H */ 70 | -------------------------------------------------------------------------------- /libraries/USBMSC/src/usbh_msc_core.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file usbh_msc_core.h 3 | \brief header file for the usbh_msc_core.c 4 | 5 | \version 2019-6-5, V1.0.0, firmware for GD32VF103 6 | */ 7 | 8 | /* 9 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USBH_MSC_CORE_H 36 | #define __USBH_MSC_CORE_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "usb_msc.h" 43 | #include "usbh_msc_scsi.h" 44 | #include "usbh_msc_bbb.h" 45 | 46 | /* structure for msc process */ 47 | typedef struct { 48 | uint8_t hc_num_in; 49 | uint8_t hc_num_out; 50 | uint8_t msc_bulk_epin; 51 | uint8_t msc_bulk_epout; 52 | uint16_t msc_bulk_epinsize; 53 | uint16_t msc_bulk_epoutsize; 54 | uint8_t buf[USBH_MSC_MPS_SIZE]; 55 | uint8_t max_lun; 56 | } usbh_msc_machine; 57 | 58 | extern usbh_class_cb usbh_msc_cb; 59 | extern usbh_msc_machine msc_machine; 60 | extern uint8_t msc_error_count; 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __USBH_MSC_CORE_H */ 67 | -------------------------------------------------------------------------------- /libraries/Wire/examples/i2c_eeprom_rxtx/i2c_eeprom_rxtx.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | /* I2C Test read/write AT24C02 */ 5 | 6 | void i2c_eeprom_read_page(int deviceaddress, unsigned int eeaddress, int8_t len) { 7 | uint8_t rdata = 0xFF; 8 | uint8_t eeoff = (eeaddress*len); 9 | 10 | eeaddress = eeoff; 11 | 12 | Wire.beginTransmission(deviceaddress); 13 | //Wire.write((int)(eeaddress >> 8)); // MSB 14 | Wire.write((int)(eeaddress & 0xFF)); // LSB 15 | Wire.endTransmission(); 16 | for (int i = 0; i < len; i++) { 17 | Wire.requestFrom(deviceaddress,1); 18 | if (Wire.available()) { 19 | rdata = Wire.read(); 20 | Serial.printf("%02x ",rdata); 21 | } 22 | } 23 | 24 | Serial.println (); 25 | } 26 | 27 | void i2c_eeprom_write_page(int deviceaddress, unsigned int eeaddress, int8_t len) { 28 | uint8_t rdata = 0; 29 | uint8_t eeoff = (eeaddress*len); 30 | 31 | eeaddress = eeoff; 32 | 33 | for (int i = 0; i < len; i++) { 34 | rdata = eeoff + i; 35 | //rdata = 255-rdata; 36 | Serial.printf("%02x ",rdata); 37 | 38 | Wire.beginTransmission(deviceaddress); 39 | //Wire.write((int)(eeaddress >> 8)); // MSB 40 | Wire.write((int)(eeaddress & 0xFF)); // LSB 41 | Wire.write(rdata); 42 | Wire.endTransmission(); 43 | 44 | eeaddress+=1; 45 | } 46 | 47 | Serial.println (); 48 | } 49 | 50 | void setup() { 51 | Serial.begin (115200); 52 | 53 | // wait for serial port to connect 54 | while (!Serial) 55 | { 56 | } 57 | 58 | Serial.println (); 59 | Wire.begin(); 60 | 61 | Serial.println ("I2C Test writing ..."); 62 | for (int p = 0; p < 16; p++) { 63 | i2c_eeprom_write_page(0x50, p, 16); 64 | } 65 | 66 | Serial.println ("I2C Test reading ..."); 67 | for (int p = 0; p < 16; p++) { 68 | i2c_eeprom_read_page(0x50, p, 16); 69 | } 70 | 71 | Serial.println ("Done."); 72 | 73 | } // end of setup 74 | 75 | void loop() {} 76 | -------------------------------------------------------------------------------- /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=Longduino 4 | maintainer= 5 | sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For gd32v boards. 6 | paragraph= 7 | category=Signal Input/Output 8 | url=http://arduino.cc/en/Reference/Wire 9 | architectures=gd32v 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "framework-arduino-gd32v", 3 | "description": "Arduino Wiring-based Framework (GD32V Core)", 4 | "version": "0.2.3", 5 | "url": "https://github.com/sipeed/Longduino" 6 | } 7 | -------------------------------------------------------------------------------- /programmers.txt: -------------------------------------------------------------------------------- 1 | gdlink.name=GD-Link OpenOCD 2 | gdlink.communication=usb 3 | gdlink.program.params.verbose=-v 4 | gdlink.program.params.quiet=-q 5 | rvdebugger.program.params.config=gd-link.cfg 6 | gdlink.program.tool=openocd 7 | 8 | jlink.name=JLink OpenOCD 9 | jlink.communication=usb 10 | jlink.program.params.verbose=-v 11 | jlink.program.params.quiet=-q 12 | rvdebugger.program.params.config=jlink.cfg 13 | jlink.program.tool=openocd 14 | 15 | rvdebugger.name=Sipeed RV Debugger 16 | rvdebugger.communication=usb 17 | rvdebugger.program.params.verbose=-v 18 | rvdebugger.program.params.quiet=-q 19 | rvdebugger.program.params.config=ftdi/sipeed-rv-debugger.cfg 20 | rvdebugger.program.tool=openocd 21 | 22 | serial.name=Serial GD32V 23 | serial.communication=usb 24 | serial.program.params.verbose=-v 25 | serial.program.params.quiet=-q 26 | serial.program.tool=serial 27 | 28 | dfu.name=DFU GD32V 29 | dfu.communication=usb 30 | dfu.program.params.verbose=-v 31 | dfu.program.params.quiet=-q 32 | dfu.program.tool=dfu 33 | 34 | dfuflash.name=DFU with suffix GD32V 35 | dfuflash.communication=usb 36 | dfuflash.program.params.verbose=-v 37 | dfuflash.program.params.quiet=-q 38 | dfuflash.program.tool=dfuflash 39 | --------------------------------------------------------------------------------