├── .github └── workflows │ └── main.yml ├── LICENSE ├── README.md ├── arduino-stepper ├── .gitignore ├── .vscode │ └── extensions.json ├── README.md ├── include │ ├── README │ ├── Stepper.h │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ ├── lcd │ │ ├── bmp.h │ │ ├── lcd.h │ │ └── oledfont.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── Stepper.cpp │ ├── lcd │ │ └── lcd.c │ ├── main.cpp │ └── systick.c └── test │ └── README ├── bustester ├── .gitignore ├── .vscode │ └── extensions.json ├── include │ ├── README │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ └── main.c └── test │ └── README ├── intrbus ├── .gitignore ├── .vscode │ └── extensions.json ├── include │ ├── README │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── main.c │ └── systick.c └── test │ └── README ├── max6675 ├── .gitignore ├── .travis.yml ├── .vscode │ ├── extensions.json │ └── settings.json ├── NOTES.md ├── README.md ├── include │ ├── README │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ ├── lcd │ │ ├── bmp.h │ │ ├── lcd.h │ │ └── oledfont.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── lcd │ │ └── lcd.c │ ├── main.c │ └── systick.c └── test │ └── README ├── micros ├── .gitignore ├── README.md ├── include │ ├── README │ ├── lcd │ │ ├── bmp.h │ │ ├── lcd.h │ │ └── oledfont.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── Micros.cpp │ ├── lcd │ │ └── lcd.c │ └── systick.c └── test │ └── README ├── partimer ├── .gitignore ├── .vscode │ └── extensions.json ├── README.md ├── include │ ├── README │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── main.c │ └── systick.c └── test │ └── README ├── requirements.txt ├── rfid-spi ├── .gitignore ├── .vscode │ └── extensions.json ├── include │ ├── MFRC522.h │ ├── NoSerial.h │ ├── README │ ├── SPI.h │ ├── deprecated.h │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ ├── lcd │ │ ├── bmp.h │ │ ├── lcd.h │ │ └── oledfont.h │ ├── lcdlog.h │ ├── require_cpp11.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── MFRC522.cpp │ ├── NoSerial.cpp │ ├── lcd │ │ └── lcd.c │ ├── lcdlog.cpp │ ├── main.cpp │ └── systick.c └── test │ └── README ├── serial-printf ├── .gitignore ├── .vscode │ ├── extensions.json │ └── settings.json ├── include │ └── README ├── lib │ └── README ├── platformio.ini ├── src │ ├── gd32vf103_libopt.h │ └── main.c └── test │ └── README ├── spi-dma-test ├── .gitignore ├── .vscode │ ├── c_cpp_properties.json │ ├── extensions.json │ ├── launch.json │ └── settings.json ├── include │ ├── README │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── main.c │ └── systick.c └── test │ └── README ├── spi-test ├── .gitignore ├── .vscode │ ├── c_cpp_properties.json │ ├── extensions.json │ ├── launch.json │ └── settings.json ├── include │ ├── README │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── main.c │ └── systick.c └── test │ └── README ├── stepper ├── .gitignore ├── README.md ├── include │ ├── README │ ├── gd32v_pjt_include.h │ ├── gd32vf103_libopt.h │ └── systick.h ├── lib │ └── README ├── platformio.ini ├── src │ ├── main.c │ └── systick.c └── test │ └── README └── timebase ├── .gitignore ├── .vscode └── extensions.json ├── include ├── README ├── gd32v_pjt_include.h ├── gd32vf103_libopt.h └── systick.h ├── lib └── README ├── platformio.ini ├── src └── main.c └── test └── README /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [ workflow_dispatch, push ] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v1 11 | 12 | - name: Cache PlatformIO 13 | id: platformio-cache-pip-id 14 | uses: actions/cache@v1 15 | with: 16 | path: ~/.cache/pip 17 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} 18 | restore-keys: | 19 | ${{ runner.os }}-pip- 20 | 21 | - name: Cache PlatformIO Packages 22 | id: platformio-cache-id 23 | uses: actions/cache@v1 24 | with: 25 | path: ~/.platformio 26 | key: ${{ runner.os }}-platformio-packages-${{ hashFiles('**/platformio.ini') }} 27 | 28 | - name: Install PlatformIO 29 | if: steps.platformio-cache-pip-id.outputs.cache-hit != 'true' || 30 | steps.platformio-cache-id.outputs.cache-hit != 'true' 31 | run: | 32 | wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -O get-platformio.py 33 | python3 get-platformio.py 34 | $HOME/.platformio/penv/bin/platformio --version 35 | 36 | # Workaround because PlatformIO fails to install the necessary dfu-util package 37 | # See https://community.platformio.org/t/dfu-suffix-not-found-for-longan-nano-build/16710/4?u=smuehlst 38 | - name: Install dfu-util 39 | run: | 40 | wget -O dfu-util.tgz https://bintray.com/platformio/tool-packages/download_file?file_path=2e415f3-tool-dfuutil-linux_x86_64-1.9.200310.tar.gz 41 | mkdir -p $HOME/.platformio/packages/tool-dfuutil 42 | tar -C $HOME/.platformio/packages/tool-dfuutil -x -f dfu-util.tgz 43 | 44 | - name: Build Stepper 45 | run: | 46 | $HOME/.platformio/penv/bin/platformio run -d stepper -v 47 | 48 | - name: Build MAX6675 49 | run: | 50 | $HOME/.platformio/penv/bin/platformio run -d max6675 -v 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This repository contains copies of source files from other Open Source 2 | projects where the respective licenses were retained. 3 | 4 | For all other files the following license is applied: 5 | 6 | This is free and unencumbered software released into the public domain. 7 | 8 | Anyone is free to copy, modify, publish, use, compile, sell, or 9 | distribute this software, either in source code form or as a compiled 10 | binary, for any purpose, commercial or non-commercial, and by any 11 | means. 12 | 13 | In jurisdictions that recognize copyright laws, the author or authors 14 | of this software dedicate any and all copyright interest in the 15 | software to the public domain. We make this dedication for the benefit 16 | of the public at large and to the detriment of our heirs and 17 | successors. We intend this dedication to be an overt act of 18 | relinquishment in perpetuity of all present and future rights to this 19 | software under copyright law. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | OTHER DEALINGS IN THE SOFTWARE. 28 | 29 | For more information, please refer to 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # longan-nano-experiments 2 | 3 | Repository for experiments with the [Sipeed Longan Nano](http://longan.sipeed.com/en/) 4 | board. 5 | -------------------------------------------------------------------------------- /arduino-stepper/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /arduino-stepper/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /arduino-stepper/README.md: -------------------------------------------------------------------------------- 1 | Arduino Stepper example 2 | ======================= 3 | 4 | Attempt to use the Arduino Stepper library with a step motor. 5 | It uses a modified version of the Stepper library which works 6 | now with the Longan Nano and a 28BYJ-48 step motor. 7 | 8 | -------------------------------------------------------------------------------- /arduino-stepper/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /arduino-stepper/include/Stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Stepper.h - Stepper library for Wiring/Arduino - Version 1.1.0 3 | * 4 | * Original library (0.1) by Tom Igoe. 5 | * Two-wire modifications (0.2) by Sebastian Gassner 6 | * Combination version (0.3) by Tom Igoe and David Mellis 7 | * Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley 8 | * High-speed stepping mod by Eugene Kozlenko 9 | * Timer rollover fix by Eugene Kozlenko 10 | * Five phase five wire (1.1.0) by Ryan Orendorff 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | * 26 | * 27 | * Drives a unipolar, bipolar, or five phase stepper motor. 28 | * 29 | * When wiring multiple stepper motors to a microcontroller, you quickly run 30 | * out of output pins, with each motor requiring 4 connections. 31 | * 32 | * By making use of the fact that at any time two of the four motor coils are 33 | * the inverse of the other two, the number of control connections can be 34 | * reduced from 4 to 2 for the unipolar and bipolar motors. 35 | * 36 | * A slightly modified circuit around a Darlington transistor array or an 37 | * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals 38 | * received, and delivers the 4 (2 plus 2 inverted ones) output signals 39 | * required for driving a stepper motor. Similarly the Arduino motor shields 40 | * 2 direction pins may be used. 41 | * 42 | * The sequence of control signals for 5 phase, 5 control wires is as follows: 43 | * 44 | * Step C0 C1 C2 C3 C4 45 | * 1 0 1 1 0 1 46 | * 2 0 1 0 0 1 47 | * 3 0 1 0 1 1 48 | * 4 0 1 0 1 0 49 | * 5 1 1 0 1 0 50 | * 6 1 0 0 1 0 51 | * 7 1 0 1 1 0 52 | * 8 1 0 1 0 0 53 | * 9 1 0 1 0 1 54 | * 10 0 0 1 0 1 55 | * 56 | * The sequence of control signals for 4 control wires is as follows: 57 | * 58 | * Step C0 C1 C2 C3 59 | * 1 1 0 1 0 60 | * 2 0 1 1 0 61 | * 3 0 1 0 1 62 | * 4 1 0 0 1 63 | * 64 | * The sequence of controls signals for 2 control wires is as follows 65 | * (columns C1 and C2 from above): 66 | * 67 | * Step C0 C1 68 | * 1 0 1 69 | * 2 1 1 70 | * 3 1 0 71 | * 4 0 0 72 | * 73 | * The circuits can be found at 74 | * 75 | * http://www.arduino.cc/en/Tutorial/Stepper 76 | */ 77 | 78 | // ensure this library description is only included once 79 | #ifndef Stepper_h 80 | #define Stepper_h 81 | 82 | #include 83 | 84 | // library interface description 85 | class Stepper { 86 | public: 87 | // constructors: 88 | Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2); 89 | Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, 90 | int motor_pin_3, int motor_pin_4); 91 | Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, 92 | int motor_pin_3, int motor_pin_4, 93 | int motor_pin_5); 94 | 95 | // speed setter method: 96 | void setSpeed(long whatSpeed); 97 | 98 | // mover method: 99 | void step(int number_of_steps); 100 | 101 | int version(void); 102 | 103 | private: 104 | void stepMotor(int this_step); 105 | 106 | uint64_t step_delay; // delay between steps, in ms, based on speed 107 | int number_of_steps; // total number of steps this motor can take 108 | int pin_count; // how many pins are in use. 109 | int step_number; // which step the motor is on 110 | 111 | // motor pin numbers: 112 | int motor_pin_1; 113 | int motor_pin_2; 114 | int motor_pin_3; 115 | int motor_pin_4; 116 | int motor_pin_5; // Only 5 phase motor 117 | 118 | uint64_t last_step_time; // time stamp in us of when the last step was taken 119 | }; 120 | 121 | #endif 122 | 123 | -------------------------------------------------------------------------------- /arduino-stepper/include/gd32v_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 | -------------------------------------------------------------------------------- /arduino-stepper/include/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 | -------------------------------------------------------------------------------- /arduino-stepper/include/lcd/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | 4 | #include "systick.h" 5 | #include "stdlib.h" 6 | #include "gd32vf103_gpio.h" 7 | 8 | #define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏 9 | #define HAS_BLK_CNTL 0 10 | 11 | #if USE_HORIZONTAL==0||USE_HORIZONTAL==1 12 | #define LCD_W 80 13 | #define LCD_H 160 14 | #else 15 | #define LCD_W 160 16 | #define LCD_H 80 17 | #endif 18 | 19 | typedef unsigned char u8; 20 | typedef unsigned int u16; 21 | typedef unsigned long u32; 22 | 23 | 24 | // #define LED_ON gpio_bit_reset(GPIOC,GPIO_PIN_13) 25 | // #define LED_OFF gpio_bit_set(GPIOC,GPIO_PIN_13) 26 | 27 | #define LED_ON 28 | #define LED_OFF 29 | 30 | #define SPI0_CFG 1 //hardware spi 31 | // #define SPI0_CFG 2 //hardware spi dma 32 | // #define SPI0_CFG 3 //software spi 33 | 34 | #define FRAME_SIZE 25600 35 | 36 | //-----------------OLED端口定义---------------- 37 | #if SPI0_CFG == 1 38 | #define OLED_SCLK_Clr() 39 | #define OLED_SCLK_Set() 40 | 41 | #define OLED_SDIN_Clr() 42 | #define OLED_SDIN_Set() 43 | 44 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 45 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 46 | #elif SPI0_CFG == 2 47 | #define OLED_SCLK_Clr() 48 | #define OLED_SCLK_Set() 49 | 50 | #define OLED_SDIN_Clr() 51 | #define OLED_SDIN_Set() 52 | 53 | #define OLED_CS_Clr() 54 | #define OLED_CS_Set() 55 | #else /* SPI0_CFG */ 56 | #define OLED_SCLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5) //CLK PA5 57 | #define OLED_SCLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 58 | 59 | #define OLED_SDIN_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_7) //DIN PA7 60 | #define OLED_SDIN_Set() gpio_bit_set(GPIOA,GPIO_PIN_7) 61 | 62 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 63 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 64 | #endif /* SPI0_CFG */ 65 | 66 | #define OLED_RST_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_1) //RES PB1 67 | #define OLED_RST_Set() gpio_bit_set(GPIOB,GPIO_PIN_1) 68 | 69 | #define OLED_DC_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_0) //DC PB0 70 | #define OLED_DC_Set() gpio_bit_set(GPIOB,GPIO_PIN_0) 71 | 72 | 73 | #if HAS_BLK_CNTL 74 | #define OLED_BLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5)//BLK 75 | #define OLED_BLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 76 | #else 77 | #define OLED_BLK_Clr() 78 | #define OLED_BLK_Set() 79 | #endif 80 | 81 | #define OLED_CMD 0 //写命令 82 | #define OLED_DATA 1 //写数据 83 | 84 | extern u16 BACK_COLOR; //背景色 85 | extern unsigned char image[12800]; 86 | 87 | void LCD_Writ_Bus(u8 dat); 88 | void LCD_WR_DATA8(u8 dat); 89 | void LCD_WR_DATA(u16 dat); 90 | void LCD_WR_REG(u8 dat); 91 | void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2); 92 | void Lcd_Init(void); 93 | void LCD_Clear(u16 Color); 94 | void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color); 95 | void LCD_DrawPoint(u16 x,u16 y,u16 color); 96 | void LCD_DrawPoint_big(u16 x,u16 y,u16 color); 97 | void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color); 98 | void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color); 99 | void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); 100 | void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color); 101 | void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color); 102 | void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color); 103 | u32 mypow(u8 m,u8 n); 104 | void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color); 105 | void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color); 106 | void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2); 107 | void LCD_ShowLogo(void); 108 | 109 | 110 | //画笔颜色 111 | #define WHITE 0xFFFF 112 | #define BLACK 0x0000 113 | #define BLUE 0x001F 114 | #define BRED 0XF81F 115 | #define GRED 0XFFE0 116 | #define GBLUE 0X07FF 117 | #define RED 0xF800 118 | #define MAGENTA 0xF81F 119 | #define GREEN 0x07E0 120 | #define CYAN 0x7FFF 121 | #define YELLOW 0xFFE0 122 | #define BROWN 0XBC40 //棕色 123 | #define BRRED 0XFC07 //棕红色 124 | #define GRAY 0X8430 //灰色 125 | //GUI颜色 126 | 127 | #define DARKBLUE 0X01CF //深蓝色 128 | #define LIGHTBLUE 0X7D7C //浅蓝色 129 | #define GRAYBLUE 0X5458 //灰蓝色 130 | //以上三色为PANEL的颜色 131 | 132 | #define LIGHTGREEN 0X841F //浅绿色 133 | #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色 134 | 135 | #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色) 136 | #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色) 137 | 138 | 139 | 140 | #endif 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /arduino-stepper/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /arduino-stepper/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /arduino-stepper/platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = arduino 15 | upload_protocol = dfu 16 | platform_packages = framework-arduino-gd32v @ https://github.com/sipeed/Longduino.git 17 | 18 | ; lib_deps = 19 | ; Stepper -------------------------------------------------------------------------------- /arduino-stepper/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern "C" { 6 | #include "lcd/lcd.h" 7 | } 8 | 9 | namespace { 10 | 11 | // set the number of steps of the motor 12 | constexpr int STEPS = 4096; 13 | 14 | constexpr int IN1 = PA0; 15 | constexpr int IN2 = PA1; 16 | constexpr int IN3 = PA2; 17 | constexpr int IN4 = PA3; 18 | 19 | Stepper stepmotor(STEPS, IN1, IN2, IN3, IN4); 20 | 21 | // char constexpr commands[] = "fbvr+-ce"; 22 | char constexpr commands[] = "frfr"; 23 | 24 | int idx = 0; 25 | 26 | char next_command(void) { 27 | char const ch = commands[idx]; 28 | idx = (idx + 1) % (sizeof(commands) - 1); 29 | 30 | return ch; 31 | } 32 | 33 | void standby(void) 34 | { // Motor soll nicht heiß werden 35 | digitalWrite(IN1, LOW); 36 | digitalWrite(IN2, LOW); 37 | digitalWrite(IN3, LOW); 38 | digitalWrite(IN4, LOW); 39 | } 40 | 41 | static void longan_oled_init(void) 42 | { 43 | Lcd_Init(); // init OLED 44 | LCD_Clear(BLACK); 45 | BACK_COLOR = BLACK; 46 | } 47 | 48 | } 49 | 50 | void setup() { 51 | longan_oled_init(); 52 | 53 | LCD_ShowString(24, 0, (u8 const *) "Starting!", GBLUE); 54 | delay(500); 55 | 56 | stepmotor.setSpeed(10); 57 | standby(); 58 | LCD_ShowString(24, 0, (u8 const *) "Initialized!", GBLUE); 59 | delay(500); 60 | } 61 | 62 | void loop() { 63 | LCD_Clear(BLACK); 64 | 65 | char ch = next_command(); 66 | char const chs = ch; 67 | int val; 68 | 69 | switch (ch) { 70 | case 'f': val = 4096; ch='\0'; break; // 71 | case 'b': val = -4096; ch='\0'; break; // 72 | case 'v': val = 2048; ch='\0'; break; // 73 | case 'r': val = -2048; ch='\0'; break; // 74 | case '+': val = 1024; ch='\0'; break; // 75 | case '-': val = -1024; ch='\0'; break; // 76 | case 'c': val = 512; break; // run continous forward 77 | case 'e': val = 0; ch='\0'; break; // 78 | case '\0': val = 0; ch='\0'; break; // reset, nichts tun 79 | default: { // falscher Befehl. Hilfe zeigen: 80 | // Serial.print(ch); Serial.println(": command not available, try: "); 81 | // Serial.println(" f/b 1T, v/r 1/4T, +/- 1/128T, c ontinue, e nd"); 82 | val = 0; ch = '\0'; // reset 83 | } break; 84 | } 85 | 86 | char buf[64]; 87 | sprintf(buf, "i %d val %d ch %c", idx, val, chs); 88 | LCD_ShowString(0, 0, (u8 const *) buf, GBLUE); 89 | 90 | // move the number of steps 91 | stepmotor.step(val); 92 | 93 | // go into standby state 94 | if (ch != 'c') { 95 | delay(10); // warte auf Stillstand 96 | standby(); 97 | } 98 | 99 | LCD_ShowString(24, 64, (u8 const *) "Loop End!", GBLUE); 100 | delay(500); 101 | } -------------------------------------------------------------------------------- /arduino-stepper/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /arduino-stepper/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /bustester/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /bustester/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /bustester/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /bustester/include/gd32v_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 | -------------------------------------------------------------------------------- /bustester/include/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 | -------------------------------------------------------------------------------- /bustester/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /bustester/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /bustester/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = gd32vf103-sdk 15 | upload_port = COM3 16 | upload_protocol = rv-link 17 | debug_tool = rv-link 18 | build_type = debug 19 | debug_port = COM3 20 | monitor_port = COM10 21 | monitor_speed = 115200 -------------------------------------------------------------------------------- /bustester/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /intrbus/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /intrbus/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /intrbus/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /intrbus/include/gd32v_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 | -------------------------------------------------------------------------------- /intrbus/include/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 | -------------------------------------------------------------------------------- /intrbus/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /intrbus/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /intrbus/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = gd32vf103-sdk 15 | upload_port = COM3 16 | upload_protocol = rv-link 17 | debug_tool = rv-link 18 | build_type = debug 19 | debug_port = COM3 20 | monitor_port = COM10 21 | monitor_speed = 115200 -------------------------------------------------------------------------------- /intrbus/src/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include "gd32v_pjt_include.h" 6 | #include "systick.h" 7 | 8 | 9 | /** 10 | \brief configure the GPIO ports 11 | \param[in] none 12 | \param[out] none 13 | \retval none 14 | */ 15 | static void gpio_config(void) 16 | { 17 | /* Configure led GPIO port */ 18 | gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13); 19 | gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1); 20 | // gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1 | GPIO_PIN_2); 21 | } 22 | 23 | static void rcu_config(void) 24 | { 25 | rcu_periph_clock_enable(RCU_GPIOA); 26 | rcu_periph_clock_enable(RCU_GPIOB); 27 | rcu_periph_clock_enable(RCU_GPIOC); 28 | 29 | rcu_periph_clock_enable(RCU_TIMER1); 30 | } 31 | 32 | #define BOP_SET_BIT(X) (X) 33 | #define BOP_CLR_BIT(X) (X << 16) 34 | 35 | /** 36 | \brief configure the TIMER peripheral 37 | \param[in] none 38 | \param[out] none 39 | \retval none 40 | */ 41 | static 42 | void timer_config(void) 43 | { 44 | /* ---------------------------------------------------------------------------- 45 | TIMER1 Configuration: 46 | TIMER1CLK = SystemCoreClock/5400 = 20KHz. 47 | TIMER1 configuration is timing mode, and the timing is 0.2s(4000/20000 = 0.2s). 48 | CH0 update rate = TIMER1 counter clock/CH0CV = 20000/4000 = 5Hz. 49 | ---------------------------------------------------------------------------- */ 50 | timer_oc_parameter_struct timer_ocinitpara; 51 | timer_parameter_struct timer_initpara; 52 | 53 | rcu_periph_clock_enable(RCU_TIMER1); 54 | 55 | timer_deinit(TIMER1); 56 | /* initialize TIMER init parameter struct */ 57 | timer_struct_para_init(&timer_initpara); 58 | /* TIMER1 configuration */ 59 | timer_initpara.prescaler = 5399; 60 | timer_initpara.alignedmode = TIMER_COUNTER_EDGE; 61 | timer_initpara.counterdirection = TIMER_COUNTER_UP; 62 | timer_initpara.period = 4000; 63 | timer_initpara.clockdivision = TIMER_CKDIV_DIV1; 64 | timer_init(TIMER1, &timer_initpara); 65 | 66 | /* initialize TIMER channel output parameter struct */ 67 | timer_channel_output_struct_para_init(&timer_ocinitpara); 68 | /* CH0,CH1 and CH2 configuration in OC timing mode */ 69 | timer_ocinitpara.outputstate = TIMER_CCX_ENABLE; 70 | timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH; 71 | timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; 72 | timer_channel_output_config(TIMER1, TIMER_CH_0, &timer_ocinitpara); 73 | 74 | /* CH0 configuration in OC timing mode */ 75 | timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_0, 2000); 76 | timer_channel_output_mode_config(TIMER1, TIMER_CH_0, TIMER_OC_MODE_TIMING); 77 | timer_channel_output_shadow_config(TIMER1, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE); 78 | 79 | timer_interrupt_enable(TIMER1, TIMER_INT_CH0); 80 | timer_enable(TIMER1); 81 | } 82 | 83 | /* Must not be static! This is a global predefined symbol. */ 84 | void TIMER1_IRQHandler(void) 85 | { 86 | static uint32_t counter; 87 | 88 | if (SET == timer_interrupt_flag_get(TIMER1, TIMER_INT_CH0)) 89 | { 90 | /* clear channel 0 interrupt bit */ 91 | timer_interrupt_flag_clear(TIMER1, TIMER_INT_CH0); 92 | 93 | LEDR_TOG; 94 | LEDG_TOG; 95 | 96 | #if 0 97 | if (counter % 10 == 0) 98 | { 99 | LEDB_TOG; 100 | } 101 | counter += 1; 102 | #endif 103 | } 104 | } 105 | 106 | /*! 107 | \brief main function 108 | \param[in] none 109 | \param[out] none 110 | \retval none 111 | */ 112 | int main(void) 113 | { 114 | rcu_config(); 115 | gpio_config(); 116 | LEDR(0); 117 | // LEDB(0); 118 | LEDG(1); 119 | eclic_global_interrupt_enable(); 120 | eclic_set_nlbits(ECLIC_GROUP_LEVEL3_PRIO1); 121 | eclic_irq_enable(TIMER1_IRQn, 1, 0); 122 | timer_config(); 123 | while (1); 124 | } 125 | -------------------------------------------------------------------------------- /intrbus/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /intrbus/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /max6675/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /max6675/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < https://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < https://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < https://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choose one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # - platformio update 39 | # 40 | # script: 41 | # - platformio run 42 | 43 | 44 | # 45 | # Template #2: The project is intended to be used as a library with examples. 46 | # 47 | 48 | # language: python 49 | # python: 50 | # - "2.7" 51 | # 52 | # sudo: false 53 | # cache: 54 | # directories: 55 | # - "~/.platformio" 56 | # 57 | # env: 58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 59 | # - PLATFORMIO_CI_SRC=examples/file.ino 60 | # - PLATFORMIO_CI_SRC=path/to/test/directory 61 | # 62 | # install: 63 | # - pip install -U platformio 64 | # - platformio update 65 | # 66 | # script: 67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 68 | -------------------------------------------------------------------------------- /max6675/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /max6675/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "gd32vf103_spi.h": "c" 4 | } 5 | } -------------------------------------------------------------------------------- /max6675/NOTES.md: -------------------------------------------------------------------------------- 1 | # Notes on MAX6675 2 | 3 | ## With ESP8266 4 | 5 | ### SCK ESP8266 6 | 7 | * Period 2 ms 8 | * 500 Hz 9 | * Inactive high 10 | 11 | ## With Longan Nano 12 | 13 | ### SCK Longan Nano with prescale factor SPI_PSC_256 14 | 15 | * Period 4.7 microseconds 16 | * Frequency 212.766 kHz 17 | * Inactive low 18 | -------------------------------------------------------------------------------- /max6675/README.md: -------------------------------------------------------------------------------- 1 | # Read temperature values from MAX6675 sensor via SPI 2 | 3 | SPI1 is configured in software mode. The Longan Nano 4 | in a loop reads the SPI1 data value and displays it 5 | on the LCD. 6 | -------------------------------------------------------------------------------- /max6675/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /max6675/include/gd32v_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 | -------------------------------------------------------------------------------- /max6675/include/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 | -------------------------------------------------------------------------------- /max6675/include/lcd/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | 4 | #include "systick.h" 5 | #include "stdlib.h" 6 | #include "gd32vf103_gpio.h" 7 | 8 | #define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏 9 | #define HAS_BLK_CNTL 0 10 | 11 | #if USE_HORIZONTAL==0||USE_HORIZONTAL==1 12 | #define LCD_W 80 13 | #define LCD_H 160 14 | #else 15 | #define LCD_W 160 16 | #define LCD_H 80 17 | #endif 18 | 19 | typedef unsigned char u8; 20 | typedef unsigned int u16; 21 | typedef unsigned long u32; 22 | 23 | 24 | // #define LED_ON gpio_bit_reset(GPIOC,GPIO_PIN_13) 25 | // #define LED_OFF gpio_bit_set(GPIOC,GPIO_PIN_13) 26 | 27 | #define LED_ON 28 | #define LED_OFF 29 | 30 | #define SPI0_CFG 1 //hardware spi 31 | // #define SPI0_CFG 2 //hardware spi dma 32 | // #define SPI0_CFG 3 //software spi 33 | 34 | #define FRAME_SIZE 25600 35 | 36 | //-----------------OLED端口定义---------------- 37 | #if SPI0_CFG == 1 38 | #define OLED_SCLK_Clr() 39 | #define OLED_SCLK_Set() 40 | 41 | #define OLED_SDIN_Clr() 42 | #define OLED_SDIN_Set() 43 | 44 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 45 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 46 | #elif SPI0_CFG == 2 47 | #define OLED_SCLK_Clr() 48 | #define OLED_SCLK_Set() 49 | 50 | #define OLED_SDIN_Clr() 51 | #define OLED_SDIN_Set() 52 | 53 | #define OLED_CS_Clr() 54 | #define OLED_CS_Set() 55 | #else /* SPI0_CFG */ 56 | #define OLED_SCLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5) //CLK PA5 57 | #define OLED_SCLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 58 | 59 | #define OLED_SDIN_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_7) //DIN PA7 60 | #define OLED_SDIN_Set() gpio_bit_set(GPIOA,GPIO_PIN_7) 61 | 62 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 63 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 64 | #endif /* SPI0_CFG */ 65 | 66 | #define OLED_RST_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_1) //RES PB1 67 | #define OLED_RST_Set() gpio_bit_set(GPIOB,GPIO_PIN_1) 68 | 69 | #define OLED_DC_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_0) //DC PB0 70 | #define OLED_DC_Set() gpio_bit_set(GPIOB,GPIO_PIN_0) 71 | 72 | 73 | #if HAS_BLK_CNTL 74 | #define OLED_BLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5)//BLK 75 | #define OLED_BLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 76 | #else 77 | #define OLED_BLK_Clr() 78 | #define OLED_BLK_Set() 79 | #endif 80 | 81 | #define OLED_CMD 0 //写命令 82 | #define OLED_DATA 1 //写数据 83 | 84 | extern u16 BACK_COLOR; //背景色 85 | extern unsigned char image[12800]; 86 | 87 | void LCD_Writ_Bus(u8 dat); 88 | void LCD_WR_DATA8(u8 dat); 89 | void LCD_WR_DATA(u16 dat); 90 | void LCD_WR_REG(u8 dat); 91 | void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2); 92 | void Lcd_Init(void); 93 | void LCD_Clear(u16 Color); 94 | void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color); 95 | void LCD_DrawPoint(u16 x,u16 y,u16 color); 96 | void LCD_DrawPoint_big(u16 x,u16 y,u16 color); 97 | void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color); 98 | void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color); 99 | void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); 100 | void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color); 101 | void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color); 102 | void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color); 103 | u32 mypow(u8 m,u8 n); 104 | void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color); 105 | void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color); 106 | void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2); 107 | void LCD_ShowLogo(void); 108 | 109 | 110 | //画笔颜色 111 | #define WHITE 0xFFFF 112 | #define BLACK 0x0000 113 | #define BLUE 0x001F 114 | #define BRED 0XF81F 115 | #define GRED 0XFFE0 116 | #define GBLUE 0X07FF 117 | #define RED 0xF800 118 | #define MAGENTA 0xF81F 119 | #define GREEN 0x07E0 120 | #define CYAN 0x7FFF 121 | #define YELLOW 0xFFE0 122 | #define BROWN 0XBC40 //棕色 123 | #define BRRED 0XFC07 //棕红色 124 | #define GRAY 0X8430 //灰色 125 | //GUI颜色 126 | 127 | #define DARKBLUE 0X01CF //深蓝色 128 | #define LIGHTBLUE 0X7D7C //浅蓝色 129 | #define GRAYBLUE 0X5458 //灰蓝色 130 | //以上三色为PANEL的颜色 131 | 132 | #define LIGHTGREEN 0X841F //浅绿色 133 | #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色 134 | 135 | #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色) 136 | #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色) 137 | 138 | 139 | 140 | #endif 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /max6675/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /max6675/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /max6675/platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = gd32vf103-sdk 15 | upload_protocol = dfu 16 | -------------------------------------------------------------------------------- /max6675/src/main.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file main.c 3 | \brief Attach MAX6675 thermocouple to Longan Nano 4 | */ 5 | 6 | /* 7 | Copyright (c) 2019, GigaDevice Semiconductor Inc. 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, this 13 | list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 3. Neither the name of the copyright holder nor the names of its contributors 18 | may be used to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 | OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "gd32v_pjt_include.h" 34 | #include "lcd/lcd.h" 35 | #include 36 | 37 | static void rcu_config(void); 38 | static void gpio_config(void); 39 | static void spi1_config(void); 40 | static void longan_oled_init(void); 41 | static void longan_led_init(void); 42 | 43 | /*! 44 | \brief main function 45 | \param[in] none 46 | \param[out] none 47 | \retval none 48 | */ 49 | int main(void) 50 | { 51 | /* peripheral clock enable */ 52 | rcu_config(); 53 | 54 | /* GPIO configure */ 55 | gpio_config(); 56 | 57 | longan_oled_init(); 58 | 59 | longan_led_init(); 60 | 61 | LCD_ShowString(24, 0, (u8 const *) "Starting!", GBLUE); 62 | 63 | /* SPI MRU configure */ 64 | spi1_config(); 65 | 66 | uint32_t cntr = 0; 67 | while (TRUE) 68 | { 69 | // empty buffer 70 | spi_i2s_data_receive(SPI1); 71 | 72 | // start SCK 73 | spi_enable(SPI1); 74 | 75 | // CS low -> enabled 76 | gpio_bit_reset(GPIOB, GPIO_PIN_12); 77 | 78 | // Wait until reveive buffer is filled. 79 | while (RESET == spi_i2s_flag_get(SPI1, SPI_FLAG_RBNE)); 80 | 81 | uint16_t const data = spi_i2s_data_receive(SPI1); 82 | 83 | // CS high -> disabled 84 | gpio_bit_set(GPIOB, GPIO_PIN_12); 85 | 86 | // stop SCK 87 | spi_disable(SPI1); 88 | 89 | char buf[32]; 90 | sprintf(buf, "SPI data 0x%x", data); 91 | LCD_ShowString(24, 0, (u8 const *) buf, GBLUE); 92 | 93 | // extract temperature bits from 16-bit value 94 | uint16_t const temp_data = data >> 3; 95 | 96 | // format temperature in degrees 97 | uint16_t const degrees = temp_data / 4; 98 | uint16_t const hundredth_degrees = (temp_data % 4) * 100 / 4; 99 | sprintf(buf, "T %u.%02u deg ", degrees, hundredth_degrees); 100 | LCD_ShowString(24, 16, (u8 const *) buf, MAGENTA); 101 | 102 | static const char blanks[] = " "; 103 | strcpy(buf, blanks); 104 | buf[cntr % (sizeof(blanks) - 1)] = 'o'; 105 | LCD_ShowString(24, 32, (u8 const *) buf, LGRAY); 106 | 107 | delay_1ms(300); 108 | cntr += 1; 109 | 110 | LEDR_TOG; 111 | } while (1); 112 | } 113 | 114 | /*! 115 | \brief configure different peripheral clocks 116 | \param[in] none 117 | \param[out] none 118 | \retval none 119 | */ 120 | static void rcu_config(void) 121 | { 122 | rcu_periph_clock_enable(RCU_GPIOA); 123 | rcu_periph_clock_enable(RCU_GPIOB); 124 | rcu_periph_clock_enable(RCU_GPIOC); 125 | 126 | rcu_periph_clock_enable(RCU_SPI1); 127 | rcu_periph_clock_enable(RCU_AF); 128 | } 129 | 130 | static void longan_oled_init(void) 131 | { 132 | Lcd_Init(); // init OLED 133 | LCD_Clear(BLACK); 134 | BACK_COLOR = BLACK; 135 | } 136 | 137 | static void longan_led_init(void) 138 | { 139 | /* 1 means off! */ 140 | LEDR(1); 141 | LEDG(1); 142 | LEDB(1); 143 | } 144 | 145 | /*! 146 | \brief configure the GPIO peripheral 147 | \param[in] none 148 | \param[out] none 149 | \retval none 150 | */ 151 | static void gpio_config(void) 152 | { 153 | /* SPI1_SCK(PB13), SPI1_MISO(PB14) GPIO pin configuration */ 154 | gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13); 155 | gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_14); 156 | /* SPI1_CS(PB12) GPIO pin configuration, 157 | * GPIO_MODE_OUT_PP as it is controlled in software. 158 | */ 159 | gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12); 160 | 161 | /* CS disabled */ 162 | gpio_bit_set(GPIOB, GPIO_PIN_12); 163 | 164 | /* configure led GPIO port */ 165 | gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13); 166 | gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1|GPIO_PIN_2); 167 | } 168 | 169 | /*! 170 | \brief configure the SPI peripheral 171 | \param[in] none 172 | \param[out] none 173 | \retval none 174 | */ 175 | static void spi1_config(void) 176 | { 177 | spi_parameter_struct spi_init_struct; 178 | 179 | /* deinitilize SPI and the parameters */ 180 | spi_i2s_deinit(SPI1); 181 | spi_struct_para_init(&spi_init_struct); 182 | 183 | /* SPI1 parameter config */ 184 | spi_init_struct.trans_mode = SPI_TRANSMODE_RECEIVEONLY; 185 | spi_init_struct.device_mode = SPI_MASTER; 186 | spi_init_struct.frame_size = SPI_FRAMESIZE_16BIT; 187 | spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_2EDGE; 188 | spi_init_struct.nss = SPI_NSS_SOFT; 189 | spi_init_struct.prescale = SPI_PSC_256; // ~5274 Hz serial frequency 190 | spi_init_struct.endian = SPI_ENDIAN_MSB; 191 | spi_init(SPI1, &spi_init_struct); 192 | } 193 | -------------------------------------------------------------------------------- /max6675/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /max6675/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /micros/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | .pio 4 | .vscode 5 | -------------------------------------------------------------------------------- /micros/README.md: -------------------------------------------------------------------------------- 1 | 2 | Test program for Arduino micros() function 3 | ========================================== 4 | 5 | The test program shows that after several seconds the Arduino micros() 6 | function returns the value -1 continuously. 7 | -------------------------------------------------------------------------------- /micros/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /micros/include/lcd/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | 4 | #include "systick.h" 5 | #include "stdlib.h" 6 | #include "gd32vf103_gpio.h" 7 | 8 | #define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏 9 | #define HAS_BLK_CNTL 0 10 | 11 | #if USE_HORIZONTAL==0||USE_HORIZONTAL==1 12 | #define LCD_W 80 13 | #define LCD_H 160 14 | #else 15 | #define LCD_W 160 16 | #define LCD_H 80 17 | #endif 18 | 19 | typedef unsigned char u8; 20 | typedef unsigned int u16; 21 | typedef unsigned long u32; 22 | 23 | 24 | // #define LED_ON gpio_bit_reset(GPIOC,GPIO_PIN_13) 25 | // #define LED_OFF gpio_bit_set(GPIOC,GPIO_PIN_13) 26 | 27 | #define LED_ON 28 | #define LED_OFF 29 | 30 | #define SPI0_CFG 1 //hardware spi 31 | // #define SPI0_CFG 2 //hardware spi dma 32 | // #define SPI0_CFG 3 //software spi 33 | 34 | #define FRAME_SIZE 25600 35 | 36 | //-----------------OLED端口定义---------------- 37 | #if SPI0_CFG == 1 38 | #define OLED_SCLK_Clr() 39 | #define OLED_SCLK_Set() 40 | 41 | #define OLED_SDIN_Clr() 42 | #define OLED_SDIN_Set() 43 | 44 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 45 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 46 | #elif SPI0_CFG == 2 47 | #define OLED_SCLK_Clr() 48 | #define OLED_SCLK_Set() 49 | 50 | #define OLED_SDIN_Clr() 51 | #define OLED_SDIN_Set() 52 | 53 | #define OLED_CS_Clr() 54 | #define OLED_CS_Set() 55 | #else /* SPI0_CFG */ 56 | #define OLED_SCLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5) //CLK PA5 57 | #define OLED_SCLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 58 | 59 | #define OLED_SDIN_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_7) //DIN PA7 60 | #define OLED_SDIN_Set() gpio_bit_set(GPIOA,GPIO_PIN_7) 61 | 62 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 63 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 64 | #endif /* SPI0_CFG */ 65 | 66 | #define OLED_RST_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_1) //RES PB1 67 | #define OLED_RST_Set() gpio_bit_set(GPIOB,GPIO_PIN_1) 68 | 69 | #define OLED_DC_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_0) //DC PB0 70 | #define OLED_DC_Set() gpio_bit_set(GPIOB,GPIO_PIN_0) 71 | 72 | 73 | #if HAS_BLK_CNTL 74 | #define OLED_BLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5)//BLK 75 | #define OLED_BLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 76 | #else 77 | #define OLED_BLK_Clr() 78 | #define OLED_BLK_Set() 79 | #endif 80 | 81 | #define OLED_CMD 0 //写命令 82 | #define OLED_DATA 1 //写数据 83 | 84 | extern u16 BACK_COLOR; //背景色 85 | extern unsigned char image[12800]; 86 | 87 | void LCD_Writ_Bus(u8 dat); 88 | void LCD_WR_DATA8(u8 dat); 89 | void LCD_WR_DATA(u16 dat); 90 | void LCD_WR_REG(u8 dat); 91 | void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2); 92 | void Lcd_Init(void); 93 | void LCD_Clear(u16 Color); 94 | void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color); 95 | void LCD_DrawPoint(u16 x,u16 y,u16 color); 96 | void LCD_DrawPoint_big(u16 x,u16 y,u16 color); 97 | void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color); 98 | void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color); 99 | void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); 100 | void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color); 101 | void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color); 102 | void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color); 103 | u32 mypow(u8 m,u8 n); 104 | void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color); 105 | void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color); 106 | void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2); 107 | void LCD_ShowLogo(void); 108 | 109 | 110 | //画笔颜色 111 | #define WHITE 0xFFFF 112 | #define BLACK 0x0000 113 | #define BLUE 0x001F 114 | #define BRED 0XF81F 115 | #define GRED 0XFFE0 116 | #define GBLUE 0X07FF 117 | #define RED 0xF800 118 | #define MAGENTA 0xF81F 119 | #define GREEN 0x07E0 120 | #define CYAN 0x7FFF 121 | #define YELLOW 0xFFE0 122 | #define BROWN 0XBC40 //棕色 123 | #define BRRED 0XFC07 //棕红色 124 | #define GRAY 0X8430 //灰色 125 | //GUI颜色 126 | 127 | #define DARKBLUE 0X01CF //深蓝色 128 | #define LIGHTBLUE 0X7D7C //浅蓝色 129 | #define GRAYBLUE 0X5458 //灰蓝色 130 | //以上三色为PANEL的颜色 131 | 132 | #define LIGHTGREEN 0X841F //浅绿色 133 | #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色 134 | 135 | #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色) 136 | #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色) 137 | 138 | 139 | 140 | #endif 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /micros/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /micros/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /micros/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; http://docs.platformio.org/page/projectconf.html 9 | 10 | [env:sipeed-longan-nano] 11 | platform = gd32v 12 | framework = arduino 13 | board = sipeed-longan-nano 14 | monitor_speed = 115200 15 | upload_protocol = dfu 16 | platform_packages = framework-arduino-gd32v @ https://github.com/sipeed/Longduino.git 17 | -------------------------------------------------------------------------------- /micros/src/Micros.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Blink 3 | * Turns on an LED on for one second, 4 | * then off for one second, repeatedly. 5 | */ 6 | 7 | #include 8 | extern "C" { 9 | #include "lcd/lcd.h" 10 | } 11 | #include 12 | #include 13 | 14 | // Set LED_BUILTIN if it is not defined by Arduino framework 15 | // #define LED_BUILTIN 2 16 | 17 | static void longan_oled_init(void) 18 | { 19 | Lcd_Init(); 20 | LCD_Clear(BLACK); 21 | BACK_COLOR = BLACK; 22 | } 23 | 24 | void setup() 25 | { 26 | longan_oled_init(); 27 | 28 | // initialize LED digital pin as an output. 29 | pinMode(LED_BUILTIN, OUTPUT); 30 | } 31 | 32 | void loop() 33 | { 34 | uint64_t const time = micros(); 35 | 36 | char buf[64]; 37 | 38 | sprintf(buf, "time %" PRIu64 " ", time); 39 | LCD_ShowString(0, 0, (u8 const *) buf, GBLUE); 40 | 41 | sprintf(buf, "time %x%08x ", 42 | static_cast(time >> 32), 43 | static_cast(time)); 44 | LCD_ShowString(0, 16, (u8 const *) buf, GBLUE); 45 | 46 | // turn the LED on (HIGH is the voltage level) 47 | digitalWrite(LED_BUILTIN, HIGH); 48 | // wait for a second 49 | delay(1000); 50 | // turn the LED off by making the voltage LOW 51 | digitalWrite(LED_BUILTIN, LOW); 52 | // wait for a second 53 | delay(1000); 54 | } 55 | -------------------------------------------------------------------------------- /micros/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /micros/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /partimer/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /partimer/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /partimer/README.md: -------------------------------------------------------------------------------- 1 | # partimer Test Program 2 | 3 | Based on the TIMERs_parallelsynchro example program from the GD32VF103 4 | firmware library. 5 | 6 | The program retrieves the mcycleh/mcycle counter via SDK function 7 | get_cycle_value(). Note that the machine cycle counter must be 8 | explicitly enabled in main(). After startup it is disabled. 9 | -------------------------------------------------------------------------------- /partimer/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /partimer/include/gd32v_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 | -------------------------------------------------------------------------------- /partimer/include/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 | -------------------------------------------------------------------------------- /partimer/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /partimer/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /partimer/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = gd32vf103-sdk 15 | upload_port = COM3 16 | upload_protocol = rv-link 17 | debug_tool = rv-link 18 | build_type = debug 19 | debug_port = COM3 20 | monitor_port = COM10 21 | monitor_speed = 115200 -------------------------------------------------------------------------------- /partimer/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /partimer/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | wheel 2 | platformio -------------------------------------------------------------------------------- /rfid-spi/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /rfid-spi/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /rfid-spi/include/NoSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef NOSERIAL_H 2 | #define NOSERIAL_H 3 | 4 | #include 5 | #include "gd32vf103_libopt.h" 6 | 7 | class Serial_ : public Stream 8 | { 9 | public: 10 | Serial_() {} 11 | 12 | virtual int available() { return 0; } 13 | virtual int read() { return 0; } 14 | virtual int peek() { return 0; } 15 | virtual void flush() {} 16 | 17 | virtual size_t write(uint8_t c) { return fwrite(&c, 1, 1, stdout); } 18 | }; 19 | 20 | extern Serial_ Serial; 21 | 22 | #endif // NOSERIAL_H -------------------------------------------------------------------------------- /rfid-spi/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /rfid-spi/include/SPI.h: -------------------------------------------------------------------------------- 1 | #ifndef SPI_H 2 | #define SPI_H 3 | 4 | #include 5 | 6 | #include "lcdlog.h" 7 | 8 | namespace replacement 9 | { 10 | 11 | #define SPI_LSBFIRST 0 12 | #define SPI_MSBFIRST 1 13 | 14 | #define SPI_MODE0 0 15 | #define SPI_MODE1 1 16 | #define SPI_MODE2 2 17 | #define SPI_MODE3 3 18 | 19 | // byte constexpr SS = PB12; 20 | 21 | class SPISettings { 22 | public: 23 | SPISettings() 24 | : _freq(1000000) 25 | , _bitOrder(SPI_MSBFIRST) 26 | , _dataMode(SPI_MODE0) {} 27 | 28 | SPISettings(uint32_t freq, uint8_t bitOrder, uint8_t dataMode) 29 | : _freq(freq) 30 | , _bitOrder(bitOrder) 31 | , _dataMode(dataMode) {} 32 | 33 | uint32_t _freq; 34 | uint8_t _bitOrder; 35 | uint8_t _dataMode; 36 | }; 37 | 38 | class SPIClass { 39 | private: 40 | uint32_t _spi_periph; 41 | uint32_t _spi_gpio; 42 | rcu_periph_enum _rcu_periph_gpio; 43 | rcu_periph_enum _rcu_periph_spi; 44 | uint32_t _mosi; 45 | uint32_t _miso; 46 | uint32_t _sclk; 47 | uint32_t _ssel; 48 | 49 | public: 50 | SPIClass(uint32_t spi_periph, uint32_t spi_gpio, 51 | rcu_periph_enum rcu_periph_gpio, 52 | rcu_periph_enum rcu_periph_spi, 53 | uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel) 54 | : _spi_periph(spi_periph), 55 | _spi_gpio(spi_gpio), 56 | _rcu_periph_gpio(rcu_periph_gpio), 57 | _rcu_periph_spi(rcu_periph_spi), 58 | _mosi(mosi), 59 | _miso(miso), 60 | _sclk(sclk), 61 | _ssel(ssel) 62 | { 63 | } 64 | 65 | SPIClass() : SPIClass(0, 0, RCU_GPIOB, RCU_SPI1, 0, 0, 0, 0) {} 66 | 67 | void begin() 68 | { 69 | } 70 | 71 | void end() 72 | { 73 | } 74 | 75 | void beginTransaction(SPISettings const& spiSettings = SPISettings()) 76 | { 77 | rcu_periph_clock_enable(_rcu_periph_gpio); 78 | rcu_periph_clock_enable(_rcu_periph_spi); 79 | rcu_periph_clock_enable(RCU_AF); 80 | 81 | /* SPI SCK, SPI MISO, SPI MOSI GPIO pin configuration */ 82 | gpio_init(_spi_gpio, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, _mosi | _miso | _sclk); 83 | 84 | /* SPI CS GPIO pin configuration, 85 | * GPIO_MODE_OUT_PP as it is controlled in software. 86 | */ 87 | gpio_init(_spi_gpio, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, _ssel); 88 | 89 | /* CS disabled */ 90 | gpio_bit_set(_spi_gpio, _ssel); 91 | 92 | spi_parameter_struct spi_init_struct; 93 | 94 | /* deinitilize SPI and the parameters */ 95 | spi_i2s_deinit(_spi_periph); 96 | spi_struct_para_init(&spi_init_struct); 97 | 98 | /* SPI1 parameter config */ 99 | spi_init_struct.trans_mode = SPI_TRANSMODE_FULLDUPLEX; 100 | spi_init_struct.device_mode = SPI_MASTER; 101 | spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT; 102 | spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE; 103 | spi_init_struct.nss = SPI_NSS_SOFT; 104 | spi_init_struct.prescale = SPI_PSC_8; 105 | spi_init_struct.endian = SPI_ENDIAN_MSB; 106 | 107 | spi_init(_spi_periph, &spi_init_struct); 108 | 109 | spi_enable(_spi_periph); 110 | } 111 | 112 | void endTransaction() 113 | { 114 | spi_disable(_spi_periph); 115 | } 116 | 117 | // timeout in ms 118 | void transfer(uint8_t const *data, uint32_t size, uint32_t timeout = 1) 119 | { 120 | LcdLog::lcdLog.logBytes((const u8 *) data, static_cast(size), WHITE); 121 | 122 | uint64_t const startT = millis(); 123 | 124 | gpio_bit_reset(_spi_gpio, _ssel); 125 | 126 | for (size_t i = 0; i < size; i++) 127 | { 128 | while (!spi_i2s_flag_get(_spi_periph, SPI_FLAG_TBE)) 129 | { 130 | if (millis() > startT + timeout) 131 | { 132 | gpio_bit_set(_spi_gpio, _ssel); 133 | return; 134 | } 135 | } 136 | spi_i2s_data_transmit(_spi_periph, *data); 137 | data++; 138 | } 139 | 140 | gpio_bit_set(_spi_gpio, _ssel); 141 | } 142 | 143 | void transfer( 144 | uint8_t const *txdata, uint8_t *rxdata, uint32_t size, uint32_t timeout = 1) 145 | { 146 | LcdLog::lcdLog.logBytes((const u8 *) txdata, static_cast(size), WHITE); 147 | uint8_t const * const rxdata_sav = rxdata; 148 | 149 | uint64_t const startT = millis(); 150 | 151 | gpio_bit_reset(_spi_gpio, _ssel); 152 | 153 | for (size_t i = 0; i < size; i++) 154 | { 155 | while (!spi_i2s_flag_get(_spi_periph, SPI_FLAG_TBE)) 156 | { 157 | if (millis() > startT + timeout) 158 | { 159 | gpio_bit_set(_spi_gpio, _ssel); 160 | return; 161 | } 162 | } 163 | spi_i2s_data_transmit(_spi_periph, *txdata); 164 | txdata++; 165 | while (!spi_i2s_flag_get(_spi_periph, SPI_FLAG_RBNE)) 166 | { 167 | if (millis() > startT + timeout) 168 | { 169 | gpio_bit_set(_spi_gpio, _ssel); 170 | return; 171 | } 172 | } 173 | *rxdata = spi_i2s_data_receive(_spi_periph); 174 | rxdata++; 175 | } 176 | 177 | gpio_bit_set(_spi_gpio, _ssel); 178 | 179 | LcdLog::lcdLog.logBytes((const u8 *) rxdata_sav, static_cast(size), GREEN); 180 | } 181 | }; 182 | 183 | } 184 | 185 | static constexpr byte SS = PA0; 186 | 187 | #endif // SPI_H -------------------------------------------------------------------------------- /rfid-spi/include/deprecated.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 by Ludwig Grill (www.rotzbua.de) 3 | * Simple deprecated workaround for Arduino IDE 4 | * IDE 1.6.8 use gcc 4.8 which do not support c++14 [[deprecated]] 5 | * Later versions should support c++14, then use c++14 syntax 6 | */ 7 | #ifndef DEPRECATED_H 8 | #define DEPRECATED_H 9 | 10 | #ifdef __has_cpp_attribute 11 | #if __has_cpp_attribute(deprecated) 12 | #define DEPRECATED [[deprecated]] 13 | #define DEPRECATED_MSG(msg) [[deprecated(msg)]] 14 | #endif // __has_cpp_attribute(deprecated) 15 | #else 16 | #define DEPRECATED __attribute__((deprecated)) 17 | #define DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) 18 | #endif // __has_cpp_attribute 19 | 20 | #endif // DEPRECATED_H 21 | -------------------------------------------------------------------------------- /rfid-spi/include/gd32v_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 | -------------------------------------------------------------------------------- /rfid-spi/include/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 | -------------------------------------------------------------------------------- /rfid-spi/include/lcd/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | 4 | #include "systick.h" 5 | #include "stdlib.h" 6 | #include "gd32vf103_gpio.h" 7 | 8 | #define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏 9 | #define HAS_BLK_CNTL 0 10 | 11 | #if USE_HORIZONTAL==0||USE_HORIZONTAL==1 12 | #define LCD_W 80 13 | #define LCD_H 160 14 | #else 15 | #define LCD_W 160 16 | #define LCD_H 80 17 | #endif 18 | 19 | typedef unsigned char u8; 20 | typedef unsigned int u16; 21 | typedef unsigned long u32; 22 | 23 | 24 | // #define LED_ON gpio_bit_reset(GPIOC,GPIO_PIN_13) 25 | // #define LED_OFF gpio_bit_set(GPIOC,GPIO_PIN_13) 26 | 27 | #define LED_ON 28 | #define LED_OFF 29 | 30 | #define SPI0_CFG 1 //hardware spi 31 | // #define SPI0_CFG 2 //hardware spi dma 32 | // #define SPI0_CFG 3 //software spi 33 | 34 | #define FRAME_SIZE 25600 35 | 36 | //-----------------OLED端口定义---------------- 37 | #if SPI0_CFG == 1 38 | #define OLED_SCLK_Clr() 39 | #define OLED_SCLK_Set() 40 | 41 | #define OLED_SDIN_Clr() 42 | #define OLED_SDIN_Set() 43 | 44 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 45 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 46 | #elif SPI0_CFG == 2 47 | #define OLED_SCLK_Clr() 48 | #define OLED_SCLK_Set() 49 | 50 | #define OLED_SDIN_Clr() 51 | #define OLED_SDIN_Set() 52 | 53 | #define OLED_CS_Clr() 54 | #define OLED_CS_Set() 55 | #else /* SPI0_CFG */ 56 | #define OLED_SCLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5) //CLK PA5 57 | #define OLED_SCLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 58 | 59 | #define OLED_SDIN_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_7) //DIN PA7 60 | #define OLED_SDIN_Set() gpio_bit_set(GPIOA,GPIO_PIN_7) 61 | 62 | #define OLED_CS_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_2) //CS PB2 63 | #define OLED_CS_Set() gpio_bit_set(GPIOB,GPIO_PIN_2) 64 | #endif /* SPI0_CFG */ 65 | 66 | #define OLED_RST_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_1) //RES PB1 67 | #define OLED_RST_Set() gpio_bit_set(GPIOB,GPIO_PIN_1) 68 | 69 | #define OLED_DC_Clr() gpio_bit_reset(GPIOB,GPIO_PIN_0) //DC PB0 70 | #define OLED_DC_Set() gpio_bit_set(GPIOB,GPIO_PIN_0) 71 | 72 | 73 | #if HAS_BLK_CNTL 74 | #define OLED_BLK_Clr() gpio_bit_reset(GPIOA,GPIO_PIN_5)//BLK 75 | #define OLED_BLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5) 76 | #else 77 | #define OLED_BLK_Clr() 78 | #define OLED_BLK_Set() 79 | #endif 80 | 81 | #define OLED_CMD 0 //写命令 82 | #define OLED_DATA 1 //写数据 83 | 84 | extern u16 BACK_COLOR; //背景色 85 | extern unsigned char image[12800]; 86 | 87 | void LCD_Writ_Bus(u8 dat); 88 | void LCD_WR_DATA8(u8 dat); 89 | void LCD_WR_DATA(u16 dat); 90 | void LCD_WR_REG(u8 dat); 91 | void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2); 92 | void Lcd_Init(void); 93 | void LCD_Clear(u16 Color); 94 | void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color); 95 | void LCD_DrawPoint(u16 x,u16 y,u16 color); 96 | void LCD_DrawPoint_big(u16 x,u16 y,u16 color); 97 | void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color); 98 | void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color); 99 | void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); 100 | void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color); 101 | void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color); 102 | void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color); 103 | u32 mypow(u8 m,u8 n); 104 | void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color); 105 | void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color); 106 | void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2); 107 | void LCD_ShowLogo(void); 108 | 109 | 110 | //画笔颜色 111 | #define WHITE 0xFFFF 112 | #define BLACK 0x0000 113 | #define BLUE 0x001F 114 | #define BRED 0XF81F 115 | #define GRED 0XFFE0 116 | #define GBLUE 0X07FF 117 | #define RED 0xF800 118 | #define MAGENTA 0xF81F 119 | #define GREEN 0x07E0 120 | #define CYAN 0x7FFF 121 | #define YELLOW 0xFFE0 122 | #define BROWN 0XBC40 //棕色 123 | #define BRRED 0XFC07 //棕红色 124 | #define GRAY 0X8430 //灰色 125 | //GUI颜色 126 | 127 | #define DARKBLUE 0X01CF //深蓝色 128 | #define LIGHTBLUE 0X7D7C //浅蓝色 129 | #define GRAYBLUE 0X5458 //灰蓝色 130 | //以上三色为PANEL的颜色 131 | 132 | #define LIGHTGREEN 0X841F //浅绿色 133 | #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色 134 | 135 | #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色) 136 | #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色) 137 | 138 | 139 | 140 | #endif 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /rfid-spi/include/lcdlog.h: -------------------------------------------------------------------------------- 1 | #ifndef LCDLOG_H 2 | #define LCDLOG_H 3 | 4 | extern "C" { 5 | #include "lcd/lcd.h" 6 | } 7 | 8 | class LcdLog 9 | { 10 | public: 11 | LcdLog() : current_line(0) {} 12 | 13 | void logString(const char *p, u16 color = WHITE); 14 | void logBytes(const u8 *p, size_t n, u16 color = WHITE); 15 | 16 | static LcdLog lcdLog; 17 | 18 | private: 19 | static constexpr unsigned int lines = 5; 20 | static constexpr unsigned int chars_per_line = 20; 21 | 22 | unsigned int current_line; 23 | 24 | void showLine(const char *p, u16 color = WHITE); 25 | }; 26 | 27 | 28 | 29 | #endif -------------------------------------------------------------------------------- /rfid-spi/include/require_cpp11.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 by Ludwig Grill (www.rotzbua.de) 3 | * Throws error if c++11 is not supported 4 | */ 5 | #ifndef REQUIRE_CPP11_H 6 | #define REQUIRE_CPP11_H 7 | 8 | #if __cplusplus < 201103L 9 | #error "This library needs at least a C++11 compliant compiler, maybe compiler argument for C++11 support is missing or if you use Arduino IDE upgrade to version >=1.6.6" 10 | #endif 11 | 12 | #endif // REQUIRE_CPP11_H 13 | -------------------------------------------------------------------------------- /rfid-spi/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /rfid-spi/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /rfid-spi/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = arduino 15 | ; platform_packages = framework-arduino-gd32v @ https://github.com/smuehlst/Longduino.git 16 | platform_packages = framework-arduino-gd32v @ file://e:/Users/stm/Documents/GitHub/Longduino 17 | upload_port = COM5 18 | upload_protocol = rv-link 19 | debug_tool = rv-link 20 | build_type = debug 21 | debug_port = COM5 22 | monitor_port = COM10 23 | monitor_speed = 115200 24 | -------------------------------------------------------------------------------- /rfid-spi/src/NoSerial.cpp: -------------------------------------------------------------------------------- 1 | #include "NoSerial.h" 2 | 3 | Serial_ Serial; -------------------------------------------------------------------------------- /rfid-spi/src/lcdlog.cpp: -------------------------------------------------------------------------------- 1 | #include "lcdlog.h" 2 | #include 3 | #include 4 | 5 | LcdLog LcdLog::lcdLog; 6 | 7 | void LcdLog::logString(const char *p, u16 color) 8 | { 9 | unsigned int logline = current_line % 10; 10 | char buf[chars_per_line + 1]; 11 | 12 | sprintf(buf, "%1u ", logline); 13 | strncpy(buf + 2, (char *) p, 18); 14 | buf[20] = 0; 15 | 16 | showLine(buf, color); 17 | } 18 | 19 | void LcdLog::logBytes(const u8 *p, size_t n, u16 color) 20 | { 21 | unsigned int logline = current_line % 10; 22 | char buf[chars_per_line + 1]; 23 | char *cp = buf; 24 | size_t i; 25 | 26 | cp += sprintf(cp, "%1u ", logline); 27 | 28 | for (i = 0; 29 | i < n 30 | && static_cast((cp + 2) - buf) < chars_per_line; 31 | i += 1) { 32 | cp += sprintf(cp, "%02x", *(p + i)); 33 | } 34 | 35 | showLine(buf, color); 36 | } 37 | 38 | void LcdLog::showLine(const char *p, u16 color) 39 | { 40 | LCD_ShowString(0, 16 * (current_line % lines), (const u8 *) p, color); 41 | current_line += 1; 42 | } -------------------------------------------------------------------------------- /rfid-spi/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include "gd32v_pjt_include.h" 6 | extern "C" { 7 | #include "lcd/lcd.h" 8 | } 9 | #include "lcdlog.h" 10 | 11 | MFRC522 mfrc522(SPI1, GPIOB, RCU_GPIOB, RCU_SPI1, 12 | GPIO_PIN_15, GPIO_PIN_14, GPIO_PIN_13, GPIO_PIN_12); // Create MFRC522 instance 13 | 14 | LcdLog lcdLog; 15 | 16 | static void gpio_config(void) 17 | { 18 | /* configure led GPIO port */ 19 | gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13); 20 | gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1 | GPIO_PIN_2); 21 | } 22 | 23 | static void rcu_config(void) 24 | { 25 | rcu_periph_clock_enable(RCU_GPIOA); 26 | rcu_periph_clock_enable(RCU_GPIOC); 27 | } 28 | 29 | static void longan_led_init(void) 30 | { 31 | /* 1 means off! */ 32 | LEDR(1); 33 | LEDG(1); 34 | LEDB(1); 35 | } 36 | 37 | static void longan_oled_init(void) 38 | { 39 | Lcd_Init(); // init OLED 40 | LCD_Clear(BLACK); 41 | BACK_COLOR = BLACK; 42 | } 43 | 44 | static void longan_serial_init(void) 45 | { 46 | /* connect port to USARTx_Tx */ 47 | gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9); 48 | 49 | /* connect port to USARTx_Rx */ 50 | gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10); 51 | 52 | /* USART configure */ 53 | usart_deinit(USART0); 54 | usart_baudrate_set(USART0, 115200U); 55 | usart_word_length_set(USART0, USART_WL_8BIT); 56 | usart_stop_bit_set(USART0, USART_STB_1BIT); 57 | usart_parity_config(USART0, USART_PM_NONE); 58 | usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE); 59 | usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE); 60 | usart_receive_config(USART0, USART_RECEIVE_ENABLE); 61 | usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); 62 | usart_enable(USART0); 63 | } 64 | 65 | /* retarget the C library printf function to the USART */ 66 | int _put_char(int ch) 67 | { 68 | usart_data_transmit(USART0, (uint8_t) ch ); 69 | while (usart_flag_get(USART0, USART_FLAG_TBE) == RESET){ 70 | } 71 | 72 | return ch; 73 | } 74 | 75 | void setup() 76 | { 77 | rcu_config(); 78 | 79 | gpio_config(); 80 | 81 | longan_serial_init(); 82 | longan_oled_init(); 83 | longan_oled_init(); 84 | 85 | longan_led_init(); 86 | 87 | Serial.println("Started"); 88 | 89 | mfrc522.PCD_Init(); // Init MFRC522 90 | delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme 91 | mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details 92 | 93 | LEDG_TOG; 94 | } 95 | 96 | void loop() { 97 | delay_1ms(500); 98 | 99 | // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. 100 | if ( ! mfrc522.PICC_IsNewCardPresent()) { 101 | return; 102 | } 103 | 104 | LEDR_TOG; 105 | 106 | // Select one of the cards 107 | if ( ! mfrc522.PICC_ReadCardSerial()) { 108 | return; 109 | } 110 | 111 | LEDB_TOG; 112 | 113 | // Dump debug info about the card; PICC_HaltA() is automatically called 114 | mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); 115 | } -------------------------------------------------------------------------------- /rfid-spi/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /rfid-spi/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /serial-printf/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /serial-printf/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /serial-printf/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "cstdio": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /serial-printf/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /serial-printf/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /serial-printf/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = gd32vf103-sdk 15 | upload_port = COM5 16 | upload_protocol = rv-link 17 | debug_tool = rv-link 18 | build_type = debug 19 | debug_port = COM5 20 | ; monitor_port = COM10 21 | monitor_speed = 115200 -------------------------------------------------------------------------------- /serial-printf/src/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 | -------------------------------------------------------------------------------- /serial-printf/src/main.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file main.c 3 | \brief USART printf 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 | 38 | /*! 39 | \brief main function 40 | \param[in] none 41 | \param[out] none 42 | \retval none 43 | */ 44 | int main(void) 45 | { 46 | /* enable GPIO clock */ 47 | rcu_periph_clock_enable(RCU_GPIOA); 48 | 49 | /* enable USART clock */ 50 | rcu_periph_clock_enable(RCU_USART0); 51 | 52 | /* connect port to USARTx_Tx */ 53 | gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9); 54 | 55 | /* connect port to USARTx_Rx */ 56 | gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10); 57 | 58 | /* USART configure */ 59 | usart_deinit(USART0); 60 | usart_baudrate_set(USART0, 115200U); 61 | usart_word_length_set(USART0, USART_WL_8BIT); 62 | usart_stop_bit_set(USART0, USART_STB_1BIT); 63 | usart_parity_config(USART0, USART_PM_NONE); 64 | usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE); 65 | usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE); 66 | usart_receive_config(USART0, USART_RECEIVE_ENABLE); 67 | usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); 68 | usart_enable(USART0); 69 | 70 | printf("a usart transmit test example!\n\r"); 71 | while(1); 72 | } 73 | 74 | /* retarget the C library printf function to the USART */ 75 | int _put_char(int ch) 76 | { 77 | usart_data_transmit(USART0, (uint8_t) ch ); 78 | while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET){ 79 | } 80 | 81 | return ch; 82 | } 83 | -------------------------------------------------------------------------------- /serial-printf/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /spi-dma-test/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | .pio 4 | -------------------------------------------------------------------------------- /spi-dma-test/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags" 5 | }, 6 | { 7 | "name": "Win32", 8 | "includePath": [ 9 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-dma-test/include", 10 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-dma-test/src", 11 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral", 12 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Include", 13 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver", 14 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver/Include", 15 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/drivers", 16 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/env_Eclipse", 17 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/stubs", 18 | "C:/.platformio/packages/tool-unity", 19 | "" 20 | ], 21 | "browse": { 22 | "limitSymbolsToIncludedHeaders": true, 23 | "path": [ 24 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-dma-test/include", 25 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-dma-test/src", 26 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral", 27 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Include", 28 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver", 29 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver/Include", 30 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/drivers", 31 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/env_Eclipse", 32 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/stubs", 33 | "C:/.platformio/packages/tool-unity", 34 | "" 35 | ] 36 | }, 37 | "defines": [ 38 | "PLATFORMIO=40101", 39 | "USE_STDPERIPH_DRIVER", 40 | "HXTAL_VALUE=8000000U", 41 | "__PLATFORMIO_BUILD_DEBUG__", 42 | "" 43 | ], 44 | "intelliSenseMode": "clang-x64", 45 | "cStandard": "c11", 46 | "cppStandard": "c++17", 47 | "compilerPath": "\"C:/.platformio/packages/toolchain-gd32v/bin/riscv-nuclei-elf-gcc.exe\" -march=rv32imac -mabi=ilp32 -mcmodel=medlow" 48 | } 49 | ], 50 | "version": 4 51 | } 52 | -------------------------------------------------------------------------------- /spi-dma-test/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /spi-dma-test/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY 2 | 3 | // PIO Unified Debugger 4 | // 5 | // Documentation: https://docs.platformio.org/page/plus/debugging.html 6 | // Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html 7 | 8 | { 9 | "version": "0.2.0", 10 | "configurations": [ 11 | { 12 | "type": "platformio-debug", 13 | "request": "launch", 14 | "name": "PIO Debug", 15 | "executable": "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-dma-test/.pio/build/sipeed-longan-nano/firmware.elf", 16 | "toolchainBinDir": "C:/.platformio/packages/toolchain-gd32v/bin", 17 | "svdPath": "C:/.platformio/platforms/gd32v/misc/svd/GD32VF103.svd", 18 | "preLaunchTask": { 19 | "type": "PlatformIO", 20 | "task": "Pre-Debug" 21 | }, 22 | "internalConsoleOptions": "openOnSessionStart" 23 | }, 24 | { 25 | "type": "platformio-debug", 26 | "request": "launch", 27 | "name": "PIO Debug (skip Pre-Debug)", 28 | "executable": "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-dma-test/.pio/build/sipeed-longan-nano/firmware.elf", 29 | "toolchainBinDir": "C:/.platformio/packages/toolchain-gd32v/bin", 30 | "svdPath": "C:/.platformio/platforms/gd32v/misc/svd/GD32VF103.svd", 31 | "internalConsoleOptions": "openOnSessionStart" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /spi-dma-test/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "gd32vf103.h": "c", 4 | "system_gd32vf103.h": "c" 5 | } 6 | } -------------------------------------------------------------------------------- /spi-dma-test/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /spi-dma-test/include/gd32v_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 | -------------------------------------------------------------------------------- /spi-dma-test/include/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 | -------------------------------------------------------------------------------- /spi-dma-test/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /spi-dma-test/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /spi-dma-test/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; http://docs.platformio.org/page/projectconf.html 9 | 10 | [env:sipeed-longan-nano] 11 | platform = gd32v 12 | framework = gd32vf103-sdk 13 | board = sipeed-longan-nano 14 | monitor_speed = 115200 15 | upload_protocol = rv-link 16 | debug_tool = rv-link 17 | build_type = debug 18 | debug_port = COM5 19 | -------------------------------------------------------------------------------- /spi-dma-test/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /spi-dma-test/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /spi-test/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | .pio 4 | -------------------------------------------------------------------------------- /spi-test/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags" 5 | }, 6 | { 7 | "name": "Win32", 8 | "includePath": [ 9 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-test/include", 10 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-test/src", 11 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral", 12 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Include", 13 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver", 14 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver/Include", 15 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/drivers", 16 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/env_Eclipse", 17 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/stubs", 18 | "C:/.platformio/packages/tool-unity", 19 | "" 20 | ], 21 | "browse": { 22 | "limitSymbolsToIncludedHeaders": true, 23 | "path": [ 24 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-test/include", 25 | "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-test/src", 26 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral", 27 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Include", 28 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver", 29 | "C:/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_usbfs_driver/Include", 30 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/drivers", 31 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/env_Eclipse", 32 | "C:/.platformio/packages/framework-gd32vf103-sdk/RISCV/stubs", 33 | "C:/.platformio/packages/tool-unity", 34 | "" 35 | ] 36 | }, 37 | "defines": [ 38 | "PLATFORMIO=40101", 39 | "USE_STDPERIPH_DRIVER", 40 | "HXTAL_VALUE=8000000U", 41 | "__PLATFORMIO_BUILD_DEBUG__", 42 | "" 43 | ], 44 | "intelliSenseMode": "clang-x64", 45 | "cStandard": "c11", 46 | "cppStandard": "c++17", 47 | "compilerPath": "\"C:/.platformio/packages/toolchain-gd32v/bin/riscv-nuclei-elf-gcc.exe\" -march=rv32imac -mabi=ilp32 -mcmodel=medlow" 48 | } 49 | ], 50 | "version": 4 51 | } 52 | -------------------------------------------------------------------------------- /spi-test/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /spi-test/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY 2 | 3 | // PIO Unified Debugger 4 | // 5 | // Documentation: https://docs.platformio.org/page/plus/debugging.html 6 | // Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html 7 | 8 | { 9 | "version": "0.2.0", 10 | "configurations": [ 11 | { 12 | "type": "platformio-debug", 13 | "request": "launch", 14 | "name": "PIO Debug", 15 | "executable": "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-test/.pio/build/sipeed-longan-nano/firmware.elf", 16 | "toolchainBinDir": "C:/.platformio/packages/toolchain-gd32v/bin", 17 | "svdPath": "C:/.platformio/platforms/gd32v/misc/svd/GD32VF103.svd", 18 | "preLaunchTask": { 19 | "type": "PlatformIO", 20 | "task": "Pre-Debug" 21 | }, 22 | "internalConsoleOptions": "openOnSessionStart" 23 | }, 24 | { 25 | "type": "platformio-debug", 26 | "request": "launch", 27 | "name": "PIO Debug (skip Pre-Debug)", 28 | "executable": "e:/Users/stm/Documents/GitHub/longannano/longan-nano-experiments/spi-test/.pio/build/sipeed-longan-nano/firmware.elf", 29 | "toolchainBinDir": "C:/.platformio/packages/toolchain-gd32v/bin", 30 | "svdPath": "C:/.platformio/platforms/gd32v/misc/svd/GD32VF103.svd", 31 | "internalConsoleOptions": "openOnSessionStart" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /spi-test/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "gd32vf103.h": "c", 4 | "system_gd32vf103.h": "c" 5 | } 6 | } -------------------------------------------------------------------------------- /spi-test/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /spi-test/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /spi-test/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /spi-test/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; http://docs.platformio.org/page/projectconf.html 9 | 10 | [env:sipeed-longan-nano] 11 | platform = gd32v 12 | framework = gd32vf103-sdk 13 | board = sipeed-longan-nano 14 | monitor_speed = 115200 15 | upload_protocol = rv-link 16 | debug_tool = rv-link 17 | build_type = debug 18 | debug_port = COM5 19 | -------------------------------------------------------------------------------- /spi-test/src/main.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file main.c 3 | \brief running SPI test 4 | 5 | This program is a small test program to test SPI receive-only and full duplect modes. 6 | */ 7 | 8 | #include "gd32vf103.h" 9 | #include "systick.h" 10 | #include 11 | 12 | /* BUILTIN LED OF LONGAN BOARDS IS PIN PC13 */ 13 | #define LED_PIN GPIO_PIN_13 14 | #define LED_GPIO_PORT GPIOC 15 | #define LED_GPIO_CLK RCU_GPIOC 16 | 17 | void longan_spi_init() 18 | { 19 | rcu_periph_clock_enable(RCU_GPIOB); 20 | rcu_periph_clock_enable(RCU_SPI1); 21 | rcu_periph_clock_enable(RCU_AF); 22 | 23 | /* SPI SCK/PB13, SPI MISO/PB14, SPI MOSI/PB15 GPIO pin configuration */ 24 | gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13); 25 | 26 | /* SPI CS/PB12 GPIO pin configuration, 27 | * GPIO_MODE_OUT_PP as it is controlled in software. 28 | */ 29 | gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12); 30 | 31 | /* CS disabled */ 32 | gpio_bit_set(GPIOB, GPIO_PIN_12); 33 | 34 | spi_parameter_struct spi_init_struct; 35 | 36 | /* deinitialize SPI and the parameters */ 37 | spi_i2s_deinit(SPI1); 38 | spi_struct_para_init(&spi_init_struct); 39 | 40 | /* SPI1 parameter config */ 41 | spi_init_struct.trans_mode = SPI_TRANSMODE_FULLDUPLEX; 42 | spi_init_struct.device_mode = SPI_MASTER; 43 | spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT; 44 | spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_2EDGE; 45 | spi_init_struct.nss = SPI_NSS_SOFT; 46 | spi_init_struct.prescale = SPI_PSC_256; 47 | spi_init_struct.endian = SPI_ENDIAN_MSB; 48 | spi_init(SPI1, &spi_init_struct); 49 | } 50 | 51 | void longan_led_init() 52 | { 53 | /* enable the led clock */ 54 | rcu_periph_clock_enable(LED_GPIO_CLK); 55 | /* configure led GPIO port */ 56 | gpio_init(LED_GPIO_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LED_PIN); 57 | 58 | GPIO_BC(LED_GPIO_PORT) = LED_PIN; 59 | } 60 | 61 | void longan_led_on() 62 | { 63 | GPIO_BOP(LED_GPIO_PORT) = LED_PIN; 64 | } 65 | 66 | void longan_led_off() 67 | { 68 | GPIO_BC(LED_GPIO_PORT) = LED_PIN; 69 | } 70 | 71 | /*! 72 | \brief main function 73 | \param[in] none 74 | \param[out] none 75 | \retval none 76 | */ 77 | int main(void) 78 | { 79 | uint32_t volatile counter = 0; 80 | 81 | longan_led_init(); 82 | longan_spi_init(); 83 | 84 | spi_enable(SPI1); 85 | while (1) { 86 | longan_led_on(); 87 | gpio_bit_reset(GPIOB, GPIO_PIN_12); 88 | 89 | while(RESET == spi_i2s_flag_get(SPI1, SPI_FLAG_TBE)); 90 | spi_i2s_data_transmit(SPI1, (uint16_t) counter); 91 | 92 | while(RESET == spi_i2s_flag_get(SPI1, SPI_FLAG_RBNE)); 93 | uint16_t volatile indata = spi_i2s_data_receive(SPI1); 94 | 95 | longan_led_off(); 96 | gpio_bit_set(GPIOB, GPIO_PIN_12); 97 | delay_1ms(1); 98 | 99 | counter += 1; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /spi-test/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /spi-test/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /stepper/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | .pio 4 | .vscode 5 | -------------------------------------------------------------------------------- /stepper/README.md: -------------------------------------------------------------------------------- 1 | Step motor test program 2 | ======================= 3 | 4 | Drive stepper motors with the Longan Nano SDK. 5 | -------------------------------------------------------------------------------- /stepper/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /stepper/include/gd32v_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 | -------------------------------------------------------------------------------- /stepper/include/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 | -------------------------------------------------------------------------------- /stepper/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /stepper/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /stepper/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; http://docs.platformio.org/page/projectconf.html 9 | 10 | [env:sipeed-longan-nano] 11 | platform = gd32v 12 | framework = gd32vf103-sdk 13 | board = sipeed-longan-nano 14 | monitor_speed = 115200 15 | upload_protocol = dfu -------------------------------------------------------------------------------- /stepper/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 | \brief delay a time in milliseconds 40 | \param[in] count: count in milliseconds 41 | \param[out] none 42 | \retval none 43 | */ 44 | void delay_1ms(uint32_t count) 45 | { 46 | uint64_t start_mtime, delta_mtime; 47 | 48 | // Don't start measuruing until we see an mtime tick 49 | uint64_t tmp = get_timer_value(); 50 | do { 51 | start_mtime = get_timer_value(); 52 | } while (start_mtime == tmp); 53 | 54 | do { 55 | delta_mtime = get_timer_value() - start_mtime; 56 | }while(delta_mtime <(SystemCoreClock/4000.0 *count )); 57 | } 58 | -------------------------------------------------------------------------------- /stepper/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /timebase/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /timebase/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /timebase/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /timebase/include/gd32v_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 | -------------------------------------------------------------------------------- /timebase/include/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 | -------------------------------------------------------------------------------- /timebase/include/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 | void delay_1ms(uint32_t count); 41 | 42 | #endif /* SYS_TICK_H */ 43 | -------------------------------------------------------------------------------- /timebase/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /timebase/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:sipeed-longan-nano] 12 | platform = gd32v 13 | board = sipeed-longan-nano 14 | framework = gd32vf103-sdk 15 | upload_port = COM3 16 | upload_protocol = rv-link 17 | debug_tool = rv-link 18 | build_type = debug 19 | debug_port = COM3 20 | monitor_port = COM10 21 | monitor_speed = 115200 -------------------------------------------------------------------------------- /timebase/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | --------------------------------------------------------------------------------