├── 02-ADC
├── core
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
└── include
│ └── gd32vf103_usb_it.h
├── 03-PWM
├── core
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
└── include
│ └── gd32vf103_usb_it.h
├── 05-LCD
├── core
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
└── include
│ └── gd32vf103_usb_it.h
├── 06-I2C
├── core
├── .gitignore
├── README.md
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
└── include
│ └── gd32vf103_usb_it.h
├── 08-SD-card
├── core
├── put_in_tf_card
│ ├── 0.bin
│ ├── 1.bin
│ ├── 2.bin
│ ├── 3.bin
│ ├── 4.bin
│ ├── 5.bin
│ ├── 6.bin
│ ├── 7.bin
│ ├── 8.bin
│ ├── 9.bin
│ └── colon.bin
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
├── README.md
└── include
│ └── gd32vf103_usb_it.h
├── 04-Interrupts
├── core
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
└── include
│ └── gd32vf103_usb_it.h
├── 07-USB-serial
├── core
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
├── README.md
└── include
│ └── gd32vf103_usb_it.h
├── 01-GPIO
├── .gitignore
├── .vscode
│ └── extensions.json
├── lib
│ ├── fatfs
│ │ ├── include
│ │ │ ├── tf_card.h
│ │ │ ├── tf_delay.h
│ │ │ └── gd32v_tf_card_if.h
│ │ └── src
│ │ │ ├── tf_delay.c
│ │ │ ├── gd32v_tf_card_if.c
│ │ │ └── 00readme.txt
│ ├── usbcdc
│ │ ├── src
│ │ │ ├── weak.c
│ │ │ └── usb_serial_if.c
│ │ └── include
│ │ │ ├── usb_serial_if.h
│ │ │ ├── drv_usbd_int.h
│ │ │ └── usbd_conf.h
│ ├── README
│ ├── pjt
│ │ └── include
│ │ │ └── gd32v_pjt_include.h
│ ├── mpu6500
│ │ └── include
│ │ │ ├── gd32v_mpu6500_if.h
│ │ │ └── mpu6500_driver.h
│ └── systick
│ │ └── include
│ │ └── systick.h
├── test
│ └── README
├── platformio.ini
├── include
│ └── gd32vf103_usb_it.h
└── src
│ └── app.c
└── README.md
/02-ADC/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/02-ADC/core
--------------------------------------------------------------------------------
/03-PWM/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/03-PWM/core
--------------------------------------------------------------------------------
/05-LCD/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/05-LCD/core
--------------------------------------------------------------------------------
/06-I2C/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/06-I2C/core
--------------------------------------------------------------------------------
/08-SD-card/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/core
--------------------------------------------------------------------------------
/04-Interrupts/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/04-Interrupts/core
--------------------------------------------------------------------------------
/07-USB-serial/core:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/07-USB-serial/core
--------------------------------------------------------------------------------
/01-GPIO/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/02-ADC/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/03-PWM/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/05-LCD/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/06-I2C/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/0.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/0.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/1.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/1.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/2.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/2.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/3.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/3.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/4.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/4.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/5.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/5.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/6.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/6.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/7.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/7.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/8.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/8.bin
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/9.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/9.bin
--------------------------------------------------------------------------------
/04-Interrupts/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/07-USB-serial/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/08-SD-card/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/08-SD-card/put_in_tf_card/colon.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linusreM/Longan-RISC-V-examples/HEAD/08-SD-card/put_in_tf_card/colon.bin
--------------------------------------------------------------------------------
/06-I2C/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## I2C Example
4 |
5 |
6 |
7 | This documentation is still WIP. Check the src/app.c comments for how I2C works on GD32V.
8 |
9 |
--------------------------------------------------------------------------------
/01-GPIO/.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 |
--------------------------------------------------------------------------------
/01-GPIO/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/02-ADC/.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 |
--------------------------------------------------------------------------------
/02-ADC/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/03-PWM/.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 |
--------------------------------------------------------------------------------
/03-PWM/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/05-LCD/.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 |
--------------------------------------------------------------------------------
/05-LCD/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/06-I2C/.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 |
--------------------------------------------------------------------------------
/06-I2C/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/04-Interrupts/.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 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/07-USB-serial/.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 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/08-SD-card/.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 |
--------------------------------------------------------------------------------
/08-SD-card/lib/fatfs/include/tf_card.h:
--------------------------------------------------------------------------------
1 | #ifndef _TF_CARD_H_
2 | #define _TF_CARD_H_
3 |
4 | //#include "gd32v_pjt_include.h"
5 | #include "gd32v_pjt_include.h"
6 | #include "diskio.h"
7 | #include "ff.h"
8 | #include "systick.h"
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/01-GPIO/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/02-ADC/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/03-PWM/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/05-LCD/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/06-I2C/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/04-Interrupts/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/07-USB-serial/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/08-SD-card/lib/usbcdc/src/weak.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This is a workaround to be able to redirect printf() from the _write call,
4 | which in the gd32v sdk is not defined as weak
5 | (if you don't need to use DMA for transfers then you can usually just implement putc() instead) */
6 | #ifdef USE_USB_PRINTF
7 | extern ssize_t _write(int fd, const void* ptr, size_t len) __attribute__((weak));
8 | #endif
--------------------------------------------------------------------------------
/01-GPIO/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/02-ADC/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/03-PWM/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/05-LCD/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/06-I2C/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/08-SD-card/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/04-Interrupts/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/07-USB-serial/lib/fatfs/include/tf_delay.h:
--------------------------------------------------------------------------------
1 | #ifndef TF_DELAY_H
2 | #define TF_DELAY_H
3 |
4 | #include "gd32vf103.h"
5 |
6 | //These functions are used for relieving the timer2 HW dependency and instead uses mtime. There is a *slight* performance loss
7 | //But should be less prone to overlapping dependencies such as for USB-serial
8 |
9 | void tf_start_timer(int32_t millis);
10 |
11 | int tf_timer_done(void);
12 | #endif //TF_DELAY_H
--------------------------------------------------------------------------------
/01-GPIO/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/02-ADC/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/03-PWM/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/05-LCD/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/06-I2C/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/04-Interrupts/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/07-USB-serial/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/08-SD-card/lib/usbcdc/include/usb_serial_if.h:
--------------------------------------------------------------------------------
1 | #ifndef USB_SERIAL_IF
2 | #define USB_SERIAL_IF
3 |
4 | #include "cdc_acm_core.h"
5 | #include
6 | #include
7 |
8 | extern uint8_t packet_sent, packet_receive;
9 | extern uint32_t receive_length;
10 | void configure_usb_serial();
11 | int usb_serial_available();
12 | size_t read_usb_serial(uint8_t* data);
13 |
14 | #ifdef USE_USB_PRINTF
15 | ssize_t _write(int fd, const void* ptr, size_t len);
16 | #endif
17 |
18 | #endif
--------------------------------------------------------------------------------
/02-ADC/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/03-PWM/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/05-LCD/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/06-I2C/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/01-GPIO/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/08-SD-card/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/04-Interrupts/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/07-USB-serial/lib/fatfs/include/gd32v_tf_card_if.h:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "tf_card.h"
3 |
4 |
5 | typedef struct{
6 | uint16_t year;
7 | uint8_t month;
8 | uint8_t day;
9 | uint8_t hour;
10 | uint8_t minute;
11 | uint8_t second;
12 | }fat_time_t;
13 | /**
14 | * Set time for FAT filesystem
15 | * */
16 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
17 | /** Get time for fat file system
18 | * */
19 | DWORD get_fattime(void);
--------------------------------------------------------------------------------
/01-GPIO/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 |
--------------------------------------------------------------------------------
/02-ADC/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 |
--------------------------------------------------------------------------------
/03-PWM/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 |
--------------------------------------------------------------------------------
/05-LCD/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 |
--------------------------------------------------------------------------------
/06-I2C/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 |
--------------------------------------------------------------------------------
/08-SD-card/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 |
--------------------------------------------------------------------------------
/04-Interrupts/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 |
--------------------------------------------------------------------------------
/07-USB-serial/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 |
--------------------------------------------------------------------------------
/01-GPIO/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/02-ADC/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/03-PWM/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/05-LCD/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/06-I2C/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/04-Interrupts/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/07-USB-serial/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/08-SD-card/lib/fatfs/src/tf_delay.c:
--------------------------------------------------------------------------------
1 | #include "systick.h"
2 | #include "gd32vf103.h"
3 |
4 |
5 | volatile uint64_t tf_current_time = 0;
6 | volatile uint64_t tf_delay_until = 0;
7 |
8 | void tf_start_timer(int32_t millis){
9 | tf_current_time = get_timer_value();
10 | tf_delay_until = tf_current_time + ((SystemCoreClock/4000)*millis);
11 | }
12 | uint32_t tf_timer_done(void){
13 |
14 | tf_current_time = get_timer_value();
15 | //if(tf_delay_start > tf_delay_until) return tf_delay_start > current_time && current_time > tf_delay_until ? 0 : 1; //On overflow
16 | if(tf_current_time > tf_delay_until) return 0; //No overflow
17 | return 1;
18 | }
--------------------------------------------------------------------------------
/01-GPIO/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/02-ADC/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/03-PWM/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/05-LCD/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/06-I2C/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/04-Interrupts/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/07-USB-serial/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/08-SD-card/lib/fatfs/src/gd32v_tf_card_if.c:
--------------------------------------------------------------------------------
1 | #include "gd32vf103.h"
2 | #include "gd32v_tf_card_if.h"
3 | #include "tf_card.h"
4 |
5 | fat_time_t time = {.year = 2020, .month = 3, .day = 6, .hour = 0, .minute = 0};
6 |
7 | void set_fattime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second){
8 | time.year = year;
9 | time.month = month;
10 | time.day = day;
11 | time.hour = hour;
12 | time.minute = minute;
13 | time.second = second;
14 | }
15 |
16 | DWORD get_fattime (void){
17 | return
18 | (((uint8_t)(time.year - 1980)) << 25) |
19 | (time.month << 21) |
20 | (time.day << 16) |
21 | (time.hour << 11) |
22 | (time.minute << 5) |
23 | (time.second << 0);
24 | }
--------------------------------------------------------------------------------
/01-GPIO/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/02-ADC/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/03-PWM/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/05-LCD/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/06-I2C/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/08-SD-card/lib/fatfs/src/00readme.txt:
--------------------------------------------------------------------------------
1 | FatFs Module Source Files R0.13c
2 |
3 |
4 | FILES
5 |
6 | 00readme.txt This file.
7 | 00history.txt Revision history.
8 | ff.c FatFs module.
9 | ffconf.h Configuration file of FatFs module.
10 | ff.h Common include file for FatFs and application module.
11 | diskio.h Common include file for FatFs and disk I/O module.
12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13 | ffunicode.c Optional Unicode utility functions.
14 | ffsystem.c An example of optional O/S related functions.
15 |
16 |
17 | Low level disk I/O module is not included in this archive because the FatFs
18 | module is only a generic file system layer and it does not depend on any specific
19 | storage device. You need to provide a low level disk I/O module written to
20 | control the storage device that attached to the target system.
21 |
22 |
--------------------------------------------------------------------------------
/02-ADC/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM0 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/03-PWM/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM0 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/05-LCD/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM0 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/06-I2C/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM0 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/01-GPIO/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM49 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | ;-DUSE_USB
24 | ;-DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/08-SD-card/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM0 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/04-Interrupts/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM20 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/07-USB-serial/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 |
16 | ;upload_protocol = dfu ;Uncomment this if uploading with DFU
17 | upload_protocol = rv-link ;Uncomment this if uploading with debugger
18 |
19 | debug_tool = rv-link
20 | debug_port = /dev/ttyACM0 ;Should be the port that the debugger is attatched to (COMX for win, /dev/ttyACMX for OSX/Linux)
21 |
22 | build_flags = -fshort-wchar ;Needed for USB
23 | -DUSE_USB
24 | -DUSE_USB_PRINTF ;Uncomment to enable printf via USB-serial (USB-serial still needs to be initiated)
25 |
26 |
--------------------------------------------------------------------------------
/01-GPIO/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 |
--------------------------------------------------------------------------------
/02-ADC/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 |
--------------------------------------------------------------------------------
/03-PWM/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 |
--------------------------------------------------------------------------------
/05-LCD/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 |
--------------------------------------------------------------------------------
/06-I2C/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 |
--------------------------------------------------------------------------------
/04-Interrupts/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 |
--------------------------------------------------------------------------------
/07-USB-serial/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 |
--------------------------------------------------------------------------------
/08-SD-card/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 |
--------------------------------------------------------------------------------
/01-GPIO/lib/pjt/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 |
--------------------------------------------------------------------------------
/02-ADC/lib/pjt/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 |
--------------------------------------------------------------------------------
/03-PWM/lib/pjt/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 |
--------------------------------------------------------------------------------
/05-LCD/lib/pjt/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 |
--------------------------------------------------------------------------------
/06-I2C/lib/pjt/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 |
--------------------------------------------------------------------------------
/08-SD-card/lib/pjt/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 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/pjt/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 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/pjt/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 |
--------------------------------------------------------------------------------
/01-GPIO/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/02-ADC/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/03-PWM/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/05-LCD/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/06-I2C/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/04-Interrupts/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/07-USB-serial/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/08-SD-card/lib/mpu6500/include/gd32v_mpu6500_if.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_IF
2 | #define MPU6500_IF
3 |
4 | #include "mpu6500_driver.h"
5 |
6 |
7 |
8 |
9 | #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
10 | #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
11 | #define I2C_MASTER_NUM 1 /*!< I2C port number for master dev */
12 | #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
13 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
14 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
15 |
16 | #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
17 | #define READ_BIT I2C_MASTER_READ /*!< I2C master read */
18 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
19 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
20 | #define ACK_VAL 0x0 /*!< I2C ack value */
21 | #define NACK_VAL 0x1 /*!< I2C nack value */
22 |
23 |
24 |
25 | void mpu6500_install(uint32_t port);
26 |
27 | void i2c_master_init(uint32_t port);
28 |
29 | void mpu_delay(int millis);
30 |
31 | void i2c_master_read_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
32 |
33 |
34 | void i2c_master_write_register(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/02-ADC/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/03-PWM/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/05-LCD/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/06-I2C/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/01-GPIO/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/08-SD-card/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/04-Interrupts/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/07-USB-serial/lib/mpu6500/include/mpu6500_driver.h:
--------------------------------------------------------------------------------
1 | #ifndef MPU6500_DRIVER
2 | #define MPU6500_DRIVER
3 |
4 | #include "mpu6500_registers.h"
5 | #include
6 | #include
7 |
8 |
9 | typedef struct{
10 | float x;
11 | float y;
12 | float z;
13 | }mpu_vector_t;
14 |
15 |
16 | typedef struct{
17 | int16_t x;
18 | int16_t y;
19 | int16_t z;
20 | }mpu_raw_vector_t;
21 |
22 | /** Initialize mpu6500 driver to be portable this is initialized with the functions used for:
23 | * read(i2c), write(i2c), and delay
24 | * read should have the structure: read(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
25 | * write should have the structure: write(void* handle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t *data)
26 | * delay should have the structure: delay(millis)
27 | * */
28 |
29 | int mpu6500_init(void (*read_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
30 | void (*write_cb)(void* pHandle, uint8_t addr, uint8_t reg, uint8_t size, uint8_t* pData),
31 | void (*delay_cb)(int millis),
32 | void* pHandle);
33 |
34 |
35 | /** Gets accelleration data from the sensor
36 | * @param pAccel Buffer to store the result in. For standard configuration this is caled to 1 = 1/4096 g
37 | * */
38 | int mpu6500_getAccel(mpu_vector_t* pAccel);
39 | /** Gets rotation data from the sensor
40 | * @param pGyro buffer to store result in
41 | * */
42 | int mpu6500_getGyro(mpu_vector_t* pGyro);
43 |
44 | /**
45 | * Get Both gyro and accelleration data
46 | * @param pAccel buffer to store accelleration data in
47 | * @param pGyro buffer to store rotation data in
48 | */
49 | int mpu6500_getGyroAccel(mpu_vector_t* pAccel, mpu_vector_t* pGyro);
50 |
51 | #endif
--------------------------------------------------------------------------------
/08-SD-card/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # SD-card Example
4 |
5 |
6 | This example uses the FAT file system library written by ChaN. The full, very comprehensive documentation can be found here: [FatFs Module Documentation](http://elm-chan.org/fsw/ff/00index_e.html)
7 |
8 | To try the example put the files in the **put_in_tf_card** folder in the root directory of the SD-card.
9 |
10 | The program will write a text file to disk and then open some images from the card to display a clock.
11 |
12 | You can convert images using this useful web-tool: https://lvgl.io/tools/imageconverter
13 | Use RGB656 binary as the output.
14 |
15 | ## Functions
16 | ```c
17 | FRESULT f_mount (
18 | FATFS* fs, /* [IN] Filesystem object */
19 | const TCHAR* path, /* [IN] Logical drive number */
20 | BYTE opt /* [IN] Initialization option */
21 | );
22 | ```
23 | Use this to mount the filesystem.
24 | ```c
25 | FRESULT f_open (
26 | FIL* fp, /* [OUT] Pointer to the file object structure */
27 | const TCHAR* path, /* [IN] File name */
28 | BYTE mode /* [IN] Mode flags */
29 | );
30 | ```
31 | Opening a file.
32 | ```c
33 | FRESULT f_write (
34 | FIL* fp, /* [IN] Pointer to the file object structure */
35 | const void* buff, /* [IN] Pointer to the data to be written */
36 | UINT btw, /* [IN] Number of bytes to write */
37 | UINT* bw /* [OUT] Pointer to the variable to return number of bytes written */
38 | );
39 | ```
40 | Write to file.
41 | ```c
42 | FRESULT f_read (
43 | FIL* fp, /* [IN] File object */
44 | void* buff, /* [OUT] Buffer to store read data */
45 | UINT btr, /* [IN] Number of bytes to read */
46 | UINT* br /* [OUT] Number of bytes read */
47 | );
48 | ```
49 | Read from a file.
50 | ```c
51 | FRESULT f_close (
52 | FIL* fp /* [IN] Pointer to the file object */
53 | );
54 | ```
55 | Close the file. Flushes any unwritten data into the file. If you just want to flush buffered data you can also use f_sync() to flush data but keep the file open.
56 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Longan Nano Examples
2 |
3 | The examples in this repository are intended as starting points for some of the different peripherals available on the GD32VF103 chip and the additional hardware on the Longan Nano board.
4 |
5 | To make getting started as easy as possible the examples in general only include the most basic basic settings to make a peripheral work. To go further you will need to either look at the firmware library examples which are much more comprehensive, or reference the manual directly.
6 |
7 | ## Using the examples
8 |
9 | All of the code that's different between the projects is inside the **src/app.c** file. All of the projects has an individual README.md which explains the program.
10 |
11 | ### Opening
12 |
13 | Use PlatformIO to open a project, just open the PIO home page, then press open project and navigate to one of the example directories.
14 |
15 | Since all of the project contains the same libraries except for the app.c file it's no problem to mix and match code from different examples.
16 |
17 | ### Programming
18 |
19 | By default the projects are confgured to be programmed using an RV-link (if you have two Longan Nano you can make one into an RV-link by programming it using this guide).
20 |
21 | If you want to use some other method for programming you can change the **platform.ini** file to your prefered programming method.
22 |
23 | ## Acknowledgements
24 |
25 | The examples in this repository are based on a number of different sources.
26 |
27 | * [GD32VF103 Firmware Library Examples](https://github.com/riscv-mcu/GD32VF103_Firmware_Library) Main reference
28 | * [GD32V Virtual Com Port](https://github.com/linusreM/GD32V-Virtual-COM-Port) in turn based on
29 | * [CDC_ACM Example](https://github.com/riscv-mcu/GD32VF103_Demo_Suites/tree/master/GD32VF103C_START_Demo_Suites/Projects/04_USBFS/Device/CDC_ACM) For USB base code
30 | * [Longan_GD32VF_examples](https://github.com/sipeed/Longan_GD32VF_examples) For LCD and RGB-led
31 | * [FatFs by ChaN](http://elm-chan.org/fsw/ff/00index_e.html) For the sd-card read/write
32 |
33 |
--------------------------------------------------------------------------------
/01-GPIO/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/02-ADC/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/03-PWM/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/05-LCD/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/06-I2C/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/08-SD-card/lib/systick/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 | * Delay one millisecond * count
41 | * @param count miliseconds to delay for
42 | */
43 | void delay_1ms(uint32_t count);
44 |
45 | /**
46 | * Delay one millisecond * count
47 | * @param count miliseconds to delay for
48 | */
49 | void delay_1us(uint32_t count);
50 |
51 | #endif /* SYS_TICK_H */
52 |
--------------------------------------------------------------------------------
/07-USB-serial/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## USB Serial Example
4 |
5 |
6 |
7 | The GD32VF103 chip includes hardware support for USB and the longan nano usb port is connected with that interface. USB can be used for a vast amount of purposes such as HID-devices, mass storage devices et.c. To make it easy to communicate between computer and MCU these examples includes an implementation of a virtual com-port to enable serial port communication over usb to a terminal on PC.
8 |
9 | To simplify writing values using usb the interface has been implemented to use **printf()**. Since printf uses a fair amount of program space the flags for **USE_USB** and **USE_USB_PRINTF** need to be defined for the compiler to include it in the program. The simplest way to put the flags in is to either use **#define** in the **app.c** file or under **-build_flags** put **-DUSE_USB** and **-DUSE_USB_SERIAL**.
10 |
11 | To use the example connect the longan nano via its usb port and open a terminal (platformIO has an included serial terminal, click the icon in the bottom bar with the little plug). Then start typing some in the terminal. When done typing press enter and the program will transmit the message written back to the terminal as well as how many bytes the message contained.
12 |
13 | ### Functions
14 |
15 |
16 | ```c
17 | void configure_usb_serial()
18 | ```
19 | This function is used to initialize the USB interface to act as a virtual serial port. The driver uses timer2 so make sure when using USB that you are not reconfiguring timer2 to do something else.
20 |
21 | ```c
22 | size_t read_usb_serial(uint8_t *data)
23 | ```
24 | This function will read any data received from the USB interface. If anything has been received it will be collected into the data buffer and ended with a '\0' string terminator. The function will also return the number of bytes received.
25 | ```c
26 | void printf()
27 | ```
28 | Works like standard printf, but is rerouted through the USB-serial port. Printing floats is currently not supported though so printing floats has to be done manualy (eg. "%d,%d", (int)float_var, (int)((float_var-((int)float_var)))*100.0)
29 |
30 | Though keep in mind that the GD32VF103 chip doesn't have dedicated hardware for float calculations so whenever possible using integer calculation instead will be a lot more efficient.
--------------------------------------------------------------------------------
/01-GPIO/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/02-ADC/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/03-PWM/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/05-LCD/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/06-I2C/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/04-Interrupts/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/07-USB-serial/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/08-SD-card/include/gd32vf103_usb_it.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file gd32vf103_it.h
3 | \brief the header file of the ISR
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef GD32VF103_USB_IT_H
36 | #define GD32VF103_USB_IT_H
37 | #ifdef USE_USB
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | #include "usbd_core.h"
43 |
44 | /* function declarations */
45 | /* this function handles USB wakeup interrupt handler */
46 | void USBFS_WKUP_IRQHandler(void);
47 | /* this function handles USBFS IRQ Handler */
48 | void USBFS_IRQHandler(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* GD32VF103_USB_IT_H */
55 | #endif
--------------------------------------------------------------------------------
/02-ADC/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/03-PWM/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/05-LCD/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/06-I2C/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/01-GPIO/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/08-SD-card/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/usbcdc/include/drv_usbd_int.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file drv_usbd_int.h
3 | \brief USB device mode interrupt header file
4 |
5 | \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __DRV_USBD_INT_H
36 | #define __DRV_USBD_INT_H
37 |
38 | #include "drv_usb_core.h"
39 | #include "drv_usb_dev.h"
40 |
41 | /* USB device-mode interrupts global service routine handler */
42 | void usbd_isr (usb_core_driver *udev);
43 |
44 | #ifdef USB_HS_DEDICATED_EP1_ENABLED
45 |
46 | uint32_t USBD_OTG_EP1IN_ISR_Handler (usb_core_driver *udev);
47 | uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev);
48 |
49 | #endif
50 |
51 | #endif /* __DRV_USBD_INT_H */
52 |
53 |
--------------------------------------------------------------------------------
/01-GPIO/src/app.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include "gd32vf103.h"
4 | #include "systick.h"
5 |
6 | #define RED_LED_PIN GPIO_PIN_13
7 | #define GREEN_LED_PIN GPIO_PIN_1
8 | #define BLUE_LED_PIN GPIO_PIN_2
9 |
10 | #define RED_LED_PORT GPIOC
11 | #define GREEN_LED_PORT GPIOA
12 | #define BLUE_LED_PORT GPIOA
13 |
14 | int main(void)
15 | {
16 | /* GD32VF103 Utilizes clock gating for peripherals so that they don't consume power while not being used
17 | therefore for each peripheral you intend to use you need to enable the clock for that peripheral.
18 | Since this example uses GPIO from PORT A and C both need to be activated. */
19 | rcu_periph_clock_enable(RCU_GPIOA);
20 | rcu_periph_clock_enable(RCU_GPIOC);
21 |
22 | /* The following two lines initializes the pins connected to the LEDs on the longan board as outputs
23 | with push-pull. */
24 | gpio_init(RED_LED_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, RED_LED_PIN);
25 | /* You can init multiple pins on the same port by using bitwise or */
26 | gpio_init(GREEN_LED_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GREEN_LED_PIN | BLUE_LED_PIN);
27 |
28 | /* This configures the A3 and A4 pins as inputs with internal pull ups enabled */
29 | gpio_init(GPIOA, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_3 | GPIO_PIN_4);
30 |
31 | /* gpio_bit_write() sets the state of a pin to either 3.3V or 0V(GND).
32 | Use SET or 1 for 3.3V, and RESET or 0 for 0V(GND) */
33 | gpio_bit_write(GPIOA, GPIO_PIN_1, SET);
34 | gpio_bit_write(GPIOA, GPIO_PIN_2, SET);
35 | gpio_bit_write(GPIOC, GPIO_PIN_13, SET);
36 |
37 |
38 | while(1){ // Loop forever
39 |
40 | if(gpio_input_bit_get(GPIOA, GPIO_PIN_3)){ // Read pin A3
41 | gpio_bit_write(GPIOA, GPIO_PIN_1, !gpio_input_bit_get(GPIOA, GPIO_PIN_1)); // If A3 is HIGH(SET), toggle A1
42 | }
43 | if(gpio_input_bit_get(GPIOA, GPIO_PIN_4)){ // Read pin A4
44 | gpio_bit_write(GPIOC, GPIO_PIN_13, (!gpio_input_bit_get(GPIOC, GPIO_PIN_13))); // If A4 is HIGH(SET), toggle C13
45 | }
46 | delay_1ms(500); // Wait for half a second
47 | }
48 |
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/02-ADC/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/03-PWM/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/05-LCD/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/06-I2C/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/01-GPIO/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/01-GPIO/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/02-ADC/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/03-PWM/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/05-LCD/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/06-I2C/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/08-SD-card/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/08-SD-card/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/04-Interrupts/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/usbcdc/include/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /*!
2 | \file usbd_conf.h
3 | \brief the header file of USB device-mode configuration
4 |
5 | \version 2019-6-5, V1.0.0, demo for GD32VF103
6 | */
7 |
8 | /*
9 | Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | 1. Redistributions of source code must retain the above copyright notice, this
15 | list of conditions and the following disclaimer.
16 | 2. Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 | 3. Neither the name of the copyright holder nor the names of its contributors
20 | may be used to endorse or promote products derived from this software without
21 | specific prior written permission.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | OF SUCH DAMAGE.
33 | */
34 |
35 | #ifndef __USBD_CONF_H
36 | #define __USBD_CONF_H
37 |
38 | #include "usb_conf.h"
39 |
40 | #define USBD_CFG_MAX_NUM 1
41 | #define USBD_ITF_MAX_NUM 1
42 |
43 | #define USB_STR_DESC_MAX_SIZE 64
44 |
45 | #define USB_STRING_COUNT 4U
46 |
47 | /* endpoint count used by the CDC ACM device */
48 | #define CDC_ACM_CMD_EP EP2_IN
49 | #define CDC_ACM_DATA_IN_EP EP1_IN
50 | #define CDC_ACM_DATA_OUT_EP EP3_OUT
51 |
52 | #define CDC_ACM_CMD_PACKET_SIZE 8
53 | #define CDC_ACM_DATA_PACKET_SIZE 64
54 |
55 | #endif /* __USBD_CONF_H */
56 |
--------------------------------------------------------------------------------
/07-USB-serial/lib/usbcdc/src/usb_serial_if.c:
--------------------------------------------------------------------------------
1 | #include "usb_serial_if.h"
2 | #include "gd32vf103.h"
3 | #include "drv_usb_hw.h"
4 | #include "systick.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define USB_BUFFER_SIZE 1024
10 | #define TIMEOUT_PRINTF 10000
11 | typedef struct{
12 | uint8_t buffer[USB_BUFFER_SIZE];
13 | uint32_t max_size;
14 | uint32_t index;
15 | }USB_serial_buffer_t;
16 |
17 | USB_serial_buffer_t usb_buffer = { .buffer = "", .max_size = USB_BUFFER_SIZE, .index = 0};
18 |
19 | uint8_t tx_buffer[64] = "";
20 |
21 | usb_core_driver USB_OTG_dev =
22 | {
23 | .dev = {
24 | .desc = {
25 | .dev_desc = (uint8_t *)&device_descriptor,
26 | .config_desc = (uint8_t *)&configuration_descriptor,
27 | .strings = usbd_strings,
28 | }
29 | }
30 | };
31 |
32 | size_t read_usb_serial(uint8_t* data){
33 | size_t ret = 0;
34 | static uint8_t receive_buffer[64] = {'\0'};
35 | usb_buffer.index = 0;
36 | if (USBD_CONFIGURED == USB_OTG_dev.dev.cur_status){
37 | while(packet_receive == 1){
38 | if(receive_length > 0){
39 | memcpy(&usb_buffer.buffer[usb_buffer.index], receive_buffer, receive_length);
40 | usb_buffer.index += receive_length;
41 | ret += receive_length;
42 | }
43 | packet_receive = 0;
44 | receive_length = 0;
45 | usbd_ep_recev (&USB_OTG_dev, CDC_ACM_DATA_OUT_EP, receive_buffer, 64);
46 | delay_1ms(1);
47 | }
48 | usb_buffer.buffer[usb_buffer.index++] = '\0';
49 | memcpy(data, usb_buffer.buffer, usb_buffer.index);
50 | }
51 | return usb_buffer.index -1;
52 | }
53 |
54 |
55 | //TODO move to USB library
56 | void configure_usb_serial(){
57 |
58 | eclic_global_interrupt_enable();
59 | eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL2_PRIO2);
60 | usb_rcu_config();
61 | usb_timer_init();
62 | usb_intr_config();
63 | usbd_init (&USB_OTG_dev, USB_CORE_ENUM_FS, &usbd_cdc_cb);
64 | }
65 |
66 | int usb_serial_available(){return USBD_CONFIGURED == USB_OTG_dev.dev.cur_status;}
67 |
68 | #ifdef USE_USB_PRINTF
69 | ssize_t _write(int fd, const void* ptr, size_t len){
70 | int64_t temp = get_timer_value();
71 | while(packet_sent == 0 && temp + TIMEOUT_PRINTF > get_timer_value());
72 | packet_sent = 0;
73 | strncpy((char*)tx_buffer, ptr, len);
74 | usbd_ep_send(&USB_OTG_dev, CDC_ACM_DATA_IN_EP, tx_buffer, len);
75 | return len;
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------